• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP WP_MatchesMapRegex类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中WP_MatchesMapRegex的典型用法代码示例。如果您正苦于以下问题:PHP WP_MatchesMapRegex类的具体用法?PHP WP_MatchesMapRegex怎么用?PHP WP_MatchesMapRegex使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了WP_MatchesMapRegex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: parse_request


//.........这里部分代码省略.........
         $this->request = $request;
         // Look for matches.
         $request_match = $request;
         if (empty($request_match)) {
             // An empty request could only match against ^$ regex
             if (isset($rewrite['$'])) {
                 $this->matched_rule = '$';
                 $query = $rewrite['$'];
                 $matches = array('');
             }
         } else {
             foreach ((array) $rewrite as $match => $query) {
                 // If the requesting file is the anchor of the match, prepend it to the path info.
                 if (!empty($req_uri) && strpos($match, $req_uri) === 0 && $req_uri != $request) {
                     $request_match = $req_uri . '/' . $request;
                 }
                 if (preg_match("#^{$match}#", $request_match, $matches) || preg_match("#^{$match}#", urldecode($request_match), $matches)) {
                     if ($wp_rewrite->use_verbose_page_rules && preg_match('/pagename=\\$matches\\[([0-9]+)\\]/', $query, $varmatch)) {
                         // this is a verbose page match, lets check to be sure about it
                         if (!get_page_by_path($matches[$varmatch[1]])) {
                             continue;
                         }
                     }
                     // Got a match.
                     $this->matched_rule = $match;
                     break;
                 }
             }
         }
         if (isset($this->matched_rule)) {
             // Trim the query of everything up to the '?'.
             $query = preg_replace("!^.+\\?!", '', $query);
             // Substitute the substring matches into the query.
             $query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
             $this->matched_query = $query;
             // Parse the query.
             parse_str($query, $perma_query_vars);
             // If we're processing a 404 request, clear the error var since we found something.
             if ('404' == $error) {
                 unset($error, $_GET['error']);
             }
         }
         // If req_uri is empty or if it is a request for ourself, unset error.
         if (empty($request) || $req_uri == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false) {
             unset($error, $_GET['error']);
             if (isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false) {
                 unset($perma_query_vars);
             }
             $this->did_permalink = false;
         }
     }
     /**
      * Filter the query variables whitelist before processing.
      *
      * Allows (publicly allowed) query vars to be added, removed, or changed prior
      * to executing the query. Needed to allow custom rewrite rules using your own arguments
      * to work, or any other custom query variables you want to be publicly available.
      *
      * @since 1.5.2
      *
      * @param array $public_query_vars The array of whitelisted query variables.
      */
     $this->public_query_vars = apply_filters('query_vars', $this->public_query_vars);
     foreach (get_post_types(array(), 'objects') as $post_type => $t) {
         if ($t->query_var) {
             $post_type_query_vars[$t->query_var] = $post_type;
开发者ID:jacques,项目名称:wordpress,代码行数:67,代码来源:class-wp.php


示例2: url_to_postid

/**
 * Examine a url and try to determine the post ID it represents.
 *
 * Checks are supposedly from the hosted site blog.
 *
 * @since 1.0.0
 *
 * @param string $url Permalink to check.
 * @return int Post ID, or 0 on failure.
 */
function url_to_postid($url)
{
    global $wp_rewrite;
    $url = apply_filters('url_to_postid', $url);
    // First, check to see if there is a 'p=N' or 'page_id=N' to match against
    if (preg_match('#[?&](p|page_id|attachment_id)=(\\d+)#', $url, $values)) {
        $id = absint($values[2]);
        if ($id) {
            return $id;
        }
    }
    // Check to see if we are using rewrite rules
    $rewrite = $wp_rewrite->wp_rewrite_rules();
    // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options
    if (empty($rewrite)) {
        return 0;
    }
    // Get rid of the #anchor
    $url_split = explode('#', $url);
    $url = $url_split[0];
    // Get rid of URL ?query=string
    $url_split = explode('?', $url);
    $url = $url_split[0];
    // Add 'www.' if it is absent and should be there
    if (false !== strpos(home_url(), '://www.') && false === strpos($url, '://www.')) {
        $url = str_replace('://', '://www.', $url);
    }
    // Strip 'www.' if it is present and shouldn't be
    if (false === strpos(home_url(), '://www.')) {
        $url = str_replace('://www.', '://', $url);
    }
    // Strip 'index.php/' if we're not using path info permalinks
    if (!$wp_rewrite->using_index_permalinks()) {
        $url = str_replace('index.php/', '', $url);
    }
    if (false !== strpos($url, home_url())) {
        // Chop off http://domain.com
        $url = str_replace(home_url(), '', $url);
    } else {
        // Chop off /path/to/blog
        $home_path = parse_url(home_url());
        $home_path = isset($home_path['path']) ? $home_path['path'] : '';
        $url = str_replace($home_path, '', $url);
    }
    // Trim leading and lagging slashes
    $url = trim($url, '/');
    $request = $url;
    // Look for matches.
    $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) {
            $request_match = $url . '/' . $request;
        }
        if (preg_match("!^{$match}!", $request_match, $matches)) {
            if ($wp_rewrite->use_verbose_page_rules && preg_match('/pagename=\\$matches\\[([0-9]+)\\]/', $query, $varmatch)) {
                // this is a verbose page match, lets check to be sure about it
                if (!get_page_by_path($matches[$varmatch[1]])) {
                    continue;
                }
            }
            // Got a match.
            // Trim the query of everything up to the '?'.
            $query = preg_replace("!^.+\\?!", '', $query);
            // Substitute the substring matches into the query.
            $query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
            // Filter out non-public query vars
            global $wp;
            parse_str($query, $query_vars);
            $query = array();
            foreach ((array) $query_vars as $key => $value) {
                if (in_array($key, $wp->public_query_vars)) {
                    $query[$key] = $value;
                }
            }
            // Do the query
            $query = new WP_Query($query);
            if (!empty($query->posts) && $query->is_singular) {
                return $query->post->ID;
            } else {
                return 0;
            }
        }
    }
    return 0;
}
开发者ID:snagga,项目名称:urbantac,代码行数:97,代码来源:rewrite.php


