-
Notifications
You must be signed in to change notification settings - Fork 0
/
sm-functions.php
115 lines (86 loc) · 3.05 KB
/
sm-functions.php
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
<?php
function sm_get_all_shortcode_packages() {
return apply_filters('smps_package_dir', array(
'simple-light' => 'Simple Light'
));
}
function sm_save_shortcode_packages( $data ) {
update_option( 'sm_shortcode_package_list', $data );
}
function sm_get_shortcode_packages() {
$sm_shortcode_packages = get_option( 'sm_shortcode_package_list' );
return !is_array( $sm_shortcode_packages ) ? array() : $sm_shortcode_packages;
}
if( !function_exists( 'sm_is_pro' ) ) {
function sm_is_pro() {
if( is_file( SHORTCODE_MAKER_ROOT.'/pro/loader.php' ) ) {
return true;
} else {
return false;
}
}
}
if( !function_exists( 'sm_get_notice' ) ) {
function sm_get_notice ( $notice_name = 'sm_admin_notices' ) {
$notice = get_option( $notice_name );
if( !is_array( $notice ) ) $notice = array();
return $notice;
}
}
if( !function_exists( 'pri' ) ) {
function pri($data) {
echo '<pre>';print_r($data);echo '</pre>';
}
}
if( !function_exists( 'sm_get_package_settings' ) ) {
function sm_get_package_settings( $classname = '', $slug = '' ) {
if( $classname ) {
if( !class_exists( $classname ) ) return;
return $classname::settings();
}
if( $slug ) {
$classname = 'Smps_'.ucwords(str_replace('-','_',$slug),'_');
return $classname::settings();
}
}
}
if( !function_exists( 'sm_get_package_classname' ) ) {
function sm_get_package_classname( $slug = '') {
return $classname = 'Smps_'.ucwords(str_replace('-','_',$slug),'_');
}
}
if( !function_exists( 'sm_extract_shortcode_atts' ) ) {
function sm_extract_shortcode_atts ( $content, $ignore_html = false ) {
global $shortcode_tags;
if ( false === strpos( $content, '[' ) ) {
return $content;
}
if (empty($shortcode_tags) || !is_array($shortcode_tags))
return $content;
// Find all registered tag names in $content.
preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches );
$tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] );
if ( empty( $tagnames ) ) {
return $content;
}
$content = do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames );
$pattern = get_shortcode_regex( $tagnames );
$atts = preg_replace_callback( "/$pattern/", 'sm_get_all_atts', $content);
// Always restore square braces so we don't break things like <!--[if IE ]>
//$content = unescape_invalid_shortcodes( $content );
$atts = json_decode($atts,true);
return $atts;
}
}
if( !function_exists( 'sm_get_all_atts' ) ) {
function sm_get_all_atts( $m ) {
global $shortcode_tags;
// allow [[foo]] syntax for escaping a tag
if ( $m[1] == '[' && $m[6] == ']' ) {
return substr($m[0], 1, -1);
}
$tag = $m[2];
$attr = shortcode_parse_atts( $m[3] );
return json_encode($attr);
}
}