PluginProbe
Snippet Shortcodes / 3.0.2
Snippet Shortcodes v3.0.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/functions.php +113 -8 2.03.0.2 View file →
@@ -9,9 +9,9 @@
9 9 */
10 10 function sh_cd_shortcodes_save_post() {
11 11
12 12 // Capture the raw $_POST fields, the save functions will process and validate the data
13 - $shortcode = sh_cd_get_values_from_post( [ 'id', 'slug', 'data', 'disabled' ] );
13 + $shortcode = sh_cd_get_values_from_post( [ 'id', 'slug', 'previous_slug', 'data', 'disabled', 'multisite' ] );
14 14
15 15 return sh_cd_db_shortcodes_save( $shortcode );
16 16 }
17 17
@@ -43,9 +43,9 @@
43 43 * @param $slug
44 44 *
45 45 * @return string
46 46 */
47 -function sh_cd_slug_generate( $slug ) {
47 +function sh_cd_slug_generate( $slug, $exising_id = NULL ) {
48 48
49 49 if ( true === empty( $slug ) ) {
50 50 return NULL;
51 51 }
@@ -56,9 +56,9 @@
56 56
57 57 $try = 1;
58 58
59 59 // Ensure the slug is unique
60 - while ( false === sh_cd_slug_is_unique( $slug ) ) {
60 + while ( false === sh_cd_slug_is_unique( $slug, $exising_id ) ) {
61 61
62 62 $slug = sprintf( '%s_%d', $original_slug, $try );
63 63
64 64 $try++;
@@ -67,8 +67,36 @@
67 67 return $slug;
68 68 }
69 69
70 70 /**
71 + * Clone an existing shortcode!
72 + *
73 + * @param $id
74 + *
75 + * @return bool
76 + */
77 +function sh_cd_clone( $id ) {
78 +
79 + if( false === sh_cd_license_is_premium() ) {
80 + return true;
81 + }
82 +
83 + if ( false === is_numeric( $id ) ) {
84 + return false;
85 + }
86 +
87 + $to_be_cloned = sh_cd_db_shortcodes_by_id( $id );
88 +
89 + if ( true === empty( $to_be_cloned ) ) {
90 + return false;
91 + }
92 +
93 + unset( $to_be_cloned['id'] );
94 +
95 + return sh_cd_db_shortcodes_save( $to_be_cloned );
96 +}
97 +
98 +/**
71 99 * Display message in admin UI
72 100 *
73 101 * @param $text
74 102 * @param bool $error
@@ -106,13 +134,16 @@
106 134 *
107 135 * @param $key
108 136 * @param $data
109 137 */
110 -function sh_cd_cache_set( $key, $data ) {
138 +function sh_cd_cache_set( $key, $data, $expire = NULL ) {
111 139
140 +
141 + $expire = ( false === empty( $expire ) ) ? (int) $expire : 1 * HOUR_IN_SECONDS;
142 +
112 143 $key = sh_cd_cache_generate_key( $key );
113 144
114 - set_transient( $key, $data, 1 * HOUR_IN_SECONDS );
145 + set_transient( $key, $data, $expire );
115 146 }
116 147
117 148 /**
118 149 * Delete cache for given shortcode slug / ID
@@ -122,13 +153,21 @@
122 153 function sh_cd_cache_delete_by_slug_or_key( $slug_or_key ) {
123 154
124 155 if ( true === is_numeric( $slug_or_key ) ) {
125 156
126 - sh_cd_cache_delete( sh_cd_db_shortcodes_get_slug_by_id( $slug_or_key ) );
157 + $slug_or_key = sh_cd_db_shortcodes_get_slug_by_id( $slug_or_key );
127 158
159 + sh_cd_cache_delete( $slug_or_key );
160 +
128 161 } else {
129 162 sh_cd_cache_delete( $slug_or_key );
130 163 }
164 +
165 + // Delete site option
166 + $slug_or_key = SH_CD_PREFIX . $slug_or_key;
167 +
168 + delete_site_option( $slug_or_key );
169 +
131 170 }
132 171
133 172 /**
134 173 * Delete cache item
@@ -151,9 +190,9 @@
151 190 *
152 191 * @return string
153 192 */
154 193 function sh_cd_cache_generate_key( $key ) {
155 - return SH_CD_SHORTCODE . $key;
194 + return SH_CD_SHORTCODE . SH_CD_PLUGIN_VERSION . $key;
156 195 }
157 196
158 197 /**
159 198 * Return link to list own shortcodes
@@ -266,9 +305,30 @@
266 305
267 306 return NULL;
268 307 }
269 308
309 +/**
310 + * Toggle the multisite of a shortcode
311 + *
312 + * @param $id
313 + */
314 +function sh_cd_toggle_multisite( $id ) {
270 315
316 + $slug = sh_cd_db_shortcodes_by_id( (int) $id );
317 +
318 + if ( false === empty( $slug ) ) {
319 +
320 + $multisite = ( 1 === (int) $slug['multisite'] ) ? 0 : 1 ;
321 +
322 + sh_cd_db_shortcodes_update_multisite( $id, $multisite );
323 +
324 + return $multisite;
325 + }
326 +
327 + return NULL;
328 +}
329 +
330 +
271 331 /**
272 332 * Display a table of premade shortcodes
273 333 *
274 334 * @param string $display
@@ -323,9 +383,9 @@
323 383 ( true == $premium_shortcode && false === $premium_user ) ? $upgrade_link : ''
324 384 );
325 385 }
326 386
327 - $html .= sprintf( '<td>%s</td></tr>', esc_html( $data['description'] ) );
387 + $html .= sprintf( '<td>%s</td></tr>', wp_kses_post( $data['description'] ) );
328 388
329 389 }
330 390
331 391 $html .= '</table>';
@@ -346,5 +406,50 @@
346 406 __('Upgrade to Premium for ', SH_CD_SLUG),
347 407 SH_CD_PREMIUM_PRICE,
348 408 __('a year ', SH_CD_SLUG)
349 409 );
410 +}
411 +
412 +/**
413 + * Is multsite functionality active for this install?
414 + *
415 + * @return bool
416 + */
417 +function sh_cd_is_multisite_enabled() {
418 +
419 + if ( false === is_multisite() ) {
420 + return false;
421 + }
422 +
423 + if ( false === sh_cd_license_is_premium() ) {
424 + return false;
425 + }
426 +
427 + return true;
428 +}
429 +
430 +/**
431 + * Fetch all multisite slugs
432 + *
433 + * @return array|null
434 + */
435 +function sh_cd_multisite_slugs() {
436 +
437 + if ( false === is_multisite() ) {
438 + return [];
439 + }
440 +
441 + $cache = sh_cd_cache_get( 'sh-cd-multisite-slugs' );
442 +
443 + if ( false !== $cache ) {
444 + return $cache;
445 + }
446 +
447 + $slugs = sh_cd_db_shortcodes_multisite_slugs();
448 +
449 + $slugs = ( false === empty( $slugs ) ) ? wp_list_pluck( $slugs, 'slug' ) : NULL;
450 +
451 + // Cache this for a short time
452 + sh_cd_cache_set( 'sh-cd-multisite-slugs', $slugs, 30 );
453 +
454 + return ( true === is_array( $slugs ) ) ? $slugs : [];
350 455 }