Skip to content

Instantly share code, notes, and snippets.

View nadeem-khan's full-sized avatar

Nadeem Khan nadeem-khan

View GitHub Profile
FROM php:7.0.4-fpm
RUN apt-get update && apt-get install -y libmcrypt-dev \
mysql-client libmagickwand-dev --no-install-recommends \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& docker-php-ext-install mcrypt pdo_mysql

This extends the built-in WordPress function get_the_ID() to return the post ID both inside and outside the loop.

Used outside the loop (in header.php):

<?php if ( function_exists( 'gt_hide_nav' ) && ! gt_hide_nav() ) : ?>
  <nav role="navigation">
    <?php if ( function_exists( 'bones_main_nav' ) ) bones_main_nav(); ?>
  </nav>

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

@nadeem-khan
nadeem-khan / order-emails.md
Last active August 29, 2015 14:05 — forked from mikejolley/gist:2263203
Add custom fields to Order email of Woocommerce

Add the field to order emails:

 add_filter('woocommerce_email_order_meta_keys', 'my_woocommerce_email_order_meta_keys');

 function my_woocommerce_email_order_meta_keys( $keys ) {
$keys['How did you hear about us?'] = 'hear_about_us';
return $keys;

}

@nadeem-khan
nadeem-khan / change-role-based-on-balance.md
Last active February 6, 2016 20:04 — forked from gabrielmerovingi/change-role-based-on-balance
Change WordPress user role based on Mycred Points

Change WordPress user role based on Mycred Points:

add_filter( 'mycred_add', 'check_for_role_change', 99, 3 );
 function check_for_role_change( $reply, $request, $mycred ) {
// Make sure that if any other filter has declined this we also decline
if ( $reply === false ) return $reply;

// Exclude admins
if ( user_can( $request['user_id'], 'manage_options' ) ) return $reply;
/**
* Custom myCRED Widget: This months leaderboard
* This widget will show this months leaderbaord with the option to set
* a title, the number of users to include and if it should be visible for
* non-members.
* @install Paste into your theme or child-themes functions.php file
* @author Gabriel S Merovingi
* @version 1.0
*/