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

Are there any hooks that alter the 404 logic?

After a bit more slogging through code and Googling, I found the answer. It’s contained in this thread (see Otto42’s post), but for the record, adding the following to your plugin will override the 404 handling for the conditions you specify: add_filter(‘template_redirect’, ‘my_404_override’ ); function my_404_override() { global $wp_query; if (<some condition is met>) { … Read more

How to know what functions are hooked to an action/filter?

Look into the global variable $wp_filter. See my plugin for a list of all comment filters for an example: <?php /* Plugin Name: List Comment Filters Description: List all comment filters on wp_footer Version: 1.1 Author: Fuxia Scholz License: GPL v2 */ add_action( ‘wp_footer’, ‘list_comment_filters’ ); function list_comment_filters() { global $wp_filter; $comment_filters = array (); … Read more