Skip to content

Commit

Permalink
wip WordPress standards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Feb 1, 2016
1 parent e608784 commit 4068c7b
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions gravityforms-multiple-form-instances.php
Expand Up @@ -23,9 +23,9 @@ class Gravity_Forms_Multiple_Form_Instances {
*
* @access public
*/
function __construct() {
public function __construct() {
// hook the HTML ID string find & replace functionality
add_filter('gform_get_form_filter', array($this, 'gform_get_form_filter'), 10, 2);
add_filter( 'gform_get_form_filter', array( $this, 'gform_get_form_filter' ), 10, 2 );
}

/**
Expand All @@ -39,10 +39,10 @@ function __construct() {
* @param array $form Array with the form settings.
* @return string $form_string The modified form HTML string.
*/
function gform_get_form_filter($form_string, $form) {
public function gform_get_form_filter( $form_string, $form ) {
// if form has been submitted, use the submitted ID, otherwise generate a new unique ID
if (isset($_POST['gform_random_id'])) {
$random_id = absint( $_POST['gform_random_id'] );
if ( isset( $_POST['gform_random_id'] ) ) {
$random_id = absint( $_POST['gform_random_id'] ); // Input var okay.
} else {
$random_id = mt_rand();
}
Expand All @@ -52,18 +52,18 @@ function gform_get_form_filter($form_string, $form) {

// define all occurences of the original form ID that wont hurt the form input
$strings = array(
"for='choice_" => "for='choice_" . $random_id . "_",
"id='choice_" => "id='choice_" . $random_id . "_",
"id='label_" => "id='label_" . $random_id . "_",
"for='choice_" => "for='choice_" . $random_id . '_',
"id='choice_" => "id='choice_" . $random_id . '_',
"id='label_" => "id='label_" . $random_id . '_',
"'gform_wrapper_" . $form['id'] . "'" => "'gform_wrapper_" . $random_id . "'",
"'gf_" . $form['id'] . "'" => "'gf_" . $random_id . "'",
"'gform_" . $form['id'] . "'" => "'gform_" . $random_id . "'",
"'gform_ajax_frame_" . $form['id'] . "'" => "'gform_ajax_frame_" . $random_id . "'",
"#gf_" . $form['id'] . "'" => "#gf_" . $random_id . "'",
"'gform_fields_" . $form['id'] . "'" => "'gform_fields_" . $random_id . "'",
"id='field_" . $form['id'] . "_" => "id='field_" . $random_id . "_",
"for='input_" . $form['id'] . "_" => "for='input_" . $random_id . "_",
"id='input_" . $form['id'] . "_" => "id='input_" . $random_id . "_",
"id='field_" . $form['id'] . '_' => "id='field_" . $random_id . '_',
"for='input_" . $form['id'] . '_' => "for='input_" . $random_id . '_',
"id='input_" . $form['id'] . '_' => "id='input_" . $random_id . '_',
"'gform_submit_button_" . $form['id'] . "'" => "'gform_submit_button_" . $random_id . "'",
'"gf_submitting_' . $form['id'] . '"' => '"gf_submitting_' . $random_id . '"',
"'gf_submitting_" . $form['id'] . "'" => "'gf_submitting_" . $random_id . "'",
Expand All @@ -82,27 +82,27 @@ function gform_get_form_filter($form_string, $form) {
"window['gf_form_conditional_logic'][" . $form['id'] . "]" => "window['gf_form_conditional_logic'][" . $random_id . "]",
"trigger('gform_post_conditional_logic', [" . $form['id'] . "," => "trigger('gform_post_conditional_logic', [" . $random_id . ",",
'gformShowPasswordStrength("input_' . $form['id'] . '_' => 'gformShowPasswordStrength("input_' . $random_id . '_',
"gformInitChosenFields('#input_" . $form['id'] . "_" => "gformInitChosenFields('#input_" . $random_id . "_",
"jQuery('#input_" . $form['id'] . "_" => "jQuery('#input_" . $random_id . "_",
"gformInitChosenFields('#input_" . $form['id'] . '_' => "gformInitChosenFields('#input_" . $random_id . '_',
"jQuery('#input_" . $form['id'] . '_' => "jQuery('#input_" . $random_id . '_',
'gforms_calendar_icon_input_' . $form['id'] . '_' => 'gforms_calendar_icon_input_' . $random_id . '_',
"id='ginput_base_price_" . $form['id'] . "_" => "id='ginput_base_price_" . $random_id . "_",
"id='ginput_quantity_" . $form['id'] . "_" => "id='ginput_quantity_" . $random_id . "_",
"gfield_price_" . $form['id'] . "_" => "gfield_price_" . $random_id . "_",
"gfield_quantity_" . $form['id'] . "_" => "gfield_quantity_" . $random_id . "_",
"gfield_product_" . $form['id'] . "_" => "gfield_product_" . $random_id . "_",
"id='ginput_base_price_" . $form['id'] . '_' => "id='ginput_base_price_" . $random_id . '_',
"id='ginput_quantity_" . $form['id'] . '_' => "id='ginput_quantity_" . $random_id . '_',
"gfield_price_" . $form['id'] . '_' => "gfield_price_" . $random_id . '_',
"gfield_quantity_" . $form['id'] . '_' => "gfield_quantity_" . $random_id . '_',
"gfield_product_" . $form['id'] . '_' => "gfield_product_" . $random_id . '_',
"ginput_total_" . $form['id'] => "ginput_total_" . $random_id,
"GFCalc(" . $form['id'] . "," => "GFCalc(" . $random_id . ",",
'gf_global["number_formats"][' . $form['id'] . ']' => 'gf_global["number_formats"][' . $random_id . ']',
"gform_next_button_" . $form['id'] . "_" => "gform_next_button_" . $random_id . "_",
"gform_next_button_" . $form['id'] . '_' => "gform_next_button_" . $random_id . '_',
$hidden_field => "<input type='hidden' name='gform_random_id' value='" . $random_id . "' />" . $hidden_field,
);

// allow addons & plugins to add additional find & replace strings
$strings = apply_filters('gform_multiple_instances_strings', $strings);
$strings = apply_filters( 'gform_multiple_instances_strings', $strings );

// replace all occurences with the new unique ID
foreach ($strings as $find => $replace) {
$form_string = str_replace($find, $replace, $form_string);
foreach ( $strings as $find => $replace ) {
$form_string = str_replace( $find, $replace, $form_string );
}

return $form_string;
Expand Down

0 comments on commit 4068c7b

Please sign in to comment.