The MU forums have moved to WordPress.org

plugin automatic options update (15 posts)

  1. dhrachov
    Member
    Posted 15 years ago #

    Hi, when updating options in admin page of my plugin I encounter this message: "Are you sure you want to do this?" and nothing else.
    But the plugin works in Wordpress (WP).

    Plugin source code is available at http://pastebin.com/f6c583e61
    It's shortened VoteItUp plugin to demonstrate this error.

    It thing it should be written according WP howtos.
    http://codex.wordpress.org/Creating_Options_Pages
    http://codex.wordpress.org/Adding_Administration_Menus

    I thing it's something with wpnonce magic because the script dies in wp_nonce_ays() function.

    Howto make the plugin compatible with WPMU?

  2. andrea_r
    Moderator
    Posted 15 years ago #

    Did you put it in the plugins folder or the mu-plugins folder?

  3. dhrachov
    Member
    Posted 15 years ago #

    andrea_r: I put it in the plugins folder.

  4. andrea_r
    Moderator
    Posted 15 years ago #

    It's likely it can't find the blog id, so it woudl have to be rewritten.

    I;d either contact the plugin author to see if they are interested in making sure it work in MU, or find another plugin that does similar.

  5. dhrachov
    Member
    Posted 15 years ago #

    andrea_r: I could send him a patch if I knew how to correct the plugin. Can you give an advice?

    In my opinion it's a little unfair that the plugin is written properly according the WP codex and it doesn't work in WPMU. No offence.

  6. andrea_r
    Moderator
    Posted 15 years ago #

    Um, the codex links above were just about creating menu items. Same process in WP & MU.

    It's dying on the nonce. Nonce is the issue, not so much WPMU.

    Read this:
    http://codex.wordpress.org/Wordpress_Nonce_Implementation

  7. dhrachov
    Member
    Posted 15 years ago #

    I have found solution.
    You have to add whitelist-options filter hook:

    add_filter('whitelist_options','my_plugin_alter_whitelist_options');
    function my_plugin_alter_whitelist_options($whitelist) {
    if(is_array($whitelist)) {
    $option_array = array('magic_name' => array('form_field_01','form_field_02','form_field_03'));
    $whitelist = array_merge($whitelist,$option_array);
    }
    return $whitelist;
    }

    'magic_name' string is whatever you want. It's good to use the name of your plugin. Remember it! 'form_field_XX' fields are form inputs that you want to save. The same as in 'page_options' input.

    Let's move on. That one is situated in form.

    <?php wp_nonce_field('magic_name-options'); ?>

    We used the 'magic_name'. The wp_nonce_field parametr MUST end with '-options' string if you want working the automatic options update.

    And the last thing to do:

    <input type="hidden" name="option_page" value="magic_name" />

    We used magic_name again!

    So why these things? wp_nonce_field creates hash X from 'magic_name-options'. When you click the Submit button it takes value of the option_page, adds '-options' string and creates hash Y. When X != Y it prints the mystic message "Are you sure you want to do this?". And whitelist is safer alternative to page_options input.
    If you use these tutorials:
    http://codex.wordpress.org/Creating_Options_Pages
    http://codex.wordpress.org/Adding_Administration_Menus
    and this guide the plugin should work in WPMU.

    Hope, it will help.
    If it works, tell me. I would post it to somewhere else (as howto).

  8. dhrachov
    Member
    Posted 15 years ago #

    andrea_r: thank you for our answers :)

  9. dhrachov
    Member
    Posted 15 years ago #

    andrea_r: thank you for your answers :D

  10. dhrachov
    Member
    Posted 15 years ago #

    This breaks the plugin in WP. So you have to replace
    <?php wp_nonce_field('magic_name-options'); ?>
    with

    <?php
    if(function_exists('wpmu_create_blog'))
    wp_nonce_field('magic_name-options');
    else
    wp_nonce_field('update-options');
    ?>

    Now it should work in WP and WPMU.

  11. teamplaylotto
    Member
    Posted 15 years ago #

    dhrachov: that was a very useful bit of information for me thanks, I was thinking I had to make 2 versions of my plugin!

    I'm having some small issues updating options for my plugin when using it on Mu, hopefully this post has helped

  12. dwenaus
    Member
    Posted 15 years ago #

    wow, that was really helpful. thank you so much!

  13. jazzigor
    Member
    Posted 15 years ago #

    So any plugin with a settings screen will fail on WPMU unless the author has taken extra care to add WPMU specific code? That's it pity, isn't it?

  14. andrea_r
    Moderator
    Posted 15 years ago #

    No, that's not what was said.

    Many plugins with options screen work perfectly well in MU in the regular plugins folder.

    The OP was abotu the plugin dying on the *nonce* not on the menus.

  15. trcwest
    Member
    Posted 15 years ago #

    has any one had the problem with the plugins updater...

    as when i log in a fresh on a new computer it tells me about the pugins that need updating theni click update then once one updates i loose the option to update the others but the plugins tab has a red note indicating that there are plugins that need to be updated??

    Any thoughts people

About this Topic

  • Started 15 years ago by dhrachov
  • Latest reply from trcwest