]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/rewrite.php
WordPress 4.5
[autoinstalls/wordpress.git] / wp-includes / rewrite.php
index 7f3b2ed321dc606a586bdb4fa7fdea0a49393c4b..0763dc500e25919aee9a4353d6890da210828987 100644 (file)
@@ -172,13 +172,27 @@ function add_rewrite_tag( $tag, $regex, $query = '' ) {
        $wp_rewrite->add_rewrite_tag( $tag, $regex, $query );
 }
 
+/**
+ * Removes an existing rewrite tag (like %postname%).
+ *
+ * @since 4.5.0
+ *
+ * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
+ *
+ * @param string $tag Name of the rewrite tag.
+ */
+function remove_rewrite_tag( $tag ) {
+       global $wp_rewrite;
+       $wp_rewrite->remove_rewrite_tag( $tag );
+}
+
 /**
  * Add permalink structure.
  *
  * @since 3.0.0
  *
  * @see WP_Rewrite::add_permastruct()
- * @global WP_Rewrite $wp_rewrite
+ * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
  *
  * @param string $name   Name for permalink structure.
  * @param string $struct Permalink structure.
@@ -197,6 +211,25 @@ function add_permastruct( $name, $struct, $args = array() ) {
        $wp_rewrite->add_permastruct( $name, $struct, $args );
 }
 
+/**
+ * Removes a permalink structure.
+ *
+ * Can only be used to remove permastructs that were added using add_permastruct().
+ * Built-in permastructs cannot be removed.
+ *
+ * @since 4.5.0
+ *
+ * @see WP_Rewrite::remove_permastruct()
+ * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
+ *
+ * @param string $name Name for permalink structure.
+ */
+function remove_permastruct( $name ) {
+       global $wp_rewrite;
+
+       $wp_rewrite->remove_permastruct( $name );
+}
+
 /**
  * Add a new feed type like /atom1/.
  *
@@ -414,7 +447,7 @@ function wp_resolve_numeric_slug_conflicts( $query_vars = array() ) {
 }
 
 /**
- * Examine a url and try to determine the post ID it represents.
+ * Examine a URL and try to determine the post ID it represents.
  *
  * Checks are supposedly from the hosted site blog.
  *
@@ -445,13 +478,6 @@ function url_to_postid( $url ) {
                        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];
@@ -461,7 +487,8 @@ function url_to_postid( $url ) {
        $url = $url_split[0];
 
        // Set the correct URL scheme.
-       $url = set_url_scheme( $url );
+       $scheme = parse_url( home_url(), PHP_URL_SCHEME );
+       $url = set_url_scheme( $url, $scheme );
 
        // Add 'www.' if it is absent and should be there
        if ( false !== strpos(home_url(), '://www.') && false === strpos($url, '://www.') )
@@ -471,6 +498,21 @@ function url_to_postid( $url ) {
        if ( false === strpos(home_url(), '://www.') )
                $url = str_replace('://www.', '://', $url);
 
+       if ( trim( $url, '/' ) === home_url() && 'page' == get_option( 'show_on_front' ) ) {
+               $page_on_front = get_option( 'page_on_front' );
+
+               if ( $page_on_front && get_post( $page_on_front ) instanceof WP_Post ) {
+                       return (int) $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;
+
        // Strip 'index.php/' if we're not using path info permalinks
        if ( !$wp_rewrite->using_index_permalinks() )
                $url = str_replace( $wp_rewrite->index . '/', '', $url );