Skip to content

Instantly share code, notes, and snippets.

@8lane
8lane / gist:8152412
Created December 27, 2013 20:45
Wordpress Multisite + Groups Plugin: Check if user is in group
<?php
$blog_id = 1; //set the blog id to the main site id
switch_to_blog( $blog_id );
$user_id = get_current_user_id();
$group = Groups_Group::read_by_name( 'Premium' );
if ( Groups_User_Group::read( $user_id, $group->group_id ) ) {
echo 'Premium';
@8lane
8lane / gist:8181524
Created December 30, 2013 12:24
Clean-up Wordpress <head>
remove_action( 'wp_head', 'feed_links_extra', 3 ); // Display the links to the extra feeds such as category feeds
remove_action( 'wp_head', 'feed_links', 2 ); // Display the links to the general feeds: Post and Comment Feed
remove_action( 'wp_head', 'rsd_link' ); // Display the link to the Really Simple Discovery service endpoint, EditURI link
remove_action( 'wp_head', 'wlwmanifest_link' ); // Display the link to the Windows Live Writer manifest file.
remove_action( 'wp_head', 'index_rel_link' ); // index link
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); // prev link
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); // start link
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 ); // Display relational links for the posts adjacent to the current post.
remove_action( 'wp_head', 'wp_generator' ); // Display the XHTML generator that is generated on the wp_head hook, WP version
@8lane
8lane / gist:8197157
Created December 31, 2013 13:58
Remove all Wordpress JS from <head> and move to the footer.
<?php
remove_action('wp_head', 'wp_print_scripts');
remove_action('wp_head', 'wp_print_head_scripts', 9);
remove_action('wp_head', 'wp_enqueue_scripts', 1);
add_action('wp_footer', 'wp_print_scripts', 3);
add_action('wp_footer', 'wp_enqueue_scripts', 3);
add_action('wp_footer', 'wp_print_head_scripts', 3);
?>
@8lane
8lane / gist:8197201
Created December 31, 2013 14:03
Remove Wordpress version parameter from any enqueued CSS & JS
<?php
function remove_wp_ver_css_js( $src ) {
if ( strpos( $src, 'ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'remove_wp_ver_css_js');
add_filter( 'script_loader_src', 'remove_wp_ver_css_js');
@8lane
8lane / gist:8197213
Last active December 12, 2019 21:20
Get number of twitter followers API 1.1
<?php
function getTwitterFollowers($screenName = 'wpbeginner')
{
// some variables
$consumerKey = 'YIQPxqfqQto5yaskourlA';
$consumerSecret = 'OH3xiYM4oN3mjGK3as9m37zkKeyiHgKhBIgiNhoM';
$token = get_option('cfTwitterToken');
// get follower count from cache
@8lane
8lane / gist:8197235
Created December 31, 2013 14:05
Get number of Facebook followers
<?php
function bfan() {
$pageID = '199776743514953';
$info = json_decode(file_get_contents('http://graph.facebook.com/' . $pageID));
return $info->likes;
}
?>
@8lane
8lane / gist:8197262
Created December 31, 2013 14:07
Change WooCommerce Paypal Icon on checkout
<?php
add_filter('woocommerce_paypal_icon', 'custom_woocommerce_paypal_icon');
function custom_woocommerce_paypal_icon( $url ) {
$url = get_bloginfo('template_url')."/images/PayPalLogo.png";
return $url;
}
?>
@8lane
8lane / gist:8271205
Created January 5, 2014 17:33
Custom loading.gif for Contact Form 7 Wordpress Plugin
<?php
// :: Custom ajax loader for Contact Form 7 ::
add_filter('wpcf7_ajax_loader', 'my_wpcf7_ajax_loader');
function my_wpcf7_ajax_loader () {
return network_home_url() . '/assets/themes/ips-helpdesk/images/ajax-loader.gif';
}
?>
@8lane
8lane / gist:8475875
Created January 17, 2014 15:59
Disable click on Wordpress parent navigation items for touch screens + bigger than 768px
var supportsTouch = 'ontouchstart' in window || navigator.msMaxTouchPoints,
docWidth = jQuery(document).width();
if ( supportsTouch && docWidth > 768 ) jQuery('#navigation .parent').on('click',function(e) { e.preventDefault(); });
@8lane
8lane / gist:9491063
Created March 11, 2014 17:45
ipb3 test if no posts in topic
<if test="$topic['posts'] == 0">
..
</if>