Custom page / message after installation of wordpress plugins - wordpress

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;
}

Related

How to disable Woocommerce Setup Wizard?

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' );

When I try to open admin panel it get redirected to woocommerce setup wizard

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' );

What happens if I redirect from a wordpress plugin activation hook?

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

wordpress plugin access file directly in browser

I am trying to access a plugin file directly in the browser, so i can run a cron.
When i go to the correct url, i am getting a page not found error.
Does wordpress by default prevent you from accessing this directly? Is it maybe something to do with the .htaccess, or should i be able to view this directly?
I am trying to access the file located like this (just an example):
http://mywebsite.com/wp-content/plugins/askimet/askimet.php
Any help would be greatly appreciated!
WordPress does not prevent you from accessing PHP files directly. However, the PHP files themselves usually do. This basically makes sure WordPress is loaded.
In your example, akismet.php has the following
// Make sure we don't expose any info if called directly
if ( !function_exists( 'add_action' ) ) {
echo 'Hi there! I\'m just a plugin, not much I can do when called directly.';
exit;
}
You probably do want WordPress to be loaded for your plugin, though.
Instead, you need to make your plugin know of a URL construct which you can detect and intercept. For example, say you visit the page example.org/?my-plugin-action. Your plugin should check for this on normal page requests (such as init or template_redirect) and if it is found, call your PHP script, then call exit; so WordPress does not try to load a page.
function my_plugin_action() {
if ( !isset($_GET['my-plugin-action']) ) return;
echo 'Run cron task here.';
exit;
}
add_action( 'init', 'my_plugin_action' );
To recap: Don't call your plugin directly. Make a URL that displays your content, then exit the script before WordPress tries to display the default page.
There is no such restriction by default in WordPress. You can access a file directly in WordPress if you want to.
See if the file code contains something like below -
if ( ! defined( 'ABSPATH' ) )
//some action if accessed directly
Otherwise, check back the URL and make sure your path is correct.
One more thing, if you will access the plugin file directly and it contains any WordPress core function, it will give error since in that case, WordPress core doesn't get loaded.
However, there are some non recommended ways to load WordPress core.

Wordpress hook action

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

Resources