Make WordPress Core


Ignore:
Timestamp:
01/15/2016 07:55:19 AM (9 years ago)
Author:
swissspidy
Message:

Embeds: Allow embedding static front pages and pages having a child page with an embed slug.

This makes embed a special slug that can't be used for new pages/posts. When https://example.com/foo/embed/ is an existing page, embeds fall back to https://example.com/foo/?embed=true.
Adds unit tests.

Fixes #34971.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rewrite.php

    r36217 r36307  
    479479    }
    480480
     481    // Get rid of the #anchor
     482    $url_split = explode('#', $url);
     483    $url = $url_split[0];
     484
     485    // Get rid of URL ?query=string
     486    $url_split = explode('?', $url);
     487    $url = $url_split[0];
     488
     489    // Set the correct URL scheme.
     490    $url = set_url_scheme( $url );
     491
     492    // Add 'www.' if it is absent and should be there
     493    if ( false !== strpos(home_url(), '://www.') && false === strpos($url, '://www.') )
     494        $url = str_replace('://', '://www.', $url);
     495
     496    // Strip 'www.' if it is present and shouldn't be
     497    if ( false === strpos(home_url(), '://www.') )
     498        $url = str_replace('://www.', '://', $url);
     499
     500    if ( trim( $url, '/' ) === home_url() && 'page' == get_option( 'show_on_front' ) ) {
     501        $page_on_front = get_option( 'page_on_front' );
     502
     503        if ( $page_on_front && get_post( $page_on_front ) instanceof WP_Post ) {
     504            return (int) $page_on_front;
     505        }
     506    }
     507
    481508    // Check to see if we are using rewrite rules
    482509    $rewrite = $wp_rewrite->wp_rewrite_rules();
     
    485512    if ( empty($rewrite) )
    486513        return 0;
    487 
    488     // Get rid of the #anchor
    489     $url_split = explode('#', $url);
    490     $url = $url_split[0];
    491 
    492     // Get rid of URL ?query=string
    493     $url_split = explode('?', $url);
    494     $url = $url_split[0];
    495 
    496     // Set the correct URL scheme.
    497     $url = set_url_scheme( $url );
    498 
    499     // Add 'www.' if it is absent and should be there
    500     if ( false !== strpos(home_url(), '://www.') && false === strpos($url, '://www.') )
    501         $url = str_replace('://', '://www.', $url);
    502 
    503     // Strip 'www.' if it is present and shouldn't be
    504     if ( false === strpos(home_url(), '://www.') )
    505         $url = str_replace('://www.', '://', $url);
    506514
    507515    // Strip 'index.php/' if we're not using path info permalinks
Note: See TracChangeset for help on using the changeset viewer.