| 1 |
<?php |
| 2 |
|
| 3 |
defined('ABSPATH') or die('Jog on!'); |
| 4 |
|
| 5 |
function sh_cd_shortcode( $atts ) |
| 6 |
{ |
| 7 |
$shortcode_args = shortcode_atts( array( |
| 8 |
'slug' => false, |
| 9 |
'format' => false, |
| 10 |
'redirect' => false |
| 11 |
), $atts ); |
| 12 |
|
| 13 |
return sh_cd_render_shortcode_from_db($shortcode_args); |
| 14 |
|
| 15 |
} |
| 16 |
add_shortcode( SH_CD_SHORTCODE, 'sh_cd_shortcode' ); |
| 17 |
|
| 18 |
function sh_cd_render_shortcode_from_db($shortcode_args) |
| 19 |
{ |
| 20 |
$slug = $shortcode_args['slug']; |
| 21 |
|
| 22 |
if ($slug != false && !empty($slug)) |
| 23 |
{ |
| 24 |
// Check if a shortcode preset |
| 25 |
if (sh_cd_is_shortcode_preset($slug)) { |
| 26 |
return sh_cd_render_shortcode_presets($shortcode_args); |
| 27 |
} |
| 28 |
else |
| 29 |
{ |
| 30 |
$cached_shortcode = sh_cd_get_cache($slug); |
| 31 |
|
| 32 |
if ($cached_shortcode != false) |
| 33 |
{ |
| 34 |
// Process other shortcodes |
| 35 |
$cached_shortcode = do_shortcode($cached_shortcode); |
| 36 |
|
| 37 |
return $cached_shortcode; |
| 38 |
} |
| 39 |
else |
| 40 |
{ |
| 41 |
$shortcode = sh_cd_get_shortcode_by_slug($slug); |
| 42 |
|
| 43 |
if ($shortcode) |
| 44 |
{ |
| 45 |
sh_cd_set_cache($slug, $shortcode); |
| 46 |
|
| 47 |
$shortcode = do_shortcode($shortcode); |
| 48 |
|
| 49 |
return $shortcode; |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
|