Ticket #34093: 34093-3.patch
File 34093-3.patch, 3.2 KB (added by , 9 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 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! 1816 1831 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 ); 1818 1834 if ( ! $gotsome ) { 1819 1835 $cache[ $key ] = ''; 1820 1836 wp_cache_set( 'get_calendar', $cache, 'calendar' ); … … 1855 1871 $last_day = date( 't', $unixmonth ); 1856 1872 1857 1873 // 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 year1874 $previous_prepared_query = $wpdb->prepare( "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year 1859 1875 FROM $wpdb->posts 1860 1876 WHERE post_date < '$thisyear-$thismonth-01' 1861 AND post_type = 'post'AND post_status = 'publish'1877 AND post_type = %s AND post_status = 'publish' 1862 1878 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 1865 1883 FROM $wpdb->posts 1866 1884 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' 1868 1886 ORDER BY post_date ASC 1869 LIMIT 1"); 1887 LIMIT 1", $post_type ); 1888 $next = $wpdb->get_row( $next_prepared_query ); 1870 1889 1871 1890 /* translators: Calendar caption: 1: month name, 2: 4-digit year */ 1872 1891 $calendar_caption = _x('%1$s %2$s', 'calendar caption'); … … 1926 1945 $daywithpost = array(); 1927 1946 1928 1947 // 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) 1930 1949 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 1933 1954 if ( $dayswithposts ) { 1934 1955 foreach ( (array) $dayswithposts as $daywith ) { 1935 1956 $daywithpost[] = $daywith[0];