$GLOBALS[‘hook_suffix’] variable empty

I thing you are missing the context. $GLOBALS[‘hook_suffix’] is available on any action fired after admin_init. Now, if you tried something like add_action( ‘admin_footer-‘. $GLOBALS[‘hook_suffix’], ‘myfunction’ ) outside of any function, you are not going to get anything. But if you do it – add_action(‘admin_menu’, ‘do_hook_to_footer’) and put the earlier hook within the do_hook_to_footer function, … Read more

How do I add Bootstrap and LESS to my migrated WordPress site?

You don’t need to create additional functions, just re-use what you already have and tweak it a bit: function theme_add_bootstrap() { wp_enqueue_style( ‘bootstrap-css’, get_template_directory_uri() . ‘/third_party/bootstrap/css/bootstrap.min.css’ ); wp_enqueue_script( ‘bootstrap-js’, get_template_directory_uri() . ‘/third_party/bootstrap/js/bootstrap.min.js’, array(), ‘3.0.0’, true ); if (WP_ENV === ‘development’) { wp_enqueue_script( ‘lesscss’, get_stylesheet_directory_uri() . ‘/third_party/less-1.5.0.min.js’ ); wp_enqueue_style( ‘style-less’, get_template_directory_uri() . ‘/css/custom.less’ ); } else … Read more

Is it acceptable to treat a filter like an action?

All actions are actually filters internally. So yes, you can do things in a filter hook. However, be mindful of which filters and what you’re doing. Some filters are ran everywhere, and doing expensive operations on them may lead to massive slowdowns. Also beware of recursion. If your expensive operation triggers the very filter you’ve … Read more

Any hook for pre-plugin-update -either bulk or single plugin update

Here are two untested ideas: Idea #1: If you want to hook before an instance of the Plugin_Upgrader class is created with: $upgrader = new Plugin_Upgrader( … ) where the upgrades are activated with: $upgrader->upgrade($plugin); // for a single plugin upgrade $upgrader->bulk_upgrade( $plugins ); // for bulk plugins upgrades then you could try: /** * … Read more

add_action and remove_action if custom field exists

I’m not clear on how your code works as-is, as I mentioned in my comment. It looks like you’re adding an action to call a function inside the function that you want to call with that action. If nothing outside the function invokes it, it never runs. add_action( ‘template_redirect’, ‘check_breadcrumb_condition’ ); function check_breadcrumb_condition(){ global $post; … Read more

Are there actions or filters I can use for Ajax calls?

If you check the source for admin-ajax.php you will notice that the admin_init hook fires and that the system checks $_REQUEST[‘action’] for hooks. Given that, you could hook to admin_init, check the “request” super global, construct wp_ajax_* and wp_ajax_nopriv_* values, then use has_action() to see if anything is hooked in.

Don’t delete a page if it holds users

It gives an array with objects. So in_array() won’t find anything, you have to convert it before. After you get the results from wbdb: $employees_array = array(); foreach($employees as $employee) { $employees_array[] = $employee->meta_value; } if(in_array($company, $employees_array)) { … }

Automatically add attributes to woocommerce product?

add_action( ‘save_post_product’, ‘create_product’, 10 ); function create_product( $post_id, $post) { // $post_id and $post are required if ( empty( $post_id ) || empty( $post ) ) { return; } // Dont’ save meta boxes for revisions or autosaves if ( defined( ‘DOING_AUTOSAVE’ ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) … Read more

Adding the hook ‘vc_before_init’ inside a object

I found the solution… First I thought the problem had something to do with wrapping the hook inside a class.. But after some more testing (sometimes you need to take a step back), it appears the hook vc_before_init has already fired on the init hook with the (default) priority of 10… My current theme (Salient) … Read more

Custom post type unintentionally called in every page

Custom post-type and taxonomy definitions are not saved to the database, and so registering them only makes WordPress “aware” of their existence for that page request. As custom post-type/taxonomy registration does not require database interaction, the performance impact is negligible. I’ve never actually seen any applications that selectively register CPTs/taxonomies (though I’m sure they’re out … Read more