wp/wp-includes/rewrite.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
--- a/wp/wp-includes/rewrite.php	Thu Sep 29 08:06:27 2022 +0200
+++ b/wp/wp-includes/rewrite.php	Fri Sep 05 18:40:08 2025 +0200
@@ -210,7 +210,8 @@
 	if ( ! is_array( $args ) ) {
 		$args = array( 'with_front' => $args );
 	}
-	if ( func_num_args() == 4 ) {
+
+	if ( func_num_args() === 4 ) {
 		$args['ep_mask'] = func_get_arg( 3 );
 	}
 
@@ -244,10 +245,10 @@
  * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
  *
  * @param string   $feedname Feed name.
- * @param callable $function Callback to run on feed display.
+ * @param callable $callback Callback to run on feed display.
  * @return string Feed action name.
  */
-function add_feed( $feedname, $function ) {
+function add_feed( $feedname, $callback ) {
 	global $wp_rewrite;
 
 	if ( ! in_array( $feedname, $wp_rewrite->feeds, true ) ) {
@@ -259,7 +260,7 @@
 	// Remove default function hook.
 	remove_action( $hook, $hook );
 
-	add_action( $hook, $function, 10, 2 );
+	add_action( $hook, $callback, 10, 2 );
 
 	return $hook;
 }
@@ -410,7 +411,10 @@
 	}
 
 	// This is the potentially clashing slug.
-	$value = $query_vars[ $compare ];
+	$value = '';
+	if ( $compare && array_key_exists( $compare, $query_vars ) ) {
+		$value = $query_vars[ $compare ];
+	}
 
 	$post = get_page_by_path( $value, OBJECT, 'post' );
 	if ( ! ( $post instanceof WP_Post ) ) {
@@ -497,8 +501,21 @@
 	 */
 	$url = apply_filters( 'url_to_postid', $url );
 
-	$url_host      = str_replace( 'www.', '', parse_url( $url, PHP_URL_HOST ) );
-	$home_url_host = str_replace( 'www.', '', parse_url( home_url(), PHP_URL_HOST ) );
+	$url_host = parse_url( $url, PHP_URL_HOST );
+
+	if ( is_string( $url_host ) ) {
+		$url_host = str_replace( 'www.', '', $url_host );
+	} else {
+		$url_host = '';
+	}
+
+	$home_url_host = parse_url( home_url(), PHP_URL_HOST );
+
+	if ( is_string( $home_url_host ) ) {
+		$home_url_host = str_replace( 'www.', '', $home_url_host );
+	} else {
+		$home_url_host = '';
+	}
 
 	// Bail early if the URL does not belong to this site.
 	if ( $url_host && $url_host !== $home_url_host ) {
@@ -526,12 +543,12 @@
 	$url    = set_url_scheme( $url, $scheme );
 
 	// Add 'www.' if it is absent and should be there.
-	if ( false !== strpos( home_url(), '://www.' ) && false === strpos( $url, '://www.' ) ) {
+	if ( str_contains( home_url(), '://www.' ) && ! str_contains( $url, '://www.' ) ) {
 		$url = str_replace( '://', '://www.', $url );
 	}
 
 	// Strip 'www.' if it is present and shouldn't be.
-	if ( false === strpos( home_url(), '://www.' ) ) {
+	if ( ! str_contains( home_url(), '://www.' ) ) {
 		$url = str_replace( '://www.', '://', $url );
 	}
 
@@ -556,7 +573,7 @@
 		$url = str_replace( $wp_rewrite->index . '/', '', $url );
 	}
 
-	if ( false !== strpos( trailingslashit( $url ), home_url( '/' ) ) ) {
+	if ( str_contains( trailingslashit( $url ), home_url( '/' ) ) ) {
 		// Chop off http://domain.com/[path].
 		$url = str_replace( home_url(), '', $url );
 	} else {
@@ -582,9 +599,11 @@
 	$request_match = $request;
 	foreach ( (array) $rewrite as $match => $query ) {
 
-		// If the requesting file is the anchor of the match,
-		// prepend it to the path info.
-		if ( ! empty( $url ) && ( $url != $request ) && ( strpos( $match, $url ) === 0 ) ) {
+		/*
+		 * If the requesting file is the anchor of the match,
+		 * prepend it to the path info.
+		 */
+		if ( ! empty( $url ) && ( $url !== $request ) && str_starts_with( $match, $url ) ) {
 			$request_match = $url . '/' . $request;
 		}
 
@@ -604,8 +623,10 @@
 				}
 			}
 
-			// Got a match.
-			// Trim the query of everything up to the '?'.
+			/*
+			 * Got a match.
+			 * Trim the query of everything up to the '?'.
+			 */
 			$query = preg_replace( '!^.+\?!', '', $query );
 
 			// Substitute the substring matches into the query.