Skip to content

Commit 86d787a

Browse files
committed
Re-enable output suppression when executing snippets
1 parent 590b431 commit 86d787a

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

php/admin-menus/class-edit-menu.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ private function validate_code( Code_Snippet $snippet ) {
178178

179179
ob_start( array( $this, 'code_error_callback' ) );
180180

181-
$result = execute_snippet( $snippet->code, $snippet->id );
181+
$result = execute_snippet( $snippet->code, $snippet->id, false );
182182

183183
ob_end_clean();
184184

php/snippet-ops.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -414,18 +414,28 @@ function export_snippets( $ids, $multisite = null, $format = 'xml' ) {
414414
*
415415
* @since 2.0
416416
*
417-
* @param string $code The snippet code to execute
418-
* @param int $id The snippet ID
417+
* @param string $code The snippet code to execute
418+
* @param int $id The snippet ID
419+
* @param bool $catch_output Whether to attempt to suppress the output of execution using buffers
420+
*
419421
* @return mixed The result of the code execution
420422
*/
421-
function execute_snippet( $code, $id = 0 ) {
423+
function execute_snippet( $code, $id = 0, $catch_output = true ) {
422424

423425
if ( empty( $code ) ) {
424426
return false;
425427
}
426428

429+
if ( $catch_output ) {
430+
ob_start();
431+
}
432+
427433
$result = eval( $code );
428434

435+
if ( $catch_output ) {
436+
ob_end_clean();
437+
}
438+
429439
do_action( 'code_snippets/after_execute_snippet', $id, $code, $result );
430440

431441
return $result;

0 commit comments

Comments
 (0)