/*———————————————————————————–*/ /* GET role /*———————————————————————————–*/ function get_user_role() { global $current_user; $user_roles = $current_user->roles; $user_role = array_shift($user_roles); return $user_role; }
Articles Tagged: Operation Method
Changing “Posts” menu name in admin (e.g. “Articles”)
// hook the translation filters add_filter(‘gettext’,’change_post_to_article’); add_filter(‘ngettext’,’change_post_to_article’); function change_post_to_article( $translated ) { $translated = str_ireplace(‘Post’,’Article’,$translated );// ireplace is PHP5 only return $translated; } Credits to smashingmagazine.com
Remove WordPress Admin Bar Menu Items
function dashboard_tweaks() { global $wp_admin_bar; $wp_admin_bar->remove_menu(‘wp-logo’); $wp_admin_bar->remove_menu(‘about’); $wp_admin_bar->remove_menu(‘wporg’); $wp_admin_bar->remove_menu(‘documentation’); $wp_admin_bar->remove_menu(‘support-forums’); $wp_admin_bar->remove_menu(‘feedback’); $wp_admin_bar->remove_menu(‘view-site’); } add_action( ‘wp_before_admin_bar_render’, ‘dashboard_tweaks’ ); Reference: http://pastebin.com/Wrk0JPxw
Remove Admin (User #1) from User list
function your_pre_user_query($user_search) { $user = wp_get_current_user(); if ($user->ID!=1) { global $wpdb; $user_search->query_where = str_replace(‘WHERE 1=1’, “WHERE 1=1 AND {$wpdb->users}.ID<>1”,$user_search->query_where); } } add_action(‘pre_user_query’,’your_pre_user_query’);
Easy to use & embed iFrame Shortcode
function GenerateIframe( $atts ) { extract( shortcode_atts( array( ‘href’ => ‘http://the-url’, ‘height’ => ‘550px’, ‘width’ => ‘600px’, ), $atts ) ); return ‘<iframe src=”‘.$href.'” width=”‘.$width.'” height=”‘.$height.'”> <p>Your Browser does not support Iframes.</p></iframe>’; } add_shortcode(‘iframe’, ‘GenerateIframe’); // how to use: [iframe href=”http://www.exmaple.com” height=”480″ width=”640″]
Make WordPress Editor Allow iFrames
// make TinyMCE allow iframes add_filter(‘tiny_mce_before_init’, create_function( ‘$a’, ‘$a[“extended_valid_elements”] = “iframe[id|class|title|style|align| frameborder|height|longdesc|marginheight|marginwidth|name|scrolling|src|width]”; return $a;’) );
Auto Include Google Analytics Code
Tested on: WordPress 3.1 RC3 I’ve been using this script on all of my sites since WordPress 2.3.0 … it just adds the standard Google tracking scripts to the footer. // Add Google Analytics Tracking Code function add_google_analytics() { ?> <script type=”text/javascript”> var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”); document.write(unescape(“%3Cscript src='” + […]
Display Specific Content only for logged in users
Tested on: WordPress 3.0.1 function content_only4logged_in($content) { // ALL LOGGED IN USERS if ( is_user_logged_in() && !is_null($content) && !is_feed() ) { return $content; } else { $content = wp_html_excerpt( $content, 80 ); $content .= ‘ …’; $content .= __( ‘Sorry, more of this content is only available for logged users.’, FB_TEXTDOMAIN ); return $content; } […]
Add parent page slug to body_class
/*************************************************************** * Function body_class_section * Add the top level page to the body class for coloured sections ***************************************************************/ add_filter(‘body_class’,’body_class_section’); function body_class_section($classes) { global $wpdb, $post; if (is_page()) { if ($post->post_parent) { $parent = end(get_post_ancestors($current_page_id)); } else { $parent = $post->ID; } $post_data = get_post($parent, ARRAY_A); $classes[] = ‘section-‘ . $post_data[‘post_name’]; } return $classes; } This […]
Only show posts and media of the logged-in Author & fix the post/media counts on the filter bars.
Tested on: WordPress 3.4.1 By default, WordPress allows Authors to see the titles of other users posts, unpublished drafts, and all media, even though they cannot be edited. Use this code to only allow posts and media of the currently logged in Author to be displayed. Unlike other solutions, this also fixes the post/media count […]