Coding Standards: Fix instances of `WordPress.PHP.NoSilencedErrors.Discouraged`.

Noteable changes:
- The `magic_quotes_runtime` and `magic_quotes_sybase` settings were removed in PHP 5.4, so no longer need to be set.
- Some functions that use external libraries can generate errors that can't be tested for, so are globally allowed to silence errors.
- Quite a few functions would cause errors if `safe_mode` was set. This setting was removed in PHP 5.4.
- Only a handful of `header()` calls needed corresponding `headers_sent()` checks for unit tests to pass, but more may need to be added as the nightlies builds are tested.

See #46732.

Built from https://develop.svn.wordpress.org/trunk@45611


git-svn-id: http://core.svn.wordpress.org/trunk@45422 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Gary Pendergast 2019-07-09 05:45:58 +00:00
parent 4a273484f3
commit abcbee954f
44 changed files with 177 additions and 170 deletions

View File

@ -35,8 +35,8 @@ require_once( ABSPATH . 'wp-admin/includes/admin.php' );
/** Load Ajax Handlers for WordPress Core */
require_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
@header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
@header( 'X-Robots-Tag: noindex' );
header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
header( 'X-Robots-Tag: noindex' );
send_nosniff_header();
nocache_headers();

View File

@ -6,7 +6,7 @@
* @subpackage Administration
*/
@header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
if ( ! defined( 'WP_ADMIN' ) ) {
require_once( dirname( __FILE__ ) . '/admin.php' );
}

View File

