if (false === $redirect_post_id) { $redirect_post_id = self::get_redirect_post_id($url); wp_cache_add($url_hash, $redirect_post_id, self::CACHE_GROUP); } if ($redirect_post_id) { $redirect_post = get_post($redirect_post_id); if (0 !== $redirect_post->post_parent) { return get_permalink($redirect_post->post_parent); } elseif (!empty($redirect_post->post_excerpt)) { return esc_url_raw($redirect_post->post_excerpt); } } return false; } static function get_redirect_post_id($url) { global $wpdb; $url_hash = self::get_url_hash($url); $redirect_post_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND post_name = %s LIMIT 1", self::POST_TYPE, $url_hash)); if (!$redirect_post_id) { $redirect_post_id = 0; } return $redirect_post_id; } private static function get_url_hash($url) { return md5($url); } } WPCOM_Legacy_Redirector::start();