/** * @param string $path * * @return string */ public function parse_request($path) { global $wp_filter; $tmp_wp_filter = $wp_filter; $GLOBALS['wp_filter'] = array(); $result = $path; $this->wp->parse_request(); if ($this->wp->matched_rule) { $result = $this->wp->matched_rule; $this->wp->matched_rule = null; } $GLOBALS['wp_filter'] = $tmp_wp_filter; return $result; }
/** * Called when the main execute function gets a 404 to check against old * permalink structures and perform redirect if an old post can be * matched. */ function redirect_old_permalink($req_uri) { global $wp_query, $wp_rewrite; global $wp_version; $rules = get_option('permalink_redirect_rules'); if (!$rules) { return; } // Backing up the rewrite object for you, imperative programmers! $wp_rewrite_old = $wp_rewrite; // Unsetting the globals. Argh! Evil global variables! foreach ($wp_query->query_vars as $key => $val) { unset($GLOBALS[$key]); } // Going through the rules. foreach ($rules as $rules2) { $wp2 = new WP(); $wp_rewrite = new YLSY_Rewrite(); $wp_rewrite->index = $wp_rewrite_old->index; $wp_rewrite->rules = $rules2; $wp2->parse_request(); if (isset($wp2->query_vars['error']) && $wp2->query_vars['error'] == 404) { continue; } $query = new WP_Query(); if ($wp_version >= '2.1') { $posts = $query->query($wp2->query_vars); } else { $wp2->build_query_string(); $posts = $query->query($wp2->query_string); } if (count($posts) > 0) { $wp_rewrite = $wp_rewrite_old; $this->execute2($query, false); return; } } // Restoring global variables. We don't bother to reset the other // variables as we are going to do a 404 anyway. $wp_rewrite = $wp_rewrite_old; }
/** * Determines the referer taxonomy * * @return string|bool Either the name of the taxonomy to use or false if a referer taxonomy wasn't found */ protected function determine_taxonomy() { global $wp; //Backup the server request variable $bk_req = $_SERVER['REQUEST_URI']; //Now set the request URL to the referrer URL //Could just chain the [1] selection, but that's not PHP5.3 compatible $url_split = explode(home_url(), esc_url(wp_get_referer())); if (isset($url_split[1])) { $_SERVER['REQUEST_URI'] = $url_split[1]; } else { return false; } //Create our own new instance of WP, and have it parse our faux request $bcn_wp = new WP(); //Copy over the current global wp object's query_vars since CPTs and taxonomies are added directly to the global $wp $bcn_wp->public_query_vars = $wp->public_query_vars; $bcn_wp->parse_request(); $_SERVER['REQUEST_URI'] = $bk_req; if (is_array($bcn_wp->query_vars)) { foreach ($bcn_wp->query_vars as $query_var => $value) { if ($taxonomy = $this->query_var_to_taxonomy($query_var)) { return $taxonomy; } } } return false; }
public static function ids_from_url($url) { global $wp; $wp = new WP(); //We need to cheat telling WP we are not in admin area to parse the URL properly $current_uri = $_SERVER['REQUEST_URI']; $self = $_SERVER['PHP_SELF']; $get = $_GET; global $current_screen; if ($current_screen) { $stored_current_screen = $current_screen->id; } else { require_once ABSPATH . '/wp-admin/includes/screen.php'; $current_screen = WP_Screen::get('front'); } $_SERVER['REQUEST_URI'] = $url; $_SERVER['PHP_SELF'] = 'foo'; $urlParts = explode('?', $url); if (count($urlParts) > 1) { parse_str($urlParts[1], $_GET); } $wp->parse_request(); $query = new WP_Query($wp->query_vars); $query->parse_query(); //Set the global post in case that no-one is set and we have a single query global $post; if (!$post && $query->have_posts() && $query->is_singular()) { $post = $query->next_post(); setup_postdata($post); } //Make the query accessible to add it to the response global $upfront_ajax_query; $upfront_ajax_query = clone $query; // Intercept /edit/(post|page)/id $editor = Upfront_ContentEditor_VirtualPage::serve(); if ($editor->parse_page()) { global $wp_query; $query = $wp_query; $post = $wp_query->next_post(); setup_postdata($post); } $_SERVER['REQUEST_URI'] = $current_uri; $_SERVER['PHP_SELF'] = $self; $_GET = $get; if (isset($stored_current_screen)) { //$current_screen = $current_screen::get($stored_current_screen); $current_screen = call_user_func(array($current_screen, 'get', $stored_current_screen)); } $cascade = self::get_entity_ids(self::get_entity_cascade($query)); return $cascade; }