From e4abc1ecbf04503bc53b21f58c72d7108d4f55f5 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Wed, 27 Jul 2016 17:11:56 +0000 Subject: [PATCH] Filesystem API: Output buffering for `request_filesystem_credentials()` should wrap the function directly. Previously `ob_end_clean()` was only called when the previous condition was successful which led to unexpected results when another output buffering was involved, like PHPUnit's. Fixes #37488. Built from https://develop.svn.wordpress.org/trunk@38167 git-svn-id: http://core.svn.wordpress.org/trunk@38108 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/ajax-actions.php | 16 +++++++++------- wp-admin/includes/plugin.php | 13 ++++++++----- wp-admin/includes/theme.php | 18 +++++++++++------- wp-includes/version.php | 2 +- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index e91b522227..90691e6a40 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -3515,12 +3515,13 @@ function wp_ajax_delete_theme() { wp_send_json_error( $status ); } - // Check filesystem credentials. `delete_plugins()` will bail otherwise. - ob_start(); + // Check filesystem credentials. `delete_theme()` will bail otherwise. $url = wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet ); - if ( false === ( $credentials = request_filesystem_credentials( $url ) ) || ! WP_Filesystem( $credentials ) ) { + ob_start(); + $credentials = request_filesystem_credentials( $url ); + ob_end_clean(); + if ( false === $credentials || ! WP_Filesystem( $credentials ) ) { global $wp_filesystem; - ob_end_clean(); $status['errorCode'] = 'unable_to_connect_to_filesystem'; $status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' ); @@ -3771,11 +3772,12 @@ function wp_ajax_delete_plugin() { } // Check filesystem credentials. `delete_plugins()` will bail otherwise. - ob_start(); $url = wp_nonce_url( 'plugins.php?action=delete-selected&verify-delete=1&checked[]=' . $plugin, 'bulk-plugins' ); - if ( false === ( $credentials = request_filesystem_credentials( $url ) ) || ! WP_Filesystem( $credentials ) ) { + ob_start(); + $credentials = request_filesystem_credentials( $url ); + ob_end_clean(); + if ( false === $credentials || ! WP_Filesystem( $credentials ) ) { global $wp_filesystem; - ob_end_clean(); $status['errorCode'] = 'unable_to_connect_to_filesystem'; $status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' ); diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php index 0d62aecad2..cf6b4babf9 100644 --- a/wp-admin/includes/plugin.php +++ b/wp-admin/includes/plugin.php @@ -782,11 +782,13 @@ function delete_plugins( $plugins, $deprecated = '' ) { foreach ( $plugins as $plugin ) $checked[] = 'checked[]=' . $plugin; - ob_start(); $url = wp_nonce_url('plugins.php?action=delete-selected&verify-delete=1&' . implode('&', $checked), 'bulk-plugins'); - if ( false === ($credentials = request_filesystem_credentials($url)) ) { - $data = ob_get_clean(); + ob_start(); + $credentials = request_filesystem_credentials( $url ); + $data = ob_get_clean(); + + if ( false === $credentials ) { if ( ! empty($data) ){ include_once( ABSPATH . 'wp-admin/admin-header.php'); echo $data; @@ -796,8 +798,9 @@ function delete_plugins( $plugins, $deprecated = '' ) { return; } - if ( ! WP_Filesystem($credentials) ) { - request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again + if ( ! WP_Filesystem( $credentials ) ) { + ob_start(); + request_filesystem_credentials( $url, '', true ); // Failed to connect, Error and request again. $data = ob_get_clean(); if ( ! empty($data) ){ diff --git a/wp-admin/includes/theme.php b/wp-admin/includes/theme.php index fd55545146..73567e1fd1 100644 --- a/wp-admin/includes/theme.php +++ b/wp-admin/includes/theme.php @@ -23,13 +23,16 @@ function delete_theme($stylesheet, $redirect = '') { if ( empty($stylesheet) ) return false; - ob_start(); - if ( empty( $redirect ) ) + if ( empty( $redirect ) ) { $redirect = wp_nonce_url('themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet); - if ( false === ($credentials = request_filesystem_credentials($redirect)) ) { - $data = ob_get_clean(); + } - if ( ! empty($data) ){ + ob_start(); + $credentials = request_filesystem_credentials( $redirect ); + $data = ob_get_clean(); + + if ( false === $credentials ) { + if ( ! empty( $data ) ){ include_once( ABSPATH . 'wp-admin/admin-header.php'); echo $data; include( ABSPATH . 'wp-admin/admin-footer.php'); @@ -38,8 +41,9 @@ function delete_theme($stylesheet, $redirect = '') { return; } - if ( ! WP_Filesystem($credentials) ) { - request_filesystem_credentials($redirect, '', true); // Failed to connect, Error and request again + if ( ! WP_Filesystem( $credentials ) ) { + ob_start(); + request_filesystem_credentials( $redirect, '', true ); // Failed to connect, Error and request again. $data = ob_get_clean(); if ( ! empty($data) ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 97fd9664ef..d93d6245ba 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.6-beta4-38166'; +$wp_version = '4.6-beta4-38167'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.