PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / trunk
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts vtrunk
2.7.7 2.7.6 2.7.5 2.7.4 trunk 1.3 2.0.4 2.0.6 2.1.91 2.2.4 2.2.7 2.2.9 2.3.1 2.3.10 2.4.10 2.4.2 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.6.0 2.6.1 2.7.0 All 28 releases
← All changes | includes/class.execute.snippet.php +17 -7 2.7.6trunk View file →
@@ -785,17 +785,22 @@
785 785 if ( empty( $snippet ) || $snippet->post_type !== WINP_SNIPPETS_POST_TYPE ) {
786 786 return false;
787 787 }
788 788
789 - $snippet_type = WINP_Helper::getMetaOption( $id, 'snippet_type', true );
789 + $snippet_type = WINP_Helper::getMetaOption( $id, 'snippet_type', true );
790 + $is_executable = in_array( $snippet_type, [ WINP_SNIPPET_TYPE_PHP, WINP_SNIPPET_TYPE_UNIVERSAL ], true );
790 791
791 - // Set current snippet ID for error handling.
792 - self::$current_snippet_id = $id;
792 + if ( $is_executable ) {
793 + // Preserve the active snippet context if execution terminates the request.
794 + self::$current_snippet_id = $id;
795 + WINP_Error_Handler::init();
796 + WINP_Error_Handler::set_current_snippet( $id, $snippet->post_title );
793 797
794 - // Register shutdown function once to catch fatal errors.
795 - if ( ! self::$shutdown_registered ) {
796 - register_shutdown_function( [ $this, 'handle_snippet_shutdown' ] );
797 - self::$shutdown_registered = true;
798 + // Register shutdown function once to catch fatal errors.
799 + if ( ! self::$shutdown_registered ) {
800 + register_shutdown_function( [ $this, 'handle_snippet_shutdown' ] );
801 + self::$shutdown_registered = true;
802 + }
798 803 }
799 804
800 805 if ( $snippet_type == WINP_SNIPPET_TYPE_UNIVERSAL ) {
801 806 $result = eval( '?>' . $code . '<?php ' );
@@ -802,8 +807,13 @@
802 807 } elseif ( $snippet_type == WINP_SNIPPET_TYPE_PHP ) {
803 808 $result = eval( $code );
804 809 } else {
805 810 $result = ! empty( $code );
811 + }
812 +
813 + if ( $is_executable ) {
814 + self::$current_snippet_id = 0;
815 + WINP_Error_Handler::clear_current_snippet();
806 816 }
807 817
808 818 if ( $catch_output ) {
809 819 ob_end_clean();