\'\"\r\n\t\(\)]/', '', preg_replace( '/(\?.*)?(#.*)?$/', '', $path ) ) ); return $path; } /** * Normalize the request uri so it can be used for caching purposes. * It removes the query string and the trailing slash, and characters * that might cause problems with the filesystem. * * **THIS DOES NOT SANITIZE THE VARIABLE IN ANY WAY.** * Only use it for comparison purposes or to generate an MD5 hash. * * @param string $request_uri - The request uri to normalize. * @return string - The normalized request uri. */ public static function normalize_request_uri( $request_uri ) { // get path from request uri $request_uri = parse_url( $request_uri, PHP_URL_PATH ); // phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url if ( empty( $request_uri ) ) { $request_uri = '/'; } elseif ( substr( $request_uri, -1 ) !== '/' && ! is_file( ABSPATH . $request_uri ) ) { $request_uri .= '/'; } return $request_uri; } /** * Checks if the post type is public. * * @param WP_Post $post - The post to check. * @return bool - True if the post type is public. */ public static function is_visible_post_type( $post ) { $post_type = is_a( $post, 'WP_Post' ) ? get_post_type_object( $post->post_type ) : null; if ( empty( $post_type ) || ! $post_type->public ) { return false; } return true; } }