Adding option to Gallery shortcode

This code should work in your functions.php add_shortcode(‘gallery’, ‘custom_gallery_function’); function custom_gallery_function($atts) { $user = wp_get_current_user(); // if current user isn’t admin, add posts to be hidden to exclude if(!in_array(‘administrator’, $user->roles)) $atts[‘exclude’] = $atts[‘exclude’] . ‘,’ . $atts[‘hide’]; // call the wordpress shortcode function return gallery_shortcode($atts); }

How to Add Custom CSS to the Media Thickbox?

In WordPress 3.5, this hook works for me: add_action( ‘print_media_templates’, ‘wpse_75746_print_style_35’ ); function wpse_75746_print_style_35() { ?> <style> .media-modal-content, .media-sidebar { background: #FFF2D4 !important; } </style> <?php } In 3.4.2, this is the one: add_action( ‘admin_print_styles-media-upload-popup’, ‘wpse_75746_print_style_342’ ); function wpse_75746_print_style_342() { ?> <style> #media-upload { background: #FFF2D4 !important; } </style> <?php }

Conditional hook based on the core function that is calling it

Much probably, using debug_backtrace in this fashion is wild hackerism… Based on @toscho’s tip, the following achieves the same results: add_filter( ‘get_blogs_of_user’, ‘reorder_users_sites’ ); function reorder_users_sites( $blogs ) { if( !did_action( ‘wp_before_admin_bar_render’ ) ) uasort( $blogs, ‘bf_uasort_by_blogname’ ); else uasort( $blogs, ‘bf_uasort_by_domain’ ); return $blogs; }

Implement Hooks Using Array

What’s wrong with good old do_action? 😉 You could write a simple wrapper: function wpse81578_hook( $hook ) { do_action( $hook ); } If you’re looking for something dynamic, take a look at the do_atomic function of the Hybrid theme framework: it “adds contextual action hooks to the theme. This allows users to easily add context-based … Read more

How to modify post content?

You might check out the content_edit_pre filter. Your example would then look like this: function wpse89725_pre_edit_content( $content, $post_id ) { $content = “nothing”; return $content; } add_filter( ‘content_edit_pre’, ‘wpse89725_pre_edit_content’, 10, 2 ); You can read more about this filter in the Codex: https://codex.wordpress.org/Plugin_API/Filter_Reference/content_edit_pre Edit: You can also try the edit_post_content filter: add_filter( ‘edit_post_content’, ‘my_pre_edit_content’, 10, … Read more

ajax, right way to do it and make it works?

In your functions.php file you should add an action to enqueue your scripts. <?php function my_enqueue_scripts() { wp_enqueue_script( ‘load_post’, get_template_directory_uri() . ‘/js/load_post.js’, array( ‘jquery’ ), ‘1.0’, 1 ); wp_localize_script( ‘load_post’, ‘wp_ajax’, array( ‘url’ => admin_url( ‘admin-ajax.php’ ), ‘nonce’ => wp_create_nonce( ‘ajax_nonce’ ) ) ); } add_action( ‘wp_enqueue_scripts’, ‘my_enqueue_scripts’ );

Capture post content before page renders

WordPress does not concatenate the entire page into a string before printing it which is what would have to happen to “capture” the whole page template. Much of the page echos as it occurs– think about template tags like the_content and the_title which don’t return strings. The just echo them. You’d have to use output … Read more

Post Content, Special Characters and Filters

Using a snippet of code like this: $hook_name=”the_content”; global $wp_filter; var_dump($wp_filter[$hook_name]); I was able to find a list of all hooked callback functions to the WordPress filter: the_content. I then located a few possible culprits, then searched for their function existence. After narrowing down my list, I came to the conclusion on the hooked callback … Read more