PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / helpers / FrmShortcodeHelper.php

FrmShortcodeHelper.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 5.0, at classes/helpers/FrmShortcodeHelper.php

94 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 /**
7 * @since 2.02.12
8 */
9
10 class FrmShortcodeHelper {
11
12 /**
13 * Get the shortcode attributes in key/value pairs from a string
14 *
15 * @since 2.02.12
16 *
17 * @param string $text
18 *
19 * @return array
20 */
21 public static function get_shortcode_attribute_array( $text ) {
22 $atts = array();
23 if ( $text !== '' ) {
24 $atts = shortcode_parse_atts( $text );
25 }
26
27 if ( ! is_array( $atts ) ) {
28 $atts = array();
29 }
30
31 return $atts;
32 }
33
34 /**
35 * Get the name of the shortcode from the regEx
36 *
37 * @since 3.0
38 *
39 * @param array $shortcodes
40 * @param int $short_key The position in the shortcodes array
41 * @param array $args
42 *
43 * @return string
44 */
45 public static function get_shortcode_tag( $shortcodes, $short_key, $args = array() ) {
46 $args = wp_parse_args(
47 $args,
48 array(
49 'conditional' => false,
50 'conditional_check' => false,
51 'foreach' => false,
52 )
53 );
54 if ( ( $args['conditional'] || $args['foreach'] ) && ! $args['conditional_check'] ) {
55 $args['conditional_check'] = true;
56 }
57
58 $prefix = '';
59 if ( $args['conditional_check'] ) {
60 if ( $args['conditional'] ) {
61 $prefix = 'if ';
62 } elseif ( $args['foreach'] ) {
63 $prefix = 'foreach ';
64 }
65 }
66
67 $with_tags = $args['conditional_check'] ? 3 : 2;
68 if ( ! empty( $shortcodes[ $with_tags ][ $short_key ] ) ) {
69 $tag = str_replace( '[' . $prefix, '', $shortcodes[0][ $short_key ] );
70 $tag = str_replace( ']', '', $tag );
71 $tag = str_replace( chr( 194 ) . chr( 160 ), ' ', $tag );
72 $tags = preg_split( '/\s+/', $tag, 2 );
73 if ( is_array( $tags ) ) {
74 $tag = $tags[0];
75 }
76 } else {
77 $tag = $shortcodes[ $with_tags - 1 ][ $short_key ];
78 }
79
80 return $tag;
81 }
82
83 public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) {
84 if ( $no_vars ) {
85 $html = str_replace( '[if ' . $code . ']', '', $html );
86 $html = str_replace( '[/if ' . $code . ']', '', $html );
87 } else {
88 $html = preg_replace( '/(\[if\s+' . $code . '\])(.*?)(\[\/if\s+' . $code . '\])/mis', '', $html );
89 }
90
91 $html = str_replace( '[' . $code . ']', $replace_with, $html );
92 }
93 }
94