What is the hook for validation on activation and download/upgrade plugin from wordpress ?
for activation, it is used register_activation_hook..Before activate it ( on the process of activating the plugin ) i will do some checking/validation..
If the verification return false, what is the hook for deactivate plugin ?
In order to deactivate the plugin, the hook is: register_deactivation_hook
Related
I am trying to disable the Woocommerce Setup Wizard but not having any luck. On a WP MU install it asks users to install plugins which is not possible for subsites. And then it asks admins to choose a theme that’s located on wordpress.org so that installation is not possible either. I need to disable this wizard. I am using the code below but it does not work. I am still being redirected to the setup wizard when I go to Woocommerce>Dashboard.
add_filter( 'woocommerce_enable_setup_wizard', 'disable_wizard' );
function disable_wizard(){
return false;
}
This should prevent the wizard from triggering:
add_filter( 'woocommerce_prevent_automatic_wizard_redirect', '__return_true' );
If you want to allow WooCommerce to trigger the wizard later, you can enable it again:
add_filter( 'woocommerce_prevent_automatic_wizard_redirect', '__return_false' );
I am having very weird issue in my store. I get redirected to woocommerce setup wizard page when I try to open any page in admin panel.
I tried setting up woocommerce settings. I have gone through all the steps and at last I again get redurected to setup wizard.
when I deactivate woocommerce plugin it runs properly. But with woocommerce pplugin it redirects to woo setup wizard.
I found the tie breaking solution guys. It was like stuck on the same page.
I got a filter from woocommerce docs.
add_filter( 'woocommerce_prevent_automatic_wizard_redirect', 'wc_subscriber_auto_redirect', 20, 1 );
function wc_subscriber_auto_redirect( $boolean ) {
return true;
}
This stopped the redirection from admin panel to wc setup wizard.
There is few options why this might happen, but probalby Your browser do cache wp-admin panel url with WOO wizard redirection.
Frist try solution: Delete browser cache.
This is what I use to prevent redirection
add_filter( 'woocommerce_prevent_automatic_wizard_redirect', '__return_true' );
Imagine a simple plugin with the following code:
register_activation_hook(__FILE__, $this, 'on_plugin_activate');
public function on_plugin_activate(){
wp_redirect("https://www.google.com");
exit();
}
Will this cancel activation of the plugin?
Yes, this will not activate the plugin as before activate plugin process completes it will redirect to google.com
When I manually triggered WordPress auto update using the wp_maybe_auto_update()function, after the auto update process completes the plugins are getting deactivated.
I was experiencing the same problem, and digging into the code revealed the cause.
The Automatic_Upgrader uses the Plugin_Upgrader to update the plugins. The plugin upgrader has a method, deactivate_plugin_before_upgrade(), that is used to deactivate the plugin before upgrade, but only in specific cases. It contains these lines:
// When in cron (background updates) don't deactivate the plugin, as we require a browser to reactivate it
if ( wp_doing_cron() )
return $return;
So when the updates are being run by a cron job, the plugins don't get deactivated. The automatic updates normally are run via cron, and so the code has made an assumption that they always will be. If the automatic updates get triggered outside of cron (as when you are manually calling wp_maybe_auto_update(), then the plugins will get deactivated, but they won't automatically get reactivated.
One solution would be to trick the upgrader into thinking that cron was running, by hooking into the 'wp_doing_cron' filter before you call wp_maybe_auto_update():
add_filter( 'wp_doing_cron', '__return_true' );
wp_maybe_auto_update();
remove_filter( 'wp_doing_cron', '__return_true' );
I want to give some tips to the people that install my plugins. So after the installation of the plugin I want them to see an instruccion page, or go directly to the configuration of the plugin.
Any hook after the activation of the plugin where I can redirect to a page ?
I could use some flash message too for the same goal.
The register_activation_hook function registers a plugin function to be run when the plugin is activated.
register_activation_hook(__FILE__, 'redirect_to_instruction_page');
function redirect_to_instruction_page(){
wp_redirect( admin_url( 'admin.php?page=instructions' ) );
exit;
}