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