Skip to content

Commit

Permalink
Revert "Put a real big warning on forms that wp isn't defined and for…
Browse files Browse the repository at this point in the history
…m will not work"
  • Loading branch information
New0 authored May 23, 2019
1 parent 0843553 commit 6ee7b64
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 71 deletions.
104 changes: 49 additions & 55 deletions assets/js/frontend-script-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand All @@ -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( '<div class="alert alert-warning">' + CFFIELD_CONFIG[instance].error_strings.wp_not_defined + '</div>' );
}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()
});


}
Expand Down
25 changes: 9 additions & 16 deletions classes/field/localizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
}
}

0 comments on commit 6ee7b64

Please sign in to comment.