Ticket #34093: 34093-2.patch
File 34093-2.patch, 3.2 KB (added by , 5 years ago) |
---|
-
src/wp-includes/general-template.php
1812 1812 $cache = array(); 1813 1813 } 1814 1814 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 // set the post type back to 'post' if the filter value is not a valid post type 1825 $post_type = 'post'; 1826 1827 } 1828 1829 // Quick check. If we have no posts at all, abort! 1816 1830 if ( ! $posts ) { 1817 $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1"); 1831 $prepared_query = $wpdb->prepare( "SELECT 1 as test FROM $wpdb->posts WHERE post_type = %s AND post_status = 'publish' LIMIT 1", $post_type ); 1832 $gotsome = $wpdb->get_var( $prepared_query ); 1818 1833 if ( ! $gotsome ) { 1819 1834 $cache[ $key ] = ''; 1820 1835 wp_cache_set( 'get_calendar', $cache, 'calendar' ); … … 1855 1870 $last_day = date( 't', $unixmonth ); 1856 1871 1857 1872 // 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 year1873 $previous_prepared_query = $wpdb->prepare( "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year 1859 1874 FROM $wpdb->posts 1860 1875 WHERE post_date < '$thisyear-$thismonth-01' 1861 AND post_type = 'post'AND post_status = 'publish'1876 AND post_type = %s AND post_status = 'publish' 1862 1877 ORDER BY post_date DESC 1863 LIMIT 1"); 1864 $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year 1878 LIMIT 1" , $post_type); 1879 $previous = $wpdb->get_row( $previous_prepared_query ); 1880 1881 $next_prepared_query = $wpdb->prepare("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year 1865 1882 FROM $wpdb->posts 1866 1883 WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59' 1867 AND post_type = 'post'AND post_status = 'publish'1884 AND post_type = %s AND post_status = 'publish' 1868 1885 ORDER BY post_date ASC 1869 LIMIT 1"); 1886 LIMIT 1", $post_type ); 1887 $next = $wpdb->get_row( $next_prepared_query ); 1870 1888 1871 1889 /* translators: Calendar caption: 1: month name, 2: 4-digit year */ 1872 1890 $calendar_caption = _x('%1$s %2$s', 'calendar caption'); … … 1926 1944 $daywithpost = array(); 1927 1945 1928 1946 // Get days with posts 1929 $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)1947 $dayswithposts_prepared_query = $wpdb->prepare( "SELECT DISTINCT DAYOFMONTH(post_date) 1930 1948 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); 1949 AND post_type = %s AND post_status = 'publish' 1950 AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", $post_type); 1951 $dayswithposts = $wpdb->get_results( $dayswithposts_prepared_query , ARRAY_N); 1952 1933 1953 if ( $dayswithposts ) { 1934 1954 foreach ( (array) $dayswithposts as $daywith ) { 1935 1955 $daywithpost[] = $daywith[0];