Skip to content

Instantly share code, notes, and snippets.

Sabrina Zeidan sabrina-zeidan

Block or report user

Report or block sabrina-zeidan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@sabrina-zeidan
sabrina-zeidan / wordpress_multisite_unfiltered_html.php
Created Dec 7, 2018
Let users apart from Superadmin insert raw code in text editor [WordPress Multisite]
View wordpress_multisite_unfiltered_html.php
//Let any user who can edit page insert unfiltered html in text editor
add_action( 'init', 'reply_unfiltered_html' );
function reply_unfiltered_html() {
$user = wp_get_current_user();
if ( current_user_can('edit_pages') )
kses_remove_filters();
}
//Let users with certain roles insert unfiltered html in text editor
add_action( 'init', 'reply_unfiltered_html_for_roles' );
function reply_unfiltered_html_for_roles() {
@sabrina-zeidan
sabrina-zeidan / wordpress_multisite_compatible_site_options_actions.php
Created Oct 16, 2018
To use one single function for stand-alone WordPress install and Multisite (in case options are network wide). Get/Update/Delete options with the same function with no need to check whether it's Multisite every time
View wordpress_multisite_compatible_site_options_actions.php
//Check if plugin is Network activated
if (!function_exists('is_plugin_active_for_network')) require_once( ABSPATH . '/wp-admin/includes/plugin.php');
$plugins = get_plugins();
foreach( $plugins as $plugin_file => $plugin_info ) {
if ( $plugin_info['TextDomain'] === $this->plugin_name ){
$plugin = $plugin_file;
break;
}
}
//And set constant
@sabrina-zeidan
sabrina-zeidan / wordpress_multisite_global_menu_anywhere.php
Created Sep 10, 2018
Get shared menu from the main site displayed anywhere in the WordPress Multisite network
View wordpress_multisite_global_menu_anywhere.php
//Get $blog_id to remember where we currently are
global $blog_id;
$current_blog_id = $blog_id;
//switch to the main site which has id of 1
switch_to_blog(1);
//Check if menu exists (regardless location)
if (wp_nav_menu(array('menu' => 'social-links'))):
//output the WordPress navigation menu, use slug/name/id
wp_nav_menu( array( 'menu' => 'social-links') );
endif;
@sabrina-zeidan
sabrina-zeidan / leave_good_tails.php
Created May 16, 2018
This function will clean your list of keywords from partially duplicated lines and return just good long-tailed keyword phrases
View leave_good_tails.php
<?php
/*
* This function will clean your list of keywords from partially duplicated lines and return just good long-tailed keyword phrases
* To learn more about about long-tails in SEO check http://sabrinazeidan.com/long-tail-keywords-for-seo-definition-examples-free-tool/
* Input file format: file.txt, UTF-8 without BOM, one keyword phrase per line
*
*/
function leave_good_tails($txt_file_url) {
$file_headers = @get_headers($txt_file_url);
if ($file_headers[0] == 'HTTP/1.0 404 Not Found'){ // or "HTTP/1.1 404 Not Found" etc.
@sabrina-zeidan
sabrina-zeidan / query_meta_without_value.php
Created Oct 18, 2017
meta_query to search post without custom field (no matter whether its empty or doesn't exist at all [WordPress]
View query_meta_without_value.php
$getposts = get_posts( array(
'numberposts' => -1, // тоже самое что posts_per_page
'post_type' => 'post',
'post_status' => 'any',
'fields' => 'ids',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'custom_field',
'compare' => 'NOT EXISTS',
@sabrina-zeidan
sabrina-zeidan / defer_javascript_parsing.php
Created Oct 12, 2017
This function will defer parsing of JavaScript for optimized page load [WordPress]
View defer_javascript_parsing.php
function add_async_and_defer_attribute($tag, $handle) {
//if ( 'adsense' == $handle ) return str_replace( 'src', 'async src', $tag );
//if ( strpos( $tag, 'jquery.js' ) ) return $tag;
return str_replace( 'src', 'defer onload="" src', $tag );
}
add_filter('script_loader_tag', 'add_async_and_defer_attribute', 10, 2);
@sabrina-zeidan
sabrina-zeidan / add_multiple_googleads.js
Created Oct 8, 2017
jQuery junction for correct inserting multiple Google Adsense blocks on the site. It will generate as many ad pushes as there are GoogleAds blocks on the current page. Automatic, convenient and lean
View add_multiple_googleads.js
jQuery(function ($) {
$(".adsbygoogle").each(function () { (adsbygoogle = window.adsbygoogle || []).push({}); })
});
@sabrina-zeidan
sabrina-zeidan / my_custom_image_size.php
Last active Oct 6, 2017
This function will create additional custom size of images in WordPress and prevent creating 2 default sizes. Second snippet controls correct name display in Media Library [WordPress]
View my_custom_image_size.php
function my_custom_image_size() {
//add additional size 'post-preview-small'
add_image_size('post-preview-small', 88, 88, true); // 88 pixels wide and tall, hard crop mode
//remove default sizes 'thumbnail' and 'medium'
remove_image_size('thumbnail');
remove_image_size('medium');
}
add_action( 'after_setup_theme', 'my_custom_image_size' );
@sabrina-zeidan
sabrina-zeidan / resize_images_gd_image_editor.php
Created Sep 19, 2017
Resize images in WordPress with in-built GD Image Editor [WordPress]
View resize_images_gd_image_editor.php
require_once( ABSPATH . 'wp-includes/class-wp-image-editor.php' );
require_once( ABSPATH . 'wp-includes/class-wp-image-editor-gd.php' );
//Get all bookcovers
$args = array( 'post_type' =>'post', 'posts_per_page' => -1, 'post_status' => 'any', 'fields' =>'ids');
$myposts = get_posts( $args );
foreach ($myposts as $mypostid) {
$bookcover = get_field('bookcover', $mypostid);
//Image options for resize
$max_w = 300;
$max_h = 450;
@sabrina-zeidan
sabrina-zeidan / trigger.php
Last active Jun 20, 2018
Trigger for WP MU Cron [Wordpress]
View trigger.php
if (!defined('ABSPATH')) {
require_once(dirname( __FILE__ ) . '/wp-load.php');
}
global $wpdb;
if ( is_multisite()) {
$sites = get_sites();
foreach ($sites as $site ) {
$blog_id = $site->blog_id;
//if ($blog_id < 6 ){//if we need certain blogs
switch_to_blog( $blog_id );
You can’t perform that action at this time.