I want to remind to my plugin users that the plugin is enabled but only on product
page (dashboard), i've came across the $pagenow
global variable:
global $pagenow;
$pagenow != 'post.php'; // This will be shown on "normal posts" too
How can i add a notice alert only on product page? This is what i have at the moment:
add_action('admin_notices', function () {
if (!is_admin()) {
return;
}
$title = __e('Your plugin is enabled');
$div = '<div class="notice notice-info is-dismissible"><p>%s</p></div>';
$pluginPath = 'path-to/my-plugin.php';
if (is_plugin_active($pluginPath)) {
echo sprintf($div, $title);
}
});
I want to remind to my plugin users that the plugin is enabled but only on product
page (dashboard), i've came across the $pagenow
global variable:
global $pagenow;
$pagenow != 'post.php'; // This will be shown on "normal posts" too
How can i add a notice alert only on product page? This is what i have at the moment:
add_action('admin_notices', function () {
if (!is_admin()) {
return;
}
$title = __e('Your plugin is enabled');
$div = '<div class="notice notice-info is-dismissible"><p>%s</p></div>';
$pluginPath = 'path-to/my-plugin.php';
if (is_plugin_active($pluginPath)) {
echo sprintf($div, $title);
}
});
Share
Improve this question
asked May 14, 2020 at 22:27
RFLRFL
731 silver badge8 bronze badges
3
|
1 Answer
Reset to default 1If you're on wp-admin/post.php, you've got either
global $post_type
- or possibly
$_POST['post_type']
, if we don't have a post ID to look up the type from
that you can test for 'product'. See the first 50 lines of wp-admin/post.php.
As an aside, I don't think you need to check for is_admin in a admin_init handler; nor do you need to check if your plugin is enabled if this code is in the same plugin, since it won't be run unless the plugin is enabled. Unless you're testing for a different plugin that is.
post_type=product
query string parameter that you can test for too? – Rup Commented May 14, 2020 at 22:33?post_type=product
query string – RFL Commented May 14, 2020 at 23:09