| @@ -3,27 +3,35 @@ | ||
| 3 | 3 | defined('ABSPATH') or die('Jog on!'); |
| 4 | 4 | |
| 5 | 5 | function sh_cd_shortcode( $atts ) |
| 6 | 6 | { |
| 7 | - $shortcode_args = shortcode_atts( array( | |
| 7 | + $user_defined_parameters = false; | |
| 8 | + | |
| 9 | + $default_arguments = array( | |
| 8 | 10 | 'slug' => false, |
| 9 | - 'format' => false | |
| 10 | - ), $atts ); | |
| 11 | + 'format' => false, | |
| 12 | + 'redirect' => false | |
| 13 | + ); | |
| 11 | 14 | |
| 12 | - return sh_cd_render_shortcode_from_db($shortcode_args); | |
| 15 | + $shortcode_args = shortcode_atts( $default_arguments, $atts ); | |
| 13 | 16 | |
| 17 | + // User defined parameters | |
| 18 | + $user_defined_parameters = sh_cd_get_user_defined_arguments($default_arguments, $atts); | |
| 19 | + | |
| 20 | + return sh_cd_render_shortcode_from_db($shortcode_args, $user_defined_parameters); | |
| 21 | + | |
| 14 | 22 | } |
| 15 | 23 | add_shortcode( SH_CD_SHORTCODE, 'sh_cd_shortcode' ); |
| 24 | +add_shortcode( SH_CD_SHORTCODE_SMALL, 'sh_cd_shortcode' ); | |
| 16 | 25 | |
| 17 | -function sh_cd_render_shortcode_from_db($shortcode_args) | |
| 26 | +function sh_cd_render_shortcode_from_db($shortcode_args, $user_defined_parameters = false) | |
| 18 | 27 | { |
| 19 | 28 | $slug = $shortcode_args['slug']; |
| 20 | 29 | |
| 21 | 30 | if ($slug != false && !empty($slug)) |
| 22 | - { | |
| 31 | + { | |
| 23 | 32 | // Check if a shortcode preset |
| 24 | - if (sh_cd_is_shortcode_preset($slug)) | |
| 25 | - { | |
| 33 | + if (sh_cd_is_shortcode_preset($slug)) { | |
| 26 | 34 | return sh_cd_render_shortcode_presets($shortcode_args); |
| 27 | 35 | } |
| 28 | 36 | else |
| 29 | 37 | { |
| @@ -29,12 +37,20 @@ | ||
| 29 | 37 | { |
| 30 | 38 | $cached_shortcode = sh_cd_get_cache($slug); |
| 31 | 39 | |
| 32 | 40 | if ($cached_shortcode != false) |
| 33 | - { | |
| 41 | + { | |
| 34 | 42 | // Process other shortcodes |
| 35 | 43 | $cached_shortcode = do_shortcode($cached_shortcode); |
| 36 | 44 | |
| 45 | + // No shortcode found or disabled? Then return nothing. | |
| 46 | + if(!$cached_shortcode) { | |
| 47 | + return ''; | |
| 48 | + } | |
| 49 | + | |
| 50 | + // Replace placeholders with user defined parameters | |
| 51 | + $cached_shortcode = sh_cd_apply_user_defined_parameters($cached_shortcode, $user_defined_parameters); | |
| 52 | + | |
| 37 | 53 | return $cached_shortcode; |
| 38 | 54 | } |
| 39 | 55 | else |
| 40 | 56 | { |
| @@ -43,12 +59,21 @@ | ||
| 43 | 59 | if ($shortcode) |
| 44 | 60 | { |
| 45 | 61 | sh_cd_set_cache($slug, $shortcode); |
| 46 | 62 | |
| 63 | + // No shortcode found or disabled? Then return nothing. | |
| 64 | + if(!$cached_shortcode) { | |
| 65 | + return ''; | |
| 66 | + } | |
| 67 | + | |
| 68 | + // Process other shortcodes | |
| 47 | 69 | $shortcode = do_shortcode($shortcode); |
| 48 | - | |
| 70 | + | |
| 71 | + // Replace placeholders with user defined parameters | |
| 72 | + $shortcode = sh_cd_apply_user_defined_parameters($shortcode, $user_defined_parameters); | |
| 73 | + | |
| 49 | 74 | return $shortcode; |
| 50 | 75 | } |
| 51 | 76 | } |
| 52 | - } | |
| 77 | + } | |
| 53 | 78 | } |
| 54 | -} | |
| 79 | +} | |