[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

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


Generated : Sat Sep 26 08:20:01 2020 Cross-referenced by PHPXref