Changeset 59908
- Timestamp:
- 03/03/2025 07:54:34 PM (2 months ago)
- Location:
- trunk
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/general-template.php
r59836 r59908 2234 2234 * 2235 2235 * @since 1.0.0 2236 * @since 6.8.0 New argument $args added, with backward compatibility. 2236 2237 * 2237 2238 * @global wpdb $wpdb WordPress database abstraction object. … … 2242 2243 * @global array $posts 2243 2244 * 2244 * @param bool $initial Optional. Whether to use initial calendar names. Default true. 2245 * @param bool $display Optional. Whether to display the calendar output. Default true. 2245 * @param array $args { 2246 * Optional. Arguments for the `get_calendar` function. 2247 * 2248 * @type bool $initial Whether to use initial calendar names. Default true. 2249 * @type bool $display Whether to display the calendar output. Default true. 2250 * @type string $post_type Optional. Post type. Default 'post'. 2251 * } 2246 2252 * @return void|string Void if `$display` argument is true, calendar HTML if `$display` is false. 2247 2253 */ 2248 function get_calendar( $ initial = true, $display = true) {2254 function get_calendar( $args = array() ) { 2249 2255 global $wpdb, $m, $monthnum, $year, $wp_locale, $posts; 2256 2257 $defaults = array( 2258 'initial' => true, 2259 'display' => true, 2260 'post_type' => 'post', 2261 ); 2262 2263 $original_args = func_get_args(); 2264 $args = array(); 2265 2266 if ( ! empty( $original_args ) ) { 2267 if ( ! is_array( $original_args[0] ) ) { 2268 if ( isset( $original_args[0] ) && is_bool( $original_args[0] ) ) { 2269 $defaults['initial'] = $original_args[0]; 2270 } 2271 if ( isset( $original_args[1] ) && is_bool( $original_args[1] ) ) { 2272 $defaults['display'] = $original_args[1]; 2273 } 2274 } else { 2275 $args = $original_args[0]; 2276 } 2277 } 2278 2279 /** 2280 * Filter the `get_calendar` function arguments before they are used. 2281 * 2282 * @since 6.8.0 2283 * 2284 * @param array $args { 2285 * Optional. Arguments for the `get_calendar` function. 2286 * 2287 * @type bool $initial Whether to use initial calendar names. Default true. 2288 * @type bool $display Whether to display the calendar output. Default true. 2289 * @type string $post_type Optional. Post type. Default 'post'. 2290 * } 2291 * @return array The arguments for the `get_calendar` function. 2292 */ 2293 $args = apply_filters( 'get_calendar_args', wp_parse_args( $args, $defaults ) ); 2250 2294 2251 2295 $key = md5( $m . $monthnum . $year ); … … 2254 2298 if ( $cache && is_array( $cache ) && isset( $cache[ $key ] ) ) { 2255 2299 /** This filter is documented in wp-includes/general-template.php */ 2256 $output = apply_filters( 'get_calendar', $cache[ $key ] );2257 2258 if ( $ display) {2300 $output = apply_filters( 'get_calendar', $cache[ $key ], $args ); 2301 2302 if ( $args['display'] ) { 2259 2303 echo $output; 2260 2304 return; … … 2268 2312 } 2269 2313 2314 $post_type = $args['post_type']; 2315 if ( ! post_type_exists( $post_type ) ) { 2316 $post_type = 'post'; 2317 } 2318 2270 2319 // Quick check. If we have no posts at all, abort! 2271 2320 if ( ! $posts ) { 2272 $gotsome = $wpdb->get_var( "SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1" ); 2321 $prepared_query = $wpdb->prepare( "SELECT 1 as test FROM $wpdb->posts WHERE post_type = %s AND post_status = 'publish' LIMIT 1", $post_type ); 2322 $gotsome = $wpdb->get_var( $prepared_query ); 2273 2323 if ( ! $gotsome ) { 2274 2324 $cache[ $key ] = ''; … … 2310 2360 2311 2361 // Get the next and previous month and year with at least one post. 2312 $previous = $wpdb->get_row(2362 $previous_prepared_query = $wpdb->prepare( 2313 2363 "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year 2314 2364 FROM $wpdb->posts 2315 2365 WHERE post_date < '$thisyear-$thismonth-01' 2316 AND post_type = 'post'AND post_status = 'publish'2366 AND post_type = %s AND post_status = 'publish' 2317 2367 ORDER BY post_date DESC 2318 LIMIT 1" 2368 LIMIT 1", 2369 $post_type 2319 2370 ); 2320 $next = $wpdb->get_row( 2371 $previous = $wpdb->get_row( $previous_prepared_query ); 2372 2373 $next_prepared_query = $wpdb->prepare( 2321 2374 "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year 2322 2375 FROM $wpdb->posts 2323 2376 WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59' 2324 AND post_type = 'post'AND post_status = 'publish'2377 AND post_type = %s AND post_status = 'publish' 2325 2378 ORDER BY post_date ASC 2326 LIMIT 1" 2379 LIMIT 1", 2380 $post_type 2327 2381 ); 2382 $next = $wpdb->get_row( $next_prepared_query ); 2328 2383 2329 2384 /* translators: Calendar caption: 1: Month name, 2: 4-digit year. */ … … 2345 2400 2346 2401 foreach ( $myweek as $wd ) { 2347 $day_name = $ initial? $wp_locale->get_weekday_initial( $wd ) : $wp_locale->get_weekday_abbrev( $wd );2402 $day_name = $args['initial'] ? $wp_locale->get_weekday_initial( $wd ) : $wp_locale->get_weekday_abbrev( $wd ); 2348 2403 $wd = esc_attr( $wd ); 2349 2404 $calendar_output .= "\n\t\t<th scope=\"col\" aria-label=\"$wd\">$day_name</th>"; … … 2359 2414 2360 2415 // Get days with posts. 2361 $dayswithposts = $wpdb->get_results(2416 $dayswithposts_prepared_query = $wpdb->prepare( 2362 2417 "SELECT DISTINCT DAYOFMONTH(post_date) 2363 2418 FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' 2364 AND post_type = 'post'AND post_status = 'publish'2419 AND post_type = %s AND post_status = 'publish' 2365 2420 AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", 2366 ARRAY_N2421 $post_type 2367 2422 ); 2423 $dayswithposts = $wpdb->get_results( $dayswithposts_prepared_query, ARRAY_N ); 2368 2424 2369 2425 if ( $dayswithposts ) { … … 2453 2509 wp_cache_set( 'get_calendar', $cache, 'calendar' ); 2454 2510 2455 if ( $display ) { 2456 /** 2457 * Filters the HTML calendar output. 2458 * 2459 * @since 3.0.0 2460 * 2461 * @param string $calendar_output HTML output of the calendar. 2462 */ 2463 echo apply_filters( 'get_calendar', $calendar_output ); 2511 /** 2512 * Filters the HTML calendar output. 2513 * 2514 * @since 3.0.0 2515 * @since 6.8.0 New argument $args added, with backward compatibility. 2516 * 2517 * @param string $calendar_output HTML output of the calendar. 2518 * @param array $args { 2519 * Optional. Array of display arguments. 2520 * 2521 * @type bool $initial Whether to use initial calendar names. Default true. 2522 * @type bool $display Whether to display the calendar output. Default true. 2523 * @type string $post_type Optional. Post type. Default 'post'. 2524 * } 2525 */ 2526 $calendar_output = apply_filters( 'get_calendar', $calendar_output, $args ); 2527 2528 if ( $args['display'] ) { 2529 echo $calendar_output; 2464 2530 return; 2465 2531 } 2466 /** This filter is documented in wp-includes/general-template.php */ 2467 return apply_filters( 'get_calendar', $calendar_output );2532 2533 return $calendar_output; 2468 2534 } 2469 2535
Note: See TracChangeset
for help on using the changeset viewer.