[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

title

Body

[close]

/wp-includes/ -> post-template.php (source)

   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   */
  16  function the_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
  17      echo get_the_ID();
  18  }
  19  
  20  /**
  21   * Retrieve the ID of the current item in the WordPress Loop.
  22   *
  23   * @since 2.1.0
  24   *
  25   * @return int|false The ID of the current item in the WordPress Loop. False if $post is not set.
  26   */
  27  function get_the_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
  28      $post = get_post();
  29      return ! empty( $post ) ? $post->ID : false;
  30  }
  31  
  32  /**
  33   * Display or retrieve the current post title with optional markup.
  34   *
  35   * @since 0.71
  36   *
  37   * @param string $before Optional. Markup to prepend to the title. Default empty.
  38   * @param string $after  Optional. Markup to append to the title. Default empty.
  39   * @param bool   $echo   Optional. Whether to echo or return the title. Default true for echo.
  40   * @return string|void Current post title if $echo is false.
  41   */
  42  function the_title( $before = '', $after = '', $echo = true ) {
  43      $title = get_the_title();
  44  
  45      if ( strlen( $title ) == 0 ) {
  46          return;
  47      }
  48  
  49      $title = $before . $title . $after;
  50  
  51      if ( $echo ) {
  52          echo $title;
  53      } else {
  54          return $title;
  55      }
  56  }
  57  
  58  /**
  59   * Sanitize the current title when retrieving or displaying.
  60   *
  61   * Works like the_title(), except the parameters can be in a string or
  62   * an array. See the function for what can be override in the $args parameter.
  63   *
  64   * The title before it is displayed will have the tags stripped and esc_attr()
  65   * before it is passed to the user or displayed. The default as with the_title(),
  66   * is to display the title.
  67   *
  68   * @since 2.3.0
  69   *
  70   * @param string|array $args {
  71   *     Title attribute arguments. Optional.
  72   *
  73   *     @type string  $before Markup to prepend to the title. Default empty.
  74   *     @type string  $after  Markup to append to the title. Default empty.
  75   *     @type bool    $echo   Whether to echo or return the title. Default true for echo.
  76   *     @type WP_Post $post   Current post object to retrieve the title for.
  77   * }
  78   * @return string|void String when echo is false.
  79   */
  80  function the_title_attribute( $args = '' ) {
  81      $defaults    = array(
  82          'before' => '',
  83          'after'  => '',
  84          'echo'   => true,
  85          'post'   => get_post(),
  86      );
  87      $parsed_args = wp_parse_args( $args, $defaults );
  88  
  89      $title = get_the_title( $parsed_args['post'] );
  90  
  91      if ( strlen( $title ) == 0 ) {
  92          return;
  93      }
  94  
  95      $title = $parsed_args['before'] . $title . $parsed_args['after'];
  96      $title = esc_attr( strip_tags( $title ) );
  97  
  98      if ( $parsed_args['echo'] ) {
  99          echo $title;
 100      } else {
 101          return $title;
 102      }
 103  }
 104  
 105  /**
 106   * Retrieve post title.
 107   *
 108   * If the post is protected and the visitor is not an admin, then "Protected"
 109   * will be displayed before the post title. If the post is private, then
 110   * "Private" will be located before the post title.
 111   *
 112   * @since 0.71
 113   *
 114   * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 115   * @return string
 116   */
 117  function get_the_title( $post = 0 ) {
 118      $post = get_post( $post );
 119  
 120      $title = isset( $post->post_title ) ? $post->post_title : '';
 121      $id    = isset( $post->ID ) ? $post->ID : 0;
 122  
 123      if ( ! is_admin() ) {
 124          if ( ! empty( $post->post_password ) ) {
 125  
 126              /* translators: %s: Protected post title. */
 127              $prepend = __( 'Protected: %s' );
 128  
 129              /**
 130               * Filters the text prepended to the post title for protected posts.
 131               *
 132               * The filter is only applied on the front end.
 133               *
 134               * @since 2.8.0
 135               *
 136               * @param string  $prepend Text displayed before the post title.
 137               *                         Default 'Protected: %s'.
 138               * @param WP_Post $post    Current post object.
 139               */
 140              $protected_title_format = apply_filters( 'protected_title_format', $prepend, $post );
 141              $title                  = sprintf( $protected_title_format, $title );
 142          } elseif ( isset( $post->post_status ) && 'private' == $post->post_status ) {
 143  
 144              /* translators: %s: Private post title. */
 145              $prepend = __( 'Private: %s' );
 146  
 147              /**
 148               * Filters the text prepended to the post title of private posts.
 149               *
 150               * The filter is only applied on the front end.
 151               *
 152               * @since 2.8.0
 153               *
 154               * @param string  $prepend Text displayed before the post title.
 155               *                         Default 'Private: %s'.
 156               * @param WP_Post $post    Current post object.
 157               */
 158              $private_title_format = apply_filters( 'private_title_format', $prepend, $post );
 159              $title                = sprintf( $private_title_format, $title );
 160          }
 161      }
 162  
 163      /**
 164       * Filters the post title.
 165       *
 166       * @since 0.71
 167       *
 168       * @param string $title The post title.
 169       * @param int    $id    The post ID.
 170       */
 171      return apply_filters( 'the_title', $title, $id );
 172  }
 173  
 174  /**
 175   * Display the Post Global Unique Identifier (guid).
 176   *
 177   * The guid will appear to be a link, but should not be used as a link to the
 178   * post. The reason you should not use it as a link, is because of moving the
 179   * blog across domains.
 180   *
 181   * URL is escaped to make it XML-safe.
 182   *
 183   * @since 1.5.0
 184   *
 185   * @param int|WP_Post $post Optional. Post ID or post object. Default is global $post.
 186   */
 187  function the_guid( $post = 0 ) {
 188      $post = get_post( $post );
 189  
 190      $guid = isset( $post->guid ) ? get_the_guid( $post ) : '';
 191      $id   = isset( $post->ID ) ? $post->ID : 0;
 192  
 193      /**
 194       * Filters the escaped Global Unique Identifier (guid) of the post.
 195       *
 196       * @since 4.2.0
 197       *
 198       * @see get_the_guid()
 199       *
 200       * @param string $guid Escaped Global Unique Identifier (guid) of the post.
 201       * @param int    $id   The post ID.
 202       */
 203      echo apply_filters( 'the_guid', $guid, $id );
 204  }
 205  
 206  /**
 207   * Retrieve the Post Global Unique Identifier (guid).
 208   *
 209   * The guid will appear to be a link, but should not be used as an link to the
 210   * post. The reason you should not use it as a link, is because of moving the
 211   * blog across domains.
 212   *
 213   * @since 1.5.0
 214   *
 215   * @param int|WP_Post $post Optional. Post ID or post object. Default is global $post.
 216   * @return string
 217   */
 218  function get_the_guid( $post = 0 ) {
 219      $post = get_post( $post );
 220  
 221      $guid = isset( $post->guid ) ? $post->guid : '';
 222      $id   = isset( $post->ID ) ? $post->ID : 0;
 223  
 224      /**
 225       * Filters the Global Unique Identifier (guid) of the post.
 226       *
 227       * @since 1.5.0
 228       *
 229       * @param string $guid Global Unique Identifier (guid) of the post.
 230       * @param int    $id   The post ID.
 231       */
 232      return apply_filters( 'get_the_guid', $guid, $id );
 233  }
 234  
 235  /**
 236   * Display the post content.
 237   *
 238   * @since 0.71
 239   *
 240   * @param string $more_link_text Optional. Content for when there is more text.
 241   * @param bool   $strip_teaser   Optional. Strip teaser content before the more text. Default is false.
 242   */
 243  function the_content( $more_link_text = null, $strip_teaser = false ) {
 244      $content = get_the_content( $more_link_text, $strip_teaser );
 245  
 246      /**
 247       * Filters the post content.
 248       *
 249       * @since 0.71
 250       *
 251       * @param string $content Content of the current post.
 252       */
 253      $content = apply_filters( 'the_content', $content );
 254      $content = str_replace( ']]>', ']]&gt;', $content );
 255      echo $content;
 256  }
 257  
 258  /**
 259   * Retrieve the post content.
 260   *
 261   * @since 0.71
 262   * @since 5.2.0 Added the `$post` parameter.
 263   *
 264   * @global int   $page      Page number of a single post/page.
 265   * @global int   $more      Boolean indicator for whether single post/page is being viewed.
 266   * @global bool  $preview   Whether post/page is in preview mode.
 267   * @global array $pages     Array of all pages in post/page. Each array element contains
 268   *                          part of the content separated by the `<!--nextpage-->` tag.
 269   * @global int   $multipage Boolean indicator for whether multiple pages are in play.
 270   *
 271   * @param string             $more_link_text Optional. Content for when there is more text.
 272   * @param bool               $strip_teaser   Optional. Strip teaser content before the more text. Default is false.
 273   * @param WP_Post|object|int $post           Optional. WP_Post instance or Post ID/object. Default is null.
 274   * @return string
 275   */
 276  function get_the_content( $more_link_text = null, $strip_teaser = false, $post = null ) {
 277      global $page, $more, $preview, $pages, $multipage;
 278  
 279      $_post = get_post( $post );
 280  
 281      if ( ! ( $_post instanceof WP_Post ) ) {
 282          return '';
 283      }
 284  
 285      if ( null === $post ) {
 286          $elements = compact( 'page', 'more', 'preview', 'pages', 'multipage' );
 287      } else {
 288          $elements = generate_postdata( $_post );
 289      }
 290  
 291      if ( null === $more_link_text ) {
 292          $more_link_text = sprintf(
 293              '<span aria-label="%1$s">%2$s</span>',
 294              sprintf(
 295                  /* translators: %s: Post title. */
 296                  __( 'Continue reading %s' ),
 297                  the_title_attribute(
 298                      array(
 299                          'echo' => false,
 300                          'post' => $_post,
 301                      )
 302                  )
 303              ),
 304              __( '(more&hellip;)' )
 305          );
 306      }
 307  
 308      $output     = '';
 309      $has_teaser = false;
 310  
 311      // If post password required and it doesn't match the cookie.
 312      if ( post_password_required( $_post ) ) {
 313          return get_the_password_form( $_post );
 314      }
 315  
 316      if ( $elements['page'] > count( $elements['pages'] ) ) { // if the requested page doesn't exist
 317          $elements['page'] = count( $elements['pages'] ); // give them the highest numbered page that DOES exist
 318      }
 319  
 320      $page_no = $elements['page'];
 321      $content = $elements['pages'][ $page_no - 1 ];
 322      if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
 323          if ( has_block( 'more', $content ) ) {
 324              // Remove the core/more block delimiters. They will be left over after $content is split up.
 325              $content = preg_replace( '/<!-- \/?wp:more(.*?) -->/', '', $content );
 326          }
 327  
 328          $content = explode( $matches[0], $content, 2 );
 329  
 330          if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) {
 331              $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
 332          }
 333  
 334          $has_teaser = true;
 335      } else {
 336          $content = array( $content );
 337      }
 338  
 339      if ( false !== strpos( $_post->post_content, '<!--noteaser-->' ) && ( ! $elements['multipage'] || $elements['page'] == 1 ) ) {
 340          $strip_teaser = true;
 341      }
 342  
 343      $teaser = $content[0];
 344  
 345      if ( $elements['more'] && $strip_teaser && $has_teaser ) {
 346          $teaser = '';
 347      }
 348  
 349      $output .= $teaser;
 350  
 351      if ( count( $content ) > 1 ) {
 352          if ( $elements['more'] ) {
 353              $output .= '<span id="more-' . $_post->ID . '"></span>' . $content[1];
 354          } else {
 355              if ( ! empty( $more_link_text ) ) {
 356  
 357                  /**
 358                   * Filters the Read More link text.
 359                   *
 360                   * @since 2.8.0
 361                   *
 362                   * @param string $more_link_element Read More link element.
 363                   * @param string $more_link_text    Read More text.
 364                   */
 365                  $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink( $_post ) . "#more-{$_post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
 366              }
 367              $output = force_balance_tags( $output );
 368          }
 369      }
 370  
 371      return $output;
 372  }
 373  
 374  /**
 375   * Display the post excerpt.
 376   *
 377   * @since 0.71
 378   */
 379  function the_excerpt() {
 380  
 381      /**
 382       * Filters the displayed post excerpt.
 383       *
 384       * @since 0.71
 385       *
 386       * @see get_the_excerpt()
 387       *
 388       * @param string $post_excerpt The post excerpt.
 389       */
 390      echo apply_filters( 'the_excerpt', get_the_excerpt() );
 391  }
 392  
 393  /**
 394   * Retrieves the post excerpt.
 395   *
 396   * @since 0.71
 397   * @since 4.5.0 Introduced the `$post` parameter.
 398   *
 399   * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 400   * @return string Post excerpt.
 401   */
 402  function get_the_excerpt( $post = null ) {
 403      if ( is_bool( $post ) ) {
 404          _deprecated_argument( __FUNCTION__, '2.3.0' );
 405      }
 406  
 407      $post = get_post( $post );
 408      if ( empty( $post ) ) {
 409          return '';
 410      }
 411  
 412      if ( post_password_required( $post ) ) {
 413          return __( 'There is no excerpt because this is a protected post.' );
 414      }
 415  
 416      /**
 417       * Filters the retrieved post excerpt.
 418       *
 419       * @since 1.2.0
 420       * @since 4.5.0 Introduced the `$post` parameter.
 421       *
 422       * @param string $post_excerpt The post excerpt.
 423       * @param WP_Post $post Post object.
 424       */
 425      return apply_filters( 'get_the_excerpt', $post->post_excerpt, $post );
 426  }
 427  
 428  /**
 429   * Determines whether the post has a custom excerpt.
 430   *
 431   * For more information on this and similar theme functions, check out
 432   * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
 433   * Conditional Tags} article in the Theme Developer Handbook.
 434   *
 435   * @since 2.3.0
 436   *
 437   * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 438   * @return bool True if the post has a custom excerpt, false otherwise.
 439   */
 440  function has_excerpt( $post = 0 ) {
 441      $post = get_post( $post );
 442      return ( ! empty( $post->post_excerpt ) );
 443  }
 444  
 445  /**
 446   * Displays the classes for the post container element.
 447   *
 448   * @since 2.7.0
 449   *
 450   * @param string|array $class   One or more classes to add to the class list.
 451   * @param int|WP_Post  $post_id Optional. Post ID or post object. Defaults to the global `$post`.
 452   */
 453  function post_class( $class = '', $post_id = null ) {
 454      // Separates classes with a single space, collates classes for post DIV
 455      echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"';
 456  }
 457  
 458  /**
 459   * Retrieves an array of the class names for the post container element.
 460   *
 461   * The class names are many. If the post is a sticky, then the 'sticky'
 462   * class name. The class 'hentry' is always added to each post. If the post has a
 463   * post thumbnail, 'has-post-thumbnail' is added as a class. For each taxonomy that
 464   * the post belongs to, a class will be added of the format '{$taxonomy}-{$slug}' -
 465   * eg 'category-foo' or 'my_custom_taxonomy-bar'.
 466   *
 467   * The 'post_tag' taxonomy is a special
 468   * case; the class has the 'tag-' prefix instead of 'post_tag-'. All class names are
 469   * passed through the filter, {@see 'post_class'}, with the list of class names, followed by
 470   * $class parameter value, with the post ID as the last parameter.
 471   *
 472   * @since 2.7.0
 473   * @since 4.2.0 Custom taxonomy class names were added.
 474   *
 475   * @param string|string[] $class   Space-separated string or array of class names to add to the class list.
 476   * @param int|WP_Post     $post_id Optional. Post ID or post object.
 477   * @return string[] Array of class names.
 478   */
 479  function get_post_class( $class = '', $post_id = null ) {
 480      $post = get_post( $post_id );
 481  
 482      $classes = array();
 483  
 484      if ( $class ) {
 485          if ( ! is_array( $class ) ) {
 486              $class = preg_split( '#\s+#', $class );
 487          }
 488          $classes = array_map( 'esc_attr', $class );
 489      } else {
 490          // Ensure that we always coerce class to being an array.
 491          $class = array();
 492      }
 493  
 494      if ( ! $post ) {
 495          return $classes;
 496      }
 497  
 498      $classes[] = 'post-' . $post->ID;
 499      if ( ! is_admin() ) {
 500          $classes[] = $post->post_type;
 501      }
 502      $classes[] = 'type-' . $post->post_type;
 503      $classes[] = 'status-' . $post->post_status;
 504  
 505      // Post Format
 506      if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
 507          $post_format = get_post_format( $post->ID );
 508  
 509          if ( $post_format && ! is_wp_error( $post_format ) ) {
 510              $classes[] = 'format-' . sanitize_html_class( $post_format );
 511          } else {
 512              $classes[] = 'format-standard';
 513          }
 514      }
 515  
 516      $post_password_required = post_password_required( $post->ID );
 517  
 518      // Post requires password.
 519      if ( $post_password_required ) {
 520          $classes[] = 'post-password-required';
 521      } elseif ( ! empty( $post->post_password ) ) {
 522          $classes[] = 'post-password-protected';
 523      }
 524  
 525      // Post thumbnails.
 526      if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) && ! is_attachment( $post ) && ! $post_password_required ) {
 527          $classes[] = 'has-post-thumbnail';
 528      }
 529  
 530      // sticky for Sticky Posts
 531      if ( is_sticky( $post->ID ) ) {
 532          if ( is_home() && ! is_paged() ) {
 533              $classes[] = 'sticky';
 534          } elseif ( is_admin() ) {
 535              $classes[] = 'status-sticky';
 536          }
 537      }
 538  
 539      // hentry for hAtom compliance
 540      $classes[] = 'hentry';
 541  
 542      // All public taxonomies
 543      $taxonomies = get_taxonomies( array( 'public' => true ) );
 544      foreach ( (array) $taxonomies as $taxonomy ) {
 545          if ( is_object_in_taxonomy( $post->post_type, $taxonomy ) ) {
 546              foreach ( (array) get_the_terms( $post->ID, $taxonomy ) as $term ) {
 547                  if ( empty( $term->slug ) ) {
 548                      continue;
 549                  }
 550  
 551                  $term_class = sanitize_html_class( $term->slug, $term->term_id );
 552                  if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) {
 553                      $term_class = $term->term_id;
 554                  }
 555  
 556                  // 'post_tag' uses the 'tag' prefix for backward compatibility.
 557                  if ( 'post_tag' == $taxonomy ) {
 558                      $classes[] = 'tag-' . $term_class;
 559                  } else {
 560                      $classes[] = sanitize_html_class( $taxonomy . '-' . $term_class, $taxonomy . '-' . $term->term_id );
 561                  }
 562              }
 563          }
 564      }
 565  
 566      $classes = array_map( 'esc_attr', $classes );
 567  
 568      /**
 569       * Filters the list of CSS class names for the current post.
 570       *
 571       * @since 2.7.0
 572       *
 573       * @param string[] $classes An array of post class names.
 574       * @param string[] $class   An array of additional class names added to the post.
 575       * @param int      $post_id The post ID.
 576       */
 577      $classes = apply_filters( 'post_class', $classes, $class, $post->ID );
 578  
 579      return array_unique( $classes );
 580  }
 581  
 582  /**
 583   * Displays the class names for the body element.
 584   *
 585   * @since 2.8.0
 586   *
 587   * @param string|string[] $class Space-separated string or array of class names to add to the class list.
 588   */
 589  function body_class( $class = '' ) {
 590      // Separates class names with a single space, collates class names for body element
 591      echo 'class="' . join( ' ', get_body_class( $class ) ) . '"';
 592  }
 593  
 594  /**
 595   * Retrieves an array of the class names for the body element.
 596   *
 597   * @since 2.8.0
 598   *
 599   * @global WP_Query $wp_query WordPress Query object.
 600   *
 601   * @param string|string[] $class Space-separated string or array of class names to add to the class list.
 602   * @return string[] Array of class names.
 603   */
 604  function get_body_class( $class = '' ) {
 605      global $wp_query;
 606  
 607      $classes = array();
 608  
 609      if ( is_rtl() ) {
 610          $classes[] = 'rtl';
 611      }
 612  
 613      if ( is_front_page() ) {
 614          $classes[] = 'home';
 615      }
 616      if ( is_home() ) {
 617          $classes[] = 'blog';
 618      }
 619      if ( is_privacy_policy() ) {
 620          $classes[] = 'privacy-policy';
 621      }
 622      if ( is_archive() ) {
 623          $classes[] = 'archive';
 624      }
 625      if ( is_date() ) {
 626          $classes[] = 'date';
 627      }
 628      if ( is_search() ) {
 629          $classes[] = 'search';
 630          $classes[] = $wp_query->posts ? 'search-results' : 'search-no-results';
 631      }
 632      if ( is_paged() ) {
 633          $classes[] = 'paged';
 634      }
 635      if ( is_attachment() ) {
 636          $classes[] = 'attachment';
 637      }
 638      if ( is_404() ) {
 639          $classes[] = 'error404';
 640      }
 641  
 642      if ( is_singular() ) {
 643          $post_id   = $wp_query->get_queried_object_id();
 644          $post      = $wp_query->get_queried_object();
 645          $post_type = $post->post_type;
 646  
 647          if ( is_page_template() ) {
 648              $classes[] = "{$post_type}-template";
 649  
 650              $template_slug  = get_page_template_slug( $post_id );
 651              $template_parts = explode( '/', $template_slug );
 652  
 653              foreach ( $template_parts as $part ) {
 654                  $classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace( array( '.', '/' ), '-', basename( $part, '.php' ) ) );
 655              }
 656              $classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace( '.', '-', $template_slug ) );
 657          } else {
 658              $classes[] = "{$post_type}-template-default";
 659          }
 660  
 661          if ( is_single() ) {
 662              $classes[] = 'single';
 663              if ( isset( $post->post_type ) ) {
 664                  $classes[] = 'single-' . sanitize_html_class( $post->post_type, $post_id );
 665                  $classes[] = 'postid-' . $post_id;
 666  
 667                  // Post Format
 668                  if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
 669                      $post_format = get_post_format( $post->ID );
 670  
 671                      if ( $post_format && ! is_wp_error( $post_format ) ) {
 672                          $classes[] = 'single-format-' . sanitize_html_class( $post_format );
 673                      } else {
 674                          $classes[] = 'single-format-standard';
 675                      }
 676                  }
 677              }
 678          }
 679  
 680          if ( is_attachment() ) {
 681              $mime_type   = get_post_mime_type( $post_id );
 682              $mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
 683              $classes[]   = 'attachmentid-' . $post_id;
 684              $classes[]   = 'attachment-' . str_replace( $mime_prefix, '', $mime_type );
 685          } elseif ( is_page() ) {
 686              $classes[] = 'page';
 687  
 688              $page_id = $wp_query->get_queried_object_id();
 689  
 690              $post = get_post( $page_id );
 691  
 692              $classes[] = 'page-id-' . $page_id;
 693  
 694              if ( get_pages(
 695                  array(
 696                      'parent' => $page_id,
 697                      'number' => 1,
 698                  )
 699              ) ) {
 700                  $classes[] = 'page-parent';
 701              }
 702  
 703              if ( $post->post_parent ) {
 704                  $classes[] = 'page-child';
 705                  $classes[] = 'parent-pageid-' . $post->post_parent;
 706              }
 707          }
 708      } elseif ( is_archive() ) {
 709          if ( is_post_type_archive() ) {
 710              $classes[] = 'post-type-archive';
 711              $post_type = get_query_var( 'post_type' );
 712              if ( is_array( $post_type ) ) {
 713                  $post_type = reset( $post_type );
 714              }
 715              $classes[] = 'post-type-archive-' . sanitize_html_class( $post_type );
 716          } elseif ( is_author() ) {
 717              $author    = $wp_query->get_queried_object();
 718              $classes[] = 'author';
 719              if ( isset( $author->user_nicename ) ) {
 720                  $classes[] = 'author-' . sanitize_html_class( $author->user_nicename, $author->ID );
 721                  $classes[] = 'author-' . $author->ID;
 722              }
 723          } elseif ( is_category() ) {
 724              $cat       = $wp_query->get_queried_object();
 725              $classes[] = 'category';
 726              if ( isset( $cat->term_id ) ) {
 727                  $cat_class = sanitize_html_class( $cat->slug, $cat->term_id );
 728                  if ( is_numeric( $cat_class ) || ! trim( $cat_class, '-' ) ) {
 729                      $cat_class = $cat->term_id;
 730                  }
 731  
 732                  $classes[] = 'category-' . $cat_class;
 733                  $classes[] = 'category-' . $cat->term_id;
 734              }
 735          } elseif ( is_tag() ) {
 736              $tag       = $wp_query->get_queried_object();
 737              $classes[] = 'tag';
 738              if ( isset( $tag->term_id ) ) {
 739                  $tag_class = sanitize_html_class( $tag->slug, $tag->term_id );
 740                  if ( is_numeric( $tag_class ) || ! trim( $tag_class, '-' ) ) {
 741                      $tag_class = $tag->term_id;
 742                  }
 743  
 744                  $classes[] = 'tag-' . $tag_class;
 745                  $classes[] = 'tag-' . $tag->term_id;
 746              }
 747          } elseif ( is_tax() ) {
 748              $term = $wp_query->get_queried_object();
 749              if ( isset( $term->term_id ) ) {
 750                  $term_class = sanitize_html_class( $term->slug, $term->term_id );
 751                  if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) {
 752                      $term_class = $term->term_id;
 753                  }
 754  
 755                  $classes[] = 'tax-' . sanitize_html_class( $term->taxonomy );
 756                  $classes[] = 'term-' . $term_class;
 757                  $classes[] = 'term-' . $term->term_id;
 758              }
 759          }
 760      }
 761  
 762      if ( is_user_logged_in() ) {
 763          $classes[] = 'logged-in';
 764      }
 765  
 766      if ( is_admin_bar_showing() ) {
 767          $classes[] = 'admin-bar';
 768          $classes[] = 'no-customize-support';
 769      }
 770  
 771      if ( current_theme_supports( 'custom-background' )
 772          && ( get_background_color() !== get_theme_support( 'custom-background', 'default-color' ) || get_background_image() ) ) {
 773          $classes[] = 'custom-background';
 774      }
 775  
 776      if ( has_custom_logo() ) {
 777          $classes[] = 'wp-custom-logo';
 778      }
 779  
 780      if ( current_theme_supports( 'responsive-embeds' ) ) {
 781          $classes[] = 'wp-embed-responsive';
 782      }
 783  
 784      $page = $wp_query->get( 'page' );
 785  
 786      if ( ! $page || $page < 2 ) {
 787          $page = $wp_query->get( 'paged' );
 788      }
 789  
 790      if ( $page && $page > 1 && ! is_404() ) {
 791          $classes[] = 'paged-' . $page;
 792  
 793          if ( is_single() ) {
 794              $classes[] = 'single-paged-' . $page;
 795          } elseif ( is_page() ) {
 796              $classes[] = 'page-paged-' . $page;
 797          } elseif ( is_category() ) {
 798              $classes[] = 'category-paged-' . $page;
 799          } elseif ( is_tag() ) {
 800              $classes[] = 'tag-paged-' . $page;
 801          } elseif ( is_date() ) {
 802              $classes[] = 'date-paged-' . $page;
 803          } elseif ( is_author() ) {
 804              $classes[] = 'author-paged-' . $page;
 805          } elseif ( is_search() ) {
 806              $classes[] = 'search-paged-' . $page;
 807          } elseif ( is_post_type_archive() ) {
 808              $classes[] = 'post-type-paged-' . $page;
 809          }
 810      }
 811  
 812      if ( ! empty( $class ) ) {
 813          if ( ! is_array( $class ) ) {
 814              $class = preg_split( '#\s+#', $class );
 815          }
 816          $classes = array_merge( $classes, $class );
 817      } else {
 818          // Ensure that we always coerce class to being an array.
 819          $class = array();
 820      }
 821  
 822      $classes = array_map( 'esc_attr', $classes );
 823  
 824      /**
 825       * Filters the list of CSS body class names for the current post or page.
 826       *
 827       * @since 2.8.0
 828       *
 829       * @param string[] $classes An array of body class names.
 830       * @param string[] $class   An array of additional class names added to the body.
 831       */
 832      $classes = apply_filters( 'body_class', $classes, $class );
 833  
 834      return array_unique( $classes );
 835  }
 836  
 837  /**
 838   * Whether post requires password and correct password has been provided.
 839   *
 840   * @since 2.7.0
 841   *
 842   * @param int|WP_Post|null $post An optional post. Global $post used if not provided.
 843   * @return bool false if a password is not required or the correct password cookie is present, true otherwise.
 844   */
 845  function post_password_required( $post = null ) {
 846      $post = get_post( $post );
 847  
 848      if ( empty( $post->post_password ) ) {
 849          /** This filter is documented in wp-includes/post-template.php */
 850          return apply_filters( 'post_password_required', false, $post );
 851      }
 852  
 853      if ( ! isset( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ) ) {
 854          /** This filter is documented in wp-includes/post-template.php */
 855          return apply_filters( 'post_password_required', true, $post );
 856      }
 857  
 858      require_once  ABSPATH . WPINC . '/class-phpass.php';
 859      $hasher = new PasswordHash( 8, true );
 860  
 861      $hash = wp_unslash( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] );
 862      if ( 0 !== strpos( $hash, '$P$B' ) ) {
 863          $required = true;
 864      } else {
 865          $required = ! $hasher->CheckPassword( $post->post_password, $hash );
 866      }
 867  
 868      /**
 869       * Filters whether a post requires the user to supply a password.
 870       *
 871       * @since 4.7.0
 872       *
 873       * @param bool    $required Whether the user needs to supply a password. True if password has not been
 874       *                          provided or is incorrect, false if password has been supplied or is not required.
 875       * @param WP_Post $post     Post data.
 876       */
 877      return apply_filters( 'post_password_required', $required, $post );
 878  }
 879  
 880  //
 881  // Page Template Functions for usage in Themes
 882  //
 883  
 884  /**
 885   * The formatted output of a list of pages.
 886   *
 887   * Displays page links for paginated posts (i.e. including the `<!--nextpage-->`
 888   * Quicktag one or more times). This tag must be within The Loop.
 889   *
 890   * @since 1.2.0
 891   * @since 5.1.0 Added the `aria_current` argument.
 892   *
 893   * @global int $page
 894   * @global int $numpages
 895   * @global int $multipage
 896   * @global int $more
 897   *
 898   * @param string|array $args {
 899   *     Optional. Array or string of default arguments.
 900   *
 901   *     @type string       $before           HTML or text to prepend to each link. Default is `<p> Pages:`.
 902   *     @type string       $after            HTML or text to append to each link. Default is `</p>`.
 903   *     @type string       $link_before      HTML or text to prepend to each link, inside the `<a>` tag.
 904   *                                          Also prepended to the current item, which is not linked. Default empty.
 905   *     @type string       $link_after       HTML or text to append to each Pages link inside the `<a>` tag.
 906   *                                          Also appended to the current item, which is not linked. Default empty.
 907   *     @type string       $aria_current     The value for the aria-current attribute. Possible values are 'page',
 908   *                                          'step', 'location', 'date', 'time', 'true', 'false'. Default is 'page'.
 909   *     @type string       $next_or_number   Indicates whether page numbers should be used. Valid values are number
 910   *                                          and next. Default is 'number'.
 911   *     @type string       $separator        Text between pagination links. Default is ' '.
 912   *     @type string       $nextpagelink     Link text for the next page link, if available. Default is 'Next Page'.
 913   *     @type string       $previouspagelink Link text for the previous page link, if available. Default is 'Previous Page'.
 914   *     @type string       $pagelink         Format string for page numbers. The % in the parameter string will be
 915   *                                          replaced with the page number, so 'Page %' generates "Page 1", "Page 2", etc.
 916   *                                          Defaults to '%', just the page number.
 917   *     @type int|bool     $echo             Whether to echo or not. Accepts 1|true or 0|false. Default 1|true.
 918   * }
 919   * @return string Formatted output in HTML.
 920   */
 921  function wp_link_pages( $args = '' ) {
 922      global $page, $numpages, $multipage, $more;
 923  
 924      $defaults = array(
 925          'before'           => '<p class="post-nav-links">' . __( 'Pages:' ),
 926          'after'            => '</p>',
 927          'link_before'      => '',
 928          'link_after'       => '',
 929          'aria_current'     => 'page',
 930          'next_or_number'   => 'number',
 931          'separator'        => ' ',
 932          'nextpagelink'     => __( 'Next page' ),
 933          'previouspagelink' => __( 'Previous page' ),
 934          'pagelink'         => '%',
 935          'echo'             => 1,
 936      );
 937  
 938      $parsed_args = wp_parse_args( $args, $defaults );
 939  
 940      /**
 941       * Filters the arguments used in retrieving page links for paginated posts.
 942       *
 943       * @since 3.0.0
 944       *
 945       * @param array $parsed_args An array of arguments for page links for paginated posts.
 946       */
 947      $parsed_args = apply_filters( 'wp_link_pages_args', $parsed_args );
 948  
 949      $output = '';
 950      if ( $multipage ) {
 951          if ( 'number' == $parsed_args['next_or_number'] ) {
 952              $output .= $parsed_args['before'];
 953              for ( $i = 1; $i <= $numpages; $i++ ) {
 954                  $link = $parsed_args['link_before'] . str_replace( '%', $i, $parsed_args['pagelink'] ) . $parsed_args['link_after'];
 955                  if ( $i != $page || ! $more && 1 == $page ) {
 956                      $link = _wp_link_page( $i ) . $link . '</a>';
 957                  } elseif ( $i === $page ) {
 958                      $link = '<span class="post-page-numbers current" aria-current="' . esc_attr( $parsed_args['aria_current'] ) . '">' . $link . '</span>';
 959                  }
 960                  /**
 961                   * Filters the HTML output of individual page number links.
 962                   *
 963                   * @since 3.6.0
 964                   *
 965                   * @param string $link The page number HTML output.
 966                   * @param int    $i    Page number for paginated posts' page links.
 967                   */
 968                  $link = apply_filters( 'wp_link_pages_link', $link, $i );
 969  
 970                  // Use the custom links separator beginning with the second link.
 971                  $output .= ( 1 === $i ) ? ' ' : $parsed_args['separator'];
 972                  $output .= $link;
 973              }
 974              $output .= $parsed_args['after'];
 975          } elseif ( $more ) {
 976              $output .= $parsed_args['before'];
 977              $prev    = $page - 1;
 978              if ( $prev > 0 ) {
 979                  $link = _wp_link_page( $prev ) . $parsed_args['link_before'] . $parsed_args['previouspagelink'] . $parsed_args['link_after'] . '</a>';
 980  
 981                  /** This filter is documented in wp-includes/post-template.php */
 982                  $output .= apply_filters( 'wp_link_pages_link', $link, $prev );
 983              }
 984              $next = $page + 1;
 985              if ( $next <= $numpages ) {
 986                  if ( $prev ) {
 987                      $output .= $parsed_args['separator'];
 988                  }
 989                  $link = _wp_link_page( $next ) . $parsed_args['link_before'] . $parsed_args['nextpagelink'] . $parsed_args['link_after'] . '</a>';
 990  
 991                  /** This filter is documented in wp-includes/post-template.php */
 992                  $output .= apply_filters( 'wp_link_pages_link', $link, $next );
 993              }
 994              $output .= $parsed_args['after'];
 995          }
 996      }
 997  
 998      /**
 999       * Filters the HTML output of page links for paginated posts.
1000       *
1001       * @since 3.6.0
1002       *
1003       * @param string $output HTML output of paginated posts' page links.
1004       * @param array  $args   An array of arguments.
1005       */
1006      $html = apply_filters( 'wp_link_pages', $output, $args );
1007  
1008      if ( $parsed_args['echo'] ) {
1009          echo $html;
1010      }
1011      return $html;
1012  }
1013  
1014  /**
1015   * Helper function for wp_link_pages().
1016   *
1017   * @since 3.1.0
1018   * @access private
1019   *
1020   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
1021   *
1022   * @param int $i Page number.
1023   * @return string Link.
1024   */
1025  function _wp_link_page( $i ) {
1026      global $wp_rewrite;
1027      $post       = get_post();
1028      $query_args = array();
1029  
1030      if ( 1 == $i ) {
1031          $url = get_permalink();
1032      } else {
1033          if ( '' == get_option( 'permalink_structure' ) || in_array( $post->post_status, array( 'draft', 'pending' ) ) ) {
1034              $url = add_query_arg( 'page', $i, get_permalink() );
1035          } elseif ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) {
1036              $url = trailingslashit( get_permalink() ) . user_trailingslashit( "$wp_rewrite->pagination_base/" . $i, 'single_paged' );
1037          } else {
1038              $url = trailingslashit( get_permalink() ) . user_trailingslashit( $i, 'single_paged' );
1039          }
1040      }
1041  
1042      if ( is_preview() ) {
1043  
1044          if ( ( 'draft' !== $post->post_status ) && isset( $_GET['preview_id'], $_GET['preview_nonce'] ) ) {
1045              $query_args['preview_id']    = wp_unslash( $_GET['preview_id'] );
1046              $query_args['preview_nonce'] = wp_unslash( $_GET['preview_nonce'] );
1047          }
1048  
1049          $url = get_preview_post_link( $post, $query_args, $url );
1050      }
1051  
1052      return '<a href="' . esc_url( $url ) . '" class="post-page-numbers">';
1053  }
1054  
1055  //
1056  // Post-meta: Custom per-post fields.
1057  //
1058  
1059  /**
1060   * Retrieve post custom meta data field.
1061   *
1062   * @since 1.5.0
1063   *
1064   * @param string $key Meta data key name.
1065   * @return false|string|array Array of values or single value, if only one element exists. False will be returned if key does not exist.
1066   */
1067  function post_custom( $key = '' ) {
1068      $custom = get_post_custom();
1069  
1070      if ( ! isset( $custom[ $key ] ) ) {
1071          return false;
1072      } elseif ( 1 == count( $custom[ $key ] ) ) {
1073          return $custom[ $key ][0];
1074      } else {
1075          return $custom[ $key ];
1076      }
1077  }
1078  
1079  /**
1080   * Display a list of post custom fields.
1081   *
1082   * @since 1.2.0
1083   *
1084   * @internal This will probably change at some point...
1085   */
1086  function the_meta() {
1087      $keys = get_post_custom_keys();
1088      if ( $keys ) {
1089          $li_html = '';
1090          foreach ( (array) $keys as $key ) {
1091              $keyt = trim( $key );
1092              if ( is_protected_meta( $keyt, 'post' ) ) {
1093                  continue;
1094              }
1095  
1096              $values = array_map( 'trim', get_post_custom_values( $key ) );
1097              $value  = implode( ', ', $values );
1098  
1099              $html = sprintf(
1100                  "<li><span class='post-meta-key'>%s</span> %s</li>\n",
1101                  /* translators: %s: Post custom field name. */
1102                  sprintf( _x( '%s:', 'Post custom field name' ), $key ),
1103                  $value
1104              );
1105  
1106              /**
1107               * Filters the HTML output of the li element in the post custom fields list.
1108               *
1109               * @since 2.2.0
1110               *
1111               * @param string $html  The HTML output for the li element.
1112               * @param string $key   Meta key.
1113               * @param string $value Meta value.
1114               */
1115              $li_html .= apply_filters( 'the_meta_key', $html, $key, $value );
1116          }
1117  
1118          if ( $li_html ) {
1119              echo "<ul class='post-meta'>\n{$li_html}</ul>\n";
1120          }
1121      }
1122  }
1123  
1124  //
1125  // Pages
1126  //
1127  
1128  /**
1129   * Retrieve or display a list of pages as a dropdown (select list).
1130   *
1131   * @since 2.1.0
1132   * @since 4.2.0 The `$value_field` argument was added.
1133   * @since 4.3.0 The `$class` argument was added.
1134   *
1135   * @see get_pages()
1136   *
1137   * @param array|string $args {
1138   *     Optional. Array or string of arguments to generate a page dropdown. See `get_pages()` for additional arguments.
1139   *
1140   *     @type int          $depth                 Maximum depth. Default 0.
1141   *     @type int          $child_of              Page ID to retrieve child pages of. Default 0.
1142   *     @type int|string   $selected              Value of the option that should be selected. Default 0.
1143   *     @type bool|int     $echo                  Whether to echo or return the generated markup. Accepts 0, 1,
1144   *                                               or their bool equivalents. Default 1.
1145   *     @type string       $name                  Value for the 'name' attribute of the select element.
1146   *                                               Default 'page_id'.
1147   *     @type string       $id                    Value for the 'id' attribute of the select element.
1148   *     @type string       $class                 Value for the 'class' attribute of the select element. Default: none.
1149   *                                               Defaults to the value of `$name`.
1150   *     @type string       $show_option_none      Text to display for showing no pages. Default empty (does not display).
1151   *     @type string       $show_option_no_change Text to display for "no change" option. Default empty (does not display).
1152   *     @type string       $option_none_value     Value to use when no page is selected. Default empty.
1153   *     @type string       $value_field           Post field used to populate the 'value' attribute of the option
1154   *                                               elements. Accepts any valid post field. Default 'ID'.
1155   * }
1156   * @return string HTML content, if not displaying.
1157   */
1158  function wp_dropdown_pages( $args = '' ) {
1159      $defaults = array(
1160          'depth'                 => 0,
1161          'child_of'              => 0,
1162          'selected'              => 0,
1163          'echo'                  => 1,
1164          'name'                  => 'page_id',
1165          'id'                    => '',
1166          'class'                 => '',
1167          'show_option_none'      => '',
1168          'show_option_no_change' => '',
1169          'option_none_value'     => '',
1170          'value_field'           => 'ID',
1171      );
1172  
1173      $parsed_args = wp_parse_args( $args, $defaults );
1174  
1175      $pages  = get_pages( $parsed_args );
1176      $output = '';
1177      // Back-compat with old system where both id and name were based on $name argument
1178      if ( empty( $parsed_args['id'] ) ) {
1179          $parsed_args['id'] = $parsed_args['name'];
1180      }
1181  
1182      if ( ! empty( $pages ) ) {
1183          $class = '';
1184          if ( ! empty( $parsed_args['class'] ) ) {
1185              $class = " class='" . esc_attr( $parsed_args['class'] ) . "'";
1186          }
1187  
1188          $output = "<select name='" . esc_attr( $parsed_args['name'] ) . "'" . $class . " id='" . esc_attr( $parsed_args['id'] ) . "'>\n";
1189          if ( $parsed_args['show_option_no_change'] ) {
1190              $output .= "\t<option value=\"-1\">" . $parsed_args['show_option_no_change'] . "</option>\n";
1191          }
1192          if ( $parsed_args['show_option_none'] ) {
1193              $output .= "\t<option value=\"" . esc_attr( $parsed_args['option_none_value'] ) . '">' . $parsed_args['show_option_none'] . "</option>\n";
1194          }
1195          $output .= walk_page_dropdown_tree( $pages, $parsed_args['depth'], $parsed_args );
1196          $output .= "</select>\n";
1197      }
1198  
1199      /**
1200       * Filters the HTML output of a list of pages as a drop down.
1201       *
1202       * @since 2.1.0
1203       * @since 4.4.0 `$parsed_args` and `$pages` added as arguments.
1204       *
1205       * @param string $output      HTML output for drop down list of pages.
1206       * @param array  $parsed_args The parsed arguments array.
1207       * @param array  $pages       List of WP_Post objects returned by `get_pages()`
1208       */
1209      $html = apply_filters( 'wp_dropdown_pages', $output, $parsed_args, $pages );
1210  
1211      if ( $parsed_args['echo'] ) {
1212          echo $html;
1213      }
1214      return $html;
1215  }
1216  
1217  /**
1218   * Retrieve or display a list of pages (or hierarchical post type items) in list (li) format.
1219   *
1220   * @since 1.5.0
1221   * @since 4.7.0 Added the `item_spacing` argument.
1222   *
1223   * @see get_pages()
1224   *
1225   * @global WP_Query $wp_query WordPress Query object.
1226   *
1227   * @param array|string $args {
1228   *     Optional. Array or string of arguments to generate a list of pages. See `get_pages()` for additional arguments.
1229   *
1230   *     @type int          $child_of     Display only the sub-pages of a single page by ID. Default 0 (all pages).
1231   *     @type string       $authors      Comma-separated list of author IDs. Default empty (all authors).
1232   *     @type string       $date_format  PHP date format to use for the listed pages. Relies on the 'show_date' parameter.
1233   *                                      Default is the value of 'date_format' option.
1234   *     @type int          $depth        Number of levels in the hierarchy of pages to include in the generated list.
1235   *                                      Accepts -1 (any depth), 0 (all pages), 1 (top-level pages only), and n (pages to
1236   *                                      the given n depth). Default 0.
1237   *     @type bool         $echo         Whether or not to echo the list of pages. Default true.
1238   *     @type string       $exclude      Comma-separated list of page IDs to exclude. Default empty.
1239   *     @type array        $include      Comma-separated list of page IDs to include. Default empty.
1240   *     @type string       $link_after   Text or HTML to follow the page link label. Default null.
1241   *     @type string       $link_before  Text or HTML to precede the page link label. Default null.
1242   *     @type string       $post_type    Post type to query for. Default 'page'.
1243   *     @type string|array $post_status  Comma-separated list or array of post statuses to include. Default 'publish'.
1244   *     @type string       $show_date    Whether to display the page publish or modified date for each page. Accepts
1245   *                                      'modified' or any other value. An empty value hides the date. Default empty.
1246   *     @type string       $sort_column  Comma-separated list of column names to sort the pages by. Accepts 'post_author',
1247   *                                      'post_date', 'post_title', 'post_name', 'post_modified', 'post_modified_gmt',
1248   *                                      'menu_order', 'post_parent', 'ID', 'rand', or 'comment_count'. Default 'post_title'.
1249   *     @type string       $title_li     List heading. Passing a null or empty value will result in no heading, and the list
1250   *                                      will not be wrapped with unordered list `<ul>` tags. Default 'Pages'.
1251   *     @type string       $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve' or 'discard'.
1252   *                                      Default 'preserve'.
1253   *     @type Walker       $walker       Walker instance to use for listing pages. Default empty (Walker_Page).
1254   * }
1255   * @return string|void HTML list of pages.
1256   */
1257  function wp_list_pages( $args = '' ) {
1258      $defaults = array(
1259          'depth'        => 0,
1260          'show_date'    => '',
1261          'date_format'  => get_option( 'date_format' ),
1262          'child_of'     => 0,
1263          'exclude'      => '',
1264          'title_li'     => __( 'Pages' ),
1265          'echo'         => 1,
1266          'authors'      => '',
1267          'sort_column'  => 'menu_order, post_title',
1268          'link_before'  => '',
1269          'link_after'   => '',
1270          'item_spacing' => 'preserve',
1271          'walker'       => '',
1272      );
1273  
1274      $parsed_args = wp_parse_args( $args, $defaults );
1275  
1276      if ( ! in_array( $parsed_args['item_spacing'], array( 'preserve', 'discard' ), true ) ) {
1277          // invalid value, fall back to default.
1278          $parsed_args['item_spacing'] = $defaults['item_spacing'];
1279      }
1280  
1281      $output       = '';
1282      $current_page = 0;
1283  
1284      // sanitize, mostly to keep spaces out
1285      $parsed_args['exclude'] = preg_replace( '/[^0-9,]/', '', $parsed_args['exclude'] );
1286  
1287      // Allow plugins to filter an array of excluded pages (but don't put a nullstring into the array)
1288      $exclude_array = ( $parsed_args['exclude'] ) ? explode( ',', $parsed_args['exclude'] ) : array();
1289  
1290      /**
1291       * Filters the array of pages to exclude from the pages list.
1292       *
1293       * @since 2.1.0
1294       *
1295       * @param array $exclude_array An array of page IDs to exclude.
1296       */
1297      $parsed_args['exclude'] = implode( ',', apply_filters( 'wp_list_pages_excludes', $exclude_array ) );
1298  
1299      $parsed_args['hierarchical'] = 0;
1300  
1301      // Query pages.
1302      $pages = get_pages( $parsed_args );
1303  
1304      if ( ! empty( $pages ) ) {
1305          if ( $parsed_args['title_li'] ) {
1306              $output .= '<li class="pagenav">' . $parsed_args['title_li'] . '<ul>';
1307          }
1308          global $wp_query;
1309          if ( is_page() || is_attachment() || $wp_query->is_posts_page ) {
1310              $current_page = get_queried_object_id();
1311          } elseif ( is_singular() ) {
1312              $queried_object = get_queried_object();
1313              if ( is_post_type_hierarchical( $queried_object->post_type ) ) {
1314                  $current_page = $queried_object->ID;
1315              }
1316          }
1317  
1318          $output .= walk_page_tree( $pages, $parsed_args['depth'], $current_page, $parsed_args );
1319  
1320          if ( $parsed_args['title_li'] ) {
1321              $output .= '</ul></li>';
1322          }
1323      }
1324  
1325      /**
1326       * Filters the HTML output of the pages to list.
1327       *
1328       * @since 1.5.1
1329       * @since 4.4.0 `$pages` added as arguments.
1330       *
1331       * @see wp_list_pages()
1332       *
1333       * @param string $output      HTML output of the pages list.
1334       * @param array  $parsed_args An array of page-listing arguments.
1335       * @param array  $pages       List of WP_Post objects returned by `get_pages()`
1336       */
1337      $html = apply_filters( 'wp_list_pages', $output, $parsed_args, $pages );
1338  
1339      if ( $parsed_args['echo'] ) {
1340          echo $html;
1341      } else {
1342          return $html;
1343      }
1344  }
1345  
1346  /**
1347   * Displays or retrieves a list of pages with an optional home link.
1348   *
1349   * The arguments are listed below and part of the arguments are for wp_list_pages() function.
1350   * Check that function for more info on those arguments.
1351   *
1352   * @since 2.7.0
1353   * @since 4.4.0 Added `menu_id`, `container`, `before`, `after`, and `walker` arguments.
1354   * @since 4.7.0 Added the `item_spacing` argument.
1355   *
1356   * @param array|string $args {
1357   *     Optional. Array or string of arguments to generate a page menu. See `wp_list_pages()` for additional arguments.
1358   *
1359   *     @type string          $sort_column  How to sort the list of pages. Accepts post column names.
1360   *                                         Default 'menu_order, post_title'.
1361   *     @type string          $menu_id      ID for the div containing the page list. Default is empty string.
1362   *     @type string          $menu_class   Class to use for the element containing the page list. Default 'menu'.
1363   *     @type string          $container    Element to use for the element containing the page list. Default 'div'.
1364   *     @type bool            $echo         Whether to echo the list or return it. Accepts true (echo) or false (return).
1365   *                                         Default true.
1366   *     @type int|bool|string $show_home    Whether to display the link to the home page. Can just enter the text
1367   *                                         you'd like shown for the home link. 1|true defaults to 'Home'.
1368   *     @type string          $link_before  The HTML or text to prepend to $show_home text. Default empty.
1369   *     @type string          $link_after   The HTML or text to append to $show_home text. Default empty.
1370   *     @type string          $before       The HTML or text to prepend to the menu. Default is '<ul>'.
1371   *     @type string          $after        The HTML or text to append to the menu. Default is '</ul>'.
1372   *     @type string          $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve'
1373   *                                         or 'discard'. Default 'discard'.
1374   *     @type Walker          $walker       Walker instance to use for listing pages. Default empty (Walker_Page).
1375   * }
1376   * @return string|void HTML menu
1377   */
1378  function wp_page_menu( $args = array() ) {
1379      $defaults = array(
1380          'sort_column'  => 'menu_order, post_title',
1381          'menu_id'      => '',
1382          'menu_class'   => 'menu',
1383          'container'    => 'div',
1384          'echo'         => true,
1385          'link_before'  => '',
1386          'link_after'   => '',
1387          'before'       => '<ul>',
1388          'after'        => '</ul>',
1389          'item_spacing' => 'discard',
1390          'walker'       => '',
1391      );
1392      $args     = wp_parse_args( $args, $defaults );
1393  
1394      if ( ! in_array( $args['item_spacing'], array( 'preserve', 'discard' ) ) ) {
1395          // invalid value, fall back to default.
1396          $args['item_spacing'] = $defaults['item_spacing'];
1397      }
1398  
1399      if ( 'preserve' === $args['item_spacing'] ) {
1400          $t = "\t";
1401          $n = "\n";
1402      } else {
1403          $t = '';
1404          $n = '';
1405      }
1406  
1407      /**
1408       * Filters the arguments used to generate a page-based menu.
1409       *
1410       * @since 2.7.0
1411       *
1412       * @see wp_page_menu()
1413       *
1414       * @param array $args An array of page menu arguments.
1415       */
1416      $args = apply_filters( 'wp_page_menu_args', $args );
1417  
1418      $menu = '';
1419  
1420      $list_args = $args;
1421  
1422      // Show Home in the menu
1423      if ( ! empty( $args['show_home'] ) ) {
1424          if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] ) {
1425              $text = __( 'Home' );
1426          } else {
1427              $text = $args['show_home'];
1428          }
1429          $class = '';
1430          if ( is_front_page() && ! is_paged() ) {
1431              $class = 'class="current_page_item"';
1432          }
1433          $menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>';
1434          // If the front page is a page, add it to the exclude list
1435          if ( get_option( 'show_on_front' ) == 'page' ) {
1436              if ( ! empty( $list_args['exclude'] ) ) {
1437                  $list_args['exclude'] .= ',';
1438              } else {
1439                  $list_args['exclude'] = '';
1440              }
1441              $list_args['exclude'] .= get_option( 'page_on_front' );
1442          }
1443      }
1444  
1445      $list_args['echo']     = false;
1446      $list_args['title_li'] = '';
1447      $menu                 .= wp_list_pages( $list_args );
1448  
1449      $container = sanitize_text_field( $args['container'] );
1450  
1451      // Fallback in case `wp_nav_menu()` was called without a container.
1452      if ( empty( $container ) ) {
1453          $container = 'div';
1454      }
1455  
1456      if ( $menu ) {
1457  
1458          // wp_nav_menu doesn't set before and after
1459          if ( isset( $args['fallback_cb'] ) &&
1460              'wp_page_menu' === $args['fallback_cb'] &&
1461              'ul' !== $container ) {
1462              $args['before'] = "<ul>{$n}";
1463              $args['after']  = '</ul>';
1464          }
1465  
1466          $menu = $args['before'] . $menu . $args['after'];
1467      }
1468  
1469      $attrs = '';
1470      if ( ! empty( $args['menu_id'] ) ) {
1471          $attrs .= ' id="' . esc_attr( $args['menu_id'] ) . '"';
1472      }
1473  
1474      if ( ! empty( $args['menu_class'] ) ) {
1475          $attrs .= ' class="' . esc_attr( $args['menu_class'] ) . '"';
1476      }
1477  
1478      $menu = "<{$container}{$attrs}>" . $menu . "</{$container}>{$n}";
1479  
1480      /**
1481       * Filters the HTML output of a page-based menu.
1482       *
1483       * @since 2.7.0
1484       *
1485       * @see wp_page_menu()
1486       *
1487       * @param string $menu The HTML output.
1488       * @param array  $args An array of arguments.
1489       */
1490      $menu = apply_filters( 'wp_page_menu', $menu, $args );
1491      if ( $args['echo'] ) {
1492          echo $menu;
1493      } else {
1494          return $menu;
1495      }
1496  }
1497  
1498  //
1499  // Page helpers
1500  //
1501  
1502  /**
1503   * Retrieve HTML list content for page list.
1504   *
1505   * @uses Walker_Page to create HTML list content.
1506   * @since 2.1.0
1507   *
1508   * @param array $pages
1509   * @param int   $depth
1510   * @param int   $current_page
1511   * @param array $r
1512   * @return string
1513   */
1514  function walk_page_tree( $pages, $depth, $current_page, $r ) {
1515      if ( empty( $r['walker'] ) ) {
1516          $walker = new Walker_Page;
1517      } else {
1518          $walker = $r['walker'];
1519      }
1520  
1521      foreach ( (array) $pages as $page ) {
1522          if ( $page->post_parent ) {
1523              $r['pages_with_children'][ $page->post_parent ] = true;
1524          }
1525      }
1526  
1527      return $walker->walk( $pages, $depth, $r, $current_page );
1528  }
1529  
1530  /**
1531   * Retrieve HTML dropdown (select) content for page list.
1532   *
1533   * @since 2.1.0
1534   * @since 5.3.0 Formalized the existing `...$args` parameter by adding it
1535   *              to the function signature.
1536   *
1537   * @uses Walker_PageDropdown to create HTML dropdown content.
1538   * @see Walker_PageDropdown::walk() for parameters and return description.
1539   *
1540   * @return string
1541   */
1542  function walk_page_dropdown_tree( ...$args ) {
1543      if ( empty( $args[2]['walker'] ) ) { // the user's options are the third parameter
1544          $walker = new Walker_PageDropdown;
1545      } else {
1546          $walker = $args[2]['walker'];
1547      }
1548  
1549      return $walker->walk( ...$args );
1550  }
1551  
1552  //
1553  // Attachments
1554  //
1555  
1556  /**
1557   * Display an attachment page link using an image or icon.
1558   *
1559   * @since 2.0.0
1560   *
1561   * @param int|WP_Post $id Optional. Post ID or post object.
1562   * @param bool        $fullsize     Optional, default is false. Whether to use full size.
1563   * @param bool        $deprecated   Deprecated. Not used.
1564   * @param bool        $permalink    Optional, default is false. Whether to include permalink.
1565   */
1566  function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) {
1567      if ( ! empty( $deprecated ) ) {
1568          _deprecated_argument( __FUNCTION__, '2.5.0' );
1569      }
1570  
1571      if ( $fullsize ) {
1572          echo wp_get_attachment_link( $id, 'full', $permalink );
1573      } else {
1574          echo wp_get_attachment_link( $id, 'thumbnail', $permalink );
1575      }
1576  }
1577  
1578  /**
1579   * Retrieve an attachment page link using an image or icon, if possible.
1580   *
1581   * @since 2.5.0
1582   * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
1583   *
1584   * @param int|WP_Post  $id        Optional. Post ID or post object.
1585   * @param string|array $size      Optional. Image size. Accepts any valid image size, or an array
1586   *                                of width and height values in pixels (in that order).
1587   *                                Default 'thumbnail'.
1588   * @param bool         $permalink Optional, Whether to add permalink to image. Default false.
1589   * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
1590   * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
1591   *                                Default false.
1592   * @param array|string $attr      Optional. Array or string of attributes. Default empty.
1593   * @return string HTML content.
1594   */
1595  function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '' ) {
1596      $_post = get_post( $id );
1597  
1598      if ( empty( $_post ) || ( 'attachment' !== $_post->post_type ) || ! wp_get_attachment_url( $_post->ID ) ) {
1599          return __( 'Missing Attachment' );
1600      }
1601  
1602      $url = wp_get_attachment_url( $_post->ID );
1603  
1604      if ( $permalink ) {
1605          $url = get_attachment_link( $_post->ID );
1606      }
1607  
1608      if ( $text ) {
1609          $link_text = $text;
1610      } elseif ( $size && 'none' != $size ) {
1611          $link_text = wp_get_attachment_image( $_post->ID, $size, $icon, $attr );
1612      } else {
1613          $link_text = '';
1614      }
1615  
1616      if ( '' === trim( $link_text ) ) {
1617          $link_text = $_post->post_title;
1618      }
1619  
1620      if ( '' === trim( $link_text ) ) {
1621          $link_text = esc_html( pathinfo( get_attached_file( $_post->ID ), PATHINFO_FILENAME ) );
1622      }
1623      /**
1624       * Filters a retrieved attachment page link.
1625       *
1626       * @since 2.7.0
1627       * @since 5.1.0 Added the $attr parameter.
1628       *
1629       * @param string       $link_html The page link HTML output.
1630       * @param int          $id        Post ID.
1631       * @param string|array $size      Size of the image. Image size or array of width and height values (in that order).
1632       *                                Default 'thumbnail'.
1633       * @param bool         $permalink Whether to add permalink to image. Default false.
1634       * @param bool         $icon      Whether to include an icon. Default false.
1635       * @param string|bool  $text      If string, will be link text. Default false.
1636       * @param array|string $attr      Array or string of attributes. Default empty.
1637       */
1638      return apply_filters( 'wp_get_attachment_link', "<a href='" . esc_url( $url ) . "'>$link_text</a>", $id, $size, $permalink, $icon, $text, $attr );
1639  }
1640  
1641  /**
1642   * Wrap attachment in paragraph tag before content.
1643   *
1644   * @since 2.0.0
1645   *
1646   * @param string $content
1647   * @return string
1648   */
1649  function prepend_attachment( $content ) {
1650      $post = get_post();
1651  
1652      if ( empty( $post->post_type ) || $post->post_type != 'attachment' ) {
1653          return $content;
1654      }
1655  
1656      if ( wp_attachment_is( 'video', $post ) ) {
1657          $meta = wp_get_attachment_metadata( get_the_ID() );
1658          $atts = array( 'src' => wp_get_attachment_url() );
1659          if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) {
1660              $atts['width']  = (int) $meta['width'];
1661              $atts['height'] = (int) $meta['height'];
1662          }
1663          if ( has_post_thumbnail() ) {
1664              $atts['poster'] = wp_get_attachment_url( get_post_thumbnail_id() );
1665          }
1666          $p = wp_video_shortcode( $atts );
1667      } elseif ( wp_attachment_is( 'audio', $post ) ) {
1668          $p = wp_audio_shortcode( array( 'src' => wp_get_attachment_url() ) );
1669      } else {
1670          $p = '<p class="attachment">';
1671          // show the medium sized image representation of the attachment if available, and link to the raw file
1672          $p .= wp_get_attachment_link( 0, 'medium', false );
1673          $p .= '</p>';
1674      }
1675  
1676      /**
1677       * Filters the attachment markup to be prepended to the post content.
1678       *
1679       * @since 2.0.0
1680       *
1681       * @see prepend_attachment()
1682       *
1683       * @param string $p The attachment HTML output.
1684       */
1685      $p = apply_filters( 'prepend_attachment', $p );
1686  
1687      return "$p\n$content";
1688  }
1689  
1690  //
1691  // Misc
1692  //
1693  
1694  /**
1695   * Retrieve protected post password form content.
1696   *
1697   * @since 1.0.0
1698   *
1699   * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
1700   * @return string HTML content for password form for password protected post.
1701   */
1702  function get_the_password_form( $post = 0 ) {
1703      $post   = get_post( $post );
1704      $label  = 'pwbox-' . ( empty( $post->ID ) ? rand() : $post->ID );
1705      $output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post">
1706      <p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p>
1707      <p><label for="' . $label . '">' . __( 'Password:' ) . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr_x( 'Enter', 'post password form' ) . '" /></p></form>
1708      ';
1709  
1710      /**
1711       * Filters the HTML output for the protected post password form.
1712       *
1713       * If modifying the password field, please note that the core database schema
1714       * limits the password field to 20 characters regardless of the value of the
1715       * size attribute in the form input.
1716       *
1717       * @since 2.7.0
1718       *
1719       * @param string $output The password form HTML output.
1720       */
1721      return apply_filters( 'the_password_form', $output );
1722  }
1723  
1724  /**
1725   * Determines whether currently in a page template.
1726   *
1727   * This template tag allows you to determine if you are in a page template.
1728   * You can optionally provide a template name or array of template names
1729   * and then the check will be specific to that template.
1730   *
1731   * For more information on this and similar theme functions, check out
1732   * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
1733   * Conditional Tags} article in the Theme Developer Handbook.
1734   *
1735   * @since 2.5.0
1736   * @since 4.2.0 The `$template` parameter was changed to also accept an array of page templates.
1737   * @since 4.7.0 Now works with any post type, not just pages.
1738   *
1739   * @param string|array $template The specific template name or array of templates to match.
1740   * @return bool True on success, false on failure.
1741   */
1742  function is_page_template( $template = '' ) {
1743      if ( ! is_singular() ) {
1744          return false;
1745      }
1746  
1747      $page_template = get_page_template_slug( get_queried_object_id() );
1748  
1749      if ( empty( $template ) ) {
1750          return (bool) $page_template;
1751      }
1752  
1753      if ( $template == $page_template ) {
1754          return true;
1755      }
1756  
1757      if ( is_array( $template ) ) {
1758          if ( ( in_array( 'default', $template, true ) && ! $page_template )
1759              || in_array( $page_template, $template, true )
1760          ) {
1761              return true;
1762          }
1763      }
1764  
1765      return ( 'default' === $template && ! $page_template );
1766  }
1767  
1768  /**
1769   * Get the specific template name for a given post.
1770   *
1771   * @since 3.4.0
1772   * @since 4.7.0 Now works with any post type, not just pages.
1773   *
1774   * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
1775   * @return string|false Page template filename. Returns an empty string when the default page template
1776   *  is in use. Returns false if the post does not exist.
1777   */
1778  function get_page_template_slug( $post = null ) {
1779      $post = get_post( $post );
1780  
1781      if ( ! $post ) {
1782          return false;
1783      }
1784  
1785      $template = get_post_meta( $post->ID, '_wp_page_template', true );
1786  
1787      if ( ! $template || 'default' == $template ) {
1788          return '';
1789      }
1790  
1791      return $template;
1792  }
1793  
1794  /**
1795   * Retrieve formatted date timestamp of a revision (linked to that revisions's page).
1796   *
1797   * @since 2.6.0
1798   *
1799   * @param int|object $revision Revision ID or revision object.
1800   * @param bool       $link     Optional, default is true. Link to revisions's page?
1801   * @return string|false i18n formatted datetimestamp or localized 'Current Revision'.
1802   */
1803  function wp_post_revision_title( $revision, $link = true ) {
1804      $revision = get_post( $revision );
1805      if ( ! $revision ) {
1806          return $revision;
1807      }
1808  
1809      if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) {
1810          return false;
1811      }
1812  
1813      /* translators: Revision date format, see https://secure.php.net/date */
1814      $datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
1815      /* translators: %s: Revision date. */
1816      $autosavef = __( '%s [Autosave]' );
1817      /* translators: %s: Revision date. */
1818      $currentf = __( '%s [Current Revision]' );
1819  
1820      $date      = date_i18n( $datef, strtotime( $revision->post_modified ) );
1821      $edit_link = get_edit_post_link( $revision->ID );
1822      if ( $link && current_user_can( 'edit_post', $revision->ID ) && $edit_link ) {
1823          $date = "<a href='$edit_link'>$date</a>";
1824      }
1825  
1826      if ( ! wp_is_post_revision( $revision ) ) {
1827          $date = sprintf( $currentf, $date );
1828      } elseif ( wp_is_post_autosave( $revision ) ) {
1829          $date = sprintf( $autosavef, $date );
1830      }
1831  
1832      return $date;
1833  }
1834  
1835  /**
1836   * Retrieve formatted date timestamp of a revision (linked to that revisions's page).
1837   *
1838   * @since 3.6.0
1839   *
1840   * @param int|object $revision Revision ID or revision object.
1841   * @param bool       $link     Optional, default is true. Link to revisions's page?
1842   * @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'.
1843   */
1844  function wp_post_revision_title_expanded( $revision, $link = true ) {
1845      $revision = get_post( $revision );
1846      if ( ! $revision ) {
1847          return $revision;
1848      }
1849  
1850      if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) {
1851          return false;
1852      }
1853  
1854      $author = get_the_author_meta( 'display_name', $revision->post_author );
1855      /* translators: Revision date format, see https://secure.php.net/date */
1856      $datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
1857  
1858      $gravatar = get_avatar( $revision->post_author, 24 );
1859  
1860      $date      = date_i18n( $datef, strtotime( $revision->post_modified ) );
1861      $edit_link = get_edit_post_link( $revision->ID );
1862      if ( $link && current_user_can( 'edit_post', $revision->ID ) && $edit_link ) {
1863          $date = "<a href='$edit_link'>$date</a>";
1864      }
1865  
1866      $revision_date_author = sprintf(
1867          /* translators: Post revision title. 1: Author avatar, 2: Author name, 3: Time ago, 4: Date. */
1868          __( '%1$s %2$s, %3$s ago (%4$s)' ),
1869          $gravatar,
1870          $author,
1871          human_time_diff( strtotime( $revision->post_modified_gmt ) ),
1872          $date
1873      );
1874  
1875      /* translators: %s: Revision date with author avatar. */
1876      $autosavef = __( '%s [Autosave]' );
1877      /* translators: %s: Revision date with author avatar. */
1878      $currentf = __( '%s [Current Revision]' );
1879  
1880      if ( ! wp_is_post_revision( $revision ) ) {
1881          $revision_date_author = sprintf( $currentf, $revision_date_author );
1882      } elseif ( wp_is_post_autosave( $revision ) ) {
1883          $revision_date_author = sprintf( $autosavef, $revision_date_author );
1884      }
1885  
1886      /**
1887       * Filters the formatted author and date for a revision.
1888       *
1889       * @since 4.4.0
1890       *
1891       * @param string  $revision_date_author The formatted string.
1892       * @param WP_Post $revision             The revision object.
1893       * @param bool    $link                 Whether to link to the revisions page, as passed into
1894       *                                      wp_post_revision_title_expanded().
1895       */
1896      return apply_filters( 'wp_post_revision_title_expanded', $revision_date_author, $revision, $link );
1897  }
1898  
1899  /**
1900   * Display a list of a post's revisions.
1901   *
1902   * Can output either a UL with edit links or a TABLE with diff interface, and
1903   * restore action links.
1904   *
1905   * @since 2.6.0
1906   *
1907   * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
1908   * @param string      $type    'all' (default), 'revision' or 'autosave'
1909   */
1910  function wp_list_post_revisions( $post_id = 0, $type = 'all' ) {
1911      $post = get_post( $post_id );
1912      if ( ! $post ) {
1913          return;
1914      }
1915  
1916      // $args array with (parent, format, right, left, type) deprecated since 3.6
1917      if ( is_array( $type ) ) {
1918          $type = ! empty( $type['type'] ) ? $type['type'] : $type;
1919          _deprecated_argument( __FUNCTION__, '3.6.0' );
1920      }
1921  
1922      $revisions = wp_get_post_revisions( $post->ID );
1923      if ( ! $revisions ) {
1924          return;
1925      }
1926  
1927      $rows = '';
1928      foreach ( $revisions as $revision ) {
1929          if ( ! current_user_can( 'read_post', $revision->ID ) ) {
1930              continue;
1931          }
1932  
1933          $is_autosave = wp_is_post_autosave( $revision );
1934          if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) ) {
1935              continue;
1936          }
1937  
1938          $rows .= "\t<li>" . wp_post_revision_title_expanded( $revision ) . "</li>\n";
1939      }
1940  
1941      echo "<div class='hide-if-js'><p>" . __( 'JavaScript must be enabled to use this feature.' ) . "</p></div>\n";
1942  
1943      echo "<ul class='post-revisions hide-if-no-js'>\n";
1944      echo $rows;
1945      echo '</ul>';
1946  }


Generated: Tue Oct 22 08:20:01 2019 Cross-referenced by PHPXref 0.7