Skip to content

Commit 5f59d27

Browse files
committed
Fix additional PHP 8.4 deprecation warnings
Address deprecation warnings for null parameters passed to WordPress core functions: - Cast null values to string for wp_parse_url() calls - Cast null values to string for preg_match() calls - Cast null values to string for explode() calls - Cast null values to string for ltrim() calls
1 parent 49895ab commit 5f59d27

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

includes/class-webfinger.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public static function get_remote_follow_endpoint( $uri ) {
290290
* @return string The cache key.
291291
*/
292292
public static function generate_cache_key( $uri ) {
293-
$uri = ltrim( $uri, '@' );
293+
$uri = ltrim( (string) $uri, '@' );
294294

295295
if ( filter_var( $uri, FILTER_VALIDATE_EMAIL ) ) {
296296
$uri = 'acct:' . $uri;
@@ -311,16 +311,16 @@ public static function guess( $actor_or_uri ) {
311311
if ( ! $actor_or_uri instanceof Actor ) {
312312
$actor = Actors::fetch_remote_by_uri( $actor_or_uri );
313313
if ( \is_wp_error( $actor ) ) {
314-
return extract_name_from_uri( $actor_or_uri ) . '@' . \wp_parse_url( $actor_or_uri, PHP_URL_HOST );
314+
return extract_name_from_uri( $actor_or_uri ) . '@' . \wp_parse_url( (string) $actor_or_uri, PHP_URL_HOST );
315315
}
316316

317317
$actor_or_uri = $actor;
318318
}
319319

320320
if ( $actor_or_uri->get_preferred_username() ) {
321-
return $actor_or_uri->get_preferred_username() . '@' . \wp_parse_url( $actor_or_uri->get_id(), PHP_URL_HOST );
321+
return $actor_or_uri->get_preferred_username() . '@' . \wp_parse_url( (string) $actor_or_uri->get_id(), PHP_URL_HOST );
322322
}
323323

324-
return extract_name_from_uri( $actor_or_uri->get_id() ) . '@' . \wp_parse_url( $actor_or_uri->get_id(), PHP_URL_HOST );
324+
return extract_name_from_uri( $actor_or_uri->get_id() ) . '@' . \wp_parse_url( (string) $actor_or_uri->get_id(), PHP_URL_HOST );
325325
}
326326
}

includes/functions.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,13 @@ function url_to_authorid( $url ) {
138138
global $wp_rewrite;
139139

140140
// Check if url hase the same host.
141-
$request_host = \wp_parse_url( $url, \PHP_URL_HOST );
141+
$request_host = \wp_parse_url( (string) $url, \PHP_URL_HOST );
142142
if ( \wp_parse_url( \home_url(), \PHP_URL_HOST ) !== $request_host && get_option( 'activitypub_old_host' ) !== $request_host ) {
143143
return null;
144144
}
145145

146146
// First, check to see if there is an 'author=N' to match against.
147-
if ( \preg_match( '/[?&]author=(\d+)/i', $url, $values ) ) {
147+
if ( \preg_match( '/[?&]author=(\d+)/i', (string) $url, $values ) ) {
148148
return \absint( $values[1] );
149149
}
150150

@@ -224,7 +224,7 @@ function is_tombstone( $wp_error ) {
224224
*/
225225
function get_rest_url_by_path( $path = '' ) {
226226
// We'll handle the leading slash.
227-
$path = ltrim( $path, '/' );
227+
$path = ltrim( (string) $path, '/' );
228228
$namespaced_path = sprintf( '/%s/%s', ACTIVITYPUB_REST_NAMESPACE, $path );
229229
return \get_rest_url( null, $namespaced_path );
230230
}
@@ -1720,7 +1720,7 @@ function extract_name_from_uri( $uri ) {
17201720
$name = \preg_replace( '|^/@?|', '', $path );
17211721
} else {
17221722
// Expected: https://example.com/users/user (default ID pattern).
1723-
$parts = \explode( '/', $path );
1723+
$parts = \explode( '/', (string) $path );
17241724
$name = \array_pop( $parts );
17251725
}
17261726
} else {
@@ -1733,11 +1733,11 @@ function extract_name_from_uri( $uri ) {
17331733
\strpos( $name, '@' ) === 0
17341734
) {
17351735
// Expected: [email protected] or acct:user@example (WebFinger).
1736-
$name = \ltrim( $name, '@' );
1736+
$name = \ltrim( (string) $name, '@' );
17371737
if ( str_starts_with( $name, 'acct:' ) ) {
17381738
$name = \substr( $name, 5 );
17391739
}
1740-
$parts = \explode( '@', $name );
1740+
$parts = \explode( '@', (string) $name );
17411741
$name = $parts[0];
17421742
}
17431743

includes/transformer/class-post.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ public function generate_reply_link( $block_content, $block ) {
586586
$webfinger = \str_replace( 'acct:', '', $author['webfinger'] );
587587
} elseif ( ! empty( $author['preferredUsername'] ) && ! empty( $author['url'] ) ) {
588588
// Construct webfinger-style identifier from username and domain.
589-
$domain = \wp_parse_url( $author['url'], PHP_URL_HOST );
589+
$domain = \wp_parse_url( (string) $author['url'], PHP_URL_HOST );
590590
$webfinger = '@' . $author['preferredUsername'] . '@' . $domain;
591591
}
592592

0 commit comments

Comments
 (0)