[wp-trac] [WordPress Trac] #21265: settings_fields() conflict with admin-ajax.php in ajax requests

WordPress Trac wp-trac at lists.automattic.com
Fri Jul 13 19:30:32 UTC 2012


#21265: settings_fields() conflict with admin-ajax.php in ajax requests
--------------------------+-----------------------------
 Reporter:  vdvtt         |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Plugins       |    Version:  3.4.1
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 I created a plugin, which uses the function 'settings_fields()' to
 generate required fields. When I save the plugin options, I decided to use
 Ajax Requests to save time.

 Until 3.3.2 this was working well, but with 3.4.1 admin-ajax.php code
 update generates a errors. Because "settings_fields()" generate hidden
 field called "action" and before 3.4.1 admin-ajax.php used $_GET['action']
 to call ajax action dynamically.

 '''How reproduce:'''
 1. Use WP 3.4.1
 2. Put this code snippet in a .php file in wp root folder:
 {{{
 <?php
         require 'wp-load.php';

         add_action('wp_ajax_mysettings_save' , 'mysettings_save');

         function mysettings_save() {
                 //DO SOMETHING USEFULL HERE
                 exit('It worked!');
         }

 ?>
 <script
 src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
 <form>
         <p><input type="text" name="my_settings_field" value=""></p>
         <button>Save</button>
         <?php settings_fields('my_settings'); ?>
 </form>
 <script>
         $('form').submit(function(event){
                 event.preventDefault();

                 $.post('wp-admin/admin-ajax.php?action=mysettings_save',
 $(this).serialize(), function(data){ console.log(data); });
         });
 </script>
 }}}


 In wordpress 3.4.1 field 'action' changes to 'update', because
 $_REQUEST['action']. In wordpress 3.3.2, field 'action' is
 'mysettings_save'.

 I have to redo all my work with my plugin with this change in Wordpress
 3.4.1.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/21265>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list