Skip to content

Commit

Permalink
Fix fatal error when calling ob_start() in output buffering display h…
Browse files Browse the repository at this point in the history
…andler
  • Loading branch information
westonruter committed Apr 28, 2018
1 parent 6ff75c9 commit 8f35f13
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions includes/utils/class-amp-validation-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -958,9 +958,20 @@ public static function wrapped_callback( $callback ) {
$before_scripts_enqueued = $wp_scripts->queue;
}

ob_start();
/*
* Verifying that the current output buffer type is not PHP_OUTPUT_HANDLER_USER is required to prevent a fatal error:
* "ob_start(): Cannot use output buffering in output buffering display handlers"
*/
$ob_status = ob_get_status();
$can_buffer = ! ( isset( $ob_status['type'] ) && 1 /* PHP_OUTPUT_HANDLER_USER */ === $ob_status['type'] );
$output = null;
if ( $can_buffer ) {
ob_start();
}
$result = call_user_func_array( $function, array_slice( $args, 0, intval( $accepted_args ) ) );
$output = ob_get_clean();
if ( $can_buffer ) {
$output = ob_get_clean();
}

// Keep track of which source enqueued the styles.
if ( isset( $wp_styles ) && isset( $wp_styles->queue ) ) {
Expand Down

0 comments on commit 8f35f13

Please sign in to comment.