[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

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


Generated: Thu Sep 24 01:02:16 2020 Cross-referenced by PHPXref 0.7.1