| @@ -1,75 +1,62 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -defined('ABSPATH') or die('Jog on!'); | |
| 4 | - | |
| 5 | -/** | |
| 6 | - * Render the main user defined shortcode [sv] | |
| 7 | - * | |
| 8 | - * @param $args | |
| 9 | - * | |
| 10 | - * @return bool|mixed|string | |
| 11 | - */ | |
| 12 | -function sh_cd_shortcode( $args ) { | |
| 13 | - | |
| 14 | - $args = wp_parse_args( $args, [ 'slug' => NULL ] ); | |
| 15 | - | |
| 16 | - return sh_cd_shortcode_render( $args ); | |
| 17 | -} | |
| 18 | -add_shortcode( SH_CD_SHORTCODE, 'sh_cd_shortcode' ); | |
| 19 | -add_shortcode( 'shortcode-variables', 'sh_cd_shortcode' ); // Backwards compatibility | |
| 20 | -add_shortcode( 's-var', 'sh_cd_shortcode' ); // Backwards compatibility | |
| 21 | - | |
| 22 | -/** | |
| 23 | - * Process the shortcode and render | |
| 24 | - * | |
| 25 | - * @param $args | |
| 26 | - * | |
| 27 | - * @return mixed|string | |
| 28 | - */ | |
| 29 | -function sh_cd_shortcode_render( $args ) { | |
| 30 | - | |
| 31 | - // Have a slug? | |
| 32 | - if ( true === empty( $args[ 'slug' ] ) ) { | |
| 33 | - return ''; | |
| 34 | - } | |
| 35 | - | |
| 36 | - // Preset shortcode? | |
| 37 | - if ( false !== sh_cd_is_preset( $args[ 'slug' ] ) ) { | |
| 38 | - return sh_cd_shortcode_presets_render( $args ); | |
| 39 | - } | |
| 40 | - | |
| 41 | - // Cached? | |
| 42 | - $shortcode = sh_cd_cache_get( $args[ 'slug' ] ); | |
| 43 | - | |
| 44 | - // If not in cache, hit the database! | |
| 45 | - if ( false === $shortcode ) { | |
| 46 | - | |
| 47 | - $shortcode = sh_cd_db_shortcodes_by_slug( $args[ 'slug' ] ); | |
| 48 | - | |
| 49 | - // Cache it! If a multisite, only cache the shortcode for 30 seconds. Otherwise, fall back to default cache time. | |
| 50 | - $cache_time = ( true === sh_cd_is_premium() && true === in_array( $args[ 'slug' ], sh_cd_multisite_slugs() ) ) ? 30 : NULL; | |
| 51 | - | |
| 52 | - sh_cd_cache_set( $args[ 'slug' ], $shortcode, $cache_time ); | |
| 53 | - | |
| 54 | - } | |
| 55 | - | |
| 56 | - // If still no reference to a shortcode then slug doesn't exist | |
| 57 | - if ( true === empty( $shortcode ) ) { | |
| 58 | - return ''; | |
| 59 | - } | |
| 60 | - | |
| 61 | - // Any other reasons this shortcode shouldn't be displayed? e.g. has the | |
| 62 | - // Premium plugin determined it's not the correct device type? etc | |
| 63 | - if ( true === apply_filters( 'sh-cd-filter-hide-shortcode', false, $shortcode ) ) { | |
| 64 | - return ''; | |
| 65 | - } | |
| 66 | - | |
| 67 | - // Let the Premium plugin (or anything else) know this shortcode was just rendered, e.g. for usage analytics | |
| 68 | - do_action( 'sh-cd-shortcode-rendered', $shortcode, $args ); | |
| 69 | - | |
| 70 | - // Process other shortcodes within this one | |
| 71 | - $shortcode = do_shortcode( $shortcode[ 'data' ] ); | |
| 72 | - | |
| 73 | - // Replace placeholders with user defined parameters | |
| 74 | - return sh_cd_apply_user_defined_parameters( $shortcode, $args ); | |
| 75 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +defined('ABSPATH') or die('Jog on!'); | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * Render the main user defined shortcode [sv] | |
| 7 | + * | |
| 8 | + * @param $args | |
| 9 | + * | |
| 10 | + * @return bool|mixed|string | |
| 11 | + */ | |
| 12 | +function sh_cd_shortcode( $args ) { | |
| 13 | + | |
| 14 | + $args = wp_parse_args( $args, [ 'slug' => NULL ] ); | |
| 15 | + | |
| 16 | + return sh_cd_shortcode_render( $args ); | |
| 17 | +} | |
| 18 | +add_shortcode( SH_CD_SHORTCODE, 'sh_cd_shortcode' ); | |
| 19 | +add_shortcode( 'shortcode-variables', 'sh_cd_shortcode' ); // Backwards compatibility | |
| 20 | +add_shortcode( 's-var', 'sh_cd_shortcode' ); // Backwards compatibility | |
| 21 | + | |
| 22 | +/** | |
| 23 | + * Process the shortcode and render | |
| 24 | + * | |
| 25 | + * @param $args | |
| 26 | + * | |
| 27 | + * @return mixed|string | |
| 28 | + */ | |
| 29 | +function sh_cd_shortcode_render( $args ) { | |
| 30 | + | |
| 31 | + // Have a slug? | |
| 32 | + if ( true === empty( $args[ 'slug' ] ) ) { | |
| 33 | + return ''; | |
| 34 | + } | |
| 35 | + | |
| 36 | + // Preset shortcode? | |
| 37 | + if ( false !== sh_cd_is_preset( $args[ 'slug' ] ) ) { | |
| 38 | + return sh_cd_shortcode_presets_render( $args ); | |
| 39 | + } | |
| 40 | + | |
| 41 | + // Cached? | |
| 42 | + $shortcode = sh_cd_cache_get( $args[ 'slug' ] ); | |
| 43 | + | |
| 44 | + // If not in cache, hit the database! | |
| 45 | + if ( true === empty( $shortcode ) ) { | |
| 46 | + $shortcode = sh_cd_db_shortcodes_by_slug( $args[ 'slug' ] ); | |
| 47 | + } | |
| 48 | + | |
| 49 | + // If still no reference to a shortcode then slug doesn't exist | |
| 50 | + if ( true === empty( $shortcode ) ) { | |
| 51 | + return ''; | |
| 52 | + } | |
| 53 | + | |
| 54 | + // Cache it! | |
| 55 | + sh_cd_cache_set( $args[ 'slug' ], $shortcode ); | |
| 56 | + | |
| 57 | + // Process other shortcodes within this one | |
| 58 | + $shortcode = do_shortcode( $shortcode ); | |
| 59 | + | |
| 60 | + // Replace placeholders with user defined parameters | |
| 61 | + return sh_cd_apply_user_defined_parameters( $shortcode, $args ); | |
| 62 | +} | |