PluginProbe
Snippet Shortcodes / 2.2
Snippet Shortcodes v2.2
5.2.1 5.2 5.1.8 5.1.6 5.1.7 5.1.5 trunk 1.0 1.1 1.2 1.3 1.3.1 1.4 1.5 1.5.1 1.6 1.6.1 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.8 2.0 2.0.1 All 74 releases
← All changes | includes/shortcode.presets.core.php +180 -132 trunk2.2 View file →
@@ -1,132 +1,180 @@
1 -<?php
2 -
3 -defined('ABSPATH') or die("Jog on!");
4 -
5 -/**
6 - * Determine if the slug belongs to a preset
7 - * @param $slug
8 - */
9 -function sh_cd_is_preset( $slug ) {
10 -
11 - $slug = sh_cd_prep_slug( $slug );
12 -
13 - // Free preset?
14 - if ( true === array_key_exists( $slug, sh_cd_shortcode_presets_free_list() ) ) {
15 - return 'free';
16 - }
17 -
18 - // Premium preset?
19 - if ( true === array_key_exists( $slug, sh_cd_shortcode_presets_premium_list() ) ) {
20 - return 'premium';
21 - }
22 -
23 - return false;
24 -}
25 -
26 -/**
27 - * Remove old references to the "sc-" prefix
28 - */
29 -function sh_cd_prep_slug( $slug ) {
30 -
31 - $slug = str_replace( 'sc-', '', $slug );
32 -
33 - return $slug;
34 -}
35 -
36 -/**
37 - * Return all free and premium premade shortcodes
38 - *
39 - * @return array
40 - */
41 -function sh_cd_presets_both_lists() {
42 -
43 - $both = array_merge( sh_cd_shortcode_presets_free_list(), sh_cd_shortcode_presets_premium_list() );
44 -
45 - ksort( $both );
46 -
47 - return $both;
48 -}
49 -
50 -/**
51 - * For a given preset, look up the class information, if valid, initiate the class and render
52 - *
53 - * @param $args
54 - *
55 - * @return string
56 - */
57 -function sh_cd_shortcode_presets_render( $args ) {
58 -
59 - $preset = sh_cd_shortcode_presets_fetch( $args[ 'slug' ] );
60 -
61 - // Not a preset?
62 - if ( false === $preset ) {
63 - return '';
64 - }
65 -
66 - // Is this a premium shortcode but no license?
67 - if ( 'premium' === $preset['sh-cd-type'] && false === sh_cd_is_premium() ) {
68 - return sprintf( '<p><strong>%s</strong> %s. <a href="%s">%s</a>.<p>',
69 - __( 'Ooops!', SH_CD_SLUG ),
70 - __('Unfortunately this is a Premium shortcode. You need to upgrade "Snippet Shortcodes" to use it', SH_CD_SLUG ),
71 - sh_cd_license_upgrade_link(),
72 - __('Upgrade now', SH_CD_SLUG )
73 - );
74 - }
75 -
76 - $class_name = 'SV_' . $preset[ 'class' ];
77 -
78 - if ( true === class_exists( $class_name ) ) {
79 -
80 - $shortcode = new $class_name();
81 -
82 - // Any plugin arguments?
83 - if ( false === empty( $preset['args'] ) ) {
84 - $args = array_merge( $args, $preset['args'] );
85 - }
86 -
87 - $shortcode->set_arguments( $args );
88 -
89 - $shortcode->init();
90 -
91 - return $shortcode->sanitised();
92 - }
93 -
94 - return '';
95 -}
96 -
97 -/**
98 - * For a given slug, fetch the preset information regarding it.
99 - *
100 - * @param $slug
101 - *
102 - * @return bool
103 - */
104 -function sh_cd_shortcode_presets_fetch( $slug ) {
105 -
106 - $slug = sh_cd_prep_slug( $slug );
107 -
108 - $free_presets = sh_cd_shortcode_presets_free_list();
109 -
110 - // Free preset?
111 - if ( true === array_key_exists( $slug, $free_presets ) ) {
112 -
113 - $preset = $free_presets[ $slug ];
114 - $preset['sh-cd-type'] = 'free';
115 -
116 - return $preset;
117 - }
118 -
119 - $premium_presents = sh_cd_shortcode_presets_premium_list();
120 -
121 - // Premium preset?
122 - if ( true === array_key_exists( $slug, $premium_presents ) ) {
123 -
124 - $preset = $premium_presents[ $slug ];
125 - $preset['sh-cd-type'] = 'premium';
126 -
127 - return $preset;
128 - }
129 -
130 - return false;
131 -
132 -}
1 +<?php
2 +
3 +defined('ABSPATH') or die("Jog on!");
4 +
5 +/**
6 + * Determine if the slug belongs to a preset
7 + * @param $slug
8 + */
9 +function sh_cd_is_preset( $slug ) {
10 +
11 + // Free preset?
12 + if ( true === array_key_exists( $slug, sh_cd_shortcode_presets_free_list() ) ) {
13 + return 'free';
14 + }
15 +
16 + // Premium preset?
17 + if ( true === array_key_exists( $slug, sh_cd_shortcode_presets_premium_list() ) ) {
18 + return 'premium';
19 + }
20 +
21 + return false;
22 +}
23 +
24 +/**
25 + * Return all free and premium premade shortcodes
26 + *
27 + * @return array
28 + */
29 +function sh_cd_presets_both_lists() {
30 +
31 + $both = array_merge( sh_cd_shortcode_presets_free_list(), sh_cd_shortcode_presets_premium_list() );
32 +
33 + ksort( $both );
34 +
35 + return $both;
36 +}
37 +
38 +/**
39 + * For a given preset, look up the class information, if valid, initiate the class and render
40 + *
41 + * @param $args
42 + *
43 + * @return string
44 + */
45 +function sh_cd_shortcode_presets_render( $args ) {
46 +
47 + $preset = sh_cd_shortcode_presets_fetch( $args[ 'slug' ] );
48 +
49 + // Not a preset?
50 + if ( false === $preset ) {
51 + return '';
52 + }
53 +
54 + // Is this a premium shortcode but no license?
55 + if ( 'premium' === $preset['sh-cd-type'] && false === sh_cd_license_is_premium() ) {
56 + return sprintf( '<p><strong>%s</strong> %s. <a href="%s">%s</a>.<p>',
57 + __( 'Ooops!', SH_CD_SLUG ),
58 + __('Unfortunately this is a Premium shortcode. You need to upgrade "Shortcode Variables" to use it', SH_CD_SLUG ),
59 + sh_cd_license_upgrade_link(),
60 + __('Upgrade now', SH_CD_SLUG )
61 + );
62 + }
63 +
64 + $class_name = 'SV_' . $preset[ 'class' ];
65 +
66 + if ( true === class_exists( $class_name ) ) {
67 +
68 + $shortcode = new $class_name();
69 +
70 + // Any plugin arguments?
71 + if ( false === empty( $preset['args'] ) ) {
72 + $args = array_merge( $args, $preset['args'] );
73 + }
74 +
75 + $shortcode->set_arguments( $args );
76 +
77 + $shortcode->init();
78 +
79 + return $shortcode->sanitised();
80 + }
81 +
82 + return '';
83 +}
84 +
85 +/**
86 + * For a given slug, fetch the preset information regarding it.
87 + *
88 + * @param $slug
89 + *
90 + * @return bool
91 + */
92 +function sh_cd_shortcode_presets_fetch( $slug ) {
93 +
94 + $free_presets = sh_cd_shortcode_presets_free_list();
95 +
96 + // Free preset?
97 + if ( true === array_key_exists( $slug, $free_presets ) ) {
98 +
99 + $preset = $free_presets[ $slug ];
100 + $preset['sh-cd-type'] = 'free';
101 +
102 + return $preset;
103 + }
104 +
105 + $premium_presents = sh_cd_shortcode_presets_premium_list();
106 +
107 + // Premium preset?
108 + if ( true === array_key_exists( $slug, $premium_presents ) ) {
109 +
110 + $preset = $premium_presents[ $slug ];
111 + $preset['sh-cd-type'] = 'premium';
112 +
113 + return $preset;
114 + }
115 +
116 + return false;
117 +
118 +}
119 +
120 +/**
121 + * Render text file for promo
122 + */
123 +function sh_cd_shortcode_render_text() {
124 +
125 + $output = '**Premium Shortcodes**' . PHP_EOL;
126 +
127 + $shortcodes = sh_cd_shortcode_presets_premium_list();
128 +
129 + foreach ( $shortcodes as $key => $data ) {
130 + $output .= sprintf('- %s - %s' . PHP_EOL , $key, $data['description'] );
131 + }
132 +
133 + $output .= '**Free Shortcodes**' . PHP_EOL;
134 +
135 + $shortcodes = sh_cd_shortcode_presets_free_list();
136 +
137 + foreach ( $shortcodes as $key => $data ) {
138 + $output .= sprintf('- %s - %s' . PHP_EOL , $key, $data['description'] );
139 + }
140 +
141 + return $output;
142 +
143 +}
144 +add_shortcode( 'sv-promo', 'sh_cd_shortcode_render_text' );
145 +
146 +/**
147 + * Shortcode to render free shortcodes (more for promo purposes)
148 + *
149 + * @return string
150 + */
151 +function sh_cd_shortcode_render_table_free() {
152 +
153 + return sh_cd_display_premade_shortcodes( 'free' );
154 +
155 +}
156 +add_shortcode( 'sv-promo-free', 'sh_cd_shortcode_render_table_free');
157 +
158 +/**
159 + * Shortcode to render premium shortcodes (more for promo purposes)
160 + *
161 + * @return string
162 + */
163 +function sh_cd_shortcode_render_table_premium() {
164 +
165 + return sh_cd_display_premade_shortcodes( 'premium' );
166 +
167 +}
168 +add_shortcode( 'sv-promo-premium', 'sh_cd_shortcode_render_table_premium');
169 +
170 +/**
171 + * Shortcode to render all shortcodes (more for promo purposes)
172 + *
173 + * @return string
174 + */
175 +function sh_cd_shortcode_render_table_all() {
176 +
177 + return sh_cd_display_premade_shortcodes();
178 +
179 +}
180 +add_shortcode( 'sv-promo-all', 'sh_cd_shortcode_render_table_all');