示例3: parse_request


//.........这里部分代码省略.........
         $this->request = $request;
         // Look for matches.
         $request_match = $request;
         if (empty($request_match)) {
             // An empty request could only match against ^$ regex
             if (isset($rewrite['$'])) {
                 $this->matched_rule = '$';
                 $query = $rewrite['$'];
                 $matches = array('');
             }
         } else {
             foreach ((array) $rewrite as $match => $query) {
                 // If the requesting file is the anchor of the match, prepend it to the path info.
                 if (!empty($req_uri) && strpos($match, $req_uri) === 0 && $req_uri != $request) {
                     $request_match = $req_uri . '/' . $request;
                 }
                 if (preg_match("#^{$match}#", $request_match, $matches) || preg_match("#^{$match}#", urldecode($request_match), $matches)) {
                     if ($wp_rewrite->use_verbose_page_rules && preg_match('/pagename=\\$matches\\[([0-9]+)\\]/', $query, $varmatch)) {
                         // this is a verbose page match, lets check to be sure about it
                         if (!get_page_by_path($matches[$varmatch[1]])) {
                             continue;
                         }
                     }
                     // Got a match.
                     $this->matched_rule = $match;
                     break;
                 }
             }
         }
         if (isset($this->matched_rule)) {
             // Trim the query of everything up to the '?'.
             $query = preg_replace("!^.+\\?!", '', $query);
             // Substitute the substring matches into the query.
             $query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
             $this->matched_query = $query;
             // Parse the query.
             parse_str($query, $perma_query_vars);
             // If we're processing a 404 request, clear the error var since we found something.
             if ('404' == $error) {
                 unset($error, $_GET['error']);
             }
         }
         // If req_uri is empty or if it is a request for ourself, unset error.
         if (empty($request) || $req_uri == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false) {
             unset($error, $_GET['error']);
             if (isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false) {
                 unset($perma_query_vars);
             }
             $this->did_permalink = false;
         }
     }
     $this->public_query_vars = apply_filters('query_vars', $this->public_query_vars);
     foreach ($GLOBALS['wp_post_types'] as $post_type => $t) {
         if ($t->query_var) {
             $post_type_query_vars[$t->query_var] = $post_type;
         }
     }
     foreach ($this->public_query_vars as $wpvar) {
         if (isset($this->extra_query_vars[$wpvar])) {
             $this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar];
         } elseif (isset($_POST[$wpvar])) {
             $this->query_vars[$wpvar] = $_POST[$wpvar];
         } elseif (isset($_GET[$wpvar])) {
             $this->query_vars[$wpvar] = $_GET[$wpvar];
         } elseif (isset($perma_query_vars[$wpvar])) {
             $this->query_vars[$wpvar] = $perma_query_vars[$wpvar];
开发者ID:ryanmerritt,项目名称:WordPress,代码行数:67,代码来源:class-wp.php


示例4: _process_generic_text


//.........这里部分代码省略.........
             } else {
                 $home_path = '';
             }
             $home_path = trim($home_path, '/');
             $req_uri = str_replace($pathinfo, '', rawurldecode($req_uri));
             $req_uri = trim($req_uri, '/');
             $req_uri = preg_replace("|^{$home_path}|", '', $req_uri);
             $req_uri = trim($req_uri, '/');
             $pathinfo = trim($pathinfo, '/');
             $pathinfo = preg_replace("|^{$home_path}|", '', $pathinfo);
             $pathinfo = trim($pathinfo, '/');
             if (!empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo)) {
                 $request = $pathinfo;
             } else {
                 // If the request uri is the index, blank it out so that we don't try to match it against a rule.
                 if ($req_uri == $wp_rewrite->index) {
                     $req_uri = '';
                 }
                 $request = $req_uri;
             }
             $request_match = $request;
             $permalink_query_vars = array();
             foreach ((array) $rewrite as $match => $query) {
                 // If the requesting file is the anchor of the match, prepend it
                 // to the path info.
                 if (!empty($req_uri) && strpos($match, $req_uri) === 0 && $req_uri != $request) {
                     $request_match = $req_uri . '/' . $request;
                 }
                 if (preg_match("!^{$match}!", $request_match, $matches) || preg_match("!^{$match}!", urldecode($request_match), $matches)) {
                     // Got a match.
                     // Trim the query of everything up to the '?'.
                     $query = preg_replace("!^.+\\?!", '', $query);
                     // Substitute the substring matches into the query.
                     $query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
                     // Parse the query.
                     parse_str($query, $permalink_query_vars);
                     break;
                 }
             }
             $post_name = $category_name = $tax_name = false;
             if (isset($permalink_query_vars['pagename'])) {
                 $icl_post_lang = isset($_POST['icl_post_language']) ? $_POST['icl_post_language'] : $current_language;
                 $sitepress->switch_lang($icl_post_lang);
                 $page_by_path = get_page_by_path($permalink_query_vars['pagename']);
                 $sitepress->switch_lang($current_language);
                 if (!empty($page_by_path->post_type)) {
                     $post_name = $permalink_query_vars['pagename'];
                     $post_type = 'page';
                 } else {
                     $post_name = $permalink_query_vars['pagename'];
                     $post_type = 'post';
                 }
             } elseif (isset($permalink_query_vars['name'])) {
                 $post_name = $permalink_query_vars['name'];
                 $post_type = 'post';
             } elseif (isset($permalink_query_vars['category_name'])) {
                 $category_name = $permalink_query_vars['category_name'];
             } elseif (isset($permalink_query_vars['p'])) {
                 // case or /archives/%post_id
                 $post_data_prepared = $wpdb->prepare("SELECT post_type, post_name FROM {$wpdb->posts} WHERE id=%d", $permalink_query_vars['p']);
                 list($post_type, $post_name) = $wpdb->get_row($post_data_prepared, ARRAY_N);
             } else {
                 if (empty($this->custom_post_query_vars) or empty($this->taxonomies_query_vars)) {
                     $this->init_query_vars();
                 }
                 foreach ($this->custom_post_query_vars as $query_vars_key => $query_vars_value) {
开发者ID:sedici,项目名称:wpmu-istec,代码行数:67,代码来源:absolute-links.class.php


示例5: wpl_url_to_postid

 function wpl_url_to_postid($url)
 {
     global $wp_rewrite;
     $url = apply_filters('url_to_postid', $url);
     $id = url_to_postid($url);
     if (isset($id) && $id > 0) {
         return $id;
     }
     // First, check to see if there is a 'p=N' or 'page_id=N' to match against
     if (preg_match('#[?&](p|page_id|attachment_id)=(\\d+)#', $url, $values)) {
         $id = absint($values[2]);
         if ($id) {
             return $id;
         }
     }
     //first check if URL is homepage
     $wordpress_url = get_bloginfo('url');
     if (substr($wordpress_url, -1, -1) != '/') {
         $wordpress_url = $wordpress_url . "/";
     }
     if (str_replace('/', '', $url) == str_replace('/', '', $wordpress_url)) {
         return get_option('page_on_front');
     }
     // Check to see if we are using rewrite rules
     $rewrite = $wp_rewrite->wp_rewrite_rules();
     // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options
     if (empty($rewrite)) {
         return 0;
     }
     // Get rid of the #anchor
     $url_split = explode('#', $url);
     $url = $url_split[0];
     // Get rid of URL ?query=string
     $url_split = explode('?', $url);
     $url = $url_split[0];
     // Add 'www.' if it is absent and should be there
     if (false !== strpos(home_url(), '://www.') && false === strpos($url, '://www.')) {
         $url = str_replace('://', '://www.', $url);
     }
     // Strip 'www.' if it is present and shouldn't be
     if (false === strpos(home_url(), '://www.')) {
         $url = str_replace('://www.', '://', $url);
     }
     // Strip 'index.php/' if we're not using path info permalinks
     if (!$wp_rewrite->using_index_permalinks()) {
         $url = str_replace('index.php/', '', $url);
     }
     if (false !== strpos($url, home_url())) {
         // Chop off http://domain.com
         $url = str_replace(home_url(), '', $url);
     } else {
         // Chop off /path/to/blog
         $home_path = parse_url(home_url());
         $home_path = isset($home_path['path']) ? $home_path['path'] : '';
         $url = str_replace($home_path, '', $url);
     }
     // Trim leading and lagging slashes
     $url = trim($url, '/');
     $request = $url;
     // Look for matches.
     $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) {
             $request_match = $url . '/' . $request;
         }
         if (preg_match("!^{$match}!", $request_match, $matches)) {
             // Got a match.
             // Trim the query of everything up to the '?'.
             $query = preg_replace("!^.+\\?!", '', $query);
             // Substitute the substring matches into the query.
             $query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
             // Filter out non-public query vars
             global $wp;
             parse_str($query, $query_vars);
             $query = array();
             foreach ((array) $query_vars as $key => $value) {
                 if (in_array($key, $wp->public_query_vars)) {
                     $query[$key] = $value;
                 }
             }
             // Taken from class-wp.php
             foreach ($GLOBALS['wp_post_types'] as $post_type => $t) {
                 if ($t->query_var) {
                     $post_type_query_vars[$t->query_var] = $post_type;
                 }
             }
             foreach ($wp->public_query_vars as $wpvar) {
                 if (isset($wp->extra_query_vars[$wpvar])) {
                     $query[$wpvar] = $wp->extra_query_vars[$wpvar];
                 } elseif (isset($_POST[$wpvar])) {
                     $query[$wpvar] = $_POST[$wpvar];
                 } elseif (isset($_GET[$wpvar])) {
                     $query[$wpvar] = $_GET[$wpvar];
                 } elseif (isset($query_vars[$wpvar])) {
                     $query[$wpvar] = $query_vars[$wpvar];
                 }
                 if (!empty($query[$wpvar])) {
                     if (!is_array($query[$wpvar])) {
//.........这里部分代码省略.........
开发者ID:devilcranx,项目名称:landing-pages,代码行数:101,代码来源:global.shared.functions.php


示例6: query_vars


//.........这里部分代码省略.........
         } else {
             $pathinfo = '';
         }
         $pathinfo_array = explode('?', $pathinfo);
         $pathinfo = str_replace("%", "%25", $pathinfo_array[0]);
         $req_uri = $_SERVER['REQUEST_URI'];
         $req_uri_array = explode('?', $req_uri);
         $req_uri = $req_uri_array[0];
         $self = $_SERVER['PHP_SELF'];
         $home_path = parse_url(home_url());
         if (isset($home_path['path'])) {
             $home_path = $home_path['path'];
         } else {
             $home_path = '';
         }
         $home_path = trim($home_path, '/');
         // Trim path info from the end and the leading home path from the
         // front. For path info requests, this leaves us with the requesting
         // filename, if any. For 404 requests, this leaves us with the
         // requested permalink.
         $req_uri = str_replace($pathinfo, '', $req_uri);
         $req_uri = trim($req_uri, '/');
         $req_uri = preg_replace("|^{$home_path}|", '', $req_uri);
         $req_uri = trim($req_uri, '/');
         $pathinfo = trim($pathinfo, '/');
         $pathinfo = preg_replace("|^{$home_path}|", '', $pathinfo);
         $pathinfo = trim($pathinfo, '/');
         $self = trim($self, '/');
         $self = preg_replace("|^{$home_path}|", '', $self);
         $self = trim($self, '/');
         // The requested permalink is in $pathinfo for path info requests and
         //  $req_uri for other requests.
         if (!empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo)) {
             $request = $pathinfo;
         } else {
             // If the request uri is the index, blank it out so that we don't try to match it against a rule.
             if ($req_uri == $wp_rewrite->index) {
                 $req_uri = '';
             }
             $request = $req_uri;
         }
         $wp->request = $request;
         // Look for matches.
         $request_match = $request;
         if (empty($request_match)) {
             // An empty request could only match against ^$ regex
             if (isset($rewrite['$'])) {
                 $wp->matched_rule = '$';
                 $query = $rewrite['$'];
                 $matches = array('');
             }
         } else {
             if ($req_uri != 'wp-app.php') {
                 foreach ((array) $rewrite as $match => $query) {
                     // If the requesting file is the anchor of the match, prepend it to the path info.
                     if (!empty($req_uri) && strpos($match, $req_uri) === 0 && $req_uri != $request) {
                         $request_match = $req_uri . '/' . $request;
                     }
                     if (preg_match("#^{$match}#", $request_match, $matches) || preg_match("#^{$match}#", urldecode($request_match), $matches)) {
                         if ($wp_rewrite->use_verbose_page_rules && preg_match('/pagename=\\$matches\\[([0-9]+)\\]/', $query, $varmatch)) {
                             // this is a verbose page match, lets check to be sure about it
                             if (!($page_foundid = $this->get_page_by_path($matches[$varmatch[1]]))) {
                                 continue;
                             } else {
                                 wp_cache_set('qts_page_request', $page_foundid);
                                 // caching query :)
                             }
                         }
                         // Got a match.
                         $wp->matched_rule = $match;
                         break;
                     }
                 }
             }
         }
         if (isset($wp->matched_rule)) {
             // Trim the query of everything up to the '?'.
             $query = preg_replace("!^.+\\?!", '', $query);
             // Substitute the substring matches into the query.
             $query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
             $wp->matched_query = $query;
             // Parse the query.
             parse_str($query, $perma_query_vars);
             // If we're processing a 404 request, clear the error var
             // since we found something.
             unset($_GET['error']);
             unset($error);
         }
         // If req_uri is empty or if it is a request for ourself, unset error.
         if (empty($request) || $req_uri == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false) {
             unset($_GET['error']);
             unset($error);
             if (isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false) {
                 unset($perma_query_vars);
             }
             $wp->did_permalink = false;
         }
     }
     return $wp->public_query_vars;
 }
开发者ID:Savantos,项目名称:cow-theme,代码行数:101,代码来源:qtranslate-slug.php


示例7: url_to_postid

/**
 * Examine a url and try to determine the post ID it represents.
 *
 * Checks are supposedly from the hosted site blog.
 *
 * @since 1.0.0
 *
 * @param string $url Permalink to check.
 * @return int Post ID, or 0 on failure.
 */
function url_to_postid($url)
{
    global $wp_rewrite;
    $url = apply_filters('url_to_postid', $url);
    // First, check to see if there is a 'p=N' or 'page_id=N' to match against
    if (preg_match('#[?&](p|page_id|attachment_id)=(\\d+)#', $url, $values)) {
        $id = absint($values[2]);
        if ($id) {
            return $id;
        }
    }
    // Check to see if we are using rewrite rules
    $rewrite = $wp_rewrite->wp_rewrite_rules();
    // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options
    if (empty($rewrite)) {
        return 0;
    }
    // $url cleanup by Mark Jaquith
    // This fixes things like #anchors, ?query=strings, missing 'www.',
    // added 'www.', or added 'index.php/' that will mess up our WP_Query
    // and return a false negative
    // Get rid of the #anchor
    $url_split = explode('#', $url);
    $url = $url_split[0];
    // Get rid of URL ?query=string
    $url_split = explode('?', $url);
    $url = $url_split[0];
    // Add 'www.' if it is absent and should be there
    if (false !== strpos(get_option('home'), '://www.') && false === strpos($url, '://www.')) {
        $url = str_replace('://', '://www.', $url);
    }
    // Strip 'www.' if it is present and shouldn't be
    if (false === strpos(get_option('home'), '://www.')) {
        $url = str_replace('://www.', '://', $url);
    }
    // Strip 'index.php/' if we're not using path info permalinks
    if (!$wp_rewrite->using_index_permalinks()) {
        $url = str_replace('index.php/', '', $url);
    }
    if (false !== strpos($url, get_option('home'))) {
        // Chop off http://domain.com
        $url = str_replace(get_option('home'), '', $url);
    } else {
        // Chop off /path/to/blog
        $home_path = parse_url(get_option('home'));
        $home_path = $home_path['path'];
        $url = str_replace($home_path, '', $url);
    }
    // Trim leading and lagging slashes
    $url = trim($url, '/');
    $request = $url;
    // Done with cleanup
    // Look for matches.
    $request_match = $request;
    foreach ($rewrite as $match => $query) {
        // If the requesting file is the anchor of the match, prepend it
        // to the path info.
        if (!empty($url) && strpos($match, $url) === 0 && $url != $request) {
            $request_match = $url . '/' . $request;
        }
        if (preg_match("!^{$match}!", $request_match, $matches)) {
            // Got a match.
            // Trim the query of everything up to the '?'.
            $query = preg_replace("!^.+\\?!", '', $query);
            // Substitute the substring matches into the query.
            $query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
            // Filter out non-public query vars
            global $wp;
            parse_str($query, $query_vars);
            $query = array();
            foreach ((array) $query_vars as $key => $value) {
                if (in_array($key, $wp->public_query_vars)) {
                    $query[$key] = $value;
                }
            }
            // Do the query
            $query = new WP_Query($query);
            if ($query->is_single || $query->is_page) {
                return $query->post->ID;
            } else {
                return 0;
            }
        }
    }
    return 0;
}
开发者ID:ericandrewlewis,项目名称:wordpress-mu,代码行数:96,代码来源:rewrite.php


示例8: url_to_postid


//.........这里部分代码省略.........

	// Check to see if we are using rewrite rules
	$rewrite = $wp_rewrite->wp_rewrite_rules();

	// Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options
	if ( empty($rewrite) )
		return 0;

	// Get rid of the #anchor
	$url_split = explode('#', $url);
	$url = $url_split[0];

	// Get rid of URL ?query=string
	$url_split = explode('?', $url);
	$url = $url_split[0];

	// Add 'www.' if it is absent and should be there
	if ( false !== strpos(home_url(), '://www.') && false === strpos($url, '://www.') )
		$url = str_replace('://', '://www.', $url);

	// Strip 'www.' if it is present and shouldn't be
	if ( false === strpos(home_url(), '://www.') )
		$url = str_replace('://www.', '://', $url);

	// Strip 'index.php/' if we're not using path info permalinks
	if ( !$wp_rewrite->using_index_permalinks() )
		$url = str_replace( $wp_rewrite->index . '/', '', $url );

	if ( false !== strpos( trailingslashit( $url ), home_url( '/' ) ) ) {
		// Chop off http://domain.com/[path]
		$url = str_replace(home_url(), '', $url);
	} else {
		// Chop off /path/to/blog
		$home_path = parse_url( home_url( '/' ) );
		$home_path = isset( $home_path['path'] ) ? $home_path['path'] : '' ;
		$url = preg_replace( sprintf( '#^%s#', preg_quote( $home_path ) ), '', trailingslashit( $url ) );
	}

	// Trim leading and lagging slashes
	$url = trim($url, '/');

	$request = $url;
	$post_type_query_vars = array();

	foreach ( get_post_types( array() , 'objects' ) as $post_type => $t ) {
		if ( ! empty( $t->query_var ) )
			$post_type_query_vars[ $t->query_var ] = $post_type;
	}

	// Look for matches.
	$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) )
			$request_match = $url . '/' . $request;

		if ( preg_match("#^$match#", $request_match, $matches) ) {

			if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) {
				// This is a verbose page match, let's check to be sure about it.
				if ( ! get_page_by_path( $matches[ $varmatch[1] ] ) )
					continue;
			}

			// Got a match.
			// Trim the query of everything up to the '?'.
			$query = preg_replace("!^.+\?!", '', $query);

			// Substitute the substring matches into the query.
			$query = addslashes(WP_MatchesMapRegex::apply($query, $matches));

			// Filter out non-public query vars
			global $wp;
			parse_str( $query, $query_vars );
			$query = array();
			foreach ( (array) $query_vars as $key => $value ) {
				if ( in_array( $key, $wp->public_query_vars ) ){
					$query[$key] = $value;
					if ( isset( $post_type_query_vars[$key] ) ) {
						$query['post_type'] = $post_type_query_vars[$key];
						$query['name'] = $value;
					}
				}
			}

			// Resolve conflicts between posts with numeric slugs and date archive queries.
			$query = wp_resolve_numeric_slug_conflicts( $query );

			// Do the query
			$query = new WP_Query( $query );
			if ( ! empty( $query->posts ) && $query->is_singular )
				return $query->post->ID;
			else
				return 0;
		}
	}
	return 0;
}
开发者ID:ShankarVellal,项目名称:WordPress,代码行数:101,代码来源:rewrite.php


