How many times can I hook into the same action?

WordPress hooks work like Hollywood: you don’t call them, they call you. But unlike Hollywood, they keep calling everyone on the list. It’s normal for an action or a filter to have multiple functions hooked to it, from different plugins, or even just different functions in the WordPress core that all do something specific. It … Read more

Use wp init hook to call other hooks?

In general: Yes, wait for a dedicated hook to start your own code. Never just throw an object instance into the global namespace. But init is rarely necessary. You hook in as late as possible. If your first code runs on wp_head do not use an earlier hook. You can even cascade hooks: add_action( ‘wp_head’, … Read more

get $post in init filter or action?

Turns out the answer was simply to use url_to_postid like this: $keyword = get_post_meta( url_to_postid( “http://”.$_SERVER[‘SERVER_NAME’].$_SERVER[‘REQUEST_URI’] ), ‘_wpg_def_keyword’, true ); Works perfectly even from init.

Why do some hooks not work inside class context?

Sometimes certain hooks need to be fired at certain times. Example, some hooks need to be fired upon init. Add this to your __construct() add_action(‘init’, array(&$this, ‘init’)); Then add this function, which will contain all hooks that need to be fired upon init. public function init(){ add_action(‘hook_name’, array(&$this, ‘your_method_name’)); add_action(‘hook_name’, array(&$this, ‘your_method_name’)); add_action(‘hook_name’, array(&$this, ‘your_method_name’)); … Read more

WooCommerce: change display order of product short description and price [closed]

If you look at woocommerce/templates/content-single-product.php you’ll see that the product summary is constructed using hooks with different priorities. Here’s the relevant section: <?php /** * woocommerce_single_product_summary hook * * @hooked woocommerce_template_single_title – 5 * @hooked woocommerce_template_single_rating – 10 * @hooked woocommerce_template_single_price – 10 * @hooked woocommerce_template_single_excerpt – 20 * @hooked woocommerce_template_single_add_to_cart – 30 * @hooked … Read more

WP Cron Doesn’t Execute When Time Elapses

First can you please confirm that you don’t have any caching plugins enabled? Caching plugins can interfere with cron jobs because your visitors are not served a live page but a cached version of your page. If you have a caching plugin enabled, you can choose one of your pages, add an exclussion to your … Read more

Difference between do_action and add_action

Use do_action( ‘unique_name’ ) to create your own actions. You can use that to offer an API for your plugin, so other plugins can register callbacks for your custom action. Example: Do I need to call do_action in my plugin? But you can use custom actions (or filters) in a theme too. Example: Best practice … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)