[ Index ]

PHP Cross Reference of WordPress

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


Generated: Wed Nov 25 01:00:04 2020 Cross-referenced by PHPXref 0.7.1