@ -778,7 +778,7 @@ endif;
}
if ( file_exists( $file ) ) {
list( $width, $height, $type, $attr ) = getimagesize( $file );
list( $width, $height, $type, $attr ) = @getimagesize( $file );
} else {
$data = wp_get_attachment_metadata( $attachment_id );
$height = isset( $data['height'] ) ? $data['height'] : 0;

View File

@ -123,7 +123,7 @@ wp_enqueue_style( 'customize-controls' );
do_action( 'customize_controls_enqueue_scripts' );
// Let's roll.
@header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
wp_user_settings();
_wp_admin_html_begin();

View File

@ -3251,7 +3251,7 @@ function wp_ajax_get_revision_diffs() {
}
$return = array();
@set_time_limit( 0 );
set_time_limit( 0 );
foreach ( $_REQUEST['compare'] as $compare_key ) {
list( $compare_from, $compare_to ) = explode( ':', $compare_key ); // from:to

View File

@ -95,7 +95,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
* @return string|false The current working directory on success, false on failure.
*/
public function cwd() {
return @getcwd();
return getcwd();
}
/**
@ -126,10 +126,10 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
return false;
}
if ( ! $recursive ) {
return @chgrp( $file, $group );
return chgrp( $file, $group );
}
if ( ! $this->is_dir( $file ) ) {
return @chgrp( $file, $group );
return chgrp( $file, $group );
}
// Is a directory, and we want recursive
$file = trailingslashit( $file );
@ -165,7 +165,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
}
if ( ! $recursive || ! $this->is_dir( $file ) ) {
return @chmod( $file, $mode );
return chmod( $file, $mode );
}
// Is a directory, and we want recursive
$file = trailingslashit( $file );
@ -193,10 +193,10 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
return false;
}
if ( ! $recursive ) {
return @chown( $file, $owner );
return chown( $file, $owner );
}
if ( ! $this->is_dir( $file ) ) {
return @chown( $file, $owner );
return chown( $file, $owner );
}
// Is a directory, and we want recursive
$filelist = $this->dirlist( $file );
@ -476,7 +476,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
if ( $atime == 0 ) {
$atime = time();
}
return @touch( $file, $time, $atime );
return touch( $file, $time, $atime );
}
/**
@ -564,11 +564,11 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
$limit_file = false;
}
if ( ! $this->is_dir( $path ) ) {
if ( ! $this->is_dir( $path ) || ! $this->is_readable( $dir ) ) {
return false;
}
$dir = @dir( $path );
$dir = dir( $path );
if ( ! $dir ) {
return false;
}

View File

@ -114,7 +114,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
}
// Set the Connection to use Passive FTP
@ftp_pasv( $this->link, true );
ftp_pasv( $this->link, true );
if ( @ftp_get_option( $this->link, FTP_TIMEOUT_SEC ) < FS_TIMEOUT ) {
@ftp_set_option( $this->link, FTP_TIMEOUT_SEC, FS_TIMEOUT );
}
@ -140,7 +140,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
return false;
}
if ( ! @ftp_fget( $this->link, $temp, $file, FTP_BINARY ) ) {
if ( ! ftp_fget( $this->link, $temp, $file, FTP_BINARY ) ) {
fclose( $temp );
unlink( $tempfile );
return false;
@ -205,7 +205,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
fseek( $temp, 0 ); // Skip back to the start of the file being written to
$ret = @ftp_fput( $this->link, $file, $temp, FTP_BINARY );
$ret = ftp_fput( $this->link, $file, $temp, FTP_BINARY );
fclose( $temp );
unlink( $tempfile );
@ -223,7 +223,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
* @return string|false The current working directory on success, false on failure.
*/
public function cwd() {
$cwd = @ftp_pwd( $this->link );
$cwd = ftp_pwd( $this->link );
if ( $cwd ) {
$cwd = trailingslashit( $cwd );
}
@ -275,9 +275,9 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
// chmod the file or directory
if ( ! function_exists( 'ftp_chmod' ) ) {
return (bool) @ftp_site( $this->link, sprintf( 'CHMOD %o %s', $mode, $file ) );
return (bool) ftp_site( $this->link, sprintf( 'CHMOD %o %s', $mode, $file ) );
}
return (bool) @ftp_chmod( $this->link, $mode, $file );
return (bool) ftp_chmod( $this->link, $mode, $file );
}
/**
@ -375,10 +375,10 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
return false;
}
if ( 'f' == $type || $this->is_file( $file ) ) {
return @ftp_delete( $this->link, $file );
return ftp_delete( $this->link, $file );
}
if ( ! $recursive ) {
return @ftp_rmdir( $this->link, $file );
return ftp_rmdir( $this->link, $file );
}
$filelist = $this->dirlist( trailingslashit( $file ) );
@ -387,7 +387,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
$this->delete( trailingslashit( $file ) . $delete_file['name'], $recursive, $delete_file['type'] );
}
}
return @ftp_rmdir( $this->link, $file );
return ftp_rmdir( $this->link, $file );
}
/**
@ -399,7 +399,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
* @return bool Whether $file exists or not.
*/
public function exists( $file ) {
$list = @ftp_nlist( $this->link, $file );
$list = ftp_nlist( $this->link, $file );
if ( empty( $list ) && $this->is_dir( $file ) ) {
return true; // File is an empty directory.
@ -536,7 +536,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
return false;
}
if ( ! @ftp_mkdir( $this->link, $path ) ) {
if ( ! ftp_mkdir( $this->link, $path ) ) {
return false;
}
$this->chmod( $path, $chmod );
@ -587,7 +587,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
$b['year'] = $lucifer[3];
$b['hour'] = $lucifer[4];
$b['minute'] = $lucifer[5];
$b['time'] = @mktime( $lucifer[4] + ( strcasecmp( $lucifer[6], 'PM' ) == 0 ? 12 : 0 ), $lucifer[5], 0, $lucifer[1], $lucifer[2], $lucifer[3] );
$b['time'] = mktime( $lucifer[4] + ( strcasecmp( $lucifer[6], 'PM' ) == 0 ? 12 : 0 ), $lucifer[5], 0, $lucifer[1], $lucifer[2], $lucifer[3] );
$b['am/pm'] = $lucifer[6];
$b['name'] = $lucifer[8];
} elseif ( ! $is_windows ) {
@ -617,7 +617,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
if ( $lcount == 8 ) {
sscanf( $lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day'] );
sscanf( $lucifer[6], '%d:%d', $b['hour'], $b['minute'] );
$b['time'] = @mktime( $b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year'] );
$b['time'] = mktime( $b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year'] );
$b['name'] = $lucifer[7];
} else {
$b['month'] = $lucifer[5];
@ -678,11 +678,11 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
$limit_file = false;
}
$pwd = @ftp_pwd( $this->link );
$pwd = ftp_pwd( $this->link );
if ( ! @ftp_chdir( $this->link, $path ) ) { // Can't change to folder = folder doesn't exist.
return false;
}
$list = @ftp_rawlist( $this->link, '-a', false );
$list = ftp_rawlist( $this->link, '-a', false );
@ftp_chdir( $this->link, $pwd );
if ( empty( $list ) ) { // Empty array = non-existent folder (real folder will show . at least).

View File

@ -33,7 +33,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
$this->errors = new WP_Error();
// Check if possible to use ftp functions.
if ( ! @include_once( ABSPATH . 'wp-admin/includes/class-ftp.php' ) ) {
if ( ! include_once( ABSPATH . 'wp-admin/includes/class-ftp.php' ) ) {
return;
}
$this->ftp = new ftp();

View File

@ -484,7 +484,17 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
* @return bool True on success, false on failure.
*/
public function move( $source, $destination, $overwrite = false ) {
return @ssh2_sftp_rename( $this->sftp_link, $source, $destination );
if ( $this->exists( $destination ) ) {
if ( $overwrite ) {
// We need to remove the destination file before we can rename the source.
$this->delete( $destination, false, 'f' );
} else {
// If we're not overwriting, the rename will fail, so return early.
return false;
}
}
return ssh2_sftp_rename( $this->sftp_link, $source, $destination );
}
/**
@ -711,12 +721,12 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
$limit_file = false;
}
if ( ! $this->is_dir( $path ) ) {
if ( ! $this->is_dir( $path ) || ! $this->is_readable( $path ) ) {
return false;
}
$ret = array();
$dir = @dir( $this->sftp_path( $path ) );
$dir = dir( $this->sftp_path( $path ) );
if ( ! $dir ) {
return false;

View File

@ -465,7 +465,7 @@ class WP_Upgrader {
$destination = $args['destination'];
$clear_destination = $args['clear_destination'];
@set_time_limit( 300 );
set_time_limit( 300 );
if ( empty( $source ) || empty( $destination ) ) {
return new WP_Error( 'bad_request', $this->strings['bad_request'] );

View File

@ -165,8 +165,9 @@ function list_files( $folder = '', $levels = 100, $exclusions = array() ) {
$files[] = $folder . $file;
}
}
closedir( $dir );
}
@closedir( $dir );
return $files;
}
@ -514,7 +515,7 @@ function wp_edit_theme_plugin_file( $args ) {
}
// Make sure PHP process doesn't die before loopback requests complete.
@set_time_limit( 300 );
set_time_limit( 300 );
// Time to wait for loopback requests to finish.
$timeout = 100;
@ -780,7 +781,7 @@ function _wp_handle_upload( &$file, $overrides, $time, $action ) {
}
// A properly uploaded file will pass this test. There should be no reason to override this one.
$test_uploaded_file = 'wp_handle_upload' === $action ? @ is_uploaded_file( $file['tmp_name'] ) : @ is_readable( $file['tmp_name'] );
$test_uploaded_file = 'wp_handle_upload' === $action ? is_uploaded_file( $file['tmp_name'] ) : @is_readable( $file['tmp_name'] );
if ( ! $test_uploaded_file ) {
return call_user_func_array( $upload_error_handler, array( &$file, __( 'Specified file failed upload test.' ) ) );
}
@ -851,6 +852,7 @@ function _wp_handle_upload( &$file, $overrides, $time, $action ) {
$move_new_file = @move_uploaded_file( $file['tmp_name'], $new_file );
} else {
// use copy and unlink because rename breaks streams.
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
$move_new_file = @copy( $file['tmp_name'], $new_file );
unlink( $file['tmp_name'] );
}
@ -868,7 +870,7 @@ function _wp_handle_upload( &$file, $overrides, $time, $action ) {
// Set correct file permissions.
$stat = stat( dirname( $new_file ) );
$perms = $stat['mode'] & 0000666;
@ chmod( $new_file, $perms );
chmod( $new_file, $perms );
// Compute the URL.
$url = $uploads['url'] . "/$filename";
@ -1854,7 +1856,7 @@ function get_filesystem_method( $args = array(), $context = '', $allow_relaxed_f
$GLOBALS['_wp_filesystem_direct_method'] = 'relaxed_ownership';
}
@fclose( $temp_handle );
fclose( $temp_handle );
@unlink( $temp_file_name );
}
}

View File

@ -163,7 +163,7 @@ function wp_update_image_subsizes( $attachment_id ) {
function wp_create_image_subsizes( $file, $image_meta, $attachment_id ) {
if ( empty( $image_meta ) || ! isset( $image_meta['width'], $image_meta['height'] ) ) {
// New uploaded image.
$imagesize = getimagesize( $file );
$imagesize = @getimagesize( $file );
$image_meta['width'] = $imagesize[0];
$image_meta['height'] = $imagesize[1];
@ -450,7 +450,11 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
* @return int|float
*/
function wp_exif_frac2dec( $str ) {
@list( $n, $d ) = explode( '/', $str );
if ( false === strpos( $str, '/' ) ) {
return $str;
}
list( $n, $d ) = explode( '/', $str );
if ( ! empty( $d ) ) {
return $n / $d;
}
@ -466,8 +470,8 @@ function wp_exif_frac2dec( $str ) {
* @return int
*/
function wp_exif_date2ts( $str ) {
@list( $date, $time ) = explode( ' ', trim( $str ) );
@list( $y, $m, $d ) = explode( ':', $date );
list( $date, $time ) = explode( ' ', trim( $str ) );
list( $y, $m, $d ) = explode( ':', $date );
return strtotime( "{$y}-{$m}-{$d} {$time}" );
}
@ -863,7 +867,7 @@ function _copy_image_file( $attachment_id ) {
*/
wp_mkdir_p( dirname( $dst_file ) );
if ( ! @copy( $src_file, $dst_file ) ) {
if ( ! copy( $src_file, $dst_file ) ) {
$dst_file = false;
}
} else {

View File

@ -376,7 +376,7 @@ function get_mu_plugins() {
return $wp_plugins;
}
@closedir( $plugins_dir );
closedir( $plugins_dir );
if ( empty( $plugin_files ) ) {
return $wp_plugins;
@ -444,7 +444,7 @@ function get_dropins() {
return $dropins;
}
@closedir( $plugins_dir );
closedir( $plugins_dir );
if ( empty( $plugin_files ) ) {
return $dropins;

View File

@ -1901,7 +1901,7 @@ function iframe_header( $title = '', $deprecated = false ) {
$current_screen = get_current_screen();
@header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
_wp_admin_html_begin();
?>
<title><?php bloginfo( 'name' ); ?> &rsaquo; <?php echo $title; ?> &#8212; <?php _e( 'WordPress' ); ?></title>
@ -2324,7 +2324,7 @@ function _wp_admin_html_begin() {
$admin_html_class = ( is_admin_bar_showing() ) ? 'wp-toolbar' : '';
if ( $is_IE ) {
@header( 'X-UA-Compatible: IE=edge' );
header( 'X-UA-Compatible: IE=edge' );
}
?>

View File

@ -881,7 +881,7 @@ $_new_bundled_files = array(
function update_core( $from, $to ) {
global $wp_filesystem, $_old_files, $_new_bundled_files, $wpdb;
@set_time_limit( 300 );
set_time_limit( 300 );
/**
* Filters feedback messages displayed during the core update process.

View File

@ -608,7 +608,7 @@ https://wordpress.org/
$login_url
);
@wp_mail( $email, __( 'New WordPress Site' ), $message );
wp_mail( $email, __( 'New WordPress Site' ), $message );
}
endif;
@ -2969,7 +2969,7 @@ function make_site_theme_from_oldschool( $theme_name, $template ) {
if ( $oldfile == 'index.php' ) {
$index = implode( '', file( "$oldpath/$oldfile" ) );
if ( strpos( $index, 'WP_USE_THEMES' ) !== false ) {
if ( ! @copy( WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "$site_dir/$newfile" ) ) {
if ( ! copy( WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "$site_dir/$newfile" ) ) {
return false;
}
@ -2978,7 +2978,7 @@ function make_site_theme_from_oldschool( $theme_name, $template ) {
}
}
if ( ! @copy( "$oldpath/$oldfile", "$site_dir/$newfile" ) ) {
if ( ! copy( "$oldpath/$oldfile", "$site_dir/$newfile" ) ) {
return false;
}
@ -3045,13 +3045,14 @@ function make_site_theme_from_default( $theme_name, $template ) {
if ( is_dir( "$default_dir/$theme_file" ) ) {
continue;
}
if ( ! @copy( "$default_dir/$theme_file", "$site_dir/$theme_file" ) ) {
if ( ! copy( "$default_dir/$theme_file", "$site_dir/$theme_file" ) ) {
return;
}
chmod( "$site_dir/$theme_file", 0777 );
}
closedir( $theme_dir );
}
@closedir( $theme_dir );
// Rewrite the theme header.
$stylelines = explode( "\n", implode( '', file( "$site_dir/style.css" ) ) );
@ -3087,13 +3088,14 @@ function make_site_theme_from_default( $theme_name, $template ) {
if ( is_dir( "$default_dir/images/$image" ) ) {
continue;
}
if ( ! @copy( "$default_dir/images/$image", "$site_dir/images/$image" ) ) {
if ( ! copy( "$default_dir/images/$image", "$site_dir/images/$image" ) ) {
return;
}
chmod( "$site_dir/images/$image", 0777 );
}
closedir( $images_dir );
}
@closedir( $images_dir );
}
/**

View File

@ -26,7 +26,7 @@ wp_enqueue_script( 'set-post-thumbnail' );
wp_enqueue_style( 'imgareaselect' );
wp_enqueue_script( 'media-gallery' );
@header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
// IDs should be integers
$ID = isset( $ID ) ? (int) $ID : 0;

View File

@ -170,7 +170,7 @@ if ( $action ) {
error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
}
@ini_set( 'display_errors', true ); //Ensure that Fatal errors are displayed.
ini_set( 'display_errors', true ); //Ensure that Fatal errors are displayed.
// Go back to "sandbox" scope so we get the same errors as before
plugin_sandbox_scrape( $plugin );
/** This action is documented in wp-admin/includes/plugin.php */

View File

@ -91,7 +91,7 @@ if ( isset( $_GET['action'] ) ) {
echo '<p>' . __( 'Plugin failed to reactivate due to a fatal error.' ) . '</p>';
error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
@ini_set( 'display_errors', true ); //Ensure that Fatal errors are displayed.
ini_set( 'display_errors', true ); //Ensure that Fatal errors are displayed.
wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
include( WP_PLUGIN_DIR . '/' . $plugin );
}

View File

@ -54,7 +54,7 @@ if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) ) {
$mysql_compat = version_compare( $mysql_version, $required_mysql_version, '>=' );
}
@header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>

View File

@ -89,7 +89,7 @@ class _WP_Dependency {
* @since 2.6.0
*/
public function __construct() {
@list( $this->handle, $this->src, $this->deps, $this->ver, $this->args ) = func_get_args();
list( $this->handle, $this->src, $this->deps, $this->ver, $this->args ) = func_get_args();
if ( ! is_array( $this->deps ) ) {
$this->deps = array();
}

View File

@ -140,8 +140,10 @@ class WP_Http_Streams {
}
if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) {
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
$handle = @stream_socket_client( 'tcp://' . $proxy->host() . ':' . $proxy->port(), $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context );
} else {
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
$handle = @stream_socket_client( $connect_host . ':' . $arrURL['port'], $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context );
}

View File

@ -436,7 +436,7 @@ class WP_Image_Editor_GD extends WP_Image_Editor {
// Set correct file permissions
$stat = stat( dirname( $filename ) );
$perms = $stat['mode'] & 0000666; //same permissions as parent folder, strip off the executable bits
@ chmod( $filename, $perms );
chmod( $filename, $perms );
/**
* Filters the name of the saved image file.

View File

@ -113,6 +113,7 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
}
try {
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
return ( (bool) @Imagick::queryFormats( $imagick_extension ) );
} catch ( Exception $e ) {
return false;
@ -654,7 +655,7 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
// Set correct file permissions
$stat = stat( dirname( $filename ) );
$perms = $stat['mode'] & 0000666; //same permissions as parent folder, strip off the executable bits
@ chmod( $filename, $perms );
chmod( $filename, $perms );
/** This filter is documented in wp-includes/class-wp-image-editor-gd.php */
return array(

View File

@ -492,23 +492,15 @@ class WP {
if ( isset( $headers['Last-Modified'] ) && false === $headers['Last-Modified'] ) {
unset( $headers['Last-Modified'] );
// In PHP 5.3+, make sure we are not sending a Last-Modified header.
if ( function_exists( 'header_remove' ) ) {
@header_remove( 'Last-Modified' );
} else {
// In PHP 5.2, send an empty Last-Modified header, but only as a
// last resort to override a header already sent. #WP23021
foreach ( headers_list() as $header ) {
if ( 0 === stripos( $header, 'Last-Modified' ) ) {
$headers['Last-Modified'] = '';
break;
}
}
if ( ! headers_sent() ) {
header_remove( 'Last-Modified' );
}
}
if ( ! headers_sent() ) {
foreach ( (array) $headers as $name => $field_value ) {
@header( "{$name}: {$field_value}" );
header( "{$name}: {$field_value}" );
}
}
if ( $exit_required ) {
@ -674,8 +666,8 @@ class WP {
}
// Only set X-Pingback for single posts that allow pings.
if ( $p && pings_open( $p ) ) {
@header( 'X-Pingback: ' . get_bloginfo( 'pingback_url', 'display' ) );
if ( $p && pings_open( $p ) && ! headers_sent() ) {
header( 'X-Pingback: ' . get_bloginfo( 'pingback_url', 'display' ) );
}
// check for paged content that exceeds the max number of pages

View File

@ -2608,9 +2608,9 @@ function discover_pingback_server_uri( $url, $deprecated = '' ) {
if ( $pingback_link_offset_dquote || $pingback_link_offset_squote ) {
$quote = ( $pingback_link_offset_dquote ) ? '"' : '\'';
$pingback_link_offset = ( $quote == '"' ) ? $pingback_link_offset_dquote : $pingback_link_offset_squote;
$pingback_href_pos = @strpos( $contents, 'href=', $pingback_link_offset );
$pingback_href_pos = strpos( $contents, 'href=', $pingback_link_offset );
$pingback_href_start = $pingback_href_pos + 6;
$pingback_href_end = @strpos( $contents, $quote, $pingback_href_start );
$pingback_href_end = strpos( $contents, $quote, $pingback_href_start );
$pingback_server_url_len = $pingback_href_end - $pingback_href_start;
$pingback_server_url = substr( $contents, $pingback_href_start, $pingback_server_url_len );
@ -2808,7 +2808,7 @@ function pingback( $content, $post_id ) {
$pingback_server_url = discover_pingback_server_uri( $pagelinkedto );
if ( $pingback_server_url ) {
@ set_time_limit( 60 );
set_time_limit( 60 );
// Now, the RPC call
$pagelinkedfrom = get_permalink( $post );

View File

@ -35,6 +35,7 @@ function _wp_can_use_pcre_u( $set = null ) {
}
if ( 'reset' === $utf8_pcre ) {
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- intentional error generated to detect PCRE/u support.
$utf8_pcre = @preg_match( '/^./u', 'a' );
}

View File

@ -677,11 +677,10 @@ function spawn_cron( $gmt_time = 0 ) {
echo ' ';
// flush any buffers and send the headers
while ( @ob_end_flush() ) {
}
wp_ob_end_flush_all();
flush();
WP_DEBUG ? include_once( ABSPATH . 'wp-cron.php' ) : @include_once( ABSPATH . 'wp-cron.php' );
include_once( ABSPATH . 'wp-cron.php' );
return true;
}

View File

@ -34,7 +34,7 @@ function wp_initial_constants() {
define( 'WP_START_TIMESTAMP', microtime( true ) );
}
$current_limit = @ini_get( 'memory_limit' );
$current_limit = ini_get( 'memory_limit' );
$current_limit_int = wp_convert_hr_to_bytes( $current_limit );
// Define memory limits.
@ -61,7 +61,7 @@ function wp_initial_constants() {
// Set memory limits.
$wp_limit_int = wp_convert_hr_to_bytes( WP_MEMORY_LIMIT );
if ( -1 !== $current_limit_int && ( -1 === $wp_limit_int || $wp_limit_int > $current_limit_int ) ) {
@ini_set( 'memory_limit', WP_MEMORY_LIMIT );
ini_set( 'memory_limit', WP_MEMORY_LIMIT );
}
if ( ! isset( $blog_id ) ) {

View File

@ -1923,7 +1923,7 @@ function get_attachment_icon( $id = 0, $fullsize = false, $max_dims = false ) {
// Do we need to constrain the image?
if ( ($max_dims = apply_filters('attachment_max_dims', $max_dims)) && file_exists($src_file) ) {
$imagesize = getimagesize($src_file);
$imagesize = @getimagesize($src_file);
if (($imagesize[0] > $max_dims[0]) || $imagesize[1] > $max_dims[1] ) {
$actual_aspect = $imagesize[0] / $imagesize[1];

View File

@ -407,7 +407,7 @@ function get_the_category_rss( $type = null ) {
} elseif ( 'atom' == $type ) {
$the_list .= sprintf( '<category scheme="%1$s" term="%2$s" />', esc_attr( get_bloginfo_rss( 'url' ) ), esc_attr( $cat_name ) );
} else {
$the_list .= "\t\t<category><![CDATA[" . @html_entity_decode( $cat_name, ENT_COMPAT, get_option( 'blog_charset' ) ) . "]]></category>\n";
$the_list .= "\t\t<category><![CDATA[" . html_entity_decode( $cat_name, ENT_COMPAT, get_option( 'blog_charset' ) ) . "]]></category>\n";
}
}

View File

@ -994,7 +994,7 @@ function _wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = fals
$string = wp_kses_normalize_entities( $string );
}
$string = @htmlspecialchars( $string, $quote_style, $charset, $double_encode );
$string = htmlspecialchars( $string, $quote_style, $charset, $double_encode );
// Back-compat.
if ( 'single' === $_quote_style ) {
@ -1129,6 +1129,7 @@ function wp_check_invalid_utf8( $string, $strip = false ) {
// Check for support for utf8 in the installed PCRE library once and store the result in a static
static $utf8_pcre = null;
if ( ! isset( $utf8_pcre ) ) {
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
$utf8_pcre = @preg_match( '/^./u', 'a' );
}
// We can't demand utf8 in the PCRE installation, so just return the string in those cases
@ -1136,7 +1137,7 @@ function wp_check_invalid_utf8( $string, $strip = false ) {
return $string;
}
// preg_match fails when it encounters invalid UTF8 in $string
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- preg_match fails when it encounters invalid UTF8 in $string
if ( 1 === @preg_match( '/^./us', $string ) ) {
return $string;
}

View File

@ -97,7 +97,7 @@ function date_i18n( $dateformatstring, $timestamp_with_offset = false, $gmt = fa
global $wp_locale;
$i = $timestamp_with_offset;
if ( false === $i ) {
if ( ! is_numeric( $i ) ) {
$i = current_time( 'timestamp', $gmt );
}
@ -177,7 +177,7 @@ function date_i18n( $dateformatstring, $timestamp_with_offset = false, $gmt = fa
}
}
}
$j = @gmdate( $dateformatstring, $i );
$j = gmdate( $dateformatstring, $i );
/**
* Filters the date formatted based on the locale.
@ -224,7 +224,7 @@ function wp_maybe_decline_date( $date ) {
$months_genitive = $wp_locale->month_genitive;
// Match a format like 'j F Y' or 'j. F'
if ( @preg_match( '#^\d{1,2}\.? [^\d ]+#u', $date ) ) {
if ( preg_match( '#^\d{1,2}\.? [^\d ]+#u', $date ) ) {
foreach ( $months as $key => $month ) {
$months[ $key ] = '# ' . $month . '( |$)#u';
@ -238,7 +238,7 @@ function wp_maybe_decline_date( $date ) {
}
// Match a format like 'F jS' or 'F j' and change it to 'j F'
if ( @preg_match( '#^[^\d ]+ \d{1,2}(st|nd|rd|th)? #u', trim( $date ) ) ) {
if ( preg_match( '#^[^\d ]+ \d{1,2}(st|nd|rd|th)? #u', trim( $date ) ) ) {
foreach ( $months as $key => $month ) {
$months[ $key ] = '#' . $month . ' (\d{1,2})(st|nd|rd|th)?#u';
}
@ -1258,7 +1258,9 @@ function status_header( $code, $description = '' ) {
$status_header = apply_filters( 'status_header', $status_header, $code, $description, $protocol );
}
@header( $status_header, true, $code );
if ( ! headers_sent() ) {
header( $status_header, true, $code );
}
}
/**
@ -1310,26 +1312,18 @@ function wp_get_nocache_headers() {
* @see wp_get_nocache_headers()
*/
function nocache_headers() {
if ( headers_sent() ) {
return;
}
$headers = wp_get_nocache_headers();
unset( $headers['Last-Modified'] );
// In PHP 5.3+, make sure we are not sending a Last-Modified header.
if ( function_exists( 'header_remove' ) ) {
@header_remove( 'Last-Modified' );
} else {
// In PHP 5.2, send an empty Last-Modified header, but only as a
// last resort to override a header already sent. #WP23021
foreach ( headers_list() as $header ) {
if ( 0 === stripos( $header, 'Last-Modified' ) ) {
$headers['Last-Modified'] = '';
break;
}
}
}
header_remove( 'Last-Modified' );
foreach ( $headers as $name => $field_value ) {
@header( "{$name}: {$field_value}" );
header( "{$name}: {$field_value}" );
}
}
@ -1829,7 +1823,7 @@ function wp_mkdir_p( $target ) {
if ( $dir_perms != ( $dir_perms & ~umask() ) ) {
$folder_parts = explode( '/', substr( $target, strlen( $target_parent ) + 1 ) );
for ( $i = 1, $c = count( $folder_parts ); $i <= $c; $i++ ) {
@chmod( $target_parent . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms );
chmod( $target_parent . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms );
}
}
@ -2426,7 +2420,7 @@ function wp_upload_bits( $name, $deprecated, $bits, $time = null ) {
return array( 'error' => sprintf( __( 'Could not write file %s' ), $new_file ) );
}
@fwrite( $ifp, $bits );
fwrite( $ifp, $bits );
fclose( $ifp );
clearstatcache();
@ -2434,7 +2428,7 @@ function wp_upload_bits( $name, $deprecated, $bits, $time = null ) {
$stat = @ stat( dirname( $new_file ) );
$perms = $stat['mode'] & 0007777;
$perms = $perms & 0000666;
@ chmod( $new_file, $perms );
chmod( $new_file, $perms );
clearstatcache();
// Compute the URL
@ -2707,7 +2701,7 @@ function wp_get_image_mime( $file ) {
$imagetype = exif_imagetype( $file );
$mime = ( $imagetype ) ? image_type_to_mime_type( $imagetype ) : false;
} elseif ( function_exists( 'getimagesize' ) ) {
$imagesize = getimagesize( $file );
$imagesize = @getimagesize( $file );
$mime = ( isset( $imagesize['mime'] ) ) ? $imagesize['mime'] : false;
} else {
$mime = false;
@ -3601,6 +3595,7 @@ function wp_json_encode( $data, $options = 0, $depth = 512 ) {
// Prepare the data for JSON serialization.
$args[0] = _wp_json_prepare_data( $data );
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- json_encode() errors are handled after this call
$json = @call_user_func_array( 'json_encode', $args );
// If json_encode() was successful, no need to do more sanity checking.
@ -3775,10 +3770,13 @@ function _wp_json_prepare_data( $data ) {
* @param int $status_code The HTTP status code to output.
*/
function wp_send_json( $response, $status_code = null ) {
@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
if ( ! headers_sent() ) {
header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
if ( null !== $status_code ) {
status_header( $status_code );
}
}
echo wp_json_encode( $response );
if ( wp_doing_ajax() ) {
@ -5726,7 +5724,7 @@ function __return_empty_string() { // phpcs:ignore WordPress.NamingConventions.V
* @see https://src.chromium.org/viewvc/chrome?view=rev&revision=6985
*/
function send_nosniff_header() {
@header( 'X-Content-Type-Options: nosniff' );
header( 'X-Content-Type-Options: nosniff' );
}
/**
@ -5840,7 +5838,7 @@ function wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override = ar
* @see https://developer.mozilla.org/en/the_x-frame-options_response_header
*/
function send_frame_options_header() {
@header( 'X-Frame-Options: SAMEORIGIN' );
header( 'X-Frame-Options: SAMEORIGIN' );
}
/**
@ -6414,7 +6412,7 @@ function wp_raise_memory_limit( $context = 'admin' ) {
return false;
}
$current_limit = @ini_get( 'memory_limit' );
$current_limit = ini_get( 'memory_limit' );
$current_limit_int = wp_convert_hr_to_bytes( $current_limit );
if ( -1 === $current_limit_int ) {
@ -6486,13 +6484,13 @@ function wp_raise_memory_limit( $context = 'admin' ) {
$filtered_limit_int = wp_convert_hr_to_bytes( $filtered_limit );
if ( -1 === $filtered_limit_int || ( $filtered_limit_int > $wp_max_limit_int && $filtered_limit_int > $current_limit_int ) ) {
if ( false !== @ini_set( 'memory_limit', $filtered_limit ) ) {
if ( false !== ini_set( 'memory_limit', $filtered_limit ) ) {
return $filtered_limit;
} else {
return false;
}
} elseif ( -1 === $wp_max_limit_int || $wp_max_limit_int > $current_limit_int ) {
if ( false !== @ini_set( 'memory_limit', $wp_max_limit ) ) {
if ( false !== ini_set( 'memory_limit', $wp_max_limit ) ) {
return $wp_max_limit;
} else {
return false;

View File

@ -496,8 +496,8 @@ function send_origin_headers() {
$origin = get_http_origin();
if ( is_allowed_http_origin( $origin ) ) {
@header( 'Access-Control-Allow-Origin: ' . $origin );
@header( 'Access-Control-Allow-Credentials: true' );
header( 'Access-Control-Allow-Origin: ' . $origin );
header( 'Access-Control-Allow-Credentials: true' );
if ( 'OPTIONS' === $_SERVER['REQUEST_METHOD'] ) {
exit;
}

View File

@ -352,7 +352,7 @@ function wp_debug_mode() {
}
if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() || wp_is_json_request() ) {
@ini_set( 'display_errors', 0 );
ini_set( 'display_errors', 0 );
}
}
@ -908,6 +908,7 @@ function is_protected_ajax_action() {
function wp_set_internal_encoding() {
if ( function_exists( 'mb_internal_encoding' ) ) {
$charset = get_option( 'blog_charset' );
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
if ( ! $charset || ! @mb_internal_encoding( $charset ) ) {
mb_internal_encoding( 'UTF-8' );
}

View File

@ -238,7 +238,7 @@ function image_downsize( $id, $size = 'medium' ) {
$info = null;
if ( $thumb_file ) {
$info = getimagesize( $thumb_file );
$info = @getimagesize( $thumb_file );
}
if ( $thumb_file && $info ) {
@ -911,7 +911,7 @@ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon
$icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' );
$src_file = $icon_dir . '/' . wp_basename( $src );
@list( $width, $height ) = getimagesize( $src_file );
list( $width, $height ) = @getimagesize( $src_file );
}
}

View File

@ -1522,7 +1522,10 @@ if ( ! function_exists( 'wp_notify_postauthor' ) ) :
$switched_locale = switch_to_locale( get_locale() );
$comment_author_domain = @gethostbyaddr( $comment->comment_author_IP );
$comment_author_domain = '';
if ( WP_Http::is_ip_address( $comment->comment_author_IP ) ) {
$comment_author_domain = gethostbyaddr( $comment->comment_author_IP );
}
// The blogname option is escaped with esc_html on the way into the database in sanitize_option
// we want to reverse this for the plain text arena of emails.
@ -1639,7 +1642,7 @@ if ( ! function_exists( 'wp_notify_postauthor' ) ) :
$message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment->comment_ID );
foreach ( $emails as $email ) {
@wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers );
wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers );
}
if ( $switched_locale ) {
@ -1696,7 +1699,11 @@ if ( ! function_exists( 'wp_notify_moderator' ) ) :
$switched_locale = switch_to_locale( get_locale() );
$comment_author_domain = @gethostbyaddr( $comment->comment_author_IP );
$comment_author_domain = '';
if ( WP_Http::is_ip_address( $comment->comment_author_IP ) ) {
$comment_author_domain = gethostbyaddr( $comment->comment_author_IP );
}
$comments_waiting = $wpdb->get_var( "SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'" );
// The blogname option is escaped with esc_html on the way into the database in sanitize_option
@ -1810,7 +1817,7 @@ if ( ! function_exists( 'wp_notify_moderator' ) ) :
$message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id );
foreach ( $emails as $email ) {
@wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers );
wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers );
}
if ( $switched_locale ) {
@ -1947,7 +1954,7 @@ if ( ! function_exists( 'wp_new_user_notification' ) ) :
*/
$wp_new_user_notification_email_admin = apply_filters( 'wp_new_user_notification_email_admin', $wp_new_user_notification_email_admin, $user, $blogname );
@wp_mail(
wp_mail(
$wp_new_user_notification_email_admin['to'],
wp_specialchars_decode( sprintf( $wp_new_user_notification_email_admin['subject'], $blogname ) ),
$wp_new_user_notification_email_admin['message'],

View File

@ -1279,19 +1279,7 @@ class WP_REST_Server {
* @param string $key Header key.
*/
public function remove_header( $key ) {
if ( function_exists( 'header_remove' ) ) {
// In PHP 5.3+ there is a way to remove an already set header.
header_remove( $key );
} else {
// In PHP 5.2, send an empty header, but only as a last resort to
// override a header already sent.
foreach ( headers_list() as $header ) {
if ( 0 === stripos( $header, "$key:" ) ) {
$this->send_header( $key, '' );
break;
}
}
}
}
/**

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.3-alpha-45610';
$wp_version = '5.3-alpha-45611';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

View File

@ -1493,7 +1493,7 @@ function wp_widget_rss_output( $rss, $args = array() ) {
$title = __( 'Untitled' );
}
$desc = @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) );
$desc = html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) );
$desc = esc_attr( wp_trim_words( $desc, 55, ' [&hellip;]' ) );
$summary = '';

View File

@ -67,7 +67,7 @@ class WP_Widget_RSS extends WP_Widget {
$link = '';
if ( ! is_wp_error( $rss ) ) {
$desc = esc_attr( strip_tags( @html_entity_decode( $rss->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ) ) );
$desc = esc_attr( strip_tags( html_entity_decode( $rss->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ) ) );
if ( empty( $title ) ) {
$title = strip_tags( $rss->get_title() );
}

View File

@ -123,6 +123,7 @@ class WP_Widget_Text extends WP_Widget {
// Suppress warnings generated by loadHTML
$errors = libxml_use_internal_errors( true );
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
@$doc->loadHTML(
sprintf(
'<!DOCTYPE html><html><head><meta charset="%s"></head><body>%s</body></html>',

View File

@ -1376,7 +1376,7 @@ class wpdb {
}
array_walk( $args, array( $this, 'escape_by_ref' ) );
$query = @vsprintf( $query, $args );
$query = vsprintf( $query, $args );
return $this->add_placeholder_escape( $query );
}
@ -1614,6 +1614,7 @@ class wpdb {
if ( WP_DEBUG ) {
mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
} else {
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
@mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
}
@ -1645,6 +1646,7 @@ class wpdb {
if ( WP_DEBUG ) {
$this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
} else {
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
$this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
}
}

View File

@ -54,10 +54,6 @@ wp_register_fatal_error_handler();
// Check for the required PHP version and for the MySQL extension or a database drop-in.
wp_check_php_mysql_versions();
// Disable magic quotes at runtime. Magic quotes are added using wpdb later in wp-settings.php.
@ini_set( 'magic_quotes_runtime', 0 );
@ini_set( 'magic_quotes_sybase', 0 );
// WordPress calculates offsets from UTC.
date_default_timezone_set( 'UTC' );
@ -90,9 +86,9 @@ wp_debug_mode();
* @param bool $enable_advanced_cache Whether to enable loading advanced-cache.php (if present).
* Default true.
*/
if ( WP_CACHE && apply_filters( 'enable_loading_advanced_cache_dropin', true ) ) {
if ( WP_CACHE && apply_filters( 'enable_loading_advanced_cache_dropin', true ) && file_exists( WP_CONTENT_DIR . '/advanced-cache.php' ) ) {
// For an advanced caching plugin to use. Uses a static drop-in because you would only want one.
WP_DEBUG ? include( WP_CONTENT_DIR . '/advanced-cache.php' ) : @include( WP_CONTENT_DIR . '/advanced-cache.php' );
include( WP_CONTENT_DIR . '/advanced-cache.php' );
// Re-initialize any hooks added manually by advanced-cache.php
if ( $wp_filter ) {