示例9: change_rules_array

 /**
  * Change Rules
  * Replace rewrite rules if subdomain is category
  * @param array $rules wordpress from get_option('rewrite_rules');
  * @return array Final rewrite rules
  */
 public function change_rules_array($rules)
 {
     if (is_array($rules)) {
         if ($this->settings['remove_category_permalink']) {
             /*
             Now We have to check that current request
             using rules without category or not,
             And the request what we are talking about should be "single" and its descendants (attachment, comment page, etc)
             by checking the real rules 
             */
             $without_category = true;
             if (2 == $this->settings['remove_category_permalink']) {
                 $request_match = $_SERVER['REQUEST_URI'];
                 $request_match = trim($request_match, '/');
                 $permalink_structure = get_option('permalink_structure');
                 $permalink_structure = trim($permalink_structure, '/');
                 /*
                  * only for single post, and there's no way 'slash' count would less than permalink structure
                  */
                 if (substr_count($request_match, '/') >= substr_count($permalink_structure, '/')) {
                     /*
                      *  the code below copied from class.wp.php
                      */
                     foreach ($rules as $match => $query) {
                         if (stripos($query, 'category_name') !== false) {
                             if (preg_match("#^{$match}#", $request_match, $matches) || preg_match("#^{$match}#", urldecode($request_match), $matches)) {
                                 // Trim the query of everything up to the '?'.
                                 $query_result = preg_replace("!^.+\\?!", '', $query);
                                 // Substitute the substring matches into the query.
                                 $query_result = addslashes(WP_MatchesMapRegex::apply($query_result, $matches));
                                 // Parse the query.
                                 parse_str($query_result, $perma_query_vars);
                                 if ((isset($perma_query_vars['name']) || isset($perma_query_vars['p'])) && isset($perma_query_vars['category_name'])) {
                                     $without_category = false;
                                     break;
                                 }
                             }
                         }
                     }
                 }
             }
             /*
              *update rules if we need to using rules without %category%
              */
             if ($without_category) {
                 $rules_removed_category = $this->get_rules_array_removed_category_permalink();
                 if ($rules_removed_category) {
                     $rules = $rules_removed_category;
                 }
             }
         }
         //replace all feed rules
         $rules["feed/(feed|rdf|rss|rss2|atom)/?\$"] = "index.php?category_name=" . $this->subdomain->slug . "&feed=\$matches[1]";
         $rules["(feed|rdf|rss|rss2|atom)/?\$"] = "index.php?category_name=" . $this->subdomain->slug . "&feed=\$matches[1]";
         if (0 == $this->settings['using_index']) {
             $rules2 = array();
             $rules2["\$"] = "index.php?category_name=" . $this->subdomain->slug;
             $rules2["page/?([0-9]{1,})/?\$"] = "index.php?category_name=" . $this->subdomain->slug . "&paged=\$matches[1]";
             $rules = $rules2 + $rules;
         }
     }
     return $rules;
 }
