[ Index ]

PHP Cross Reference of WordPress

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


Generated: Sun May 31 01:00:03 2020 Cross-referenced by PHPXref 0.7.1