[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  <?php
   2  /**
   3   * WordPress Link Template Functions
   4   *
   5   * @package WordPress
   6   * @subpackage Template
   7   */
   8  
   9  /**
  10   * Displays the permalink for the current post.
  11   *
  12   * @since 1.2.0
  13   * @since 4.4.0 Added the `$post` parameter.
  14   *
  15   * @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`.
  16   */
  17  function the_permalink( $post = 0 ) {
  18      /**
  19       * Filters the display of the permalink for the current post.
  20       *
  21       * @since 1.5.0
  22       * @since 4.4.0 Added the `$post` parameter.
  23       *
  24       * @param string      $permalink The permalink for the current post.
  25       * @param int|WP_Post $post      Post ID, WP_Post object, or 0. Default 0.
  26       */
  27      echo esc_url( apply_filters( 'the_permalink', get_permalink( $post ), $post ) );
  28  }
  29  
  30  /**
  31   * Retrieves a trailing-slashed string if the site is set for adding trailing slashes.
  32   *
  33   * Conditionally adds a trailing slash if the permalink structure has a trailing
  34   * slash, strips the trailing slash if not. The string is passed through the
  35   * {@see 'user_trailingslashit'} filter. Will remove trailing slash from string, if
  36   * site is not set to have them.
  37   *
  38   * @since 2.2.0
  39   *
  40   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
  41   *
  42   * @param string $string      URL with or without a trailing slash.
  43   * @param string $type_of_url Optional. The type of URL being considered (e.g. single, category, etc)
  44   *                            for use in the filter. Default empty string.
  45   * @return string The URL with the trailing slash appended or stripped.
  46   */
  47  function user_trailingslashit( $string, $type_of_url = '' ) {
  48      global $wp_rewrite;
  49      if ( $wp_rewrite->use_trailing_slashes ) {
  50          $string = trailingslashit( $string );
  51      } else {
  52          $string = untrailingslashit( $string );
  53      }
  54  
  55      /**
  56       * Filters the trailing-slashed string, depending on whether the site is set to use trailing slashes.
  57       *
  58       * @since 2.2.0
  59       *
  60       * @param string $string      URL with or without a trailing slash.
  61       * @param string $type_of_url The type of URL being considered. Accepts 'single', 'single_trackback',
  62       *                            'single_feed', 'single_paged', 'commentpaged', 'paged', 'home', 'feed',
  63       *                            'category', 'page', 'year', 'month', 'day', 'post_type_archive'.
  64       */
  65      return apply_filters( 'user_trailingslashit', $string, $type_of_url );
  66  }
  67  
  68  /**
  69   * Displays the permalink anchor for the current post.
  70   *
  71   * The permalink mode title will use the post title for the 'a' element 'id'
  72   * attribute. The id mode uses 'post-' with the post ID for the 'id' attribute.
  73   *
  74   * @since 0.71
  75   *
  76   * @param string $mode Optional. Permalink mode. Accepts 'title' or 'id'. Default 'id'.
  77   */
  78  function permalink_anchor( $mode = 'id' ) {
  79      $post = get_post();
  80      switch ( strtolower( $mode ) ) {
  81          case 'title':
  82              $title = sanitize_title( $post->post_title ) . '-' . $post->ID;
  83              echo '<a id="' . $title . '"></a>';
  84              break;
  85          case 'id':
  86          default:
  87              echo '<a id="post-' . $post->ID . '"></a>';
  88              break;
  89      }
  90  }
  91  
  92  /**
  93   * Determine whether post should always use a plain permalink structure.
  94   *
  95   * @since 5.7.0
  96   *
  97   * @param WP_Post|int|null $post   Optional. Post ID or post object. Defaults to global $post.
  98   * @param bool|null        $sample Optional. Whether to force consideration based on sample links.
  99   *                                 If omitted, a sample link is generated if a post object is passed
 100   *                                 with the filter property set to 'sample'.
 101   * @return bool Whether to use a plain permalink structure.
 102   */
 103  function wp_force_plain_post_permalink( $post = null, $sample = null ) {
 104      if (
 105          null === $sample &&
 106          is_object( $post ) &&
 107          isset( $post->filter ) &&
 108          'sample' === $post->filter
 109      ) {
 110          $sample = true;
 111      } else {
 112          $post   = get_post( $post );
 113          $sample = null !== $sample ? $sample : false;
 114      }
 115  
 116      if ( ! $post ) {
 117          return true;
 118      }
 119  
 120      $post_status_obj = get_post_status_object( get_post_status( $post ) );
 121      $post_type_obj   = get_post_type_object( get_post_type( $post ) );
 122  
 123      if ( ! $post_status_obj || ! $post_type_obj ) {
 124          return true;
 125      }
 126  
 127      if (
 128          // Publicly viewable links never have plain permalinks.
 129          is_post_status_viewable( $post_status_obj ) ||
 130          (
 131              // Private posts don't have plain permalinks if the user can read them.
 132              $post_status_obj->private &&
 133              current_user_can( 'read_post', $post->ID )
 134          ) ||
 135          // Protected posts don't have plain links if getting a sample URL.
 136          ( $post_status_obj->protected && $sample )
 137      ) {
 138          return false;
 139      }
 140  
 141      return true;
 142  }
 143  
 144  /**
 145   * Retrieves the full permalink for the current post or post ID.
 146   *
 147   * This function is an alias for get_permalink().
 148   *
 149   * @since 3.9.0
 150   *
 151   * @see get_permalink()
 152   *
 153   * @param int|WP_Post $post      Optional. Post ID or post object. Default is the global `$post`.
 154   * @param bool        $leavename Optional. Whether to keep post name or page name. Default false.
 155   * @return string|false The permalink URL or false if post does not exist.
 156   */
 157  function get_the_permalink( $post = 0, $leavename = false ) {
 158      return get_permalink( $post, $leavename );
 159  }
 160  
 161  /**
 162   * Retrieves the full permalink for the current post or post ID.
 163   *
 164   * @since 1.0.0
 165   *
 166   * @param int|WP_Post $post      Optional. Post ID or post object. Default is the global `$post`.
 167   * @param bool        $leavename Optional. Whether to keep post name or page name. Default false.
 168   * @return string|false The permalink URL or false if post does not exist.
 169   */
 170  function get_permalink( $post = 0, $leavename = false ) {
 171      $rewritecode = array(
 172          '%year%',
 173          '%monthnum%',
 174          '%day%',
 175          '%hour%',
 176          '%minute%',
 177          '%second%',
 178          $leavename ? '' : '%postname%',
 179          '%post_id%',
 180          '%category%',
 181          '%author%',
 182          $leavename ? '' : '%pagename%',
 183      );
 184  
 185      if ( is_object( $post ) && isset( $post->filter ) && 'sample' === $post->filter ) {
 186          $sample = true;
 187      } else {
 188          $post   = get_post( $post );
 189          $sample = false;
 190      }
 191  
 192      if ( empty( $post->ID ) ) {
 193          return false;
 194      }
 195  
 196      if ( 'page' === $post->post_type ) {
 197          return get_page_link( $post, $leavename, $sample );
 198      } elseif ( 'attachment' === $post->post_type ) {
 199          return get_attachment_link( $post, $leavename );
 200      } elseif ( in_array( $post->post_type, get_post_types( array( '_builtin' => false ) ), true ) ) {
 201          return get_post_permalink( $post, $leavename, $sample );
 202      }
 203  
 204      $permalink = get_option( 'permalink_structure' );
 205  
 206      /**
 207       * Filters the permalink structure for a post before token replacement occurs.
 208       *
 209       * Only applies to posts with post_type of 'post'.
 210       *
 211       * @since 3.0.0
 212       *
 213       * @param string  $permalink The site's permalink structure.
 214       * @param WP_Post $post      The post in question.
 215       * @param bool    $leavename Whether to keep the post name.
 216       */
 217      $permalink = apply_filters( 'pre_post_link', $permalink, $post, $leavename );
 218  
 219      if (
 220          $permalink &&
 221          ! wp_force_plain_post_permalink( $post )
 222      ) {
 223  
 224          $category = '';
 225          if ( strpos( $permalink, '%category%' ) !== false ) {
 226              $cats = get_the_category( $post->ID );
 227              if ( $cats ) {
 228                  $cats = wp_list_sort(
 229                      $cats,
 230                      array(
 231                          'term_id' => 'ASC',
 232                      )
 233                  );
 234  
 235                  /**
 236                   * Filters the category that gets used in the %category% permalink token.
 237                   *
 238                   * @since 3.5.0
 239                   *
 240                   * @param WP_Term  $cat  The category to use in the permalink.
 241                   * @param array    $cats Array of all categories (WP_Term objects) associated with the post.
 242                   * @param WP_Post  $post The post in question.
 243                   */
 244                  $category_object = apply_filters( 'post_link_category', $cats[0], $cats, $post );
 245  
 246                  $category_object = get_term( $category_object, 'category' );
 247                  $category        = $category_object->slug;
 248                  if ( $category_object->parent ) {
 249                      $category = get_category_parents( $category_object->parent, false, '/', true ) . $category;
 250                  }
 251              }
 252              // Show default category in permalinks,
 253              // without having to assign it explicitly.
 254              if ( empty( $category ) ) {
 255                  $default_category = get_term( get_option( 'default_category' ), 'category' );
 256                  if ( $default_category && ! is_wp_error( $default_category ) ) {
 257                      $category = $default_category->slug;
 258                  }
 259              }
 260          }
 261  
 262          $author = '';
 263          if ( strpos( $permalink, '%author%' ) !== false ) {
 264              $authordata = get_userdata( $post->post_author );
 265              $author     = $authordata->user_nicename;
 266          }
 267  
 268          // This is not an API call because the permalink is based on the stored post_date value,
 269          // which should be parsed as local time regardless of the default PHP timezone.
 270          $date = explode( ' ', str_replace( array( '-', ':' ), ' ', $post->post_date ) );
 271  
 272          $rewritereplace = array(
 273              $date[0],
 274              $date[1],
 275              $date[2],
 276              $date[3],
 277              $date[4],
 278              $date[5],
 279              $post->post_name,
 280              $post->ID,
 281              $category,
 282              $author,
 283              $post->post_name,
 284          );
 285  
 286          $permalink = home_url( str_replace( $rewritecode, $rewritereplace, $permalink ) );
 287          $permalink = user_trailingslashit( $permalink, 'single' );
 288  
 289      } else { // If they're not using the fancy permalink option.
 290          $permalink = home_url( '?p=' . $post->ID );
 291      }
 292  
 293      /**
 294       * Filters the permalink for a post.
 295       *
 296       * Only applies to posts with post_type of 'post'.
 297       *
 298       * @since 1.5.0
 299       *
 300       * @param string  $permalink The post's permalink.
 301       * @param WP_Post $post      The post in question.
 302       * @param bool    $leavename Whether to keep the post name.
 303       */
 304      return apply_filters( 'post_link', $permalink, $post, $leavename );
 305  }
 306  
 307  /**
 308   * Retrieves the permalink for a post of a custom post type.
 309   *
 310   * @since 3.0.0
 311   *
 312   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 313   *
 314   * @param int|WP_Post $id        Optional. Post ID or post object. Default is the global `$post`.
 315   * @param bool        $leavename Optional. Whether to keep post name. Default false.
 316   * @param bool        $sample    Optional. Is it a sample permalink. Default false.
 317   * @return string|WP_Error The post permalink.
 318   */
 319  function get_post_permalink( $id = 0, $leavename = false, $sample = false ) {
 320      global $wp_rewrite;
 321  
 322      $post = get_post( $id );
 323  
 324      if ( is_wp_error( $post ) ) {
 325          return $post;
 326      }
 327  
 328      $post_link = $wp_rewrite->get_extra_permastruct( $post->post_type );
 329  
 330      $slug = $post->post_name;
 331  
 332      $force_plain_link = wp_force_plain_post_permalink( $post );
 333  
 334      $post_type = get_post_type_object( $post->post_type );
 335  
 336      if ( $post_type->hierarchical ) {
 337          $slug = get_page_uri( $post );
 338      }
 339  
 340      if ( ! empty( $post_link ) && ( ! $force_plain_link || $sample ) ) {
 341          if ( ! $leavename ) {
 342              $post_link = str_replace( "%$post->post_type%", $slug, $post_link );
 343          }
 344          $post_link = home_url( user_trailingslashit( $post_link ) );
 345      } else {
 346          if ( $post_type->query_var && ( isset( $post->post_status ) && ! $force_plain_link ) ) {
 347              $post_link = add_query_arg( $post_type->query_var, $slug, '' );
 348          } else {
 349              $post_link = add_query_arg(
 350                  array(
 351                      'post_type' => $post->post_type,
 352                      'p'         => $post->ID,
 353                  ),
 354                  ''
 355              );
 356          }
 357          $post_link = home_url( $post_link );
 358      }
 359  
 360      /**
 361       * Filters the permalink for a post of a custom post type.
 362       *
 363       * @since 3.0.0
 364       *
 365       * @param string  $post_link The post's permalink.
 366       * @param WP_Post $post      The post in question.
 367       * @param bool    $leavename Whether to keep the post name.
 368       * @param bool    $sample    Is it a sample permalink.
 369       */
 370      return apply_filters( 'post_type_link', $post_link, $post, $leavename, $sample );
 371  }
 372  
 373  /**
 374   * Retrieves the permalink for the current page or page ID.
 375   *
 376   * Respects page_on_front. Use this one.
 377   *
 378   * @since 1.5.0
 379   *
 380   * @param int|WP_Post $post      Optional. Post ID or object. Default uses the global `$post`.
 381   * @param bool        $leavename Optional. Whether to keep the page name. Default false.
 382   * @param bool        $sample    Optional. Whether it should be treated as a sample permalink.
 383   *                               Default false.
 384   * @return string The page permalink.
 385   */
 386  function get_page_link( $post = false, $leavename = false, $sample = false ) {
 387      $post = get_post( $post );
 388  
 389      if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) {
 390          $link = home_url( '/' );
 391      } else {
 392          $link = _get_page_link( $post, $leavename, $sample );
 393      }
 394  
 395      /**
 396       * Filters the permalink for a page.
 397       *
 398       * @since 1.5.0
 399       *
 400       * @param string $link    The page's permalink.
 401       * @param int    $post_id The ID of the page.
 402       * @param bool   $sample  Is it a sample permalink.
 403       */
 404      return apply_filters( 'page_link', $link, $post->ID, $sample );
 405  }
 406  
 407  /**
 408   * Retrieves the page permalink.
 409   *
 410   * Ignores page_on_front. Internal use only.
 411   *
 412   * @since 2.1.0
 413   * @access private
 414   *
 415   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 416   *
 417   * @param int|WP_Post $post      Optional. Post ID or object. Default uses the global `$post`.
 418   * @param bool        $leavename Optional. Whether to keep the page name. Default false.
 419   * @param bool        $sample    Optional. Whether it should be treated as a sample permalink.
 420   *                               Default false.
 421   * @return string The page permalink.
 422   */
 423  function _get_page_link( $post = false, $leavename = false, $sample = false ) {
 424      global $wp_rewrite;
 425  
 426      $post = get_post( $post );
 427  
 428      $force_plain_link = wp_force_plain_post_permalink( $post );
 429  
 430      $link = $wp_rewrite->get_page_permastruct();
 431  
 432      if ( ! empty( $link ) && ( ( isset( $post->post_status ) && ! $force_plain_link ) || $sample ) ) {
 433          if ( ! $leavename ) {
 434              $link = str_replace( '%pagename%', get_page_uri( $post ), $link );
 435          }
 436  
 437          $link = home_url( $link );
 438          $link = user_trailingslashit( $link, 'page' );
 439      } else {
 440          $link = home_url( '?page_id=' . $post->ID );
 441      }
 442  
 443      /**
 444       * Filters the permalink for a non-page_on_front page.
 445       *
 446       * @since 2.1.0
 447       *
 448       * @param string $link    The page's permalink.
 449       * @param int    $post_id The ID of the page.
 450       */
 451      return apply_filters( '_get_page_link', $link, $post->ID );
 452  }
 453  
 454  /**
 455   * Retrieves the permalink for an attachment.
 456   *
 457   * This can be used in the WordPress Loop or outside of it.
 458   *
 459   * @since 2.0.0
 460   *
 461   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 462   *
 463   * @param int|object $post      Optional. Post ID or object. Default uses the global `$post`.
 464   * @param bool       $leavename Optional. Whether to keep the page name. Default false.
 465   * @return string The attachment permalink.
 466   */
 467  function get_attachment_link( $post = null, $leavename = false ) {
 468      global $wp_rewrite;
 469  
 470      $link = false;
 471  
 472      $post             = get_post( $post );
 473      $force_plain_link = wp_force_plain_post_permalink( $post );
 474      $parent_id        = $post->post_parent;
 475      $parent           = $parent_id ? get_post( $parent_id ) : false;
 476      $parent_valid     = true; // Default for no parent.
 477      if (
 478          $parent_id &&
 479          (
 480              $post->post_parent === $post->ID ||
 481              ! $parent ||
 482              ! is_post_type_viewable( get_post_type( $parent ) )
 483          )
 484      ) {
 485          // Post is either its own parent or parent post unavailable.
 486          $parent_valid = false;
 487      }
 488  
 489      if ( $force_plain_link || ! $parent_valid ) {
 490          $link = false;
 491      } elseif ( $wp_rewrite->using_permalinks() && $parent ) {
 492          if ( 'page' === $parent->post_type ) {
 493              $parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front.
 494          } else {
 495              $parentlink = get_permalink( $post->post_parent );
 496          }
 497  
 498          if ( is_numeric( $post->post_name ) || false !== strpos( get_option( 'permalink_structure' ), '%category%' ) ) {
 499              $name = 'attachment/' . $post->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker.
 500          } else {
 501              $name = $post->post_name;
 502          }
 503  
 504          if ( strpos( $parentlink, '?' ) === false ) {
 505              $link = user_trailingslashit( trailingslashit( $parentlink ) . '%postname%' );
 506          }
 507  
 508          if ( ! $leavename ) {
 509              $link = str_replace( '%postname%', $name, $link );
 510          }
 511      } elseif ( $wp_rewrite->using_permalinks() && ! $leavename ) {
 512          $link = home_url( user_trailingslashit( $post->post_name ) );
 513      }
 514  
 515      if ( ! $link ) {
 516          $link = home_url( '/?attachment_id=' . $post->ID );
 517      }
 518  
 519      /**
 520       * Filters the permalink for an attachment.
 521       *
 522       * @since 2.0.0
 523       * @since 5.6.0 Providing an empty string will now disable
 524       *              the view attachment page link on the media modal.
 525       *
 526       * @param string $link    The attachment's permalink.
 527       * @param int    $post_id Attachment ID.
 528       */
 529      return apply_filters( 'attachment_link', $link, $post->ID );
 530  }
 531  
 532  /**
 533   * Retrieves the permalink for the year archives.
 534   *
 535   * @since 1.5.0
 536   *
 537   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 538   *
 539   * @param int|false $year Integer of year. False for current year.
 540   * @return string The permalink for the specified year archive.
 541   */
 542  function get_year_link( $year ) {
 543      global $wp_rewrite;
 544      if ( ! $year ) {
 545          $year = current_time( 'Y' );
 546      }
 547      $yearlink = $wp_rewrite->get_year_permastruct();
 548      if ( ! empty( $yearlink ) ) {
 549          $yearlink = str_replace( '%year%', $year, $yearlink );
 550          $yearlink = home_url( user_trailingslashit( $yearlink, 'year' ) );
 551      } else {
 552          $yearlink = home_url( '?m=' . $year );
 553      }
 554  
 555      /**
 556       * Filters the year archive permalink.
 557       *
 558       * @since 1.5.0
 559       *
 560       * @param string $yearlink Permalink for the year archive.
 561       * @param int    $year     Year for the archive.
 562       */
 563      return apply_filters( 'year_link', $yearlink, $year );
 564  }
 565  
 566  /**
 567   * Retrieves the permalink for the month archives with year.
 568   *
 569   * @since 1.0.0
 570   *
 571   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 572   *
 573   * @param int|false $year  Integer of year. False for current year.
 574   * @param int|false $month Integer of month. False for current month.
 575   * @return string The permalink for the specified month and year archive.
 576   */
 577  function get_month_link( $year, $month ) {
 578      global $wp_rewrite;
 579      if ( ! $year ) {
 580          $year = current_time( 'Y' );
 581      }
 582      if ( ! $month ) {
 583          $month = current_time( 'm' );
 584      }
 585      $monthlink = $wp_rewrite->get_month_permastruct();
 586      if ( ! empty( $monthlink ) ) {
 587          $monthlink = str_replace( '%year%', $year, $monthlink );
 588          $monthlink = str_replace( '%monthnum%', zeroise( (int) $month, 2 ), $monthlink );
 589          $monthlink = home_url( user_trailingslashit( $monthlink, 'month' ) );
 590      } else {
 591          $monthlink = home_url( '?m=' . $year . zeroise( $month, 2 ) );
 592      }
 593  
 594      /**
 595       * Filters the month archive permalink.
 596       *
 597       * @since 1.5.0
 598       *
 599       * @param string $monthlink Permalink for the month archive.
 600       * @param int    $year      Year for the archive.
 601       * @param int    $month     The month for the archive.
 602       */
 603      return apply_filters( 'month_link', $monthlink, $year, $month );
 604  }
 605  
 606  /**
 607   * Retrieves the permalink for the day archives with year and month.
 608   *
 609   * @since 1.0.0
 610   *
 611   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 612   *
 613   * @param int|false $year  Integer of year. False for current year.
 614   * @param int|false $month Integer of month. False for current month.
 615   * @param int|false $day   Integer of day. False for current day.
 616   * @return string The permalink for the specified day, month, and year archive.
 617   */
 618  function get_day_link( $year, $month, $day ) {
 619      global $wp_rewrite;
 620      if ( ! $year ) {
 621          $year = current_time( 'Y' );
 622      }
 623      if ( ! $month ) {
 624          $month = current_time( 'm' );
 625      }
 626      if ( ! $day ) {
 627          $day = current_time( 'j' );
 628      }
 629  
 630      $daylink = $wp_rewrite->get_day_permastruct();
 631      if ( ! empty( $daylink ) ) {
 632          $daylink = str_replace( '%year%', $year, $daylink );
 633          $daylink = str_replace( '%monthnum%', zeroise( (int) $month, 2 ), $daylink );
 634          $daylink = str_replace( '%day%', zeroise( (int) $day, 2 ), $daylink );
 635          $daylink = home_url( user_trailingslashit( $daylink, 'day' ) );
 636      } else {
 637          $daylink = home_url( '?m=' . $year . zeroise( $month, 2 ) . zeroise( $day, 2 ) );
 638      }
 639  
 640      /**
 641       * Filters the day archive permalink.
 642       *
 643       * @since 1.5.0
 644       *
 645       * @param string $daylink Permalink for the day archive.
 646       * @param int    $year    Year for the archive.
 647       * @param int    $month   Month for the archive.
 648       * @param int    $day     The day for the archive.
 649       */
 650      return apply_filters( 'day_link', $daylink, $year, $month, $day );
 651  }
 652  
 653  /**
 654   * Displays the permalink for the feed type.
 655   *
 656   * @since 3.0.0
 657   *
 658   * @param string $anchor The link's anchor text.
 659   * @param string $feed   Optional. Feed type. Possible values include 'rss2', 'atom'.
 660   *                       Default is the value of get_default_feed().
 661   */
 662  function the_feed_link( $anchor, $feed = '' ) {
 663      $link = '<a href="' . esc_url( get_feed_link( $feed ) ) . '">' . $anchor . '</a>';
 664  
 665      /**
 666       * Filters the feed link anchor tag.
 667       *
 668       * @since 3.0.0
 669       *
 670       * @param string $link The complete anchor tag for a feed link.
 671       * @param string $feed The feed type. Possible values include 'rss2', 'atom',
 672       *                     or an empty string for the default feed type.
 673       */
 674      echo apply_filters( 'the_feed_link', $link, $feed );
 675  }
 676  
 677  /**
 678   * Retrieves the permalink for the feed type.
 679   *
 680   * @since 1.5.0
 681   *
 682   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 683   *
 684   * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'.
 685   *                     Default is the value of get_default_feed().
 686   * @return string The feed permalink.
 687   */
 688  function get_feed_link( $feed = '' ) {
 689      global $wp_rewrite;
 690  
 691      $permalink = $wp_rewrite->get_feed_permastruct();
 692  
 693      if ( $permalink ) {
 694          if ( false !== strpos( $feed, 'comments_' ) ) {
 695              $feed      = str_replace( 'comments_', '', $feed );
 696              $permalink = $wp_rewrite->get_comment_feed_permastruct();
 697          }
 698  
 699          if ( get_default_feed() == $feed ) {
 700              $feed = '';
 701          }
 702  
 703          $permalink = str_replace( '%feed%', $feed, $permalink );
 704          $permalink = preg_replace( '#/+#', '/', "/$permalink" );
 705          $output    = home_url( user_trailingslashit( $permalink, 'feed' ) );
 706      } else {
 707          if ( empty( $feed ) ) {
 708              $feed = get_default_feed();
 709          }
 710  
 711          if ( false !== strpos( $feed, 'comments_' ) ) {
 712              $feed = str_replace( 'comments_', 'comments-', $feed );
 713          }
 714  
 715          $output = home_url( "?feed={$feed}" );
 716      }
 717  
 718      /**
 719       * Filters the feed type permalink.
 720       *
 721       * @since 1.5.0
 722       *
 723       * @param string $output The feed permalink.
 724       * @param string $feed   The feed type. Possible values include 'rss2', 'atom',
 725       *                       or an empty string for the default feed type.
 726       */
 727      return apply_filters( 'feed_link', $output, $feed );
 728  }
 729  
 730  /**
 731   * Retrieves the permalink for the post comments feed.
 732   *
 733   * @since 2.2.0
 734   *
 735   * @param int    $post_id Optional. Post ID. Default is the ID of the global `$post`.
 736   * @param string $feed    Optional. Feed type. Possible values include 'rss2', 'atom'.
 737   *                        Default is the value of get_default_feed().
 738   * @return string The permalink for the comments feed for the given post.
 739   */
 740  function get_post_comments_feed_link( $post_id = 0, $feed = '' ) {
 741      $post_id = absint( $post_id );
 742  
 743      if ( ! $post_id ) {
 744          $post_id = get_the_ID();
 745      }
 746  
 747      if ( empty( $feed ) ) {
 748          $feed = get_default_feed();
 749      }
 750  
 751      $post       = get_post( $post_id );
 752      $unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent;
 753  
 754      if ( get_option( 'permalink_structure' ) ) {
 755          if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post_id ) {
 756              $url = _get_page_link( $post_id );
 757          } else {
 758              $url = get_permalink( $post_id );
 759          }
 760  
 761          if ( $unattached ) {
 762              $url = home_url( '/feed/' );
 763              if ( get_default_feed() !== $feed ) {
 764                  $url .= "$feed/";
 765              }
 766              $url = add_query_arg( 'attachment_id', $post_id, $url );
 767          } else {
 768              $url = trailingslashit( $url ) . 'feed';
 769              if ( get_default_feed() != $feed ) {
 770                  $url .= "/$feed";
 771              }
 772              $url = user_trailingslashit( $url, 'single_feed' );
 773          }
 774      } else {
 775          if ( $unattached ) {
 776              $url = add_query_arg(
 777                  array(
 778                      'feed'          => $feed,
 779                      'attachment_id' => $post_id,
 780                  ),
 781                  home_url( '/' )
 782              );
 783          } elseif ( 'page' === $post->post_type ) {
 784              $url = add_query_arg(
 785                  array(
 786                      'feed'    => $feed,
 787                      'page_id' => $post_id,
 788                  ),
 789                  home_url( '/' )
 790              );
 791          } else {
 792              $url = add_query_arg(
 793                  array(
 794                      'feed' => $feed,
 795                      'p'    => $post_id,
 796                  ),
 797                  home_url( '/' )
 798              );
 799          }
 800      }
 801  
 802      /**
 803       * Filters the post comments feed permalink.
 804       *
 805       * @since 1.5.1
 806       *
 807       * @param string $url Post comments feed permalink.
 808       */
 809      return apply_filters( 'post_comments_feed_link', $url );
 810  }
 811  
 812  /**
 813   * Displays the comment feed link for a post.
 814   *
 815   * Prints out the comment feed link for a post. Link text is placed in the
 816   * anchor. If no link text is specified, default text is used. If no post ID is
 817   * specified, the current post is used.
 818   *
 819   * @since 2.5.0
 820   *
 821   * @param string $link_text Optional. Descriptive link text. Default 'Comments Feed'.
 822   * @param int    $post_id   Optional. Post ID. Default is the ID of the global `$post`.
 823   * @param string $feed      Optional. Feed type. Possible values include 'rss2', 'atom'.
 824   *                          Default is the value of get_default_feed().
 825   */
 826  function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) {
 827      $url = get_post_comments_feed_link( $post_id, $feed );
 828      if ( empty( $link_text ) ) {
 829          $link_text = __( 'Comments Feed' );
 830      }
 831  
 832      $link = '<a href="' . esc_url( $url ) . '">' . $link_text . '</a>';
 833      /**
 834       * Filters the post comment feed link anchor tag.
 835       *
 836       * @since 2.8.0
 837       *
 838       * @param string $link    The complete anchor tag for the comment feed link.
 839       * @param int    $post_id Post ID.
 840       * @param string $feed    The feed type. Possible values include 'rss2', 'atom',
 841       *                        or an empty string for the default feed type.
 842       */
 843      echo apply_filters( 'post_comments_feed_link_html', $link, $post_id, $feed );
 844  }
 845  
 846  /**
 847   * Retrieves the feed link for a given author.
 848   *
 849   * Returns a link to the feed for all posts by a given author. A specific feed
 850   * can be requested or left blank to get the default feed.
 851   *
 852   * @since 2.5.0
 853   *
 854   * @param int    $author_id Author ID.
 855   * @param string $feed      Optional. Feed type. Possible values include 'rss2', 'atom'.
 856   *                          Default is the value of get_default_feed().
 857   * @return string Link to the feed for the author specified by $author_id.
 858   */
 859  function get_author_feed_link( $author_id, $feed = '' ) {
 860      $author_id           = (int) $author_id;
 861      $permalink_structure = get_option( 'permalink_structure' );
 862  
 863      if ( empty( $feed ) ) {
 864          $feed = get_default_feed();
 865      }
 866  
 867      if ( ! $permalink_structure ) {
 868          $link = home_url( "?feed=$feed&amp;author=" . $author_id );
 869      } else {
 870          $link = get_author_posts_url( $author_id );
 871          if ( get_default_feed() == $feed ) {
 872              $feed_link = 'feed';
 873          } else {
 874              $feed_link = "feed/$feed";
 875          }
 876  
 877          $link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' );
 878      }
 879  
 880      /**
 881       * Filters the feed link for a given author.
 882       *
 883       * @since 1.5.1
 884       *
 885       * @param string $link The author feed link.
 886       * @param string $feed Feed type. Possible values include 'rss2', 'atom'.
 887       */
 888      $link = apply_filters( 'author_feed_link', $link, $feed );
 889  
 890      return $link;
 891  }
 892  
 893  /**
 894   * Retrieves the feed link for a category.
 895   *
 896   * Returns a link to the feed for all posts in a given category. A specific feed
 897   * can be requested or left blank to get the default feed.
 898   *
 899   * @since 2.5.0
 900   *
 901   * @param int    $cat_id Category ID.
 902   * @param string $feed   Optional. Feed type. Possible values include 'rss2', 'atom'.
 903   *                       Default is the value of get_default_feed().
 904   * @return string Link to the feed for the category specified by $cat_id.
 905   */
 906  function get_category_feed_link( $cat_id, $feed = '' ) {
 907      return get_term_feed_link( $cat_id, 'category', $feed );
 908  }
 909  
 910  /**
 911   * Retrieves the feed link for a term.
 912   *
 913   * Returns a link to the feed for all posts in a given term. A specific feed
 914   * can be requested or left blank to get the default feed.
 915   *
 916   * @since 3.0.0
 917   *
 918   * @param int    $term_id  Term ID.
 919   * @param string $taxonomy Optional. Taxonomy of `$term_id`. Default 'category'.
 920   * @param string $feed     Optional. Feed type. Possible values include 'rss2', 'atom'.
 921   *                         Default is the value of get_default_feed().
 922   * @return string|false Link to the feed for the term specified by $term_id and $taxonomy.
 923   */
 924  function get_term_feed_link( $term_id, $taxonomy = 'category', $feed = '' ) {
 925      $term_id = (int) $term_id;
 926  
 927      $term = get_term( $term_id, $taxonomy );
 928  
 929      if ( empty( $term ) || is_wp_error( $term ) ) {
 930          return false;
 931      }
 932  
 933      if ( empty( $feed ) ) {
 934          $feed = get_default_feed();
 935      }
 936  
 937      $permalink_structure = get_option( 'permalink_structure' );
 938  
 939      if ( ! $permalink_structure ) {
 940          if ( 'category' === $taxonomy ) {
 941              $link = home_url( "?feed=$feed&amp;cat=$term_id" );
 942          } elseif ( 'post_tag' === $taxonomy ) {
 943              $link = home_url( "?feed=$feed&amp;tag=$term->slug" );
 944          } else {
 945              $t    = get_taxonomy( $taxonomy );
 946              $link = home_url( "?feed=$feed&amp;$t->query_var=$term->slug" );
 947          }
 948      } else {
 949          $link = get_term_link( $term_id, $term->taxonomy );
 950          if ( get_default_feed() == $feed ) {
 951              $feed_link = 'feed';
 952          } else {
 953              $feed_link = "feed/$feed";
 954          }
 955  
 956          $link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' );
 957      }
 958  
 959      if ( 'category' === $taxonomy ) {
 960          /**
 961           * Filters the category feed link.
 962           *
 963           * @since 1.5.1
 964           *
 965           * @param string $link The category feed link.
 966           * @param string $feed Feed type. Possible values include 'rss2', 'atom'.
 967           */
 968          $link = apply_filters( 'category_feed_link', $link, $feed );
 969      } elseif ( 'post_tag' === $taxonomy ) {
 970          /**
 971           * Filters the post tag feed link.
 972           *
 973           * @since 2.3.0
 974           *
 975           * @param string $link The tag feed link.
 976           * @param string $feed Feed type. Possible values include 'rss2', 'atom'.
 977           */
 978          $link = apply_filters( 'tag_feed_link', $link, $feed );
 979      } else {
 980          /**
 981           * Filters the feed link for a taxonomy other than 'category' or 'post_tag'.
 982           *
 983           * @since 3.0.0
 984           *
 985           * @param string $link     The taxonomy feed link.
 986           * @param string $feed     Feed type. Possible values include 'rss2', 'atom'.
 987           * @param string $taxonomy The taxonomy name.
 988           */
 989          $link = apply_filters( 'taxonomy_feed_link', $link, $feed, $taxonomy );
 990      }
 991  
 992      return $link;
 993  }
 994  
 995  /**
 996   * Retrieves the permalink for a tag feed.
 997   *
 998   * @since 2.3.0
 999   *
1000   * @param int    $tag_id Tag ID.
1001   * @param string $feed   Optional. Feed type. Possible values include 'rss2', 'atom'.
1002   *                       Default is the value of get_default_feed().
1003   * @return string The feed permalink for the given tag.
1004   */
1005  function get_tag_feed_link( $tag_id, $feed = '' ) {
1006      return get_term_feed_link( $tag_id, 'post_tag', $feed );
1007  }
1008  
1009  /**
1010   * Retrieves the edit link for a tag.
1011   *
1012   * @since 2.7.0
1013   *
1014   * @param int    $tag_id   Tag ID.
1015   * @param string $taxonomy Optional. Taxonomy slug. Default 'post_tag'.
1016   * @return string The edit tag link URL for the given tag.
1017   */
1018  function get_edit_tag_link( $tag_id, $taxonomy = 'post_tag' ) {
1019      /**
1020       * Filters the edit link for a tag (or term in another taxonomy).
1021       *
1022       * @since 2.7.0
1023       *
1024       * @param string $link The term edit link.
1025       */
1026      return apply_filters( 'get_edit_tag_link', get_edit_term_link( $tag_id, $taxonomy ) );
1027  }
1028  
1029  /**
1030   * Displays or retrieves the edit link for a tag with formatting.
1031   *
1032   * @since 2.7.0
1033   *
1034   * @param string  $link   Optional. Anchor text. If empty, default is 'Edit This'. Default empty.
1035   * @param string  $before Optional. Display before edit link. Default empty.
1036   * @param string  $after  Optional. Display after edit link. Default empty.
1037   * @param WP_Term $tag    Optional. Term object. If null, the queried object will be inspected.
1038   *                        Default null.
1039   */
1040  function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) {
1041      $link = edit_term_link( $link, '', '', $tag, false );
1042  
1043      /**
1044       * Filters the anchor tag for the edit link for a tag (or term in another taxonomy).
1045       *
1046       * @since 2.7.0
1047       *
1048       * @param string $link The anchor tag for the edit link.
1049       */
1050      echo $before . apply_filters( 'edit_tag_link', $link ) . $after;
1051  }
1052  
1053  /**
1054   * Retrieves the URL for editing a given term.
1055   *
1056   * @since 3.1.0
1057   * @since 4.5.0 The `$taxonomy` parameter was made optional.
1058   *
1059   * @param int    $term_id     Term ID.
1060   * @param string $taxonomy    Optional. Taxonomy. Defaults to the taxonomy of the term identified
1061   *                            by `$term_id`.
1062   * @param string $object_type Optional. The object type. Used to highlight the proper post type
1063   *                            menu on the linked page. Defaults to the first object_type associated
1064   *                            with the taxonomy.
1065   * @return string|null The edit term link URL for the given term, or null on failure.
1066   */
1067  function get_edit_term_link( $term_id, $taxonomy = '', $object_type = '' ) {
1068      $term = get_term( $term_id, $taxonomy );
1069      if ( ! $term || is_wp_error( $term ) ) {
1070          return;
1071      }
1072  
1073      $tax = get_taxonomy( $term->taxonomy );
1074      if ( ! $tax || ! current_user_can( 'edit_term', $term->term_id ) ) {
1075          return;
1076      }
1077  
1078      $args = array(
1079          'taxonomy' => $taxonomy,
1080          'tag_ID'   => $term->term_id,
1081      );
1082  
1083      if ( $object_type ) {
1084          $args['post_type'] = $object_type;
1085      } elseif ( ! empty( $tax->object_type ) ) {
1086          $args['post_type'] = reset( $tax->object_type );
1087      }
1088  
1089      if ( $tax->show_ui ) {
1090          $location = add_query_arg( $args, admin_url( 'term.php' ) );
1091      } else {
1092          $location = '';
1093      }
1094  
1095      /**
1096       * Filters the edit link for a term.
1097       *
1098       * @since 3.1.0
1099       *
1100       * @param string $location    The edit link.
1101       * @param int    $term_id     Term ID.
1102       * @param string $taxonomy    Taxonomy name.
1103       * @param string $object_type The object type (eg. the post type).
1104       */
1105      return apply_filters( 'get_edit_term_link', $location, $term_id, $taxonomy, $object_type );
1106  }
1107  
1108  /**
1109   * Displays or retrieves the edit term link with formatting.
1110   *
1111   * @since 3.1.0
1112   *
1113   * @param string  $link   Optional. Anchor text. If empty, default is 'Edit This'. Default empty.
1114   * @param string  $before Optional. Display before edit link. Default empty.
1115   * @param string  $after  Optional. Display after edit link. Default empty.
1116   * @param WP_Term $term   Optional. Term object. If null, the queried object will be inspected. Default null.
1117   * @param bool    $echo   Optional. Whether or not to echo the return. Default true.
1118   * @return string|void HTML content.
1119   */
1120  function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) {
1121      if ( is_null( $term ) ) {
1122          $term = get_queried_object();
1123      }
1124  
1125      if ( ! $term ) {
1126          return;
1127      }
1128  
1129      $tax = get_taxonomy( $term->taxonomy );
1130      if ( ! current_user_can( 'edit_term', $term->term_id ) ) {
1131          return;
1132      }
1133  
1134      if ( empty( $link ) ) {
1135          $link = __( 'Edit This' );
1136      }
1137  
1138      $link = '<a href="' . get_edit_term_link( $term->term_id, $term->taxonomy ) . '">' . $link . '</a>';
1139  
1140      /**
1141       * Filters the anchor tag for the edit link of a term.
1142       *
1143       * @since 3.1.0
1144       *
1145       * @param string $link    The anchor tag for the edit link.
1146       * @param int    $term_id Term ID.
1147       */
1148      $link = $before . apply_filters( 'edit_term_link', $link, $term->term_id ) . $after;
1149  
1150      if ( $echo ) {
1151          echo $link;
1152      } else {
1153          return $link;
1154      }
1155  }
1156  
1157  /**
1158   * Retrieves the permalink for a search.
1159   *
1160   * @since 3.0.0
1161   *
1162   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
1163   *
1164   * @param string $query Optional. The query string to use. If empty the current query is used. Default empty.
1165   * @return string The search permalink.
1166   */
1167  function get_search_link( $query = '' ) {
1168      global $wp_rewrite;
1169  
1170      if ( empty( $query ) ) {
1171          $search = get_search_query( false );
1172      } else {
1173          $search = stripslashes( $query );
1174      }
1175  
1176      $permastruct = $wp_rewrite->get_search_permastruct();
1177  
1178      if ( empty( $permastruct ) ) {
1179          $link = home_url( '?s=' . urlencode( $search ) );
1180      } else {
1181          $search = urlencode( $search );
1182          $search = str_replace( '%2F', '/', $search ); // %2F(/) is not valid within a URL, send it un-encoded.
1183          $link   = str_replace( '%search%', $search, $permastruct );
1184          $link   = home_url( user_trailingslashit( $link, 'search' ) );
1185      }
1186  
1187      /**
1188       * Filters the search permalink.
1189       *
1190       * @since 3.0.0
1191       *
1192       * @param string $link   Search permalink.
1193       * @param string $search The URL-encoded search term.
1194       */
1195      return apply_filters( 'search_link', $link, $search );
1196  }
1197  
1198  /**
1199   * Retrieves the permalink for the search results feed.
1200   *
1201   * @since 2.5.0
1202   *
1203   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
1204   *
1205   * @param string $search_query Optional. Search query. Default empty.
1206   * @param string $feed         Optional. Feed type. Possible values include 'rss2', 'atom'.
1207   *                             Default is the value of get_default_feed().
1208   * @return string The search results feed permalink.
1209   */
1210  function get_search_feed_link( $search_query = '', $feed = '' ) {
1211      global $wp_rewrite;
1212      $link = get_search_link( $search_query );
1213  
1214      if ( empty( $feed ) ) {
1215          $feed = get_default_feed();
1216      }
1217  
1218      $permastruct = $wp_rewrite->get_search_permastruct();
1219  
1220      if ( empty( $permastruct ) ) {
1221          $link = add_query_arg( 'feed', $feed, $link );
1222      } else {
1223          $link  = trailingslashit( $link );
1224          $link .= "feed/$feed/";
1225      }
1226  
1227      /**
1228       * Filters the search feed link.
1229       *
1230       * @since 2.5.0
1231       *
1232       * @param string $link Search feed link.
1233       * @param string $feed Feed type. Possible values include 'rss2', 'atom'.
1234       * @param string $type The search type. One of 'posts' or 'comments'.
1235       */
1236      return apply_filters( 'search_feed_link', $link, $feed, 'posts' );
1237  }
1238  
1239  /**
1240   * Retrieves the permalink for the search results comments feed.
1241   *
1242   * @since 2.5.0
1243   *
1244   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
1245   *
1246   * @param string $search_query Optional. Search query. Default empty.
1247   * @param string $feed         Optional. Feed type. Possible values include 'rss2', 'atom'.
1248   *                             Default is the value of get_default_feed().
1249   * @return string The comments feed search results permalink.
1250   */
1251  function get_search_comments_feed_link( $search_query = '', $feed = '' ) {
1252      global $wp_rewrite;
1253  
1254      if ( empty( $feed ) ) {
1255          $feed = get_default_feed();
1256      }
1257  
1258      $link = get_search_feed_link( $search_query, $feed );
1259  
1260      $permastruct = $wp_rewrite->get_search_permastruct();
1261  
1262      if ( empty( $permastruct ) ) {
1263          $link = add_query_arg( 'feed', 'comments-' . $feed, $link );
1264      } else {
1265          $link = add_query_arg( 'withcomments', 1, $link );
1266      }
1267  
1268      /** This filter is documented in wp-includes/link-template.php */
1269      return apply_filters( 'search_feed_link', $link, $feed, 'comments' );
1270  }
1271  
1272  /**
1273   * Retrieves the permalink for a post type archive.
1274   *
1275   * @since 3.1.0
1276   * @since 4.5.0 Support for posts was added.
1277   *
1278   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
1279   *
1280   * @param string $post_type Post type.
1281   * @return string|false The post type archive permalink. False if the post type
1282   *                      does not exist or does not have an archive.
1283   */
1284  function get_post_type_archive_link( $post_type ) {
1285      global $wp_rewrite;
1286  
1287      $post_type_obj = get_post_type_object( $post_type );
1288      if ( ! $post_type_obj ) {
1289          return false;
1290      }
1291  
1292      if ( 'post' === $post_type ) {
1293          $show_on_front  = get_option( 'show_on_front' );
1294          $page_for_posts = get_option( 'page_for_posts' );
1295  
1296          if ( 'page' === $show_on_front && $page_for_posts ) {
1297              $link = get_permalink( $page_for_posts );
1298          } else {
1299              $link = get_home_url();
1300          }
1301          /** This filter is documented in wp-includes/link-template.php */
1302          return apply_filters( 'post_type_archive_link', $link, $post_type );
1303      }
1304  
1305      if ( ! $post_type_obj->has_archive ) {
1306          return false;
1307      }
1308  
1309      if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) ) {
1310          $struct = ( true === $post_type_obj->has_archive ) ? $post_type_obj->rewrite['slug'] : $post_type_obj->has_archive;
1311          if ( $post_type_obj->rewrite['with_front'] ) {
1312              $struct = $wp_rewrite->front . $struct;
1313          } else {
1314              $struct = $wp_rewrite->root . $struct;
1315          }
1316          $link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) );
1317      } else {
1318          $link = home_url( '?post_type=' . $post_type );
1319      }
1320  
1321      /**
1322       * Filters the post type archive permalink.
1323       *
1324       * @since 3.1.0
1325       *
1326       * @param string $link      The post type archive permalink.
1327       * @param string $post_type Post type name.
1328       */
1329      return apply_filters( 'post_type_archive_link', $link, $post_type );
1330  }
1331  
1332  /**
1333   * Retrieves the permalink for a post type archive feed.
1334   *
1335   * @since 3.1.0
1336   *
1337   * @param string $post_type Post type.
1338   * @param string $feed      Optional. Feed type. Possible values include 'rss2', 'atom'.
1339   *                          Default is the value of get_default_feed().
1340   * @return string|false The post type feed permalink. False if the post type
1341   *                      does not exist or does not have an archive.
1342   */
1343  function get_post_type_archive_feed_link( $post_type, $feed = '' ) {
1344      $default_feed = get_default_feed();
1345      if ( empty( $feed ) ) {
1346          $feed = $default_feed;
1347      }
1348  
1349      $link = get_post_type_archive_link( $post_type );
1350      if ( ! $link ) {
1351          return false;
1352      }
1353  
1354      $post_type_obj = get_post_type_object( $post_type );
1355      if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) && $post_type_obj->rewrite['feeds'] ) {
1356          $link  = trailingslashit( $link );
1357          $link .= 'feed/';
1358          if ( $feed != $default_feed ) {
1359              $link .= "$feed/";
1360          }
1361      } else {
1362          $link = add_query_arg( 'feed', $feed, $link );
1363      }
1364  
1365      /**
1366       * Filters the post type archive feed link.
1367       *
1368       * @since 3.1.0
1369       *
1370       * @param string $link The post type archive feed link.
1371       * @param string $feed Feed type. Possible values include 'rss2', 'atom'.
1372       */
1373      return apply_filters( 'post_type_archive_feed_link', $link, $feed );
1374  }
1375  
1376  /**
1377   * Retrieves the URL used for the post preview.
1378   *
1379   * Allows additional query args to be appended.
1380   *
1381   * @since 4.4.0
1382   *
1383   * @param int|WP_Post $post         Optional. Post ID or `WP_Post` object. Defaults to global `$post`.
1384   * @param array       $query_args   Optional. Array of additional query args to be appended to the link.
1385   *                                  Default empty array.
1386   * @param string      $preview_link Optional. Base preview link to be used if it should differ from the
1387   *                                  post permalink. Default empty.
1388   * @return string|null URL used for the post preview, or null if the post does not exist.
1389   */
1390  function get_preview_post_link( $post = null, $query_args = array(), $preview_link = '' ) {
1391      $post = get_post( $post );
1392      if ( ! $post ) {
1393          return;
1394      }
1395  
1396      $post_type_object = get_post_type_object( $post->post_type );
1397      if ( is_post_type_viewable( $post_type_object ) ) {
1398          if ( ! $preview_link ) {
1399              $preview_link = set_url_scheme( get_permalink( $post ) );
1400          }
1401  
1402          $query_args['preview'] = 'true';
1403          $preview_link          = add_query_arg( $query_args, $preview_link );
1404      }
1405  
1406      /**
1407       * Filters the URL used for a post preview.
1408       *
1409       * @since 2.0.5
1410       * @since 4.0.0 Added the `$post` parameter.
1411       *
1412       * @param string  $preview_link URL used for the post preview.
1413       * @param WP_Post $post         Post object.
1414       */
1415      return apply_filters( 'preview_post_link', $preview_link, $post );
1416  }
1417  
1418  /**
1419   * Retrieves the edit post link for post.
1420   *
1421   * Can be used within the WordPress loop or outside of it. Can be used with
1422   * pages, posts, attachments, and revisions.
1423   *
1424   * @since 2.3.0
1425   *
1426   * @param int|WP_Post $id      Optional. Post ID or post object. Default is the global `$post`.
1427   * @param string      $context Optional. How to output the '&' character. Default '&amp;'.
1428   * @return string|null The edit post link for the given post. Null if the post type does not exist
1429   *                     or does not allow an editing UI.
1430   */
1431  function get_edit_post_link( $id = 0, $context = 'display' ) {
1432      $post = get_post( $id );
1433      if ( ! $post ) {
1434          return;
1435      }
1436  
1437      if ( 'revision' === $post->post_type ) {
1438          $action = '';
1439      } elseif ( 'display' === $context ) {
1440          $action = '&amp;action=edit';
1441      } else {
1442          $action = '&action=edit';
1443      }
1444  
1445      $post_type_object = get_post_type_object( $post->post_type );
1446      if ( ! $post_type_object ) {
1447          return;
1448      }
1449  
1450      if ( ! current_user_can( 'edit_post', $post->ID ) ) {
1451          return;
1452      }
1453  
1454      if ( $post_type_object->_edit_link ) {
1455          $link = admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) );
1456      } else {
1457          $link = '';
1458      }
1459  
1460      /**
1461       * Filters the post edit link.
1462       *
1463       * @since 2.3.0
1464       *
1465       * @param string $link    The edit link.
1466       * @param int    $post_id Post ID.
1467       * @param string $context The link context. If set to 'display' then ampersands
1468       *                        are encoded.
1469       */
1470      return apply_filters( 'get_edit_post_link', $link, $post->ID, $context );
1471  }
1472  
1473  /**
1474   * Displays the edit post link for post.
1475   *
1476   * @since 1.0.0
1477   * @since 4.4.0 The `$class` argument was added.
1478   *
1479   * @param string      $text   Optional. Anchor text. If null, default is 'Edit This'. Default null.
1480   * @param string      $before Optional. Display before edit link. Default empty.
1481   * @param string      $after  Optional. Display after edit link. Default empty.
1482   * @param int|WP_Post $id     Optional. Post ID or post object. Default is the global `$post`.
1483   * @param string      $class  Optional. Add custom class to link. Default 'post-edit-link'.
1484   */
1485  function edit_post_link( $text = null, $before = '', $after = '', $id = 0, $class = 'post-edit-link' ) {
1486      $post = get_post( $id );
1487      if ( ! $post ) {
1488          return;
1489      }
1490  
1491      $url = get_edit_post_link( $post->ID );
1492      if ( ! $url ) {
1493          return;
1494      }
1495  
1496      if ( null === $text ) {
1497          $text = __( 'Edit This' );
1498      }
1499  
1500      $link = '<a class="' . esc_attr( $class ) . '" href="' . esc_url( $url ) . '">' . $text . '</a>';
1501  
1502      /**
1503       * Filters the post edit link anchor tag.
1504       *
1505       * @since 2.3.0
1506       *
1507       * @param string $link    Anchor tag for the edit link.
1508       * @param int    $post_id Post ID.
1509       * @param string $text    Anchor text.
1510       */
1511      echo $before . apply_filters( 'edit_post_link', $link, $post->ID, $text ) . $after;
1512  }
1513  
1514  /**
1515   * Retrieves the delete posts link for post.
1516   *
1517   * Can be used within the WordPress loop or outside of it, with any post type.
1518   *
1519   * @since 2.9.0
1520   *
1521   * @param int|WP_Post $id           Optional. Post ID or post object. Default is the global `$post`.
1522   * @param string      $deprecated   Not used.
1523   * @param bool        $force_delete Optional. Whether to bypass Trash and force deletion. Default false.
1524   * @return string|void The delete post link URL for the given post.
1525   */
1526  function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) {
1527      if ( ! empty( $deprecated ) ) {
1528          _deprecated_argument( __FUNCTION__, '3.0.0' );
1529      }
1530  
1531      $post = get_post( $id );
1532      if ( ! $post ) {
1533          return;
1534      }
1535  
1536      $post_type_object = get_post_type_object( $post->post_type );
1537      if ( ! $post_type_object ) {
1538          return;
1539      }
1540  
1541      if ( ! current_user_can( 'delete_post', $post->ID ) ) {
1542          return;
1543      }
1544  
1545      $action = ( $force_delete || ! EMPTY_TRASH_DAYS ) ? 'delete' : 'trash';
1546  
1547      $delete_link = add_query_arg( 'action', $action, admin_url( sprintf( $post_type_object->_edit_link, $post->ID ) ) );
1548  
1549      /**
1550       * Filters the post delete link.
1551       *
1552       * @since 2.9.0
1553       *
1554       * @param string $link         The delete link.
1555       * @param int    $post_id      Post ID.
1556       * @param bool   $force_delete Whether to bypass the Trash and force deletion. Default false.
1557       */
1558      return apply_filters( 'get_delete_post_link', wp_nonce_url( $delete_link, "$action-post_{$post->ID}" ), $post->ID, $force_delete );
1559  }
1560  
1561  /**
1562   * Retrieves the edit comment link.
1563   *
1564   * @since 2.3.0
1565   *
1566   * @param int|WP_Comment $comment_id Optional. Comment ID or WP_Comment object.
1567   * @return string|void The edit comment link URL for the given comment.
1568   */
1569  function get_edit_comment_link( $comment_id = 0 ) {
1570      $comment = get_comment( $comment_id );
1571  
1572      if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
1573          return;
1574      }
1575  
1576      $location = admin_url( 'comment.php?action=editcomment&amp;c=' ) . $comment->comment_ID;
1577  
1578      /**
1579       * Filters the comment edit link.
1580       *
1581       * @since 2.3.0
1582       *
1583       * @param string $location The edit link.
1584       */
1585      return apply_filters( 'get_edit_comment_link', $location );
1586  }
1587  
1588  /**
1589   * Displays the edit comment link with formatting.
1590   *
1591   * @since 1.0.0
1592   *
1593   * @param string $text   Optional. Anchor text. If null, default is 'Edit This'. Default null.
1594   * @param string $before Optional. Display before edit link. Default empty.
1595   * @param string $after  Optional. Display after edit link. Default empty.
1596   */
1597  function edit_comment_link( $text = null, $before = '', $after = '' ) {
1598      $comment = get_comment();
1599  
1600      if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
1601          return;
1602      }
1603  
1604      if ( null === $text ) {
1605          $text = __( 'Edit This' );
1606      }
1607  
1608      $link = '<a class="comment-edit-link" href="' . esc_url( get_edit_comment_link( $comment ) ) . '">' . $text . '</a>';
1609  
1610      /**
1611       * Filters the comment edit link anchor tag.
1612       *
1613       * @since 2.3.0
1614       *
1615       * @param string $link       Anchor tag for the edit link.
1616       * @param int    $comment_id Comment ID.
1617       * @param string $text       Anchor text.
1618       */
1619      echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID, $text ) . $after;
1620  }
1621  
1622  /**
1623   * Displays the edit bookmark link.
1624   *
1625   * @since 2.7.0
1626   *
1627   * @param int|stdClass $link Optional. Bookmark ID. Default is the ID of the current bookmark.
1628   * @return string|void The edit bookmark link URL.
1629   */
1630  function get_edit_bookmark_link( $link = 0 ) {
1631      $link = get_bookmark( $link );
1632  
1633      if ( ! current_user_can( 'manage_links' ) ) {
1634          return;
1635      }
1636  
1637      $location = admin_url( 'link.php?action=edit&amp;link_id=' ) . $link->link_id;
1638  
1639      /**
1640       * Filters the bookmark edit link.
1641       *
1642       * @since 2.7.0
1643       *
1644       * @param string $location The edit link.
1645       * @param int    $link_id  Bookmark ID.
1646       */
1647      return apply_filters( 'get_edit_bookmark_link', $location, $link->link_id );
1648  }
1649  
1650  /**
1651   * Displays the edit bookmark link anchor content.
1652   *
1653   * @since 2.7.0
1654   *
1655   * @param string $link     Optional. Anchor text. If empty, default is 'Edit This'. Default empty.
1656   * @param string $before   Optional. Display before edit link. Default empty.
1657   * @param string $after    Optional. Display after edit link. Default empty.
1658   * @param int    $bookmark Optional. Bookmark ID. Default is the current bookmark.
1659   */
1660  function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = null ) {
1661      $bookmark = get_bookmark( $bookmark );
1662  
1663      if ( ! current_user_can( 'manage_links' ) ) {
1664          return;
1665      }
1666  
1667      if ( empty( $link ) ) {
1668          $link = __( 'Edit This' );
1669      }
1670  
1671      $link = '<a href="' . esc_url( get_edit_bookmark_link( $bookmark ) ) . '">' . $link . '</a>';
1672  
1673      /**
1674       * Filters the bookmark edit link anchor tag.
1675       *
1676       * @since 2.7.0
1677       *
1678       * @param string $link    Anchor tag for the edit link.
1679       * @param int    $link_id Bookmark ID.
1680       */
1681      echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after;
1682  }
1683  
1684  /**
1685   * Retrieves the edit user link.
1686   *
1687   * @since 3.5.0
1688   *
1689   * @param int $user_id Optional. User ID. Defaults to the current user.
1690   * @return string URL to edit user page or empty string.
1691   */
1692  function get_edit_user_link( $user_id = null ) {
1693      if ( ! $user_id ) {
1694          $user_id = get_current_user_id();
1695      }
1696  
1697      if ( empty( $user_id ) || ! current_user_can( 'edit_user', $user_id ) ) {
1698          return '';
1699      }
1700  
1701      $user = get_userdata( $user_id );
1702  
1703      if ( ! $user ) {
1704          return '';
1705      }
1706  
1707      if ( get_current_user_id() == $user->ID ) {
1708          $link = get_edit_profile_url( $user->ID );
1709      } else {
1710          $link = add_query_arg( 'user_id', $user->ID, self_admin_url( 'user-edit.php' ) );
1711      }
1712  
1713      /**
1714       * Filters the user edit link.
1715       *
1716       * @since 3.5.0
1717       *
1718       * @param string $link    The edit link.
1719       * @param int    $user_id User ID.
1720       */
1721      return apply_filters( 'get_edit_user_link', $link, $user->ID );
1722  }
1723  
1724  //
1725  // Navigation links.
1726  //
1727  
1728  /**
1729   * Retrieves the previous post that is adjacent to the current post.
1730   *
1731   * @since 1.5.0
1732   *
1733   * @param bool         $in_same_term   Optional. Whether post should be in a same taxonomy term. Default false.
1734   * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
1735   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
1736   * @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no
1737   *                             corresponding post exists.
1738   */
1739  function get_previous_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
1740      return get_adjacent_post( $in_same_term, $excluded_terms, true, $taxonomy );
1741  }
1742  
1743  /**
1744   * Retrieves the next post that is adjacent to the current post.
1745   *
1746   * @since 1.5.0
1747   *
1748   * @param bool         $in_same_term   Optional. Whether post should be in a same taxonomy term. Default false.
1749   * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
1750   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
1751   * @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no
1752   *                             corresponding post exists.
1753   */
1754  function get_next_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
1755      return get_adjacent_post( $in_same_term, $excluded_terms, false, $taxonomy );
1756  }
1757  
1758  /**
1759   * Retrieves the adjacent post.
1760   *
1761   * Can either be next or previous post.
1762   *
1763   * @since 2.5.0
1764   *
1765   * @global wpdb $wpdb WordPress database abstraction object.
1766   *
1767   * @param bool         $in_same_term   Optional. Whether post should be in a same taxonomy term. Default false.
1768   * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty string.
1769   * @param bool         $previous       Optional. Whether to retrieve previous post. Default true
1770   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
1771   * @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no
1772   *                             corresponding post exists.
1773   */
1774  function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
1775      global $wpdb;
1776  
1777      $post = get_post();
1778      if ( ! $post || ! taxonomy_exists( $taxonomy ) ) {
1779          return null;
1780      }
1781  
1782      $current_post_date = $post->post_date;
1783  
1784      $join     = '';
1785      $where    = '';
1786      $adjacent = $previous ? 'previous' : 'next';
1787  
1788      if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) {
1789          // Back-compat, $excluded_terms used to be $excluded_categories with IDs separated by " and ".
1790          if ( false !== strpos( $excluded_terms, ' and ' ) ) {
1791              _deprecated_argument(
1792                  __FUNCTION__,
1793                  '3.3.0',
1794                  sprintf(
1795                      /* translators: %s: The word 'and'. */
1796                      __( 'Use commas instead of %s to separate excluded terms.' ),
1797                      "'and'"
1798                  )
1799              );
1800              $excluded_terms = explode( ' and ', $excluded_terms );
1801          } else {
1802              $excluded_terms = explode( ',', $excluded_terms );
1803          }
1804  
1805          $excluded_terms = array_map( 'intval', $excluded_terms );
1806      }
1807  
1808      /**
1809       * Filters the IDs of terms excluded from adjacent post queries.
1810       *
1811       * The dynamic portion of the hook name, `$adjacent`, refers to the type
1812       * of adjacency, 'next' or 'previous'.
1813       *
1814       * Possible hook names include:
1815       *
1816       *  - `get_next_post_excluded_terms`
1817       *  - `get_previous_post_excluded_terms`
1818       *
1819       * @since 4.4.0
1820       *
1821       * @param array|string $excluded_terms Array of excluded term IDs. Empty string if none were provided.
1822       */
1823      $excluded_terms = apply_filters( "get_{$adjacent}_post_excluded_terms", $excluded_terms );
1824  
1825      if ( $in_same_term || ! empty( $excluded_terms ) ) {
1826          if ( $in_same_term ) {
1827              $join  .= " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";
1828              $where .= $wpdb->prepare( 'AND tt.taxonomy = %s', $taxonomy );
1829  
1830              if ( ! is_object_in_taxonomy( $post->post_type, $taxonomy ) ) {
1831                  return '';
1832              }
1833              $term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
1834  
1835              // Remove any exclusions from the term array to include.
1836              $term_array = array_diff( $term_array, (array) $excluded_terms );
1837              $term_array = array_map( 'intval', $term_array );
1838  
1839              if ( ! $term_array || is_wp_error( $term_array ) ) {
1840                  return '';
1841              }
1842  
1843              $where .= ' AND tt.term_id IN (' . implode( ',', $term_array ) . ')';
1844          }
1845  
1846          if ( ! empty( $excluded_terms ) ) {
1847              $where .= " AND p.ID NOT IN ( SELECT tr.object_id FROM $wpdb->term_relationships tr LEFT JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE tt.term_id IN (" . implode( ',', array_map( 'intval', $excluded_terms ) ) . ') )';
1848          }
1849      }
1850  
1851      // 'post_status' clause depends on the current user.
1852      if ( is_user_logged_in() ) {
1853          $user_id = get_current_user_id();
1854  
1855          $post_type_object = get_post_type_object( $post->post_type );
1856          if ( empty( $post_type_object ) ) {
1857              $post_type_cap    = $post->post_type;
1858              $read_private_cap = 'read_private_' . $post_type_cap . 's';
1859          } else {
1860              $read_private_cap = $post_type_object->cap->read_private_posts;
1861          }
1862  
1863          /*
1864           * Results should include private posts belonging to the current user, or private posts where the
1865           * current user has the 'read_private_posts' cap.
1866           */
1867          $private_states = get_post_stati( array( 'private' => true ) );
1868          $where         .= " AND ( p.post_status = 'publish'";
1869          foreach ( (array) $private_states as $state ) {
1870              if ( current_user_can( $read_private_cap ) ) {
1871                  $where .= $wpdb->prepare( ' OR p.post_status = %s', $state );
1872              } else {
1873                  $where .= $wpdb->prepare( ' OR (p.post_author = %d AND p.post_status = %s)', $user_id, $state );
1874              }
1875          }
1876          $where .= ' )';
1877      } else {
1878          $where .= " AND p.post_status = 'publish'";
1879      }
1880  
1881      $op    = $previous ? '<' : '>';
1882      $order = $previous ? 'DESC' : 'ASC';
1883  
1884      /**
1885       * Filters the JOIN clause in the SQL for an adjacent post query.
1886       *
1887       * The dynamic portion of the hook name, `$adjacent`, refers to the type
1888       * of adjacency, 'next' or 'previous'.
1889       *
1890       * Possible hook names include:
1891       *
1892       *  - `get_next_post_join`
1893       *  - `get_previous_post_join`
1894       *
1895       * @since 2.5.0
1896       * @since 4.4.0 Added the `$taxonomy` and `$post` parameters.
1897       *
1898       * @param string  $join           The JOIN clause in the SQL.
1899       * @param bool    $in_same_term   Whether post should be in a same taxonomy term.
1900       * @param array   $excluded_terms Array of excluded term IDs.
1901       * @param string  $taxonomy       Taxonomy. Used to identify the term used when `$in_same_term` is true.
1902       * @param WP_Post $post           WP_Post object.
1903       */
1904      $join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_term, $excluded_terms, $taxonomy, $post );
1905  
1906      /**
1907       * Filters the WHERE clause in the SQL for an adjacent post query.
1908       *
1909       * The dynamic portion of the hook name, `$adjacent`, refers to the type
1910       * of adjacency, 'next' or 'previous'.
1911       *
1912       * Possible hook names include:
1913       *
1914       *  - `get_next_post_where`
1915       *  - `get_previous_post_where`
1916       *
1917       * @since 2.5.0
1918       * @since 4.4.0 Added the `$taxonomy` and `$post` parameters.
1919       *
1920       * @param string  $where          The `WHERE` clause in the SQL.
1921       * @param bool    $in_same_term   Whether post should be in a same taxonomy term.
1922       * @param array   $excluded_terms Array of excluded term IDs.
1923       * @param string  $taxonomy       Taxonomy. Used to identify the term used when `$in_same_term` is true.
1924       * @param WP_Post $post           WP_Post object.
1925       */
1926      $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare( "WHERE p.post_date $op %s AND p.post_type = %s $where", $current_post_date, $post->post_type ), $in_same_term, $excluded_terms, $taxonomy, $post );
1927  
1928      /**
1929       * Filters the ORDER BY clause in the SQL for an adjacent post query.
1930       *
1931       * The dynamic portion of the hook name, `$adjacent`, refers to the type
1932       * of adjacency, 'next' or 'previous'.
1933       *
1934       * Possible hook names include:
1935       *
1936       *  - `get_next_post_sort`
1937       *  - `get_previous_post_sort`
1938       *
1939       * @since 2.5.0
1940       * @since 4.4.0 Added the `$post` parameter.
1941       * @since 4.9.0 Added the `$order` parameter.
1942       *
1943       * @param string $order_by The `ORDER BY` clause in the SQL.
1944       * @param WP_Post $post    WP_Post object.
1945       * @param string  $order   Sort order. 'DESC' for previous post, 'ASC' for next.
1946       */
1947      $sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1", $post, $order );
1948  
1949      $query     = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort";
1950      $query_key = 'adjacent_post_' . md5( $query );
1951      $result    = wp_cache_get( $query_key, 'counts' );
1952      if ( false !== $result ) {
1953          if ( $result ) {
1954              $result = get_post( $result );
1955          }
1956          return $result;
1957      }
1958  
1959      $result = $wpdb->get_var( $query );
1960      if ( null === $result ) {
1961          $result = '';
1962      }
1963  
1964      wp_cache_set( $query_key, $result, 'counts' );
1965  
1966      if ( $result ) {
1967          $result = get_post( $result );
1968      }
1969  
1970      return $result;
1971  }
1972  
1973  /**
1974   * Retrieves the adjacent post relational link.
1975   *
1976   * Can either be next or previous post relational link.
1977   *
1978   * @since 2.8.0
1979   *
1980   * @param string       $title          Optional. Link title format. Default '%title'.
1981   * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
1982   * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
1983   * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
1984   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
1985   * @return string|void The adjacent post relational link URL.
1986   */
1987  function get_adjacent_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
1988      $post = get_post();
1989      if ( $previous && is_attachment() && $post ) {
1990          $post = get_post( $post->post_parent );
1991      } else {
1992          $post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy );
1993      }
1994  
1995      if ( empty( $post ) ) {
1996          return;
1997      }
1998  
1999      $post_title = the_title_attribute(
2000          array(
2001              'echo' => false,
2002              'post' => $post,
2003          )
2004      );
2005  
2006      if ( empty( $post_title ) ) {
2007          $post_title = $previous ? __( 'Previous Post' ) : __( 'Next Post' );
2008      }
2009  
2010      $date = mysql2date( get_option( 'date_format' ), $post->post_date );
2011  
2012      $title = str_replace( '%title', $post_title, $title );
2013      $title = str_replace( '%date', $date, $title );
2014  
2015      $link  = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
2016      $link .= esc_attr( $title );
2017      $link .= "' href='" . get_permalink( $post ) . "' />\n";
2018  
2019      $adjacent = $previous ? 'previous' : 'next';
2020  
2021      /**
2022       * Filters the adjacent post relational link.
2023       *
2024       * The dynamic portion of the hook name, `$adjacent`, refers to the type
2025       * of adjacency, 'next' or 'previous'.
2026       *
2027       * Possible hook names include:
2028       *
2029       *  - `next_post_rel_link`
2030       *  - `previous_post_rel_link`
2031       *
2032       * @since 2.8.0
2033       *
2034       * @param string $link The relational link.
2035       */
2036      return apply_filters( "{$adjacent}_post_rel_link", $link );
2037  }
2038  
2039  /**
2040   * Displays the relational links for the posts adjacent to the current post.
2041   *
2042   * @since 2.8.0
2043   *
2044   * @param string       $title          Optional. Link title format. Default '%title'.
2045   * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
2046   * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
2047   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
2048   */
2049  function adjacent_posts_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
2050      echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, true, $taxonomy );
2051      echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy );
2052  }
2053  
2054  /**
2055   * Displays relational links for the posts adjacent to the current post for single post pages.
2056   *
2057   * This is meant to be attached to actions like 'wp_head'. Do not call this directly in plugins
2058   * or theme templates.
2059   *
2060   * @since 3.0.0
2061   * @since 5.6.0 No longer used in core.
2062   *
2063   * @see adjacent_posts_rel_link()
2064   */
2065  function adjacent_posts_rel_link_wp_head() {
2066      if ( ! is_single() || is_attachment() ) {
2067          return;
2068      }
2069      adjacent_posts_rel_link();
2070  }
2071  
2072  /**
2073   * Displays the relational link for the next post adjacent to the current post.
2074   *
2075   * @since 2.8.0
2076   *
2077   * @see get_adjacent_post_rel_link()
2078   *
2079   * @param string       $title          Optional. Link title format. Default '%title'.
2080   * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
2081   * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
2082   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
2083   */
2084  function next_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
2085      echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy );
2086  }
2087  
2088  /**
2089   * Displays the relational link for the previous post adjacent to the current post.
2090   *
2091   * @since 2.8.0
2092   *
2093   * @see get_adjacent_post_rel_link()
2094   *
2095   * @param string       $title          Optional. Link title format. Default '%title'.
2096   * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
2097   * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default true.
2098   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
2099   */
2100  function prev_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
2101      echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, true, $taxonomy );
2102  }
2103  
2104  /**
2105   * Retrieves the boundary post.
2106   *
2107   * Boundary being either the first or last post by publish date within the constraints specified
2108   * by $in_same_term or $excluded_terms.
2109   *
2110   * @since 2.8.0
2111   *
2112   * @param bool         $in_same_term   Optional. Whether returned post should be in a same taxonomy term.
2113   *                                     Default false.
2114   * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
2115   *                                     Default empty.
2116   * @param bool         $start          Optional. Whether to retrieve first or last post. Default true
2117   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
2118   * @return null|array Array containing the boundary post object if successful, null otherwise.
2119   */
2120  function get_boundary_post( $in_same_term = false, $excluded_terms = '', $start = true, $taxonomy = 'category' ) {
2121      $post = get_post();
2122      if ( ! $post || ! is_single() || is_attachment() || ! taxonomy_exists( $taxonomy ) ) {
2123          return null;
2124      }
2125  
2126      $query_args = array(
2127          'posts_per_page'         => 1,
2128          'order'                  => $start ? 'ASC' : 'DESC',
2129          'update_post_term_cache' => false,
2130          'update_post_meta_cache' => false,
2131      );
2132  
2133      $term_array = array();
2134  
2135      if ( ! is_array( $excluded_terms ) ) {
2136          if ( ! empty( $excluded_terms ) ) {
2137              $excluded_terms = explode( ',', $excluded_terms );
2138          } else {
2139              $excluded_terms = array();
2140          }
2141      }
2142  
2143      if ( $in_same_term || ! empty( $excluded_terms ) ) {
2144          if ( $in_same_term ) {
2145              $term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
2146          }
2147  
2148          if ( ! empty( $excluded_terms ) ) {
2149              $excluded_terms = array_map( 'intval', $excluded_terms );
2150              $excluded_terms = array_diff( $excluded_terms, $term_array );
2151  
2152              $inverse_terms = array();
2153              foreach ( $excluded_terms as $excluded_term ) {
2154                  $inverse_terms[] = $excluded_term * -1;
2155              }
2156              $excluded_terms = $inverse_terms;
2157          }
2158  
2159          $query_args['tax_query'] = array(
2160              array(
2161                  'taxonomy' => $taxonomy,
2162                  'terms'    => array_merge( $term_array, $excluded_terms ),
2163              ),
2164          );
2165      }
2166  
2167      return get_posts( $query_args );
2168  }
2169  
2170  /**
2171   * Retrieves the previous post link that is adjacent to the current post.
2172   *
2173   * @since 3.7.0
2174   *
2175   * @param string       $format         Optional. Link anchor format. Default '&laquo; %link'.
2176   * @param string       $link           Optional. Link permalink format. Default '%title'.
2177   * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
2178   * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
2179   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
2180   * @return string The link URL of the previous post in relation to the current post.
2181   */
2182  function get_previous_post_link( $format = '&laquo; %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
2183      return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, true, $taxonomy );
2184  }
2185  
2186  /**
2187   * Displays the previous post link that is adjacent to the current post.
2188   *
2189   * @since 1.5.0
2190   *
2191   * @see get_previous_post_link()
2192   *
2193   * @param string       $format         Optional. Link anchor format. Default '&laquo; %link'.
2194   * @param string       $link           Optional. Link permalink format. Default '%title'.
2195   * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
2196   * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
2197   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
2198   */
2199  function previous_post_link( $format = '&laquo; %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
2200      echo get_previous_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy );
2201  }
2202  
2203  /**
2204   * Retrieves the next post link that is adjacent to the current post.
2205   *
2206   * @since 3.7.0
2207   *
2208   * @param string       $format         Optional. Link anchor format. Default '&laquo; %link'.
2209   * @param string       $link           Optional. Link permalink format. Default '%title'.
2210   * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
2211   * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
2212   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
2213   * @return string The link URL of the next post in relation to the current post.
2214   */
2215  function get_next_post_link( $format = '%link &raquo;', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
2216      return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, false, $taxonomy );
2217  }
2218  
2219  /**
2220   * Displays the next post link that is adjacent to the current post.
2221   *
2222   * @since 1.5.0
2223   *
2224   * @see get_next_post_link()
2225   *
2226   * @param string       $format         Optional. Link anchor format. Default '&laquo; %link'.
2227   * @param string       $link           Optional. Link permalink format. Default '%title'
2228   * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
2229   * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
2230   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
2231   */
2232  function next_post_link( $format = '%link &raquo;', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
2233      echo get_next_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy );
2234  }
2235  
2236  /**
2237   * Retrieves the adjacent post link.
2238   *
2239   * Can be either next post link or previous.
2240   *
2241   * @since 3.7.0
2242   *
2243   * @param string       $format         Link anchor format.
2244   * @param string       $link           Link permalink format.
2245   * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
2246   * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded terms IDs. Default empty.
2247   * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
2248   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
2249   * @return string The link URL of the previous or next post in relation to the current post.
2250   */
2251  function get_adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
2252      if ( $previous && is_attachment() ) {
2253          $post = get_post( get_post()->post_parent );
2254      } else {
2255          $post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy );
2256      }
2257  
2258      if ( ! $post ) {
2259          $output = '';
2260      } else {
2261          $title = $post->post_title;
2262  
2263          if ( empty( $post->post_title ) ) {
2264              $title = $previous ? __( 'Previous Post' ) : __( 'Next Post' );
2265          }
2266  
2267          /** This filter is documented in wp-includes/post-template.php */
2268          $title = apply_filters( 'the_title', $title, $post->ID );
2269  
2270          $date = mysql2date( get_option( 'date_format' ), $post->post_date );
2271          $rel  = $previous ? 'prev' : 'next';
2272  
2273          $string = '<a href="' . get_permalink( $post ) . '" rel="' . $rel . '">';
2274          $inlink = str_replace( '%title', $title, $link );
2275          $inlink = str_replace( '%date', $date, $inlink );
2276          $inlink = $string . $inlink . '</a>';
2277  
2278          $output = str_replace( '%link', $inlink, $format );
2279      }
2280  
2281      $adjacent = $previous ? 'previous' : 'next';
2282  
2283      /**
2284       * Filters the adjacent post link.
2285       *
2286       * The dynamic portion of the hook name, `$adjacent`, refers to the type
2287       * of adjacency, 'next' or 'previous'.
2288       *
2289       * Possible hook names include:
2290       *
2291       *  - `next_post_link`
2292       *  - `previous_post_link`
2293       *
2294       * @since 2.6.0
2295       * @since 4.2.0 Added the `$adjacent` parameter.
2296       *
2297       * @param string  $output   The adjacent post link.
2298       * @param string  $format   Link anchor format.
2299       * @param string  $link     Link permalink format.
2300       * @param WP_Post $post     The adjacent post.
2301       * @param string  $adjacent Whether the post is previous or next.
2302       */
2303      return apply_filters( "{$adjacent}_post_link", $output, $format, $link, $post, $adjacent );
2304  }
2305  
2306  /**
2307   * Displays the adjacent post link.
2308   *
2309   * Can be either next post link or previous.
2310   *
2311   * @since 2.5.0
2312   *
2313   * @param string       $format         Link anchor format.
2314   * @param string       $link           Link permalink format.
2315   * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
2316   * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded category IDs. Default empty.
2317   * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
2318   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
2319   */
2320  function adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
2321      echo get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, $previous, $taxonomy );
2322  }
2323  
2324  /**
2325   * Retrieves the link for a page number.
2326   *
2327   * @since 1.5.0
2328   *
2329   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
2330   *
2331   * @param int  $pagenum Optional. Page number. Default 1.
2332   * @param bool $escape  Optional. Whether to escape the URL for display, with esc_url(). Defaults to true.
2333   *                      Otherwise, prepares the URL with esc_url_raw().
2334   * @return string The link URL for the given page number.
2335   */
2336  function get_pagenum_link( $pagenum = 1, $escape = true ) {
2337      global $wp_rewrite;
2338  
2339      $pagenum = (int) $pagenum;
2340  
2341      $request = remove_query_arg( 'paged' );
2342  
2343      $home_root = parse_url( home_url() );
2344      $home_root = ( isset( $home_root['path'] ) ) ? $home_root['path'] : '';
2345      $home_root = preg_quote( $home_root, '|' );
2346  
2347      $request = preg_replace( '|^' . $home_root . '|i', '', $request );
2348      $request = preg_replace( '|^/+|', '', $request );
2349  
2350      if ( ! $wp_rewrite->using_permalinks() || is_admin() ) {
2351          $base = trailingslashit( get_bloginfo( 'url' ) );
2352  
2353          if ( $pagenum > 1 ) {
2354              $result = add_query_arg( 'paged', $pagenum, $base . $request );
2355          } else {
2356              $result = $base . $request;
2357          }
2358      } else {
2359          $qs_regex = '|\?.*?$|';
2360          preg_match( $qs_regex, $request, $qs_match );
2361  
2362          if ( ! empty( $qs_match[0] ) ) {
2363              $query_string = $qs_match[0];
2364              $request      = preg_replace( $qs_regex, '', $request );
2365          } else {
2366              $query_string = '';
2367          }
2368  
2369          $request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request );
2370          $request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request );
2371          $request = ltrim( $request, '/' );
2372  
2373          $base = trailingslashit( get_bloginfo( 'url' ) );
2374  
2375          if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' !== $request ) ) {
2376              $base .= $wp_rewrite->index . '/';
2377          }
2378  
2379          if ( $pagenum > 1 ) {
2380              $request = ( ( ! empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . '/' . $pagenum, 'paged' );
2381          }
2382  
2383          $result = $base . $request . $query_string;
2384      }
2385  
2386      /**
2387       * Filters the page number link for the current request.
2388       *
2389       * @since 2.5.0
2390       * @since 5.2.0 Added the `$pagenum` argument.
2391       *
2392       * @param string $result  The page number link.
2393       * @param int    $pagenum The page number.
2394       */
2395      $result = apply_filters( 'get_pagenum_link', $result, $pagenum );
2396  
2397      if ( $escape ) {
2398          return esc_url( $result );
2399      } else {
2400          return esc_url_raw( $result );
2401      }
2402  }
2403  
2404  /**
2405   * Retrieves the next posts page link.
2406   *
2407   * Backported from 2.1.3 to 2.0.10.
2408   *
2409   * @since 2.0.10
2410   *
2411   * @global int $paged
2412   *
2413   * @param int $max_page Optional. Max pages. Default 0.
2414   * @return string|void The link URL for next posts page.
2415   */
2416  function get_next_posts_page_link( $max_page = 0 ) {
2417      global $paged;
2418  
2419      if ( ! is_single() ) {
2420          if ( ! $paged ) {
2421              $paged = 1;
2422          }
2423          $nextpage = (int) $paged + 1;
2424          if ( ! $max_page || $max_page >= $nextpage ) {
2425              return get_pagenum_link( $nextpage );
2426          }
2427      }
2428  }
2429  
2430  /**
2431   * Displays or retrieves the next posts page link.
2432   *
2433   * @since 0.71
2434   *
2435   * @param int  $max_page Optional. Max pages. Default 0.
2436   * @param bool $echo     Optional. Whether to echo the link. Default true.
2437   * @return string|void The link URL for next posts page if `$echo = false`.
2438   */
2439  function next_posts( $max_page = 0, $echo = true ) {
2440      $output = esc_url( get_next_posts_page_link( $max_page ) );
2441  
2442      if ( $echo ) {
2443          echo $output;
2444      } else {
2445          return $output;
2446      }
2447  }
2448  
2449  /**
2450   * Retrieves the next posts page link.
2451   *
2452   * @since 2.7.0
2453   *
2454   * @global int      $paged
2455   * @global WP_Query $wp_query WordPress Query object.
2456   *
2457   * @param string $label    Content for link text.
2458   * @param int    $max_page Optional. Max pages. Default 0.
2459   * @return string|void HTML-formatted next posts page link.
2460   */
2461  function get_next_posts_link( $label = null, $max_page = 0 ) {
2462      global $paged, $wp_query;
2463  
2464      if ( ! $max_page ) {
2465          $max_page = $wp_query->max_num_pages;
2466      }
2467  
2468      if ( ! $paged ) {
2469          $paged = 1;
2470      }
2471  
2472      $nextpage = (int) $paged + 1;
2473  
2474      if ( null === $label ) {
2475          $label = __( 'Next Page &raquo;' );
2476      }
2477  
2478      if ( ! is_single() && ( $nextpage <= $max_page ) ) {
2479          /**
2480           * Filters the anchor tag attributes for the next posts page link.
2481           *
2482           * @since 2.7.0
2483           *
2484           * @param string $attributes Attributes for the anchor tag.
2485           */
2486          $attr = apply_filters( 'next_posts_link_attributes', '' );
2487  
2488          return '<a href="' . next_posts( $max_page, false ) . "\" $attr>" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label ) . '</a>';
2489      }
2490  }
2491  
2492  /**
2493   * Displays the next posts page link.
2494   *
2495   * @since 0.71
2496   *
2497   * @param string $label    Content for link text.
2498   * @param int    $max_page Optional. Max pages. Default 0.
2499   */
2500  function next_posts_link( $label = null, $max_page = 0 ) {
2501      echo get_next_posts_link( $label, $max_page );
2502  }
2503  
2504  /**
2505   * Retrieves the previous posts page link.
2506   *
2507   * Will only return string, if not on a single page or post.
2508   *
2509   * Backported to 2.0.10 from 2.1.3.
2510   *
2511   * @since 2.0.10
2512   *
2513   * @global int $paged
2514   *
2515   * @return string|void The link for the previous posts page.
2516   */
2517  function get_previous_posts_page_link() {
2518      global $paged;
2519  
2520      if ( ! is_single() ) {
2521          $nextpage = (int) $paged - 1;
2522          if ( $nextpage < 1 ) {
2523              $nextpage = 1;
2524          }
2525          return get_pagenum_link( $nextpage );
2526      }
2527  }
2528  
2529  /**
2530   * Displays or retrieves the previous posts page link.
2531   *
2532   * @since 0.71
2533   *
2534   * @param bool $echo Optional. Whether to echo the link. Default true.
2535   * @return string|void The previous posts page link if `$echo = false`.
2536   */
2537  function previous_posts( $echo = true ) {
2538      $output = esc_url( get_previous_posts_page_link() );
2539  
2540      if ( $echo ) {
2541          echo $output;
2542      } else {
2543          return $output;
2544      }
2545  }
2546  
2547  /**
2548   * Retrieves the previous posts page link.
2549   *
2550   * @since 2.7.0
2551   *
2552   * @global int $paged
2553   *
2554   * @param string $label Optional. Previous page link text.
2555   * @return string|void HTML-formatted previous page link.
2556   */
2557  function get_previous_posts_link( $label = null ) {
2558      global $paged;
2559  
2560      if ( null === $label ) {
2561          $label = __( '&laquo; Previous Page' );
2562      }
2563  
2564      if ( ! is_single() && $paged > 1 ) {
2565          /**
2566           * Filters the anchor tag attributes for the previous posts page link.
2567           *
2568           * @since 2.7.0
2569           *
2570           * @param string $attributes Attributes for the anchor tag.
2571           */
2572          $attr = apply_filters( 'previous_posts_link_attributes', '' );
2573          return '<a href="' . previous_posts( false ) . "\" $attr>" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label ) . '</a>';
2574      }
2575  }
2576  
2577  /**
2578   * Displays the previous posts page link.
2579   *
2580   * @since 0.71
2581   *
2582   * @param string $label Optional. Previous page link text.
2583   */
2584  function previous_posts_link( $label = null ) {
2585      echo get_previous_posts_link( $label );
2586  }
2587  
2588  /**
2589   * Retrieves the post pages link navigation for previous and next pages.
2590   *
2591   * @since 2.8.0
2592   *
2593   * @global WP_Query $wp_query WordPress Query object.
2594   *
2595   * @param string|array $args {
2596   *     Optional. Arguments to build the post pages link navigation.
2597   *
2598   *     @type string $sep      Separator character. Default '&#8212;'.
2599   *     @type string $prelabel Link text to display for the previous page link.
2600   *                            Default '&laquo; Previous Page'.
2601   *     @type string $nxtlabel Link text to display for the next page link.
2602   *                            Default 'Next Page &raquo;'.
2603   * }
2604   * @return string The posts link navigation.
2605   */
2606  function get_posts_nav_link( $args = array() ) {
2607      global $wp_query;
2608  
2609      $return = '';
2610  
2611      if ( ! is_singular() ) {
2612          $defaults = array(
2613              'sep'      => ' &#8212; ',
2614              'prelabel' => __( '&laquo; Previous Page' ),
2615              'nxtlabel' => __( 'Next Page &raquo;' ),
2616          );
2617          $args     = wp_parse_args( $args, $defaults );
2618  
2619          $max_num_pages = $wp_query->max_num_pages;
2620          $paged         = get_query_var( 'paged' );
2621  
2622          // Only have sep if there's both prev and next results.
2623          if ( $paged < 2 || $paged >= $max_num_pages ) {
2624              $args['sep'] = '';
2625          }
2626  
2627          if ( $max_num_pages > 1 ) {
2628              $return  = get_previous_posts_link( $args['prelabel'] );
2629              $return .= preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $args['sep'] );
2630              $return .= get_next_posts_link( $args['nxtlabel'] );
2631          }
2632      }
2633      return $return;
2634  
2635  }
2636  
2637  /**
2638   * Displays the post pages link navigation for previous and next pages.
2639   *
2640   * @since 0.71
2641   *
2642   * @param string $sep      Optional. Separator for posts navigation links. Default empty.
2643   * @param string $prelabel Optional. Label for previous pages. Default empty.
2644   * @param string $nxtlabel Optional Label for next pages. Default empty.
2645   */
2646  function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) {
2647      $args = array_filter( compact( 'sep', 'prelabel', 'nxtlabel' ) );
2648      echo get_posts_nav_link( $args );
2649  }
2650  
2651  /**
2652   * Retrieves the navigation to next/previous post, when applicable.
2653   *
2654   * @since 4.1.0
2655   * @since 4.4.0 Introduced the `in_same_term`, `excluded_terms`, and `taxonomy` arguments.
2656   * @since 5.3.0 Added the `aria_label` parameter.
2657   * @since 5.5.0 Added the `class` parameter.
2658   *
2659   * @param array $args {
2660   *     Optional. Default post navigation arguments. Default empty array.
2661   *
2662   *     @type string       $prev_text          Anchor text to display in the previous post link. Default '%title'.
2663   *     @type string       $next_text          Anchor text to display in the next post link. Default '%title'.
2664   *     @type bool         $in_same_term       Whether link should be in a same taxonomy term. Default false.
2665   *     @type int[]|string $excluded_terms     Array or comma-separated list of excluded term IDs. Default empty.
2666   *     @type string       $taxonomy           Taxonomy, if `$in_same_term` is true. Default 'category'.
2667   *     @type string       $screen_reader_text Screen reader text for the nav element. Default 'Post navigation'.
2668   *     @type string       $aria_label         ARIA label text for the nav element. Default 'Posts'.
2669   *     @type string       $class              Custom class for the nav element. Default 'post-navigation'.
2670   * }
2671   * @return string Markup for post links.
2672   */
2673  function get_the_post_navigation( $args = array() ) {
2674      // Make sure the nav element has an aria-label attribute: fallback to the screen reader text.
2675      if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) {
2676          $args['aria_label'] = $args['screen_reader_text'];
2677      }
2678  
2679      $args = wp_parse_args(
2680          $args,
2681          array(
2682              'prev_text'          => '%title',
2683              'next_text'          => '%title',
2684              'in_same_term'       => false,
2685              'excluded_terms'     => '',
2686              'taxonomy'           => 'category',
2687              'screen_reader_text' => __( 'Post navigation' ),
2688              'aria_label'         => __( 'Posts' ),
2689              'class'              => 'post-navigation',
2690          )
2691      );
2692  
2693      $navigation = '';
2694  
2695      $previous = get_previous_post_link(
2696          '<div class="nav-previous">%link</div>',
2697          $args['prev_text'],
2698          $args['in_same_term'],
2699          $args['excluded_terms'],
2700          $args['taxonomy']
2701      );
2702  
2703      $next = get_next_post_link(
2704          '<div class="nav-next">%link</div>',
2705          $args['next_text'],
2706          $args['in_same_term'],
2707          $args['excluded_terms'],
2708          $args['taxonomy']
2709      );
2710  
2711      // Only add markup if there's somewhere to navigate to.
2712      if ( $previous || $next ) {
2713          $navigation = _navigation_markup( $previous . $next, $args['class'], $args['screen_reader_text'], $args['aria_label'] );
2714      }
2715  
2716      return $navigation;
2717  }
2718  
2719  /**
2720   * Displays the navigation to next/previous post, when applicable.
2721   *
2722   * @since 4.1.0
2723   *
2724   * @param array $args Optional. See get_the_post_navigation() for available arguments.
2725   *                    Default empty array.
2726   */
2727  function the_post_navigation( $args = array() ) {
2728      echo get_the_post_navigation( $args );
2729  }
2730  
2731  /**
2732   * Returns the navigation to next/previous set of posts, when applicable.
2733   *
2734   * @since 4.1.0
2735   * @since 5.3.0 Added the `aria_label` parameter.
2736   * @since 5.5.0 Added the `class` parameter.
2737   *
2738   * @global WP_Query $wp_query WordPress Query object.
2739   *
2740   * @param array $args {
2741   *     Optional. Default posts navigation arguments. Default empty array.
2742   *
2743   *     @type string $prev_text          Anchor text to display in the previous posts link.
2744   *                                      Default 'Older posts'.
2745   *     @type string $next_text          Anchor text to display in the next posts link.
2746   *                                      Default 'Newer posts'.
2747   *     @type string $screen_reader_text Screen reader text for the nav element.
2748   *                                      Default 'Posts navigation'.
2749   *     @type string $aria_label         ARIA label text for the nav element. Default 'Posts'.
2750   *     @type string $class              Custom class for the nav element. Default 'posts-navigation'.
2751   * }
2752   * @return string Markup for posts links.
2753   */
2754  function get_the_posts_navigation( $args = array() ) {
2755      $navigation = '';
2756  
2757      // Don't print empty markup if there's only one page.
2758      if ( $GLOBALS['wp_query']->max_num_pages > 1 ) {
2759          // Make sure the nav element has an aria-label attribute: fallback to the screen reader text.
2760          if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) {
2761              $args['aria_label'] = $args['screen_reader_text'];
2762          }
2763  
2764          $args = wp_parse_args(
2765              $args,
2766              array(
2767                  'prev_text'          => __( 'Older posts' ),
2768                  'next_text'          => __( 'Newer posts' ),
2769                  'screen_reader_text' => __( 'Posts navigation' ),
2770                  'aria_label'         => __( 'Posts' ),
2771                  'class'              => 'posts-navigation',
2772              )
2773          );
2774  
2775          $next_link = get_previous_posts_link( $args['next_text'] );
2776          $prev_link = get_next_posts_link( $args['prev_text'] );
2777  
2778          if ( $prev_link ) {
2779              $navigation .= '<div class="nav-previous">' . $prev_link . '</div>';
2780          }
2781  
2782          if ( $next_link ) {
2783              $navigation .= '<div class="nav-next">' . $next_link . '</div>';
2784          }
2785  
2786          $navigation = _navigation_markup( $navigation, $args['class'], $args['screen_reader_text'], $args['aria_label'] );
2787      }
2788  
2789      return $navigation;
2790  }
2791  
2792  /**
2793   * Displays the navigation to next/previous set of posts, when applicable.
2794   *
2795   * @since 4.1.0
2796   *
2797   * @param array $args Optional. See get_the_posts_navigation() for available arguments.
2798   *                    Default empty array.
2799   */
2800  function the_posts_navigation( $args = array() ) {
2801      echo get_the_posts_navigation( $args );
2802  }
2803  
2804  /**
2805   * Retrieves a paginated navigation to next/previous set of posts, when applicable.
2806   *
2807   * @since 4.1.0
2808   * @since 5.3.0 Added the `aria_label` parameter.
2809   * @since 5.5.0 Added the `class` parameter.
2810   *
2811   * @param array $args {
2812   *     Optional. Default pagination arguments, see paginate_links().
2813   *
2814   *     @type string $screen_reader_text Screen reader text for navigation element.
2815   *                                      Default 'Posts navigation'.
2816   *     @type string $aria_label         ARIA label text for the nav element. Default 'Posts'.
2817   *     @type string $class              Custom class for the nav element. Default 'pagination'.
2818   * }
2819   * @return string Markup for pagination links.
2820   */
2821  function get_the_posts_pagination( $args = array() ) {
2822      $navigation = '';
2823  
2824      // Don't print empty markup if there's only one page.
2825      if ( $GLOBALS['wp_query']->max_num_pages > 1 ) {
2826          // Make sure the nav element has an aria-label attribute: fallback to the screen reader text.
2827          if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) {
2828              $args['aria_label'] = $args['screen_reader_text'];
2829          }
2830  
2831          $args = wp_parse_args(
2832              $args,
2833              array(
2834                  'mid_size'           => 1,
2835                  'prev_text'          => _x( 'Previous', 'previous set of posts' ),
2836                  'next_text'          => _x( 'Next', 'next set of posts' ),
2837                  'screen_reader_text' => __( 'Posts navigation' ),
2838                  'aria_label'         => __( 'Posts' ),
2839                  'class'              => 'pagination',
2840              )
2841          );
2842  
2843          // Make sure we get a string back. Plain is the next best thing.
2844          if ( isset( $args['type'] ) && 'array' === $args['type'] ) {
2845              $args['type'] = 'plain';
2846          }
2847  
2848          // Set up paginated links.
2849          $links = paginate_links( $args );
2850  
2851          if ( $links ) {
2852              $navigation = _navigation_markup( $links, $args['class'], $args['screen_reader_text'], $args['aria_label'] );
2853          }
2854      }
2855  
2856      return $navigation;
2857  }
2858  
2859  /**
2860   * Displays a paginated navigation to next/previous set of posts, when applicable.
2861   *
2862   * @since 4.1.0
2863   *
2864   * @param array $args Optional. See get_the_posts_pagination() for available arguments.
2865   *                    Default empty array.
2866   */
2867  function the_posts_pagination( $args = array() ) {
2868      echo get_the_posts_pagination( $args );
2869  }
2870  
2871  /**
2872   * Wraps passed links in navigational markup.
2873   *
2874   * @since 4.1.0
2875   * @since 5.3.0 Added the `aria_label` parameter.
2876   * @access private
2877   *
2878   * @param string $links              Navigational links.
2879   * @param string $class              Optional. Custom class for the nav element.
2880   *                                   Default 'posts-navigation'.
2881   * @param string $screen_reader_text Optional. Screen reader text for the nav element.
2882   *                                   Default 'Posts navigation'.
2883   * @param string $aria_label         Optional. ARIA label for the nav element.
2884   *                                   Defaults to the value of `$screen_reader_text`.
2885   * @return string Navigation template tag.
2886   */
2887  function _navigation_markup( $links, $class = 'posts-navigation', $screen_reader_text = '', $aria_label = '' ) {
2888      if ( empty( $screen_reader_text ) ) {
2889          $screen_reader_text = __( 'Posts navigation' );
2890      }
2891      if ( empty( $aria_label ) ) {
2892          $aria_label = $screen_reader_text;
2893      }
2894  
2895      $template = '
2896      <nav class="navigation %1$s" role="navigation" aria-label="%4$s">
2897          <h2 class="screen-reader-text">%2$s</h2>
2898          <div class="nav-links">%3$s</div>
2899      </nav>';
2900  
2901      /**
2902       * Filters the navigation markup template.
2903       *
2904       * Note: The filtered template HTML must contain specifiers for the navigation
2905       * class (%1$s), the screen-reader-text value (%2$s), placement of the navigation
2906       * links (%3$s), and ARIA label text if screen-reader-text does not fit that (%4$s):
2907       *
2908       *     <nav class="navigation %1$s" role="navigation" aria-label="%4$s">
2909       *         <h2 class="screen-reader-text">%2$s</h2>
2910       *         <div class="nav-links">%3$s</div>
2911       *     </nav>
2912       *
2913       * @since 4.4.0
2914       *
2915       * @param string $template The default template.
2916       * @param string $class    The class passed by the calling function.
2917       * @return string Navigation template.
2918       */
2919      $template = apply_filters( 'navigation_markup_template', $template, $class );
2920  
2921      return sprintf( $template, sanitize_html_class( $class ), esc_html( $screen_reader_text ), $links, esc_html( $aria_label ) );
2922  }
2923  
2924  /**
2925   * Retrieves the comments page number link.
2926   *
2927   * @since 2.7.0
2928   *
2929   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
2930   *
2931   * @param int $pagenum  Optional. Page number. Default 1.
2932   * @param int $max_page Optional. The maximum number of comment pages. Default 0.
2933   * @return string The comments page number link URL.
2934   */
2935  function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) {
2936      global $wp_rewrite;
2937  
2938      $pagenum = (int) $pagenum;
2939  
2940      $result = get_permalink();
2941  
2942      if ( 'newest' === get_option( 'default_comments_page' ) ) {
2943          if ( $pagenum != $max_page ) {
2944              if ( $wp_rewrite->using_permalinks() ) {
2945                  $result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' );
2946              } else {
2947                  $result = add_query_arg( 'cpage', $pagenum, $result );
2948              }
2949          }
2950      } elseif ( $pagenum > 1 ) {
2951          if ( $wp_rewrite->using_permalinks() ) {
2952              $result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' );
2953          } else {
2954              $result = add_query_arg( 'cpage', $pagenum, $result );
2955          }
2956      }
2957  
2958      $result .= '#comments';
2959  
2960      /**
2961       * Filters the comments page number link for the current request.
2962       *
2963       * @since 2.7.0
2964       *
2965       * @param string $result The comments page number link.
2966       */
2967      return apply_filters( 'get_comments_pagenum_link', $result );
2968  }
2969  
2970  /**
2971   * Retrieves the link to the next comments page.
2972   *
2973   * @since 2.7.1
2974   *
2975   * @global WP_Query $wp_query WordPress Query object.
2976   *
2977   * @param string $label    Optional. Label for link text. Default empty.
2978   * @param int    $max_page Optional. Max page. Default 0.
2979   * @return string|void HTML-formatted link for the next page of comments.
2980   */
2981  function get_next_comments_link( $label = '', $max_page = 0 ) {
2982      global $wp_query;
2983  
2984      if ( ! is_singular() ) {
2985          return;
2986      }
2987  
2988      $page = get_query_var( 'cpage' );
2989  
2990      if ( ! $page ) {
2991          $page = 1;
2992      }
2993  
2994      $nextpage = (int) $page + 1;
2995  
2996      if ( empty( $max_page ) ) {
2997          $max_page = $wp_query->max_num_comment_pages;
2998      }
2999  
3000      if ( empty( $max_page ) ) {
3001          $max_page = get_comment_pages_count();
3002      }
3003  
3004      if ( $nextpage > $max_page ) {
3005          return;
3006      }
3007  
3008      if ( empty( $label ) ) {
3009          $label = __( 'Newer Comments &raquo;' );
3010      }
3011  
3012      /**
3013       * Filters the anchor tag attributes for the next comments page link.
3014       *
3015       * @since 2.7.0
3016       *
3017       * @param string $attributes Attributes for the anchor tag.
3018       */
3019      return '<a href="' . esc_url( get_comments_pagenum_link( $nextpage, $max_page ) ) . '" ' . apply_filters( 'next_comments_link_attributes', '' ) . '>' . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label ) . '</a>';
3020  }
3021  
3022  /**
3023   * Displays the link to the next comments page.
3024   *
3025   * @since 2.7.0
3026   *
3027   * @param string $label    Optional. Label for link text. Default empty.
3028   * @param int    $max_page Optional. Max page. Default 0.
3029   */
3030  function next_comments_link( $label = '', $max_page = 0 ) {
3031      echo get_next_comments_link( $label, $max_page );
3032  }
3033  
3034  /**
3035   * Retrieves the link to the previous comments page.
3036   *
3037   * @since 2.7.1
3038   *
3039   * @param string $label Optional. Label for comments link text. Default empty.
3040   * @return string|void HTML-formatted link for the previous page of comments.
3041   */
3042  function get_previous_comments_link( $label = '' ) {
3043      if ( ! is_singular() ) {
3044          return;
3045      }
3046  
3047      $page = get_query_var( 'cpage' );
3048  
3049      if ( (int) $page <= 1 ) {
3050          return;
3051      }
3052  
3053      $prevpage = (int) $page - 1;
3054  
3055      if ( empty( $label ) ) {
3056          $label = __( '&laquo; Older Comments' );
3057      }
3058  
3059      /**
3060       * Filters the anchor tag attributes for the previous comments page link.
3061       *
3062       * @since 2.7.0
3063       *
3064       * @param string $attributes Attributes for the anchor tag.
3065       */
3066      return '<a href="' . esc_url( get_comments_pagenum_link( $prevpage ) ) . '" ' . apply_filters( 'previous_comments_link_attributes', '' ) . '>' . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label ) . '</a>';
3067  }
3068  
3069  /**
3070   * Displays the link to the previous comments page.
3071   *
3072   * @since 2.7.0
3073   *
3074   * @param string $label Optional. Label for comments link text. Default empty.
3075   */
3076  function previous_comments_link( $label = '' ) {
3077      echo get_previous_comments_link( $label );
3078  }
3079  
3080  /**
3081   * Displays or retrieves pagination links for the comments on the current post.
3082   *
3083   * @see paginate_links()
3084   * @since 2.7.0
3085   *
3086   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
3087   *
3088   * @param string|array $args Optional args. See paginate_links(). Default empty array.
3089   * @return void|string|array Void if 'echo' argument is true and 'type' is not an array,
3090   *                           or if the query is not for an existing single post of any post type.
3091   *                           Otherwise, markup for comment page links or array of comment page links,
3092   *                           depending on 'type' argument.
3093   */
3094  function paginate_comments_links( $args = array() ) {
3095      global $wp_rewrite;
3096  
3097      if ( ! is_singular() ) {
3098          return;
3099      }
3100  
3101      $page = get_query_var( 'cpage' );
3102      if ( ! $page ) {
3103          $page = 1;
3104      }
3105      $max_page = get_comment_pages_count();
3106      $defaults = array(
3107          'base'         => add_query_arg( 'cpage', '%#%' ),
3108          'format'       => '',
3109          'total'        => $max_page,
3110          'current'      => $page,
3111          'echo'         => true,
3112          'type'         => 'plain',
3113          'add_fragment' => '#comments',
3114      );
3115      if ( $wp_rewrite->using_permalinks() ) {
3116          $defaults['base'] = user_trailingslashit( trailingslashit( get_permalink() ) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged' );
3117      }
3118  
3119      $args       = wp_parse_args( $args, $defaults );
3120      $page_links = paginate_links( $args );
3121  
3122      if ( $args['echo'] && 'array' !== $args['type'] ) {
3123          echo $page_links;
3124      } else {
3125          return $page_links;
3126      }
3127  }
3128  
3129  /**
3130   * Retrieves navigation to next/previous set of comments, when applicable.
3131   *
3132   * @since 4.4.0
3133   * @since 5.3.0 Added the `aria_label` parameter.
3134   * @since 5.5.0 Added the `class` parameter.
3135   *
3136   * @param array $args {
3137   *     Optional. Default comments navigation arguments.
3138   *
3139   *     @type string $prev_text          Anchor text to display in the previous comments link.
3140   *                                      Default 'Older comments'.
3141   *     @type string $next_text          Anchor text to display in the next comments link.
3142   *                                      Default 'Newer comments'.
3143   *     @type string $screen_reader_text Screen reader text for the nav element. Default 'Comments navigation'.
3144   *     @type string $aria_label         ARIA label text for the nav element. Default 'Comments'.
3145   *     @type string $class              Custom class for the nav element. Default 'comment-navigation'.
3146   * }
3147   * @return string Markup for comments links.
3148   */
3149  function get_the_comments_navigation( $args = array() ) {
3150      $navigation = '';
3151  
3152      // Are there comments to navigate through?
3153      if ( get_comment_pages_count() > 1 ) {
3154          // Make sure the nav element has an aria-label attribute: fallback to the screen reader text.
3155          if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) {
3156              $args['aria_label'] = $args['screen_reader_text'];
3157          }
3158  
3159          $args = wp_parse_args(
3160              $args,
3161              array(
3162                  'prev_text'          => __( 'Older comments' ),
3163                  'next_text'          => __( 'Newer comments' ),
3164                  'screen_reader_text' => __( 'Comments navigation' ),
3165                  'aria_label'         => __( 'Comments' ),
3166                  'class'              => 'comment-navigation',
3167              )
3168          );
3169  
3170          $prev_link = get_previous_comments_link( $args['prev_text'] );
3171          $next_link = get_next_comments_link( $args['next_text'] );
3172  
3173          if ( $prev_link ) {
3174              $navigation .= '<div class="nav-previous">' . $prev_link . '</div>';
3175          }
3176  
3177          if ( $next_link ) {
3178              $navigation .= '<div class="nav-next">' . $next_link . '</div>';
3179          }
3180  
3181          $navigation = _navigation_markup( $navigation, $args['class'], $args['screen_reader_text'], $args['aria_label'] );
3182      }
3183  
3184      return $navigation;
3185  }
3186  
3187  /**
3188   * Displays navigation to next/previous set of comments, when applicable.
3189   *
3190   * @since 4.4.0
3191   *
3192   * @param array $args See get_the_comments_navigation() for available arguments. Default empty array.
3193   */
3194  function the_comments_navigation( $args = array() ) {
3195      echo get_the_comments_navigation( $args );
3196  }
3197  
3198  /**
3199   * Retrieves a paginated navigation to next/previous set of comments, when applicable.
3200   *
3201   * @since 4.4.0
3202   * @since 5.3.0 Added the `aria_label` parameter.
3203   * @since 5.5.0 Added the `class` parameter.
3204   *
3205   * @see paginate_comments_links()
3206   *
3207   * @param array $args {
3208   *     Optional. Default pagination arguments.
3209   *
3210   *     @type string $screen_reader_text Screen reader text for the nav element. Default 'Comments navigation'.
3211   *     @type string $aria_label         ARIA label text for the nav element. Default 'Comments'.
3212   *     @type string $class              Custom class for the nav element. Default 'comments-pagination'.
3213   * }
3214   * @return string Markup for pagination links.
3215   */
3216  function get_the_comments_pagination( $args = array() ) {
3217      $navigation = '';
3218  
3219      // Make sure the nav element has an aria-label attribute: fallback to the screen reader text.
3220      if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) {
3221          $args['aria_label'] = $args['screen_reader_text'];
3222      }
3223  
3224      $args         = wp_parse_args(
3225          $args,
3226          array(
3227              'screen_reader_text' => __( 'Comments navigation' ),
3228              'aria_label'         => __( 'Comments' ),
3229              'class'              => 'comments-pagination',
3230          )
3231      );
3232      $args['echo'] = false;
3233  
3234      // Make sure we get a string back. Plain is the next best thing.
3235      if ( isset( $args['type'] ) && 'array' === $args['type'] ) {
3236          $args['type'] = 'plain';
3237      }
3238  
3239      $links = paginate_comments_links( $args );
3240  
3241      if ( $links ) {
3242          $navigation = _navigation_markup( $links, $args['class'], $args['screen_reader_text'], $args['aria_label'] );
3243      }
3244  
3245      return $navigation;
3246  }
3247  
3248  /**
3249   * Displays a paginated navigation to next/previous set of comments, when applicable.
3250   *
3251   * @since 4.4.0
3252   *
3253   * @param array $args See get_the_comments_pagination() for available arguments. Default empty array.
3254   */
3255  function the_comments_pagination( $args = array() ) {
3256      echo get_the_comments_pagination( $args );
3257  }
3258  
3259  /**
3260   * Retrieves the URL for the current site where the front end is accessible.
3261   *
3262   * Returns the 'home' option with the appropriate protocol. The protocol will be 'https'
3263   * if is_ssl() evaluates to true; otherwise, it will be the same as the 'home' option.
3264   * If `$scheme` is 'http' or 'https', is_ssl() is overridden.
3265   *
3266   * @since 3.0.0
3267   *
3268   * @param string      $path   Optional. Path relative to the home URL. Default empty.
3269   * @param string|null $scheme Optional. Scheme to give the home URL context. Accepts
3270   *                            'http', 'https', 'relative', 'rest', or null. Default null.
3271   * @return string Home URL link with optional path appended.
3272   */
3273  function home_url( $path = '', $scheme = null ) {
3274      return get_home_url( null, $path, $scheme );
3275  }
3276  
3277  /**
3278   * Retrieves the URL for a given site where the front end is accessible.
3279   *
3280   * Returns the 'home' option with the appropriate protocol. The protocol will be 'https'
3281   * if is_ssl() evaluates to true; otherwise, it will be the same as the 'home' option.
3282   * If `$scheme` is 'http' or 'https', is_ssl() is overridden.
3283   *
3284   * @since 3.0.0
3285   *
3286   * @param int|null    $blog_id Optional. Site ID. Default null (current site).
3287   * @param string      $path    Optional. Path relative to the home URL. Default empty.
3288   * @param string|null $scheme  Optional. Scheme to give the home URL context. Accepts
3289   *                             'http', 'https', 'relative', 'rest', or null. Default null.
3290   * @return string Home URL link with optional path appended.
3291   */
3292  function get_home_url( $blog_id = null, $path = '', $scheme = null ) {
3293      $orig_scheme = $scheme;
3294  
3295      if ( empty( $blog_id ) || ! is_multisite() ) {
3296          $url = get_option( 'home' );
3297      } else {
3298          switch_to_blog( $blog_id );
3299          $url = get_option( 'home' );
3300          restore_current_blog();
3301      }
3302  
3303      if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ), true ) ) {
3304          if ( is_ssl() ) {
3305              $scheme = 'https';
3306          } else {
3307              $scheme = parse_url( $url, PHP_URL_SCHEME );
3308          }
3309      }
3310  
3311      $url = set_url_scheme( $url, $scheme );
3312  
3313      if ( $path && is_string( $path ) ) {
3314          $url .= '/' . ltrim( $path, '/' );
3315      }
3316  
3317      /**
3318       * Filters the home URL.
3319       *
3320       * @since 3.0.0
3321       *
3322       * @param string      $url         The complete home URL including scheme and path.
3323       * @param string      $path        Path relative to the home URL. Blank string if no path is specified.
3324       * @param string|null $orig_scheme Scheme to give the home URL context. Accepts 'http', 'https',
3325       *                                 'relative', 'rest', or null.
3326       * @param int|null    $blog_id     Site ID, or null for the current site.
3327       */
3328      return apply_filters( 'home_url', $url, $path, $orig_scheme, $blog_id );
3329  }
3330  
3331  /**
3332   * Retrieves the URL for the current site where WordPress application files
3333   * (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible.
3334   *
3335   * Returns the 'site_url' option with the appropriate protocol, 'https' if
3336   * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
3337   * overridden.
3338   *
3339   * @since 3.0.0
3340   *
3341   * @param string      $path   Optional. Path relative to the site URL. Default empty.
3342   * @param string|null $scheme Optional. Scheme to give the site URL context. See set_url_scheme().
3343   * @return string Site URL link with optional path appended.
3344   */
3345  function site_url( $path = '', $scheme = null ) {
3346      return get_site_url( null, $path, $scheme );
3347  }
3348  
3349  /**
3350   * Retrieves the URL for a given site where WordPress application files
3351   * (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible.
3352   *
3353   * Returns the 'site_url' option with the appropriate protocol, 'https' if
3354   * is_ssl() and 'http' otherwise. If `$scheme` is 'http' or 'https',
3355   * `is_ssl()` is overridden.
3356   *
3357   * @since 3.0.0
3358   *
3359   * @param int|null    $blog_id Optional. Site ID. Default null (current site).
3360   * @param string      $path    Optional. Path relative to the site URL. Default empty.
3361   * @param string|null $scheme  Optional. Scheme to give the site URL context. Accepts
3362   *                             'http', 'https', 'login', 'login_post', 'admin', or
3363   *                             'relative'. Default null.
3364   * @return string Site URL link with optional path appended.
3365   */
3366  function get_site_url( $blog_id = null, $path = '', $scheme = null ) {
3367      if ( empty( $blog_id ) || ! is_multisite() ) {
3368          $url = get_option( 'siteurl' );
3369      } else {
3370          switch_to_blog( $blog_id );
3371          $url = get_option( 'siteurl' );
3372          restore_current_blog();
3373      }
3374  
3375      $url = set_url_scheme( $url, $scheme );
3376  
3377      if ( $path && is_string( $path ) ) {
3378          $url .= '/' . ltrim( $path, '/' );
3379      }
3380  
3381      /**
3382       * Filters the site URL.
3383       *
3384       * @since 2.7.0
3385       *
3386       * @param string      $url     The complete site URL including scheme and path.
3387       * @param string      $path    Path relative to the site URL. Blank string if no path is specified.
3388       * @param string|null $scheme  Scheme to give the site URL context. Accepts 'http', 'https', 'login',
3389       *                             'login_post', 'admin', 'relative' or null.
3390       * @param int|null    $blog_id Site ID, or null for the current site.
3391       */
3392      return apply_filters( 'site_url', $url, $path, $scheme, $blog_id );
3393  }
3394  
3395  /**
3396   * Retrieves the URL to the admin area for the current site.
3397   *
3398   * @since 2.6.0
3399   *
3400   * @param string $path   Optional. Path relative to the admin URL. Default 'admin'.
3401   * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl().
3402   *                       'http' or 'https' can be passed to force those schemes.
3403   * @return string Admin URL link with optional path appended.
3404   */
3405  function admin_url( $path = '', $scheme = 'admin' ) {
3406      return get_admin_url( null, $path, $scheme );
3407  }
3408  
3409  /**
3410   * Retrieves the URL to the admin area for a given site.
3411   *
3412   * @since 3.0.0
3413   *
3414   * @param int|null $blog_id Optional. Site ID. Default null (current site).
3415   * @param string   $path    Optional. Path relative to the admin URL. Default empty.
3416   * @param string   $scheme  Optional. The scheme to use. Accepts 'http' or 'https',
3417   *                          to force those schemes. Default 'admin', which obeys
3418   *                          force_ssl_admin() and is_ssl().
3419   * @return string Admin URL link with optional path appended.
3420   */
3421  function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' ) {
3422      $url = get_site_url( $blog_id, 'wp-admin/', $scheme );
3423  
3424      if ( $path && is_string( $path ) ) {
3425          $url .= ltrim( $path, '/' );
3426      }
3427  
3428      /**
3429       * Filters the admin area URL.
3430       *
3431       * @since 2.8.0
3432       *
3433       * @param string   $url     The complete admin area URL including scheme and path.
3434       * @param string   $path    Path relative to the admin area URL. Blank string if no path is specified.
3435       * @param int|null $blog_id Site ID, or null for the current site.
3436       */
3437      return apply_filters( 'admin_url', $url, $path, $blog_id );
3438  }
3439  
3440  /**
3441   * Retrieves the URL to the includes directory.
3442   *
3443   * @since 2.6.0
3444   *
3445   * @param string      $path   Optional. Path relative to the includes URL. Default empty.
3446   * @param string|null $scheme Optional. Scheme to give the includes URL context. Accepts
3447   *                            'http', 'https', or 'relative'. Default null.
3448   * @return string Includes URL link with optional path appended.
3449   */
3450  function includes_url( $path = '', $scheme = null ) {
3451      $url = site_url( '/' . WPINC . '/', $scheme );
3452  
3453      if ( $path && is_string( $path ) ) {
3454          $url .= ltrim( $path, '/' );
3455      }
3456  
3457      /**
3458       * Filters the URL to the includes directory.
3459       *
3460       * @since 2.8.0
3461       *
3462       * @param string $url  The complete URL to the includes directory including scheme and path.
3463       * @param string $path Path relative to the URL to the wp-includes directory. Blank string
3464       *                     if no path is specified.
3465       */
3466      return apply_filters( 'includes_url', $url, $path );
3467  }
3468  
3469  /**
3470   * Retrieves the URL to the content directory.
3471   *
3472   * @since 2.6.0
3473   *
3474   * @param string $path Optional. Path relative to the content URL. Default empty.
3475   * @return string Content URL link with optional path appended.
3476   */
3477  function content_url( $path = '' ) {
3478      $url = set_url_scheme( WP_CONTENT_URL );
3479  
3480      if ( $path && is_string( $path ) ) {
3481          $url .= '/' . ltrim( $path, '/' );
3482      }
3483  
3484      /**
3485       * Filters the URL to the content directory.
3486       *
3487       * @since 2.8.0
3488       *
3489       * @param string $url  The complete URL to the content directory including scheme and path.
3490       * @param string $path Path relative to the URL to the content directory. Blank string
3491       *                     if no path is specified.
3492       */
3493      return apply_filters( 'content_url', $url, $path );
3494  }
3495  
3496  /**
3497   * Retrieves a URL within the plugins or mu-plugins directory.
3498   *
3499   * Defaults to the plugins directory URL if no arguments are supplied.
3500   *
3501   * @since 2.6.0
3502   *
3503   * @param string $path   Optional. Extra path appended to the end of the URL, including
3504   *                       the relative directory if $plugin is supplied. Default empty.
3505   * @param string $plugin Optional. A full path to a file inside a plugin or mu-plugin.
3506   *                       The URL will be relative to its directory. Default empty.
3507   *                       Typically this is done by passing `__FILE__` as the argument.
3508   * @return string Plugins URL link with optional paths appended.
3509   */
3510  function plugins_url( $path = '', $plugin = '' ) {
3511  
3512      $path          = wp_normalize_path( $path );
3513      $plugin        = wp_normalize_path( $plugin );
3514      $mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );
3515  
3516      if ( ! empty( $plugin ) && 0 === strpos( $plugin, $mu_plugin_dir ) ) {
3517          $url = WPMU_PLUGIN_URL;
3518      } else {
3519          $url = WP_PLUGIN_URL;
3520      }
3521  
3522      $url = set_url_scheme( $url );
3523  
3524      if ( ! empty( $plugin ) && is_string( $plugin ) ) {
3525          $folder = dirname( plugin_basename( $plugin ) );
3526          if ( '.' !== $folder ) {
3527              $url .= '/' . ltrim( $folder, '/' );
3528          }
3529      }
3530  
3531      if ( $path && is_string( $path ) ) {
3532          $url .= '/' . ltrim( $path, '/' );
3533      }
3534  
3535      /**
3536       * Filters the URL to the plugins directory.
3537       *
3538       * @since 2.8.0
3539       *
3540       * @param string $url    The complete URL to the plugins directory including scheme and path.
3541       * @param string $path   Path relative to the URL to the plugins directory. Blank string
3542       *                       if no path is specified.
3543       * @param string $plugin The plugin file path to be relative to. Blank string if no plugin
3544       *                       is specified.
3545       */
3546      return apply_filters( 'plugins_url', $url, $path, $plugin );
3547  }
3548  
3549  /**
3550   * Retrieves the site URL for the current network.
3551   *
3552   * Returns the site URL with the appropriate protocol, 'https' if
3553   * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
3554   * overridden.
3555   *
3556   * @since 3.0.0
3557   *
3558   * @see set_url_scheme()
3559   *
3560   * @param string      $path   Optional. Path relative to the site URL. Default empty.
3561   * @param string|null $scheme Optional. Scheme to give the site URL context. Accepts
3562   *                            'http', 'https', or 'relative'. Default null.
3563   * @return string Site URL link with optional path appended.
3564   */
3565  function network_site_url( $path = '', $scheme = null ) {
3566      if ( ! is_multisite() ) {
3567          return site_url( $path, $scheme );
3568      }
3569  
3570      $current_network = get_network();
3571  
3572      if ( 'relative' === $scheme ) {
3573          $url = $current_network->path;
3574      } else {
3575          $url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme );
3576      }
3577  
3578      if ( $path && is_string( $path ) ) {
3579          $url .= ltrim( $path, '/' );
3580      }
3581  
3582      /**
3583       * Filters the network site URL.
3584       *
3585       * @since 3.0.0
3586       *
3587       * @param string      $url    The complete network site URL including scheme and path.
3588       * @param string      $path   Path relative to the network site URL. Blank string if
3589       *                            no path is specified.
3590       * @param string|null $scheme Scheme to give the URL context. Accepts 'http', 'https',
3591       *                            'relative' or null.
3592       */
3593      return apply_filters( 'network_site_url', $url, $path, $scheme );
3594  }
3595  
3596  /**
3597   * Retrieves the home URL for the current network.
3598   *
3599   * Returns the home URL with the appropriate protocol, 'https' is_ssl()
3600   * and 'http' otherwise. If `$scheme` is 'http' or 'https', `is_ssl()` is
3601   * overridden.
3602   *
3603   * @since 3.0.0
3604   *
3605   * @param string      $path   Optional. Path relative to the home URL. Default empty.
3606   * @param string|null $scheme Optional. Scheme to give the home URL context. Accepts
3607   *                            'http', 'https', or 'relative'. Default null.
3608   * @return string Home URL link with optional path appended.
3609   */
3610  function network_home_url( $path = '', $scheme = null ) {
3611      if ( ! is_multisite() ) {
3612          return home_url( $path, $scheme );
3613      }
3614  
3615      $current_network = get_network();
3616      $orig_scheme     = $scheme;
3617  
3618      if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ), true ) ) {
3619          $scheme = is_ssl() ? 'https' : 'http';
3620      }
3621  
3622      if ( 'relative' === $scheme ) {
3623          $url = $current_network->path;
3624      } else {
3625          $url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme );
3626      }
3627  
3628      if ( $path && is_string( $path ) ) {
3629          $url .= ltrim( $path, '/' );
3630      }
3631  
3632      /**
3633       * Filters the network home URL.
3634       *
3635       * @since 3.0.0
3636       *
3637       * @param string      $url         The complete network home URL including scheme and path.
3638       * @param string      $path        Path relative to the network home URL. Blank string
3639       *                                 if no path is specified.
3640       * @param string|null $orig_scheme Scheme to give the URL context. Accepts 'http', 'https',
3641       *                                 'relative' or null.
3642       */
3643      return apply_filters( 'network_home_url', $url, $path, $orig_scheme );
3644  }
3645  
3646  /**
3647   * Retrieves the URL to the admin area for the network.
3648   *
3649   * @since 3.0.0
3650   *
3651   * @param string $path   Optional path relative to the admin URL. Default empty.
3652   * @param string $scheme Optional. The scheme to use. Default is 'admin', which obeys force_ssl_admin()
3653   *                       and is_ssl(). 'http' or 'https' can be passed to force those schemes.
3654   * @return string Admin URL link with optional path appended.
3655   */
3656  function network_admin_url( $path = '', $scheme = 'admin' ) {
3657      if ( ! is_multisite() ) {
3658          return admin_url( $path, $scheme );
3659      }
3660  
3661      $url = network_site_url( 'wp-admin/network/', $scheme );
3662  
3663      if ( $path && is_string( $path ) ) {
3664          $url .= ltrim( $path, '/' );
3665      }
3666  
3667      /**
3668       * Filters the network admin URL.
3669       *
3670       * @since 3.0.0
3671       *
3672       * @param string $url  The complete network admin URL including scheme and path.
3673       * @param string $path Path relative to the network admin URL. Blank string if
3674       *                     no path is specified.
3675       */
3676      return apply_filters( 'network_admin_url', $url, $path );
3677  }
3678  
3679  /**
3680   * Retrieves the URL to the admin area for the current user.
3681   *
3682   * @since 3.0.0
3683   *
3684   * @param string $path   Optional. Path relative to the admin URL. Default empty.
3685   * @param string $scheme Optional. The scheme to use. Default is 'admin', which obeys force_ssl_admin()
3686   *                       and is_ssl(). 'http' or 'https' can be passed to force those schemes.
3687   * @return string Admin URL link with optional path appended.
3688   */
3689  function user_admin_url( $path = '', $scheme = 'admin' ) {
3690      $url = network_site_url( 'wp-admin/user/', $scheme );
3691  
3692      if ( $path && is_string( $path ) ) {
3693          $url .= ltrim( $path, '/' );
3694      }
3695  
3696      /**
3697       * Filters the user admin URL for the current user.
3698       *
3699       * @since 3.1.0
3700       *
3701       * @param string $url  The complete URL including scheme and path.
3702       * @param string $path Path relative to the URL. Blank string if
3703       *                     no path is specified.
3704       */
3705      return apply_filters( 'user_admin_url', $url, $path );
3706  }
3707  
3708  /**
3709   * Retrieves the URL to the admin area for either the current site or the network depending on context.
3710   *
3711   * @since 3.1.0
3712   *
3713   * @param string $path   Optional. Path relative to the admin URL. Default empty.
3714   * @param string $scheme Optional. The scheme to use. Default is 'admin', which obeys force_ssl_admin()
3715   *                       and is_ssl(). 'http' or 'https' can be passed to force those schemes.
3716   * @return string Admin URL link with optional path appended.
3717   */
3718  function self_admin_url( $path = '', $scheme = 'admin' ) {
3719      if ( is_network_admin() ) {
3720          $url = network_admin_url( $path, $scheme );
3721      } elseif ( is_user_admin() ) {
3722          $url = user_admin_url( $path, $scheme );
3723      } else {
3724          $url = admin_url( $path, $scheme );
3725      }
3726  
3727      /**
3728       * Filters the admin URL for the current site or network depending on context.
3729       *
3730       * @since 4.9.0
3731       *
3732       * @param string $url    The complete URL including scheme and path.
3733       * @param string $path   Path relative to the URL. Blank string if no path is specified.
3734       * @param string $scheme The scheme to use.
3735       */
3736      return apply_filters( 'self_admin_url', $url, $path, $scheme );
3737  }
3738  
3739  /**
3740   * Sets the scheme for a URL.
3741   *
3742   * @since 3.4.0
3743   * @since 4.4.0 The 'rest' scheme was added.
3744   *
3745   * @param string      $url    Absolute URL that includes a scheme
3746   * @param string|null $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login',
3747   *                            'login_post', 'admin', 'relative', 'rest', 'rpc', or null. Default null.
3748   * @return string URL with chosen scheme.
3749   */
3750  function set_url_scheme( $url, $scheme = null ) {
3751      $orig_scheme = $scheme;
3752  
3753      if ( ! $scheme ) {
3754          $scheme = is_ssl() ? 'https' : 'http';
3755      } elseif ( 'admin' === $scheme || 'login' === $scheme || 'login_post' === $scheme || 'rpc' === $scheme ) {
3756          $scheme = is_ssl() || force_ssl_admin() ? 'https' : 'http';
3757      } elseif ( 'http' !== $scheme && 'https' !== $scheme && 'relative' !== $scheme ) {
3758          $scheme = is_ssl() ? 'https' : 'http';
3759      }
3760  
3761      $url = trim( $url );
3762      if ( substr( $url, 0, 2 ) === '//' ) {
3763          $url = 'http:' . $url;
3764      }
3765  
3766      if ( 'relative' === $scheme ) {
3767          $url = ltrim( preg_replace( '#^\w+://[^/]*#', '', $url ) );
3768          if ( '' !== $url && '/' === $url[0] ) {
3769              $url = '/' . ltrim( $url, "/ \t\n\r\0\x0B" );
3770          }
3771      } else {
3772          $url = preg_replace( '#^\w+://#', $scheme . '://', $url );
3773      }
3774  
3775      /**
3776       * Filters the resulting URL after setting the scheme.
3777       *
3778       * @since 3.4.0
3779       *
3780       * @param string      $url         The complete URL including scheme and path.
3781       * @param string      $scheme      Scheme applied to the URL. One of 'http', 'https', or 'relative'.
3782       * @param string|null $orig_scheme Scheme requested for the URL. One of 'http', 'https', 'login',
3783       *                                 'login_post', 'admin', 'relative', 'rest', 'rpc', or null.
3784       */
3785      return apply_filters( 'set_url_scheme', $url, $scheme, $orig_scheme );
3786  }
3787  
3788  /**
3789   * Retrieves the URL to the user's dashboard.
3790   *
3791   * If a user does not belong to any site, the global user dashboard is used. If the user
3792   * belongs to the current site, the dashboard for the current site is returned. If the user
3793   * cannot edit the current site, the dashboard to the user's primary site is returned.
3794   *
3795   * @since 3.1.0
3796   *
3797   * @param int    $user_id Optional. User ID. Defaults to current user.
3798   * @param string $path    Optional path relative to the dashboard. Use only paths known to
3799   *                        both site and user admins. Default empty.
3800   * @param string $scheme  The scheme to use. Default is 'admin', which obeys force_ssl_admin()
3801   *                        and is_ssl(). 'http' or 'https' can be passed to force those schemes.
3802   * @return string Dashboard URL link with optional path appended.
3803   */
3804  function get_dashboard_url( $user_id = 0, $path = '', $scheme = 'admin' ) {
3805      $user_id = $user_id ? (int) $user_id : get_current_user_id();
3806  
3807      $blogs = get_blogs_of_user( $user_id );
3808  
3809      if ( is_multisite() && ! user_can( $user_id, 'manage_network' ) && empty( $blogs ) ) {
3810          $url = user_admin_url( $path, $scheme );
3811      } elseif ( ! is_multisite() ) {
3812          $url = admin_url( $path, $scheme );
3813      } else {
3814          $current_blog = get_current_blog_id();
3815  
3816          if ( $current_blog && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blog, array_keys( $blogs ), true ) ) ) {
3817              $url = admin_url( $path, $scheme );
3818          } else {
3819              $active = get_active_blog_for_user( $user_id );
3820              if ( $active ) {
3821                  $url = get_admin_url( $active->blog_id, $path, $scheme );
3822              } else {
3823                  $url = user_admin_url( $path, $scheme );
3824              }
3825          }
3826      }
3827  
3828      /**
3829       * Filters the dashboard URL for a user.
3830       *
3831       * @since 3.1.0
3832       *
3833       * @param string $url     The complete URL including scheme and path.
3834       * @param int    $user_id The user ID.
3835       * @param string $path    Path relative to the URL. Blank string if no path is specified.
3836       * @param string $scheme  Scheme to give the URL context. Accepts 'http', 'https', 'login',
3837       *                        'login_post', 'admin', 'relative' or null.
3838       */
3839      return apply_filters( 'user_dashboard_url', $url, $user_id, $path, $scheme );
3840  }
3841  
3842  /**
3843   * Retrieves the URL to the user's profile editor.
3844   *
3845   * @since 3.1.0
3846   *
3847   * @param int    $user_id Optional. User ID. Defaults to current user.
3848   * @param string $scheme  Optional. The scheme to use. Default is 'admin', which obeys force_ssl_admin()
3849   *                        and is_ssl(). 'http' or 'https' can be passed to force those schemes.
3850   * @return string Dashboard URL link with optional path appended.
3851   */
3852  function get_edit_profile_url( $user_id = 0, $scheme = 'admin' ) {
3853      $user_id = $user_id ? (int) $user_id : get_current_user_id();
3854  
3855      if ( is_user_admin() ) {
3856          $url = user_admin_url( 'profile.php', $scheme );
3857      } elseif ( is_network_admin() ) {
3858          $url = network_admin_url( 'profile.php', $scheme );
3859      } else {
3860          $url = get_dashboard_url( $user_id, 'profile.php', $scheme );
3861      }
3862  
3863      /**
3864       * Filters the URL for a user's profile editor.
3865       *
3866       * @since 3.1.0
3867       *
3868       * @param string $url     The complete URL including scheme and path.
3869       * @param int    $user_id The user ID.
3870       * @param string $scheme  Scheme to give the URL context. Accepts 'http', 'https', 'login',
3871       *                        'login_post', 'admin', 'relative' or null.
3872       */
3873      return apply_filters( 'edit_profile_url', $url, $user_id, $scheme );
3874  }
3875  
3876  /**
3877   * Returns the canonical URL for a post.
3878   *
3879   * When the post is the same as the current requested page the function will handle the
3880   * pagination arguments too.
3881   *
3882   * @since 4.6.0
3883   *
3884   * @param int|WP_Post $post Optional. Post ID or object. Default is global `$post`.
3885   * @return string|false The canonical URL, or false if the post does not exist or has not
3886   *                      been published yet.
3887   */
3888  function wp_get_canonical_url( $post = null ) {
3889      $post = get_post( $post );
3890  
3891      if ( ! $post ) {
3892          return false;
3893      }
3894  
3895      if ( 'publish' !== $post->post_status ) {
3896          return false;
3897      }
3898  
3899      $canonical_url = get_permalink( $post );
3900  
3901      // If a canonical is being generated for the current page, make sure it has pagination if needed.
3902      if ( get_queried_object_id() === $post->ID ) {
3903          $page = get_query_var( 'page', 0 );
3904          if ( $page >= 2 ) {
3905              if ( ! get_option( 'permalink_structure' ) ) {
3906                  $canonical_url = add_query_arg( 'page', $page, $canonical_url );
3907              } else {
3908                  $canonical_url = trailingslashit( $canonical_url ) . user_trailingslashit( $page, 'single_paged' );
3909              }
3910          }
3911  
3912          $cpage = get_query_var( 'cpage', 0 );
3913          if ( $cpage ) {
3914              $canonical_url = get_comments_pagenum_link( $cpage );
3915          }
3916      }
3917  
3918      /**
3919       * Filters the canonical URL for a post.
3920       *
3921       * @since 4.6.0
3922       *
3923       * @param string  $canonical_url The post's canonical URL.
3924       * @param WP_Post $post          Post object.
3925       */
3926      return apply_filters( 'get_canonical_url', $canonical_url, $post );
3927  }
3928  
3929  /**
3930   * Outputs rel=canonical for singular queries.
3931   *
3932   * @since 2.9.0
3933   * @since 4.6.0 Adjusted to use `wp_get_canonical_url()`.
3934   */
3935  function rel_canonical() {
3936      if ( ! is_singular() ) {
3937          return;
3938      }
3939  
3940      $id = get_queried_object_id();
3941  
3942      if ( 0 === $id ) {
3943          return;
3944      }
3945  
3946      $url = wp_get_canonical_url( $id );
3947  
3948      if ( ! empty( $url ) ) {
3949          echo '<link rel="canonical" href="' . esc_url( $url ) . '" />' . "\n";
3950      }
3951  }
3952  
3953  /**
3954   * Returns a shortlink for a post, page, attachment, or site.
3955   *
3956   * This function exists to provide a shortlink tag that all themes and plugins can target.
3957   * A plugin must hook in to provide the actual shortlinks. Default shortlink support is
3958   * limited to providing ?p= style links for posts. Plugins can short-circuit this function
3959   * via the {@see 'pre_get_shortlink'} filter or filter the output via the {@see 'get_shortlink'}
3960   * filter.
3961   *
3962   * @since 3.0.0
3963   *
3964   * @param int    $id          Optional. A post or site ID. Default is 0, which means the current post or site.
3965   * @param string $context     Optional. Whether the ID is a 'site' id, 'post' id, or 'media' id. If 'post',
3966   *                            the post_type of the post is consulted. If 'query', the current query is consulted
3967   *                            to determine the ID and context. Default 'post'.
3968   * @param bool   $allow_slugs Optional. Whether to allow post slugs in the shortlink. It is up to the plugin how
3969   *                            and whether to honor this. Default true.
3970   * @return string A shortlink or an empty string if no shortlink exists for the requested resource or if shortlinks
3971   *                are not enabled.
3972   */
3973  function wp_get_shortlink( $id = 0, $context = 'post', $allow_slugs = true ) {
3974      /**
3975       * Filters whether to preempt generating a shortlink for the given post.
3976       *
3977       * Returning a truthy value from the filter will effectively short-circuit
3978       * the shortlink generation process, returning that value instead.
3979       *
3980       * @since 3.0.0
3981       *
3982       * @param false|string $return      Short-circuit return value. Either false or a URL string.
3983       * @param int          $id          Post ID, or 0 for the current post.
3984       * @param string       $context     The context for the link. One of 'post' or 'query',
3985       * @param bool         $allow_slugs Whether to allow post slugs in the shortlink.
3986       */
3987      $shortlink = apply_filters( 'pre_get_shortlink', false, $id, $context, $allow_slugs );
3988  
3989      if ( false !== $shortlink ) {
3990          return $shortlink;
3991      }
3992  
3993      $post_id = 0;
3994      if ( 'query' === $context && is_singular() ) {
3995          $post_id = get_queried_object_id();
3996          $post    = get_post( $post_id );
3997      } elseif ( 'post' === $context ) {
3998          $post = get_post( $id );
3999          if ( ! empty( $post->ID ) ) {
4000              $post_id = $post->ID;
4001          }
4002      }
4003  
4004      $shortlink = '';
4005  
4006      // Return `?p=` link for all public post types.
4007      if ( ! empty( $post_id ) ) {
4008          $post_type = get_post_type_object( $post->post_type );
4009  
4010          if ( 'page' === $post->post_type && get_option( 'page_on_front' ) == $post->ID && 'page' === get_option( 'show_on_front' ) ) {
4011              $shortlink = home_url( '/' );
4012          } elseif ( $post_type && $post_type->public ) {
4013              $shortlink = home_url( '?p=' . $post_id );
4014          }
4015      }
4016  
4017      /**
4018       * Filters the shortlink for a post.
4019       *
4020       * @since 3.0.0
4021       *
4022       * @param string $shortlink   Shortlink URL.
4023       * @param int    $id          Post ID, or 0 for the current post.
4024       * @param string $context     The context for the link. One of 'post' or 'query',
4025       * @param bool   $allow_slugs Whether to allow post slugs in the shortlink. Not used by default.
4026       */
4027      return apply_filters( 'get_shortlink', $shortlink, $id, $context, $allow_slugs );
4028  }
4029  
4030  /**
4031   * Injects rel=shortlink into the head if a shortlink is defined for the current page.
4032   *
4033   * Attached to the {@see 'wp_head'} action.
4034   *
4035   * @since 3.0.0
4036   */
4037  function wp_shortlink_wp_head() {
4038      $shortlink = wp_get_shortlink( 0, 'query' );
4039  
4040      if ( empty( $shortlink ) ) {
4041          return;
4042      }
4043  
4044      echo "<link rel='shortlink' href='" . esc_url( $shortlink ) . "' />\n";
4045  }
4046  
4047  /**
4048   * Sends a Link: rel=shortlink header if a shortlink is defined for the current page.
4049   *
4050   * Attached to the {@see 'wp'} action.
4051   *
4052   * @since 3.0.0
4053   */
4054  function wp_shortlink_header() {
4055      if ( headers_sent() ) {
4056          return;
4057      }
4058  
4059      $shortlink = wp_get_shortlink( 0, 'query' );
4060  
4061      if ( empty( $shortlink ) ) {
4062          return;
4063      }
4064  
4065      header( 'Link: <' . $shortlink . '>; rel=shortlink', false );
4066  }
4067  
4068  /**
4069   * Displays the shortlink for a post.
4070   *
4071   * Must be called from inside "The Loop"
4072   *
4073   * Call like the_shortlink( __( 'Shortlinkage FTW' ) )
4074   *
4075   * @since 3.0.0
4076   *
4077   * @param string $text   Optional The link text or HTML to be displayed. Defaults to 'This is the short link.'
4078   * @param string $title  Optional The tooltip for the link. Must be sanitized. Defaults to the sanitized post title.
4079   * @param string $before Optional HTML to display before the link. Default empty.
4080   * @param string $after  Optional HTML to display after the link. Default empty.
4081   */
4082  function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) {
4083      $post = get_post();
4084  
4085      if ( empty( $text ) ) {
4086          $text = __( 'This is the short link.' );
4087      }
4088  
4089      if ( empty( $title ) ) {
4090          $title = the_title_attribute( array( 'echo' => false ) );
4091      }
4092  
4093      $shortlink = wp_get_shortlink( $post->ID );
4094  
4095      if ( ! empty( $shortlink ) ) {
4096          $link = '<a rel="shortlink" href="' . esc_url( $shortlink ) . '" title="' . $title . '">' . $text . '</a>';
4097  
4098          /**
4099           * Filters the short link anchor tag for a post.
4100           *
4101           * @since 3.0.0
4102           *
4103           * @param string $link      Shortlink anchor tag.
4104           * @param string $shortlink Shortlink URL.
4105           * @param string $text      Shortlink's text.
4106           * @param string $title     Shortlink's title attribute.
4107           */
4108          $link = apply_filters( 'the_shortlink', $link, $shortlink, $text, $title );
4109          echo $before, $link, $after;
4110      }
4111  }
4112  
4113  
4114  /**
4115   * Retrieves the avatar URL.
4116   *
4117   * @since 4.2.0
4118   *
4119   * @param mixed $id_or_email The Gravatar to retrieve a URL for. Accepts a user_id, gravatar md5 hash,
4120   *                           user email, WP_User object, WP_Post object, or WP_Comment object.
4121   * @param array $args {
4122   *     Optional. Arguments to return instead of the default arguments.
4123   *
4124   *     @type int    $size           Height and width of the avatar in pixels. Default 96.
4125   *     @type string $default        URL for the default image or a default type. Accepts '404' (return
4126   *                                  a 404 instead of a default image), 'retro' (8bit), 'monsterid' (monster),
4127   *                                  'wavatar' (cartoon face), 'indenticon' (the "quilt"), 'mystery', 'mm',
4128   *                                  or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF), or
4129   *                                  'gravatar_default' (the Gravatar logo). Default is the value of the
4130   *                                  'avatar_default' option, with a fallback of 'mystery'.
4131   *     @type bool   $force_default  Whether to always show the default image, never the Gravatar. Default false.
4132   *     @type string $rating         What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are
4133   *                                  judged in that order. Default is the value of the 'avatar_rating' option.
4134   *     @type string $scheme         URL scheme to use. See set_url_scheme() for accepted values.
4135   *                                  Default null.
4136   *     @type array  $processed_args When the function returns, the value will be the processed/sanitized $args
4137   *                                  plus a "found_avatar" guess. Pass as a reference. Default null.
4138   * }
4139   * @return string|false The URL of the avatar on success, false on failure.
4140   */
4141  function get_avatar_url( $id_or_email, $args = null ) {
4142      $args = get_avatar_data( $id_or_email, $args );
4143      return $args['url'];
4144  }
4145  
4146  
4147  /**
4148   * Check if this comment type allows avatars to be retrieved.
4149   *
4150   * @since 5.1.0
4151   *
4152   * @param string $comment_type Comment type to check.
4153   * @return bool Whether the comment type is allowed for retrieving avatars.
4154   */
4155  function is_avatar_comment_type( $comment_type ) {
4156      /**
4157       * Filters the list of allowed comment types for retrieving avatars.
4158       *
4159       * @since 3.0.0
4160       *
4161       * @param array $types An array of content types. Default only contains 'comment'.
4162       */
4163      $allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) );
4164  
4165      return in_array( $comment_type, (array) $allowed_comment_types, true );
4166  }
4167  
4168  
4169  /**
4170   * Retrieves default data about the avatar.
4171   *
4172   * @since 4.2.0
4173   *
4174   * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash,
4175   *                           user email, WP_User object, WP_Post object, or WP_Comment object.
4176   * @param array $args {
4177   *     Optional. Arguments to return instead of the default arguments.
4178   *
4179   *     @type int    $size           Height and width of the avatar image file in pixels. Default 96.
4180   *     @type int    $height         Display height of the avatar in pixels. Defaults to $size.
4181   *     @type int    $width          Display width of the avatar in pixels. Defaults to $size.
4182   *     @type string $default        URL for the default image or a default type. Accepts '404' (return
4183   *                                  a 404 instead of a default image), 'retro' (8bit), 'monsterid' (monster),
4184   *                                  'wavatar' (cartoon face), 'indenticon' (the "quilt"), 'mystery', 'mm',
4185   *                                  or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF), or
4186   *                                  'gravatar_default' (the Gravatar logo). Default is the value of the
4187   *                                  'avatar_default' option, with a fallback of 'mystery'.
4188   *     @type bool   $force_default  Whether to always show the default image, never the Gravatar. Default false.
4189   *     @type string $rating         What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are
4190   *                                  judged in that order. Default is the value of the 'avatar_rating' option.
4191   *     @type string $scheme         URL scheme to use. See set_url_scheme() for accepted values.
4192   *                                  Default null.
4193   *     @type array  $processed_args When the function returns, the value will be the processed/sanitized $args
4194   *                                  plus a "found_avatar" guess. Pass as a reference. Default null.
4195   *     @type string $extra_attr     HTML attributes to insert in the IMG element. Is not sanitized. Default empty.
4196   * }
4197   * @return array {
4198   *     Along with the arguments passed in `$args`, this will contain a couple of extra arguments.
4199   *
4200   *     @type bool   $found_avatar True if we were able to find an avatar for this user,
4201   *                                false or not set if we couldn't.
4202   *     @type string $url          The URL of the avatar we found.
4203   * }
4204   */
4205  function get_avatar_data( $id_or_email, $args = null ) {
4206      $args = wp_parse_args(
4207          $args,
4208          array(
4209              'size'           => 96,
4210              'height'         => null,
4211              'width'          => null,
4212              'default'        => get_option( 'avatar_default', 'mystery' ),
4213              'force_default'  => false,
4214              'rating'         => get_option( 'avatar_rating' ),
4215              'scheme'         => null,
4216              'processed_args' => null, // If used, should be a reference.
4217              'extra_attr'     => '',
4218          )
4219      );
4220  
4221      if ( is_numeric( $args['size'] ) ) {
4222          $args['size'] = absint( $args['size'] );
4223          if ( ! $args['size'] ) {
4224              $args['size'] = 96;
4225          }
4226      } else {
4227          $args['size'] = 96;
4228      }
4229  
4230      if ( is_numeric( $args['height'] ) ) {
4231          $args['height'] = absint( $args['height'] );
4232          if ( ! $args['height'] ) {
4233              $args['height'] = $args['size'];
4234          }
4235      } else {
4236          $args['height'] = $args['size'];
4237      }
4238  
4239      if ( is_numeric( $args['width'] ) ) {
4240          $args['width'] = absint( $args['width'] );
4241          if ( ! $args['width'] ) {
4242              $args['width'] = $args['size'];
4243          }
4244      } else {
4245          $args['width'] = $args['size'];
4246      }
4247  
4248      if ( empty( $args['default'] ) ) {
4249          $args['default'] = get_option( 'avatar_default', 'mystery' );
4250      }
4251  
4252      switch ( $args['default'] ) {
4253          case 'mm':
4254          case 'mystery':
4255          case 'mysteryman':
4256              $args['default'] = 'mm';
4257              break;
4258          case 'gravatar_default':
4259              $args['default'] = false;
4260              break;
4261      }
4262  
4263      $args['force_default'] = (bool) $args['force_default'];
4264  
4265      $args['rating'] = strtolower( $args['rating'] );
4266  
4267      $args['found_avatar'] = false;
4268  
4269      /**
4270       * Filters whether to retrieve the avatar URL early.
4271       *
4272       * Passing a non-null value in the 'url' member of the return array will
4273       * effectively short circuit get_avatar_data(), passing the value through
4274       * the {@see 'get_avatar_data'} filter and returning early.
4275       *
4276       * @since 4.2.0
4277       *
4278       * @param array $args        Arguments passed to get_avatar_data(), after processing.
4279       * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash,
4280       *                           user email, WP_User object, WP_Post object, or WP_Comment object.
4281       */
4282      $args = apply_filters( 'pre_get_avatar_data', $args, $id_or_email );
4283  
4284      if ( isset( $args['url'] ) ) {
4285          /** This filter is documented in wp-includes/link-template.php */
4286          return apply_filters( 'get_avatar_data', $args, $id_or_email );
4287      }
4288  
4289      $email_hash = '';
4290      $user       = false;
4291      $email      = false;
4292  
4293      if ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) {
4294          $id_or_email = get_comment( $id_or_email );
4295      }
4296  
4297      // Process the user identifier.
4298      if ( is_numeric( $id_or_email ) ) {
4299          $user = get_user_by( 'id', absint( $id_or_email ) );
4300      } elseif ( is_string( $id_or_email ) ) {
4301          if ( strpos( $id_or_email, '@md5.gravatar.com' ) ) {
4302              // MD5 hash.
4303              list( $email_hash ) = explode( '@', $id_or_email );
4304          } else {
4305              // Email address.
4306              $email = $id_or_email;
4307          }
4308      } elseif ( $id_or_email instanceof WP_User ) {
4309          // User object.
4310          $user = $id_or_email;
4311      } elseif ( $id_or_email instanceof WP_Post ) {
4312          // Post object.
4313          $user = get_user_by( 'id', (int) $id_or_email->post_author );
4314      } elseif ( $id_or_email instanceof WP_Comment ) {
4315          if ( ! is_avatar_comment_type( get_comment_type( $id_or_email ) ) ) {
4316              $args['url'] = false;
4317              /** This filter is documented in wp-includes/link-template.php */
4318              return apply_filters( 'get_avatar_data', $args, $id_or_email );
4319          }
4320  
4321          if ( ! empty( $id_or_email->user_id ) ) {
4322              $user = get_user_by( 'id', (int) $id_or_email->user_id );
4323          }
4324          if ( ( ! $user || is_wp_error( $user ) ) && ! empty( $id_or_email->comment_author_email ) ) {
4325              $email = $id_or_email->comment_author_email;
4326          }
4327      }
4328  
4329      if ( ! $email_hash ) {
4330          if ( $user ) {
4331              $email = $user->user_email;
4332          }
4333  
4334          if ( $email ) {
4335              $email_hash = md5( strtolower( trim( $email ) ) );
4336          }
4337      }
4338  
4339      if ( $email_hash ) {
4340          $args['found_avatar'] = true;
4341          $gravatar_server      = hexdec( $email_hash[0] ) % 3;
4342      } else {
4343          $gravatar_server = rand( 0, 2 );
4344      }
4345  
4346      $url_args = array(
4347          's' => $args['size'],
4348          'd' => $args['default'],
4349          'f' => $args['force_default'] ? 'y' : false,
4350          'r' => $args['rating'],
4351      );
4352  
4353      if ( is_ssl() ) {
4354          $url = 'https://secure.gravatar.com/avatar/' . $email_hash;
4355      } else {
4356          $url = sprintf( 'http://%d.gravatar.com/avatar/%s', $gravatar_server, $email_hash );
4357      }
4358  
4359      $url = add_query_arg(
4360          rawurlencode_deep( array_filter( $url_args ) ),
4361          set_url_scheme( $url, $args['scheme'] )
4362      );
4363  
4364      /**
4365       * Filters the avatar URL.
4366       *
4367       * @since 4.2.0
4368       *
4369       * @param string $url         The URL of the avatar.
4370       * @param mixed  $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash,
4371       *                            user email, WP_User object, WP_Post object, or WP_Comment object.
4372       * @param array  $args        Arguments passed to get_avatar_data(), after processing.
4373       */
4374      $args['url'] = apply_filters( 'get_avatar_url', $url, $id_or_email, $args );
4375  
4376      /**
4377       * Filters the avatar data.
4378       *
4379       * @since 4.2.0
4380       *
4381       * @param array $args        Arguments passed to get_avatar_data(), after processing.
4382       * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash,
4383       *                           user email, WP_User object, WP_Post object, or WP_Comment object.
4384       */
4385      return apply_filters( 'get_avatar_data', $args, $id_or_email );
4386  }
4387  
4388  /**
4389   * Retrieves the URL of a file in the theme.
4390   *
4391   * Searches in the stylesheet directory before the template directory so themes
4392   * which inherit from a parent theme can just override one file.
4393   *
4394   * @since 4.7.0
4395   *
4396   * @param string $file Optional. File to search for in the stylesheet directory.
4397   * @return string The URL of the file.
4398   */
4399  function get_theme_file_uri( $file = '' ) {
4400      $file = ltrim( $file, '/' );
4401  
4402      if ( empty( $file ) ) {
4403          $url = get_stylesheet_directory_uri();
4404      } elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
4405          $url = get_stylesheet_directory_uri() . '/' . $file;
4406      } else {
4407          $url = get_template_directory_uri() . '/' . $file;
4408      }
4409  
4410      /**
4411       * Filters the URL to a file in the theme.
4412       *
4413       * @since 4.7.0
4414       *
4415       * @param string $url  The file URL.
4416       * @param string $file The requested file to search for.
4417       */
4418      return apply_filters( 'theme_file_uri', $url, $file );
4419  }
4420  
4421  /**
4422   * Retrieves the URL of a file in the parent theme.
4423   *
4424   * @since 4.7.0
4425   *
4426   * @param string $file Optional. File to return the URL for in the template directory.
4427   * @return string The URL of the file.
4428   */
4429  function get_parent_theme_file_uri( $file = '' ) {
4430      $file = ltrim( $file, '/' );
4431  
4432      if ( empty( $file ) ) {
4433          $url = get_template_directory_uri();
4434      } else {
4435          $url = get_template_directory_uri() . '/' . $file;
4436      }
4437  
4438      /**
4439       * Filters the URL to a file in the parent theme.
4440       *
4441       * @since 4.7.0
4442       *
4443       * @param string $url  The file URL.
4444       * @param string $file The requested file to search for.
4445       */
4446      return apply_filters( 'parent_theme_file_uri', $url, $file );
4447  }
4448  
4449  /**
4450   * Retrieves the path of a file in the theme.
4451   *
4452   * Searches in the stylesheet directory before the template directory so themes
4453   * which inherit from a parent theme can just override one file.
4454   *
4455   * @since 4.7.0
4456   *
4457   * @param string $file Optional. File to search for in the stylesheet directory.
4458   * @return string The path of the file.
4459   */
4460  function get_theme_file_path( $file = '' ) {
4461      $file = ltrim( $file, '/' );
4462  
4463      if ( empty( $file ) ) {
4464          $path = get_stylesheet_directory();
4465      } elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
4466          $path = get_stylesheet_directory() . '/' . $file;
4467      } else {
4468          $path = get_template_directory() . '/' . $file;
4469      }
4470  
4471      /**
4472       * Filters the path to a file in the theme.
4473       *
4474       * @since 4.7.0
4475       *
4476       * @param string $path The file path.
4477       * @param string $file The requested file to search for.
4478       */
4479      return apply_filters( 'theme_file_path', $path, $file );
4480  }
4481  
4482  /**
4483   * Retrieves the path of a file in the parent theme.
4484   *
4485   * @since 4.7.0
4486   *
4487   * @param string $file Optional. File to return the path for in the template directory.
4488   * @return string The path of the file.
4489   */
4490  function get_parent_theme_file_path( $file = '' ) {
4491      $file = ltrim( $file, '/' );
4492  
4493      if ( empty( $file ) ) {
4494          $path = get_template_directory();
4495      } else {
4496          $path = get_template_directory() . '/' . $file;
4497      }
4498  
4499      /**
4500       * Filters the path to a file in the parent theme.
4501       *
4502       * @since 4.7.0
4503       *
4504       * @param string $path The file path.
4505       * @param string $file The requested file to search for.
4506       */
4507      return apply_filters( 'parent_theme_file_path', $path, $file );
4508  }
4509  
4510  /**
4511   * Retrieves the URL to the privacy policy page.
4512   *
4513   * @since 4.9.6
4514   *
4515   * @return string The URL to the privacy policy page. Empty string if it doesn't exist.
4516   */
4517  function get_privacy_policy_url() {
4518      $url            = '';
4519      $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
4520  
4521      if ( ! empty( $policy_page_id ) && get_post_status( $policy_page_id ) === 'publish' ) {
4522          $url = (string) get_permalink( $policy_page_id );
4523      }
4524  
4525      /**
4526       * Filters the URL of the privacy policy page.
4527       *
4528       * @since 4.9.6
4529       *
4530       * @param string $url            The URL to the privacy policy page. Empty string
4531       *                               if it doesn't exist.
4532       * @param int    $policy_page_id The ID of privacy policy page.
4533       */
4534      return apply_filters( 'privacy_policy_url', $url, $policy_page_id );
4535  }
4536  
4537  /**
4538   * Displays the privacy policy link with formatting, when applicable.
4539   *
4540   * @since 4.9.6
4541   *
4542   * @param string $before Optional. Display before privacy policy link. Default empty.
4543   * @param string $after  Optional. Display after privacy policy link. Default empty.
4544   */
4545  function the_privacy_policy_link( $before = '', $after = '' ) {
4546      echo get_the_privacy_policy_link( $before, $after );
4547  }
4548  
4549  /**
4550   * Returns the privacy policy link with formatting, when applicable.
4551   *
4552   * @since 4.9.6
4553   *
4554   * @param string $before Optional. Display before privacy policy link. Default empty.
4555   * @param string $after  Optional. Display after privacy policy link. Default empty.
4556   * @return string Markup for the link and surrounding elements. Empty string if it
4557   *                doesn't exist.
4558   */
4559  function get_the_privacy_policy_link( $before = '', $after = '' ) {
4560      $link               = '';
4561      $privacy_policy_url = get_privacy_policy_url();
4562      $policy_page_id     = (int) get_option( 'wp_page_for_privacy_policy' );
4563      $page_title         = ( $policy_page_id ) ? get_the_title( $policy_page_id ) : '';
4564  
4565      if ( $privacy_policy_url && $page_title ) {
4566          $link = sprintf(
4567              '<a class="privacy-policy-link" href="%s">%s</a>',
4568              esc_url( $privacy_policy_url ),
4569              esc_html( $page_title )
4570          );
4571      }
4572  
4573      /**
4574       * Filters the privacy policy link.
4575       *
4576       * @since 4.9.6
4577       *
4578       * @param string $link               The privacy policy link. Empty string if it
4579       *                                   doesn't exist.
4580       * @param string $privacy_policy_url The URL of the privacy policy. Empty string
4581       *                                   if it doesn't exist.
4582       */
4583      $link = apply_filters( 'the_privacy_policy_link', $link, $privacy_policy_url );
4584  
4585      if ( $link ) {
4586          return $before . $link . $after;
4587      }
4588  
4589      return '';
4590  }


Generated : Sun May 9 08:20:02 2021 Cross-referenced by PHPXref