| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* A base shortcode for all lockers |
| 5 |
* |
| 6 |
* @since 1.0.0 |
| 7 |
*/ |
| 8 |
class WINP_SnippetShortcode extends Wbcr_FactoryShortcodes324_Shortcode { |
| 9 |
|
| 10 |
public $shortcode_name = 'wbcr_php_snippet'; |
| 11 |
|
| 12 |
/** |
| 13 |
* Includes assets |
| 14 |
* @var bool |
| 15 |
*/ |
| 16 |
public $assets_in_header = true; |
| 17 |
|
| 18 |
/** |
| 19 |
* Content render |
| 20 |
* |
| 21 |
* @param array $attr |
| 22 |
* @param string $content |
| 23 |
*/ |
| 24 |
public function html($attr, $content) |
| 25 |
{ |
| 26 |
if( isset($attr['title']) ) { |
| 27 |
unset($attr['title']); |
| 28 |
} |
| 29 |
|
| 30 |
$attr = array_map('sanitize_title', $attr); |
| 31 |
|
| 32 |
// Let users pass arbitrary variables, through shortcode attributes. |
| 33 |
// @since 2.0.5 |
| 34 |
extract($attr, EXTR_SKIP); |
| 35 |
|
| 36 |
$id = isset($attr['id']) |
| 37 |
? (int)$attr['id'] |
| 38 |
: null; |
| 39 |
|
| 40 |
if( !$id ) { |
| 41 |
echo '<span style="color:red">' . __('[wbcr_php_snippet]: PHP snippets error (not passed the snippet ID)', 'insert-php') . '</span>'; |
| 42 |
|
| 43 |
return; |
| 44 |
} |
| 45 |
|
| 46 |
$snippet_meta = get_post_meta($id, ''); |
| 47 |
|
| 48 |
if( empty($snippet_meta) ) { |
| 49 |
return; |
| 50 |
} |
| 51 |
|
| 52 |
$is_activate = isset($snippet_meta[$this->plugin->getPrefix() . 'snippet_activate']) && $snippet_meta[$this->plugin->getPrefix() . 'snippet_activate'][0]; |
| 53 |
|
| 54 |
$snippet_code = isset($snippet_meta[$this->plugin->getPrefix() . 'snippet_code']) |
| 55 |
? $snippet_meta[$this->plugin->getPrefix() . 'snippet_code'] |
| 56 |
: null; |
| 57 |
|
| 58 |
$snippet_scope = isset($snippet_meta[$this->plugin->getPrefix() . 'snippet_scope']) |
| 59 |
? $snippet_meta[$this->plugin->getPrefix() . 'snippet_scope'][0] |
| 60 |
: null; |
| 61 |
|
| 62 |
if( !$is_activate || empty($snippet_code) || $snippet_scope != 'shortcode' ) { |
| 63 |
return; |
| 64 |
} |
| 65 |
|
| 66 |
eval($snippet_code[0]); |
| 67 |
} |
| 68 |
} |