PluginProbe
Snippet Shortcodes / 4.2.3
Snippet Shortcodes v4.2.3
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 +112 -358 5.24.2.3 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,16 @@
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 15 // 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' ] ) ) {
16 + if ( ! SH_CD_IS_PREMIUM && false === empty( $shortcode[ 'previous_slug' ] ) ) {
59 17 $shortcode[ 'slug' ] = $shortcode[ 'previous_slug' ];
60 18 }
61 -
19 +
62 20 return sh_cd_db_shortcodes_save( $shortcode );
63 21 }
64 22
65 23 /**
@@ -77,9 +35,9 @@
77 35 return $shortcode;
78 36 }
79 37
80 38 foreach ( $user_defined_parameters as $key => $value ) {
81 - $shortcode = str_replace( '%%' . $key . '%%', esc_attr( $value ), $shortcode );
39 + $shortcode = str_replace( '%%' . $key . '%%', $value, $shortcode );
82 40 }
83 41
84 42 return $shortcode;
85 43 }
@@ -96,9 +54,9 @@
96 54 if ( true === empty( $slug ) ) {
97 55 return NULL;
98 56 }
99 57
100 - $slug = sanitize_key( $slug );
58 + $slug = sanitize_title( $slug );
101 59
102 60 $original_slug = $slug;
103 61
104 62 $try = 1;
@@ -122,9 +80,9 @@
122 80 * @return bool
123 81 */
124 82 function sh_cd_clone( $id ) {
125 83
126 - if( false === sh_cd_is_premium() ) {
84 + if( false === SH_CD_IS_PREMIUM ) {
127 85 return true;
128 86 }
129 87
130 88 if ( false === is_numeric( $id ) ) {
@@ -189,10 +147,8 @@
189 147
190 148 $key = sh_cd_cache_generate_key( $key );
191 149
192 150 set_transient( $key, $data, $expire );
193 -
194 - do_action( 'sh-cd-global-cache-delete' );
195 151 }
196 152
197 153 /**
198 154 * Delete cache for given shortcode slug / ID
@@ -224,20 +180,15 @@
224 180 * @param $key
225 181 *
226 182 * @return mixed
227 183 */
228 -function sh_cd_cache_delete( $key, $trigger_global_hook = true ) {
184 +function sh_cd_cache_delete( $key ) {
229 185
230 186 $key = sh_cd_cache_generate_key( $key );
231 187
232 - if ( true === $trigger_global_hook ) {
233 - do_action( 'sh-cd-global-cache-delete' );
234 - }
235 -
236 188 return delete_transient( $key );
237 189 }
238 190
239 -
240 191 /**
241 192 * Generate cache key
242 193 *
243 194 * @param $key
@@ -284,8 +235,21 @@
284 235 return esc_url( $link );
285 236 }
286 237
287 238 /**
239 + * Return link to delete own shortcode
240 + *
241 + * @param $id
242 + * @return mixed
243 + */
244 +function sh_cd_link_your_shortcodes_delete( $id ) {
245 +
246 + $link = admin_url('admin.php?page=sh-cd-shortcode-variables-your-shortcodes&action=delete&id=' . (int) $id );
247 +
248 + return esc_url( $link );
249 +}
250 +
251 +/**
288 252 * Either fetch data from the $_POST object or from the array passed in!
289 253 *
290 254 * @param $object
291 255 * @param $key
@@ -369,27 +333,73 @@
369 333
370 334 return NULL;
371 335 }
372 336
337 +
373 338 /**
374 - * Display an upgrade button
339 + * Display a table of premade shortcodes
375 340 *
376 - * @param string $css_class
377 - * @param null $link
341 + * @param string $display
342 + * @return string
378 343 */
379 -function sh_cd_upgrade_button( $css_class = '', $link = NULL ) {
344 +function sh_cd_display_premade_shortcodes( $display = 'all' ) {
380 345
381 - $link = ( false === empty( $link ) ) ? $link : SH_CD_UPGRADE_LINK . '?hash=' . sh_cd_generate_site_hash() ;
346 + $premium_user = SH_CD_IS_PREMIUM;
347 + $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 348
383 - $price = sh_cd_license_price();
384 - $price = ( false === empty( $price ) ) ? sprintf( '- £%s %s', $price, __( 'a year ', SH_CD_SLUG ) ) : '';
349 + switch ( $display ) {
350 + case 'free':
351 + $shortcodes = sh_cd_shortcode_presets_free_list();
352 + $show_premium_col = false;
353 + break;
354 + case 'premium':
355 + $shortcodes = sh_cd_shortcode_presets_premium_list();
356 + $show_premium_col = false;
357 + break;
358 + default:
359 + $shortcodes = sh_cd_presets_both_lists();
360 + $show_premium_col = true;
361 + }
385 362
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 - );
363 + $html = sprintf('<table class="widefat sh-cd-table" width="100%%">
364 + <tr class="row-title">
365 + <th class="row-title" width="30%%">%s</th>', __('Shortcode', SH_CD_SLUG ) );
366 +
367 + if ( true === $show_premium_col) {
368 + $html .= sprintf( '<th class="row-title">%s</th>', __('Premium', SH_CD_SLUG ) );
369 + }
370 +
371 + $html .= sprintf( '<th width="*">%s</th>
372 + </tr>', __('Description', SH_CD_SLUG ) );
373 +
374 + $class = '';
375 +
376 + foreach ( $shortcodes as $key => $data ) {
377 +
378 + $class = ($class == 'alternate') ? '' : 'alternate';
379 +
380 + $shortcode = '[' . SH_CD_SHORTCODE. ' slug="' . $key . '"]';
381 +
382 + $premium_shortcode = ( true === isset( $data['premium'] ) && true === $data['premium'] );
383 +
384 + $html .= sprintf( '<tr class="%s"><td>%s</td>', $class, esc_html( $shortcode ) );
385 +
386 +
387 + if ( true === $show_premium_col) {
388 +
389 + $html .= sprintf( '<td align="middle">%s%s</td>',
390 + ( true === $premium_shortcode && true === $premium_user ) ? '<i class="fas fa-check"></i>' : '',
391 + ( true == $premium_shortcode && false === $premium_user ) ? $upgrade_link : ''
392 + );
393 + }
394 +
395 + $html .= sprintf( '<td>%s</td></tr>', wp_kses_post( $data['description'] ) );
396 +
397 + }
398 +
399 + $html .= '</table>';
400 +
401 + return $html;
392 402 }
393 403
394 404 /**
395 405 * Display an upgrade button
@@ -396,22 +406,19 @@
396 406 *
397 407 * @param string $css_class
398 408 * @param null $link
399 409 */
400 -function sh_cd_premium_shortcode_download( $return = false ) {
410 +function sh_cd_upgrade_button( $css_class = '', $link = NULL ) {
401 411
402 - $link = SH_CD_GET_PREMIUM_LINK . '?hash=' . sh_cd_generate_site_hash();
412 + $link = ( false === empty( $link ) ) ? $link : SH_CD_UPGRADE_LINK . '?hash=' . sh_cd_generate_site_hash() ;
403 413
404 - $html = sprintf('<a href="%s" class="button-primary sh-cd-button sh-cd-upgrade-button"><i class="fas fa-download"></i> %s</a>',
414 + 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 415 esc_url( $link ),
406 - __( 'Download Premium Plugin', SH_CD_SLUG )
416 + esc_attr( ' ' . $css_class ),
417 + __( 'Upgrade to Premium for ', SH_CD_SLUG ),
418 + esc_html( sh_cd_license_price() ),
419 + __( 'a year ', SH_CD_SLUG )
407 420 );
408 -
409 - if ( true === $return ) {
410 - return $html;
411 - }
412 -
413 - echo $html;
414 421 }
415 422
416 423 /**
417 424 * Is multsite functionality active for this install?
@@ -419,17 +426,13 @@
419 426 * @return bool
420 427 */
421 428 function sh_cd_is_multisite_enabled() {
422 429
423 - if ( true === defined( 'YK_TEST_IS_MULTISITE' ) && true === YK_TEST_IS_MULTISITE ) {
424 - return true;
425 - }
426 -
427 430 if ( false === is_multisite() ) {
428 431 return false;
429 432 }
430 433
431 - if ( false === sh_cd_is_premium() ) {
434 + if ( false === SH_CD_IS_PREMIUM ) {
432 435 return false;
433 436 }
434 437
435 438 return true;
@@ -467,9 +470,9 @@
467 470 * @return bool
468 471 */
469 472 function sh_cd_reached_free_limit() {
470 473
471 - if ( true === sh_cd_is_premium() ) {
474 + if ( true === SH_CD_IS_PREMIUM ) {
472 475 return false;
473 476 }
474 477
475 478 $existing_shortcodes = sh_cd_db_shortcodes_count();
@@ -477,19 +480,12 @@
477 480 if ( true === empty( $existing_shortcodes ) ) {
478 481 return false;
479 482 }
480 483
481 - return ( (int) $existing_shortcodes >= sh_cd_get_free_limit() );
484 + return ( (int) $existing_shortcodes >= SH_CD_FREE_SHORTCODE_LIMIT );
482 485 }
483 486
484 487 /**
485 - * Return free limit for shortcodes
486 - */
487 -function sh_cd_get_free_limit() {
488 - return 10;
489 -}
490 -
491 -/**
492 488 * Get the minimum user role allowed for viewing data pages in admin
493 489 * @return mixed|void
494 490 */
495 491 function sh_cd_permission_role() {
@@ -494,9 +490,9 @@
494 490 */
495 491 function sh_cd_permission_role() {
496 492
497 493 // If not premium, then admin only
498 - if ( false === sh_cd_is_premium() ) {
494 + if ( false === SH_CD_IS_PREMIUM ) {
499 495 return 'manage_options';
500 496 }
501 497
502 498 $permission_role = get_option( 'sh-cd-edit-permissions', 'manage_options' );
@@ -521,9 +517,9 @@
521 517 * @return bool (default false)
522 518 */
523 519 function sh_cd_is_shortcode_db_value_by_id_enabled() {
524 520
525 - if ( false === sh_cd_is_premium() ) {
521 + if ( false === SH_CD_IS_PREMIUM ) {
526 522 return false;
527 523 }
528 524
529 525 // Disabling by filter overrides the setting in WP admin
@@ -540,48 +536,21 @@
540 536 * Display upgrade notice
541 537 *
542 538 * @param bool $pro_plus
543 539 */
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;
540 +function sh_cd_display_pro_upgrade_notice( ) {
541 + ?>
547 542
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>
543 + <div class="postbox sh-cd-advertise-premium">
544 + <h3 class="hndle"><span><?php echo __( 'Upgrade Snippet Shortcodes and get more features!', SH_CD_SLUG ); ?> </span></h3>
551 545 <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>
546 + <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 547 </div>
555 548 </div>
556 -<?php
557 -}
558 549
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 - );
550 + <?php
573 551 }
574 -
575 -/**
576 - * Display info symbol with tooltip
577 - */
578 -function sh_cd_display_info_tooltip( $text ) {
579 552
580 - return sprintf ('<i class="fa-regular fa-circle-question sh-cd-tooltip" title="%s">',
581 - esc_html( $text )
582 - );
583 -}
584 553
585 554 /**
586 555 * Process a CSV attachment and import into database
587 556 *
@@ -592,11 +561,13 @@
592 561 * @return string
593 562 */
594 563 function sh_cd_import_csv( $attachment_id, $dry_run = true ) {
595 564
596 - sh_cd_permission_check();
565 + if ( false === sh_cd_permission_check() ) {
566 + return 'You do not have the correct admin permissions';
567 + }
597 568
598 - if ( false === sh_cd_is_premium() ) {
569 + if ( false === SH_CD_IS_PREMIUM ) {
599 570 return 'This is a premium feature';
600 571 }
601 572
602 573 $csv_path = get_attached_file( $attachment_id );
@@ -611,13 +582,8 @@
611 582 if ( true === empty( $csv ) ) {
612 583 return 'Error: The CSV appears to be empty.';
613 584 }
614 585
615 - // Lowercase the header row up front so it's compared consistently against our
616 - // (lowercase) column names both here and per-row below - previously the header row
617 - // was validated case-sensitively while each data row's keys were lowercased.
618 - $csv[0] = array_map( 'strtolower', $csv[0] );
619 -
620 586 array_walk($csv, function(&$a) use ($csv) {
621 587 $a = array_combine($csv[0], $a);
622 588 });
623 589
@@ -660,19 +626,15 @@
660 626 }
661 627
662 628 if ( false === $dry_run ) {
663 629
664 - $shortcode = [ 'previous_slug' => '' ];
630 + $shortcode = [ 'slug' => $row[ 'slug' ],
631 + 'previous_slug' => '',
632 + 'data' => $row[ 'content' ],
633 + 'disabled' => ! sh_cd_to_bool( $row[ 'enabled' ] ),
634 + 'multisite' => sh_cd_to_bool( $row[ 'global' ] )
635 + ];
665 636
666 - foreach ( sh_cd_csv_columns() as $column_name => $column ) {
667 -
668 - if ( false === isset( $row[ $column_name ] ) ) {
669 - continue;
670 - }
671 -
672 - $shortcode = array_merge( $shortcode, call_user_func( $column[ 'import' ], $row[ $column_name ] ) );
673 - }
674 -
675 637 $result = sh_cd_db_shortcodes_save( $shortcode );
676 638
677 639 if ( false === $result ) {
678 640 $output .= 'Skipped: Error inserting into database (most likely a field contains too many characters or in the wrong format): ' . implode( ',', $row ) . PHP_EOL;
@@ -698,16 +660,14 @@
698 660 * @return bool|string
699 661 */
700 662 function sh_cd_import_csv_validate_header( $header_row ) {
701 663
702 - $required_columns = array_keys( array_filter( sh_cd_csv_columns(), function( $column ) {
703 - return true === $column[ 'required' ];
704 - } ) );
664 + $expected_headers = [ 'slug', 'content', 'global', 'enabled' ];
705 665
706 - foreach ( $required_columns as $column ) {
666 + foreach ( $expected_headers as $column ) {
707 667
708 668 if ( false === isset( $header_row[ $column ] ) ) {
709 - return 'Missing column: ' . $column . '. Expecting at least: ' . implode( ',', $required_columns ) . PHP_EOL;
669 + return 'Missing column: ' . $column . '. Expecting: ' . implode( ',', $expected_headers ) . PHP_EOL;
710 670 }
711 671 }
712 672
713 673 return true;
@@ -724,10 +684,10 @@
724 684 if ( true === empty( $csv_row[ 'slug' ] ) ) {
725 685 return 'Skipped: Missing slug: ' . implode( ',', $csv_row );
726 686 }
727 687
728 - if ( true === empty( $csv_row[ 'content' ] ) ) {
729 - return 'Skipped: Missing content: ' . implode( ',', $csv_row );
688 + if ( false === empty( $isset[ 'content' ] ) ) {
689 + return 'Skipped: Content: ' . implode( ',', $csv_row );
730 690 }
731 691
732 692 $allowed_bools = [ 'yes', 'no', 'true', 'false', '1', '0' ];
733 693
@@ -740,70 +700,12 @@
740 700 false === in_array( $csv_row[ 'enabled' ], $allowed_bools ) ) {
741 701 return 'Skipped: Invalid "enabled" value. Must be "yes" or "no": ' . implode( ',', $csv_row );
742 702 }
743 703
744 - // Give any Premium-registered columns a chance to reject their own value, so dry-run
745 - // mode surfaces bad input instead of it being silently coerced later on save.
746 - foreach ( sh_cd_csv_columns() as $column_name => $column ) {
747 -
748 - if ( false === isset( $csv_row[ $column_name ] ) || false === isset( $column[ 'validate' ] ) ) {
749 - continue;
750 - }
751 -
752 - $validation_result = call_user_func( $column[ 'validate' ], $csv_row[ $column_name ] );
753 -
754 - if ( true !== $validation_result ) {
755 - return $validation_result;
756 - }
757 - }
758 -
759 704 return true;
760 705 }
761 706
762 707 /**
763 - * Ordered map of CSV column name => column definition, used by both sh_cd_import_csv() and
764 - * sh_cd_export_csv(). Extensible via the 'sh-cd-csv-columns' filter so Premium can add columns
765 - * for its own fields without core knowing about them - column names must be unique (a later
766 - * registration silently overwrites an earlier one of the same name, same as any other array-shaped
767 - * filter in this plugin).
768 - *
769 - * Each column definition:
770 - * 'required' => bool column must be present in the CSV header row
771 - * 'export' => callable( array $shortcode ): string decoded shortcode row -> CSV cell value
772 - * 'import' => callable( string $value ): array CSV cell value -> partial $shortcode to merge
773 - * 'validate' => callable( string $value ): true|string optional; true, or an error message
774 - *
775 - * @return array
776 - */
777 -function sh_cd_csv_columns() {
778 -
779 - $columns = [
780 - 'slug' => [
781 - 'required' => true,
782 - 'export' => function( $shortcode ) { return $shortcode[ 'slug' ]; },
783 - 'import' => function( $value ) { return [ 'slug' => $value ]; },
784 - ],
785 - 'content' => [
786 - 'required' => true,
787 - 'export' => function( $shortcode ) { return stripslashes( $shortcode[ 'data' ] ); },
788 - 'import' => function( $value ) { return [ 'data' => $value ]; },
789 - ],
790 - 'global' => [
791 - 'required' => true,
792 - 'export' => function( $shortcode ) { return ( 1 === (int) $shortcode[ 'multisite' ] ) ? 'yes' : 'no'; },
793 - 'import' => function( $value ) { return [ 'multisite' => sh_cd_to_bool( $value ) ? 1 : 0 ]; },
794 - ],
795 - 'enabled' => [
796 - 'required' => true,
797 - 'export' => function( $shortcode ) { return ( 1 === (int) $shortcode[ 'disabled' ] ) ? 'no' : 'yes'; },
798 - 'import' => function( $value ) { return [ 'disabled' => sh_cd_to_bool( $value ) ? 0 : 1 ]; },
799 - ],
800 - ];
801 -
802 - return apply_filters( 'sh-cd-csv-columns', $columns );
803 -}
804 -
805 -/**
806 708 * Convert string to bool
807 709 * @param $string
808 710 * @return mixed
809 711 */
@@ -811,49 +713,8 @@
811 713 return filter_var( $string, FILTER_VALIDATE_BOOLEAN );
812 714 }
813 715
814 716 /**
815 - * Export all shortcodes as a CSV string in the same column format sh_cd_import_csv() expects
816 - * (see sh_cd_csv_columns()), so the output can be re-imported unchanged.
817 - *
818 - * @return string
819 - */
820 -function sh_cd_export_csv() {
821 -
822 - sh_cd_permission_check();
823 -
824 - $shortcodes = sh_cd_db_shortcodes_all();
825 - $columns = sh_cd_csv_columns();
826 -
827 - $stream = fopen( 'php://temp', 'r+' );
828 -
829 - fputcsv( $stream, array_keys( $columns ) );
830 -
831 - foreach ( $shortcodes as $shortcode ) {
832 -
833 - // sh_cd_db_shortcodes_all() returns raw DB rows - run each through the same
834 - // 'sh-cd-db-loaded-shortcode' filter used when loading a single shortcode, so
835 - // Premium's JSON-encoded columns (device_type, roles, etc.) are decoded back into
836 - // arrays before the column export callbacks below run.
837 - $shortcode = sh_cd_db_filter_loaded_shortcode( $shortcode );
838 -
839 - $row = [];
840 -
841 - foreach ( $columns as $column ) {
842 - $row[] = call_user_func( $column[ 'export' ], $shortcode );
843 - }
844 -
845 - fputcsv( $stream, $row );
846 - }
847 -
848 - rewind( $stream );
849 - $csv = stream_get_contents( $stream );
850 - fclose( $stream );
851 -
852 - return $csv;
853 -}
854 -
855 -/**
856 717 * Our version of kses and the HTML we are happy with
857 718 */
858 719 function sh_cd_wp_kses( $value ) {
859 720
@@ -870,112 +731,5 @@
870 731 $basic_tags[ 'td' ] = [ 'id' => true, 'class' => true ];
871 732 $basic_tags[ 'li' ] = [ 'class' => true ];
872 733
873 734 return wp_kses( $value, $basic_tags );
874 -}
875 -
876 -/**
877 - * Return the current url
878 - */
879 -function sh_cd_get_current_url() {
880 - $protocol = (
881 - ( isset($_SERVER['HTTPS'] ) && 'on' == $_SERVER['HTTPS'] ) ||
882 - ( isset($_SERVER['SERVER_PORT'] ) && 443 == $_SERVER['SERVER_PORT'] )
883 - ) ? 'https://' : 'http://';
884 -
885 - return $protocol . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
886 -}
887 -
888 -/**
889 - * Get selected default editor
890 - */
891 -function sh_cd_default_editor_get() {
892 - return get_option( 'sh-cd-option-default-editor', 'tinymce' );
893 -}
894 -
895 -/**
896 - * Is editor valid
897 - */
898 -function sh_cd_editors_is_valid( $editor ) {
899 - $editors = sh_cd_editors_options();
900 -
901 - return ! empty( $editors[ $editor ] );
902 -}
903 -
904 -/**
905 - * Return valid editors
906 - */
907 -function sh_cd_editors_options( $keys_only = true ) {
908 - return [ 'tinymce' => __( 'WordPress Editor', SH_CD_SLUG ), 'code' => __( 'HTML Editor', SH_CD_SLUG ) ];
909 -}
910 -
911 -/**
912 - * Are tooltips enabled?
913 - */
914 -function sh_cd_tooltips_is_enabled() {
915 - return ( 'yes' === get_option( 'sh-cd-option-tool-tips-enabled', 'yes' ) );
916 -}
917 -
918 -/**
919 - * Is render-count analytics (tracking how many times each shortcode is rendered, incrementing
920 - * a DB counter on every render) enabled? A Premium-only feature, on by default - lets a
921 - * high-traffic site opt out of the extra database write on every shortcode render.
922 - *
923 - * @return bool (default true when Premium, always false otherwise)
924 - */
925 -function sh_cd_is_render_count_enabled() {
926 -
927 - if ( false === sh_cd_is_premium() ) {
928 - return false;
929 - }
930 -
931 - return ( 'yes' === get_option( 'sh-cd-option-render-count-enabled', 'yes' ) );
932 -}
933 -
934 -/**
935 - * Fetch icons for given shortcode
936 - *
937 - * @param [type] $shortcode
938 - * @param boolean $return_array
939 - * @return void
940 - */
941 -function sh_cd_icons_for_shortcode( $shortcode, $return_array = false ) {
942 -
943 - if ( true === empty( $shortcode ) ) {
944 - return [];
945 - }
946 -
947 - $icons = [];
948 -
949 - if ( false === empty( $shortcode[ 'header' ] ) ) {
950 - $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 ) ) );
951 - }
952 -
953 - if ( false === empty( $shortcode[ 'footer' ] ) ) {
954 - $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 ) ) );
955 - }
956 -
957 - if ( false === empty( $shortcode[ 'device_type' ] ) ) {
958 - $shortcode[ 'device_type' ] = json_decode( $shortcode[ 'device_type' ] );
959 - }
960 -
961 - if ( true === is_array( $shortcode[ 'device_type' ] ) ) {
962 -
963 - if ( true === in_array( 'desktop', $shortcode[ 'device_type' ] ) ) {
964 - $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 ) ) );
965 - }
966 -
967 - if ( true === in_array( 'mobile', $shortcode[ 'device_type' ] ) ) {
968 - $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 ) ) );
969 - }
970 -
971 - if ( true === in_array( 'tablet', $shortcode[ 'device_type' ] ) ) {
972 - $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 ) ) );
973 - }
974 - }
975 -
976 - if ( true === $return_array ) {
977 - return $icons;
978 - }
979 -
980 - return ( false === empty( $icons ) ) ? implode( PHP_EOL, $icons ) : '';
981 735 }