[ 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   * Displays 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   * Retrieves 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   * Displays or retrieves 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   * Sanitizes 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   * Retrieves the post title.
 107   *
 108   * If the post is protected and the visitor is not an admin, then "Protected"
 109   * will be inserted before the post title. If the post is private, then
 110   * "Private" will be inserted 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   * Displays 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   * Retrieves 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   * Displays 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   * Retrieves 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   * Displays 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|string[] $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( implode( ' ', 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( implode( ' ', 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   * Determines whether the post requires password and whether a 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 object.
 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 page link arguments. See wp_link_pages()
 950       *                           for information on accepted arguments.
 951       */
 952      $parsed_args = apply_filters( 'wp_link_pages_args', $parsed_args );
 953  
 954      $output = '';
 955      if ( $multipage ) {
 956          if ( 'number' === $parsed_args['next_or_number'] ) {
 957              $output .= $parsed_args['before'];
 958              for ( $i = 1; $i <= $numpages; $i++ ) {
 959                  $link = $parsed_args['link_before'] . str_replace( '%', $i, $parsed_args['pagelink'] ) . $parsed_args['link_after'];
 960                  if ( $i != $page || ! $more && 1 == $page ) {
 961                      $link = _wp_link_page( $i ) . $link . '</a>';
 962                  } elseif ( $i === $page ) {
 963                      $link = '<span class="post-page-numbers current" aria-current="' . esc_attr( $parsed_args['aria_current'] ) . '">' . $link . '</span>';
 964                  }
 965                  /**
 966                   * Filters the HTML output of individual page number links.
 967                   *
 968                   * @since 3.6.0
 969                   *
 970                   * @param string $link The page number HTML output.
 971                   * @param int    $i    Page number for paginated posts' page links.
 972                   */
 973                  $link = apply_filters( 'wp_link_pages_link', $link, $i );
 974  
 975                  // Use the custom links separator beginning with the second link.
 976                  $output .= ( 1 === $i ) ? ' ' : $parsed_args['separator'];
 977                  $output .= $link;
 978              }
 979              $output .= $parsed_args['after'];
 980          } elseif ( $more ) {
 981              $output .= $parsed_args['before'];
 982              $prev    = $page - 1;
 983              if ( $prev > 0 ) {
 984                  $link = _wp_link_page( $prev ) . $parsed_args['link_before'] . $parsed_args['previouspagelink'] . $parsed_args['link_after'] . '</a>';
 985  
 986                  /** This filter is documented in wp-includes/post-template.php */
 987                  $output .= apply_filters( 'wp_link_pages_link', $link, $prev );
 988              }
 989              $next = $page + 1;
 990              if ( $next <= $numpages ) {
 991                  if ( $prev ) {
 992                      $output .= $parsed_args['separator'];
 993                  }
 994                  $link = _wp_link_page( $next ) . $parsed_args['link_before'] . $parsed_args['nextpagelink'] . $parsed_args['link_after'] . '</a>';
 995  
 996                  /** This filter is documented in wp-includes/post-template.php */
 997                  $output .= apply_filters( 'wp_link_pages_link', $link, $next );
 998              }
 999              $output .= $parsed_args['after'];
1000          }
1001      }
1002  
1003      /**
1004       * Filters the HTML output of page links for paginated posts.
1005       *
1006       * @since 3.6.0
1007       *
1008       * @param string       $output HTML output of paginated posts' page links.
1009       * @param array|string $args   An array or query string of arguments. See wp_link_pages()
1010       *                             for information on accepted arguments.
1011       */
1012      $html = apply_filters( 'wp_link_pages', $output, $args );
1013  
1014      if ( $parsed_args['echo'] ) {
1015          echo $html;
1016      }
1017      return $html;
1018  }
1019  
1020  /**
1021   * Helper function for wp_link_pages().
1022   *
1023   * @since 3.1.0
1024   * @access private
1025   *
1026   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
1027   *
1028   * @param int $i Page number.
1029   * @return string Link.
1030   */
1031  function _wp_link_page( $i ) {
1032      global $wp_rewrite;
1033      $post       = get_post();
1034      $query_args = array();
1035  
1036      if ( 1 == $i ) {
1037          $url = get_permalink();
1038      } else {
1039          if ( ! get_option( 'permalink_structure' ) || in_array( $post->post_status, array( 'draft', 'pending' ), true ) ) {
1040              $url = add_query_arg( 'page', $i, get_permalink() );
1041          } elseif ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) {
1042              $url = trailingslashit( get_permalink() ) . user_trailingslashit( "$wp_rewrite->pagination_base/" . $i, 'single_paged' );
1043          } else {
1044              $url = trailingslashit( get_permalink() ) . user_trailingslashit( $i, 'single_paged' );
1045          }
1046      }
1047  
1048      if ( is_preview() ) {
1049  
1050          if ( ( 'draft' !== $post->post_status ) && isset( $_GET['preview_id'], $_GET['preview_nonce'] ) ) {
1051              $query_args['preview_id']    = wp_unslash( $_GET['preview_id'] );
1052              $query_args['preview_nonce'] = wp_unslash( $_GET['preview_nonce'] );
1053          }
1054  
1055          $url = get_preview_post_link( $post, $query_args, $url );
1056      }
1057  
1058      return '<a href="' . esc_url( $url ) . '" class="post-page-numbers">';
1059  }
1060  
1061  //
1062  // Post-meta: Custom per-post fields.
1063  //
1064  
1065  /**
1066   * Retrieves post custom meta data field.
1067   *
1068   * @since 1.5.0
1069   *
1070   * @param string $key Meta data key name.
1071   * @return array|string|false Array of values, or single value if only one element exists.
1072   *                            False if the key does not exist.
1073   */
1074  function post_custom( $key = '' ) {
1075      $custom = get_post_custom();
1076  
1077      if ( ! isset( $custom[ $key ] ) ) {
1078          return false;
1079      } elseif ( 1 === count( $custom[ $key ] ) ) {
1080          return $custom[ $key ][0];
1081      } else {
1082          return $custom[ $key ];
1083      }
1084  }
1085  
1086  /**
1087   * Displays a list of post custom fields.
1088   *
1089   * @since 1.2.0
1090   *
1091   * @internal This will probably change at some point...
1092   */
1093  function the_meta() {
1094      $keys = get_post_custom_keys();
1095      if ( $keys ) {
1096          $li_html = '';
1097          foreach ( (array) $keys as $key ) {
1098              $keyt = trim( $key );
1099              if ( is_protected_meta( $keyt, 'post' ) ) {
1100                  continue;
1101              }
1102  
1103              $values = array_map( 'trim', get_post_custom_values( $key ) );
1104              $value  = implode( ', ', $values );
1105  
1106              $html = sprintf(
1107                  "<li><span class='post-meta-key'>%s</span> %s</li>\n",
1108                  /* translators: %s: Post custom field name. */
1109                  sprintf( _x( '%s:', 'Post custom field name' ), $key ),
1110                  $value
1111              );
1112  
1113              /**
1114               * Filters the HTML output of the li element in the post custom fields list.
1115               *
1116               * @since 2.2.0
1117               *
1118               * @param string $html  The HTML output for the li element.
1119               * @param string $key   Meta key.
1120               * @param string $value Meta value.
1121               */
1122              $li_html .= apply_filters( 'the_meta_key', $html, $key, $value );
1123          }
1124  
1125          if ( $li_html ) {
1126              echo "<ul class='post-meta'>\n{$li_html}</ul>\n";
1127          }
1128      }
1129  }
1130  
1131  //
1132  // Pages.
1133  //
1134  
1135  /**
1136   * Retrieves or displays a list of pages as a dropdown (select list).
1137   *
1138   * @since 2.1.0
1139   * @since 4.2.0 The `$value_field` argument was added.
1140   * @since 4.3.0 The `$class` argument was added.
1141   *
1142   * @see get_pages()
1143   *
1144   * @param array|string $args {
1145   *     Optional. Array or string of arguments to generate a page dropdown. See `get_pages()` for additional arguments.
1146   *
1147   *     @type int          $depth                 Maximum depth. Default 0.
1148   *     @type int          $child_of              Page ID to retrieve child pages of. Default 0.
1149   *     @type int|string   $selected              Value of the option that should be selected. Default 0.
1150   *     @type bool|int     $echo                  Whether to echo or return the generated markup. Accepts 0, 1,
1151   *                                               or their bool equivalents. Default 1.
1152   *     @type string       $name                  Value for the 'name' attribute of the select element.
1153   *                                               Default 'page_id'.
1154   *     @type string       $id                    Value for the 'id' attribute of the select element.
1155   *     @type string       $class                 Value for the 'class' attribute of the select element. Default: none.
1156   *                                               Defaults to the value of `$name`.
1157   *     @type string       $show_option_none      Text to display for showing no pages. Default empty (does not display).
1158   *     @type string       $show_option_no_change Text to display for "no change" option. Default empty (does not display).
1159   *     @type string       $option_none_value     Value to use when no page is selected. Default empty.
1160   *     @type string       $value_field           Post field used to populate the 'value' attribute of the option
1161   *                                               elements. Accepts any valid post field. Default 'ID'.
1162   * }
1163   * @return string HTML dropdown list of pages.
1164   */
1165  function wp_dropdown_pages( $args = '' ) {
1166      $defaults = array(
1167          'depth'                 => 0,
1168          'child_of'              => 0,
1169          'selected'              => 0,
1170          'echo'                  => 1,
1171          'name'                  => 'page_id',
1172          'id'                    => '',
1173          'class'                 => '',
1174          'show_option_none'      => '',
1175          'show_option_no_change' => '',
1176          'option_none_value'     => '',
1177          'value_field'           => 'ID',
1178      );
1179  
1180      $parsed_args = wp_parse_args( $args, $defaults );
1181  
1182      $pages  = get_pages( $parsed_args );
1183      $output = '';
1184      // Back-compat with old system where both id and name were based on $name argument.
1185      if ( empty( $parsed_args['id'] ) ) {
1186          $parsed_args['id'] = $parsed_args['name'];
1187      }
1188  
1189      if ( ! empty( $pages ) ) {
1190          $class = '';
1191          if ( ! empty( $parsed_args['class'] ) ) {
1192              $class = " class='" . esc_attr( $parsed_args['class'] ) . "'";
1193          }
1194  
1195          $output = "<select name='" . esc_attr( $parsed_args['name'] ) . "'" . $class . " id='" . esc_attr( $parsed_args['id'] ) . "'>\n";
1196          if ( $parsed_args['show_option_no_change'] ) {
1197              $output .= "\t<option value=\"-1\">" . $parsed_args['show_option_no_change'] . "</option>\n";
1198          }
1199          if ( $parsed_args['show_option_none'] ) {
1200              $output .= "\t<option value=\"" . esc_attr( $parsed_args['option_none_value'] ) . '">' . $parsed_args['show_option_none'] . "</option>\n";
1201          }
1202          $output .= walk_page_dropdown_tree( $pages, $parsed_args['depth'], $parsed_args );
1203          $output .= "</select>\n";
1204      }
1205  
1206      /**
1207       * Filters the HTML output of a list of pages as a drop down.
1208       *
1209       * @since 2.1.0
1210       * @since 4.4.0 `$parsed_args` and `$pages` added as arguments.
1211       *
1212       * @param string    $output      HTML output for drop down list of pages.
1213       * @param array     $parsed_args The parsed arguments array. See wp_dropdown_pages()
1214       *                               for information on accepted arguments.
1215       * @param WP_Post[] $pages       Array of the page objects.
1216       */
1217      $html = apply_filters( 'wp_dropdown_pages', $output, $parsed_args, $pages );
1218  
1219      if ( $parsed_args['echo'] ) {
1220          echo $html;
1221      }
1222  
1223      return $html;
1224  }
1225  
1226  /**
1227   * Retrieves or displays a list of pages (or hierarchical post type items) in list (li) format.
1228   *
1229   * @since 1.5.0
1230   * @since 4.7.0 Added the `item_spacing` argument.
1231   *
1232   * @see get_pages()
1233   *
1234   * @global WP_Query $wp_query WordPress Query object.
1235   *
1236   * @param array|string $args {
1237   *     Optional. Array or string of arguments to generate a list of pages. See `get_pages()` for additional arguments.
1238   *
1239   *     @type int          $child_of     Display only the sub-pages of a single page by ID. Default 0 (all pages).
1240   *     @type string       $authors      Comma-separated list of author IDs. Default empty (all authors).
1241   *     @type string       $date_format  PHP date format to use for the listed pages. Relies on the 'show_date' parameter.
1242   *                                      Default is the value of 'date_format' option.
1243   *     @type int          $depth        Number of levels in the hierarchy of pages to include in the generated list.
1244   *                                      Accepts -1 (any depth), 0 (all pages), 1 (top-level pages only), and n (pages to
1245   *                                      the given n depth). Default 0.
1246   *     @type bool         $echo         Whether or not to echo the list of pages. Default true.
1247   *     @type string       $exclude      Comma-separated list of page IDs to exclude. Default empty.
1248   *     @type array        $include      Comma-separated list of page IDs to include. Default empty.
1249   *     @type string       $link_after   Text or HTML to follow the page link label. Default null.
1250   *     @type string       $link_before  Text or HTML to precede the page link label. Default null.
1251   *     @type string       $post_type    Post type to query for. Default 'page'.
1252   *     @type string|array $post_status  Comma-separated list or array of post statuses to include. Default 'publish'.
1253   *     @type string       $show_date    Whether to display the page publish or modified date for each page. Accepts
1254   *                                      'modified' or any other value. An empty value hides the date. Default empty.
1255   *     @type string       $sort_column  Comma-separated list of column names to sort the pages by. Accepts 'post_author',
1256   *                                      'post_date', 'post_title', 'post_name', 'post_modified', 'post_modified_gmt',
1257   *                                      'menu_order', 'post_parent', 'ID', 'rand', or 'comment_count'. Default 'post_title'.
1258   *     @type string       $title_li     List heading. Passing a null or empty value will result in no heading, and the list
1259   *                                      will not be wrapped with unordered list `<ul>` tags. Default 'Pages'.
1260   *     @type string       $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve' or 'discard'.
1261   *                                      Default 'preserve'.
1262   *     @type Walker       $walker       Walker instance to use for listing pages. Default empty which results in a
1263   *                                      Walker_Page instance being used.
1264   * }
1265   * @return void|string Void if 'echo' argument is true, HTML list of pages if 'echo' is false.
1266   */
1267  function wp_list_pages( $args = '' ) {
1268      $defaults = array(
1269          'depth'        => 0,
1270          'show_date'    => '',
1271          'date_format'  => get_option( 'date_format' ),
1272          'child_of'     => 0,
1273          'exclude'      => '',
1274          'title_li'     => __( 'Pages' ),
1275          'echo'         => 1,
1276          'authors'      => '',
1277          'sort_column'  => 'menu_order, post_title',
1278          'link_before'  => '',
1279          'link_after'   => '',
1280          'item_spacing' => 'preserve',
1281          'walker'       => '',
1282      );
1283  
1284      $parsed_args = wp_parse_args( $args, $defaults );
1285  
1286      if ( ! in_array( $parsed_args['item_spacing'], array( 'preserve', 'discard' ), true ) ) {
1287          // Invalid value, fall back to default.
1288          $parsed_args['item_spacing'] = $defaults['item_spacing'];
1289      }
1290  
1291      $output       = '';
1292      $current_page = 0;
1293  
1294      // Sanitize, mostly to keep spaces out.
1295      $parsed_args['exclude'] = preg_replace( '/[^0-9,]/', '', $parsed_args['exclude'] );
1296  
1297      // Allow plugins to filter an array of excluded pages (but don't put a nullstring into the array).
1298      $exclude_array = ( $parsed_args['exclude'] ) ? explode( ',', $parsed_args['exclude'] ) : array();
1299  
1300      /**
1301       * Filters the array of pages to exclude from the pages list.
1302       *
1303       * @since 2.1.0
1304       *
1305       * @param string[] $exclude_array An array of page IDs to exclude.
1306       */
1307      $parsed_args['exclude'] = implode( ',', apply_filters( 'wp_list_pages_excludes', $exclude_array ) );
1308  
1309      $parsed_args['hierarchical'] = 0;
1310  
1311      // Query pages.
1312      $pages = get_pages( $parsed_args );
1313  
1314      if ( ! empty( $pages ) ) {
1315          if ( $parsed_args['title_li'] ) {
1316              $output .= '<li class="pagenav">' . $parsed_args['title_li'] . '<ul>';
1317          }
1318          global $wp_query;
1319          if ( is_page() || is_attachment() || $wp_query->is_posts_page ) {
1320              $current_page = get_queried_object_id();
1321          } elseif ( is_singular() ) {
1322              $queried_object = get_queried_object();
1323              if ( is_post_type_hierarchical( $queried_object->post_type ) ) {
1324                  $current_page = $queried_object->ID;
1325              }
1326          }
1327  
1328          $output .= walk_page_tree( $pages, $parsed_args['depth'], $current_page, $parsed_args );
1329  
1330          if ( $parsed_args['title_li'] ) {
1331              $output .= '</ul></li>';
1332          }
1333      }
1334  
1335      /**
1336       * Filters the HTML output of the pages to list.
1337       *
1338       * @since 1.5.1
1339       * @since 4.4.0 `$pages` added as arguments.
1340       *
1341       * @see wp_list_pages()
1342       *
1343       * @param string    $output      HTML output of the pages list.
1344       * @param array     $parsed_args An array of page-listing arguments. See wp_list_pages()
1345       *                               for information on accepted arguments.
1346       * @param WP_Post[] $pages       Array of the page objects.
1347       */
1348      $html = apply_filters( 'wp_list_pages', $output, $parsed_args, $pages );
1349  
1350      if ( $parsed_args['echo'] ) {
1351          echo $html;
1352      } else {
1353          return $html;
1354      }
1355  }
1356  
1357  /**
1358   * Displays or retrieves a list of pages with an optional home link.
1359   *
1360   * The arguments are listed below and part of the arguments are for wp_list_pages() function.
1361   * Check that function for more info on those arguments.
1362   *
1363   * @since 2.7.0
1364   * @since 4.4.0 Added `menu_id`, `container`, `before`, `after`, and `walker` arguments.
1365   * @since 4.7.0 Added the `item_spacing` argument.
1366   *
1367   * @param array|string $args {
1368   *     Optional. Array or string of arguments to generate a page menu. See `wp_list_pages()` for additional arguments.
1369   *
1370   *     @type string          $sort_column  How to sort the list of pages. Accepts post column names.
1371   *                                         Default 'menu_order, post_title'.
1372   *     @type string          $menu_id      ID for the div containing the page list. Default is empty string.
1373   *     @type string          $menu_class   Class to use for the element containing the page list. Default 'menu'.
1374   *     @type string          $container    Element to use for the element containing the page list. Default 'div'.
1375   *     @type bool            $echo         Whether to echo the list or return it. Accepts true (echo) or false (return).
1376   *                                         Default true.
1377   *     @type int|bool|string $show_home    Whether to display the link to the home page. Can just enter the text
1378   *                                         you'd like shown for the home link. 1|true defaults to 'Home'.
1379   *     @type string          $link_before  The HTML or text to prepend to $show_home text. Default empty.
1380   *     @type string          $link_after   The HTML or text to append to $show_home text. Default empty.
1381   *     @type string          $before       The HTML or text to prepend to the menu. Default is '<ul>'.
1382   *     @type string          $after        The HTML or text to append to the menu. Default is '</ul>'.
1383   *     @type string          $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve'
1384   *                                         or 'discard'. Default 'discard'.
1385   *     @type Walker          $walker       Walker instance to use for listing pages. Default empty which results in a
1386   *                                         Walker_Page instance being used.
1387   * }
1388   * @return void|string Void if 'echo' argument is true, HTML menu if 'echo' is false.
1389   */
1390  function wp_page_menu( $args = array() ) {
1391      $defaults = array(
1392          'sort_column'  => 'menu_order, post_title',
1393          'menu_id'      => '',
1394          'menu_class'   => 'menu',
1395          'container'    => 'div',
1396          'echo'         => true,
1397          'link_before'  => '',
1398          'link_after'   => '',
1399          'before'       => '<ul>',
1400          'after'        => '</ul>',
1401          'item_spacing' => 'discard',
1402          'walker'       => '',
1403      );
1404      $args     = wp_parse_args( $args, $defaults );
1405  
1406      if ( ! in_array( $args['item_spacing'], array( 'preserve', 'discard' ), true ) ) {
1407          // Invalid value, fall back to default.
1408          $args['item_spacing'] = $defaults['item_spacing'];
1409      }
1410  
1411      if ( 'preserve' === $args['item_spacing'] ) {
1412          $t = "\t";
1413          $n = "\n";
1414      } else {
1415          $t = '';
1416          $n = '';
1417      }
1418  
1419      /**
1420       * Filters the arguments used to generate a page-based menu.
1421       *
1422       * @since 2.7.0
1423       *
1424       * @see wp_page_menu()
1425       *
1426       * @param array $args An array of page menu arguments. See wp_page_menu()
1427       *                    for information on accepted arguments.
1428       */
1429      $args = apply_filters( 'wp_page_menu_args', $args );
1430  
1431      $menu = '';
1432  
1433      $list_args = $args;
1434  
1435      // Show Home in the menu.
1436      if ( ! empty( $args['show_home'] ) ) {
1437          if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] ) {
1438              $text = __( 'Home' );
1439          } else {
1440              $text = $args['show_home'];
1441          }
1442          $class = '';
1443          if ( is_front_page() && ! is_paged() ) {
1444              $class = 'class="current_page_item"';
1445          }
1446          $menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>';
1447          // If the front page is a page, add it to the exclude list.
1448          if ( 'page' === get_option( 'show_on_front' ) ) {
1449              if ( ! empty( $list_args['exclude'] ) ) {
1450                  $list_args['exclude'] .= ',';
1451              } else {
1452                  $list_args['exclude'] = '';
1453              }
1454              $list_args['exclude'] .= get_option( 'page_on_front' );
1455          }
1456      }
1457  
1458      $list_args['echo']     = false;
1459      $list_args['title_li'] = '';
1460      $menu                 .= wp_list_pages( $list_args );
1461  
1462      $container = sanitize_text_field( $args['container'] );
1463  
1464      // Fallback in case `wp_nav_menu()` was called without a container.
1465      if ( empty( $container ) ) {
1466          $container = 'div';
1467      }
1468  
1469      if ( $menu ) {
1470  
1471          // wp_nav_menu() doesn't set before and after.
1472          if ( isset( $args['fallback_cb'] ) &&
1473              'wp_page_menu' === $args['fallback_cb'] &&
1474              'ul' !== $container ) {
1475              $args['before'] = "<ul>{$n}";
1476              $args['after']  = '</ul>';
1477          }
1478  
1479          $menu = $args['before'] . $menu . $args['after'];
1480      }
1481  
1482      $attrs = '';
1483      if ( ! empty( $args['menu_id'] ) ) {
1484          $attrs .= ' id="' . esc_attr( $args['menu_id'] ) . '"';
1485      }
1486  
1487      if ( ! empty( $args['menu_class'] ) ) {
1488          $attrs .= ' class="' . esc_attr( $args['menu_class'] ) . '"';
1489      }
1490  
1491      $menu = "<{$container}{$attrs}>" . $menu . "</{$container}>{$n}";
1492  
1493      /**
1494       * Filters the HTML output of a page-based menu.
1495       *
1496       * @since 2.7.0
1497       *
1498       * @see wp_page_menu()
1499       *
1500       * @param string $menu The HTML output.
1501       * @param array  $args An array of arguments. See wp_page_menu()
1502       *                     for information on accepted arguments.
1503       */
1504      $menu = apply_filters( 'wp_page_menu', $menu, $args );
1505  
1506      if ( $args['echo'] ) {
1507          echo $menu;
1508      } else {
1509          return $menu;
1510      }
1511  }
1512  
1513  //
1514  // Page helpers.
1515  //
1516  
1517  /**
1518   * Retrieves HTML list content for page list.
1519   *
1520   * @uses Walker_Page to create HTML list content.
1521   * @since 2.1.0
1522   *
1523   * @param array $pages
1524   * @param int   $depth
1525   * @param int   $current_page
1526   * @param array $args
1527   * @return string
1528   */
1529  function walk_page_tree( $pages, $depth, $current_page, $args ) {
1530      if ( empty( $args['walker'] ) ) {
1531          $walker = new Walker_Page;
1532      } else {
1533          /**
1534           * @var Walker $walker
1535           */
1536          $walker = $args['walker'];
1537      }
1538  
1539      foreach ( (array) $pages as $page ) {
1540          if ( $page->post_parent ) {
1541              $args['pages_with_children'][ $page->post_parent ] = true;
1542          }
1543      }
1544  
1545      return $walker->walk( $pages, $depth, $args, $current_page );
1546  }
1547  
1548  /**
1549   * Retrieves HTML dropdown (select) content for page list.
1550   *
1551   * @since 2.1.0
1552   * @since 5.3.0 Formalized the existing `...$args` parameter by adding it
1553   *              to the function signature.
1554   *
1555   * @uses Walker_PageDropdown to create HTML dropdown content.
1556   * @see Walker_PageDropdown::walk() for parameters and return description.
1557   *
1558   * @param mixed ...$args Elements array, maximum hierarchical depth and optional additional arguments.
1559   * @return string
1560   */
1561  function walk_page_dropdown_tree( ...$args ) {
1562      if ( empty( $args[2]['walker'] ) ) { // The user's options are the third parameter.
1563          $walker = new Walker_PageDropdown;
1564      } else {
1565          /**
1566           * @var Walker $walker
1567           */
1568          $walker = $args[2]['walker'];
1569      }
1570  
1571      return $walker->walk( ...$args );
1572  }
1573  
1574  //
1575  // Attachments.
1576  //
1577  
1578  /**
1579   * Displays an attachment page link using an image or icon.
1580   *
1581   * @since 2.0.0
1582   *
1583   * @param int|WP_Post $id Optional. Post ID or post object.
1584   * @param bool        $fullsize     Optional. Whether to use full size. Default false.
1585   * @param bool        $deprecated   Deprecated. Not used.
1586   * @param bool        $permalink    Optional. Whether to include permalink. Default false.
1587   */
1588  function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) {
1589      if ( ! empty( $deprecated ) ) {
1590          _deprecated_argument( __FUNCTION__, '2.5.0' );
1591      }
1592  
1593      if ( $fullsize ) {
1594          echo wp_get_attachment_link( $id, 'full', $permalink );
1595      } else {
1596          echo wp_get_attachment_link( $id, 'thumbnail', $permalink );
1597      }
1598  }
1599  
1600  /**
1601   * Retrieves an attachment page link using an image or icon, if possible.
1602   *
1603   * @since 2.5.0
1604   * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
1605   *
1606   * @param int|WP_Post  $id        Optional. Post ID or post object.
1607   * @param string|int[] $size      Optional. Image size. Accepts any registered image size name, or an array
1608   *                                of width and height values in pixels (in that order). Default 'thumbnail'.
1609   * @param bool         $permalink Optional. Whether to add permalink to image. Default false.
1610   * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
1611   * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
1612   *                                Default false.
1613   * @param array|string $attr      Optional. Array or string of attributes. Default empty.
1614   * @return string HTML content.
1615   */
1616  function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '' ) {
1617      $_post = get_post( $id );
1618  
1619      if ( empty( $_post ) || ( 'attachment' !== $_post->post_type ) || ! wp_get_attachment_url( $_post->ID ) ) {
1620          return __( 'Missing Attachment' );
1621      }
1622  
1623      $url = wp_get_attachment_url( $_post->ID );
1624  
1625      if ( $permalink ) {
1626          $url = get_attachment_link( $_post->ID );
1627      }
1628  
1629      if ( $text ) {
1630          $link_text = $text;
1631      } elseif ( $size && 'none' !== $size ) {
1632          $link_text = wp_get_attachment_image( $_post->ID, $size, $icon, $attr );
1633      } else {
1634          $link_text = '';
1635      }
1636  
1637      if ( '' === trim( $link_text ) ) {
1638          $link_text = $_post->post_title;
1639      }
1640  
1641      if ( '' === trim( $link_text ) ) {
1642          $link_text = esc_html( pathinfo( get_attached_file( $_post->ID ), PATHINFO_FILENAME ) );
1643      }
1644      /**
1645       * Filters a retrieved attachment page link.
1646       *
1647       * @since 2.7.0
1648       * @since 5.1.0 Added the `$attr` parameter.
1649       *
1650       * @param string       $link_html The page link HTML output.
1651       * @param int|WP_Post  $id        Post ID or object. Can be 0 for the current global post.
1652       * @param string|int[] $size      Requested image size. Can be any registered image size name, or
1653       *                                an array of width and height values in pixels (in that order).
1654       * @param bool         $permalink Whether to add permalink to image. Default false.
1655       * @param bool         $icon      Whether to include an icon.
1656       * @param string|false $text      If string, will be link text.
1657       * @param array|string $attr      Array or string of attributes.
1658       */
1659      return apply_filters( 'wp_get_attachment_link', "<a href='" . esc_url( $url ) . "'>$link_text</a>", $id, $size, $permalink, $icon, $text, $attr );
1660  }
1661  
1662  /**
1663   * Wraps attachment in paragraph tag before content.
1664   *
1665   * @since 2.0.0
1666   *
1667   * @param string $content
1668   * @return string
1669   */
1670  function prepend_attachment( $content ) {
1671      $post = get_post();
1672  
1673      if ( empty( $post->post_type ) || 'attachment' !== $post->post_type ) {
1674          return $content;
1675      }
1676  
1677      if ( wp_attachment_is( 'video', $post ) ) {
1678          $meta = wp_get_attachment_metadata( get_the_ID() );
1679          $atts = array( 'src' => wp_get_attachment_url() );
1680          if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) {
1681              $atts['width']  = (int) $meta['width'];
1682              $atts['height'] = (int) $meta['height'];
1683          }
1684          if ( has_post_thumbnail() ) {
1685              $atts['poster'] = wp_get_attachment_url( get_post_thumbnail_id() );
1686          }
1687          $p = wp_video_shortcode( $atts );
1688      } elseif ( wp_attachment_is( 'audio', $post ) ) {
1689          $p = wp_audio_shortcode( array( 'src' => wp_get_attachment_url() ) );
1690      } else {
1691          $p = '<p class="attachment">';
1692          // Show the medium sized image representation of the attachment if available, and link to the raw file.
1693          $p .= wp_get_attachment_link( 0, 'medium', false );
1694          $p .= '</p>';
1695      }
1696  
1697      /**
1698       * Filters the attachment markup to be prepended to the post content.
1699       *
1700       * @since 2.0.0
1701       *
1702       * @see prepend_attachment()
1703       *
1704       * @param string $p The attachment HTML output.
1705       */
1706      $p = apply_filters( 'prepend_attachment', $p );
1707  
1708      return "$p\n$content";
1709  }
1710  
1711  //
1712  // Misc.
1713  //
1714  
1715  /**
1716   * Retrieves protected post password form content.
1717   *
1718   * @since 1.0.0
1719   *
1720   * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
1721   * @return string HTML content for password form for password protected post.
1722   */
1723  function get_the_password_form( $post = 0 ) {
1724      $post   = get_post( $post );
1725      $label  = 'pwbox-' . ( empty( $post->ID ) ? rand() : $post->ID );
1726      $output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post">
1727      <p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p>
1728      <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>
1729      ';
1730  
1731      /**
1732       * Filters the HTML output for the protected post password form.
1733       *
1734       * If modifying the password field, please note that the core database schema
1735       * limits the password field to 20 characters regardless of the value of the
1736       * size attribute in the form input.
1737       *
1738       * @since 2.7.0
1739       * @since 5.8.0 Added the `$post` parameter.
1740       *
1741       * @param string  $output The password form HTML output.
1742       * @param WP_Post $post   Post object.
1743       */
1744      return apply_filters( 'the_password_form', $output, $post );
1745  }
1746  
1747  /**
1748   * Determines whether the current post uses a page template.
1749   *
1750   * This template tag allows you to determine if you are in a page template.
1751   * You can optionally provide a template filename or array of template filenames
1752   * and then the check will be specific to that template.
1753   *
1754   * For more information on this and similar theme functions, check out
1755   * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
1756   * Conditional Tags} article in the Theme Developer Handbook.
1757   *
1758   * @since 2.5.0
1759   * @since 4.2.0 The `$template` parameter was changed to also accept an array of page templates.
1760   * @since 4.7.0 Now works with any post type, not just pages.
1761   *
1762   * @param string|string[] $template The specific template filename or array of templates to match.
1763   * @return bool True on success, false on failure.
1764   */
1765  function is_page_template( $template = '' ) {
1766      if ( ! is_singular() ) {
1767          return false;
1768      }
1769  
1770      $page_template = get_page_template_slug( get_queried_object_id() );
1771  
1772      if ( empty( $template ) ) {
1773          return (bool) $page_template;
1774      }
1775  
1776      if ( $template == $page_template ) {
1777          return true;
1778      }
1779  
1780      if ( is_array( $template ) ) {
1781          if ( ( in_array( 'default', $template, true ) && ! $page_template )
1782              || in_array( $page_template, $template, true )
1783          ) {
1784              return true;
1785          }
1786      }
1787  
1788      return ( 'default' === $template && ! $page_template );
1789  }
1790  
1791  /**
1792   * Gets the specific template filename for a given post.
1793   *
1794   * @since 3.4.0
1795   * @since 4.7.0 Now works with any post type, not just pages.
1796   *
1797   * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
1798   * @return string|false Page template filename. Returns an empty string when the default page template
1799   *                      is in use. Returns false if the post does not exist.
1800   */
1801  function get_page_template_slug( $post = null ) {
1802      $post = get_post( $post );
1803  
1804      if ( ! $post ) {
1805          return false;
1806      }
1807  
1808      $template = get_post_meta( $post->ID, '_wp_page_template', true );
1809  
1810      if ( ! $template || 'default' === $template ) {
1811          return '';
1812      }
1813  
1814      return $template;
1815  }
1816  
1817  /**
1818   * Retrieves formatted date timestamp of a revision (linked to that revisions's page).
1819   *
1820   * @since 2.6.0
1821   *
1822   * @param int|object $revision Revision ID or revision object.
1823   * @param bool       $link     Optional. Whether to link to revision's page. Default true.
1824   * @return string|false i18n formatted datetimestamp or localized 'Current Revision'.
1825   */
1826  function wp_post_revision_title( $revision, $link = true ) {
1827      $revision = get_post( $revision );
1828      if ( ! $revision ) {
1829          return $revision;
1830      }
1831  
1832      if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ), true ) ) {
1833          return false;
1834      }
1835  
1836      /* translators: Revision date format, see https://www.php.net/manual/datetime.format.php */
1837      $datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
1838      /* translators: %s: Revision date. */
1839      $autosavef = __( '%s [Autosave]' );
1840      /* translators: %s: Revision date. */
1841      $currentf = __( '%s [Current Revision]' );
1842  
1843      $date      = date_i18n( $datef, strtotime( $revision->post_modified ) );
1844      $edit_link = get_edit_post_link( $revision->ID );
1845      if ( $link && current_user_can( 'edit_post', $revision->ID ) && $edit_link ) {
1846          $date = "<a href='$edit_link'>$date</a>";
1847      }
1848  
1849      if ( ! wp_is_post_revision( $revision ) ) {
1850          $date = sprintf( $currentf, $date );
1851      } elseif ( wp_is_post_autosave( $revision ) ) {
1852          $date = sprintf( $autosavef, $date );
1853      }
1854  
1855      return $date;
1856  }
1857  
1858  /**
1859   * Retrieves formatted date timestamp of a revision (linked to that revisions's page).
1860   *
1861   * @since 3.6.0
1862   *
1863   * @param int|object $revision Revision ID or revision object.
1864   * @param bool       $link     Optional. Whether to link to revision's page. Default true.
1865   * @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'.
1866   */
1867  function wp_post_revision_title_expanded( $revision, $link = true ) {
1868      $revision = get_post( $revision );
1869      if ( ! $revision ) {
1870          return $revision;
1871      }
1872  
1873      if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ), true ) ) {
1874          return false;
1875      }
1876  
1877      $author = get_the_author_meta( 'display_name', $revision->post_author );
1878      /* translators: Revision date format, see https://www.php.net/manual/datetime.format.php */
1879      $datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
1880  
1881      $gravatar = get_avatar( $revision->post_author, 24 );
1882  
1883      $date      = date_i18n( $datef, strtotime( $revision->post_modified ) );
1884      $edit_link = get_edit_post_link( $revision->ID );
1885      if ( $link && current_user_can( 'edit_post', $revision->ID ) && $edit_link ) {
1886          $date = "<a href='$edit_link'>$date</a>";
1887      }
1888  
1889      $revision_date_author = sprintf(
1890          /* translators: Post revision title. 1: Author avatar, 2: Author name, 3: Time ago, 4: Date. */
1891          __( '%1$s %2$s, %3$s ago (%4$s)' ),
1892          $gravatar,
1893          $author,
1894          human_time_diff( strtotime( $revision->post_modified_gmt ) ),
1895          $date
1896      );
1897  
1898      /* translators: %s: Revision date with author avatar. */
1899      $autosavef = __( '%s [Autosave]' );
1900      /* translators: %s: Revision date with author avatar. */
1901      $currentf = __( '%s [Current Revision]' );
1902  
1903      if ( ! wp_is_post_revision( $revision ) ) {
1904          $revision_date_author = sprintf( $currentf, $revision_date_author );
1905      } elseif ( wp_is_post_autosave( $revision ) ) {
1906          $revision_date_author = sprintf( $autosavef, $revision_date_author );
1907      }
1908  
1909      /**
1910       * Filters the formatted author and date for a revision.
1911       *
1912       * @since 4.4.0
1913       *
1914       * @param string  $revision_date_author The formatted string.
1915       * @param WP_Post $revision             The revision object.
1916       * @param bool    $link                 Whether to link to the revisions page, as passed into
1917       *                                      wp_post_revision_title_expanded().
1918       */
1919      return apply_filters( 'wp_post_revision_title_expanded', $revision_date_author, $revision, $link );
1920  }
1921  
1922  /**
1923   * Displays a list of a post's revisions.
1924   *
1925   * Can output either a UL with edit links or a TABLE with diff interface, and
1926   * restore action links.
1927   *
1928   * @since 2.6.0
1929   *
1930   * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
1931   * @param string      $type    'all' (default), 'revision' or 'autosave'
1932   */
1933  function wp_list_post_revisions( $post_id = 0, $type = 'all' ) {
1934      $post = get_post( $post_id );
1935      if ( ! $post ) {
1936          return;
1937      }
1938  
1939      // $args array with (parent, format, right, left, type) deprecated since 3.6.
1940      if ( is_array( $type ) ) {
1941          $type = ! empty( $type['type'] ) ? $type['type'] : $type;
1942          _deprecated_argument( __FUNCTION__, '3.6.0' );
1943      }
1944  
1945      $revisions = wp_get_post_revisions( $post->ID );
1946      if ( ! $revisions ) {
1947          return;
1948      }
1949  
1950      $rows = '';
1951      foreach ( $revisions as $revision ) {
1952          if ( ! current_user_can( 'read_post', $revision->ID ) ) {
1953              continue;
1954          }
1955  
1956          $is_autosave = wp_is_post_autosave( $revision );
1957          if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) ) {
1958              continue;
1959          }
1960  
1961          $rows .= "\t<li>" . wp_post_revision_title_expanded( $revision ) . "</li>\n";
1962      }
1963  
1964      echo "<div class='hide-if-js'><p>" . __( 'JavaScript must be enabled to use this feature.' ) . "</p></div>\n";
1965  
1966      echo "<ul class='post-revisions hide-if-no-js'>\n";
1967      echo $rows;
1968      echo '</ul>';
1969  }
1970  
1971  /**
1972   * Retrieves the parent post object for the given post.
1973   *
1974   * @since 5.7.0
1975   *
1976   * @param int|WP_Post|null $post Optional. Post ID or WP_Post object. Default is global $post.
1977   * @return WP_Post|null Parent post object, or null if there isn't one.
1978   */
1979  function get_post_parent( $post = null ) {
1980      $wp_post = get_post( $post );
1981      return ! empty( $wp_post->post_parent ) ? get_post( $wp_post->post_parent ) : null;
1982  }
1983  
1984  /**
1985   * Returns whether the given post has a parent post.
1986   *
1987   * @since 5.7.0
1988   *
1989   * @param int|WP_Post|null $post Optional. Post ID or WP_Post object. Default is global $post.
1990   * @return bool Whether the post has a parent post.
1991   */
1992  function has_post_parent( $post = null ) {
1993      return (bool) get_post_parent( $post );
1994  }


Generated: Tue Mar 19 01:00:02 2024 Cross-referenced by PHPXref 0.7.1