开发者ID:developmentDM2,项目名称:The-Haute-Mess,代码行数:69,代码来源:class.subdomain.php


示例10: parse_request

 /**
  * Parse request to find correct WordPress query.
  *
  * Sets up the query variables based on the request. There are also many
  * filters and actions that can be used to further manipulate the result.
  *
  * @since 2.0.0
  *
  * @param array|string $extra_query_vars Set the extra query variables.
  */
 function parse_request($extra_query_vars = '')
 {
     global $wp_rewrite;
     $this->query_vars = array();
     $taxonomy_query_vars = array();
     if (is_array($extra_query_vars)) {
         $this->extra_query_vars =& $extra_query_vars;
     } else {
         if (!empty($extra_query_vars)) {
             parse_str($extra_query_vars, $this->extra_query_vars);
         }
     }
     // Process PATH_INFO, REQUEST_URI, and 404 for permalinks.
     // Fetch the rewrite rules.
     $rewrite = $wp_rewrite->wp_rewrite_rules();
     if (!empty($rewrite)) {
         // If we match a rewrite rule, this will be cleared.
         $error = '404';
         $this->did_permalink = true;
         if (isset($_SERVER['PATH_INFO'])) {
             $pathinfo = $_SERVER['PATH_INFO'];
         } else {
             $pathinfo = '';
         }
         $pathinfo_array = explode('?', $pathinfo);
         $pathinfo = str_replace("%", "%25", $pathinfo_array[0]);
         $req_uri = $_SERVER['REQUEST_URI'];
         $req_uri_array = explode('?', $req_uri);
         $req_uri = $req_uri_array[0];
         $self = $_SERVER['PHP_SELF'];
         $home_path = parse_url(get_option('home'));
         if (isset($home_path['path'])) {
             $home_path = $home_path['path'];
         } else {
             $home_path = '';
         }
         $home_path = trim($home_path, '/');
         // Trim path info from the end and the leading home path from the
         // front.  For path info requests, this leaves us with the requesting
         // filename, if any.  For 404 requests, this leaves us with the
         // requested permalink.
         $req_uri = str_replace($pathinfo, '', rawurldecode($req_uri));
         $req_uri = trim($req_uri, '/');
         $req_uri = preg_replace("|^{$home_path}|", '', $req_uri);
         $req_uri = trim($req_uri, '/');
         $pathinfo = trim($pathinfo, '/');
         $pathinfo = preg_replace("|^{$home_path}|", '', $pathinfo);
         $pathinfo = trim($pathinfo, '/');
         $self = trim($self, '/');
         $self = preg_replace("|^{$home_path}|", '', $self);
         $self = trim($self, '/');
         // The requested permalink is in $pathinfo for path info requests and
         //  $req_uri for other requests.
         if (!empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo)) {
             $request = $pathinfo;
         } else {
             // If the request uri is the index, blank it out so that we don't try to match it against a rule.
             if ($req_uri == $wp_rewrite->index) {
                 $req_uri = '';
             }
             $request = $req_uri;
         }
         $this->request = $request;
         // Look for matches.
         $request_match = $request;
         foreach ((array) $rewrite as $match => $query) {
             // Don't try to match against AtomPub calls
             if ($req_uri == 'wp-app.php') {
                 break;
             }
             // If the requesting file is the anchor of the match, prepend it
             // to the path info.
             if (!empty($req_uri) && strpos($match, $req_uri) === 0 && $req_uri != $request) {
                 $request_match = $req_uri . '/' . $request;
             }
             if (preg_match("#^{$match}#", $request_match, $matches) || preg_match("#^{$match}#", urldecode($request_match), $matches)) {
                 // Got a match.
                 $this->matched_rule = $match;
                 // Trim the query of everything up to the '?'.
                 $query = preg_replace("!^.+\\?!", '', $query);
                 // Substitute the substring matches into the query.
                 $query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
                 $this->matched_query = $query;
                 // Parse the query.
                 parse_str($query, $perma_query_vars);
                 // If we're processing a 404 request, clear the error var
                 // since we found something.
                 if (isset($_GET['error'])) {
                     unset($_GET['error']);
                 }
//.........这里部分代码省略.........
开发者ID:gigikiri,项目名称:bcnAutoWallpaperSite,代码行数:101,代码来源:classes.php


示例11: url_to_postid


//.........这里部分代码省略.........
     }
     // Strip 'index.php/' if we're not using path info permalinks
     if (isset($wp_rewrite) && !$wp_rewrite->using_index_permalinks()) {
         $url = str_replace('index.php/', '', $url);
     }
     if (false !== strpos($url, home_url())) {
         // Chop off http://domain.com
         $url = str_replace(home_url(), '', $url);
     } else {
         // Chop off /path/to/blog
         $home_path = parse_url(home_url());
         $home_path = isset($home_path['path']) ? $home_path['path'] : '';
         $url = str_replace($home_path, '', $url);
     }
     // Trim leading and lagging slashes
     $url = trim($url, '/');
     $request = $url;
     if (empty($request) && (!isset($_GET) || empty($_GET))) {
         return get_option('page_on_front');
     }
     // Look for matches.
     $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) {
             $request_match = $url . '/' . $request;
         }
         if (preg_match("!^{$match}!", $request_match, $matches)) {
             // Got a match.
             // Trim the query of everything up to the '?'.
             $query = preg_replace("!^.+\\?!", '', $query);
             // Substitute the substring matches into the query.
             $query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
             // Filter out non-public query vars
             global $wp;
             parse_str($query, $query_vars);
             $query = array();
             foreach ((array) $query_vars as $key => $value) {
                 if (in_array($key, $wp->public_query_vars)) {
                     $query[$key] = $value;
                 }
             }
             /************************************************************************
              * ADDED: $GLOBALS['wp_post_types'] doesn't seem to have custom postypes
              * Trying below to find posttypes in $rewrite rules
              *************************************************************************/
             // PostType Array
             $custom_post_type = false;
             $post_types = array();
             foreach ($rewrite as $key => $value) {
                 if (preg_match('/post_type=([^&]+)/i', $value, $matched)) {
                     if (isset($matched[1]) && !in_array($matched[1], $post_types)) {
                         $post_types[] = $matched[1];
                     }
                 }
             }
             foreach ((array) $query_vars as $key => $value) {
                 if (in_array($key, $post_types)) {
                     $custom_post_type = true;
                     $query['post_type'] = $key;
                     $query['postname'] = $value;
                 }
             }
             // print_r($post_types);
             /************************************************************************
开发者ID:WP-Panda,项目名称:crrepetitor,代码行数:67,代码来源:extension_metaboxes.php


示例12: url_to_custompostid

/**
 * Custom post type rewrite function 
 * @param unknown $url
 * @return number|Ambigous <string, NULL>
 */
function url_to_custompostid($url)
{
    global $wp_rewrite, $wpdb;
    $moreName = '';
    $url = apply_filters('url_to_postid', $url);
    $rewrite = $wp_rewrite->wp_rewrite_rules();
    if (empty($rewrite)) {
        return 0;
    }
    $url_split = explode('#', $url);
    $url = $url_split[0];
    $url_split = explode('?', $url);
    $url = $url_split[0];
    if (false !== strpos(home_url(), '://www.') && false === strpos($url, '://www.')) {
        $url = str_replace('://', '://www.', $url);
    }
    // Add 'www.' if it is absent and should be there
    if (false === strpos(home_url(), '://www.')) {
        $url = str_replace('://www.', '://', $url);
    }
    // Strip 'www.' if it is present and shouldn't be
    if (!$wp_rewrite->using_index_permalinks()) {
        $url = str_replace('index.php/', '', $url);
    }
    // Strip 'index.php/' if we're not using path info permalinks
    if (false !== strpos($url, home_url())) {
        $url = str_replace(home_url(), '', $url);
        // Chop off http://domain.com
    } else {
        $home_path = parse_url(home_url());
        // Chop off /path/to/blog
        $home_path = isset($home_path['path']) ? $home_path['path'] : '';
        $url = str_replace($home_path, '', $url);
    }
    $url = trim($url, '/');
    // Trim leading and lagging slashes
    $request = $url;
    $request_match = $request;
    // Look for matches.
    foreach ((array) $rewrite as $match => $query) {
        if (!empty($url) && $url != $request && strpos($match, $url) === 0) {
            $request_match = $url . '/' . $request;
        }
        if (preg_match("!^{$match}!", $request_match, $matches)) {
            if ($wp_rewrite->use_verbose_page_rules && preg_match('/pagename=\\$matches\\[([0-9]+)\\]/', $query, $varmatch)) {
                if (!get_page_by_path($matches[$varmatch[1]])) {
                    continue;
                }
            }
            $query = preg_replace('!^.+\\?!', '', $query);
            $query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
            global $wp;
            global $wpdb;
            parse_str($query, $query_vars);
            $query = array();
            foreach ((array) $query_vars as $key => $value) {
                if (in_array($key, $wp->public_query_vars)) {
                    $query[$key] = $value;
                }
            }
            if (!empty($query['videogallery'])) {
                $moreName = $wpdb->get_var('SELECT ID FROM ' . $wpdb->prefix . 'posts WHERE post_name="' . $query['videogallery'] . '" LIMIT 1');
            }
            return $moreName;
        }
    }
    return 0;
}
开发者ID:jblane,项目名称:contus-video-gallery,代码行数:73,代码来源:hdflvvideoshare.php


示例13: getPageObject

 /**
  * Parse which page we are on using URL
  */
 public function getPageObject($pageUrl)
 {
     global $wp_rewrite;
     // If post type, we are using url_to_postid function
     $postId = url_to_postid($pageUrl);
     if ($postId) {
         $postType = get_post_type_object(get_post($postId)->post_type);
         return array('value' => $postId, 'title' => get_the_title($postId), 'type' => get_post($postId)->post_type, 'label' => is_array($postType->labels) ? $postType->labels['name'] : $postType->labels->name);
     }
     $path = str_replace(get_site_url(), '', $pageUrl);
     $path = trim($path, '/');
     // If path is empty, then it is front page
     if (empty($pa 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP WP_Meta_Query类代码示例发布时间:2022-05-23
下一篇:
PHP WP_List_Table类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap