wp_rewrite_rules(); // not using rewrite rules, and 'author=N' method failed, so we're out of options if ( empty( $rewrite ) ) { return 0; } // generate rewrite rule for the author url $author_rewrite = $wp_rewrite->get_author_permastruct(); $author_regexp = \str_replace( '%author%', '', $author_rewrite ); // match the rewrite rule with the passed url if ( \preg_match( '/https?:\/\/(.+)' . \preg_quote( $author_regexp, '/' ) . '([^\/]+)/i', $url, $match ) ) { $user = \get_user_by( 'slug', $match[2] ); if ( $user ) { return $user->ID; } } return 0; } }