Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Events Manager Pro Forms Fix
- Version: 1.2
- Plugin URI: http://wp-events-plugin.com
- Description: Fixes php.ini max_input_vars limitation on 24+ form fields for EM Form Builder
- Author: Marcus Sykes
- Author URI: http://wp-events-plugin.com
- */
- /*
- fixing max_input_vars = 1000 limit which is preventing more than 23 custom fields
- data package coming in as json string in 'fields_json'
- stripcslashes()
- */
- class EMP_Forms_Fix{
- public static function init(){
- global $pagenow;
- if( !empty($_REQUEST['page']) && $_REQUEST['page'] == 'events-manager-forms-editor'){
- add_action('admin_init', 'EMP_Forms_Fix::post', 8, 1);
- add_action('admin_head', 'EMP_Forms_Fix::js', 10, 1);
- }
- }
- public static function post(){
- if( isset($_REQUEST['fields_json']) ){
- $str = $test = str_replace(array('[]\\"','\\"', "\\'",'\\\\'),array('"','"',"'",'\\'), trim($_REQUEST['fields_json']));
- $test = (array) json_decode($test);
- if (count($test)) $_REQUEST = array_merge($_REQUEST, $test);
- }
- }
- public static function js( $form_name) {
- ?>
- <script type="text/javascript">
- jQuery(document).ready( function($){
- if (typeof JSON.stringify != 'undefined'){
- if (typeof jQuery.serializeJSON == 'undefined') jQuery.fn.serializeJSON = function(){
- var o = {},
- a = this.serializeArray();
- jQuery.each(a, function() {
- if (o[this.name] !== undefined) {
- if (!o[this.name].push) { o[this.name] = [o[this.name]]; }
- o[this.name].push(this.value || '');
- } else {
- o[this.name] = this.value || '';
- }
- });
- return JSON.stringify(o, null, 2);
- }
- jQuery('.em-form-custom').submit(function(event){
- var myform = jQuery(this);
- if (myform.find('#fields_json').length) return; //have already made switch, so let default submit take place
- event.preventDefault();
- var data = myform.serializeJSON();
- myform.empty().append(jQuery('<input/>').attr({id:'fields_json', name:'fields_json', value:data})).submit();
- });
- }
- });
- </script>
- <?php
- }
- }
- if( is_admin() ){
- EMP_Forms_Fix::init();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement