| @@ -18,17 +18,14 @@ | ||
| 18 | 18 | * @return array |
| 19 | 19 | */ |
| 20 | 20 | public static function get_shortcode_attribute_array( $text ) { |
| 21 | 21 | $atts = array(); |
| 22 | + | |
| 22 | 23 | if ( $text !== '' ) { |
| 23 | 24 | $atts = shortcode_parse_atts( $text ); |
| 24 | 25 | } |
| 25 | 26 | |
| 26 | - if ( ! is_array( $atts ) ) { | |
| 27 | - $atts = array(); | |
| 28 | - } | |
| 29 | - | |
| 30 | - return $atts; | |
| 27 | + return is_array( $atts ) ? $atts : array(); | |
| 31 | 28 | } |
| 32 | 29 | |
| 33 | 30 | /** |
| 34 | 31 | * Returns shortcodes that are shown/hidden based on the context. |
| @@ -33,8 +30,9 @@ | ||
| 33 | 30 | /** |
| 34 | 31 | * Returns shortcodes that are shown/hidden based on the context. |
| 35 | 32 | * |
| 36 | 33 | * @since 6.16.3 |
| 34 | + * | |
| 37 | 35 | * @return array |
| 38 | 36 | */ |
| 39 | 37 | public static function get_contextual_shortcodes() { |
| 40 | 38 | return array( |
| @@ -70,13 +68,14 @@ | ||
| 70 | 68 | * |
| 71 | 69 | * @return array |
| 72 | 70 | */ |
| 73 | 71 | public static function get_contextual_codes() { |
| 74 | - $contextual_shortcodes = self::get_contextual_shortcodes(); | |
| 75 | - $result = array(); | |
| 76 | - foreach ( $contextual_shortcodes as $type => $shortcodes ) { | |
| 72 | + $result = array(); | |
| 73 | + | |
| 74 | + foreach ( self::get_contextual_shortcodes() as $type => $shortcodes ) { | |
| 77 | 75 | $result[ $type ] = array_keys( $shortcodes ); |
| 78 | 76 | } |
| 77 | + | |
| 79 | 78 | return $result; |
| 80 | 79 | } |
| 81 | 80 | |
| 82 | 81 | /** |
| @@ -98,13 +97,15 @@ | ||
| 98 | 97 | 'conditional_check' => false, |
| 99 | 98 | 'foreach' => false, |
| 100 | 99 | ) |
| 101 | 100 | ); |
| 101 | + | |
| 102 | 102 | if ( ( $args['conditional'] || $args['foreach'] ) && ! $args['conditional_check'] ) { |
| 103 | 103 | $args['conditional_check'] = true; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $prefix = ''; |
| 107 | + | |
| 107 | 108 | if ( $args['conditional_check'] ) { |
| 108 | 109 | if ( $args['conditional'] ) { |
| 109 | 110 | $prefix = 'if '; |
| 110 | 111 | } elseif ( $args['foreach'] ) { |
| @@ -112,23 +113,29 @@ | ||
| 112 | 113 | } |
| 113 | 114 | } |
| 114 | 115 | |
| 115 | 116 | $with_tags = $args['conditional_check'] ? 3 : 2; |
| 116 | - if ( ! empty( $shortcodes[ $with_tags ][ $short_key ] ) ) { | |
| 117 | - $tag = str_replace( '[' . $prefix, '', $shortcodes[0][ $short_key ] ); | |
| 118 | - $tag = str_replace( ']', '', $tag ); | |
| 119 | - $tag = str_replace( chr( 194 ) . chr( 160 ), ' ', $tag ); | |
| 120 | - $tags = preg_split( '/\s+/', $tag, 2 ); | |
| 121 | - if ( is_array( $tags ) ) { | |
| 122 | - $tag = $tags[0]; | |
| 123 | - } | |
| 124 | - } else { | |
| 125 | - $tag = $shortcodes[ $with_tags - 1 ][ $short_key ]; | |
| 117 | + | |
| 118 | + if ( empty( $shortcodes[ $with_tags ][ $short_key ] ) ) { | |
| 119 | + return $shortcodes[ $with_tags - 1 ][ $short_key ]; | |
| 126 | 120 | } |
| 127 | 121 | |
| 128 | - return $tag; | |
| 122 | + $tag = str_replace( '[' . $prefix, '', $shortcodes[0][ $short_key ] ); | |
| 123 | + $tag = str_replace( ']', '', $tag ); | |
| 124 | + $tag = str_replace( chr( 194 ) . chr( 160 ), ' ', $tag ); | |
| 125 | + $tags = preg_split( '/\s+/', $tag, 2 ); | |
| 126 | + | |
| 127 | + return is_array( $tags ) ? $tags[0] : $tag; | |
| 129 | 128 | } |
| 130 | 129 | |
| 130 | + /** | |
| 131 | + * @param bool $no_vars | |
| 132 | + * @param string $code | |
| 133 | + * @param string $replace_with | |
| 134 | + * @param string $html | |
| 135 | + * | |
| 136 | + * @return void | |
| 137 | + */ | |
| 131 | 138 | public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) { |
| 132 | 139 | if ( $no_vars ) { |
| 133 | 140 | $html = str_replace( '[if ' . $code . ']', '', $html ); |
| 134 | 141 | $html = str_replace( '[/if ' . $code . ']', '', $html ); |