From 6ee7b6430190ae7092b258c908b10ef924e1ad18 Mon Sep 17 00:00:00 2001 From: Nicolas Figueira Date: Thu, 23 May 2019 12:45:11 +0200 Subject: [PATCH] Revert "Put a real big warning on forms that wp isn't defined and form will not work" --- assets/js/frontend-script-init.js | 104 ++++++++++++++---------------- classes/field/localizer.php | 25 +++---- 2 files changed, 58 insertions(+), 71 deletions(-) diff --git a/assets/js/frontend-script-init.js b/assets/js/frontend-script-init.js index d01753a0b..45372d56e 100755 --- a/assets/js/frontend-script-init.js +++ b/assets/js/frontend-script-init.js @@ -345,8 +345,6 @@ var cf_jsfields_init, cf_presubmit; window.addEventListener("load", function(){ (function( $ ) { 'use strict'; - var wpDefined = undefined === typeof window.wp; - window.CALDERA_FORMS = {}; @@ -361,61 +359,57 @@ window.addEventListener("load", function(){ form_id = $el.attr('id'); instance = $el.data('instance'); - if ('object' === typeof CFFIELD_CONFIG[instance] ) { + if ('object' === typeof CFFIELD_CONFIG[instance] ) { $form = $( document.getElementById( form_id )); - if( ! wpDefined ){ - $( $form.data( 'target' ) ).append( '
' + CFFIELD_CONFIG[instance].error_strings.wp_not_defined + '
' ); - }else{ - if ( ! protocolChecked ) { - //check for protocol mis-match on submit url - protocolCheck = new CalderaFormsCrossOriginWarning($el, $, CFFIELD_CONFIG[instance].error_strings); - protocolCheck.maybeWarn(); - - //don't check twice - protocolChecked = true; - } - - if ( ! jQueryChecked && CFFIELD_CONFIG[instance].error_strings.hasOwnProperty( 'jquery_old' ) ) { - //check for old jQuery - jQueryCheck = new CalderaFormsJQueryWarning($el, $, CFFIELD_CONFIG[instance].error_strings); - jQueryCheck.maybeWarn(); - - //don't check twice - jQueryChecked = true; - } - - formId = $el.data( 'form-id' ); - config = CFFIELD_CONFIG[instance].configs; - - var state = new CFState(formId, $ ); - state.init( CFFIELD_CONFIG[instance].fields.defaults,CFFIELD_CONFIG[instance].fields.calcDefaults ); - - if( 'object' !== typeof window.cfstate ){ - window.cfstate = {}; - } - - window.cfstate[ form_id ] = state; - - $form.find( '[data-sync]' ).each( function(){ - var $field = $( this ); - if ( ! $field.data( 'unsync' ) ) { - new CalderaFormsFieldSync($field, $field.data('binds'), $form, $, state); - } - }); - - - config_object = new Caldera_Forms_Field_Config( config, $(document.getElementById(form_id)), $, state ); - config_object.init(); - $( document ).trigger( 'cf.form.init',{ - $form: $form, - idAttr: form_id, - formId: formId, - state: state, - fieldIds: CFFIELD_CONFIG[instance].fields.hasOwnProperty( 'ids' ) ? CFFIELD_CONFIG[instance].fields.ids : [], - nonce: jQuery( '#_cf_verify_' + formId ).val() - }); - } + if ( ! protocolChecked ) { + //check for protocol mis-match on submit url + protocolCheck = new CalderaFormsCrossOriginWarning($el, $, CFFIELD_CONFIG[instance].error_strings); + protocolCheck.maybeWarn(); + + //don't check twice + protocolChecked = true; + } + + if ( ! jQueryChecked && CFFIELD_CONFIG[instance].error_strings.hasOwnProperty( 'jquery_old' ) ) { + //check for old jQuery + jQueryCheck = new CalderaFormsJQueryWarning($el, $, CFFIELD_CONFIG[instance].error_strings); + jQueryCheck.maybeWarn(); + + //don't check twice + jQueryChecked = true; + } + + formId = $el.data( 'form-id' ); + config = CFFIELD_CONFIG[instance].configs; + + var state = new CFState(formId, $ ); + state.init( CFFIELD_CONFIG[instance].fields.defaults,CFFIELD_CONFIG[instance].fields.calcDefaults ); + + if( 'object' !== typeof window.cfstate ){ + window.cfstate = {}; + } + + window.cfstate[ form_id ] = state; + + $form.find( '[data-sync]' ).each( function(){ + var $field = $( this ); + if ( ! $field.data( 'unsync' ) ) { + new CalderaFormsFieldSync($field, $field.data('binds'), $form, $, state); + } + }); + + + config_object = new Caldera_Forms_Field_Config( config, $(document.getElementById(form_id)), $, state ); + config_object.init(); + $( document ).trigger( 'cf.form.init',{ + $form: $form, + idAttr: form_id, + formId: formId, + state: state, + fieldIds: CFFIELD_CONFIG[instance].fields.hasOwnProperty( 'ids' ) ? CFFIELD_CONFIG[instance].fields.ids : [], + nonce: jQuery( '#_cf_verify_' + formId ).val() + }); } diff --git a/classes/field/localizer.php b/classes/field/localizer.php index 796480daa..9626644ea 100755 --- a/classes/field/localizer.php +++ b/classes/field/localizer.php @@ -104,23 +104,16 @@ public static function localize_cb(){ * @return array */ protected static function error_strings(){ - if( current_user_can( Caldera_Forms::get_manage_cap('admin') ) ) { - $strings = array( - 'wp_not_defined' => __( 'The variable wp is not defined, your forms can not function as expected.', 'caldera-forms' ), - 'mixed_protocol' => __( 'Submission URL and current URL protocols do not match. Form may not function properly.', 'caldera-forms' ), - 'jquery_old' => __( 'An out of date version of jQuery is loaded on the page. Form may not function properly.', 'caldera-forms' ) - ); - }else{ - $message = __( 'Form may not function properly. Contact site administrator.', 'caldera-forms' ); - $strings = array( - 'wp_not_defined' => $message, - 'mixed_protocol' => $message, - //jquery_old is intentionally omitted. See assets/js/front-end-script-init.js ~L378. - ); - - } + $strings = array( + 'mixed_protocol' => __( 'Submission URL and current URL protocols do not match. Form may not function properly.', 'caldera-forms' ), + 'jquery_old' => __( 'An out of date version of jQuery is loaded on the page. Form may not function properly.', 'caldera-forms' ) + ); + + if( ! current_user_can( Caldera_Forms::get_manage_cap( 'admin' )) ){ + unset( $strings[ 'jquery_old' ] ); + } return $strings; } -} +} \ No newline at end of file