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