Created
January 12, 2018 15:02
-
-
Save baerkins/38a1e962f01ee4ccde02dd29656d7032 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Custom Gravity Forms Spinner | |
* | |
* @since 1.0.0 | |
*/ | |
add_filter( 'gform_ajax_spinner_url', 'spinner_url', 10, 2 ); | |
function spinner_url( $image_src, $form ) { | |
return get_bloginfo('template_directory') . '/dist/images/spinner.gif'; | |
} | |
/** | |
* Add Conditional Caps to Gravity Forms Total Field | |
* | |
*/ | |
class RW_GF_Total_Field_Logic { | |
public function __construct() { | |
add_action( 'init', array( $this, 'init' ) ); | |
} | |
function init() { | |
if ( ! property_exists( 'GFForms', 'version' ) || ! version_compare( GFForms::$version, '1.9', '>=' ) ) { | |
return; | |
} | |
add_filter( 'gform_field_content', array( $this, 'maybe_add_logic_event' ), 10, 2 ); | |
add_filter( 'gform_admin_pre_render', array( $this, 'enable_total_in_conditional_logic' ) ); | |
} | |
function maybe_add_logic_event( $content, $field ) { | |
if ( $field->type != 'total' ) { | |
return $content; | |
} | |
$logic_event = $field->get_conditional_logic_event( 'change' ); | |
return ! empty( $logic_event ) ? str_replace( "gform_hidden'", "gform_hidden' value='0' {$logic_event}", $content ) : $content; | |
} | |
function enable_total_in_conditional_logic( $form ) { | |
if ( GFCommon::is_entry_detail() ) { | |
return $form; | |
} | |
echo "<script type='text/javascript'>" . | |
" gform.addFilter('gform_is_conditional_logic_field', function (isConditionalLogicField, field) {" . | |
" return field.type == 'total' ? true : isConditionalLogicField;" . | |
' });' . | |
" gform.addFilter('gform_conditional_logic_operators', function (operators, objectType, fieldId) {" . | |
' var targetField = GetFieldById(fieldId);' . | |
" if (targetField && targetField['type'] == 'total') {" . | |
" operators = {'>': 'greaterThan', '<': 'lessThan'};" . | |
' }' . | |
' return operators;' . | |
' });' . | |
'</script>'; | |
return $form; | |
} | |
} | |
new RW_GF_Total_Field_Logic(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment