PluginProbe
Snippet Shortcodes / 4.1
Snippet Shortcodes v4.1
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
shortcode-variables / includes / shortcode.user.php

shortcode.user.php in Snippet Shortcodes 4.1, at includes/shortcode.user.php

67 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 // Process other shortcodes within this one
62 $shortcode = do_shortcode( $shortcode );
63
64 // Replace placeholders with user defined parameters
65 return sh_cd_apply_user_defined_parameters( $shortcode, $args );
66 }
67