Skip to content

Commit d7ea796

Browse files
authored
gw-advanced-conditional-shortcodes.php: Deprecated snippet in favor of Spellbook.
1 parent 5850964 commit d7ea796

File tree

1 file changed

+2
-62
lines changed

1 file changed

+2
-62
lines changed
Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,6 @@
11
<?php
22
/**
3-
* Gravity Wiz // Gravity Forms // Advanced Conditional Shortcodes
3+
* This snippet is now available as a free plugin with Spellbook. ✨
4+
* Instructions for installing this plugin can be found here:
45
* https://gravitywiz.com/gravity-forms-advanced-conditional-shortcode/
5-
*
6-
* Allows multiple conditions in a single Gravity Forms shortcode.
7-
*
8-
* @version 0.1
9-
* @author David Smith <[email protected]>
10-
* @license GPL-2.0+
11-
* @link https://gravitywiz.com
12-
*
13-
* Plugin Name: Gravity Forms Advanced Conditional Shortcodes
14-
* Plugin URI: http://gravitywiz.com
15-
* Description: Allows multiple conditions in a single Gravity Forms shortcode.
16-
* Author: Gravity Wiz
17-
* Version: 0.1
18-
* Author URI: http://gravitywiz.com
19-
*
206
*/
21-
add_filter( 'gform_shortcode_conditional', function( $result, $atts, $content ) {
22-
23-
if ( ! isset( $atts['value'] ) || isset( $atts['merge_tag'] ) ) {
24-
return $result;
25-
}
26-
27-
$relation = strtolower( rgar( $atts, 'relation', 'all' ) ); // or 'any'
28-
$conditions = array();
29-
30-
foreach ( $atts as $key => $prop ) {
31-
32-
preg_match( '|value(\d*)$|', $key, $match );
33-
if ( ! empty( $match ) ) {
34-
list( , $index ) = $match;
35-
$conditions[] = array(
36-
'value' => rgar( $atts, sprintf( 'value%s', $index ) ),
37-
'operator' => rgar( $atts, sprintf( 'operator%s', $index ) ),
38-
'compare' => rgar( $atts, sprintf( 'compare%s', $index ) ),
39-
);
40-
}
41-
}
42-
43-
$conditional_met = $relation == 'all';
44-
45-
foreach ( $conditions as $condition ) {
46-
$is_match = GFFormsModel::matches_operation( $condition['value'], $condition['compare'], $condition['operator'] );
47-
if ( $relation == 'any' && $is_match ) {
48-
$conditional_met = true;
49-
break;
50-
} elseif ( $relation == 'all' && ! $is_match ) {
51-
$conditional_met = false;
52-
break;
53-
}
54-
}
55-
56-
if ( ! $conditional_met ) {
57-
return '';
58-
}
59-
60-
// find and remove any starting/closing <br> tags
61-
if ( rgar( $atts, 'format' ) != 'raw' ) {
62-
$content = preg_replace( '/^<br(?: *\/)?>|<br(?: *\/)?>$/', '', $content );
63-
}
64-
65-
return do_shortcode( $content );
66-
}, 10, 3 );

0 commit comments

Comments
 (0)