Odd map_meta_cap $args on post edit — sometimes integer, sometimes string

The map_meta_cap function handles context arguments generically – you can give it anything and it’ll happily pass it down the chain. It’s only particular capabilities like edit_post that expect the argument to be an integer, but even then it’s up to the caller to pass an appropriate value. Here’s where you get your string/integer mashups … Read more

How to replace default comments with custom HTML?

Note that with the following: add_filter (‘comments_template’, ‘fbcommentbox’, 100); we expect fbcommentbox() to return the path to the new comments template file. The default is the path of comments.php. If you create the fbcommentbox.php file in your theme, then you could try: add_filter( ‘comments_template’, ‘fbcommentbox’, 100); function fbcommentbox( $theme_template ) { // Path to our … Read more

How can I check user capability when a page loads (via functions.php)?

If you want to redirect, a good event to use is template_redirect: add_action( ‘template_redirect’, ‘my_page_template_redirect’ ); function my_page_template_redirect() { // You can skip is_user_logged_in() if checking the user capability if( is_page( 1234 ) && ! current_user_can( ‘do_something_special’ ) ) { $redirect_to = ‘http://example.com/redirection-page’; // Default code status for redirection using wp_redirect is 302 // If … Read more

Adding bootstrap classes to video shortcodes

This is how I bootstrapped youtube embeds in one of my projects. /** * Responsive Youtube embeds. */ add_filter( ’embed_oembed_html’, function( $html, $url, $attr, $post_ID ) { if ( false !== stripos( $html, ‘<iframe ‘ ) && false !== stripos( $html, ‘.youtube.com/embed’ ) ) { $html = sprintf(‘<div class=”embed-responsive embed-responsive-16by9″>%s</div>’, $html ); } return $html; … Read more

After plugin activation hook

In the context of official plugin repository this is very explicitly forbidden by the guidelines (emphasis mine): 7. No “phoning home” without user’s informed consent. This seemingly simple rule actually covers several different aspects: No unauthorized collection of user data. For example, sending the admin’s email address back to your own servers without permission of … Read more