Skip to content

Instantly share code, notes, and snippets.

@sjaved87
sjaved87 / wp-list-expired-members.php
Created February 16, 2017 15:24
List expired members of Membership 2 in a table with a shortcode. It can be used standalone without Membership 2 plugin (just remove the condition in loop).
<?php
function listexpiremembers_func( $atts, $content ) {
if ( !defined( 'MS_PLUGIN' ) ) return $content;
$args['subscription_status'] = 'expired';
$all_members = MS_Model_Member::get_members( $args );
$total_items = MS_Model_Member::get_members_count( $args );
if( $all_members ){
@sjaved87
sjaved87 / allow-zip-gzip-ml.php
Created January 31, 2017 06:18
Allow zip and gzip files in WordPress Media Library
<?php
function sjaved_zip_gzip_mime_types ( $mimes ) {
$existing_mimes['zip'] = 'application/zip';
$existing_mimes['gz'] = 'application/x-gzip';
return $mimes;
}
add_filter('upload_mimes', 'sjaved_zip_gzip_mime_types');
@sjaved87
sjaved87 / allow-svg-ml.php
Created January 31, 2017 06:12
Allow SVG files in media library.
<?php
function sjaved_svg_mime_type($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'sjaved_svg_mime_type');
@sjaved87
sjaved87 / domain-mapping-hide-menu.php
Last active January 5, 2017 13:06
[WPMU DEV Domain Mapping plugin] This snippet will remove the Domain Mapping menu under Tools from all sites unless its Super Admin who is viewing the site.
<?php
add_action( 'admin_menu', 'wpmudev_hide_domain_mapping_menu', 999 );
function wpmudev_hide_domain_mapping_menu() {
if( is_super_admin() ) return;
$page = remove_submenu_page( 'tools.php', 'domainmapping' );
}
@sjaved87
sjaved87 / mp-order-number-on-edit.php
Created January 1, 2017 15:46
Display order number in edit order page for WPMU DEV MarketPress plugin. Just add the code in functions.php file of your child theme or use it as mu-plugin.
<?php
function wpmudev_mp_sho_order_number( $post ){
if( 'mp_order' != get_post_type( $post ) ) return $post;
echo '<h1 class=&quot;order_number&quot;> # ' .$post->post_title . '</h1>';
echo '<style>
h1.order_number{
margin-top: -42px;
@sjaved87
sjaved87 / blog-id-to-body-class.php
Created November 30, 2016 14:38
This snippet will add ID to body class like blog-1 if its main site.
<?php
function add_site_id_to_body_class( $classes ) {
global $post;
$current_blog_ID = get_current_blog_id();
$classes[] = 'blog-' . $current_blog_ID;
@sjaved87
sjaved87 / current_page_link.php
Created November 26, 2016 08:30
WordPress - Get current page URL on any page, post, home or any archive page (category, author, custom post type).
@sjaved87
sjaved87 / disable-plugin-for-mobile.php
Last active November 17, 2016 09:21
Disable a specific plugin for mobile devices.
<?php
add_filter('site_option_active_sitewide_plugins', 'wpmu_modify_sitewide_plugins', 99999);
function wpmu_modify_sitewide_plugins($value) {
global $current_blog;
$useragent=$_SERVER['HTTP_USER_AGENT'];
if(preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|
@sjaved87
sjaved87 / active_events_count.php
Last active September 2, 2016 18:34
WPMU DEV Events+ plugin - This snippet will count and return the active events.
<?php
function get_active_events_count(){
global $wpdb;
$count = $wpdb->get_var(
$wpdb->prepare(
"SELECT count(*)
FROM $wpdb->postmeta
WHERE meta_key = %s
and meta_value = %s ",
@sjaved87
sjaved87 / welcome.php
Created September 1, 2016 12:55
This shortcode will display display name of the logged in user. This is the shortcode [welcome_message].
<?php
function sjaved_welcome_message_cb(){
$current_user = wp_get_current_user();
echo 'Hello ' . $current_user->display_name ;
}
add_shortocde('welcome_message', 'sjaved_welcome_message_cb', 10);