add_action with a class method is causing fatal errors
Try: <?php $class = new MyClass(); class MyClass { public function MyClass() { add_action(‘init’, array($this, ‘core’)); } public static function core() { echo “I never get to here”; } } ?>
Try: <?php $class = new MyClass(); class MyClass { public function MyClass() { add_action(‘init’, array($this, ‘core’)); } public static function core() { echo “I never get to here”; } } ?>
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
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’ ); }
The best way to solve this is to simplify your code. Right now, ScriptQueuer::QueueCss() is just a static method, and it is getting its data too late. You could use an immutable object instead and then just register one of its methods as callback. Example: class Enqueuer { private $stylesheets; public function __construct( ArrayObject $stylesheets … Read more
The earliest safe hook to get post information is the template_redirect hook. All the hooks in question runs before WordPress has setup postdata, so any post info are still unavailable at that point. The globals like $wp_query and $post will still contain no data, that is why your efforts returns nothing. EDIT Extra info as … Read more
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
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
As you haven’t stated what you are trying to achieve and have just mentioned you need to fetch associated data. You have two options to query your custom table: You need to do a custom query separately using the post id from the post object while iterating over the posts. Modify the joins of main … Read more
That would be: remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_title’, 5 ); You can read about it here: remove_action Codex
Yes, delete_expired_transients is a cron event that runs once per day and the function delete_expired_transients() is automatically called when the cron event runs — see wp-includes/default-filters.php. So you do not need to call the function manually like you did in your my_custom_fn() function. And if you use a plugin like WP Crontrol, you can easily … Read more