What is the criteria for pluggable functions?

Pluggable functions are less elastic than filters/actions. You can have only one pluggable function “active” – so only one plugin can override the core function. And you don’t have much control over which plugin will it be (WP will use the pluggable function that gets defined first). So it won’t be very useful if all … Read more

What is the $context in remove_meta_box function?

The context within the screen IS where the boxes should display. Available contexts vary from screen to screen. Post edit screen contexts include ‘normal’, ‘side’, and ‘advanced’. Comments screen contexts include ‘normal’ and ‘side’. Menus meta boxes (accordion sections) all use the ‘side’ context. Global default is ‘advanced’. So it is the place you are … Read more

Properly applying nonce to a form using AJAX

You just need to send the nonce along with your AJAX data: $.ajax({ type: ‘POST’, url : profile_edit.ajaxurl, data: $(‘#profile_update’).serialize() + ‘&my_nonce=” + profile_edit.nonce + “&action=update_profile_post’, // don’t forget the action name! }); Alternatively, since you’re using jQuery’s serialize() function, you could just add the nonce directly in the form: <?php wp_nonce_field( ‘update_profile_validation’, ‘my_nonce’ ); … Read more

Can I pass two roles to the function get_users?

I don’t think it’s possible to do it with the get_users function. From what the Codex implies, you cannot pass arrays to the role argument. But it should be fairly easy to code your way out of that limitation. Try this: function filter_two_roles($user) { $roles = array(‘academic’,’student’); return in_array($user->roles[0], $roles); } $users = get_users(‘fields=all_with_meta’); // … Read more

Setting featured image with function, 1 part not working

You have to set the $single paramter of get_post_meta to false (or don’t set it) to get an array. Here is a sped-up version: if ($attachment_id = get_post_meta($post_id, ‘featured_image’, true)) : elseif ($attachment_id = get_post_meta($post_id, ‘upload_single_image’, true)) : elseif ($attachment_id = get_post_meta($post_id, ‘create_gallery’, false)) : $attachment_id = $attachment_id[0][‘upload_image’]; endif; Note: I did not test this. … Read more

Exclude Empty Child Categories in Menu

I would go about this slightly differently. Still using the wp_get_nav_menu_items filter, but first I’ll build an array containing the IDs of all empty terms. Then I’ll compare each of the $items to this for potential exclusion: add_filter( ‘wp_get_nav_menu_items’, ‘wpse177082’, 10, 3 ); function wpse177082 ( $items, $menu, $args ) { global $wpdb; $empty = … Read more