| @@ -1,45 +1,49 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | 2 | /** |
| 4 | 3 | * Text Shortcode |
| 5 | 4 | */ |
| 5 | + | |
| 6 | +// Exit if accessed directly | |
| 7 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 8 | + exit; | |
| 9 | +} | |
| 10 | + | |
| 6 | 11 | class WINP_SnippetShortcodeText extends WINP_SnippetShortcode { |
| 7 | - | |
| 12 | + | |
| 8 | 13 | public $shortcode_name = 'wbcr_text_snippet'; |
| 9 | - | |
| 14 | + | |
| 10 | 15 | /** |
| 11 | 16 | * Content render |
| 12 | 17 | * |
| 13 | 18 | * @param array $attr |
| 14 | 19 | * @param string $content |
| 20 | + * @param string $tag | |
| 15 | 21 | */ |
| 16 | - public function html($attr, $content) | |
| 17 | - { | |
| 22 | + public function html( $attr, $content, $tag ) { | |
| 18 | 23 | $id = $this->getSnippetId( $attr, WINP_SNIPPET_TYPE_TEXT ); |
| 19 | 24 | |
| 20 | 25 | if( !$id ) { |
| 21 | - echo '<span style="color:red">' . __('[wbcr_text_snippet]: PHP snippets error (not passed the snippet ID)', 'insert-php') . '</span>'; | |
| 26 | + echo '<span style="color:red">' . __('[' . esc_html( $tag ) . ']: Text snippets error (not passed the snippet ID)', 'insert-php') . '</span>'; | |
| 22 | 27 | |
| 23 | 28 | return; |
| 24 | 29 | } |
| 25 | - | |
| 26 | - $snippet_meta = get_post_meta($id, ''); | |
| 27 | - if( empty($snippet_meta) ) { | |
| 30 | + | |
| 31 | + $snippet = get_post( $id ); | |
| 32 | + $snippet_meta = get_post_meta( $id, '' ); | |
| 33 | + | |
| 34 | + if ( ! $snippet || empty( $snippet_meta ) ) { | |
| 28 | 35 | return; |
| 29 | 36 | } |
| 30 | - | |
| 31 | - $is_activate = $this->getSnippetActivate( $snippet_meta ); | |
| 32 | - $snippet_content = get_post($id)->post_content; | |
| 37 | + | |
| 38 | + $is_activate = $this->getSnippetActivate( $snippet_meta ); | |
| 33 | 39 | $snippet_scope = $this->getSnippetScope( $snippet_meta ); |
| 34 | - $is_condition = WINP_Plugin::app()->getExecuteObject()->checkCondition($id); | |
| 35 | - | |
| 36 | - if( !$is_activate || empty($snippet_content) || $snippet_scope != 'shortcode' || !$is_condition ) { | |
| 40 | + $is_condition = WINP_Plugin::app()->getExecuteObject()->checkCondition( $id ); | |
| 41 | + | |
| 42 | + if ( ! $is_activate || $snippet_scope != 'shortcode' || ! $is_condition ) { | |
| 37 | 43 | return; |
| 38 | 44 | } |
| 39 | - | |
| 40 | - $code = do_shortcode($snippet_content); | |
| 41 | - $code = str_replace( '{{SNIPPET_CONTENT}}', $content, $code ); | |
| 42 | - echo( $code ); | |
| 45 | + | |
| 46 | + echo str_replace( '{{SNIPPET_CONTENT}}', $content, do_shortcode( $snippet->post_content ) ); | |
| 43 | 47 | } |
| 44 | - | |
| 48 | + | |
| 45 | 49 | } |