Make WordPress Core

Opened 13 years ago

Closed 10 years ago

#21265 closed defect (bug) (wontfix)

settings_fields() conflict with admin-ajax.php in ajax requests

Reported by: vdvtt's profile vdvtt Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4.1
Component: Plugins Keywords: needs-patch
Focuses: administration Cc:

Description

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 $_GETaction? 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 $_REQUESTaction?. 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.

Attachments (1)

bug_ajax.php (618 bytes) - added by vdvtt 13 years ago.
Simple PHP file with code to generate bug

Download all attachments as: .zip

Change History (4)

@vdvtt
13 years ago

Simple PHP file with code to generate bug

#1 @nacin
11 years ago

  • Component changed from Plugins to Admin APIs
  • Focuses administration added

#2 @nacin
11 years ago

  • Component changed from Admin APIs to Plugins

Sorry for the noise.

#3 @chriscct7
10 years ago

  • Keywords needs-patch added
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Closing as wontfix. Complete lack of interest on the ticket over the last 3 years, and by now, most developers affected would have worked around this in their plugins. Feel free to reopen when more interest re-emerges (particularly if there's a patch)

Note: See TracTickets for help on using tickets.