Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I wrote a simple plugin that before now only had one option so the code below calling wp_nonce_field worked fine. However, now that I've had a second option it seems that the code below only allows updating of the most recent field. I unfortunately have to admit that I do not fully understand what the wp_nonce_field code is doing and I'd love someone to explain it to me. The code I am using came from here I know it's most likely something super simple.

 $cookie_hours = (get_option('mobileesp_wp_cookie_hours') =="") ? "24" : get_option('mobileesp_wp_cookie_hours');
echo '
<div class="wrap">
    <h2>MobileESP for WordPress Settings</h2>
    <p>This WordPress plugin will detect mobile devices and redirect the user. For this plugin to work you must first enter the redirect url below. 
    You must also create a mobile site or have content at that location. </p>
    <form method="post" action="options.php">
        '.wp_nonce_field('update-options').'
        <table class="form-table">
            <tr valign="top">
                <th scope="row"><label for="mobileesp_wp_target_url">Where do we send mobile devices?</label></th>
                <td><input type="text" name="mobileesp_wp_target_url" id="mobileesp_wp_target_url" value="'.get_option('mobileesp_wp_target_url').'" class="regular-text code" /></td>
            </tr>
            <tr valign="top">
                <th scope="row"><label for="mobileesp_wp_cookie_hours">How many hours should the cookie be valid?</label></th>
                <td><input type="text" name="mobileesp_wp_cookie_hours" id="mobileesp_wp_cookie_hours" value="'.$cookie_hours.'" class="regular-text code" /></td>
            </tr>
        </table>
        <input type="hidden" name="action" value="update" />
        <input type="hidden" name="page_options" value="mobileesp_wp_target_url" />
        <input type="hidden" name="page_options" value="mobileesp_wp_cookie_hours" />
        <p class="submit"><input type="submit" name="Submit" value="Submit" class="button-primary" /></p>
    </form>

Here is the full source of the most recent version (with only one option) http://plugins.svn.wordpress.org/mobileesp-for-wordpress/trunk/mobileesp_wp.php

share|improve this question
Could you show the php code, where you "catch" the nonce field? Where the $_POST processing is going on... – Miha Rekar Oct 25 '12 at 9:04
Pretty sure that's all happening on the WordPress side of things (in page-options.php). Added link to full source of most recent version. – BandonRandon Oct 25 '12 at 9:10

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.