Removing action added by a plugin in Wordpress - wordpress

I am using Popup Maker plugin for Wordpress and I am trying to prevent it to load on a particular page using the functions.php file of a child theme.
I've located in the plugin's directory the file popup-maker.php which contains the following line at the end:
add_action( 'plugins_loaded', 'popmake_initialize', 0 );
If I remove / comment this line, the popup will not fire, so I guess this is the action I need to remove. I have read the WP codex and numerous posts but still can't get it to work.
Right now I am stuck at this (function I have added in my child theme's functions.php file):
function remove_popmaker() {
remove_action('plugins_loaded', 'popmake_initialize', 0);
}
add_action( 'init', 'remove_popmaker', 1 );
PS: I am using shopkeeper theme and Woocommerce.
All help appreciated, thanks.

you are adding a action to init which is after plugins_loaded so you cannot remove a action after it has run.
you can try the same action but you will have to do this from a plugin
remove_action( 'plugins_loaded', 'remove_popmaker', 0 );
But i suspect actions added before yours will be run after, this may be unpredictable if not you may have to code a MUplugin (google this).

There is a way I managed to do this:
add_action('wp', 'disableEmailPopup');
function disableEmailPopup () {
global $post;
if ($post->ID === 11625249) return remove_action( 'wp_enqueue_scripts', 'popmake_load_site_scripts');
}

#BMM - Without knowing the use case as to why you need to disable the entire plugin on one page its hard to give you the best answer.
For example if you simply wanted a single popup to not show on one page you can use the conditions panel to add a negative condition using the (!) button. Click it to turn it red and you will check for the opposite of a condition, so (!) Page Selected: Page xyz would prevent it from loading on that page.
Alternatively you can create your own custom conditions allowing you to add that condition to any popup.
Lastly if you wanted to unhook it just from the front end you can simply remove the rendering & script handlers
remove_action( 'wp_footer', 'popmake_render_popups', 1 );
remove_action( 'wp_head', 'popmake_script_loading_enabled' );
And if you want to prevent the queries as well
remove_action( 'wp_enqueue_scripts', 'popmake_preload_popups', 11 );
Hope that helps.

Related

remove_action is not working for me to remove a theme's action..?

I'm running WordPress + WooCommerce + Storefront. I'm trying to remove the "Built with Storefront & WooCommerce" credit in the footer.
I see lots of articles explaining how to do that by using remove_action as follows:
remove_action('storefront_footer', 'storefront_credit',20);
This is not working, though. I've tried it through a Snippets plugin, and I've tried it through the functions.php in my child theme.
I've also verified that nothing seems to have changed in the theme code since these articles were written, so it has the same function and hook names.
I'm not sure what I'm missing here..?? Any information on this would be greatly appreciated. Thanks!
In order to remove the action you must be sure to remove it before it's added. This is a parent theme's hook, so if you remove_action from the child theme or via code Snippets, it's already too late.
Unless... you make the remove_action trigger earlier, by hooking that to "wp" WordPress action.
Try with:
add_action( 'wp', 'bbloomer_remove_storefront_actions' );
function bbloomer_remove_storefront_actions() {
remove_action( 'storefront_footer', 'storefront_credit', 20 );
}
Another cool thing you can do to absolutely make sure you can remove an action is by using the same hook, but with a lower priority:
add_action( 'storefront_footer', 'bbloomer_remove_storefront_actions', 19 );
function bbloomer_remove_storefront_actions() {
remove_action( 'storefront_footer', 'storefront_credit', 20 );
}
In this example, I'm removing 'storefront_credit' which has priority = 20 by hooking into the same hook, with priority 19, so that I remove it before it's added.

storefront_sticky_add_to_cart refuses to be removed

Almost finished my WooCommerce Storefront child theme.
There's a block sitting under the footer on the product pages that I have zero desire to keep. Just as I've done with a few other extraneous pieces of markup, I tracked down the action and removed it:
remove_action( 'storefront_after_footer', 'storefront_sticky_single_add_to_cart');
... It is still showing in the page.
I've even tried some random things I found:
add_filter ('storefront_sticky_add_to_cart', '__return_false');
and
function cleanup_parent_filters()
{
//...
remove_action( 'storefront_after_footer', 'storefront_sticky_single_add_to_cart');
}
add_action( 'wp_loaded', 'cleanup_parent_filters');
With no results.
This is really more annoying than anything. I can remove the entire do_action( 'storefront_after_footer' ); from the template as I really just don't care to have it there, but now I need to know why this is not working as expected out of principle.
try
remove_action( 'storefront_after_footer',
'storefront_sticky_single_add_to_cart', 999 );
remove_action needs the priority value as it was used to add the action. From the Docs
Important: To remove a hook, the $function_to_remove and $priority
arguments must match when the hook was added. This goes for both
filters and actions. No warning will be given on removal failure.
And why 999? From the source code.
Disclaimer: I haven't tested this out.

How to safely remove an action hook in child-theme?

I am working on a WordPress installation called PointFinder. Items that are posted by users get deleted after some pre-defined period. My goal is to disable this behaviour. I already found the corresponding code lines and deactivated the add_action hook that triggers the periodically called function pointfinder_clean_pending_orders() in schedule-config.php, which works fine for the moment.
add_action( 'pointfinder_schedule_hooks_hourly', 'pointfinder_clean_pending_orders' ); // <--- commented out this line
function pointfinder_clean_pending_orders() {
/* code that cleans-up ... */
}
How can I achieve the deactivation in my child-theme ? If I simply add a remove_action to functions.php in my child-theme, will that work? I am not sure what will be called first, add_action in schedule-config.php or my remove_action in functions.php ?
I only have access to the productive server and no testing environment and thus I am a bit reluctant regarding experiments.
try this:
add_action('init','remove_hourly_hook');
function remove_hourly_hook() {
remove_action( 'pointfinder_schedule_hooks_hourly', 'pointfinder_clean_pending_orders' );
}
What this does is after WordPress is initialized (regardless of the order of functions.php being called), it will then remove the action.
Now, if the initial add_action is inside a its own hook, you will want to make sure your hook 'init' is changed to occur afterwards.

Remove ratings from output tab and add it in after product summary

I'm using an already purchased wordpress theme. The rating tab is located under "woocommerce_output_product_data_tabs". I already know how to unset it from the output tabs but I don't know how to add it in "woocommerce_after_single_product_summary". Did you do something similar to this?
Firstly, create a Child Theme so that your modifications do not get overridden when any Theme Updates are released.
Head into your functions.php, in your Parent Theme, and locate the function entry for your Ratings Tab. Copy this coding into the functions.php file, within your Child Theme.
Within the add_action entry, you will need to change the code as follows:
add_action('woocommerce_after_single_product_summary', 'THIS_NEEDS_TO_BE_THE_SAME_AS_THE_FUNCTION_NAME');
Hope this helps.
Try This
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10, 2 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
function woocommerce_template_single_rating( $woocommerce_template_single_title, $int ) {
// make action magic happen here...
};

NextGen Gallery issues with Iframe plugins

I have tried few iframe based popup plugins with WordPress Nextgen gallery. It always generates a js error from frame_event_publisher.js file.
Is there anyway to prevent the loading of this file within another plugin?
One way to fix it is to forcibly dequeue the script. You'll have to add a condition to dequeue it only when needed since NextGEN probably needs this script to work.
add_action( 'wp_print_scripts', 'dequeue_frame_event_publisher', 100 );
function dequeue_frame_event_publisher() {
if ( is_admin() ) { // Add another condition to check if in an iframe.
wp_dequeue_script( 'frame_event_publisher' );
}
}

Resources