[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

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


Generated : Fri Oct 30 08:20:01 2020 Cross-referenced by PHPXref