Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have create a plugin that I want to redirect to the options page of that plugin after the user activates it. This works fine when I test it locally. However, on a live installation of wordpress, it does not behave in the same manner.

Here is my code below:

        register_activation_hook(__FILE__, 'srpt_plugin_activate');
add_action('admin_init', 'srpt_plugin_redirect');

function my_plugin_activate() {
    add_option('srpt_activation_redirect', true);
}

function srpt_plugin_redirect() {
    $srpt_url = admin_url( 'admin.php?page=plugin-options-page/plugin-options-page.php', 'http' );
    if (get_option('srpt_activation_redirect', false)) {
        delete_option('srpt_activation_redirect');
        wp_redirect($srpt_url);
    }

This is the substitution to the original uri:

plugin-options-page.php

Thank you for your time if I don't get a chance to thank you later. Wayne Hatter.

share|improve this question
    
Okay, I just tested it again with this addition: wp-admin/admin.php?page=plugin-options-page/plugin-options-page.php Then I got this message: The plugin generated 245 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin. –  Wayne Hatter May 28 '12 at 12:28
    
If there is any output before the redirection function, it will fail because headers can't be set after the output has been started. Turn WP_DEBUG on in wp-config.php file and test. –  Ashfame May 28 '12 at 12:49

1 Answer 1

You add this as your activation hook:

    register_activation_hook(__FILE__, 'srpt_plugin_activate');

but the function is my_plugin_activate not srpt_plugin_activate. This is based on the fact that there is no function srpt_plugin_activate, and looking at the code my_plugin_activate fills its place in the flow. Is this a typo in the question or in the live code?

Plus, re your 245 characters of unexpected output. You are creating no output intentionally before the redirect? So you must be getting an error message, possibly PHP warning or notice level, and that is giving you the 245 characters of unexpected output. I do not know why your options page url would end in .php my plugins always create their options pages using add_submenu_page and I define a string to use as the page name, and then the url for the page is for example: /wp-admin/admin.php?page=the_string_i_gave. Here is an example of me adding an options page to one of my plugins:

add_submenu_page('wswpsubscriber', __('Main Management Area','WsWpSubscriber'), __('Options','WsPsSubscriber'),'manage_options','wswps_setup',array(&$this,'subscribe_main_menu'));

function subscribe_main_menu

then controls the output for the page found at /wp-admin/admin.php?page=wswps_setup

share|improve this answer
    
Thanks a lot man, it was a typo. I used an example script and forgot to change that function name to reflect the changes. Thanks alot. I will buy you some pencils one day. –  Wayne Hatter May 28 '12 at 14:40
1  
An upvote and a mark as correct will do fine –  Liam Bailey May 28 '12 at 20:59
    
I need a reputation score of 15. I only have a reputation of 1. Obviously I am new to this exchange. So please have patience with me. –  Wayne Hatter May 29 '12 at 13:30
    
Oh, I was only kidding Wayne, but I didn't think you needed 15 points to mark an answer to your own question as correct using the tick under the score. –  Liam Bailey May 30 '12 at 20:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.