Make WordPress Core

Ticket #46227: 46227.11.diff

File 46227.11.diff, 3.1 KB (added by audrasjb, 4 years ago)

Patch refreshed for WP 5.7

  • src/wp-includes/default-filters.php

    diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php
    index 334a12a929..83721635fc 100644
    a b add_action( 'wp_head', 'wp_print_styles', 8 ); 
    297297add_action( 'wp_head', 'wp_print_head_scripts', 9 );
    298298add_action( 'wp_head', 'wp_generator' );
    299299add_action( 'wp_head', 'rel_canonical' );
     300add_action( 'wp_head', 'rel_feed_for_posts', 10, 0 );
    300301add_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
    301302add_action( 'wp_head', 'wp_custom_css_cb', 101 );
    302303add_action( 'wp_head', 'wp_site_icon', 99 );
  • src/wp-includes/general-template.php

    diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php
    index 26fe0a3674..6399590d51 100644
    a b function wp_enqueue_code_editor( $args ) { 
    36463646        return $settings;
    36473647}
    36483648
     3649/**
     3650 * Adds a link rel=feed element to the home page when a static front page is set in Settings > Reading.
     3651 *
     3652 * See {@see 'wp_head'}.
     3653 *
     3654 * @since 5.7.0
     3655 */
     3656function rel_feed_for_posts() {
     3657        $page_for_posts = get_option( 'page_for_posts' );
     3658
     3659        if ( is_front_page() && ! is_home() ) {
     3660                echo '<link rel="feed" type="text/html" href="' . get_the_permalink( $page_for_posts ) . '" title="' . the_title_attribute( array( 'echo' => false, 'post' => $page_for_posts ) ) . '" />';
     3661        }
     3662}
     3663
    36493664/**
    36503665 * Generate and return code editor settings.
    36513666 *
  • tests/phpunit/tests/general/document-title.php

    diff --git a/tests/phpunit/tests/general/document-title.php b/tests/phpunit/tests/general/document-title.php
    index a15f926ea9..9dc39b74bb 100644
    a b  
    11<?php
    22
    33/**
    4  * A set of unit tests for functions in wp-includes/general-template.php
     4 * A set of unit tests for testing the Document Title functions in wp-includes/general-template.php
    55 *
    66 * @group template
    77 * @group document-title
     8 * @ticket 46227
    89 */
    910class Tests_General_DocumentTitle extends WP_UnitTestCase {
    1011
    class Tests_General_DocumentTitle extends WP_UnitTestCase { 
    275276        function _change_title_separator( $sep ) {
    276277                return '%%';
    277278        }
     279
     280        // Test adding custom feed link to the blog page in the header.
     281        function test_add_feed_link_to_header_front_page() {
     282                $test_title = 'Blog';
     283                // create a sample blog page.
     284                $blog_page_id = $this->factory->post->create(
     285                        array(
     286                                'post_title' => $test_title,
     287                                'post_type'  => 'page',
     288                        )
     289                );
     290
     291                update_option( 'page_for_posts', $blog_page_id );
     292                update_option( 'show_on_front', 'page' );
     293
     294                $this->go_to('/');
     295
     296                $doc = new DOMDocument();
     297                $doc->preserveWhiteSpace = false;
     298
     299                $test_link_str = '<link rel="feed" type="text/html" href="' . get_the_permalink( $blog_page_id ) . '" title="' . the_title_attribute( array( 'echo' => false, 'post' => $blog_page_id ) ) . '" />';
     300                $doc->loadHTML( $test_link_str );
     301
     302                $selector = new DOMXPath( $doc );
     303                $result = $selector->query( "/html/head/link[@rel= 'feed']" );
     304                $test_blog_title = $result->item(0)->getAttribute( 'title' );
     305
     306                $this->assertEquals( $test_blog_title, $test_title );
     307        }
    278308}