Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incompatibilities with PHP 8.1 #2668

Merged
merged 5 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 000-debug/debug-mode.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
add_action( 'muplugins_loaded', __NAMESPACE__ . '\init_debug_mode' );

function init_debug_mode() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$enable = filter_var( $_GET['a8c-debug'] ?? '', FILTER_SANITIZE_STRING );
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$enable = $_GET['a8c-debug'] ?? '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could sanitize_text_field() be used here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GaryJones yes, but we use $enable only to compare its value against two predefined constants, that is why I decided not to waste CPU cycles.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

if ( in_array( $enable, [ 'true', 'false' ], true ) ) {
set_debug_mode( 'true' === $enable );
}
Expand Down
7 changes: 5 additions & 2 deletions search/includes/classes/class-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,7 @@ public function get_statsd_prefix( $url, $mode = 'other' ) {

// Assume all host names are in the format es-ha-$dc.vipv2.net
$matches = array();
if ( preg_match( '/^es-ha[-.](.*)\.vipv2\.net$/', $host, $matches ) ) {
if ( preg_match( '/^es-ha[-.](.*)\.vipv2\.net$/', (string) $host, $matches ) ) {
$key_parts[] = $matches[1]; // DC of ES node
$key_parts[] = 'ha' . $port . '_vipgo'; // HA endpoint e.g. ha9235_vipgo
} else {
Expand Down Expand Up @@ -1883,8 +1883,11 @@ public function get_index_routing_allocation_include_dc() {
return $dc;
}

/**
* @return string|null
*/
public function get_origin_dc_from_es_endpoint( $url ) {
$dc = null;
$dc = '';

if ( ! $url ) {
return null;
Expand Down
6 changes: 5 additions & 1 deletion vip-helpers/class-user-cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
}

class User_Cleanup {
/**
* @param string|null|false $emails_string
* @return array
*/
public static function parse_emails_string( $emails_string ) {
$emails = [];

$emails_string = trim( $emails_string );
$emails_string = trim( (string) $emails_string );

if ( false !== strpos( $emails_string, ',' ) ) {
$emails_raw = explode( ',', $emails_string );
Expand Down
6 changes: 3 additions & 3 deletions vip-helpers/vip-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,19 +347,19 @@ class_exists( 'Jetpack_User_Agent_Info' ) && ! Jetpack_User_Agent_Info::is_table
// Leave these wrapped in function_exists() b/c they are so generically named
if ( ! function_exists( 'wp_startswith' ) ) :
function wp_startswith( $haystack, $needle ) {
return 0 === strpos( $haystack, $needle );
return 0 === strpos( (string) $haystack, (string) $needle );
}
endif;

if ( ! function_exists( 'wp_endswith' ) ) :
function wp_endswith( $haystack, $needle ) {
return substr( $haystack, -strlen( $needle ) ) === $needle;
return substr( (string) $haystack, -strlen( (string) $needle ) ) === $needle;
}
endif;

if ( ! function_exists( 'wp_in' ) ) :
function wp_in( $needle, $haystack ) {
return false !== strpos( $haystack, $needle );
return false !== strpos( (string) $haystack, (string) $needle );
}
endif;

Expand Down