Changeset 45667 for trunk/src/wp-includes/general-template.php
- Timestamp:
- 07/25/2019 12:47:53 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/general-template.php
r45590 r45667 1822 1822 ); 1823 1823 1824 $ r= wp_parse_args( $args, $defaults );1825 1826 $post_type_object = get_post_type_object( $ r['post_type'] );1824 $parsed_args = wp_parse_args( $args, $defaults ); 1825 1826 $post_type_object = get_post_type_object( $parsed_args['post_type'] ); 1827 1827 if ( ! is_post_type_viewable( $post_type_object ) ) { 1828 1828 return; 1829 1829 } 1830 $ r['post_type'] = $post_type_object->name;1831 1832 if ( '' == $ r['type'] ) {1833 $ r['type'] = 'monthly';1834 } 1835 1836 if ( ! empty( $ r['limit'] ) ) {1837 $ r['limit'] = absint( $r['limit'] );1838 $ r['limit'] = ' LIMIT ' . $r['limit'];1839 } 1840 1841 $order = strtoupper( $ r['order'] );1830 $parsed_args['post_type'] = $post_type_object->name; 1831 1832 if ( '' == $parsed_args['type'] ) { 1833 $parsed_args['type'] = 'monthly'; 1834 } 1835 1836 if ( ! empty( $parsed_args['limit'] ) ) { 1837 $parsed_args['limit'] = absint( $parsed_args['limit'] ); 1838 $parsed_args['limit'] = ' LIMIT ' . $parsed_args['limit']; 1839 } 1840 1841 $order = strtoupper( $parsed_args['order'] ); 1842 1842 if ( $order !== 'ASC' ) { 1843 1843 $order = 'DESC'; … … 1847 1847 $archive_week_separator = '–'; 1848 1848 1849 $sql_where = $wpdb->prepare( "WHERE post_type = %s AND post_status = 'publish'", $ r['post_type'] );1849 $sql_where = $wpdb->prepare( "WHERE post_type = %s AND post_status = 'publish'", $parsed_args['post_type'] ); 1850 1850 1851 1851 /** … … 1855 1855 * 1856 1856 * @param string $sql_where Portion of SQL query containing the WHERE clause. 1857 * @param array $ rAn array of default arguments.1858 */ 1859 $where = apply_filters( 'getarchives_where', $sql_where, $ r);1857 * @param array $parsed_args An array of default arguments. 1858 */ 1859 $where = apply_filters( 'getarchives_where', $sql_where, $parsed_args ); 1860 1860 1861 1861 /** … … 1864 1864 * @since 2.2.0 1865 1865 * 1866 * @param string $sql_join Portion of SQL query containing JOIN clause.1867 * @param array $ rAn array of default arguments.1868 */ 1869 $join = apply_filters( 'getarchives_join', '', $ r);1866 * @param string $sql_join Portion of SQL query containing JOIN clause. 1867 * @param array $parsed_args An array of default arguments. 1868 */ 1869 $join = apply_filters( 'getarchives_join', '', $parsed_args ); 1870 1870 1871 1871 $output = ''; … … 1873 1873 $last_changed = wp_cache_get_last_changed( 'posts' ); 1874 1874 1875 $limit = $ r['limit'];1876 1877 if ( 'monthly' == $ r['type'] ) {1875 $limit = $parsed_args['limit']; 1876 1877 if ( 'monthly' == $parsed_args['type'] ) { 1878 1878 $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date $order $limit"; 1879 1879 $key = md5( $query ); … … 1885 1885 } 1886 1886 if ( $results ) { 1887 $after = $ r['after'];1887 $after = $parsed_args['after']; 1888 1888 foreach ( (array) $results as $result ) { 1889 1889 $url = get_month_link( $result->year, $result->month ); 1890 if ( 'post' !== $ r['post_type'] ) {1891 $url = add_query_arg( 'post_type', $ r['post_type'], $url );1890 if ( 'post' !== $parsed_args['post_type'] ) { 1891 $url = add_query_arg( 'post_type', $parsed_args['post_type'], $url ); 1892 1892 } 1893 1893 /* translators: 1: month name, 2: 4-digit year */ 1894 1894 $text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $result->year ); 1895 if ( $ r['show_post_count'] ) {1896 $ r['after'] = ' (' . $result->posts . ')' . $after;1895 if ( $parsed_args['show_post_count'] ) { 1896 $parsed_args['after'] = ' (' . $result->posts . ')' . $after; 1897 1897 } 1898 $selected = is_archive() && (string) $ r['year'] === $result->year && (string) $r['monthnum'] === $result->month;1899 $output .= get_archives_link( $url, $text, $ r['format'], $r['before'], $r['after'], $selected );1898 $selected = is_archive() && (string) $parsed_args['year'] === $result->year && (string) $parsed_args['monthnum'] === $result->month; 1899 $output .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected ); 1900 1900 } 1901 1901 } 1902 } elseif ( 'yearly' == $ r['type'] ) {1902 } elseif ( 'yearly' == $parsed_args['type'] ) { 1903 1903 $query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit"; 1904 1904 $key = md5( $query ); … … 1910 1910 } 1911 1911 if ( $results ) { 1912 $after = $ r['after'];1912 $after = $parsed_args['after']; 1913 1913 foreach ( (array) $results as $result ) { 1914 1914 $url = get_year_link( $result->year ); 1915 if ( 'post' !== $ r['post_type'] ) {1916 $url = add_query_arg( 'post_type', $ r['post_type'], $url );1915 if ( 'post' !== $parsed_args['post_type'] ) { 1916 $url = add_query_arg( 'post_type', $parsed_args['post_type'], $url ); 1917 1917 } 1918 1918 $text = sprintf( '%d', $result->year ); 1919 if ( $ r['show_post_count'] ) {1920 $ r['after'] = ' (' . $result->posts . ')' . $after;1919 if ( $parsed_args['show_post_count'] ) { 1920 $parsed_args['after'] = ' (' . $result->posts . ')' . $after; 1921 1921 } 1922 $selected = is_archive() && (string) $ r['year'] === $result->year;1923 $output .= get_archives_link( $url, $text, $ r['format'], $r['before'], $r['after'], $selected );1922 $selected = is_archive() && (string) $parsed_args['year'] === $result->year; 1923 $output .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected ); 1924 1924 } 1925 1925 } 1926 } elseif ( 'daily' == $ r['type'] ) {1926 } elseif ( 'daily' == $parsed_args['type'] ) { 1927 1927 $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date $order $limit"; 1928 1928 $key = md5( $query ); … … 1934 1934 } 1935 1935 if ( $results ) { 1936 $after = $ r['after'];1936 $after = $parsed_args['after']; 1937 1937 foreach ( (array) $results as $result ) { 1938 1938 $url = get_day_link( $result->year, $result->month, $result->dayofmonth ); 1939 if ( 'post' !== $ r['post_type'] ) {1940 $url = add_query_arg( 'post_type', $ r['post_type'], $url );1939 if ( 'post' !== $parsed_args['post_type'] ) { 1940 $url = add_query_arg( 'post_type', $parsed_args['post_type'], $url ); 1941 1941 } 1942 1942 $date = sprintf( '%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth ); 1943 1943 $text = mysql2date( get_option( 'date_format' ), $date ); 1944 if ( $ r['show_post_count'] ) {1945 $ r['after'] = ' (' . $result->posts . ')' . $after;1944 if ( $parsed_args['show_post_count'] ) { 1945 $parsed_args['after'] = ' (' . $result->posts . ')' . $after; 1946 1946 } 1947 $selected = is_archive() && (string) $ r['year'] === $result->year && (string) $r['monthnum'] === $result->month && (string) $r['day'] === $result->dayofmonth;1948 $output .= get_archives_link( $url, $text, $ r['format'], $r['before'], $r['after'], $selected );1947 $selected = is_archive() && (string) $parsed_args['year'] === $result->year && (string) $parsed_args['monthnum'] === $result->month && (string) $parsed_args['day'] === $result->dayofmonth; 1948 $output .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected ); 1949 1949 } 1950 1950 } 1951 } elseif ( 'weekly' == $ r['type'] ) {1951 } elseif ( 'weekly' == $parsed_args['type'] ) { 1952 1952 $week = _wp_mysql_week( '`post_date`' ); 1953 1953 $query = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit"; … … 1961 1961 $arc_w_last = ''; 1962 1962 if ( $results ) { 1963 $after = $ r['after'];1963 $after = $parsed_args['after']; 1964 1964 foreach ( (array) $results as $result ) { 1965 1965 if ( $result->week != $arc_w_last ) { … … 1976 1976 home_url( '/' ) 1977 1977 ); 1978 if ( 'post' !== $ r['post_type'] ) {1979 $url = add_query_arg( 'post_type', $ r['post_type'], $url );1978 if ( 'post' !== $parsed_args['post_type'] ) { 1979 $url = add_query_arg( 'post_type', $parsed_args['post_type'], $url ); 1980 1980 } 1981 1981 $text = $arc_week_start . $archive_week_separator . $arc_week_end; 1982 if ( $ r['show_post_count'] ) {1983 $ r['after'] = ' (' . $result->posts . ')' . $after;1982 if ( $parsed_args['show_post_count'] ) { 1983 $parsed_args['after'] = ' (' . $result->posts . ')' . $after; 1984 1984 } 1985 $selected = is_archive() && (string) $ r['year'] === $result->yr && (string) $r['w'] === $result->week;1986 $output .= get_archives_link( $url, $text, $ r['format'], $r['before'], $r['after'], $selected );1985 $selected = is_archive() && (string) $parsed_args['year'] === $result->yr && (string) $parsed_args['w'] === $result->week; 1986 $output .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected ); 1987 1987 } 1988 1988 } 1989 1989 } 1990 } elseif ( ( 'postbypost' == $ r['type'] ) || ( 'alpha' == $r['type'] ) ) {1991 $orderby = ( 'alpha' == $ r['type'] ) ? 'post_title ASC ' : 'post_date DESC, ID DESC ';1990 } elseif ( ( 'postbypost' == $parsed_args['type'] ) || ( 'alpha' == $parsed_args['type'] ) ) { 1991 $orderby = ( 'alpha' == $parsed_args['type'] ) ? 'post_title ASC ' : 'post_date DESC, ID DESC '; 1992 1992 $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit"; 1993 1993 $key = md5( $query ); … … 2009 2009 } 2010 2010 $selected = $result->ID === get_the_ID(); 2011 $output .= get_archives_link( $url, $text, $ r['format'], $r['before'], $r['after'], $selected );2011 $output .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected ); 2012 2012 } 2013 2013 } 2014 2014 } 2015 2015 } 2016 if ( $ r['echo'] ) {2016 if ( $parsed_args['echo'] ) { 2017 2017 echo $output; 2018 2018 } else {
Note: See TracChangeset
for help on using the changeset viewer.