[resolved] register_activation_hook (7 posts)

  1. Hi,

    I'm trying to add a custom message to my plugin upon activation. I would simply like to show a message telling the user to please visit the plugin settings page.

    I have tried this hook:

    function jwl_visit_settings_page () {
     echo '<div id="message" class="updated"><p>Thank you for choosing Google Webfonts.  Please visit the settings page to get started.</p></div>';

    but I receive an error about generating xxx characters of unexpected output... and no message. (checked white space around php, etc..)

    I believe this has something to do with running the hook within the main.php file (from reading the codex).

    All of my functions, from creating the admin pages and options, to displaying all content, is all located in one file.. my main.php file.

    What exactly is it I'm missing here?

  2. Is there anyone out there who has implemented this into their plugin? Who would be willing to share??

  3. Is there no one... no one at all... Is there perhaps a secret society I need to join? I'm down for whatever initiation procedures may be required!

    Here is the warning message I receive with the function above, when activating the plugin:

    The plugin generated 134 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.
  4. I'm sure there is many ways to go about it, but I think you are using the wrong hook.

    If you want that class="updated" message posted until the user visits the settings page then try add_action('admin_notices', 'jwl_visit_settings_page'); instead like so.

    if( get_option( 'jwl_option' ) == '' )
        add_action( 'admin_notices' , 'jwl_visit_settings_page' );
    function jwl_visit_settings_page() {
        echo '<div class="updated">
           <p>Thank you for choosing Google Webfonts.  Please visit the settings page to get started.</p>

    That way until the add_option() and update_option() are executed and the option is filled with a value, the admin message will continue to be displayed.

    Or use another conditional, you get the idea.

  5. Thank you, kind sir!!

    Okay, that's working. However, I'm confused on how I get the message to not be displayed.

    Ideally, what I would like is to link the words "settings page" in the message to the actual settings page (which I can do), and when they click that link, the message disappears.

    Any further help or clarification would be most appreciated.

  6. I think it's documented here.


    There are also other links on that page.

    The setting page will be a reproducible URL... Give the source code of other plugins a looks to see how they do it.

    For example, SyntaxHighlighter Evolved has this down as the link:

    $links[] = '<a href="' . admin_url( 'options-general.php?page=syntaxhighlighter' ) . '">' . __( 'Settings', 'syntaxhighlighter' ) . '</a>';

    That's line 300 in syntaxhighlighter.php.

    That $links[] can be inserted into your update message so that it not only reminds the user to go there but also provides them a link to do so.

  7. Thank you very much, Jan.

    Your info pointed me in the right direction, and with a little customization, I was able to achieve what I needed.

    I can't thank you enough!

    For anyone else out there looking, here is the code I used (which will only display the message on the admin plugins page, and will remain there until the user manually dismisses the message).

    Thanks again, Jan!!

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.