[wp-trac] [WordPress Trac] #61269: Plugin Dependencies: Add filter to restore auto-redirect after plugin activation

WordPress Trac noreply at wordpress.org
Thu May 23 16:54:34 UTC 2024


#61269: Plugin Dependencies: Add filter to restore auto-redirect after plugin
activation
-------------------------------------------------+-------------------------
 Reporter:  hellofromTonya                       |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  closed
 Priority:  normal                               |   Milestone:  6.5.4
Component:  Upgrade/Install                      |     Version:  6.5.3
 Severity:  normal                               |  Resolution:  invalid
 Keywords:  needs-testing needs-testing-info     |     Focuses:
  needs-dev-note                                 |  administration
-------------------------------------------------+-------------------------
Changes (by valani9099):

 * keywords:  has-patch needs-dev-note needs-testing needs-testing-info =>
     needs-testing needs-testing-info needs-dev-note
 * status:  new => closed
 * focuses:   => administration
 * resolution:   => invalid
 * version:  6.5 => 6.5.3


Comment:

 Hello @hellofromTonya,

 To restore auto-redirect after plugin activation in WordPress, you can use
 a filter hook. WordPress provides the activate_plugin action hook, which
 can be utilized to add custom functionality immediately after a plugin is
 activated.

 Here’s the complete code snippet that you would typically add to your
 plugin’s main file:

 {{{#!php
 <?php
 function my_plugin_redirect() {
     if (isset($_GET['activate']) && $_GET['activate'] == 'true') {
         // Redirect to a specific page after activation
         wp_redirect(admin_url('admin.php?page=my-plugin-settings'));
         exit;
     }
 }
 add_action('admin_init', 'my_plugin_redirect');
 }}}

 Make sure that the page you are redirecting to (admin.php?page=my-plugin-
 settings) exists and is registered correctly in your plugin.

 By adding this code, you ensure that after the plugin is activated, the
 user will be automatically redirected to the specified settings page,
 enhancing the user experience by guiding them to the configuration area of
 your plugin.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/61269#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list