I would like to use create a function in my custom plugin to tell WP to use a different header

I am not sure what you want to do is doable (seems impossible to me but everything seems impossible until someone does it). I thought of a very ugly workaround. add_filter( ‘template_include’, function( $template ) { $temp = get_temp_dir() . basename( $template ); file_put_contents( $temp, str_replace( ‘get_header(‘, ‘get_header2(‘, file_get_contents( $template ) ) ); return $temp; … Read more

What is the Javascript event for an item being added to the cart in Woocommerce?

Read the source. From woocommerce-ajax.php (in the plugin’s root folder) Javascript/Ajax add to cart /** * AJAX add to cart * * @access public * @return void */ function woocommerce_ajax_add_to_cart() { global $woocommerce; check_ajax_referer( ‘add-to-cart’, ‘security’ ); $product_id = (int) apply_filters(‘woocommerce_add_to_cart_product_id’, $_POST[‘product_id’]); $passed_validation = apply_filters(‘woocommerce_add_to_cart_validation’, true, $product_id, 1); if ($passed_validation && $woocommerce->cart->add_to_cart($product_id, 1)) : // … Read more

What is the purpose of $merged_filters?

For those of you who may be wondering what this does – I have figured it out. When a new function is added to an action/filter hook, it is added at the end of the array. However, WordPress specifies that those functions are to be executed by priority. When a function is added, merged_filters is … Read more

I need some direction on how to have a sidebar based on meta rather than page

Create a sidebar $type . ‘_sidebar’ Register the sidebar $type . ‘_sidebar’ (e.g dog_sidebar) Pass the type as GET argument to the widget.php (create some menu entries or something else where you link to e.g. wp-admin/widgets.php?sidebar_type=dog_sidebar) Filter out every sidebar that should not be displayed. You can use this function: global $wp_registered_sidebars; $type =filter_input( INPUT_GET, … Read more

Using has_filter with a class based plugin to check whether the plugin is active or not

To do literally what you’re wanting here, the easiest way is to store the instance of the plugin class in a global variable at the end of your plugin: class My_Plugin { static $instance; function __construct(){} /* or private, with singleton get_instance() method */ function setup(){ … } } $my_plugin_instance = new My_Plugin(); add_action( ‘plugins_loaded’, … Read more