admin管理员组文章数量:1130349
I believe i have to add this to my plugin to redirect after plugin activation
as per
register_activation_hook(__FILE__, 'nht_plugin_activate');
add_action('admin_init', 'nht_plugin_redirect');
function nht_plugin_activate() {
add_option('nht_plugin_do_activation_redirect', true);
}
function nht_plugin_redirect() {
if (get_option('nht_plugin_do_activation_redirect', false)) {
delete_option('nht_plugin_do_activation_redirect');
if(!isset($_GET['activate-multi']))
{
wp_redirect("edit.php?post_type=headline&page=news-headline");
}
}
}
But what is plugin prefix nht ? How can i make my plugin to work redirect after plugin activation what are things to be updates?
I believe i have to add this to my plugin to redirect after plugin activation
as per https://wordpress.stackexchange/a/178504/145078
register_activation_hook(__FILE__, 'nht_plugin_activate');
add_action('admin_init', 'nht_plugin_redirect');
function nht_plugin_activate() {
add_option('nht_plugin_do_activation_redirect', true);
}
function nht_plugin_redirect() {
if (get_option('nht_plugin_do_activation_redirect', false)) {
delete_option('nht_plugin_do_activation_redirect');
if(!isset($_GET['activate-multi']))
{
wp_redirect("edit.php?post_type=headline&page=news-headline");
}
}
}
But what is plugin prefix nht ? How can i make my plugin to work redirect after plugin activation what are things to be updates?
Share Improve this question asked Nov 15, 2018 at 19:50 user145078user145078 5- 1 "nht_" is the prefix. You should replace that with your own. Prefixes are just to make a function name unique to avoid namespace collisions. Since that's the prefix of someone else's plugin, it would be unwise to use it with exactly the same name as the function would already be defined. – butlerblog Commented Nov 15, 2018 at 21:23
- @butlerblog oh okay then it does not seems to work for me – user145078 Commented Nov 16, 2018 at 7:52
- If it worked without changing it, it will work if you change it - there would be no difference. Just make sure you change the function names both where they are defined AND in the hook. – butlerblog Commented Nov 16, 2018 at 13:02
- @butlerblog yeah i understand that ..the code does not seems to work – user145078 Commented Nov 16, 2018 at 13:09
- @butlerblog my mistake , the code was not getting updated that's why it did n't worked ..please make it as answer .thanks :) – user145078 Commented Nov 16, 2018 at 13:23
1 Answer
Reset to default 0In this case, "nht_" is a prefix to avoid naming collisions with similar functions. This is a "best practice" to observe when doing your own development.
So if you're developing something that would be distributed publicly, you should be the habit of applying your own prefix to your function names; and since this particular code snippet is something from another person/plugin, it's definitely a good idea to replace it with your own. So change "nht_" to something that you would use as a prefix:
register_activation_hook(__FILE__, 'my_custom_prefix_plugin_activate');
add_action('admin_init', 'my_custom_prefix_plugin_redirect');
function my_custom_prefix_plugin_activate() {
add_option('my_custom_prefix_plugin_do_activation_redirect', true);
}
function my_custom_prefix_plugin_redirect() {
if (get_option('my_custom_prefix_plugin_do_activation_redirect', false)) {
delete_option('my_custom_prefix_plugin_do_activation_redirect');
if(!isset($_GET['activate-multi'])) {
wp_redirect("edit.php?post_type=headline&page=news-headline");
}
}
}
I applied "my_custom_prefix_" in your code where appropriate as an example. Note this not only included function names, but also the wp_option that the setting is saved under. But you would want to change it to something that suits you and/or your plugin.
I believe i have to add this to my plugin to redirect after plugin activation
as per
register_activation_hook(__FILE__, 'nht_plugin_activate');
add_action('admin_init', 'nht_plugin_redirect');
function nht_plugin_activate() {
add_option('nht_plugin_do_activation_redirect', true);
}
function nht_plugin_redirect() {
if (get_option('nht_plugin_do_activation_redirect', false)) {
delete_option('nht_plugin_do_activation_redirect');
if(!isset($_GET['activate-multi']))
{
wp_redirect("edit.php?post_type=headline&page=news-headline");
}
}
}
But what is plugin prefix nht ? How can i make my plugin to work redirect after plugin activation what are things to be updates?
I believe i have to add this to my plugin to redirect after plugin activation
as per https://wordpress.stackexchange/a/178504/145078
register_activation_hook(__FILE__, 'nht_plugin_activate');
add_action('admin_init', 'nht_plugin_redirect');
function nht_plugin_activate() {
add_option('nht_plugin_do_activation_redirect', true);
}
function nht_plugin_redirect() {
if (get_option('nht_plugin_do_activation_redirect', false)) {
delete_option('nht_plugin_do_activation_redirect');
if(!isset($_GET['activate-multi']))
{
wp_redirect("edit.php?post_type=headline&page=news-headline");
}
}
}
But what is plugin prefix nht ? How can i make my plugin to work redirect after plugin activation what are things to be updates?
Share Improve this question asked Nov 15, 2018 at 19:50 user145078user145078 5- 1 "nht_" is the prefix. You should replace that with your own. Prefixes are just to make a function name unique to avoid namespace collisions. Since that's the prefix of someone else's plugin, it would be unwise to use it with exactly the same name as the function would already be defined. – butlerblog Commented Nov 15, 2018 at 21:23
- @butlerblog oh okay then it does not seems to work for me – user145078 Commented Nov 16, 2018 at 7:52
- If it worked without changing it, it will work if you change it - there would be no difference. Just make sure you change the function names both where they are defined AND in the hook. – butlerblog Commented Nov 16, 2018 at 13:02
- @butlerblog yeah i understand that ..the code does not seems to work – user145078 Commented Nov 16, 2018 at 13:09
- @butlerblog my mistake , the code was not getting updated that's why it did n't worked ..please make it as answer .thanks :) – user145078 Commented Nov 16, 2018 at 13:23
1 Answer
Reset to default 0In this case, "nht_" is a prefix to avoid naming collisions with similar functions. This is a "best practice" to observe when doing your own development.
So if you're developing something that would be distributed publicly, you should be the habit of applying your own prefix to your function names; and since this particular code snippet is something from another person/plugin, it's definitely a good idea to replace it with your own. So change "nht_" to something that you would use as a prefix:
register_activation_hook(__FILE__, 'my_custom_prefix_plugin_activate');
add_action('admin_init', 'my_custom_prefix_plugin_redirect');
function my_custom_prefix_plugin_activate() {
add_option('my_custom_prefix_plugin_do_activation_redirect', true);
}
function my_custom_prefix_plugin_redirect() {
if (get_option('my_custom_prefix_plugin_do_activation_redirect', false)) {
delete_option('my_custom_prefix_plugin_do_activation_redirect');
if(!isset($_GET['activate-multi'])) {
wp_redirect("edit.php?post_type=headline&page=news-headline");
}
}
}
I applied "my_custom_prefix_" in your code where appropriate as an example. Note this not only included function names, but also the wp_option that the setting is saved under. But you would want to change it to something that suits you and/or your plugin.
本文标签: Redirect to custom admin menu after plugin activation
版权声明:本文标题:Redirect to custom admin menu after plugin activation 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749174714a2327601.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论