{"id":8364281,"date":"2016-10-27T18:42:27","date_gmt":"2016-10-27T18:42:27","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/wp_redirect-to-settings-page\/"},"modified":"2016-10-27T18:42:27","modified_gmt":"2016-10-27T18:42:27","slug":"wp_redirect-to-settings-page","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/wp_redirect-to-settings-page\/","title":{"rendered":"wp_redirect to Settings Page"},"content":{"rendered":"<p>So I&#8217;ve got a plugin that I&#8217;ve created and on activation, I want to send the user from the plugin to it&#8217;s Settings page immediately.<\/p>\n<p>Here&#8217;s the code I&#8217;ve got going:<\/p>\n<pre><code>function dbn_uaa_Plugin_Activated() {\n  \/\/ some stuff unrelated to the problem goes here\n\n  \/\/ redirect code follows:\n  wp_redirect(admin_url(&#039;options-general.php?page=dbn-user-action-settings&#039;));\n  exit;\n}\nregister_activation_hook(__FILE__, &#039;dbn_uaa_PluginActivated&#039;);<\/code><\/pre>\n<p>When the <code>wp_redirect<\/code> and <code>exit<\/code> code are in there, none of the function actually functions.  Strip it out, the unrelated stuff works fine.  But with it there, I attempt to activate the plugin and the resulting URL for the settings page is correct, but I get a &#8220;Sorry, you are not allowed to access this page.&#8221; error.<\/p>\n<p>Strip out the redirect code and the plugin activates cleanly.  And I can use the sidebar admin menu to navigate to the Settings page, successfully.  <em>I&#8217;ve compared the URLs generated by the redirect and by the sidebar menu and they are identical.<\/em><\/p>\n<p>I also tried stripping out the redirect code and placing it in <code>class-dbn-uaa-activator.php<\/code> with the exact same results as trying it with the <code>register_activation_hook<\/code> code\/function shown above.<\/p>\n<p>What the hell am I missing here?<\/p>\n","protected":false},"template":"","class_list":["post-8364281","topic","type-topic","status-publish","hentry","topic-tag-register_activation_hook","topic-tag-wp_redirect"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/8364281","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/8364281\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=8364281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}