| @@ -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 ' ); |
| @@ -804,8 +809,13 @@ | ||
| 804 | 809 | } else { |
| 805 | 810 | $result = ! empty( $code ); |
| 806 | 811 | } |
| 807 | 812 | |
| 813 | + if ( $is_executable ) { | |
| 814 | + self::$current_snippet_id = 0; | |
| 815 | + WINP_Error_Handler::clear_current_snippet(); | |
| 816 | + } | |
| 817 | + | |
| 808 | 818 | if ( $catch_output ) { |
| 809 | 819 | ob_end_clean(); |
| 810 | 820 | } |
| 811 | 821 | |
| @@ -985,9 +995,9 @@ | ||
| 985 | 995 | 'Content-Type: text/html; charset=UTF-8', |
| 986 | 996 | ]; |
| 987 | 997 | |
| 988 | 998 | // Send email. |
| 989 | - $sent = wp_mail( $email_address, $subject, $email_body, $headers ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_mail_wp_mail | |
| 999 | + $sent = wp_mail( $email_address, $subject, $email_body, $headers ); | |
| 990 | 1000 | |
| 991 | 1001 | // If email sent successfully, mark this error as emailed. |
| 992 | 1002 | if ( $sent ) { |
| 993 | 1003 | $emailed_errors[ $error_signature ] = time(); |
| @@ -1421,9 +1431,10 @@ | ||
| 1421 | 1431 | if ( is_object( $value ) ) { |
| 1422 | 1432 | if ( ! isset( $value->units ) || ! isset( $value->unitsCount ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
| 1423 | 1433 | return 0; |
| 1424 | 1434 | } |
| 1425 | - return ( current_time( 'timestamp' ) - $this->get_timestamp( $value->units, $value->unitsCount ) ) * 1000; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase, WordPress.DateTime.CurrentTimeTimestamp.Requested | |
| 1435 | + $current_timestamp = current_datetime()->getTimestamp(); | |
| 1436 | + return ( $current_timestamp - $this->get_timestamp( $value->units, $value->unitsCount ) ) * 1000; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase | |
| 1426 | 1437 | } else { |
| 1427 | 1438 | return $value; |
| 1428 | 1439 | } |
| 1429 | 1440 | } |