PluginProbe
Snippet Shortcodes / 4.1.6
Snippet Shortcodes v4.1.6
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 +100 -246 5.1.54.1.6 View file →
@@ -2,48 +2,8 @@
2 2
3 3 defined('ABSPATH') or die('Jog on!');
4 4
5 5 /**
6 - * Is the Premium plugin enabled and do we have a valid license?
7 - *
8 - * @return bool
9 - */
10 -function sh_cd_is_premium() {
11 -
12 - if ( false === sh_cd_is_premium_plugin_activated() ) {
13 - return false;
14 - }
15 -
16 - return apply_filters( 'sh-cd-license-is-premium', false );
17 -}
18 -
19 -/**
20 - * Is Premium plugin enabled?
21 - */
22 -function sh_cd_is_premium_plugin_activated() {
23 - return defined( 'YK_SS_PLUGIN_NAME' );
24 -}
25 -
26 -/**
27 - * Generate a site hash to identify this site.
28 - **/
29 -function sh_cd_generate_site_hash() {
30 -
31 - $site_hash = get_option( 'sh-cd-hash' );
32 -
33 - // Generate a basic site key from URL and plugin slug
34 - if( false == $site_hash ) {
35 -
36 - $site_hash = md5( 'yeken-sh-cd-' . site_url() );
37 - $site_hash = substr( $site_hash, 0, 6 );
38 -
39 - update_option( 'sh-cd-hash', $site_hash );
40 -
41 - }
42 - return $site_hash;
43 -}
44 -
45 -/**
46 6 * Save / Insert a shortcode
47 7 *
48 8 * @return bool
49 9 */
@@ -48,18 +8,11 @@
48 8 * @return bool
49 9 */
50 10 function sh_cd_shortcodes_save_post() {
51 11
52 - $fields = apply_filters( 'sh-cd-post-field-keys', [ 'id', 'slug', 'previous_slug', 'data', 'disabled', 'multisite', 'editor' ] );
53 -
54 12 // Capture the raw $_POST fields, the save functions will process and validate the data
55 - $shortcode = sh_cd_get_values_from_post( $fields );
13 + $shortcode = sh_cd_get_values_from_post( [ 'id', 'slug', 'previous_slug', 'data', 'disabled', 'multisite' ] );
56 14
57 - // If we are not premium, then the user is not allowed to change the site slug (otherwise they could just re-use variables and by pass the limit)
58 - if ( ! sh_cd_is_premium() && false === empty( $shortcode[ 'previous_slug' ] ) ) {
59 - $shortcode[ 'slug' ] = $shortcode[ 'previous_slug' ];
60 - }
61 -
62 15 return sh_cd_db_shortcodes_save( $shortcode );
63 16 }
64 17
65 18 /**
@@ -96,9 +49,9 @@
96 49 if ( true === empty( $slug ) ) {
97 50 return NULL;
98 51 }
99 52
100 - $slug = sanitize_key( $slug );
53 + $slug = sanitize_title( $slug );
101 54
102 55 $original_slug = $slug;
103 56
104 57 $try = 1;
@@ -122,9 +75,9 @@
122 75 * @return bool
123 76 */
124 77 function sh_cd_clone( $id ) {
125 78
126 - if( false === sh_cd_is_premium() ) {
79 + if( false === SH_CD_IS_PREMIUM ) {
127 80 return true;
128 81 }
129 82
130 83 if ( false === is_numeric( $id ) ) {
@@ -189,10 +142,8 @@
189 142
190 143 $key = sh_cd_cache_generate_key( $key );
191 144
192 145 set_transient( $key, $data, $expire );
193 -
194 - do_action( 'sh-cd-global-cache-delete' );
195 146 }
196 147
197 148 /**
198 149 * Delete cache for given shortcode slug / ID
@@ -224,20 +175,15 @@
224 175 * @param $key
225 176 *
226 177 * @return mixed
227 178 */
228 -function sh_cd_cache_delete( $key, $trigger_global_hook = true ) {
179 +function sh_cd_cache_delete( $key ) {
229 180
230 181 $key = sh_cd_cache_generate_key( $key );
231 182
232 - if ( true === $trigger_global_hook ) {
233 - do_action( 'sh-cd-global-cache-delete' );
234 - }
235 -
236 183 return delete_transient( $key );
237 184 }
238 185
239 -
240 186 /**
241 187 * Generate cache key
242 188 *
243 189 * @param $key
@@ -284,8 +230,21 @@
284 230 return esc_url( $link );
285 231 }
286 232
287 233 /**
234 + * Return link to delete own shortcode
235 + *
236 + * @param $id
237 + * @return mixed
238 + */
239 +function sh_cd_link_your_shortcodes_delete( $id ) {
240 +
241 + $link = admin_url('admin.php?page=sh-cd-shortcode-variables-your-shortcodes&action=delete&id=' . (int) $id );
242 +
243 + return esc_url( $link );
244 +}
245 +
246 +/**
288 247 * Either fetch data from the $_POST object or from the array passed in!
289 248 *
290 249 * @param $object
291 250 * @param $key
@@ -369,27 +328,73 @@
369 328
370 329 return NULL;
371 330 }
372 331
332 +
373 333 /**
374 - * Display an upgrade button
334 + * Display a table of premade shortcodes
375 335 *
376 - * @param string $css_class
377 - * @param null $link
336 + * @param string $display
337 + * @return string
378 338 */
379 -function sh_cd_upgrade_button( $css_class = '', $link = NULL ) {
339 +function sh_cd_display_premade_shortcodes( $display = 'all' ) {
380 340
381 - $link = ( false === empty( $link ) ) ? $link : SH_CD_UPGRADE_LINK . '?hash=' . sh_cd_generate_site_hash() ;
341 + $premium_user = SH_CD_IS_PREMIUM;
342 + $upgrade_link = sprintf( '<a class="button" href="%1$s"><i class="fas fa-check"></i> %2$s</a>', sh_cd_license_upgrade_link(), __('Upgrade now', SH_CD_SLUG ) );
382 343
383 - $price = sh_cd_license_price();
384 - $price = ( false === empty( $price ) ) ? sprintf( '- £%s %s', $price, __( 'a year ', SH_CD_SLUG ) ) : '';
344 + switch ( $display ) {
345 + case 'free':
346 + $shortcodes = sh_cd_shortcode_presets_free_list();
347 + $show_premium_col = false;
348 + break;
349 + case 'premium':
350 + $shortcodes = sh_cd_shortcode_presets_premium_list();
351 + $show_premium_col = false;
352 + break;
353 + default:
354 + $shortcodes = sh_cd_presets_both_lists();
355 + $show_premium_col = true;
356 + }
385 357
386 - echo sprintf('<a href="%s" class="button-primary sh-cd-upgrade-button sh-cd-button %s"><i class="far fa-star"></i> %s %s</a>',
387 - esc_url( $link ),
388 - esc_attr( ' ' . $css_class ),
389 - __( 'Purchase a license ', SH_CD_SLUG ),
390 - $price
391 - );
358 + $html = sprintf('<table class="widefat sh-cd-table" width="100%%">
359 + <tr class="row-title">
360 + <th class="row-title" width="30%%">%s</th>', __('Shortcode', SH_CD_SLUG ) );
361 +
362 + if ( true === $show_premium_col) {
363 + $html .= sprintf( '<th class="row-title">%s</th>', __('Premium', SH_CD_SLUG ) );
364 + }
365 +
366 + $html .= sprintf( '<th width="*">%s</th>
367 + </tr>', __('Description', SH_CD_SLUG ) );
368 +
369 + $class = '';
370 +
371 + foreach ( $shortcodes as $key => $data ) {
372 +
373 + $class = ($class == 'alternate') ? '' : 'alternate';
374 +
375 + $shortcode = '[' . SH_CD_SHORTCODE. ' slug="' . $key . '"]';
376 +
377 + $premium_shortcode = ( true === isset( $data['premium'] ) && true === $data['premium'] );
378 +
379 + $html .= sprintf( '<tr class="%s"><td>%s</td>', $class, esc_html( $shortcode ) );
380 +
381 +
382 + if ( true === $show_premium_col) {
383 +
384 + $html .= sprintf( '<td align="middle">%s%s</td>',
385 + ( true === $premium_shortcode && true === $premium_user ) ? '<i class="fas fa-check"></i>' : '',
386 + ( true == $premium_shortcode && false === $premium_user ) ? $upgrade_link : ''
387 + );
388 + }
389 +
390 + $html .= sprintf( '<td>%s</td></tr>', wp_kses_post( $data['description'] ) );
391 +
392 + }
393 +
394 + $html .= '</table>';
395 +
396 + return $html;
392 397 }
393 398
394 399 /**
395 400 * Display an upgrade button
@@ -396,22 +401,19 @@
396 401 *
397 402 * @param string $css_class
398 403 * @param null $link
399 404 */
400 -function sh_cd_premium_shortcode_download( $return = false ) {
405 +function sh_cd_upgrade_button( $css_class = '', $link = NULL ) {
401 406
402 - $link = SH_CD_GET_PREMIUM_LINK . '?hash=' . sh_cd_generate_site_hash();
407 + $link = ( false === empty( $link ) ) ? $link : SH_CD_UPGRADE_LINK . '?hash=' . sh_cd_generate_site_hash() ;
403 408
404 - $html = sprintf('<a href="%s" class="button-primary sh-cd-button sh-cd-upgrade-button"><i class="fas fa-download"></i> %s</a>',
409 + echo sprintf('<a href="%s" class="button-primary sh-cd-upgrade-button%s"><i class="far fa-credit-card"></i> %s £%s %s</a>',
405 410 esc_url( $link ),
406 - __( 'Download Premium Plugin', SH_CD_SLUG )
411 + esc_attr( ' ' . $css_class ),
412 + __( 'Upgrade to Premium for ', SH_CD_SLUG ),
413 + esc_html( sh_cd_license_price() ),
414 + __( 'a year ', SH_CD_SLUG )
407 415 );
408 -
409 - if ( true === $return ) {
410 - return $html;
411 - }
412 -
413 - echo $html;
414 416 }
415 417
416 418 /**
417 419 * Is multsite functionality active for this install?
@@ -419,17 +421,13 @@
419 421 * @return bool
420 422 */
421 423 function sh_cd_is_multisite_enabled() {
422 424
423 - if ( true === defined( 'YK_TEST_IS_MULTISITE' ) && true === YK_TEST_IS_MULTISITE ) {
424 - return true;
425 - }
426 -
427 425 if ( false === is_multisite() ) {
428 426 return false;
429 427 }
430 428
431 - if ( false === sh_cd_is_premium() ) {
429 + if ( false === SH_CD_IS_PREMIUM ) {
432 430 return false;
433 431 }
434 432
435 433 return true;
@@ -467,9 +465,9 @@
467 465 * @return bool
468 466 */
469 467 function sh_cd_reached_free_limit() {
470 468
471 - if ( true === sh_cd_is_premium() ) {
469 + if ( true === SH_CD_IS_PREMIUM ) {
472 470 return false;
473 471 }
474 472
475 473 $existing_shortcodes = sh_cd_db_shortcodes_count();
@@ -477,19 +475,12 @@
477 475 if ( true === empty( $existing_shortcodes ) ) {
478 476 return false;
479 477 }
480 478
481 - return ( (int) $existing_shortcodes >= sh_cd_get_free_limit() );
479 + return ( (int) $existing_shortcodes >= SH_CD_FREE_SHORTCODE_LIMIT );
482 480 }
483 481
484 482 /**
485 - * Return free limit for shortcodes
486 - */
487 -function sh_cd_get_free_limit() {
488 - return 10;
489 -}
490 -
491 -/**
492 483 * Get the minimum user role allowed for viewing data pages in admin
493 484 * @return mixed|void
494 485 */
495 486 function sh_cd_permission_role() {
@@ -494,9 +485,9 @@
494 485 */
495 486 function sh_cd_permission_role() {
496 487
497 488 // If not premium, then admin only
498 - if ( false === sh_cd_is_premium() ) {
489 + if ( false === SH_CD_IS_PREMIUM ) {
499 490 return 'manage_options';
500 491 }
501 492
502 493 $permission_role = get_option( 'sh-cd-edit-permissions', 'manage_options' );
@@ -521,9 +512,9 @@
521 512 * @return bool (default false)
522 513 */
523 514 function sh_cd_is_shortcode_db_value_by_id_enabled() {
524 515
525 - if ( false === sh_cd_is_premium() ) {
516 + if ( false === SH_CD_IS_PREMIUM ) {
526 517 return false;
527 518 }
528 519
529 520 // Disabling by filter overrides the setting in WP admin
@@ -540,48 +531,21 @@
540 531 * Display upgrade notice
541 532 *
542 533 * @param bool $pro_plus
543 534 */
544 -function sh_cd_display_pro_upgrade_notice( $title = NULL, $content = '', $class = '' ) {
545 -
546 - $title = ( true === empty( $title ) ) ? __( 'Upgrade Snippet Shortcodes and get more features!', SH_CD_SLUG ) : $title;
535 +function sh_cd_display_pro_upgrade_notice( ) {
536 + ?>
547 537
548 - ?>
549 - <div class="postbox sh-cd-advertise-premium <?php echo esc_attr( $class ) ?>">
550 - <h3 class="hndle"><i class="fa-regular fa-star"></i> <?php echo esc_html( $title ) ?></h3>
538 + <div class="postbox sh-cd-advertise-premium">
539 + <h3 class="hndle"><span><?php echo __( 'Upgrade Snippet Shortcodes and get more features!', SH_CD_SLUG ); ?> </span></h3>
551 540 <div style="padding: 0px 15px 0px 15px">
552 - <p><?php echo wp_kses( $content, [ 'ul' => [ 'class' ], 'li' => [], 'strong' => [], 'span' => [], 'div' => [] ] ); ?></p>
553 - <p><a href="<?php echo esc_url( admin_url('admin.php?page=sh-cd-shortcode-variables-upgrade') ); ?>" class="button-primary sh-cd-upgrade-button"><i class="fa-regular fa-star"></i> <?php echo __( 'Get Premium', SH_CD_SLUG ); ?></a></p>
541 + <p><a href="<?php echo esc_url( admin_url('admin.php?page=sh-cd-shortcode-variables-license') ); ?>" class="button-primary"><?php echo __( 'Upgrade now', SH_CD_SLUG ); ?></a></p>
554 542 </div>
555 543 </div>
556 -<?php
557 -}
558 544
559 -/**
560 - * Display a star to prompt for a Premioum upgrade
561 - *
562 - * @param bool $pro_plus
563 - */
564 -function sh_cd_display_premium_star() {
565 -
566 - if ( true === sh_cd_is_premium() ) {
567 - return ''; // We don't want to show the star if the user has already upgraded
568 - }
569 -
570 - return sprintf ('<a href="%s"><i class="fa-regular fa-star"></i></a>',
571 - esc_url( admin_url('admin.php?page=sh-cd-shortcode-variables-upgrade') )
572 - );
545 + <?php
573 546 }
574 -
575 -/**
576 - * Display info symbol with tooltip
577 - */
578 -function sh_cd_display_info_tooltip( $text ) {
579 547
580 - return sprintf ('<i class="fa-regular fa-circle-question sh-cd-tooltip" title="%s">',
581 - esc_html( $text )
582 - );
583 -}
584 548
585 549 /**
586 550 * Process a CSV attachment and import into database
587 551 *
@@ -592,11 +556,13 @@
592 556 * @return string
593 557 */
594 558 function sh_cd_import_csv( $attachment_id, $dry_run = true ) {
595 559
596 - sh_cd_permission_check();
560 + if ( false === sh_cd_permission_check() ) {
561 + return 'You do not have the correct admin permissions';
562 + }
597 563
598 - if ( false === sh_cd_is_premium() ) {
564 + if ( false === SH_CD_IS_PREMIUM ) {
599 565 return 'This is a premium feature';
600 566 }
601 567
602 568 $csv_path = get_attached_file( $attachment_id );
@@ -713,10 +679,10 @@
713 679 if ( true === empty( $csv_row[ 'slug' ] ) ) {
714 680 return 'Skipped: Missing slug: ' . implode( ',', $csv_row );
715 681 }
716 682
717 - if ( true === empty( $csv_row[ 'content' ] ) ) {
718 - return 'Skipped: Missing content: ' . implode( ',', $csv_row );
683 + if ( false === empty( $isset[ 'content' ] ) ) {
684 + return 'Skipped: Content: ' . implode( ',', $csv_row );
719 685 }
720 686
721 687 $allowed_bools = [ 'yes', 'no', 'true', 'false', '1', '0' ];
722 688
@@ -740,116 +706,4 @@
740 706 */
741 707 function sh_cd_to_bool( $string ) {
742 708 return filter_var( $string, FILTER_VALIDATE_BOOLEAN );
743 709 }
744 -
745 -/**
746 - * Our version of kses and the HTML we are happy with
747 - */
748 -function sh_cd_wp_kses( $value ) {
749 -
750 - $basic_tags = wp_kses_allowed_html( 'html' );
751 -
752 - $basic_tags[ 'a' ] = [ 'id' => true, 'class' => true, 'href' => true, 'title' => true, 'target' => true];
753 - $basic_tags[ 'canvas' ] = [ 'id' => true, 'class' => true ];
754 - $basic_tags[ 'div' ] = [ 'id' => true, 'class' => true, 'style' => true ];
755 - $basic_tags[ 'i' ] = [ 'id' => true, 'class' => true ];
756 - $basic_tags[ 'p' ] = [ 'id' => true, 'class' => true ];
757 - $basic_tags[ 'span' ] = [ 'id' => true, 'class' => true ];
758 - $basic_tags[ 'table' ] = [ 'id' => true, 'class' => true ];
759 - $basic_tags[ 'tr' ] = [ 'id' => true, 'class' => true ];
760 - $basic_tags[ 'td' ] = [ 'id' => true, 'class' => true ];
761 - $basic_tags[ 'li' ] = [ 'class' => true ];
762 -
763 - return wp_kses( $value, $basic_tags );
764 -}
765 -
766 -/**
767 - * Return the current url
768 - */
769 -function sh_cd_get_current_url() {
770 - $protocol = (
771 - ( isset($_SERVER['HTTPS'] ) && 'on' == $_SERVER['HTTPS'] ) ||
772 - ( isset($_SERVER['SERVER_PORT'] ) && 443 == $_SERVER['SERVER_PORT'] )
773 - ) ? 'https://' : 'http://';
774 -
775 - return $protocol . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
776 -}
777 -
778 -/**
779 - * Get selected default editor
780 - */
781 -function sh_cd_default_editor_get() {
782 - return get_option( 'sh-cd-option-default-editor', 'tinymce' );
783 -}
784 -
785 -/**
786 - * Is editor valid
787 - */
788 -function sh_cd_editors_is_valid( $editor ) {
789 - $editors = sh_cd_editors_options();
790 -
791 - return ! empty( $editors[ $editor ] );
792 -}
793 -
794 -/**
795 - * Return valid editors
796 - */
797 -function sh_cd_editors_options( $keys_only = true ) {
798 - return [ 'tinymce' => __( 'WordPress Editor', SH_CD_SLUG ), 'code' => __( 'HTML Editor', SH_CD_SLUG ) ];
799 -}
800 -
801 -/**
802 - * Are tooltips enabled?
803 - */
804 -function sh_cd_tooltips_is_enabled() {
805 - return ( 'yes' === get_option( 'sh-cd-option-tool-tips-enabled', 'yes' ) );
806 -}
807 -
808 -/**
809 - * Fetch icons for given shortcode
810 - *
811 - * @param [type] $shortcode
812 - * @param boolean $return_array
813 - * @return void
814 - */
815 -function sh_cd_icons_for_shortcode( $shortcode, $return_array = false ) {
816 -
817 - if ( true === empty( $shortcode ) ) {
818 - return [];
819 - }
820 -
821 - $icons = [];
822 -
823 - if ( false === empty( $shortcode[ 'header' ] ) ) {
824 - $icons[] = sprintf( '<i class="fa-solid fa-heading sh-cd-option-icon sh-cd-tooltip" title="%s"></i>', esc_html( __( 'Insert into WP Header', SH_CD_SLUG ) ) );
825 - }
826 -
827 - if ( false === empty( $shortcode[ 'footer' ] ) ) {
828 - $icons[] = sprintf( '<i class="fa-solid fa-shoe-prints sh-cd-option-icon sh-cd-tooltip" title="%s"></i>', esc_html( __( 'Insert into WP Footer', SH_CD_SLUG ) ) );
829 - }
830 -
831 - if ( false === empty( $shortcode[ 'device_type' ] ) ) {
832 - $shortcode[ 'device_type' ] = json_decode( $shortcode[ 'device_type' ] );
833 - }
834 -
835 - if ( true === is_array( $shortcode[ 'device_type' ] ) ) {
836 -
837 - if ( true === in_array( 'desktop', $shortcode[ 'device_type' ] ) ) {
838 - $icons[] = sprintf( '<i class="fa-solid fa-desktop sh-cd-option-icon sh-cd-tooltip" title="%s"></i>', esc_html( __( 'Display only on desktop devices', SH_CD_SLUG ) ) );
839 - }
840 -
841 - if ( true === in_array( 'mobile', $shortcode[ 'device_type' ] ) ) {
842 - $icons[] = sprintf( '<i class="fa-solid fa-mobile-screen sh-cd-option-icon sh-cd-tooltip" title="%s"></i>', esc_html( __( 'Display only on mobile devices', SH_CD_SLUG ) ) );
843 - }
844 -
845 - if ( true === in_array( 'tablet', $shortcode[ 'device_type' ] ) ) {
846 - $icons[] = sprintf( '<i class="fa-solid fa-tablet-screen-button sh-cd-option-icon sh-cd-tooltip" title="%s"></i>', esc_html( __( 'Display only on tablet devices', SH_CD_SLUG ) ) );
847 - }
848 - }
849 -
850 - if ( true === $return_array ) {
851 - return $icons;
852 - }
853 -
854 - return ( false === empty( $icons ) ) ? implode( PHP_EOL, $icons ) : '';
855 -}