Ticket #35425: 35425.wp-admin.1.diff
File 35425.wp-admin.1.diff, 41.2 KB (added by , 9 years ago) |
---|
-
src/wp-admin/includes/bookmark.php
197 197 if ( $update ) { 198 198 if ( false === $wpdb->update( $wpdb->links, compact( 'link_url', 'link_name', 'link_image', 'link_target', 'link_description', 'link_visible', 'link_rating', 'link_rel', 'link_notes', 'link_rss' ), compact( 'link_id' ) ) ) { 199 199 if ( $wp_error ) { 200 return new WP_Error( 'db_update_error', __( 'Could not update link in the database' ), $wpdb->last_error);200 return new WP_Error( 'db_update_error', __( 'Could not update link in the database' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'db_error' => $wpdb->last_error ) ); 201 201 } else { 202 202 return 0; 203 203 } … … 205 205 } else { 206 206 if ( false === $wpdb->insert( $wpdb->links, compact( 'link_url', 'link_name', 'link_image', 'link_target', 'link_description', 'link_visible', 'link_owner', 'link_rating', 'link_rel', 'link_notes', 'link_rss' ) ) ) { 207 207 if ( $wp_error ) { 208 return new WP_Error( 'db_insert_error', __( 'Could not insert link into the database' ), $wpdb->last_error);208 return new WP_Error( 'db_insert_error', __( 'Could not insert link into the database' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'db_error' => $wpdb->last_error ) ); 209 209 } else { 210 210 return 0; 211 211 } -
src/wp-admin/includes/class-wp-press-this.php
259 259 global $wp_version; 260 260 261 261 if ( empty( $url ) ) { 262 return new WP_Error( 'invalid-url', __( 'A valid URL was not provided.' ) );262 return new WP_Error( 'invalid-url', __( 'A valid URL was not provided.' ), array( 'status' => WP_Http::NOT_FOUND ) ); 263 263 } 264 264 265 265 $remote_url = wp_safe_remote_get( $url, array( -
src/wp-admin/includes/class-wp-upgrader.php
178 178 } 179 179 180 180 if ( ! is_object($wp_filesystem) ) 181 return new WP_Error( 'fs_unavailable', $this->strings['fs_unavailable']);181 return new WP_Error( 'fs_unavailable', $this->strings['fs_unavailable'], array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 182 182 183 183 if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ) 184 return new WP_Error( 'fs_error', $this->strings['fs_error'], $wp_filesystem->errors);184 return new WP_Error( 'fs_error', $this->strings['fs_error'], array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => $wp_filesystem->errors ) ); 185 185 186 186 foreach ( (array)$directories as $dir ) { 187 187 switch ( $dir ) { 188 188 case ABSPATH: 189 189 if ( ! $wp_filesystem->abspath() ) 190 return new WP_Error( 'fs_no_root_dir', $this->strings['fs_no_root_dir']);190 return new WP_Error( 'fs_no_root_dir', $this->strings['fs_no_root_dir'], array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 191 191 break; 192 192 case WP_CONTENT_DIR: 193 193 if ( ! $wp_filesystem->wp_content_dir() ) 194 return new WP_Error( 'fs_no_content_dir', $this->strings['fs_no_content_dir']);194 return new WP_Error( 'fs_no_content_dir', $this->strings['fs_no_content_dir'], array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 195 195 break; 196 196 case WP_PLUGIN_DIR: 197 197 if ( ! $wp_filesystem->wp_plugins_dir() ) 198 return new WP_Error( 'fs_no_plugins_dir', $this->strings['fs_no_plugins_dir']);198 return new WP_Error( 'fs_no_plugins_dir', $this->strings['fs_no_plugins_dir'], array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 199 199 break; 200 200 case get_theme_root(): 201 201 if ( ! $wp_filesystem->wp_themes_dir() ) 202 return new WP_Error( 'fs_no_themes_dir', $this->strings['fs_no_themes_dir']);202 return new WP_Error( 'fs_no_themes_dir', $this->strings['fs_no_themes_dir'], array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 203 203 break; 204 204 default: 205 205 if ( ! $wp_filesystem->find_folder($dir) ) 206 return new WP_Error( 'fs_no_folder', sprintf( $this->strings['fs_no_folder'], esc_html( basename( $dir ) ) ) );206 return new WP_Error( 'fs_no_folder', sprintf( $this->strings['fs_no_folder'], esc_html( basename( $dir ) ) ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 207 207 break; 208 208 } 209 209 } … … 241 241 return $package; //must be a local file.. 242 242 243 243 if ( empty($package) ) 244 return new WP_Error( 'no_package', $this->strings['no_package']);244 return new WP_Error( 'no_package', $this->strings['no_package'], array( 'status' => WP_Http::NOT_FOUND ) ); 245 245 246 246 $this->skin->feedback('downloading_package', $package); 247 247 … … 248 248 $download_file = download_url($package); 249 249 250 250 if ( is_wp_error($download_file) ) 251 return new WP_Error( 'download_failed', $this->strings['download_failed'], $download_file->get_error_message());251 return new WP_Error( 'download_failed', $this->strings['download_failed'], array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => $download_file->get_error_message() ) ); 252 252 253 253 return $download_file; 254 254 } … … 297 297 if ( is_wp_error($result) ) { 298 298 $wp_filesystem->delete($working_dir, true); 299 299 if ( 'incompatible_archive' == $result->get_error_code() ) { 300 return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], $result->get_error_data() );300 return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => $result->get_error_data() ) ); 301 301 } 302 302 return $result; 303 303 } … … 355 355 } 356 356 357 357 if ( ! empty( $unwritable_files ) ) { 358 return new WP_Error( 'files_not_writable', $this->strings['files_not_writable'], implode( ', ', $unwritable_files) );358 return new WP_Error( 'files_not_writable', $this->strings['files_not_writable'], array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => implode( ', ', $unwritable_files ) ) ); 359 359 } 360 360 361 361 if ( ! $wp_filesystem->delete( $remote_destination, true ) ) { 362 return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'] );362 return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'], array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 363 363 } 364 364 365 365 return true; … … 418 418 @set_time_limit( 300 ); 419 419 420 420 if ( empty( $source ) || empty( $destination ) ) { 421 return new WP_Error( 'bad_request', $this->strings['bad_request'] );421 return new WP_Error( 'bad_request', $this->strings['bad_request'], array( 'status' => WP_Http::BAD_REQUEST ) ); 422 422 } 423 423 $this->skin->feedback( 'installing_package' ); 424 424 … … 451 451 if ( 1 == count( $source_files ) && $wp_filesystem->is_dir( trailingslashit( $args['source'] ) . $source_files[0] . '/' ) ) { //Only one folder? Then we want its contents. 452 452 $source = trailingslashit( $args['source'] ) . trailingslashit( $source_files[0] ); 453 453 } elseif ( count( $source_files ) == 0 ) { 454 return new WP_Error( 'incompatible_archive_empty', $this->strings['incompatible_archive'], $this->strings['no_files']); // There are no files?454 return new WP_Error( 'incompatible_archive_empty', $this->strings['incompatible_archive'], array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => $this->strings['no_files'] ) ); // There are no files? 455 455 } else { // It's only a single file, the upgrader will use the folder name of this file as the destination folder. Folder name is based on zip filename. 456 456 $source = trailingslashit( $args['source'] ); 457 457 } … … 523 523 $_files = $wp_filesystem->dirlist($remote_destination); 524 524 if ( ! empty($_files) ) { 525 525 $wp_filesystem->delete($remote_source, true); //Clear out the source files. 526 return new WP_Error( 'folder_exists', $this->strings['folder_exists'], $remote_destination);526 return new WP_Error( 'folder_exists', $this->strings['folder_exists'], array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => $remote_destination ) ); 527 527 } 528 528 } 529 529 … … 530 530 //Create destination if needed 531 531 if ( ! $wp_filesystem->exists( $remote_destination ) ) { 532 532 if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) { 533 return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination);533 return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed'], array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => $remote_destination ) ); 534 534 } 535 535 } 536 536 // Copy new version of item into place. … … 1110 1110 } 1111 1111 1112 1112 if ( ! $plugins_found ) 1113 return new WP_Error( 'incompatible_archive_no_plugins', $this->strings['incompatible_archive'], __( 'No valid plugins were found.') );1113 return new WP_Error( 'incompatible_archive_no_plugins', $this->strings['incompatible_archive'], array( 'status' => WP_Http::NOT_FOUND, 'error' => __( 'No valid plugins were found.' ) ) ); 1114 1114 1115 1115 return $source; 1116 1116 } … … 1164 1164 1165 1165 $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : ''; 1166 1166 if ( empty($plugin) ) 1167 return new WP_Error( 'bad_request', $this->strings['bad_request']);1167 return new WP_Error( 'bad_request', $this->strings['bad_request'], array( 'status' => WP_Http::BAD_REQUEST ) ); 1168 1168 1169 1169 if ( is_plugin_active($plugin) ) { 1170 1170 //Deactivate the plugin silently, Prevent deactivation hooks from running. … … 1199 1199 1200 1200 $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : ''; 1201 1201 if ( empty($plugin) ) 1202 return new WP_Error( 'bad_request', $this->strings['bad_request']);1202 return new WP_Error( 'bad_request', $this->strings['bad_request'], array( 'status' => WP_Http::BAD_REQUEST ) ); 1203 1203 1204 1204 $plugins_dir = $wp_filesystem->wp_plugins_dir(); 1205 1205 $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) ); … … 1214 1214 $deleted = $wp_filesystem->delete($plugins_dir . $plugin); 1215 1215 1216 1216 if ( ! $deleted ) 1217 return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed']);1217 return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'], array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 1218 1218 1219 1219 return true; 1220 1220 } … … 1653 1653 // A proper archive should have a style.css file in the single subdirectory 1654 1654 if ( ! file_exists( $working_directory . 'style.css' ) ) { 1655 1655 return new WP_Error( 'incompatible_archive_theme_no_style', $this->strings['incompatible_archive'], 1656 /* translators: %s: style.css */ 1657 sprintf( __( 'The theme is missing the %s stylesheet.' ), 1658 '<code>style.css</code>' 1656 array( 1657 /* translators: %s: style.css */ 1658 'error' => sprintf( __( 'The theme is missing the %s stylesheet.' ), 1659 '<code>style.css</code>' 1660 ), 1661 'status' => WP_Http::INTERNAL_SERVER_ERROR, 1659 1662 ) 1660 1663 ); 1661 1664 } … … 1664 1667 1665 1668 if ( empty( $info['Name'] ) ) { 1666 1669 return new WP_Error( 'incompatible_archive_theme_no_name', $this->strings['incompatible_archive'], 1667 /* translators: %s: style.css */ 1668 sprintf( __( 'The %s stylesheet doesn’t contain a valid theme header.' ), 1669 '<code>style.css</code>' 1670 array( 1671 /* translators: %s: style.css */ 1672 'error' => sprintf( __( 'The %s stylesheet doesn’t contain a valid theme header.' ), 1673 '<code>style.css</code>' 1674 ), 1675 'status' => WP_Http::INTERNAL_SERVER_ERROR, 1670 1676 ) 1671 1677 ); 1672 1678 } … … 1674 1680 // If it's not a child theme, it must have at least an index.php to be legit. 1675 1681 if ( empty( $info['Template'] ) && ! file_exists( $working_directory . 'index.php' ) ) { 1676 1682 return new WP_Error( 'incompatible_archive_theme_no_index', $this->strings['incompatible_archive'], 1677 /* translators: %s: index.php */ 1678 sprintf( __( 'The theme is missing the %s file.' ), 1679 '<code>index.php</code>' 1683 array( 1684 /* translators: %s: index.php */ 1685 'error' => sprintf( __( 'The theme is missing the %s file.' ), 1686 '<code>index.php</code>' 1687 ), 1688 'status' => WP_Http::INTERNAL_SERVER_ERROR, 1680 1689 ) 1681 1690 ); 1682 1691 } … … 2022 2031 $remote_destination = $wp_filesystem->find_folder( WP_LANG_DIR ); 2023 2032 if ( ! $wp_filesystem->exists( $remote_destination ) ) 2024 2033 if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) 2025 return new WP_Error( 'mkdir_failed_lang_dir', $this->strings['mkdir_failed'], $remote_destination);2034 return new WP_Error( 'mkdir_failed_lang_dir', $this->strings['mkdir_failed'], array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => $remote_destination ) ); 2026 2035 2027 2036 foreach ( $language_updates as $language_update ) { 2028 2037 … … 2106 2115 2107 2116 if ( ! $mo || ! $po ) { 2108 2117 return new WP_Error( 'incompatible_archive_pomo', $this->strings['incompatible_archive'], 2109 /* translators: 1: .po 2: .mo */ 2110 sprintf( __( 'The language pack is missing either the %1$s or %2$s files.' ), 2111 '<code>.po</code>', 2112 '<code>.mo</code>' 2118 array( 2119 /* translators: 1: .po 2: .mo */ 2120 'error' => sprintf( __( 'The language pack is missing either the %1$s or %2$s files.' ), 2121 '<code>.po</code>', 2122 '<code>.mo</code>' 2123 ), 2124 'status' => WP_Http::INTERNAL_SERVER_ERROR, 2113 2125 ) 2114 2126 ); 2115 2127 } … … 2219 2231 2220 2232 // Is an update available? 2221 2233 if ( !isset( $current->response ) || $current->response == 'latest' ) 2222 return new WP_Error( 'up_to_date', $this->strings['up_to_date']);2234 return new WP_Error( 'up_to_date', $this->strings['up_to_date'], array( 'status' => WP_Http::BAD_REQUEST ) ); 2223 2235 2224 2236 $res = $this->fs_connect( array( ABSPATH, WP_CONTENT_DIR ), $parsed_args['allow_relaxed_file_ownership'] ); 2225 2237 if ( ! $res || is_wp_error( $res ) ) { … … 2263 2275 // Copy update-core.php from the new version into place. 2264 2276 if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) { 2265 2277 $wp_filesystem->delete($working_dir, true); 2266 return new WP_Error( 'copy_failed_for_update_core_file', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), 'wp-admin/includes/update-core.php');2278 return new WP_Error( 'copy_failed_for_update_core_file', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => 'wp-admin/includes/update-core.php' ) ); 2267 2279 } 2268 2280 $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE); 2269 2281 … … 2270 2282 require_once( ABSPATH . 'wp-admin/includes/update-core.php' ); 2271 2283 2272 2284 if ( ! function_exists( 'update_core' ) ) 2273 return new WP_Error( 'copy_failed_space', $this->strings['copy_failed_space'] );2285 return new WP_Error( 'copy_failed_space', $this->strings['copy_failed_space'], array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 2274 2286 2275 2287 $result = update_core( $working_dir, $wp_dir ); 2276 2288 -
src/wp-admin/includes/file.php
479 479 function download_url( $url, $timeout = 300 ) { 480 480 //WARNING: The file is not automatically deleted, The script must unlink() the file. 481 481 if ( ! $url ) 482 return new WP_Error( 'http_no_url', __('Invalid URL Provided.'));482 return new WP_Error( 'http_no_url', __('Invalid URL Provided.'), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 483 483 484 484 $tmpfname = wp_tempnam($url); 485 485 if ( ! $tmpfname ) 486 return new WP_Error( 'http_no_file', __('Could not create Temporary file.'));486 return new WP_Error( 'http_no_file', __('Could not create Temporary file.'), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 487 487 488 488 $response = wp_safe_remote_get( $url, array( 'timeout' => $timeout, 'stream' => true, 'filename' => $tmpfname ) ); 489 489 … … 494 494 495 495 if ( 200 != wp_remote_retrieve_response_code( $response ) ){ 496 496 unlink( $tmpfname ); 497 return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ) );497 return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ), array( 'status' => WP_Http::NOT_FOUND ) ); 498 498 } 499 499 500 500 $content_md5 = wp_remote_retrieve_header( $response, 'content-md5' ); … … 531 531 if ( $file_md5 === $expected_raw_md5 ) 532 532 return true; 533 533 534 return new WP_Error( 'md5_mismatch', sprintf( __( 'The checksum of the file (%1$s) does not match the expected checksum value (%2$s).' ), bin2hex( $file_md5 ), bin2hex( $expected_raw_md5) ) );534 return new WP_Error( 'md5_mismatch', sprintf( __( 'The checksum of the file (%1$s) does not match the expected checksum value (%2$s).' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => bin2hex( $file_md5 ), bin2hex( $expected_raw_md5 ) ) ) ); 535 535 } 536 536 537 537 /** … … 553 553 global $wp_filesystem; 554 554 555 555 if ( ! $wp_filesystem || !is_object($wp_filesystem) ) 556 return new WP_Error( 'fs_unavailable', __('Could not access filesystem.'));556 return new WP_Error( 'fs_unavailable', __('Could not access filesystem.'), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 557 557 558 558 // Unzip can use a lot of memory, but not this much hopefully 559 559 /** This filter is documented in wp-admin/admin.php */ … … 622 622 623 623 $zopen = $z->open( $file, ZIPARCHIVE::CHECKCONS ); 624 624 if ( true !== $zopen ) 625 return new WP_Error( 'incompatible_archive', __( 'Incompatible Archive.' ), array( ' ziparchive_error' => $zopen ) );625 return new WP_Error( 'incompatible_archive', __( 'Incompatible Archive.' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'ziparchive_error' => $zopen ) ); 626 626 627 627 $uncompressed_size = 0; 628 628 629 629 for ( $i = 0; $i < $z->numFiles; $i++ ) { 630 630 if ( ! $info = $z->statIndex($i) ) 631 return new WP_Error( 'stat_failed_ziparchive', __( 'Could not retrieve file from archive.' ) );631 return new WP_Error( 'stat_failed_ziparchive', __( 'Could not retrieve file from archive.' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 632 632 633 633 if ( '__MACOSX/' === substr($info['name'], 0, 9) ) // Skip the OS X-created __MACOSX directory 634 634 continue; … … 649 649 if ( defined( 'DOING_CRON' ) && DOING_CRON ) { 650 650 $available_space = @disk_free_space( WP_CONTENT_DIR ); 651 651 if ( $available_space && ( $uncompressed_size * 2.1 ) > $available_space ) 652 return new WP_Error( 'disk_full_unzip_file', __( 'Could not copy files. You may have run out of disk space.' ), compact( 'uncompressed_size', 'available_space') );652 return new WP_Error( 'disk_full_unzip_file', __( 'Could not copy files. You may have run out of disk space.' ), array( 'status' => WP_Http::INSUFFICIENT_STORAGE, 'error' => compact( 'uncompressed_size', 'available_space' ) ) ); 653 653 } 654 654 655 655 $needed_dirs = array_unique($needed_dirs); … … 672 672 foreach ( $needed_dirs as $_dir ) { 673 673 // Only check to see if the Dir exists upon creation failure. Less I/O this way. 674 674 if ( ! $wp_filesystem->mkdir( $_dir, FS_CHMOD_DIR ) && ! $wp_filesystem->is_dir( $_dir ) ) { 675 return new WP_Error( 'mkdir_failed_ziparchive', __( 'Could not create directory.' ), substr( $_dir, strlen( $to) ) );675 return new WP_Error( 'mkdir_failed_ziparchive', __( 'Could not create directory.' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => substr( $_dir, strlen( $to ) ) ) ); 676 676 } 677 677 } 678 678 unset($needed_dirs); … … 679 679 680 680 for ( $i = 0; $i < $z->numFiles; $i++ ) { 681 681 if ( ! $info = $z->statIndex($i) ) 682 return new WP_Error( 'stat_failed_ziparchive', __( 'Could not retrieve file from archive.' ) );682 return new WP_Error( 'stat_failed_ziparchive', __( 'Could not retrieve file from archive.' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 683 683 684 684 if ( '/' == substr($info['name'], -1) ) // directory 685 685 continue; … … 689 689 690 690 $contents = $z->getFromIndex($i); 691 691 if ( false === $contents ) 692 return new WP_Error( 'extract_failed_ziparchive', __( 'Could not extract file from archive.' ), $info['name'] );692 return new WP_Error( 'extract_failed_ziparchive', __( 'Could not extract file from archive.' ), $info['name'], array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 693 693 694 694 if ( ! $wp_filesystem->put_contents( $to . $info['name'], $contents, FS_CHMOD_FILE) ) 695 return new WP_Error( 'copy_failed_ziparchive', __( 'Could not copy file.' ), $info['name'] );695 return new WP_Error( 'copy_failed_ziparchive', __( 'Could not copy file.' ), $info['name'], array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 696 696 } 697 697 698 698 $z->close(); … … 730 730 731 731 // Is the archive valid? 732 732 if ( !is_array($archive_files) ) 733 return new WP_Error( 'incompatible_archive', __('Incompatible Archive.'), $archive->errorInfo(true));733 return new WP_Error( 'incompatible_archive', __('Incompatible Archive.'), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => $archive->errorInfo(true) ) ); 734 734 735 735 if ( 0 == count($archive_files) ) 736 return new WP_Error( 'empty_archive_pclzip', __( 'Empty archive.' ) );736 return new WP_Error( 'empty_archive_pclzip', __( 'Empty archive.' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 737 737 738 738 $uncompressed_size = 0; 739 739 … … 755 755 if ( defined( 'DOING_CRON' ) && DOING_CRON ) { 756 756 $available_space = @disk_free_space( WP_CONTENT_DIR ); 757 757 if ( $available_space && ( $uncompressed_size * 2.1 ) > $available_space ) 758 return new WP_Error( 'disk_full_unzip_file', __( 'Could not copy files. You may have run out of disk space.' ), compact( 'uncompressed_size', 'available_space') );758 return new WP_Error( 'disk_full_unzip_file', __( 'Could not copy files. You may have run out of disk space.' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => compact( 'uncompressed_size', 'available_space' ) ) ); 759 759 } 760 760 761 761 $needed_dirs = array_unique($needed_dirs); … … 778 778 foreach ( $needed_dirs as $_dir ) { 779 779 // Only check to see if the dir exists upon creation failure. Less I/O this way. 780 780 if ( ! $wp_filesystem->mkdir( $_dir, FS_CHMOD_DIR ) && ! $wp_filesystem->is_dir( $_dir ) ) 781 return new WP_Error( 'mkdir_failed_pclzip', __( 'Could not create directory.' ), substr( $_dir, strlen( $to) ) );781 return new WP_Error( 'mkdir_failed_pclzip', __( 'Could not create directory.' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => substr( $_dir, strlen( $to ) ) ) ); 782 782 } 783 783 unset($needed_dirs); 784 784 … … 791 791 continue; 792 792 793 793 if ( ! $wp_filesystem->put_contents( $to . $file['filename'], $file['content'], FS_CHMOD_FILE) ) 794 return new WP_Error( 'copy_failed_pclzip', __( 'Could not copy file.' ), $file['filename'] );794 return new WP_Error( 'copy_failed_pclzip', __( 'Could not copy file.' ), $file['filename'], array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 795 795 } 796 796 return true; 797 797 } … … 826 826 // If copy failed, chmod file to 0644 and try again. 827 827 $wp_filesystem->chmod( $to . $filename, FS_CHMOD_FILE ); 828 828 if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) 829 return new WP_Error( 'copy_failed_copy_dir', __( 'Could not copy file.' ), $to . $filename);829 return new WP_Error( 'copy_failed_copy_dir', __( 'Could not copy file.' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => $to . $filename ) ); 830 830 } 831 831 } elseif ( 'd' == $fileinfo['type'] ) { 832 832 if ( !$wp_filesystem->is_dir($to . $filename) ) { 833 833 if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) ) 834 return new WP_Error( 'mkdir_failed_copy_dir', __( 'Could not create directory.' ), $to . $filename);834 return new WP_Error( 'mkdir_failed_copy_dir', __( 'Could not create directory.' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => $to . $filename ) ); 835 835 } 836 836 837 837 // generate the $sub_skip_list for the subdirectory as a sub-set of the existing $skip_list -
src/wp-admin/includes/media.php
278 278 $file = wp_handle_upload($_FILES[$file_id], $overrides, $time); 279 279 280 280 if ( isset($file['error']) ) 281 return new WP_Error( 'upload_error', $file['error'] );281 return new WP_Error( 'upload_error', $file['error'], array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 282 282 283 283 $name_parts = pathinfo($name); 284 284 $name = trim( substr( $name, 0, -(1 + strlen($name_parts['extension'])) ) ); … … 397 397 398 398 $file = wp_handle_sideload( $file_array, $overrides, $time ); 399 399 if ( isset($file['error']) ) 400 return new WP_Error( 'upload_error', $file['error'] );400 return new WP_Error( 'upload_error', $file['error'], array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 401 401 402 402 $url = $file['url']; 403 403 $type = $file['type']; … … 851 851 // Set variables for storage, fix file filename for query strings. 852 852 preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches ); 853 853 if ( ! $matches ) { 854 return new WP_Error( 'image_sideload_failed', __( 'Invalid image URL' ) );854 return new WP_Error( 'image_sideload_failed', __( 'Invalid image URL' ), array( 'status' => WP_Http::NOT_FOUND ) ); 855 855 } 856 856 857 857 $file_array = array(); … … 887 887 $html = "<img src='$src' alt='$alt' />"; 888 888 return $html; 889 889 } else { 890 return new WP_Error( 'image_sideload_failed' );890 return new WP_Error( 'image_sideload_failed', null, array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 891 891 } 892 892 } 893 893 -
src/wp-admin/includes/nav-menu.php
906 906 /* translators: %s: walker class name */ 907 907 sprintf( __( 'The Walker class named %s does not exist.' ), 908 908 '<strong>' . $walker_class_name . '</strong>' 909 ) 909 ), 910 array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) 910 911 ); 911 912 } 912 913 -
src/wp-admin/includes/plugin.php
601 601 602 602 if ( ob_get_length() > 0 ) { 603 603 $output = ob_get_clean(); 604 return new WP_Error( 'unexpected_output', __('The plugin generated unexpected output.'), $output);604 return new WP_Error( 'unexpected_output', __('The plugin generated unexpected output.'), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => $output ) ); 605 605 } 606 606 ob_end_clean(); 607 607 } … … 738 738 } 739 739 740 740 if ( !empty($errors) ) 741 return new WP_Error( 'plugins_invalid', __('One of the plugins is invalid.'), $errors);741 return new WP_Error( 'plugins_invalid', __('One of the plugins is invalid.'), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => $errors ) ); 742 742 743 743 return true; 744 744 } … … 793 793 } 794 794 795 795 if ( ! is_object($wp_filesystem) ) 796 return new WP_Error( 'fs_unavailable', __('Could not access filesystem.'));796 return new WP_Error( 'fs_unavailable', __('Could not access filesystem.'), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 797 797 798 798 if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ) 799 return new WP_Error( 'fs_error', __('Filesystem error.'), $wp_filesystem->errors);799 return new WP_Error( 'fs_error', __('Filesystem error.'), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => $wp_filesystem->errors ) ); 800 800 801 801 // Get the base plugin folder. 802 802 $plugins_dir = $wp_filesystem->wp_plugins_dir(); 803 803 if ( empty( $plugins_dir ) ) { 804 return new WP_Error( 'fs_no_plugins_dir', __( 'Unable to locate WordPress Plugin directory.' ) );804 return new WP_Error( 'fs_no_plugins_dir', __( 'Unable to locate WordPress Plugin directory.' ), array( 'status' => WP_Http::NOT_FOUND ) ); 805 805 } 806 806 807 807 $plugins_dir = trailingslashit( $plugins_dir ); … … 874 874 } 875 875 876 876 if ( ! empty($errors) ) 877 return new WP_Error( 'could_not_remove_plugin', sprintf(__('Could not fully remove the plugin(s) %s.'), implode(', ', $errors)) );877 return new WP_Error( 'could_not_remove_plugin', sprintf( __( 'Could not fully remove the plugin(s) %s.' ), implode( ', ', $errors ) ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 878 878 879 879 return true; 880 880 } … … 929 929 */ 930 930 function validate_plugin($plugin) { 931 931 if ( validate_file($plugin) ) 932 return new WP_Error( 'plugin_invalid', __('Invalid plugin path.'));932 return new WP_Error( 'plugin_invalid', __( 'Invalid plugin path.' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 933 933 if ( ! file_exists(WP_PLUGIN_DIR . '/' . $plugin) ) 934 return new WP_Error( 'plugin_not_found', __('Plugin file does not exist.'));934 return new WP_Error( 'plugin_not_found', __( 'Plugin file does not exist.' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 935 935 936 936 $installed_plugins = get_plugins(); 937 937 if ( ! isset($installed_plugins[$plugin]) ) 938 return new WP_Error( 'no_plugin_header', __('The plugin does not have a valid header.'));938 return new WP_Error( 'no_plugin_header', __( 'The plugin does not have a valid header.' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 939 939 return 0; 940 940 } 941 941 -
src/wp-admin/includes/post.php
30 30 31 31 if ( $update && ! current_user_can( 'edit_post', $post_data['ID'] ) ) { 32 32 if ( 'page' == $post_data['post_type'] ) 33 return new WP_Error( 'edit_others_pages', __( 'You are not allowed to edit pages as this user.' ) );33 return new WP_Error( 'edit_others_pages', __( 'You are not allowed to edit pages as this user.' ), array( 'status' => WP_Http::FORBIDDEN ) ); 34 34 else 35 return new WP_Error( 'edit_others_posts', __( 'You are not allowed to edit posts as this user.' ) );35 return new WP_Error( 'edit_others_posts', __( 'You are not allowed to edit posts as this user.' ), array( 'status' => WP_Http::FORBIDDEN ) ); 36 36 } elseif ( ! $update && ! current_user_can( $ptype->cap->create_posts ) ) { 37 37 if ( 'page' == $post_data['post_type'] ) 38 return new WP_Error( 'edit_others_pages', __( 'You are not allowed to create pages as this user.' ) );38 return new WP_Error( 'edit_others_pages', __( 'You are not allowed to create pages as this user.' ), array( 'status' => WP_Http::FORBIDDEN ) ); 39 39 else 40 return new WP_Error( 'edit_others_posts', __( 'You are not allowed to create posts as this user.' ) );40 return new WP_Error( 'edit_others_posts', __( 'You are not allowed to create posts as this user.' ), array( 'status' => WP_Http::FORBIDDEN ) ); 41 41 } 42 42 43 43 if ( isset( $post_data['content'] ) ) … … 68 68 && ! current_user_can( $ptype->cap->edit_others_posts ) ) { 69 69 if ( $update ) { 70 70 if ( 'page' == $post_data['post_type'] ) 71 return new WP_Error( 'edit_others_pages', __( 'You are not allowed to edit pages as this user.' ) );71 return new WP_Error( 'edit_others_pages', __( 'You are not allowed to edit pages as this user.' ), array( 'status' => WP_Http::FORBIDDEN ) ); 72 72 else 73 return new WP_Error( 'edit_others_posts', __( 'You are not allowed to edit posts as this user.' ) );73 return new WP_Error( 'edit_others_posts', __( 'You are not allowed to edit posts as this user.' ), array( 'status' => WP_Http::FORBIDDEN ) ); 74 74 } else { 75 75 if ( 'page' == $post_data['post_type'] ) 76 return new WP_Error( 'edit_others_pages', __( 'You are not allowed to create pages as this user.' ) );76 return new WP_Error( 'edit_others_pages', __( 'You are not allowed to create pages as this user.' ), array( 'status' => WP_Http::FORBIDDEN ) ); 77 77 else 78 return new WP_Error( 'edit_others_posts', __( 'You are not allowed to create posts as this user.' ) );78 return new WP_Error( 'edit_others_posts', __( 'You are not allowed to create posts as this user.' ), array( 'status' => WP_Http::FORBIDDEN ) ); 79 79 } 80 80 } 81 81 … … 160 160 $post_data['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss ); 161 161 $valid_date = wp_checkdate( $mm, $jj, $aa, $post_data['post_date'] ); 162 162 if ( !$valid_date ) { 163 return new WP_Error( 'invalid_date', __( 'Whoops, the provided date is invalid.' ) );163 return new WP_Error( 'invalid_date', __( 'Whoops, the provided date is invalid.' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 164 164 } 165 165 $post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] ); 166 166 } … … 714 714 715 715 if ( !current_user_can( $ptype->cap->edit_posts ) ) { 716 716 if ( 'page' == $ptype->name ) 717 return new WP_Error( 'edit_pages', __( 'You are not allowed to create pages on this site.' ) );717 return new WP_Error( 'edit_pages', __( 'You are not allowed to create pages on this site.' ), array( 'status' => WP_Http::FORBIDDEN ) ); 718 718 else 719 return new WP_Error( 'edit_posts', __( 'You are not allowed to create posts or drafts on this site.' ) );719 return new WP_Error( 'edit_posts', __( 'You are not allowed to create posts or drafts on this site.' ), array( 'status' => WP_Http::FORBIDDEN ) ); 720 720 } 721 721 722 722 $_POST['post_mime_type'] = ''; … … 1768 1768 $post_data['ID'] = $post_data['post_ID'] = $post_id; 1769 1769 1770 1770 if ( false === wp_verify_nonce( $post_data['_wpnonce'], 'update-post_' . $post_id ) ) { 1771 return new WP_Error( 'invalid_nonce', __( 'Error while saving.' ) );1771 return new WP_Error( 'invalid_nonce', __( 'Error while saving.' ), array( 'status' => WP_Http::FORBIDDEN ) ); 1772 1772 } 1773 1773 1774 1774 $post = get_post( $post_id ); 1775 1775 1776 1776 if ( ! current_user_can( 'edit_post', $post->ID ) ) { 1777 return new WP_Error( 'edit_posts', __( 'You are not allowed to edit this item.' ) );1777 return new WP_Error( 'edit_posts', __( 'You are not allowed to edit this item.' ), array( 'status' => WP_Http::FORBIDDEN ) ); 1778 1778 } 1779 1779 1780 1780 if ( 'auto-draft' == $post->post_status ) -
src/wp-admin/includes/schema.php
1103 1103 1104 1104 $msg .= '<p>' . __( 'You can still use your site but any subdomain you create may not be accessible. If you know your DNS is correct, ignore this message.' ) . '</p>'; 1105 1105 1106 return new WP_Error( 'no_wildcard_dns', $msg );1106 return new WP_Error( 'no_wildcard_dns', $msg, array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 1107 1107 } 1108 1108 } 1109 1109 -
src/wp-admin/includes/taxonomy.php
113 113 if ( ! $wp_error ) { 114 114 return 0; 115 115 } else { 116 return new WP_Error( 'cat_name', __( 'You did not enter a category name.' ) );116 return new WP_Error( 'cat_name', __( 'You did not enter a category name.' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 117 117 } 118 118 } 119 119 -
src/wp-admin/includes/theme.php
52 52 } 53 53 54 54 if ( ! is_object($wp_filesystem) ) 55 return new WP_Error( 'fs_unavailable', __('Could not access filesystem.'));55 return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 56 56 57 57 if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ) 58 return new WP_Error( 'fs_error', __('Filesystem error.'), $wp_filesystem->errors);58 return new WP_Error( 'fs_error', __( 'Filesystem error.' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => $wp_filesystem->errors ) ); 59 59 60 60 // Get the base plugin folder. 61 61 $themes_dir = $wp_filesystem->wp_themes_dir(); 62 62 if ( empty( $themes_dir ) ) { 63 return new WP_Error( 'fs_no_themes_dir', __( 'Unable to locate WordPress theme directory.' ) );63 return new WP_Error( 'fs_no_themes_dir', __( 'Unable to locate WordPress theme directory.' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 64 64 } 65 65 66 66 $themes_dir = trailingslashit( $themes_dir ); … … 68 68 $deleted = $wp_filesystem->delete( $theme_dir, true ); 69 69 70 70 if ( ! $deleted ) { 71 return new WP_Error( 'could_not_remove_theme', sprintf( __( 'Could not fully remove the theme %s.' ), $stylesheet ) );71 return new WP_Error( 'could_not_remove_theme', sprintf( __( 'Could not fully remove the theme %s.' ), $stylesheet ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 72 72 } 73 73 74 74 $theme_translations = wp_get_installed_translations( 'themes' ); -
src/wp-admin/includes/update-core.php
831 831 } 832 832 if ( ! $distro ) { 833 833 $wp_filesystem->delete( $from, true ); 834 return new WP_Error( 'insane_distro', __('The update could not be unpacked') );834 return new WP_Error( 'insane_distro', __('The update could not be unpacked'), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 835 835 } 836 836 837 837 … … 848 848 $versions_file = trailingslashit( $wp_filesystem->wp_content_dir() ) . 'upgrade/version-current.php'; 849 849 if ( ! $wp_filesystem->copy( $from . $distro . 'wp-includes/version.php', $versions_file ) ) { 850 850 $wp_filesystem->delete( $from, true ); 851 return new WP_Error( 'copy_failed_for_version_file', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), 'wp-includes/version.php');851 return new WP_Error( 'copy_failed_for_version_file', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => 'wp-includes/version.php' ) ); 852 852 } 853 853 854 854 $wp_filesystem->chmod( $versions_file, FS_CHMOD_FILE ); … … 869 869 $wp_filesystem->delete($from, true); 870 870 871 871 if ( !$mysql_compat && !$php_compat ) 872 return new WP_Error( 'php_mysql_not_compatible', sprintf( __('The update cannot be installed because WordPress %1$s requires PHP version %2$s or higher and MySQL version %3$s or higher. You are running PHP version %4$s and MySQL version %5$s.'), $wp_version, $required_php_version, $required_mysql_version, $php_version, $mysql_version ) );872 return new WP_Error( 'php_mysql_not_compatible', sprintf( __('The update cannot be installed because WordPress %1$s requires PHP version %2$s or higher and MySQL version %3$s or higher. You are running PHP version %4$s and MySQL version %5$s.'), $wp_version, $required_php_version, $required_mysql_version, $php_version, $mysql_version ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 873 873 elseif ( !$php_compat ) 874 return new WP_Error( 'php_not_compatible', sprintf( __('The update cannot be installed because WordPress %1$s requires PHP version %2$s or higher. You are running version %3$s.'), $wp_version, $required_php_version, $php_version ) );874 return new WP_Error( 'php_not_compatible', sprintf( __('The update cannot be installed because WordPress %1$s requires PHP version %2$s or higher. You are running version %3$s.'), $wp_version, $required_php_version, $php_version ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 875 875 elseif ( !$mysql_compat ) 876 return new WP_Error( 'mysql_not_compatible', sprintf( __('The update cannot be installed because WordPress %1$s requires MySQL version %2$s or higher. You are running version %3$s.'), $wp_version, $required_mysql_version, $mysql_version ) );876 return new WP_Error( 'mysql_not_compatible', sprintf( __('The update cannot be installed because WordPress %1$s requires MySQL version %2$s or higher. You are running version %3$s.'), $wp_version, $required_mysql_version, $mysql_version ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR ) ); 877 877 878 878 /** This filter is documented in wp-admin/includes/update-core.php */ 879 879 apply_filters( 'update_feedback', __( 'Preparing to install the latest version…' ) ); … … 923 923 $error_data = version_compare( $old_wp_version, '3.7-beta2', '>' ) ? array_keys( $files_not_writable ) : ''; 924 924 925 925 if ( $files_not_writable ) 926 return new WP_Error( 'files_not_writable', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), implode( ', ', $error_data) );926 return new WP_Error( 'files_not_writable', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => implode( ', ', $error_data ) ) ); 927 927 } 928 928 } 929 929 … … 1159 1159 // If copy failed, chmod file to 0644 and try again. 1160 1160 $wp_filesystem->chmod( $to . $filename, FS_CHMOD_FILE ); 1161 1161 if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) 1162 return new WP_Error( 'copy_failed__copy_dir', __( 'Could not copy file.' ), $to . $filename);1162 return new WP_Error( 'copy_failed__copy_dir', __( 'Could not copy file.' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => $to . $filename ) ); 1163 1163 } 1164 1164 } elseif ( 'd' == $fileinfo['type'] ) { 1165 1165 if ( !$wp_filesystem->is_dir($to . $filename) ) { 1166 1166 if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) ) 1167 return new WP_Error( 'mkdir_failed__copy_dir', __( 'Could not create directory.' ), $to . $filename);1167 return new WP_Error( 'mkdir_failed__copy_dir', __( 'Could not create directory.' ), array( 'status' => WP_Http::INTERNAL_SERVER_ERROR, 'error' => $to . $filename ) ); 1168 1168 } 1169 1169 1170 1170 /*