functions-shortcodes.php
3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
/**
* Functions responsible for shortcodes management.
*
* @since 5.0.5
* @package Shortcodes_Ultimate
* @subpackage Shortcodes_Ultimate/includes
*/
/**
* Add a shortcode.
*
* @since 5.0.5
* @param array $data New shortcode data.
* @param boolean $replace Replace existing shortcode or not.
*/
function su_add_shortcode( $data, $replace = true ) {
return Shortcodes_Ultimate_Shortcodes::add( $data, $replace );
}
/**
* Remove a shortcode.
*
* @since 5.0.5
* @param string $id Shortcode ID to remove.
*/
function su_remove_shortcode( $id ) {
return Shortcodes_Ultimate_Shortcodes::remove( $id );
}
/**
* Get all shortcodes.
*
* @since 5.0.5
* @return array The collection of available shortcodes.
*/
function su_get_all_shortcodes() {
return Shortcodes_Ultimate_Shortcodes::get_all();
}
/**
* Get specific shortcode by ID.
*
* @since 5.0.5
* @param string $id The ID (without prefix) of shortcode.
* @return array|boolean Shortcode data if found, False otherwise.
*/
function su_get_shortcode( $id ) {
return Shortcodes_Ultimate_Shortcodes::get( $id );
}
function su_get_groups() {
return Shortcodes_Ultimate_Shortcodes::get_groups();
}
/**
* Get shortcode default settings.
*
* @since 5.4.0
* @param string $id Shortcode ID.
* @return array Array with default settings.
*/
function su_get_shortcode_defaults( $id ) {
$shortcode = su_get_shortcode( $id );
$defaults = array();
if ( ! isset( $shortcode['atts'] ) ) {
return $defaults;
}
foreach ( $shortcode['atts'] as $key => $props ) {
$defaults[ $key ] = isset( $props['default'] ) ? $props['default'] : '';
}
return $defaults;
}
/**
* Parse shortcode attribute values.
*
* @since 5.4.0
* @param string $id Shortcode ID.
* @param array $atts Input values.
* @param array $extra Additional attributes.
* @return array Parsed values.
*/
function su_parse_shortcode_atts( $id, $atts, $extra = array() ) {
return shortcode_atts(
array_merge( su_get_shortcode_defaults( $id ), $extra ),
$atts,
$id
);
}
/**
* Custom do_shortcode function for nested shortcodes
*
* @since 5.0.4
* @param string $content Shortcode content.
* @param string $pre First shortcode letter.
* @return string Formatted content.
*/
function su_do_nested_shortcodes_alt( $content, $pre ) {
if ( strpos( $content, '[_' ) !== false ) {
$content = preg_replace( '@(\[_*)_(' . $pre . '|/)@', '$1$2', $content );
}
return do_shortcode( $content );
}
/**
* Remove underscores from nested shortcodes.
*
* @since 5.0.4
* @param string $content String with nested shortcodes.
* @param string $shortcode Shortcode tag name (without prefix).
* @return string Parsed string.
*/
function su_do_nested_shortcodes( $content, $shortcode ) {
if ( get_option( 'su_option_do_nested_shortcodes_alt' ) ) {
return su_do_nested_shortcodes_alt( $content, substr( $shortcode, 0, 1 ) );
}
$prefix = su_get_shortcode_prefix();
if ( strpos( $content, '[_' . $prefix . $shortcode ) !== false ) {
$content = str_replace(
array( '[_' . $prefix . $shortcode, '[_/' . $prefix . $shortcode ),
array( '[' . $prefix . $shortcode, '[/' . $prefix . $shortcode ),
$content
);
return do_shortcode( $content );
}
return do_shortcode( wptexturize( $content ) );
}
/**
* Get shortcode prefix.
*
* @since 5.0.5
* @return string Shortcode prefix.
*/
function su_get_shortcode_prefix() {
return get_option( 'su_option_prefix' );
}
/**
* Do shortcodes in attributes.
*
* Replace braces with square brackets: {shortcode} => [shortcode], applies do_shortcode() filter.
*
* @since 5.0.5
* @param string $value Attribute value with shortcodes.
* @return string Parsed string.
*/
function su_do_attribute( $value ) {
$value = str_replace( array( '{', '}' ), array( '[', ']' ), $value );
$value = do_shortcode( $value );
return $value;
}