Hooking in to an archive page?

Use archive_template filter in your plugin to override archive templates for a given post type, for example, movies: <?php function get_movies_archive_template( $archive_template ) { if ( is_post_type_archive ( ‘movies’ ) ) { $archive_template = dirname( __FILE__ ) . ‘/templates/movies-archive-template.php’; } return $archive_template; } add_filter( ‘archive_template’, ‘get_movies_archive_template’ ) ; See archive_template in Codex.

Storing state between hook functions

Uing OOP for your plugin it’s very easy. class MyPlugin { static $flag; static function function_a() { self::$flag = ‘a value’; } static function function_b() { if ( ! is_null(self::$flag) ) echo self::$flag; // echo ‘A Value’; } } add_action(‘plugins_loaded’, array(‘MyPlugin’, ‘function_a’) ); add_action(‘init’, array(‘MyPlugin’, ‘function_b’) ); Not using OOP you can use global variables. … Read more

Set the default category of an attachment

To solve the problem 1, you could hook to add_attachment and edit_attachment hook. add_action(‘add_attachment’, ‘wpse_set_attachment_category’); add_action(‘edit_attachment’, ‘wpse_set_attachment_category’); function wpse_set_attachment_category( $post_ID ) { // if attachment already have categories, stop here if( wp_get_object_terms( $post_ID, ‘category’ ) ) return; // no, then get the default one $post_category = array( get_option(‘default_category’) ); // then set category if default … Read more

How to find a callback attached to a bbpress hook?

To find an attached callback, you normally can just do the following: printf( ‘<pre>%s</pre>’, var_export( $GLOBALS[‘wp_filter’][‘hook_name’], TRUE ) ); This should give you back an array of callbacks attached to a hook, ordered by priority (which serves as key).

How to hook in after user’s registration email has been sent?

I would use the registration_redirect filter. This allows you to set where the user is sent to, but leaves WordPress to perform the redirect (after everything has successfully processed). function wpse_139267_registration_redirect( $url ) { return site_url( ‘thank-you’ ); } add_filter( ‘registration_redirect’, ‘wpse_139267_registration_redirect’ );

Plugin activation hook in an abstract class

The best way to get around this problem is not creating that abstract class. Never combine object creation with business logic in the same class. This is called a statically linked dependency and usually a flawed design, because you cannot change it on runtime (for tests or per hooks, for example). Avoid inheritance. Separation of … Read more