当前位置: 首页>>代码示例>>PHP>>正文


PHP wp_resolve_numeric_slug_conflicts函数代码示例

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


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

示例1: parse_request


//.........这里部分代码省略.........
             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.0
      *
      * @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;
         }
     }
     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];
         }
         if (!empty($this->query_vars[$wpvar])) {
             if (!is_array($this->query_vars[$wpvar])) {
                 $this->query_vars[$wpvar] = (string) $this->query_vars[$wpvar];
             } else {
                 foreach ($this->query_vars[$wpvar] as $vkey => $v) {
                     if (!is_object($v)) {
                         $this->query_vars[$wpvar][$vkey] = (string) $v;
                     }
                 }
             }
             if (isset($post_type_query_vars[$wpvar])) {
                 $this->query_vars['post_type'] = $post_type_query_vars[$wpvar];
                 $this->query_vars['name'] = $this->query_vars[$wpvar];
             }
         }
     }
     // Convert urldecoded spaces back into +
     foreach (get_taxonomies(array(), 'objects') as $taxonomy => $t) {
         if ($t->query_var && isset($this->query_vars[$t->query_var])) {
             $this->query_vars[$t->query_var] = str_replace(' ', '+', $this->query_vars[$t->query_var]);
         }
     }
     // Limit publicly queried post_types to those that are publicly_queryable
     if (isset($this->query_vars['post_type'])) {
         $queryable_post_types = get_post_types(array('publicly_queryable' => true));
         if (!is_array($this->query_vars['post_type'])) {
             if (!in_array($this->query_vars['post_type'], $queryable_post_types)) {
                 unset($this->query_vars['post_type']);
             }
         } else {
             $this->query_vars['post_type'] = array_intersect($this->query_vars['post_type'], $queryable_post_types);
         }
     }
     // Resolve conflicts between posts with numeric slugs and date archive queries.
     $this->query_vars = wp_resolve_numeric_slug_conflicts($this->query_vars);
     foreach ((array) $this->private_query_vars as $var) {
         if (isset($this->extra_query_vars[$var])) {
             $this->query_vars[$var] = $this->extra_query_vars[$var];
         }
     }
     if (isset($error)) {
         $this->query_vars['error'] = $error;
     }
     /**
      * Filter the array of parsed query variables.
      *
      * @since 2.1.0
      *
      * @param array $query_vars The array of requested query variables.
      */
     $this->query_vars = apply_filters('request', $this->query_vars);
     /**
      * Fires once all query variables for the current request have been parsed.
      *
      * @since 2.1.0
      *
      * @param WP &$this Current WordPress environment instance (passed by reference).
      */
     do_action_ref_array('parse_request', array(&$this));
 }
开发者ID:andxbes,项目名称:firstwpSite1,代码行数:101,代码来源:class-wp.php

示例2: 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


注:本文中的wp_resolve_numeric_slug_conflicts函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。