| @@ -1,75 +1,55 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Php Shortcode | |
| 4 | - */ | |
| 5 | - | |
| 6 | -// Exit if accessed directly | |
| 7 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 8 | - exit; | |
| 9 | -} | |
| 10 | - | |
| 11 | -class WINP_SnippetShortcodePhp extends WINP_SnippetShortcode { | |
| 12 | - | |
| 13 | - public $shortcode_name = 'wbcr_php_snippet'; | |
| 14 | - | |
| 15 | - /** | |
| 16 | - * Content render | |
| 17 | - * | |
| 18 | - * @param array $attr | |
| 19 | - * @param string $content | |
| 20 | - * @param string $tag | |
| 21 | - */ | |
| 22 | - public function html( $attr, $content, $tag ) { | |
| 23 | - $id = $this->get_snippet_id( $attr, WINP_SNIPPET_TYPE_PHP ); | |
| 24 | - | |
| 25 | - if ( ! $id && ( current_user_can( 'manage_options' ) || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ) ) { | |
| 26 | - /* translators: %s: Shortcode tag name */ | |
| 27 | - echo '<span style="color:red">' . sprintf( esc_html__( '[%s]: PHP snippets error (not passed the snippet ID)', 'insert-php' ), esc_html( $tag ) ) . '</span>'; | |
| 28 | - | |
| 29 | - return; | |
| 30 | - } | |
| 31 | - | |
| 32 | - $snippet = get_post( $id ); | |
| 33 | - $snippet_meta = get_post_meta( $id, '' ); | |
| 34 | - | |
| 35 | - if ( ! $snippet || empty( $snippet_meta ) ) { | |
| 36 | - return; | |
| 37 | - } | |
| 38 | - | |
| 39 | - $attr = $this->filter_attributes( $attr, $id ); | |
| 40 | - | |
| 41 | - // Let users pass arbitrary variables, through shortcode attributes. | |
| 42 | - // @since 2.0.5 | |
| 43 | - extract( $attr, EXTR_SKIP ); | |
| 44 | - | |
| 45 | - $is_activate = $this->get_snippet_activate( $snippet_meta ); | |
| 46 | - $snippet_scope = $this->get_snippet_scope( $snippet_meta ); | |
| 47 | - $snippet_content = $this->get_snippet_content( $snippet, $snippet_meta, $id ); | |
| 48 | - | |
| 49 | - if ( ! $is_activate || empty( $snippet_content ) || $snippet_scope != 'shortcode' || WINP_Helper::is_safe_mode() ) { | |
| 50 | - return; | |
| 51 | - } | |
| 52 | - | |
| 53 | - if ( defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML ) { | |
| 54 | - if ( is_user_logged_in() && WINP_Plugin::app()->current_user_car() ) { | |
| 55 | - echo esc_html__( 'This Woody snippet cannot run because unfiltered HTML insertion is disabled.', 'insert-php' ); | |
| 56 | - } | |
| 57 | - | |
| 58 | - return; | |
| 59 | - } | |
| 60 | - | |
| 61 | - // Track shortcode execution. | |
| 62 | - WINP_Plugin::app()->get_execute_object()->track_shortcode_snippet( $id ); | |
| 63 | - | |
| 64 | - // Initialize error handler. | |
| 65 | - WINP_Error_Handler::init(); | |
| 66 | - | |
| 67 | - // Set current snippet context for error handler. | |
| 68 | - WINP_Error_Handler::set_current_snippet( $id, $snippet->post_title, $snippet_content ); | |
| 69 | - | |
| 70 | - eval( $snippet_content ); | |
| 71 | - | |
| 72 | - // Clear snippet context after execution. | |
| 73 | - WINP_Error_Handler::clear_current_snippet(); | |
| 74 | - } | |
| 75 | -} | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Php Shortcode | |
| 4 | + */ | |
| 5 | + | |
| 6 | +// Exit if accessed directly | |
| 7 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 8 | + exit; | |
| 9 | +} | |
| 10 | + | |
| 11 | +class WINP_SnippetShortcodePhp extends WINP_SnippetShortcode { | |
| 12 | + | |
| 13 | + public $shortcode_name = 'wbcr_php_snippet'; | |
| 14 | + | |
| 15 | + /** | |
| 16 | + * Content render | |
| 17 | + * | |
| 18 | + * @param array $attr | |
| 19 | + * @param string $content | |
| 20 | + * @param string $tag | |
| 21 | + */ | |
| 22 | + public function html( $attr, $content, $tag ) { | |
| 23 | + $id = $this->getSnippetId( $attr, WINP_SNIPPET_TYPE_PHP ); | |
| 24 | + | |
| 25 | + if ( ! $id ) { | |
| 26 | + echo '<span style="color:red">' . __( '[' . esc_html( $tag ) . ']: PHP snippets error (not passed the snippet ID)', 'insert-php' ) . '</span>'; | |
| 27 | + | |
| 28 | + return; | |
| 29 | + } | |
| 30 | + | |
| 31 | + $snippet = get_post( $id ); | |
| 32 | + $snippet_meta = get_post_meta( $id, '' ); | |
| 33 | + | |
| 34 | + if ( ! $snippet || empty( $snippet_meta ) ) { | |
| 35 | + return; | |
| 36 | + } | |
| 37 | + | |
| 38 | + $attr = $this->filterAttributes( $attr, $id ); | |
| 39 | + | |
| 40 | + // Let users pass arbitrary variables, through shortcode attributes. | |
| 41 | + // @since 2.0.5 | |
| 42 | + extract( $attr, EXTR_SKIP ); | |
| 43 | + | |
| 44 | + $is_activate = $this->getSnippetActivate( $snippet_meta ); | |
| 45 | + $snippet_scope = $this->getSnippetScope( $snippet_meta ); | |
| 46 | + $snippet_content = $this->getSnippetContent( $snippet, $snippet_meta, $id ); | |
| 47 | + | |
| 48 | + if ( ! $is_activate || empty( $snippet_content ) || $snippet_scope != 'shortcode' || WINP_Helper::is_safe_mode() ) { | |
| 49 | + return; | |
| 50 | + } | |
| 51 | + | |
| 52 | + eval( $snippet_content ); | |
| 53 | + } | |
| 54 | + | |
| 55 | +} | |