General: Fix various issues flagged by the PHPCompatibilityWP PHPCS ruleset.
As part of the continued effort to improve PHP compatibility, the following improvments are being made: - Removing deprecated PHP `safe_mode` checks not found in bundled external libraries. - Change the remaining `while` loops using `each()` to `foreach` loops. - Prevent false positives from being flagged for the `sodium_compat` library being caused by loading this in a non-standard way. - Add inline comments to not flag deprecated PHP directives in the getID3 library. Props desrosj, earnjam, dryanpress. See #49922. git-svn-id: https://develop.svn.wordpress.org/trunk@47735 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
05423578d7
commit
8e2de8212b
@ -40,6 +40,22 @@
|
|||||||
-->
|
-->
|
||||||
<exclude-pattern>/vendor/*</exclude-pattern>
|
<exclude-pattern>/vendor/*</exclude-pattern>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
PHPCompatibilityParagonieSodiumCompat prevents false positives in `sodium_compat`.
|
||||||
|
However, because these files are included in a non-standard path, false positives are triggered in WordPress Core.
|
||||||
|
-->
|
||||||
|
<exclude-pattern>src/wp-includes/sodium_compat/lib/php72compat_const\.php$</exclude-pattern>
|
||||||
|
|
||||||
|
<rule ref="PHPCompatibility.FunctionUse.NewFunctions.sodium_crypto_sign_keypair_from_secretkey_and_publickeyFound">
|
||||||
|
<exclude-pattern>/sodium_compat/src/Compat\.php$</exclude-pattern>
|
||||||
|
</rule>
|
||||||
|
<rule ref="PHPCompatibility.FunctionUse.NewFunctions.sodium_padFound">
|
||||||
|
<exclude-pattern>/sodium_compat/src/Compat\.php$</exclude-pattern>
|
||||||
|
</rule>
|
||||||
|
<rule ref="PHPCompatibility.FunctionUse.NewFunctions.sodium_unpadFound">
|
||||||
|
<exclude-pattern>/sodium_compat/src/Compat\.php$</exclude-pattern>
|
||||||
|
</rule>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
PHPCompatibilityParagonieRandomCompat prevents false positives in `random_compat`.
|
PHPCompatibilityParagonieRandomCompat prevents false positives in `random_compat`.
|
||||||
However, because these files are included in a non-standard path, false positives are triggered in WordPress Core.
|
However, because these files are included in a non-standard path, false positives are triggered in WordPress Core.
|
||||||
|
@ -369,13 +369,6 @@ function populate_options( array $options = array() ) {
|
|||||||
*/
|
*/
|
||||||
do_action( 'populate_options' );
|
do_action( 'populate_options' );
|
||||||
|
|
||||||
if ( ini_get( 'safe_mode' ) ) {
|
|
||||||
// Safe mode can break mkdir() so use a flat structure by default.
|
|
||||||
$uploads_use_yearmonth_folders = 0;
|
|
||||||
} else {
|
|
||||||
$uploads_use_yearmonth_folders = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If WP_DEFAULT_THEME doesn't exist, fall back to the latest core default theme.
|
// If WP_DEFAULT_THEME doesn't exist, fall back to the latest core default theme.
|
||||||
$stylesheet = WP_DEFAULT_THEME;
|
$stylesheet = WP_DEFAULT_THEME;
|
||||||
$template = WP_DEFAULT_THEME;
|
$template = WP_DEFAULT_THEME;
|
||||||
@ -466,7 +459,7 @@ function populate_options( array $options = array() ) {
|
|||||||
'db_version' => $wp_db_version,
|
'db_version' => $wp_db_version,
|
||||||
|
|
||||||
// 2.0.1
|
// 2.0.1
|
||||||
'uploads_use_yearmonth_folders' => $uploads_use_yearmonth_folders,
|
'uploads_use_yearmonth_folders' => 1,
|
||||||
'upload_path' => '',
|
'upload_path' => '',
|
||||||
|
|
||||||
// 2.1
|
// 2.1
|
||||||
|
@ -285,7 +285,7 @@ class getID3
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check safe_mode off
|
// Check safe_mode off
|
||||||
if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) {
|
if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { // phpcs:ignore // phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.get_magic_quotes_runtimeDeprecated
|
||||||
$this->warning('WARNING: Safe mode is on, shorten support disabled, md5data/sha1data for ogg vorbis disabled, ogg vorbos/flac tag writing disabled.');
|
$this->warning('WARNING: Safe mode is on, shorten support disabled, md5data/sha1data for ogg vorbis disabled, ogg vorbos/flac tag writing disabled.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,13 +300,13 @@ class getID3
|
|||||||
if (version_compare(PHP_VERSION, '7.4.0', '<')) {
|
if (version_compare(PHP_VERSION, '7.4.0', '<')) {
|
||||||
// Check for magic_quotes_runtime
|
// Check for magic_quotes_runtime
|
||||||
if (function_exists('get_magic_quotes_runtime')) {
|
if (function_exists('get_magic_quotes_runtime')) {
|
||||||
if (get_magic_quotes_runtime()) {
|
if (get_magic_quotes_runtime()) { // phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.get_magic_quotes_runtimeDeprecated
|
||||||
$this->startup_error .= 'magic_quotes_runtime must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_runtime(0) and set_magic_quotes_runtime(1).'."\n";
|
$this->startup_error .= 'magic_quotes_runtime must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_runtime(0) and set_magic_quotes_runtime(1).'."\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check for magic_quotes_gpc
|
// Check for magic_quotes_gpc
|
||||||
if (function_exists('get_magic_quotes_gpc')) {
|
if (function_exists('get_magic_quotes_gpc')) {
|
||||||
if (get_magic_quotes_gpc()) {
|
if (get_magic_quotes_gpc()) { // phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.get_magic_quotes_gpcDeprecated
|
||||||
$this->startup_error .= 'magic_quotes_gpc must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_gpc(0) and set_magic_quotes_gpc(1).'."\n";
|
$this->startup_error .= 'magic_quotes_gpc must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_gpc(0) and set_magic_quotes_gpc(1).'."\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1560,7 +1560,7 @@ class getID3
|
|||||||
// page sequence numbers likely happens for OggSpeex and OggFLAC as well, but
|
// page sequence numbers likely happens for OggSpeex and OggFLAC as well, but
|
||||||
// currently vorbiscomment only works on OggVorbis files.
|
// currently vorbiscomment only works on OggVorbis files.
|
||||||
|
|
||||||
if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) {
|
if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { // phpcs:ignore // phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.get_magic_quotes_runtimeDeprecated
|
||||||
|
|
||||||
$this->warning('Failed making system call to vorbiscomment.exe - '.$algorithm.'_data is incorrect - error returned: PHP running in Safe Mode (backtick operator not available)');
|
$this->warning('Failed making system call to vorbiscomment.exe - '.$algorithm.'_data is incorrect - error returned: PHP running in Safe Mode (backtick operator not available)');
|
||||||
$this->info[$algorithm.'_data'] = false;
|
$this->info[$algorithm.'_data'] = false;
|
||||||
|
@ -183,7 +183,7 @@ class Snoopy
|
|||||||
$frameurls = $this->_frameurls;
|
$frameurls = $this->_frameurls;
|
||||||
$this->_frameurls = array();
|
$this->_frameurls = array();
|
||||||
|
|
||||||
while(list(,$frameurl) = each($frameurls))
|
foreach ( $frameurls as $frameurl )
|
||||||
{
|
{
|
||||||
if($this->_framedepth < $this->maxframes)
|
if($this->_framedepth < $this->maxframes)
|
||||||
{
|
{
|
||||||
@ -243,7 +243,7 @@ class Snoopy
|
|||||||
$frameurls = $this->_frameurls;
|
$frameurls = $this->_frameurls;
|
||||||
$this->_frameurls = array();
|
$this->_frameurls = array();
|
||||||
|
|
||||||
while(list(,$frameurl) = each($frameurls))
|
foreach ( $frameurls as $frameurl )
|
||||||
{
|
{
|
||||||
if($this->_framedepth < $this->maxframes)
|
if($this->_framedepth < $this->maxframes)
|
||||||
{
|
{
|
||||||
@ -341,7 +341,7 @@ class Snoopy
|
|||||||
$frameurls = $this->_frameurls;
|
$frameurls = $this->_frameurls;
|
||||||
$this->_frameurls = array();
|
$this->_frameurls = array();
|
||||||
|
|
||||||
while(list(,$frameurl) = each($frameurls))
|
foreach ( $frameurls as $frameurl )
|
||||||
{
|
{
|
||||||
if($this->_framedepth < $this->maxframes)
|
if($this->_framedepth < $this->maxframes)
|
||||||
{
|
{
|
||||||
@ -408,7 +408,7 @@ class Snoopy
|
|||||||
$frameurls = $this->_frameurls;
|
$frameurls = $this->_frameurls;
|
||||||
$this->_frameurls = array();
|
$this->_frameurls = array();
|
||||||
|
|
||||||
while(list(,$frameurl) = each($frameurls))
|
foreach ( $frameurls as $frameurl )
|
||||||
{
|
{
|
||||||
if($this->_framedepth < $this->maxframes)
|
if($this->_framedepth < $this->maxframes)
|
||||||
{
|
{
|
||||||
@ -629,13 +629,13 @@ class Snoopy
|
|||||||
|
|
||||||
// catenate the non-empty matches from the conditional subpattern
|
// catenate the non-empty matches from the conditional subpattern
|
||||||
|
|
||||||
while(list($key,$val) = each($links[2]))
|
foreach ( $links[2] as $key => $val )
|
||||||
{
|
{
|
||||||
if(!empty($val))
|
if(!empty($val))
|
||||||
$match[] = $val;
|
$match[] = $val;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(list($key,$val) = each($links[3]))
|
foreach ( $links[3] as $key => $val )
|
||||||
{
|
{
|
||||||
if(!empty($val))
|
if(!empty($val))
|
||||||
$match[] = $val;
|
$match[] = $val;
|
||||||
@ -821,7 +821,7 @@ class Snoopy
|
|||||||
{
|
{
|
||||||
if(!is_array($this->rawheaders))
|
if(!is_array($this->rawheaders))
|
||||||
$this->rawheaders = (array)$this->rawheaders;
|
$this->rawheaders = (array)$this->rawheaders;
|
||||||
while(list($headerKey,$headerVal) = each($this->rawheaders))
|
foreach ( $this->rawheaders as $headerKey => $headerVal )
|
||||||
$headers .= $headerKey.": ".$headerVal."\r\n";
|
$headers .= $headerKey.": ".$headerVal."\r\n";
|
||||||
}
|
}
|
||||||
if(!empty($content_type)) {
|
if(!empty($content_type)) {
|
||||||
@ -985,7 +985,7 @@ class Snoopy
|
|||||||
{
|
{
|
||||||
if(!is_array($this->rawheaders))
|
if(!is_array($this->rawheaders))
|
||||||
$this->rawheaders = (array)$this->rawheaders;
|
$this->rawheaders = (array)$this->rawheaders;
|
||||||
while(list($headerKey,$headerVal) = each($this->rawheaders))
|
foreach ( $this->rawheaders as $headerKey => $headerVal )
|
||||||
$headers[] = $headerKey.": ".$headerVal;
|
$headers[] = $headerKey.": ".$headerVal;
|
||||||
}
|
}
|
||||||
if(!empty($content_type)) {
|
if(!empty($content_type)) {
|
||||||
@ -1204,9 +1204,9 @@ class Snoopy
|
|||||||
switch ($this->_submit_type) {
|
switch ($this->_submit_type) {
|
||||||
case "application/x-www-form-urlencoded":
|
case "application/x-www-form-urlencoded":
|
||||||
reset($formvars);
|
reset($formvars);
|
||||||
while(list($key,$val) = each($formvars)) {
|
foreach ( $formvars as $key => $val ) {
|
||||||
if (is_array($val) || is_object($val)) {
|
if (is_array($val) || is_object($val)) {
|
||||||
while (list($cur_key, $cur_val) = each($val)) {
|
foreach ( $val as $cur_key => $cur_val ) {
|
||||||
$postdata .= urlencode($key)."[]=".urlencode($cur_val)."&";
|
$postdata .= urlencode($key)."[]=".urlencode($cur_val)."&";
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
@ -1218,9 +1218,9 @@ class Snoopy
|
|||||||
$this->_mime_boundary = "Snoopy".md5(uniqid(microtime()));
|
$this->_mime_boundary = "Snoopy".md5(uniqid(microtime()));
|
||||||
|
|
||||||
reset($formvars);
|
reset($formvars);
|
||||||
while(list($key,$val) = each($formvars)) {
|
foreach ( $formvars as $key => $val ) {
|
||||||
if (is_array($val) || is_object($val)) {
|
if (is_array($val) || is_object($val)) {
|
||||||
while (list($cur_key, $cur_val) = each($val)) {
|
foreach ( $val as $cur_key => $cur_val ) {
|
||||||
$postdata .= "--".$this->_mime_boundary."\r\n";
|
$postdata .= "--".$this->_mime_boundary."\r\n";
|
||||||
$postdata .= "Content-Disposition: form-data; name=\"$key\[\]\"\r\n\r\n";
|
$postdata .= "Content-Disposition: form-data; name=\"$key\[\]\"\r\n\r\n";
|
||||||
$postdata .= "$cur_val\r\n";
|
$postdata .= "$cur_val\r\n";
|
||||||
@ -1233,9 +1233,9 @@ class Snoopy
|
|||||||
}
|
}
|
||||||
|
|
||||||
reset($formfiles);
|
reset($formfiles);
|
||||||
while (list($field_name, $file_names) = each($formfiles)) {
|
foreach ( $formfiles as $field_name => $file_names ) {
|
||||||
settype($file_names, "array");
|
settype($file_names, "array");
|
||||||
while (list(, $file_name) = each($file_names)) {
|
foreach ( $file_names as $file_name ) {
|
||||||
if (!is_readable($file_name)) continue;
|
if (!is_readable($file_name)) continue;
|
||||||
|
|
||||||
$fp = fopen($file_name, "r");
|
$fp = fopen($file_name, "r");
|
||||||
|
Loading…
Reference in New Issue
Block a user