PluginProbe
Snippet Shortcodes / 2.0
Snippet Shortcodes v2.0
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 2.0, at includes/shortcode.user.php

62 lines 1.5 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 ( 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 }