How to set custom cookies before output

Depends on whether or not you need to check against WordPress’ user authentication. If you need to know whether they’re a logged in user, hook onto ‘init’. Otherwise, the sooner the better. If it’s something that should fire on every page load, and only checks for existence of the cookie and doesn’t need to tap … Read more

Action hook on Edit custom post type?

register_post_type() has a registration option called ‘register_meta_box_cb’. Set that to a valid callback and it will call that function only when it is compiling the meta boxes for that post type’s edit screen. Something like this: register_post_type( ‘foo’, array( ‘public’ => true, ‘label’ => ‘foo’, ‘register_meta_box_cb’ => ‘bar’, )); function bar(){ add_meta_box(‘blah’, ‘blah’, /* etc … Read more

Add new column to sites page

here is a modified version of your class that should work: class Add_Blog_ID { public static function init() { $class = __CLASS__ ; if ( empty( $GLOBALS[ $class ] ) ) $GLOBALS[ $class ] = new $class; } public function __construct() { add_filter( ‘wpmu_blogs_columns’, array( $this, ‘get_id’ ) ); add_action( ‘manage_sites_custom_column’, array( $this, ‘add_columns’ ), … Read more

Perform action on WPMU blog deletion

Yes, inside /wp-admin/includes/ms.php there is the action hook delete_blog. This test prevents a blog deletion: add_action( ‘delete_blog’, ‘prevent_blog_delete_wpse_82961’, 10, 2 ); /** * @param int $blog_id Blog ID * @param bool $drop True if blog’s table should be dropped. Default is false. */ function prevent_blog_delete_wpse_82961( $blog_id, $drop ) { wp_die( ‘aborting delete_blog’ ); }

add_action in a function, is it possible?

If you want to find out whether you’re on a specific page, post, in a category archive, etc., then core has to offer Conditional Tags for this. If you want to hook a js-script definition, then a better way to do this is the following: // Assuming that you drop your js code into a … Read more

What is the earliest possible hook for safely using `is_front_page`?

The parse_query() method of the WP_Query class sets the variables on which the conditional tags are based. The parse_query hook are executed before returning from parse_query() method, variables are already set (eg. is_home, used by is_front_page()) and is_front_page() will work, but function that changes the current state can be hooked to parse_query (it’s still parse_query() … Read more