| [ Root ] [ Index ] |
PHP Cross Reference of WordPress TrunkProvided by Yoast |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * WordPress Post Template Functions. 4 * 5 * Gets content for the current post in the loop. 6 * 7 * @package WordPress 8 * @subpackage Template 9 */ 10 11 /** 12 * Display the ID of the current item in the WordPress Loop. 13 * 14 * @since 0.71 15 * @uses $id 16 */ 17 function the_ID() { 18 global $id; 19 echo $id; 20 } 21 22 /** 23 * Retrieve the ID of the current item in the WordPress Loop. 24 * 25 * @since 2.1.0 26 * @uses $id 27 * 28 * @return unknown 29 */ 30 function get_the_ID() { 31 global $id; 32 return $id; 33 } 34 35 /** 36 * Display or retrieve the current post title with optional content. 37 * 38 * @since 0.71 39 * 40 * @param string $before Optional. Content to prepend to the title. 41 * @param string $after Optional. Content to append to the title. 42 * @param bool $echo Optional, default to true.Whether to display or return. 43 * @return null|string Null on no title. String if $echo parameter is false. 44 */ 45 function the_title($before = '', $after = '', $echo = true) { 46 $title = get_the_title(); 47 48 if ( strlen($title) == 0 ) 49 return; 50 51 $title = $before . $title . $after; 52 53 if ( $echo ) 54 echo $title; 55 else 56 return $title; 57 } 58 59 /** 60 * Sanitize the current title when retrieving or displaying. 61 * 62 * Works like {@link the_title()}, except the parameters can be in a string or 63 * an array. See the function for what can be override in the $args parameter. 64 * 65 * The title before it is displayed will have the tags stripped and {@link 66 * esc_attr()} before it is passed to the user or displayed. The default 67 * as with {@link the_title()}, is to display the title. 68 * 69 * @since 2.3.0 70 * 71 * @param string|array $args Optional. Override the defaults. 72 * @return string|null Null on failure or display. String when echo is false. 73 */ 74 function the_title_attribute( $args = '' ) { 75 $title = get_the_title(); 76 77 if ( strlen($title) == 0 ) 78 return; 79 80 $defaults = array('before' => '', 'after' => '', 'echo' => true); 81 $r = wp_parse_args($args, $defaults); 82 extract( $r, EXTR_SKIP ); 83 84 85 $title = $before . $title . $after; 86 $title = esc_attr(strip_tags($title)); 87 88 if ( $echo ) 89 echo $title; 90 else 91 return $title; 92 } 93 94 /** 95 * Retrieve post title. 96 * 97 * If the post is protected and the visitor is not an admin, then "Protected" 98 * will be displayed before the post title. If the post is private, then 99 * "Private" will be located before the post title. 100 * 101 * @since 0.71 102 * 103 * @param int $id Optional. Post ID. 104 * @return string 105 */ 106 function get_the_title( $id = 0 ) { 107 $post = &get_post($id); 108 109 $title = isset($post->post_title) ? $post->post_title : ''; 110 $id = isset($post->ID) ? $post->ID : (int) $id; 111 112 if ( !is_admin() ) { 113 if ( !empty($post->post_password) ) { 114 $protected_title_format = apply_filters('protected_title_format', __('Protected: %s')); 115 $title = sprintf($protected_title_format, $title); 116 } else if ( isset($post->post_status) && 'private' == $post->post_status ) { 117 $private_title_format = apply_filters('private_title_format', __('Private: %s')); 118 $title = sprintf($private_title_format, $title); 119 } 120 } 121 return apply_filters( 'the_title', $title, $id ); 122 } 123 124 /** 125 * Display the Post Global Unique Identifier (guid). 126 * 127 * The guid will appear to be a link, but should not be used as an link to the 128 * post. The reason you should not use it as a link, is because of moving the 129 * blog across domains. 130 * 131 * @since 1.5.0 132 * 133 * @param int $id Optional. Post ID. 134 */ 135 function the_guid( $id = 0 ) { 136 echo get_the_guid($id); 137 } 138 139 /** 140 * Retrieve the Post Global Unique Identifier (guid). 141 * 142 * The guid will appear to be a link, but should not be used as an link to the 143 * post. The reason you should not use it as a link, is because of moving the 144 * blog across domains. 145 * 146 * @since 1.5.0 147 * 148 * @param int $id Optional. Post ID. 149 * @return string 150 */ 151 function get_the_guid( $id = 0 ) { 152 $post = &get_post($id); 153 154 return apply_filters('get_the_guid', $post->guid); 155 } 156 157 /** 158 * Display the post content. 159 * 160 * @since 0.71 161 * 162 * @param string $more_link_text Optional. Content for when there is more text. 163 * @param string $stripteaser Optional. Teaser content before the more text. 164 */ 165 function the_content($more_link_text = null, $stripteaser = 0) { 166 $content = get_the_content($more_link_text, $stripteaser); 167 $content = apply_filters('the_content', $content); 168 $content = str_replace(']]>', ']]>', $content); 169 echo $content; 170 } 171 172 /** 173 * Retrieve the post content. 174 * 175 * @since 0.71 176 * 177 * @param string $more_link_text Optional. Content for when there is more text. 178 * @param string $stripteaser Optional. Teaser content before the more text. 179 * @return string 180 */ 181 function get_the_content($more_link_text = null, $stripteaser = 0) { 182 global $id, $post, $more, $page, $pages, $multipage, $preview; 183 184 if ( null === $more_link_text ) 185 $more_link_text = __( '(more...)' ); 186 187 $output = ''; 188 $hasTeaser = false; 189 190 // If post password required and it doesn't match the cookie. 191 if ( post_password_required($post) ) { 192 $output = get_the_password_form(); 193 return $output; 194 } 195 196 if ( $page > count($pages) ) // if the requested page doesn't exist 197 $page = count($pages); // give them the highest numbered page that DOES exist 198 199 $content = $pages[$page-1]; 200 if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) { 201 $content = explode($matches[0], $content, 2); 202 if ( !empty($matches[1]) && !empty($more_link_text) ) 203 $more_link_text = strip_tags(wp_kses_no_null(trim($matches[1]))); 204 205 $hasTeaser = true; 206 } else { 207 $content = array($content); 208 } 209 if ( (false !== strpos($post->post_content, '<!--noteaser-->') && ((!$multipage) || ($page==1))) ) 210 $stripteaser = 1; 211 $teaser = $content[0]; 212 if ( ($more) && ($stripteaser) && ($hasTeaser) ) 213 $teaser = ''; 214 $output .= $teaser; 215 if ( count($content) > 1 ) { 216 if ( $more ) { 217 $output .= '<span id="more-' . $id . '"></span>' . $content[1]; 218 } else { 219 if ( ! empty($more_link_text) ) 220 $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-$id\" class=\"more-link\">$more_link_text</a>", $more_link_text ); 221 $output = force_balance_tags($output); 222 } 223 224 } 225 if ( $preview ) // preview fix for javascript bug with foreign languages 226 $output = preg_replace_callback('/\%u([0-9A-F]{4})/', create_function('$match', 'return "&#" . base_convert($match[1], 16, 10) . ";";'), $output); 227 228 return $output; 229 } 230 231 /** 232 * Display the post excerpt. 233 * 234 * @since 0.71 235 * @uses apply_filters() Calls 'the_excerpt' hook on post excerpt. 236 */ 237 function the_excerpt() { 238 echo apply_filters('the_excerpt', get_the_excerpt()); 239 } 240 241 /** 242 * Retrieve the post excerpt. 243 * 244 * @since 0.71 245 * 246 * @param mixed $deprecated Not used. 247 * @return string 248 */ 249 function get_the_excerpt( $deprecated = '' ) { 250 if ( !empty( $deprecated ) ) 251 _deprecated_argument( __FUNCTION__, '2.3' ); 252 253 global $post; 254 $output = $post->post_excerpt; 255 if ( post_password_required($post) ) { 256 $output = __('There is no excerpt because this is a protected post.'); 257 return $output; 258 } 259 260 return apply_filters('get_the_excerpt', $output); 261 } 262 263 /** 264 * Whether post has excerpt. 265 * 266 * @since 2.3.0 267 * 268 * @param int $id Optional. Post ID. 269 * @return bool 270 */ 271 function has_excerpt( $id = 0 ) { 272 $post = &get_post( $id ); 273 return ( !empty( $post->post_excerpt ) ); 274 } 275 276 /** 277 * Display the classes for the post div. 278 * 279 * @since 2.7.0 280 * 281 * @param string|array $class One or more classes to add to the class list. 282 * @param int $post_id An optional post ID. 283 */ 284 function post_class( $class = '', $post_id = null ) { 285 // Separates classes with a single space, collates classes for post DIV 286 echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"'; 287 } 288 289 /** 290 * Retrieve the classes for the post div as an array. 291 * 292 * The class names are add are many. If the post is a sticky, then the 'sticky' 293 * class name. The class 'hentry' is always added to each post. For each 294 * category, the class will be added with 'category-' with category slug is 295 * added. The tags are the same way as the categories with 'tag-' before the tag 296 * slug. All classes are passed through the filter, 'post_class' with the list 297 * of classes, followed by $class parameter value, with the post ID as the last 298 * parameter. 299 * 300 * @since 2.7.0 301 * 302 * @param string|array $class One or more classes to add to the class list. 303 * @param int $post_id An optional post ID. 304 * @return array Array of classes. 305 */ 306 function get_post_class( $class = '', $post_id = null ) { 307 $post = get_post($post_id); 308 309 $classes = array(); 310 311 if ( empty($post) ) 312 return $classes; 313 314 $classes[] = 'post-' . $post->ID; 315 $classes[] = $post->post_type; 316 $classes[] = 'type-' . $post->post_type; 317 318 // sticky for Sticky Posts 319 if ( is_sticky($post->ID) && is_home()) 320 $classes[] = 'sticky'; 321 322 // hentry for hAtom compliace 323 $classes[] = 'hentry'; 324 325 // Categories 326 foreach ( (array) get_the_category($post->ID) as $cat ) { 327 if ( empty($cat->slug ) ) 328 continue; 329 $classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->cat_ID); 330 } 331 332 // Tags 333 foreach ( (array) get_the_tags($post->ID) as $tag ) { 334 if ( empty($tag->slug ) ) 335 continue; 336 $classes[] = 'tag-' . sanitize_html_class($tag->slug, $tag->term_id); 337 } 338 339 if ( !empty($class) ) { 340 if ( !is_array( $class ) ) 341 $class = preg_split('#\s+#', $class); 342 $classes = array_merge($classes, $class); 343 } 344 345 $classes = array_map('esc_attr', $classes); 346 347 return apply_filters('post_class', $classes, $class, $post->ID); 348 } 349 350 /** 351 * Display the classes for the body element. 352 * 353 * @since 2.8.0 354 * 355 * @param string|array $class One or more classes to add to the class list. 356 */ 357 function body_class( $class = '' ) { 358 // Separates classes with a single space, collates classes for body element 359 echo 'class="' . join( ' ', get_body_class( $class ) ) . '"'; 360 } 361 362 /** 363 * Retrieve the classes for the body element as an array. 364 * 365 * @since 2.8.0 366 * 367 * @param string|array $class One or more classes to add to the class list. 368 * @return array Array of classes. 369 */ 370 function get_body_class( $class = '' ) { 371 global $wp_query, $wpdb; 372 373 $classes = array(); 374 375 if ( 'rtl' == get_bloginfo( 'text_direction' ) ) 376 $classes[] = 'rtl'; 377 378 if ( is_front_page() ) 379 $classes[] = 'home'; 380 if ( is_home() ) 381 $classes[] = 'blog'; 382 if ( is_archive() ) 383 $classes[] = 'archive'; 384 if ( is_date() ) 385 $classes[] = 'date'; 386 if ( is_search() ) 387 $classes[] = 'search'; 388 if ( is_paged() ) 389 $classes[] = 'paged'; 390 if ( is_attachment() ) 391 $classes[] = 'attachment'; 392 if ( is_404() ) 393 $classes[] = 'error404'; 394 395 if ( is_single() ) { 396 $post_id = $wp_query->get_queried_object_id(); 397 $post = $wp_query->get_queried_object(); 398 399 $classes[] = 'single'; 400 $classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id); 401 $classes[] = 'postid-' . $post_id; 402 403 if ( is_attachment() ) { 404 $mime_type = get_post_mime_type($post_id); 405 $mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' ); 406 $classes[] = 'attachmentid-' . $post_id; 407 $classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type ); 408 } 409 } elseif ( is_archive() ) { 410 if ( is_author() ) { 411 $author = $wp_query->get_queried_object(); 412 $classes[] = 'author'; 413 $classes[] = 'author-' . sanitize_html_class( $author->user_nicename , $author->ID ); 414 } elseif ( is_category() ) { 415 $cat = $wp_query->get_queried_object(); 416 $classes[] = 'category'; 417 $classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->cat_ID ); 418 } elseif ( is_tag() ) { 419 $tags = $wp_query->get_queried_object(); 420 $classes[] = 'tag'; 421 $classes[] = 'tag-' . sanitize_html_class( $tags->slug, $tags->term_id ); 422 } 423 } elseif ( is_page() ) { 424 $classes[] = 'page'; 425 426 $page_id = $wp_query->get_queried_object_id(); 427 428 $post = get_page($page_id); 429 430 $classes[] = 'page-id-' . $page_id; 431 432 if ( $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status = 'publish' LIMIT 1", $page_id) ) ) 433 $classes[] = 'page-parent'; 434 435 if ( $post->post_parent ) { 436 $classes[] = 'page-child'; 437 $classes[] = 'parent-pageid-' . $post->post_parent; 438 } 439 if ( is_page_template() ) { 440 $classes[] = 'page-template'; 441 $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_post_meta( $page_id, '_wp_page_template', true ) ), '' ); 442 } 443 } elseif ( is_search() ) { 444 if ( !empty( $wp_query->posts ) ) 445 $classes[] = 'search-results'; 446 else 447 $classes[] = 'search-no-results'; 448 } 449 450 if ( is_user_logged_in() ) 451 $classes[] = 'logged-in'; 452 453 $page = $wp_query->get( 'page' ); 454 455 if ( !$page || $page < 2) 456 $page = $wp_query->get( 'paged' ); 457 458 if ( $page && $page > 1 ) { 459 $classes[] = 'paged-' . $page; 460 461 if ( is_single() ) 462 $classes[] = 'single-paged-' . $page; 463 elseif ( is_page() ) 464 $classes[] = 'page-paged-' . $page; 465 elseif ( is_category() ) 466 $classes[] = 'category-paged-' . $page; 467 elseif ( is_tag() ) 468 $classes[] = 'tag-paged-' . $page; 469 elseif ( is_date() ) 470 $classes[] = 'date-paged-' . $page; 471 elseif ( is_author() ) 472 $classes[] = 'author-paged-' . $page; 473 elseif ( is_search() ) 474 $classes[] = 'search-paged-' . $page; 475 } 476 477 if ( !empty( $class ) ) { 478 if ( !is_array( $class ) ) 479 $class = preg_split( '#\s+#', $class ); 480 $classes = array_merge( $classes, $class ); 481 } 482 483 $classes = array_map( 'esc_attr', $classes ); 484 485 return apply_filters( 'body_class', $classes, $class ); 486 } 487 488 /** 489 * Whether post requires password and correct password has been provided. 490 * 491 * @since 2.7.0 492 * 493 * @param int|object $post An optional post. Global $post used if not provided. 494 * @return bool false if a password is not required or the correct password cookie is present, true otherwise. 495 */ 496 function post_password_required( $post = null ) { 497 $post = get_post($post); 498 499 if ( empty($post->post_password) ) 500 return false; 501 502 if ( !isset($_COOKIE['wp-postpass_' . COOKIEHASH]) ) 503 return true; 504 505 if ( $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password ) 506 return true; 507 508 return false; 509 } 510 511 /** 512 * Display "sticky" CSS class, if a post is sticky. 513 * 514 * @since 2.7.0 515 * 516 * @param int $post_id An optional post ID. 517 */ 518 function sticky_class( $post_id = null ) { 519 if ( !is_sticky($post_id) ) 520 return; 521 522 echo " sticky"; 523 } 524 525 /** 526 * Page Template Functions for usage in Themes 527 * 528 * @package WordPress 529 * @subpackage Template 530 */ 531 532 /** 533 * The formatted output of a list of pages. 534 * 535 * Displays page links for paginated posts (i.e. includes the <!--nextpage-->. 536 * Quicktag one or more times). This tag must be within The Loop. 537 * 538 * The defaults for overwriting are: 539 * 'next_or_number' - Default is 'number' (string). Indicates whether page 540 * numbers should be used. Valid values are number and next. 541 * 'nextpagelink' - Default is 'Next Page' (string). Text for link to next page. 542 * of the bookmark. 543 * 'previouspagelink' - Default is 'Previous Page' (string). Text for link to 544 * previous page, if available. 545 * 'pagelink' - Default is '%' (String).Format string for page numbers. The % in 546 * the parameter string will be replaced with the page number, so Page % 547 * generates "Page 1", "Page 2", etc. Defaults to %, just the page number. 548 * 'before' - Default is '<p> Pages:' (string). The html or text to prepend to 549 * each bookmarks. 550 * 'after' - Default is '</p>' (string). The html or text to append to each 551 * bookmarks. 552 * 'link_before' - Default is '' (string). The html or text to prepend to each 553 * Pages link inside the <a> tag. 554 * 'link_after' - Default is '' (string). The html or text to append to each 555 * Pages link inside the <a> tag. 556 * 557 * @since 1.2.0 558 * @access private 559 * 560 * @param string|array $args Optional. Overwrite the defaults. 561 * @return string Formatted output in HTML. 562 */ 563 function wp_link_pages($args = '') { 564 $defaults = array( 565 'before' => '<p>' . __('Pages:'), 'after' => '</p>', 566 'link_before' => '', 'link_after' => '', 567 'next_or_number' => 'number', 'nextpagelink' => __('Next page'), 568 'previouspagelink' => __('Previous page'), 'pagelink' => '%', 569 'echo' => 1 570 ); 571 572 $r = wp_parse_args( $args, $defaults ); 573 $r = apply_filters( 'wp_link_pages_args', $r ); 574 extract( $r, EXTR_SKIP ); 575 576 global $post, $page, $numpages, $multipage, $more, $pagenow; 577 578 $output = ''; 579 if ( $multipage ) { 580 if ( 'number' == $next_or_number ) { 581 $output .= $before; 582 for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) { 583 $j = str_replace('%',$i,$pagelink); 584 $output .= ' '; 585 if ( ($i != $page) || ((!$more) && ($page==1)) ) { 586 if ( 1 == $i ) { 587 $output .= '<a href="' . get_permalink() . '">'; 588 } else { 589 if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) ) 590 $output .= '<a href="' . add_query_arg('page', $i, get_permalink()) . '">'; 591 elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID ) 592 $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit('page/' . $i, 'single_paged'). '">'; 593 else 594 $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">'; 595 } 596 597 } 598 $output .= $link_before; 599 $output .= $j; 600 $output .= $link_after; 601 if ( ($i != $page) || ((!$more) && ($page==1)) ) 602 $output .= '</a>'; 603 } 604 $output .= $after; 605 } else { 606 if ( $more ) { 607 $output .= $before; 608 $i = $page - 1; 609 if ( $i && $more ) { 610 if ( 1 == $i ) { 611 $output .= '<a href="' . get_permalink() . '">'; 612 } else { 613 if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) ) 614 $output .= '<a href="' . add_query_arg('page', $i, get_permalink()) . '">'; 615 elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID ) 616 $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit('page/' . $i, 'single_paged'). '">'; 617 else 618 $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">'; 619 } 620 $output .= $link_before. $previouspagelink . $link_after . '</a>'; 621 } 622 $i = $page + 1; 623 if ( $i <= $numpages && $more ) { 624 if ( 1 == $i ) { 625 $output .= '<a href="' . get_permalink() . '">'; 626 } else { 627 if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) ) 628 $output .= '<a href="' . add_query_arg('page', $i, get_permalink()) . '">'; 629 elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID ) 630 $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit('page/' . $i, 'single_paged'). '">'; 631 else 632 $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">'; 633 } 634 $output .= $link_before. $nextpagelink . $link_after . '</a>'; 635 } 636 $output .= $after; 637 } 638 } 639 } 640 641 if ( $echo ) 642 echo $output; 643 644 return $output; 645 } 646 647 648 // 649 // Post-meta: Custom per-post fields. 650 // 651 652 /** 653 * Retrieve post custom meta data field. 654 * 655 * @since 1.5.0 656 * 657 * @param string $key Meta data key name. 658 * @return string|array Array of values or single value, if only one element exists. 659 */ 660 function post_custom( $key = '' ) { 661 $custom = get_post_custom(); 662 663 if ( 1 == count($custom[$key]) ) 664 return $custom[$key][0]; 665 else 666 return $custom[$key]; 667 } 668 669 /** 670 * Display list of post custom fields. 671 * 672 * @internal This will probably change at some point... 673 * @since 1.2.0 674 * @uses apply_filters() Calls 'the_meta_key' on list item HTML content, with key and value as separate parameters. 675 */ 676 function the_meta() { 677 if ( $keys = get_post_custom_keys() ) { 678 echo "<ul class='post-meta'>\n"; 679 foreach ( (array) $keys as $key ) { 680 $keyt = trim($key); 681 if ( '_' == $keyt{0} ) 682 continue; 683 $values = array_map('trim', get_post_custom_values($key)); 684 $value = implode($values,', '); 685 echo apply_filters('the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value); 686 } 687 echo "</ul>\n"; 688 } 689 } 690 691 // 692 // Pages 693 // 694 695 /** 696 * Retrieve or display list of pages as a dropdown (select list). 697 * 698 * @since 2.1.0 699 * 700 * @param array|string $args Optional. Override default arguments. 701 * @return string HTML content, if not displaying. 702 */ 703 function wp_dropdown_pages($args = '') { 704 $defaults = array( 705 'depth' => 0, 'child_of' => 0, 706 'selected' => 0, 'echo' => 1, 707 'name' => 'page_id', 'id' => '', 708 'show_option_none' => '', 'show_option_no_change' => '', 709 'option_none_value' => '' 710 ); 711 712 $r = wp_parse_args( $args, $defaults ); 713 extract( $r, EXTR_SKIP ); 714 715 $pages = get_pages($r); 716 $output = ''; 717 $name = esc_attr($name); 718 // Back-compat with old system where both id and name were based on $name argument 719 if ( empty($id) ) 720 $id = $name; 721 722 if ( ! empty($pages) ) { 723 $output = "<select name=\"$name\" id=\"$id\">\n"; 724 if ( $show_option_no_change ) 725 $output .= "\t<option value=\"-1\">$show_option_no_change</option>"; 726 if ( $show_option_none ) 727 $output .= "\t<option value=\"" . esc_attr($option_none_value) . "\">$show_option_none</option>\n"; 728 $output .= walk_page_dropdown_tree($pages, $depth, $r); 729 $output .= "</select>\n"; 730 } 731 732 $output = apply_filters('wp_dropdown_pages', $output); 733 734 if ( $echo ) 735 echo $output; 736 737 return $output; 738 } 739 740 /** 741 * Retrieve or display list of pages in list (li) format. 742 * 743 * @since 1.5.0 744 * 745 * @param array|string $args Optional. Override default arguments. 746 * @return string HTML content, if not displaying. 747 */ 748 function wp_list_pages($args = '') { 749 $defaults = array( 750 'depth' => 0, 'show_date' => '', 751 'date_format' => get_option('date_format'), 752 'child_of' => 0, 'exclude' => '', 753 'title_li' => __('Pages'), 'echo' => 1, 754 'authors' => '', 'sort_column' => 'menu_order, post_title', 755 'link_before' => '', 'link_after' => '', 'walker' => '', 756 ); 757 758 $r = wp_parse_args( $args, $defaults ); 759 extract( $r, EXTR_SKIP ); 760 761 $output = ''; 762 $current_page = 0; 763 764 // sanitize, mostly to keep spaces out 765 $r['exclude'] = preg_replace('/[^0-9,]/', '', $r['exclude']); 766 767 // Allow plugins to filter an array of excluded pages (but don't put a nullstring into the array) 768 $exclude_array = ( $r['exclude'] ) ? explode(',', $r['exclude']) : array(); 769 $r['exclude'] = implode( ',', apply_filters('wp_list_pages_excludes', $exclude_array) ); 770 771 // Query pages. 772 $r['hierarchical'] = 0; 773 $pages = get_pages($r); 774 775 if ( !empty($pages) ) { 776 if ( $r['title_li'] ) 777 $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>'; 778 779 global $wp_query; 780 if ( is_page() || is_attachment() || $wp_query->is_posts_page ) 781 $current_page = $wp_query->get_queried_object_id(); 782 $output .= walk_page_tree($pages, $r['depth'], $current_page, $r); 783 784 if ( $r['title_li'] ) 785 $output .= '</ul></li>'; 786 } 787 788 $output = apply_filters('wp_list_pages', $output, $r); 789 790 if ( $r['echo'] ) 791 echo $output; 792 else 793 return $output; 794 } 795 796 /** 797 * Display or retrieve list of pages with optional home link. 798 * 799 * The arguments are listed below and part of the arguments are for {@link 800 * wp_list_pages()} function. Check that function for more info on those 801 * arguments. 802 * 803 * <ul> 804 * <li><strong>sort_column</strong> - How to sort the list of pages. Defaults 805 * to page title. Use column for posts table.</li> 806 * <li><strong>menu_class</strong> - Class to use for the div ID which contains 807 * the page list. Defaults to 'menu'.</li> 808 * <li><strong>echo</strong> - Whether to echo list or return it. Defaults to 809 * echo.</li> 810 * <li><strong>link_before</strong> - Text before show_home argument text.</li> 811 * <li><strong>link_after</strong> - Text after show_home argument text.</li> 812 * <li><strong>show_home</strong> - If you set this argument, then it will 813 * display the link to the home page. The show_home argument really just needs 814 * to be set to the value of the text of the link.</li> 815 * </ul> 816 * 817 * @since 2.7.0 818 * 819 * @param array|string $args 820 */ 821 function wp_page_menu( $args = array() ) { 822 $defaults = array('sort_column' => 'menu_order, post_title', 'menu_class' => 'menu', 'echo' => true, 'link_before' => '', 'link_after' => ''); 823 $args = wp_parse_args( $args, $defaults ); 824 $args = apply_filters( 'wp_page_menu_args', $args ); 825 826 $menu = ''; 827 828 $list_args = $args; 829 830 // Show Home in the menu 831 if ( isset($args['show_home']) && ! empty($args['show_home']) ) { 832 if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] ) 833 $text = __('Home'); 834 else 835 $text = $args['show_home']; 836 $class = ''; 837 if ( is_front_page() && !is_paged() ) 838 $class = 'class="current_page_item"'; 839 $menu .= '<li ' . $class . '><a href="' . home_url() . '" title="' . esc_attr($text) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>'; 840 // If the front page is a page, add it to the exclude list 841 if (get_option('show_on_front') == 'page') { 842 if ( !empty( $list_args['exclude'] ) ) { 843 $list_args['exclude'] .= ','; 844 } else { 845 $list_args['exclude'] = ''; 846 } 847 $list_args['exclude'] .= get_option('page_on_front'); 848 } 849 } 850 851 $list_args['echo'] = false; 852 $list_args['title_li'] = ''; 853 $menu .= str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages($list_args) ); 854 855 if ( $menu ) 856 $menu = '<ul>' . $menu . '</ul>'; 857 858 $menu = '<div class="' . esc_attr($args['menu_class']) . '">' . $menu . "</div>\n"; 859 $menu = apply_filters( 'wp_page_menu', $menu, $args ); 860 if ( $args['echo'] ) 861 echo $menu; 862 else 863 return $menu; 864 } 865 866 // 867 // Page helpers 868 // 869 870 /** 871 * Retrieve HTML list content for page list. 872 * 873 * @uses Walker_Page to create HTML list content. 874 * @since 2.1.0 875 * @see Walker_Page::walk() for parameters and return description. 876 */ 877 function walk_page_tree($pages, $depth, $current_page, $r) { 878 if ( empty($r['walker']) ) 879 $walker = new Walker_Page; 880 else 881 $walker = $r['walker']; 882 883 $args = array($pages, $depth, $r, $current_page); 884 return call_user_func_array(array(&$walker, 'walk'), $args); 885 } 886 887 /** 888 * Retrieve HTML dropdown (select) content for page list. 889 * 890 * @uses Walker_PageDropdown to create HTML dropdown content. 891 * @since 2.1.0 892 * @see Walker_PageDropdown::walk() for parameters and return description. 893 */ 894 function walk_page_dropdown_tree() { 895 $args = func_get_args(); 896 if ( empty($args[2]['walker']) ) // the user's options are the third parameter 897 $walker = new Walker_PageDropdown; 898 else 899 $walker = $args[2]['walker']; 900 901 return call_user_func_array(array(&$walker, 'walk'), $args); 902 } 903 904 // 905 // Attachments 906 // 907 908 /** 909 * Display an attachment page link using an image or icon. 910 * 911 * @since 2.0.0 912 * 913 * @param int $id Optional. Post ID. 914 * @param bool $fullsize Optional, default is false. Whether to use full size. 915 * @param bool $deprecated Deprecated. Not used. 916 * @param bool $permalink Optional, default is false. Whether to include permalink. 917 */ 918 function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) { 919 if ( !empty( $deprecated ) ) 920 _deprecated_argument( __FUNCTION__, '2.5' ); 921 922 if ( $fullsize ) 923 echo wp_get_attachment_link($id, 'full', $permalink); 924 else 925 echo wp_get_attachment_link($id, 'thumbnail', $permalink); 926 } 927 928 /** 929 * Retrieve an attachment page link using an image or icon, if possible. 930 * 931 * @since 2.5.0 932 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function. 933 * 934 * @param int $id Optional. Post ID. 935 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string. 936 * @param bool $permalink Optional, default is false. Whether to add permalink to image. 937 * @param bool $icon Optional, default is false. Whether to include icon. 938 * @param string $text Optional, default is false. If string, then will be link text. 939 * @return string HTML content. 940 */ 941 function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false) { 942 $id = intval($id); 943 $_post = & get_post( $id ); 944 945 if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url($_post->ID) ) 946 return __('Missing Attachment'); 947 948 if ( $permalink ) 949 $url = get_attachment_link($_post->ID); 950 951 $post_title = esc_attr($_post->post_title); 952 953 if ( $text ) { 954 $link_text = esc_attr($text); 955 } elseif ( ( is_int($size) && $size != 0 ) or ( is_string($size) && $size != 'none' ) or $size != false ) { 956 $link_text = wp_get_attachment_image($id, $size, $icon); 957 } else { 958 $link_text = ''; 959 } 960 961 if( trim($link_text) == '' ) 962 $link_text = $_post->post_title; 963 964 return apply_filters( 'wp_get_attachment_link', "<a href='$url' title='$post_title'>$link_text</a>", $id, $size, $permalink, $icon, $text ); 965 } 966 967 /** 968 * Wrap attachment in <<p>> element before content. 969 * 970 * @since 2.0.0 971 * @uses apply_filters() Calls 'prepend_attachment' hook on HTML content. 972 * 973 * @param string $content 974 * @return string 975 */ 976 function prepend_attachment($content) { 977 global $post; 978 979 if ( empty($post->post_type) || $post->post_type != 'attachment' ) 980 return $content; 981 982 $p = '<p class="attachment">'; 983 // show the medium sized image representation of the attachment if available, and link to the raw file 984 $p .= wp_get_attachment_link(0, 'medium', false); 985 $p .= '</p>'; 986 $p = apply_filters('prepend_attachment', $p); 987 988 return "$p\n$content"; 989 } 990 991 // 992 // Misc 993 // 994 995 /** 996 * Retrieve protected post password form content. 997 * 998 * @since 1.0.0 999 * @uses apply_filters() Calls 'the_password_form' filter on output. 1000 * 1001 * @return string HTML content for password form for password protected post. 1002 */ 1003 function get_the_password_form() { 1004 global $post; 1005 $label = 'pwbox-'.(empty($post->ID) ? rand() : $post->ID); 1006 $output = '<form action="' . get_option('siteurl') . '/wp-pass.php" method="post"> 1007 <p>' . __("This post is password protected. To view it please enter your password below:") . '</p> 1008 <p><label for="' . $label . '">' . __("Password:") . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr__("Submit") . '" /></p> 1009 </form> 1010 '; 1011 return apply_filters('the_password_form', $output); 1012 } 1013 1014 /** 1015 * Whether currently in a page template. 1016 * 1017 * This template tag allows you to determine if you are in a page template. 1018 * You can optionally provide a template name and then the check will be 1019 * specific to that template. 1020 * 1021 * @since 2.5.0 1022 * @uses $wp_query 1023 * 1024 * @param string $template The specific template name if specific matching is required. 1025 * @return bool False on failure, true if success. 1026 */ 1027 function is_page_template($template = '') { 1028 if (!is_page()) { 1029 return false; 1030 } 1031 1032 global $wp_query; 1033 1034 $page = $wp_query->get_queried_object(); 1035 $custom_fields = get_post_custom_values('_wp_page_template',$page->ID); 1036 $page_template = $custom_fields[0]; 1037 1038 // We have no argument passed so just see if a page_template has been specified 1039 if ( empty( $template ) ) { 1040 if (!empty( $page_template ) ) { 1041 return true; 1042 } 1043 } elseif ( $template == $page_template) { 1044 return true; 1045 } 1046 1047 return false; 1048 } 1049 1050 /** 1051 * Retrieve formatted date timestamp of a revision (linked to that revisions's page). 1052 * 1053 * @package WordPress 1054 * @subpackage Post_Revisions 1055 * @since 2.6.0 1056 * 1057 * @uses date_i18n() 1058 * 1059 * @param int|object $revision Revision ID or revision object. 1060 * @param bool $link Optional, default is true. Link to revisions's page? 1061 * @return string i18n formatted datetimestamp or localized 'Current Revision'. 1062 */ 1063 function wp_post_revision_title( $revision, $link = true ) { 1064 if ( !$revision = get_post( $revision ) ) 1065 return $revision; 1066 1067 if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) 1068 return false; 1069 1070 /* translators: revision date format, see http://php.net/date */ 1071 $datef = _x( 'j F, Y @ G:i', 'revision date format'); 1072 /* translators: 1: date */ 1073 $autosavef = __( '%1$s [Autosave]' ); 1074 /* translators: 1: date */ 1075 $currentf = __( '%1$s [Current Revision]' ); 1076 1077 $date = date_i18n( $datef, strtotime( $revision->post_modified ) ); 1078 if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) 1079 $date = "<a href='$link'>$date</a>"; 1080 1081 if ( !wp_is_post_revision( $revision ) ) 1082 $date = sprintf( $currentf, $date ); 1083 elseif ( wp_is_post_autosave( $revision ) ) 1084 $date = sprintf( $autosavef, $date ); 1085 1086 return $date; 1087 } 1088 1089 /** 1090 * Display list of a post's revisions. 1091 * 1092 * Can output either a UL with edit links or a TABLE with diff interface, and 1093 * restore action links. 1094 * 1095 * Second argument controls parameters: 1096 * (bool) parent : include the parent (the "Current Revision") in the list. 1097 * (string) format : 'list' or 'form-table'. 'list' outputs UL, 'form-table' 1098 * outputs TABLE with UI. 1099 * (int) right : what revision is currently being viewed - used in 1100 * form-table format. 1101 * (int) left : what revision is currently being diffed against right - 1102 * used in form-table format. 1103 * 1104 * @package WordPress 1105 * @subpackage Post_Revisions 1106 * @since 2.6.0 1107 * 1108 * @uses wp_get_post_revisions() 1109 * @uses wp_post_revision_title() 1110 * @uses get_edit_post_link() 1111 * @uses get_the_author_meta() 1112 * 1113 * @todo split into two functions (list, form-table) ? 1114 * 1115 * @param int|object $post_id Post ID or post object. 1116 * @param string|array $args See description {@link wp_parse_args()}. 1117 * @return null 1118 */ 1119 function wp_list_post_revisions( $post_id = 0, $args = null ) { 1120 if ( !$post = get_post( $post_id ) ) 1121 return; 1122 1123 $defaults = array( 'parent' => false, 'right' => false, 'left' => false, 'format' => 'list', 'type' => 'all' ); 1124 extract( wp_parse_args( $args, $defaults ), EXTR_SKIP ); 1125 1126 switch ( $type ) { 1127 case 'autosave' : 1128 if ( !$autosave = wp_get_post_autosave( $post->ID ) ) 1129 return; 1130 $revisions = array( $autosave ); 1131 break; 1132 case 'revision' : // just revisions - remove autosave later 1133 case 'all' : 1134 default : 1135 if ( !$revisions = wp_get_post_revisions( $post->ID ) ) 1136 return; 1137 break; 1138 } 1139 1140 /* translators: post revision: 1: when, 2: author name */ 1141 $titlef = _x( '%1$s by %2$s', 'post revision' ); 1142 1143 if ( $parent ) 1144 array_unshift( $revisions, $post ); 1145 1146 $rows = ''; 1147 $class = false; 1148 $can_edit_post = current_user_can( 'edit_post', $post->ID ); 1149 foreach ( $revisions as $revision ) { 1150 if ( !current_user_can( 'read_post', $revision->ID ) ) 1151 continue; 1152 if ( 'revision' === $type && wp_is_post_autosave( $revision ) ) 1153 continue; 1154 1155 $date = wp_post_revision_title( $revision ); 1156 $name = get_the_author_meta( 'display_name', $revision->post_author ); 1157 1158 if ( 'form-table' == $format ) { 1159 if ( $left ) 1160 $left_checked = $left == $revision->ID ? ' checked="checked"' : ''; 1161 else 1162 $left_checked = $right_checked ? ' checked="checked"' : ''; // [sic] (the next one) 1163 $right_checked = $right == $revision->ID ? ' checked="checked"' : ''; 1164 1165 $class = $class ? '' : " class='alternate'"; 1166 1167 if ( $post->ID != $revision->ID && $can_edit_post ) 1168 $actions = '<a href="' . wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'diff' => false, 'action' => 'restore' ) ), "restore-post_$post->ID|$revision->ID" ) . '">' . __( 'Restore' ) . '</a>'; 1169 else 1170 $actions = ''; 1171 1172 $rows .= "<tr$class>\n"; 1173 $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='left' value='$revision->ID'$left_checked />\n"; 1174 $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='right' value='$revision->ID'$right_checked /></th>\n"; 1175 $rows .= "\t<td>$date</td>\n"; 1176 $rows .= "\t<td>$name</td>\n"; 1177 $rows .= "\t<td class='action-links'>$actions</td>\n"; 1178 $rows .= "</tr>\n"; 1179 } else { 1180 $title = sprintf( $titlef, $date, $name ); 1181 $rows .= "\t<li>$title</li>\n"; 1182 } 1183 } 1184 1185 if ( 'form-table' == $format ) : ?> 1186 1187 <form action="revision.php" method="get"> 1188 1189 <div class="tablenav"> 1190 <div class="alignleft"> 1191 <input type="submit" class="button-secondary" value="<?php esc_attr_e( 'Compare Revisions' ); ?>" /> 1192 <input type="hidden" name="action" value="diff" /> 1193 <input type="hidden" name="post_type" value="<?php echo esc_attr($GLOBALS['post_type']); ?>" /> 1194 </div> 1195 </div> 1196 1197 <br class="clear" /> 1198 1199 <table class="widefat post-revisions" cellspacing="0" id="post-revisions"> 1200 <col /> 1201 <col /> 1202 <col style="width: 33%" /> 1203 <col style="width: 33%" /> 1204 <col style="width: 33%" /> 1205 <thead> 1206 <tr> 1207 <th scope="col"><?php _e( 'Old' ); ?></th> 1208 <th scope="col"><?php _e( 'New' ); ?></th> 1209 <th scope="col"><?php _e( 'Date Created' ); ?></th> 1210 <th scope="col"><?php _e( 'Author' ); ?></th> 1211 <th scope="col" class="action-links"><?php _e( 'Actions' ); ?></th> 1212 </tr> 1213 </thead> 1214 <tbody> 1215 1216 <?php echo $rows; ?> 1217 1218 </tbody> 1219 </table> 1220 1221 </form> 1222 1223 <?php 1224 else : 1225 echo "<ul class='post-revisions'>\n"; 1226 echo $rows; 1227 echo "</ul>"; 1228 endif; 1229 1230 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri Mar 19 21:30:06 2010 | Cross-referenced by PHPXref 0.7 |