WordPress.org

Make WordPress Core

Ticket #34093: 34093-3.patch

File 34093-3.patch, 3.2 KB (added by dwainm, 6 years ago)

Patch with updated spacing.

  • src/wp-includes/general-template.php

     
    18121812                $cache = array();
    18131813        }
    18141814
    1815         // Quick check. If we have no posts at all, abort!
     1815    /**
     1816     * Filter the `get_calander` function's post type.
     1817     *
     1818     * @since 4.4
     1819     * @param string $post_type . The default is 'post'.
     1820     */
     1821    $post_type = apply_filters('get_calendar_post_type', 'post');
     1822
     1823    if ( ! post_type_exists( $post_type ) ) {
     1824
     1825        // set the post type back to 'post' if the filter value is not a valid post type
     1826        $post_type = 'post';
     1827
     1828    }
     1829
     1830    // Quick check. If we have no posts at all, abort!
    18161831        if ( ! $posts ) {
    1817                 $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
     1832        $prepared_query = $wpdb->prepare( "SELECT 1 as test FROM $wpdb->posts WHERE post_type = %s AND post_status = 'publish' LIMIT 1", $post_type );
     1833                $gotsome = $wpdb->get_var( $prepared_query );
    18181834                if ( ! $gotsome ) {
    18191835                        $cache[ $key ] = '';
    18201836                        wp_cache_set( 'get_calendar', $cache, 'calendar' );
     
    18551871        $last_day = date( 't', $unixmonth );
    18561872
    18571873        // Get the next and previous month and year with at least one post
    1858         $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
     1874        $previous_prepared_query = $wpdb->prepare( "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
    18591875                FROM $wpdb->posts
    18601876                WHERE post_date < '$thisyear-$thismonth-01'
    1861                 AND post_type = 'post' AND post_status = 'publish'
     1877                AND post_type = %s AND post_status = 'publish'
    18621878                        ORDER BY post_date DESC
    1863                         LIMIT 1");
    1864         $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
     1879                        LIMIT 1" , $post_type);
     1880    $previous = $wpdb->get_row( $previous_prepared_query );
     1881
     1882    $next_prepared_query = $wpdb->prepare("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
    18651883                FROM $wpdb->posts
    18661884                WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
    1867                 AND post_type = 'post' AND post_status = 'publish'
     1885                AND post_type = %s AND post_status = 'publish'
    18681886                        ORDER BY post_date ASC
    1869                         LIMIT 1");
     1887                        LIMIT 1", $post_type );
     1888        $next = $wpdb->get_row( $next_prepared_query );
    18701889
    18711890        /* translators: Calendar caption: 1: month name, 2: 4-digit year */
    18721891        $calendar_caption = _x('%1$s %2$s', 'calendar caption');
     
    19261945        $daywithpost = array();
    19271946
    19281947        // Get days with posts
    1929         $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
     1948    $dayswithposts_prepared_query = $wpdb->prepare( "SELECT DISTINCT DAYOFMONTH(post_date)
    19301949                FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
    1931                 AND post_type = 'post' AND post_status = 'publish'
    1932                 AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
     1950                AND post_type = %s AND post_status = 'publish'
     1951                AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", $post_type);
     1952        $dayswithposts = $wpdb->get_results( $dayswithposts_prepared_query , ARRAY_N);
     1953
    19331954        if ( $dayswithposts ) {
    19341955                foreach ( (array) $dayswithposts as $daywith ) {
    19351956                        $daywithpost[] = $daywith[0];