$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Redirect to custom admin menu after plugin activation|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Redirect to custom admin menu after plugin activation

matteradmin7PV0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

In 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.

Post a comment

comment list (0)

  1. No comments so far