Making an add_filter() call from within an add_filter() call

You can add or remove hooks from inside other hooks if you get the timing right but I don’t understand why you are making this so complex. function set_title($title) { global $wp_query,$post,$address; $address = $wp_query->query_vars[‘address’]; if ($address) { return $address; } } add_filter(‘wp_title’, ‘set_title’); If you need the share the value, use a static variable: … Read more

What hook can I use to modify custom post data before it is displayed on the page?

You can use the_content filter to modify content before it’s output. function my_the_content_filter( $content ) { // maybe limit to archive or single cpt display? if( is_post_type_archive( ‘your-cpt’ ) || is_singular( ‘your-cpt’ ) ){ global $post; $meta = get_post_meta( $post->ID, ‘some-key’, true ); if( false === $meta ){ return $content . ‘some extra content’; } … Read more

What is the action or filter for adding information under the Permalink in Edit Post/Page?

You can try the edit_form_after_title action: add_action( ‘edit_form_after_title’, function(){ echo ‘<hr/><div>My custom HTML</div><hr/>’; }); to add your custom HTML after the permalink: It will inject the HTML between div#titlediv and div#postdivrich: <div id=”post-body-content”> <div id=”titlediv”>…<!– /titlediv –> <hr><div>My custom HTML</div><hr> <div id=”postdivrich” class=”postarea edit-form-section”>…</div> … </div> Tip: when you have question like this, best thing … Read more

How to use add_action for multiple instances of the same class

When you call add_meta_box() you must provide a unique ID as the first parameter. Consider this case: add_meta_box( ‘foobox’, ‘Foo Title’, ‘foo_callback’ ); add_meta_box( ‘foobox’, ‘Bar Title’, ‘bar_callback’ ); You will just get the Bar Title metabox now, because it will overwrite the first one. What you need is a new ID for each box: … Read more

Adding custom Bulk Actions

Unfortunately it’s still not really doable in a clean way. You can see the latest about this here in this trac ticket #16031 I just checked the source and the filter is still basically the same.

Action inside another action not working

I think I worked out the problem. before_wp_tiny_mce_action is not an action hook called before the actual TinyMCE editor in the DOM. It is called before the script that is loaded via the admin_print_footer_scripts action. So I think the admin_footer action hook is before the before_wp_tiny_mce_action action hook so I am calling my action too … Read more

How can I get the user that publishes a post?

I am not sure if that is built in, but you can try adding something like this to your functions.php function set_publisher( $new_status, $old_status, $post ) { $publisher_id = get_current_user_id(); if ( $new_status == ‘publish’ && $publisher_id > 0) { update_post_meta($post->ID, ‘post_publisher’, $publisher_id); } } add_action( ‘transition_post_status’, ‘set_publisher’, 10, 3 ); And then when you … Read more