[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  <?php
   2  /**
   3   * WordPress Link Template Functions
   4   *
   5   * @package WordPress
   6   * @subpackage Template
   7   */
   8  
   9  /**
  10   * Displays the permalink for the current post.
  11   *
  12   * @since 1.2.0
  13   * @since 4.4.0 Added the `$post` parameter.
  14   *
  15   * @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`.
  16   */
  17  function the_permalink( $post = 0 ) {
  18      /**
  19       * Filters the display of the permalink for the current post.
  20       *
  21       * @since 1.5.0
  22       * @since 4.4.0 Added the `$post` parameter.
  23       *
  24       * @param string      $permalink The permalink for the current post.
  25       * @param int|WP_Post $post      Post ID, WP_Post object, or 0. Default 0.
  26       */
  27      echo esc_url( apply_filters( 'the_permalink', get_permalink( $post ), $post ) );
  28  }
  29  
  30  /**
  31   * Retrieves a trailing-slashed string if the site is set for adding trailing slashes.
  32   *
  33   * Conditionally adds a trailing slash if the permalink structure has a trailing
  34   * slash, strips the trailing slash if not. The string is passed through the
  35   * {@see 'user_trailingslashit'} filter. Will remove trailing slash from string, if
  36   * site is not set to have them.
  37   *
  38   * @since 2.2.0
  39   *
  40   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
  41   *
  42   * @param string $string      URL with or without a trailing slash.
  43   * @param string $type_of_url Optional. The type of URL being considered (e.g. single, category, etc)
  44   *                            for use in the filter. Default empty string.
  45   * @return string The URL with the trailing slash appended or stripped.
  46   */
  47  function user_trailingslashit( $string, $type_of_url = '' ) {
  48      global $wp_rewrite;
  49      if ( $wp_rewrite->use_trailing_slashes ) {
  50          $string = trailingslashit( $string );
  51      } else {
  52          $string = untrailingslashit( $string );
  53      }
  54  
  55      /**
  56       * Filters the trailing-slashed string, depending on whether the site is set to use trailing slashes.
  57       *
  58       * @since 2.2.0
  59       *
  60       * @param string $string      URL with or without a trailing slash.
  61       * @param string $type_of_url The type of URL being considered. Accepts 'single', 'single_trackback',
  62       *                            'single_feed', 'single_paged', 'commentpaged', 'paged', 'home', 'feed',
  63       *                            'category', 'page', 'year', 'month', 'day', 'post_type_archive'.
  64       */
  65      return apply_filters( 'user_trailingslashit', $string, $type_of_url );
  66  }
  67  
  68  /**
  69   * Displays the permalink anchor for the current post.
  70   *
  71   * The permalink mode title will use the post title for the 'a' element 'id'
  72   * attribute. The id mode uses 'post-' with the post ID for the 'id' attribute.
  73   *
  74   * @since 0.71
  75   *
  76   * @param string $mode Optional. Permalink mode. Accepts 'title' or 'id'. Default 'id'.
  77   */
  78  function permalink_anchor( $mode = 'id' ) {
  79      $post = get_post();
  80      switch ( strtolower( $mode ) ) {
  81          case 'title':
  82              $title = sanitize_title( $post->post_title ) . '-' . $post->ID;
  83              echo '<a id="' . $title . '"></a>';
  84              break;
  85          case 'id':
  86          default:
  87              echo '<a id="post-' . $post->ID . '"></a>';
  88              break;
  89      }
  90  }
  91  
  92  /**
  93   * Retrieves the full permalink for the current post or post ID.
  94   *
  95   * This function is an alias for get_permalink().
  96   *
  97   * @since 3.9.0
  98   *
  99   * @see get_permalink()
 100   *
 101   * @param int|WP_Post $post      Optional. Post ID or post object. Default is the global `$post`.
 102   * @param bool        $leavename Optional. Whether to keep post name or page name. Default false.
 103   * @return string|false The permalink URL or false if post does not exist.
 104   */
 105  function get_the_permalink( $post = 0, $leavename = false ) {
 106      return get_permalink( $post, $leavename );
 107  }
 108  
 109  /**
 110   * Retrieves the full permalink for the current post or post ID.
 111   *
 112   * @since 1.0.0
 113   *
 114   * @param int|WP_Post $post      Optional. Post ID or post object. Default is the global `$post`.
 115   * @param bool        $leavename Optional. Whether to keep post name or page name. Default false.
 116   * @return string|false The permalink URL or false if post does not exist.
 117   */
 118  function get_permalink( $post = 0, $leavename = false ) {
 119      $rewritecode = array(
 120          '%year%',
 121          '%monthnum%',
 122          '%day%',
 123          '%hour%',
 124          '%minute%',
 125          '%second%',
 126          $leavename ? '' : '%postname%',
 127          '%post_id%',
 128          '%category%',
 129          '%author%',
 130          $leavename ? '' : '%pagename%',
 131      );
 132  
 133      if ( is_object( $post ) && isset( $post->filter ) && 'sample' === $post->filter ) {
 134          $sample = true;
 135      } else {
 136          $post   = get_post( $post );
 137          $sample = false;
 138      }
 139  
 140      if ( empty( $post->ID ) ) {
 141          return false;
 142      }
 143  
 144      if ( 'page' === $post->post_type ) {
 145          return get_page_link( $post, $leavename, $sample );
 146      } elseif ( 'attachment' === $post->post_type ) {
 147          return get_attachment_link( $post, $leavename );
 148      } elseif ( in_array( $post->post_type, get_post_types( array( '_builtin' => false ) ), true ) ) {
 149          return get_post_permalink( $post, $leavename, $sample );
 150      }
 151  
 152      $permalink = get_option( 'permalink_structure' );
 153  
 154      /**
 155       * Filters the permalink structure for a post before token replacement occurs.
 156       *
 157       * Only applies to posts with post_type of 'post'.
 158       *
 159       * @since 3.0.0
 160       *
 161       * @param string  $permalink The site's permalink structure.
 162       * @param WP_Post $post      The post in question.
 163       * @param bool    $leavename Whether to keep the post name.
 164       */
 165      $permalink = apply_filters( 'pre_post_link', $permalink, $post, $leavename );
 166  
 167      if ( $permalink && ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ), true ) ) {
 168  
 169          $category = '';
 170          if ( strpos( $permalink, '%category%' ) !== false ) {
 171              $cats = get_the_category( $post->ID );
 172              if ( $cats ) {
 173                  $cats = wp_list_sort(
 174                      $cats,
 175                      array(
 176                          'term_id' => 'ASC',
 177                      )
 178                  );
 179  
 180                  /**
 181                   * Filters the category that gets used in the %category% permalink token.
 182                   *
 183                   * @since 3.5.0
 184                   *
 185                   * @param WP_Term  $cat  The category to use in the permalink.
 186                   * @param array    $cats Array of all categories (WP_Term objects) associated with the post.
 187                   * @param WP_Post  $post The post in question.
 188                   */
 189                  $category_object = apply_filters( 'post_link_category', $cats[0], $cats, $post );
 190  
 191                  $category_object = get_term( $category_object, 'category' );
 192                  $category        = $category_object->slug;
 193                  if ( $category_object->parent ) {
 194                      $category = get_category_parents( $category_object->parent, false, '/', true ) . $category;
 195                  }
 196              }
 197              // Show default category in permalinks,
 198              // without having to assign it explicitly.
 199              if ( empty( $category ) ) {
 200                  $default_category = get_term( get_option( 'default_category' ), 'category' );
 201                  if ( $default_category && ! is_wp_error( $default_category ) ) {
 202                      $category = $default_category->slug;
 203                  }
 204              }
 205          }
 206  
 207          $author = '';
 208          if ( strpos( $permalink, '%author%' ) !== false ) {
 209              $authordata = get_userdata( $post->post_author );
 210              $author     = $authordata->user_nicename;
 211          }
 212  
 213          // This is not an API call because the permalink is based on the stored post_date value,
 214          // which should be parsed as local time regardless of the default PHP timezone.
 215          $date = explode( ' ', str_replace( array( '-', ':' ), ' ', $post->post_date ) );
 216  
 217          $rewritereplace = array(
 218              $date[0],
 219              $date[1],
 220              $date[2],
 221              $date[3],
 222              $date[4],
 223              $date[5],
 224              $post->post_name,
 225              $post->ID,
 226              $category,
 227              $author,
 228              $post->post_name,
 229          );
 230  
 231          $permalink = home_url( str_replace( $rewritecode, $rewritereplace, $permalink ) );
 232          $permalink = user_trailingslashit( $permalink, 'single' );
 233  
 234      } else { // If they're not using the fancy permalink option.
 235          $permalink = home_url( '?p=' . $post->ID );
 236      }
 237  
 238      /**
 239       * Filters the permalink for a post.
 240       *
 241       * Only applies to posts with post_type of 'post'.
 242       *
 243       * @since 1.5.0
 244       *
 245       * @param string  $permalink The post's permalink.
 246       * @param WP_Post $post      The post in question.
 247       * @param bool    $leavename Whether to keep the post name.
 248       */
 249      return apply_filters( 'post_link', $permalink, $post, $leavename );
 250  }
 251  
 252  /**
 253   * Retrieves the permalink for a post of a custom post type.
 254   *
 255   * @since 3.0.0
 256   *
 257   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 258   *
 259   * @param int|WP_Post $id        Optional. Post ID or post object. Default is the global `$post`.
 260   * @param bool        $leavename Optional. Whether to keep post name. Default false.
 261   * @param bool        $sample    Optional. Is it a sample permalink. Default false.
 262   * @return string|WP_Error The post permalink.
 263   */
 264  function get_post_permalink( $id = 0, $leavename = false, $sample = false ) {
 265      global $wp_rewrite;
 266  
 267      $post = get_post( $id );
 268  
 269      if ( is_wp_error( $post ) ) {
 270          return $post;
 271      }
 272  
 273      $post_link = $wp_rewrite->get_extra_permastruct( $post->post_type );
 274  
 275      $slug = $post->post_name;
 276  
 277      $draft_or_pending = get_post_status( $post ) && in_array( get_post_status( $post ), array( 'draft', 'pending', 'auto-draft', 'future' ), true );
 278  
 279      $post_type = get_post_type_object( $post->post_type );
 280  
 281      if ( $post_type->hierarchical ) {
 282          $slug = get_page_uri( $post );
 283      }
 284  
 285      if ( ! empty( $post_link ) && ( ! $draft_or_pending || $sample ) ) {
 286          if ( ! $leavename ) {
 287              $post_link = str_replace( "%$post->post_type%", $slug, $post_link );
 288          }
 289          $post_link = home_url( user_trailingslashit( $post_link ) );
 290      } else {
 291          if ( $post_type->query_var && ( isset( $post->post_status ) && ! $draft_or_pending ) ) {
 292              $post_link = add_query_arg( $post_type->query_var, $slug, '' );
 293          } else {
 294              $post_link = add_query_arg(
 295                  array(
 296                      'post_type' => $post->post_type,
 297                      'p'         => $post->ID,
 298                  ),
 299                  ''
 300              );
 301          }
 302          $post_link = home_url( $post_link );
 303      }
 304  
 305      /**
 306       * Filters the permalink for a post of a custom post type.
 307       *
 308       * @since 3.0.0
 309       *
 310       * @param string  $post_link The post's permalink.
 311       * @param WP_Post $post      The post in question.
 312       * @param bool    $leavename Whether to keep the post name.
 313       * @param bool    $sample    Is it a sample permalink.
 314       */
 315      return apply_filters( 'post_type_link', $post_link, $post, $leavename, $sample );
 316  }
 317  
 318  /**
 319   * Retrieves the permalink for the current page or page ID.
 320   *
 321   * Respects page_on_front. Use this one.
 322   *
 323   * @since 1.5.0
 324   *
 325   * @param int|WP_Post $post      Optional. Post ID or object. Default uses the global `$post`.
 326   * @param bool        $leavename Optional. Whether to keep the page name. Default false.
 327   * @param bool        $sample    Optional. Whether it should be treated as a sample permalink.
 328   *                               Default false.
 329   * @return string The page permalink.
 330   */
 331  function get_page_link( $post = false, $leavename = false, $sample = false ) {
 332      $post = get_post( $post );
 333  
 334      if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) {
 335          $link = home_url( '/' );
 336      } else {
 337          $link = _get_page_link( $post, $leavename, $sample );
 338      }
 339  
 340      /**
 341       * Filters the permalink for a page.
 342       *
 343       * @since 1.5.0
 344       *
 345       * @param string $link    The page's permalink.
 346       * @param int    $post_id The ID of the page.
 347       * @param bool   $sample  Is it a sample permalink.
 348       */
 349      return apply_filters( 'page_link', $link, $post->ID, $sample );
 350  }
 351  
 352  /**
 353   * Retrieves the page permalink.
 354   *
 355   * Ignores page_on_front. Internal use only.
 356   *
 357   * @since 2.1.0
 358   * @access private
 359   *
 360   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 361   *
 362   * @param int|WP_Post $post      Optional. Post ID or object. Default uses the global `$post`.
 363   * @param bool        $leavename Optional. Whether to keep the page name. Default false.
 364   * @param bool        $sample    Optional. Whether it should be treated as a sample permalink.
 365   *                               Default false.
 366   * @return string The page permalink.
 367   */
 368  function _get_page_link( $post = false, $leavename = false, $sample = false ) {
 369      global $wp_rewrite;
 370  
 371      $post = get_post( $post );
 372  
 373      $draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ), true );
 374  
 375      $link = $wp_rewrite->get_page_permastruct();
 376  
 377      if ( ! empty( $link ) && ( ( isset( $post->post_status ) && ! $draft_or_pending ) || $sample ) ) {
 378          if ( ! $leavename ) {
 379              $link = str_replace( '%pagename%', get_page_uri( $post ), $link );
 380          }
 381  
 382          $link = home_url( $link );
 383          $link = user_trailingslashit( $link, 'page' );
 384      } else {
 385          $link = home_url( '?page_id=' . $post->ID );
 386      }
 387  
 388      /**
 389       * Filters the permalink for a non-page_on_front page.
 390       *
 391       * @since 2.1.0
 392       *
 393       * @param string $link    The page's permalink.
 394       * @param int    $post_id The ID of the page.
 395       */
 396      return apply_filters( '_get_page_link', $link, $post->ID );
 397  }
 398  
 399  /**
 400   * Retrieves the permalink for an attachment.
 401   *
 402   * This can be used in the WordPress Loop or outside of it.
 403   *
 404   * @since 2.0.0
 405   *
 406   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 407   *
 408   * @param int|object $post      Optional. Post ID or object. Default uses the global `$post`.
 409   * @param bool       $leavename Optional. Whether to keep the page name. Default false.
 410   * @return string The attachment permalink.
 411   */
 412  function get_attachment_link( $post = null, $leavename = false ) {
 413      global $wp_rewrite;
 414  
 415      $link = false;
 416  
 417      $post   = get_post( $post );
 418      $parent = ( $post->post_parent > 0 && $post->post_parent != $post->ID ) ? get_post( $post->post_parent ) : false;
 419      if ( $parent && ! in_array( $parent->post_type, get_post_types(), true ) ) {
 420          $parent = false;
 421      }
 422  
 423      if ( $wp_rewrite->using_permalinks() && $parent ) {
 424          if ( 'page' === $parent->post_type ) {
 425              $parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front.
 426          } else {
 427              $parentlink = get_permalink( $post->post_parent );
 428          }
 429  
 430          if ( is_numeric( $post->post_name ) || false !== strpos( get_option( 'permalink_structure' ), '%category%' ) ) {
 431              $name = 'attachment/' . $post->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker.
 432          } else {
 433              $name = $post->post_name;
 434          }
 435  
 436          if ( strpos( $parentlink, '?' ) === false ) {
 437              $link = user_trailingslashit( trailingslashit( $parentlink ) . '%postname%' );
 438          }
 439  
 440          if ( ! $leavename ) {
 441              $link = str_replace( '%postname%', $name, $link );
 442          }
 443      } elseif ( $wp_rewrite->using_permalinks() && ! $leavename ) {
 444          $link = home_url( user_trailingslashit( $post->post_name ) );
 445      }
 446  
 447      if ( ! $link ) {
 448          $link = home_url( '/?attachment_id=' . $post->ID );
 449      }
 450  
 451      /**
 452       * Filters the permalink for an attachment.
 453       *
 454       * @since 2.0.0
 455       *
 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   *
1965   * @see adjacent_posts_rel_link()
1966   */
1967  function adjacent_posts_rel_link_wp_head() {
1968      if ( ! is_single() || is_attachment() ) {
1969          return;
1970      }
1971      adjacent_posts_rel_link();
1972  }
1973  
1974  /**
1975   * Displays the relational link for the next post adjacent to the current post.
1976   *
1977   * @since 2.8.0
1978   *
1979   * @see get_adjacent_post_rel_link()
1980   *
1981   * @param string       $title          Optional. Link title format. Default '%title'.
1982   * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
1983   * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
1984   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
1985   */
1986  function next_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
1987      echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy );
1988  }
1989  
1990  /**
1991   * Displays the relational link for the previous post adjacent to the current post.
1992   *
1993   * @since 2.8.0
1994   *
1995   * @see get_adjacent_post_rel_link()
1996   *
1997   * @param string       $title          Optional. Link title format. Default '%title'.
1998   * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
1999   * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default true.
2000   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
2001   */
2002  function prev_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
2003      echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, true, $taxonomy );
2004  }
2005  
2006  /**
2007   * Retrieves the boundary post.
2008   *
2009   * Boundary being either the first or last post by publish date within the constraints specified
2010   * by $in_same_term or $excluded_terms.
2011   *
2012   * @since 2.8.0
2013   *
2014   * @param bool         $in_same_term   Optional. Whether returned post should be in a same taxonomy term.
2015   *                                     Default false.
2016   * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
2017   *                                     Default empty.
2018   * @param bool         $start          Optional. Whether to retrieve first or last post. Default true
2019   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
2020   * @return null|array Array containing the boundary post object if successful, null otherwise.
2021   */
2022  function get_boundary_post( $in_same_term = false, $excluded_terms = '', $start = true, $taxonomy = 'category' ) {
2023      $post = get_post();
2024      if ( ! $post || ! is_single() || is_attachment() || ! taxonomy_exists( $taxonomy ) ) {
2025          return null;
2026      }
2027  
2028      $query_args = array(
2029          'posts_per_page'         => 1,
2030          'order'                  => $start ? 'ASC' : 'DESC',
2031          'update_post_term_cache' => false,
2032          'update_post_meta_cache' => false,
2033      );
2034  
2035      $term_array = array();
2036  
2037      if ( ! is_array( $excluded_terms ) ) {
2038          if ( ! empty( $excluded_terms ) ) {
2039              $excluded_terms = explode( ',', $excluded_terms );
2040          } else {
2041              $excluded_terms = array();
2042          }
2043      }
2044  
2045      if ( $in_same_term || ! empty( $excluded_terms ) ) {
2046          if ( $in_same_term ) {
2047              $term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
2048          }
2049  
2050          if ( ! empty( $excluded_terms ) ) {
2051              $excluded_terms = array_map( 'intval', $excluded_terms );
2052              $excluded_terms = array_diff( $excluded_terms, $term_array );
2053  
2054              $inverse_terms = array();
2055              foreach ( $excluded_terms as $excluded_term ) {
2056                  $inverse_terms[] = $excluded_term * -1;
2057              }
2058              $excluded_terms = $inverse_terms;
2059          }
2060  
2061          $query_args['tax_query'] = array(
2062              array(
2063                  'taxonomy' => $taxonomy,
2064                  'terms'    => array_merge( $term_array, $excluded_terms ),
2065              ),
2066          );
2067      }
2068  
2069      return get_posts( $query_args );
2070  }
2071  
2072  /**
2073   * Retrieves the previous post link that is adjacent to the current post.
2074   *
2075   * @since 3.7.0
2076   *
2077   * @param string       $format         Optional. Link anchor format. Default '&laquo; %link'.
2078   * @param string       $link           Optional. Link permalink format. Default '%title'.
2079   * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
2080   * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
2081   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
2082   * @return string The link URL of the previous post in relation to the current post.
2083   */
2084  function get_previous_post_link( $format = '&laquo; %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
2085      return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, true, $taxonomy );
2086  }
2087  
2088  /**
2089   * Displays the previous post link that is adjacent to the current post.
2090   *
2091   * @since 1.5.0
2092   *
2093   * @see get_previous_post_link()
2094   *
2095   * @param string       $format         Optional. Link anchor format. Default '&laquo; %link'.
2096   * @param string       $link           Optional. Link permalink format. Default '%title'.
2097   * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
2098   * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
2099   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
2100   */
2101  function previous_post_link( $format = '&laquo; %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
2102      echo get_previous_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy );
2103  }
2104  
2105  /**
2106   * Retrieves the next post link that is adjacent to the current post.
2107   *
2108   * @since 3.7.0
2109   *
2110   * @param string       $format         Optional. Link anchor format. Default '&laquo; %link'.
2111   * @param string       $link           Optional. Link permalink format. Default '%title'.
2112   * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
2113   * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
2114   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
2115   * @return string The link URL of the next post in relation to the current post.
2116   */
2117  function get_next_post_link( $format = '%link &raquo;', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
2118      return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, false, $taxonomy );
2119  }
2120  
2121  /**
2122   * Displays the next post link that is adjacent to the current post.
2123   *
2124   * @since 1.5.0
2125   *
2126   * @see get_next_post_link()
2127   *
2128   * @param string       $format         Optional. Link anchor format. Default '&laquo; %link'.
2129   * @param string       $link           Optional. Link permalink format. Default '%title'
2130   * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
2131   * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
2132   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
2133   */
2134  function next_post_link( $format = '%link &raquo;', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
2135      echo get_next_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy );
2136  }
2137  
2138  /**
2139   * Retrieves the adjacent post link.
2140   *
2141   * Can be either next post link or previous.
2142   *
2143   * @since 3.7.0
2144   *
2145   * @param string       $format         Link anchor format.
2146   * @param string       $link           Link permalink format.
2147   * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
2148   * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded terms IDs. Default empty.
2149   * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
2150   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
2151   * @return string The link URL of the previous or next post in relation to the current post.
2152   */
2153  function get_adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
2154      if ( $previous && is_attachment() ) {
2155          $post = get_post( get_post()->post_parent );
2156      } else {
2157          $post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy );
2158      }
2159  
2160      if ( ! $post ) {
2161          $output = '';
2162      } else {
2163          $title = $post->post_title;
2164  
2165          if ( empty( $post->post_title ) ) {
2166              $title = $previous ? __( 'Previous Post' ) : __( 'Next Post' );
2167          }
2168  
2169          /** This filter is documented in wp-includes/post-template.php */
2170          $title = apply_filters( 'the_title', $title, $post->ID );
2171  
2172          $date = mysql2date( get_option( 'date_format' ), $post->post_date );
2173          $rel  = $previous ? 'prev' : 'next';
2174  
2175          $string = '<a href="' . get_permalink( $post ) . '" rel="' . $rel . '">';
2176          $inlink = str_replace( '%title', $title, $link );
2177          $inlink = str_replace( '%date', $date, $inlink );
2178          $inlink = $string . $inlink . '</a>';
2179  
2180          $output = str_replace( '%link', $inlink, $format );
2181      }
2182  
2183      $adjacent = $previous ? 'previous' : 'next';
2184  
2185      /**
2186       * Filters the adjacent post link.
2187       *
2188       * The dynamic portion of the hook name, `$adjacent`, refers to the type
2189       * of adjacency, 'next' or 'previous'.
2190       *
2191       * @since 2.6.0
2192       * @since 4.2.0 Added the `$adjacent` parameter.
2193       *
2194       * @param string  $output   The adjacent post link.
2195       * @param string  $format   Link anchor format.
2196       * @param string  $link     Link permalink format.
2197       * @param WP_Post $post     The adjacent post.
2198       * @param string  $adjacent Whether the post is previous or next.
2199       */
2200      return apply_filters( "{$adjacent}_post_link", $output, $format, $link, $post, $adjacent );
2201  }
2202  
2203  /**
2204   * Displays the adjacent post link.
2205   *
2206   * Can be either next post link or previous.
2207   *
2208   * @since 2.5.0
2209   *
2210   * @param string       $format         Link anchor format.
2211   * @param string       $link           Link permalink format.
2212   * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
2213   * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded category IDs. Default empty.
2214   * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
2215   * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
2216   */
2217  function adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
2218      echo get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, $previous, $taxonomy );
2219  }
2220  
2221  /**
2222   * Retrieves the link for a page number.
2223   *
2224   * @since 1.5.0
2225   *
2226   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
2227   *
2228   * @param int  $pagenum Optional. Page number. Default 1.
2229   * @param bool $escape  Optional. Whether to escape the URL for display, with esc_url(). Defaults to true.
2230   *                      Otherwise, prepares the URL with esc_url_raw().
2231   * @return string The link URL for the given page number.
2232   */
2233  function get_pagenum_link( $pagenum = 1, $escape = true ) {
2234      global $wp_rewrite;
2235  
2236      $pagenum = (int) $pagenum;
2237  
2238      $request = remove_query_arg( 'paged' );
2239  
2240      $home_root = parse_url( home_url() );
2241      $home_root = ( isset( $home_root['path'] ) ) ? $home_root['path'] : '';
2242      $home_root = preg_quote( $home_root, '|' );
2243  
2244      $request = preg_replace( '|^' . $home_root . '|i', '', $request );
2245      $request = preg_replace( '|^/+|', '', $request );
2246  
2247      if ( ! $wp_rewrite->using_permalinks() || is_admin() ) {
2248          $base = trailingslashit( get_bloginfo( 'url' ) );
2249  
2250          if ( $pagenum > 1 ) {
2251              $result = add_query_arg( 'paged', $pagenum, $base . $request );
2252          } else {
2253              $result = $base . $request;
2254          }
2255      } else {
2256          $qs_regex = '|\?.*?$|';
2257          preg_match( $qs_regex, $request, $qs_match );
2258  
2259          if ( ! empty( $qs_match[0] ) ) {
2260              $query_string = $qs_match[0];
2261              $request      = preg_replace( $qs_regex, '', $request );
2262          } else {
2263              $query_string = '';
2264          }
2265  
2266          $request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request );
2267          $request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request );
2268          $request = ltrim( $request, '/' );
2269  
2270          $base = trailingslashit( get_bloginfo( 'url' ) );
2271  
2272          if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' !== $request ) ) {
2273              $base .= $wp_rewrite->index . '/';
2274          }
2275  
2276          if ( $pagenum > 1 ) {
2277              $request = ( ( ! empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . '/' . $pagenum, 'paged' );
2278          }
2279  
2280          $result = $base . $request . $query_string;
2281      }
2282  
2283      /**
2284       * Filters the page number link for the current request.
2285       *
2286       * @since 2.5.0
2287       * @since 5.2.0 Added the `$pagenum` argument.
2288       *
2289       * @param string $result  The page number link.
2290       * @param int    $pagenum The page number.
2291       */
2292      $result = apply_filters( 'get_pagenum_link', $result, $pagenum );
2293  
2294      if ( $escape ) {
2295          return esc_url( $result );
2296      } else {
2297          return esc_url_raw( $result );
2298      }
2299  }
2300  
2301  /**
2302   * Retrieves the next posts page link.
2303   *
2304   * Backported from 2.1.3 to 2.0.10.
2305   *
2306   * @since 2.0.10
2307   *
2308   * @global int $paged
2309   *
2310   * @param int $max_page Optional. Max pages. Default 0.
2311   * @return string|void The link URL for next posts page.
2312   */
2313  function get_next_posts_page_link( $max_page = 0 ) {
2314      global $paged;
2315  
2316      if ( ! is_single() ) {
2317          if ( ! $paged ) {
2318              $paged = 1;
2319          }
2320          $nextpage = intval( $paged ) + 1;
2321          if ( ! $max_page || $max_page >= $nextpage ) {
2322              return get_pagenum_link( $nextpage );
2323          }
2324      }
2325  }
2326  
2327  /**
2328   * Displays or retrieves the next posts page link.
2329   *
2330   * @since 0.71
2331   *
2332   * @param int  $max_page Optional. Max pages. Default 0.
2333   * @param bool $echo     Optional. Whether to echo the link. Default true.
2334   * @return string|void The link URL for next posts page if `$echo = false`.
2335   */
2336  function next_posts( $max_page = 0, $echo = true ) {
2337      $output = esc_url( get_next_posts_page_link( $max_page ) );
2338  
2339      if ( $echo ) {
2340          echo $output;
2341      } else {
2342          return $output;
2343      }
2344  }
2345  
2346  /**
2347   * Retrieves the next posts page link.
2348   *
2349   * @since 2.7.0
2350   *
2351   * @global int      $paged
2352   * @global WP_Query $wp_query WordPress Query object.
2353   *
2354   * @param string $label    Content for link text.
2355   * @param int    $max_page Optional. Max pages. Default 0.
2356   * @return string|void HTML-formatted next posts page link.
2357   */
2358  function get_next_posts_link( $label = null, $max_page = 0 ) {
2359      global $paged, $wp_query;
2360  
2361      if ( ! $max_page ) {
2362          $max_page = $wp_query->max_num_pages;
2363      }
2364  
2365      if ( ! $paged ) {
2366          $paged = 1;
2367      }
2368  
2369      $nextpage = intval( $paged ) + 1;
2370  
2371      if ( null === $label ) {
2372          $label = __( 'Next Page &raquo;' );
2373      }
2374  
2375      if ( ! is_single() && ( $nextpage <= $max_page ) ) {
2376          /**
2377           * Filters the anchor tag attributes for the next posts page link.
2378           *
2379           * @since 2.7.0
2380           *
2381           * @param string $attributes Attributes for the anchor tag.
2382           */
2383          $attr = apply_filters( 'next_posts_link_attributes', '' );
2384  
2385          return '<a href="' . next_posts( $max_page, false ) . "\" $attr>" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label ) . '</a>';
2386      }
2387  }
2388  
2389  /**
2390   * Displays the next posts page link.
2391   *
2392   * @since 0.71
2393   *
2394   * @param string $label    Content for link text.
2395   * @param int    $max_page Optional. Max pages. Default 0.
2396   */
2397  function next_posts_link( $label = null, $max_page = 0 ) {
2398      echo get_next_posts_link( $label, $max_page );
2399  }
2400  
2401  /**
2402   * Retrieves the previous posts page link.
2403   *
2404   * Will only return string, if not on a single page or post.
2405   *
2406   * Backported to 2.0.10 from 2.1.3.
2407   *
2408   * @since 2.0.10
2409   *
2410   * @global int $paged
2411   *
2412   * @return string|void The link for the previous posts page.
2413   */
2414  function get_previous_posts_page_link() {
2415      global $paged;
2416  
2417      if ( ! is_single() ) {
2418          $nextpage = intval( $paged ) - 1;
2419          if ( $nextpage < 1 ) {
2420              $nextpage = 1;
2421          }
2422          return get_pagenum_link( $nextpage );
2423      }
2424  }
2425  
2426  /**
2427   * Displays or retrieves the previous posts page link.
2428   *
2429   * @since 0.71
2430   *
2431   * @param bool $echo Optional. Whether to echo the link. Default true.
2432   * @return string|void The previous posts page link if `$echo = false`.
2433   */
2434  function previous_posts( $echo = true ) {
2435      $output = esc_url( get_previous_posts_page_link() );
2436  
2437      if ( $echo ) {
2438          echo $output;
2439      } else {
2440          return $output;
2441      }
2442  }
2443  
2444  /**
2445   * Retrieves the previous posts page link.
2446   *
2447   * @since 2.7.0
2448   *
2449   * @global int $paged
2450   *
2451   * @param string $label Optional. Previous page link text.
2452   * @return string|void HTML-formatted previous page link.
2453   */
2454  function get_previous_posts_link( $label = null ) {
2455      global $paged;
2456  
2457      if ( null === $label ) {
2458          $label = __( '&laquo; Previous Page' );
2459      }
2460  
2461      if ( ! is_single() && $paged > 1 ) {
2462          /**
2463           * Filters the anchor tag attributes for the previous posts page link.
2464           *
2465           * @since 2.7.0
2466           *
2467           * @param string $attributes Attributes for the anchor tag.
2468           */
2469          $attr = apply_filters( 'previous_posts_link_attributes', '' );
2470          return '<a href="' . previous_posts( false ) . "\" $attr>" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label ) . '</a>';
2471      }
2472  }
2473  
2474  /**
2475   * Displays the previous posts page link.
2476   *
2477   * @since 0.71
2478   *
2479   * @param string $label Optional. Previous page link text.
2480   */
2481  function previous_posts_link( $label = null ) {
2482      echo get_previous_posts_link( $label );
2483  }
2484  
2485  /**
2486   * Retrieves the post pages link navigation for previous and next pages.
2487   *
2488   * @since 2.8.0
2489   *
2490   * @global WP_Query $wp_query WordPress Query object.
2491   *
2492   * @param string|array $args {
2493   *     Optional. Arguments to build the post pages link navigation.
2494   *
2495   *     @type string $sep      Separator character. Default '&#8212;'.
2496   *     @type string $prelabel Link text to display for the previous page link.
2497   *                            Default '&laquo; Previous Page'.
2498   *     @type string $nxtlabel Link text to display for the next page link.
2499   *                            Default 'Next Page &raquo;'.
2500   * }
2501   * @return string The posts link navigation.
2502   */
2503  function get_posts_nav_link( $args = array() ) {
2504      global $wp_query;
2505  
2506      $return = '';
2507  
2508      if ( ! is_singular() ) {
2509          $defaults = array(
2510              'sep'      => ' &#8212; ',
2511              'prelabel' => __( '&laquo; Previous Page' ),
2512              'nxtlabel' => __( 'Next Page &raquo;' ),
2513          );
2514          $args     = wp_parse_args( $args, $defaults );
2515  
2516          $max_num_pages = $wp_query->max_num_pages;
2517          $paged         = get_query_var( 'paged' );
2518  
2519          // Only have sep if there's both prev and next results.
2520          if ( $paged < 2 || $paged >= $max_num_pages ) {
2521              $args['sep'] = '';
2522          }
2523  
2524          if ( $max_num_pages > 1 ) {
2525              $return  = get_previous_posts_link( $args['prelabel'] );
2526              $return .= preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $args['sep'] );
2527              $return .= get_next_posts_link( $args['nxtlabel'] );
2528          }
2529      }
2530      return $return;
2531  
2532  }
2533  
2534  /**
2535   * Displays the post pages link navigation for previous and next pages.
2536   *
2537   * @since 0.71
2538   *
2539   * @param string $sep      Optional. Separator for posts navigation links. Default empty.
2540   * @param string $prelabel Optional. Label for previous pages. Default empty.
2541   * @param string $nxtlabel Optional Label for next pages. Default empty.
2542   */
2543  function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) {
2544      $args = array_filter( compact( 'sep', 'prelabel', 'nxtlabel' ) );
2545      echo get_posts_nav_link( $args );
2546  }
2547  
2548  /**
2549   * Retrieves the navigation to next/previous post, when applicable.
2550   *
2551   * @since 4.1.0
2552   * @since 4.4.0 Introduced the `in_same_term`, `excluded_terms`, and `taxonomy` arguments.
2553   * @since 5.3.0 Added the `aria_label` parameter.
2554   * @since 5.5.0 Added the `class` parameter.
2555   *
2556   * @param array $args {
2557   *     Optional. Default post navigation arguments. Default empty array.
2558   *
2559   *     @type string       $prev_text          Anchor text to display in the previous post link. Default '%title'.
2560   *     @type string       $next_text          Anchor text to display in the next post link. Default '%title'.
2561   *     @type bool         $in_same_term       Whether link should be in a same taxonomy term. Default false.
2562   *     @type array|string $excluded_terms     Array or comma-separated list of excluded term IDs. Default empty.
2563   *     @type string       $taxonomy           Taxonomy, if `$in_same_term` is true. Default 'category'.
2564   *     @type string       $screen_reader_text Screen reader text for the nav element. Default 'Post navigation'.
2565   *     @type string       $aria_label         ARIA label text for the nav element. Default 'Posts'.
2566   *     @type string       $class              Custom class for the nav element. Default 'post-navigation'.
2567   * }
2568   * @return string Markup for post links.
2569   */
2570  function get_the_post_navigation( $args = array() ) {
2571      // Make sure the nav element has an aria-label attribute: fallback to the screen reader text.
2572      if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) {
2573          $args['aria_label'] = $args['screen_reader_text'];
2574      }
2575  
2576      $args = wp_parse_args(
2577          $args,
2578          array(
2579              'prev_text'          => '%title',
2580              'next_text'          => '%title',
2581              'in_same_term'       => false,
2582              'excluded_terms'     => '',
2583              'taxonomy'           => 'category',
2584              'screen_reader_text' => __( 'Post navigation' ),
2585              'aria_label'         => __( 'Posts' ),
2586              'class'              => 'post-navigation',
2587          )
2588      );
2589  
2590      $navigation = '';
2591  
2592      $previous = get_previous_post_link(
2593          '<div class="nav-previous">%link</div>',
2594          $args['prev_text'],
2595          $args['in_same_term'],
2596          $args['excluded_terms'],
2597          $args['taxonomy']
2598      );
2599  
2600      $next = get_next_post_link(
2601          '<div class="nav-next">%link</div>',
2602          $args['next_text'],
2603          $args['in_same_term'],
2604          $args['excluded_terms'],
2605          $args['taxonomy']
2606      );
2607  
2608      // Only add markup if there's somewhere to navigate to.
2609      if ( $previous || $next ) {
2610          $navigation = _navigation_markup( $previous . $next, $args['class'], $args['screen_reader_text'], $args['aria_label'] );
2611      }
2612  
2613      return $navigation;
2614  }
2615  
2616  /**
2617   * Displays the navigation to next/previous post, when applicable.
2618   *
2619   * @since 4.1.0
2620   *
2621   * @param array $args Optional. See get_the_post_navigation() for available arguments.
2622   *                    Default empty array.
2623   */
2624  function the_post_navigation( $args = array() ) {
2625      echo get_the_post_navigation( $args );
2626  }
2627  
2628  /**
2629   * Returns the navigation to next/previous set of posts, when applicable.
2630   *
2631   * @since 4.1.0
2632   * @since 5.3.0 Added the `aria_label` parameter.
2633   * @since 5.5.0 Added the `class` parameter.
2634   *
2635   * @global WP_Query $wp_query WordPress Query object.
2636   *
2637   * @param array $args {
2638   *     Optional. Default posts navigation arguments. Default empty array.
2639   *
2640   *     @type string $prev_text          Anchor text to display in the previous posts link.
2641   *                                      Default 'Older posts'.
2642   *     @type string $next_text          Anchor text to display in the next posts link.
2643   *                                      Default 'Newer posts'.
2644   *     @type string $screen_reader_text Screen reader text for the nav element.
2645   *                                      Default 'Posts navigation'.
2646   *     @type string $aria_label         ARIA label text for the nav element. Default 'Posts'.
2647   *     @type string $class              Custom class for the nav element. Default 'posts-navigation'.
2648   * }
2649   * @return string Markup for posts links.
2650   */
2651  function get_the_posts_navigation( $args = array() ) {
2652      $navigation = '';
2653  
2654      // Don't print empty markup if there's only one page.
2655      if ( $GLOBALS['wp_query']->max_num_pages > 1 ) {
2656          // Make sure the nav element has an aria-label attribute: fallback to the screen reader text.
2657          if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) {
2658              $args['aria_label'] = $args['screen_reader_text'];
2659          }
2660  
2661          $args = wp_parse_args(
2662              $args,
2663              array(
2664                  'prev_text'          => __( 'Older posts' ),
2665                  'next_text'          => __( 'Newer posts' ),
2666                  'screen_reader_text' => __( 'Posts navigation' ),
2667                  'aria_label'         => __( 'Posts' ),
2668                  'class'              => 'posts-navigation',
2669              )
2670          );
2671  
2672          $next_link = get_previous_posts_link( $args['next_text'] );
2673          $prev_link = get_next_posts_link( $args['prev_text'] );
2674  
2675          if ( $prev_link ) {
2676              $navigation .= '<div class="nav-previous">' . $prev_link . '</div>';
2677          }
2678  
2679          if ( $next_link ) {
2680              $navigation .= '<div class="nav-next">' . $next_link . '</div>';
2681          }
2682  
2683          $navigation = _navigation_markup( $navigation, $args['class'], $args['screen_reader_text'], $args['aria_label'] );
2684      }
2685  
2686      return $navigation;
2687  }
2688  
2689  /**
2690   * Displays the navigation to next/previous set of posts, when applicable.
2691   *
2692   * @since 4.1.0
2693   *
2694   * @param array $args Optional. See get_the_posts_navigation() for available arguments.
2695   *                    Default empty array.
2696   */
2697  function the_posts_navigation( $args = array() ) {
2698      echo get_the_posts_navigation( $args );
2699  }
2700  
2701  /**
2702   * Retrieves a paginated navigation to next/previous set of posts, when applicable.
2703   *
2704   * @since 4.1.0
2705   * @since 5.3.0 Added the `aria_label` parameter.
2706   * @since 5.5.0 Added the `class` parameter.
2707   *
2708   * @param array $args {
2709   *     Optional. Default pagination arguments, see paginate_links().
2710   *
2711   *     @type string $screen_reader_text Screen reader text for navigation element.
2712   *                                      Default 'Posts navigation'.
2713   *     @type string $aria_label         ARIA label text for the nav element. Default 'Posts'.
2714   *     @type string $class              Custom class for the nav element. Default 'pagination'.
2715   * }
2716   * @return string Markup for pagination links.
2717   */
2718  function get_the_posts_pagination( $args = array() ) {
2719      $navigation = '';
2720  
2721      // Don't print empty markup if there's only one page.
2722      if ( $GLOBALS['wp_query']->max_num_pages > 1 ) {
2723          // Make sure the nav element has an aria-label attribute: fallback to the screen reader text.
2724          if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) {
2725              $args['aria_label'] = $args['screen_reader_text'];
2726          }
2727  
2728          $args = wp_parse_args(
2729              $args,
2730              array(
2731                  'mid_size'           => 1,
2732                  'prev_text'          => _x( 'Previous', 'previous set of posts' ),
2733                  'next_text'          => _x( 'Next', 'next set of posts' ),
2734                  'screen_reader_text' => __( 'Posts navigation' ),
2735                  'aria_label'         => __( 'Posts' ),
2736                  'class'              => 'pagination',
2737              )
2738          );
2739  
2740          // Make sure we get a string back. Plain is the next best thing.
2741          if ( isset( $args['type'] ) && 'array' === $args['type'] ) {
2742              $args['type'] = 'plain';
2743          }
2744  
2745          // Set up paginated links.
2746          $links = paginate_links( $args );
2747  
2748          if ( $links ) {
2749              $navigation = _navigation_markup( $links, $args['class'], $args['screen_reader_text'], $args['aria_label'] );
2750          }
2751      }
2752  
2753      return $navigation;
2754  }
2755  
2756  /**
2757   * Displays a paginated navigation to next/previous set of posts, when applicable.
2758   *
2759   * @since 4.1.0
2760   *
2761   * @param array $args Optional. See get_the_posts_pagination() for available arguments.
2762   *                    Default empty array.
2763   */
2764  function the_posts_pagination( $args = array() ) {
2765      echo get_the_posts_pagination( $args );
2766  }
2767  
2768  /**
2769   * Wraps passed links in navigational markup.
2770   *
2771   * @since 4.1.0
2772   * @since 5.3.0 Added the `aria_label` parameter.
2773   * @access private
2774   *
2775   * @param string $links              Navigational links.
2776   * @param string $class              Optional. Custom class for the nav element.
2777   *                                   Default 'posts-navigation'.
2778   * @param string $screen_reader_text Optional. Screen reader text for the nav element.
2779   *                                   Default 'Posts navigation'.
2780   * @param string $aria_label         Optional. ARIA label for the nav element.
2781   *                                   Defaults to the value of `$screen_reader_text`.
2782   * @return string Navigation template tag.
2783   */
2784  function _navigation_markup( $links, $class = 'posts-navigation', $screen_reader_text = '', $aria_label = '' ) {
2785      if ( empty( $screen_reader_text ) ) {
2786          $screen_reader_text = __( 'Posts navigation' );
2787      }
2788      if ( empty( $aria_label ) ) {
2789          $aria_label = $screen_reader_text;
2790      }
2791  
2792      $template = '
2793      <nav class="navigation %1$s" role="navigation" aria-label="%4$s">
2794          <h2 class="screen-reader-text">%2$s</h2>
2795          <div class="nav-links">%3$s</div>
2796      </nav>';
2797  
2798      /**
2799       * Filters the navigation markup template.
2800       *
2801       * Note: The filtered template HTML must contain specifiers for the navigation
2802       * class (%1$s), the screen-reader-text value (%2$s), placement of the navigation
2803       * links (%3$s), and ARIA label text if screen-reader-text does not fit that (%4$s):
2804       *
2805       *     <nav class="navigation %1$s" role="navigation" aria-label="%4$s">
2806       *         <h2 class="screen-reader-text">%2$s</h2>
2807       *         <div class="nav-links">%3$s</div>
2808       *     </nav>
2809       *
2810       * @since 4.4.0
2811       *
2812       * @param string $template The default template.
2813       * @param string $class    The class passed by the calling function.
2814       * @return string Navigation template.
2815       */
2816      $template = apply_filters( 'navigation_markup_template', $template, $class );
2817  
2818      return sprintf( $template, sanitize_html_class( $class ), esc_html( $screen_reader_text ), $links, esc_html( $aria_label ) );
2819  }
2820  
2821  /**
2822   * Retrieves the comments page number link.
2823   *
2824   * @since 2.7.0
2825   *
2826   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
2827   *
2828   * @param int $pagenum  Optional. Page number. Default 1.
2829   * @param int $max_page Optional. The maximum number of comment pages. Default 0.
2830   * @return string The comments page number link URL.
2831   */
2832  function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) {
2833      global $wp_rewrite;
2834  
2835      $pagenum = (int) $pagenum;
2836  
2837      $result = get_permalink();
2838  
2839      if ( 'newest' === get_option( 'default_comments_page' ) ) {
2840          if ( $pagenum != $max_page ) {
2841              if ( $wp_rewrite->using_permalinks() ) {
2842                  $result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' );
2843              } else {
2844                  $result = add_query_arg( 'cpage', $pagenum, $result );
2845              }
2846          }
2847      } elseif ( $pagenum > 1 ) {
2848          if ( $wp_rewrite->using_permalinks() ) {
2849              $result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' );
2850          } else {
2851              $result = add_query_arg( 'cpage', $pagenum, $result );
2852          }
2853      }
2854  
2855      $result .= '#comments';
2856  
2857      /**
2858       * Filters the comments page number link for the current request.
2859       *
2860       * @since 2.7.0
2861       *
2862       * @param string $result The comments page number link.
2863       */
2864      return apply_filters( 'get_comments_pagenum_link', $result );
2865  }
2866  
2867  /**
2868   * Retrieves the link to the next comments page.
2869   *
2870   * @since 2.7.1
2871   *
2872   * @global WP_Query $wp_query WordPress Query object.
2873   *
2874   * @param string $label    Optional. Label for link text. Default empty.
2875   * @param int    $max_page Optional. Max page. Default 0.
2876   * @return string|void HTML-formatted link for the next page of comments.
2877   */
2878  function get_next_comments_link( $label = '', $max_page = 0 ) {
2879      global $wp_query;
2880  
2881      if ( ! is_singular() ) {
2882          return;
2883      }
2884  
2885      $page = get_query_var( 'cpage' );
2886  
2887      if ( ! $page ) {
2888          $page = 1;
2889      }
2890  
2891      $nextpage = intval( $page ) + 1;
2892  
2893      if ( empty( $max_page ) ) {
2894          $max_page = $wp_query->max_num_comment_pages;
2895      }
2896  
2897      if ( empty( $max_page ) ) {
2898          $max_page = get_comment_pages_count();
2899      }
2900  
2901      if ( $nextpage > $max_page ) {
2902          return;
2903      }
2904  
2905      if ( empty( $label ) ) {
2906          $label = __( 'Newer Comments &raquo;' );
2907      }
2908  
2909      /**
2910       * Filters the anchor tag attributes for the next comments page link.
2911       *
2912       * @since 2.7.0
2913       *
2914       * @param string $attributes Attributes for the anchor tag.
2915       */
2916      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>';
2917  }
2918  
2919  /**
2920   * Displays the link to the next comments page.
2921   *
2922   * @since 2.7.0
2923   *
2924   * @param string $label    Optional. Label for link text. Default empty.
2925   * @param int    $max_page Optional. Max page. Default 0.
2926   */
2927  function next_comments_link( $label = '', $max_page = 0 ) {
2928      echo get_next_comments_link( $label, $max_page );
2929  }
2930  
2931  /**
2932   * Retrieves the link to the previous comments page.
2933   *
2934   * @since 2.7.1
2935   *
2936   * @param string $label Optional. Label for comments link text. Default empty.
2937   * @return string|void HTML-formatted link for the previous page of comments.
2938   */
2939  function get_previous_comments_link( $label = '' ) {
2940      if ( ! is_singular() ) {
2941          return;
2942      }
2943  
2944      $page = get_query_var( 'cpage' );
2945  
2946      if ( intval( $page ) <= 1 ) {
2947          return;
2948      }
2949  
2950      $prevpage = intval( $page ) - 1;
2951  
2952      if ( empty( $label ) ) {
2953          $label = __( '&laquo; Older Comments' );
2954      }
2955  
2956      /**
2957       * Filters the anchor tag attributes for the previous comments page link.
2958       *
2959       * @since 2.7.0
2960       *
2961       * @param string $attributes Attributes for the anchor tag.
2962       */
2963      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>';
2964  }
2965  
2966  /**
2967   * Displays the link to the previous comments page.
2968   *
2969   * @since 2.7.0
2970   *
2971   * @param string $label Optional. Label for comments link text. Default empty.
2972   */
2973  function previous_comments_link( $label = '' ) {
2974      echo get_previous_comments_link( $label );
2975  }
2976  
2977  /**
2978   * Displays or retrieves pagination links for the comments on the current post.
2979   *
2980   * @see paginate_links()
2981   * @since 2.7.0
2982   *
2983   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
2984   *
2985   * @param string|array $args Optional args. See paginate_links(). Default empty array.
2986   * @return void|string|array Void if 'echo' argument is true and 'type' is not an array,
2987   *                           or if the query is not for an existing single post of any post type.
2988   *                           Otherwise, markup for comment page links or array of comment page links,
2989   *                           depending on 'type' argument.
2990   */
2991  function paginate_comments_links( $args = array() ) {
2992      global $wp_rewrite;
2993  
2994      if ( ! is_singular() ) {
2995          return;
2996      }
2997  
2998      $page = get_query_var( 'cpage' );
2999      if ( ! $page ) {
3000          $page = 1;
3001      }
3002      $max_page = get_comment_pages_count();
3003      $defaults = array(
3004          'base'         => add_query_arg( 'cpage', '%#%' ),
3005          'format'       => '',
3006          'total'        => $max_page,
3007          'current'      => $page,
3008          'echo'         => true,
3009          'type'         => 'plain',
3010          'add_fragment' => '#comments',
3011      );
3012      if ( $wp_rewrite->using_permalinks() ) {
3013          $defaults['base'] = user_trailingslashit( trailingslashit( get_permalink() ) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged' );
3014      }
3015  
3016      $args       = wp_parse_args( $args, $defaults );
3017      $page_links = paginate_links( $args );
3018  
3019      if ( $args['echo'] && 'array' !== $args['type'] ) {
3020          echo $page_links;
3021      } else {
3022          return $page_links;
3023      }
3024  }
3025  
3026  /**
3027   * Retrieves navigation to next/previous set of comments, when applicable.
3028   *
3029   * @since 4.4.0
3030   * @since 5.3.0 Added the `aria_label` parameter.
3031   * @since 5.5.0 Added the `class` parameter.
3032   *
3033   * @param array $args {
3034   *     Optional. Default comments navigation arguments.
3035   *
3036   *     @type string $prev_text          Anchor text to display in the previous comments link.
3037   *                                      Default 'Older comments'.
3038   *     @type string $next_text          Anchor text to display in the next comments link.
3039   *                                      Default 'Newer comments'.
3040   *     @type string $screen_reader_text Screen reader text for the nav element. Default 'Comments navigation'.
3041   *     @type string $aria_label         ARIA label text for the nav element. Default 'Comments'.
3042   *     @type string $class              Custom class for the nav element. Default 'comment-navigation'.
3043   * }
3044   * @return string Markup for comments links.
3045   */
3046  function get_the_comments_navigation( $args = array() ) {
3047      $navigation = '';
3048  
3049      // Are there comments to navigate through?
3050      if ( get_comment_pages_count() > 1 ) {
3051          // Make sure the nav element has an aria-label attribute: fallback to the screen reader text.
3052          if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) {
3053              $args['aria_label'] = $args['screen_reader_text'];
3054          }
3055  
3056          $args = wp_parse_args(
3057              $args,
3058              array(
3059                  'prev_text'          => __( 'Older comments' ),
3060                  'next_text'          => __( 'Newer comments' ),
3061                  'screen_reader_text' => __( 'Comments navigation' ),
3062                  'aria_label'         => __( 'Comments' ),
3063                  'class'              => 'comment-navigation',
3064              )
3065          );
3066  
3067          $prev_link = get_previous_comments_link( $args['prev_text'] );
3068          $next_link = get_next_comments_link( $args['next_text'] );
3069  
3070          if ( $prev_link ) {
3071              $navigation .= '<div class="nav-previous">' . $prev_link . '</div>';
3072          }
3073  
3074          if ( $next_link ) {
3075              $navigation .= '<div class="nav-next">' . $next_link . '</div>';
3076          }
3077  
3078          $navigation = _navigation_markup( $navigation, $args['class'], $args['screen_reader_text'], $args['aria_label'] );
3079      }
3080  
3081      return $navigation;
3082  }
3083  
3084  /**
3085   * Displays navigation to next/previous set of comments, when applicable.
3086   *
3087   * @since 4.4.0
3088   *
3089   * @param array $args See get_the_comments_navigation() for available arguments. Default empty array.
3090   */
3091  function the_comments_navigation( $args = array() ) {
3092      echo get_the_comments_navigation( $args );
3093  }
3094  
3095  /**
3096   * Retrieves a paginated navigation to next/previous set of comments, when applicable.
3097   *
3098   * @since 4.4.0
3099   * @since 5.3.0 Added the `aria_label` parameter.
3100   * @since 5.5.0 Added the `class` parameter.
3101   *
3102   * @see paginate_comments_links()
3103   *
3104   * @param array $args {
3105   *     Optional. Default pagination arguments.
3106   *
3107   *     @type string $screen_reader_text Screen reader text for the nav element. Default 'Comments navigation'.
3108   *     @type string $aria_label         ARIA label text for the nav element. Default 'Comments'.
3109   *     @type string $class              Custom class for the nav element. Default 'comments-pagination'.
3110   * }
3111   * @return string Markup for pagination links.
3112   */
3113  function get_the_comments_pagination( $args = array() ) {
3114      $navigation = '';
3115  
3116      // Make sure the nav element has an aria-label attribute: fallback to the screen reader text.
3117      if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) {
3118          $args['aria_label'] = $args['screen_reader_text'];
3119      }
3120  
3121      $args         = wp_parse_args(
3122          $args,
3123          array(
3124              'screen_reader_text' => __( 'Comments navigation' ),
3125              'aria_label'         => __( 'Comments' ),
3126              'class'              => 'comments-pagination',
3127          )
3128      );
3129      $args['echo'] = false;
3130  
3131      // Make sure we get a string back. Plain is the next best thing.
3132      if ( isset( $args['type'] ) && 'array' === $args['type'] ) {
3133          $args['type'] = 'plain';
3134      }
3135  
3136      $links = paginate_comments_links( $args );
3137  
3138      if ( $links ) {
3139          $navigation = _navigation_markup( $links, $args['class'], $args['screen_reader_text'], $args['aria_label'] );
3140      }
3141  
3142      return $navigation;
3143  }
3144  
3145  /**
3146   * Displays a paginated navigation to next/previous set of comments, when applicable.
3147   *
3148   * @since 4.4.0
3149   *
3150   * @param array $args See get_the_comments_pagination() for available arguments. Default empty array.
3151   */
3152  function the_comments_pagination( $args = array() ) {
3153      echo get_the_comments_pagination( $args );
3154  }
3155  
3156  /**
3157   * Retrieves the URL for the current site where the front end is accessible.
3158   *
3159   * Returns the 'home' option with the appropriate protocol. The protocol will be 'https'
3160   * if is_ssl() evaluates to true; otherwise, it will be the same as the 'home' option.
3161   * If `$scheme` is 'http' or 'https', is_ssl() is overridden.
3162   *
3163   * @since 3.0.0
3164   *
3165   * @param string      $path   Optional. Path relative to the home URL. Default empty.
3166   * @param string|null $scheme Optional. Scheme to give the home URL context. Accepts
3167   *                            'http', 'https', 'relative', 'rest', or null. Default null.
3168   * @return string Home URL link with optional path appended.
3169   */
3170  function home_url( $path = '', $scheme = null ) {
3171      return get_home_url( null, $path, $scheme );
3172  }
3173  
3174  /**
3175   * Retrieves the URL for a given site where the front end is accessible.
3176   *
3177   * Returns the 'home' option with the appropriate protocol. The protocol will be 'https'
3178   * if is_ssl() evaluates to true; otherwise, it will be the same as the 'home' option.
3179   * If `$scheme` is 'http' or 'https', is_ssl() is overridden.
3180   *
3181   * @since 3.0.0
3182   *
3183   * @global string $pagenow
3184   *
3185   * @param int         $blog_id Optional. Site ID. Default null (current site).
3186   * @param string      $path    Optional. Path relative to the home URL. Default empty.
3187   * @param string|null $scheme  Optional. Scheme to give the home URL context. Accepts
3188   *                             'http', 'https', 'relative', 'rest', or null. Default null.
3189   * @return string Home URL link with optional path appended.
3190   */
3191  function get_home_url( $blog_id = null, $path = '', $scheme = null ) {
3192      global $pagenow;
3193  
3194      $orig_scheme = $scheme;
3195  
3196      if ( empty( $blog_id ) || ! is_multisite() ) {
3197          $url = get_option( 'home' );
3198      } else {
3199          switch_to_blog( $blog_id );
3200          $url = get_option( 'home' );
3201          restore_current_blog();
3202      }
3203  
3204      if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ), true ) ) {
3205          if ( is_ssl() && ! is_admin() && 'wp-login.php' !== $pagenow ) {
3206              $scheme = 'https';
3207          } else {
3208              $scheme = parse_url( $url, PHP_URL_SCHEME );
3209          }
3210      }
3211  
3212      $url = set_url_scheme( $url, $scheme );
3213  
3214      if ( $path && is_string( $path ) ) {
3215          $url .= '/' . ltrim( $path, '/' );
3216      }
3217  
3218      /**
3219       * Filters the home URL.
3220       *
3221       * @since 3.0.0
3222       *
3223       * @param string      $url         The complete home URL including scheme and path.
3224       * @param string      $path        Path relative to the home URL. Blank string if no path is specified.
3225       * @param string|null $orig_scheme Scheme to give the home URL context. Accepts 'http', 'https',
3226       *                                 'relative', 'rest', or null.
3227       * @param int|null    $blog_id     Site ID, or null for the current site.
3228       */
3229      return apply_filters( 'home_url', $url, $path, $orig_scheme, $blog_id );
3230  }
3231  
3232  /**
3233   * Retrieves the URL for the current site where WordPress application files
3234   * (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible.
3235   *
3236   * Returns the 'site_url' option with the appropriate protocol, 'https' if
3237   * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
3238   * overridden.
3239   *
3240   * @since 3.0.0
3241   *
3242   * @param string $path   Optional. Path relative to the site URL. Default empty.
3243   * @param string $scheme Optional. Scheme to give the site URL context. See set_url_scheme().
3244   * @return string Site URL link with optional path appended.
3245   */
3246  function site_url( $path = '', $scheme = null ) {
3247      return get_site_url( null, $path, $scheme );
3248  }
3249  
3250  /**
3251   * Retrieves the URL for a given site where WordPress application files
3252   * (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible.
3253   *
3254   * Returns the 'site_url' option with the appropriate protocol, 'https' if
3255   * is_ssl() and 'http' otherwise. If `$scheme` is 'http' or 'https',
3256   * `is_ssl()` is overridden.
3257   *
3258   * @since 3.0.0
3259   *
3260   * @param int    $blog_id Optional. Site ID. Default null (current site).
3261   * @param string $path    Optional. Path relative to the site URL. Default empty.
3262   * @param string $scheme  Optional. Scheme to give the site URL context. Accepts
3263   *                        'http', 'https', 'login', 'login_post', 'admin', or
3264   *                        'relative'. Default null.
3265   * @return string Site URL link with optional path appended.
3266   */
3267  function get_site_url( $blog_id = null, $path = '', $scheme = null ) {
3268      if ( empty( $blog_id ) || ! is_multisite() ) {
3269          $url = get_option( 'siteurl' );
3270      } else {
3271          switch_to_blog( $blog_id );
3272          $url = get_option( 'siteurl' );
3273          restore_current_blog();
3274      }
3275  
3276      $url = set_url_scheme( $url, $scheme );
3277  
3278      if ( $path && is_string( $path ) ) {
3279          $url .= '/' . ltrim( $path, '/' );
3280      }
3281  
3282      /**
3283       * Filters the site URL.
3284       *
3285       * @since 2.7.0
3286       *
3287       * @param string      $url     The complete site URL including scheme and path.
3288       * @param string      $path    Path relative to the site URL. Blank string if no path is specified.
3289       * @param string|null $scheme  Scheme to give the site URL context. Accepts 'http', 'https', 'login',
3290       *                             'login_post', 'admin', 'relative' or null.
3291       * @param int|null    $blog_id Site ID, or null for the current site.
3292       */
3293      return apply_filters( 'site_url', $url, $path, $scheme, $blog_id );
3294  }
3295  
3296  /**
3297   * Retrieves the URL to the admin area for the current site.
3298   *
3299   * @since 2.6.0
3300   *
3301   * @param string $path   Optional path relative to the admin URL.
3302   * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl().
3303   *                       'http' or 'https' can be passed to force those schemes.
3304   * @return string Admin URL link with optional path appended.
3305   */
3306  function admin_url( $path = '', $scheme = 'admin' ) {
3307      return get_admin_url( null, $path, $scheme );
3308  }
3309  
3310  /**
3311   * Retrieves the URL to the admin area for a given site.
3312   *
3313   * @since 3.0.0
3314   *
3315   * @param int    $blog_id Optional. Site ID. Default null (current site).
3316   * @param string $path    Optional. Path relative to the admin URL. Default empty.
3317   * @param string $scheme  Optional. The scheme to use. Accepts 'http' or 'https',
3318   *                        to force those schemes. Default 'admin', which obeys
3319   *                        force_ssl_admin() and is_ssl().
3320   * @return string Admin URL link with optional path appended.
3321   */
3322  function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' ) {
3323      $url = get_site_url( $blog_id, 'wp-admin/', $scheme );
3324  
3325      if ( $path && is_string( $path ) ) {
3326          $url .= ltrim( $path, '/' );
3327      }
3328  
3329      /**
3330       * Filters the admin area URL.
3331       *
3332       * @since 2.8.0
3333       *
3334       * @param string   $url     The complete admin area URL including scheme and path.
3335       * @param string   $path    Path relative to the admin area URL. Blank string if no path is specified.
3336       * @param int|null $blog_id Site ID, or null for the current site.
3337       */
3338      return apply_filters( 'admin_url', $url, $path, $blog_id );
3339  }
3340  
3341  /**
3342   * Retrieves the URL to the includes directory.
3343   *
3344   * @since 2.6.0
3345   *
3346   * @param string $path   Optional. Path relative to the includes URL. Default empty.
3347   * @param string $scheme Optional. Scheme to give the includes URL context. Accepts
3348   *                       'http', 'https', or 'relative'. Default null.
3349   * @return string Includes URL link with optional path appended.
3350   */
3351  function includes_url( $path = '', $scheme = null ) {
3352      $url = site_url( '/' . WPINC . '/', $scheme );
3353  
3354      if ( $path && is_string( $path ) ) {
3355          $url .= ltrim( $path, '/' );
3356      }
3357  
3358      /**
3359       * Filters the URL to the includes directory.
3360       *
3361       * @since 2.8.0
3362       *
3363       * @param string $url  The complete URL to the includes directory including scheme and path.
3364       * @param string $path Path relative to the URL to the wp-includes directory. Blank string
3365       *                     if no path is specified.
3366       */
3367      return apply_filters( 'includes_url', $url, $path );
3368  }
3369  
3370  /**
3371   * Retrieves the URL to the content directory.
3372   *
3373   * @since 2.6.0
3374   *
3375   * @param string $path Optional. Path relative to the content URL. Default empty.
3376   * @return string Content URL link with optional path appended.
3377   */
3378  function content_url( $path = '' ) {
3379      $url = set_url_scheme( WP_CONTENT_URL );
3380  
3381      if ( $path && is_string( $path ) ) {
3382          $url .= '/' . ltrim( $path, '/' );
3383      }
3384  
3385      /**
3386       * Filters the URL to the content directory.
3387       *
3388       * @since 2.8.0
3389       *
3390       * @param string $url  The complete URL to the content directory including scheme and path.
3391       * @param string $path Path relative to the URL to the content directory. Blank string
3392       *                     if no path is specified.
3393       */
3394      return apply_filters( 'content_url', $url, $path );
3395  }
3396  
3397  /**
3398   * Retrieves a URL within the plugins or mu-plugins directory.
3399   *
3400   * Defaults to the plugins directory URL if no arguments are supplied.
3401   *
3402   * @since 2.6.0
3403   *
3404   * @param string $path   Optional. Extra path appended to the end of the URL, including
3405   *                       the relative directory if $plugin is supplied. Default empty.
3406   * @param string $plugin Optional. A full path to a file inside a plugin or mu-plugin.
3407   *                       The URL will be relative to its directory. Default empty.
3408   *                       Typically this is done by passing `__FILE__` as the argument.
3409   * @return string Plugins URL link with optional paths appended.
3410   */
3411  function plugins_url( $path = '', $plugin = '' ) {
3412  
3413      $path          = wp_normalize_path( $path );
3414      $plugin        = wp_normalize_path( $plugin );
3415      $mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );
3416  
3417      if ( ! empty( $plugin ) && 0 === strpos( $plugin, $mu_plugin_dir ) ) {
3418          $url = WPMU_PLUGIN_URL;
3419      } else {
3420          $url = WP_PLUGIN_URL;
3421      }
3422  
3423      $url = set_url_scheme( $url );
3424  
3425      if ( ! empty( $plugin ) && is_string( $plugin ) ) {
3426          $folder = dirname( plugin_basename( $plugin ) );
3427          if ( '.' !== $folder ) {
3428              $url .= '/' . ltrim( $folder, '/' );
3429          }
3430      }
3431  
3432      if ( $path && is_string( $path ) ) {
3433          $url .= '/' . ltrim( $path, '/' );
3434      }
3435  
3436      /**
3437       * Filters the URL to the plugins directory.
3438       *
3439       * @since 2.8.0
3440       *
3441       * @param string $url    The complete URL to the plugins directory including scheme and path.
3442       * @param string $path   Path relative to the URL to the plugins directory. Blank string
3443       *                       if no path is specified.
3444       * @param string $plugin The plugin file path to be relative to. Blank string if no plugin
3445       *                       is specified.
3446       */
3447      return apply_filters( 'plugins_url', $url, $path, $plugin );
3448  }
3449  
3450  /**
3451   * Retrieves the site URL for the current network.
3452   *
3453   * Returns the site URL with the appropriate protocol, 'https' if
3454   * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
3455   * overridden.
3456   *
3457   * @since 3.0.0
3458   *
3459   * @see set_url_scheme()
3460   *
3461   * @param string $path   Optional. Path relative to the site URL. Default empty.
3462   * @param string $scheme Optional. Scheme to give the site URL context. Accepts
3463   *                       'http', 'https', or 'relative'. Default null.
3464   * @return string Site URL link with optional path appended.
3465   */
3466  function network_site_url( $path = '', $scheme = null ) {
3467      if ( ! is_multisite() ) {
3468          return site_url( $path, $scheme );
3469      }
3470  
3471      $current_network = get_network();
3472  
3473      if ( 'relative' === $scheme ) {
3474          $url = $current_network->path;
3475      } else {
3476          $url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme );
3477      }
3478  
3479      if ( $path && is_string( $path ) ) {
3480          $url .= ltrim( $path, '/' );
3481      }
3482  
3483      /**
3484       * Filters the network site URL.
3485       *
3486       * @since 3.0.0
3487       *
3488       * @param string      $url    The complete network site URL including scheme and path.
3489       * @param string      $path   Path relative to the network site URL. Blank string if
3490       *                            no path is specified.
3491       * @param string|null $scheme Scheme to give the URL context. Accepts 'http', 'https',
3492       *                            'relative' or null.
3493       */
3494      return apply_filters( 'network_site_url', $url, $path, $scheme );
3495  }
3496  
3497  /**
3498   * Retrieves the home URL for the current network.
3499   *
3500   * Returns the home URL with the appropriate protocol, 'https' is_ssl()
3501   * and 'http' otherwise. If `$scheme` is 'http' or 'https', `is_ssl()` is
3502   * overridden.
3503   *
3504   * @since 3.0.0
3505   *
3506   * @param string $path   Optional. Path relative to the home URL. Default empty.
3507   * @param string $scheme Optional. Scheme to give the home URL context. Accepts
3508   *                       'http', 'https', or 'relative'. Default null.
3509   * @return string Home URL link with optional path appended.
3510   */
3511  function network_home_url( $path = '', $scheme = null ) {
3512      if ( ! is_multisite() ) {
3513          return home_url( $path, $scheme );
3514      }
3515  
3516      $current_network = get_network();
3517      $orig_scheme     = $scheme;
3518  
3519      if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ), true ) ) {
3520          $scheme = is_ssl() && ! is_admin() ? 'https' : 'http';
3521      }
3522  
3523      if ( 'relative' === $scheme ) {
3524          $url = $current_network->path;
3525      } else {
3526          $url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme );
3527      }
3528  
3529      if ( $path && is_string( $path ) ) {
3530          $url .= ltrim( $path, '/' );
3531      }
3532  
3533      /**
3534       * Filters the network home URL.
3535       *
3536       * @since 3.0.0
3537       *
3538       * @param string      $url         The complete network home URL including scheme and path.
3539       * @param string      $path        Path relative to the network home URL. Blank string
3540       *                                 if no path is specified.
3541       * @param string|null $orig_scheme Scheme to give the URL context. Accepts 'http', 'https',
3542       *                                 'relative' or null.
3543       */
3544      return apply_filters( 'network_home_url', $url, $path, $orig_scheme );
3545  }
3546  
3547  /**
3548   * Retrieves the URL to the admin area for the network.
3549   *
3550   * @since 3.0.0
3551   *
3552   * @param string $path   Optional path relative to the admin URL. Default empty.
3553   * @param string $scheme Optional. The scheme to use. Default is 'admin', which obeys force_ssl_admin()
3554   *                       and is_ssl(). 'http' or 'https' can be passed to force those schemes.
3555   * @return string Admin URL link with optional path appended.
3556   */
3557  function network_admin_url( $path = '', $scheme = 'admin' ) {
3558      if ( ! is_multisite() ) {
3559          return admin_url( $path, $scheme );
3560      }
3561  
3562      $url = network_site_url( 'wp-admin/network/', $scheme );
3563  
3564      if ( $path && is_string( $path ) ) {
3565          $url .= ltrim( $path, '/' );
3566      }
3567  
3568      /**
3569       * Filters the network admin URL.
3570       *
3571       * @since 3.0.0
3572       *
3573       * @param string $url  The complete network admin URL including scheme and path.
3574       * @param string $path Path relative to the network admin URL. Blank string if
3575       *                     no path is specified.
3576       */
3577      return apply_filters( 'network_admin_url', $url, $path );
3578  }
3579  
3580  /**
3581   * Retrieves the URL to the admin area for the current user.
3582   *
3583   * @since 3.0.0
3584   *
3585   * @param string $path   Optional. Path relative to the admin URL. Default empty.
3586   * @param string $scheme Optional. The scheme to use. Default is 'admin', which obeys force_ssl_admin()
3587   *                       and is_ssl(). 'http' or 'https' can be passed to force those schemes.
3588   * @return string Admin URL link with optional path appended.
3589   */
3590  function user_admin_url( $path = '', $scheme = 'admin' ) {
3591      $url = network_site_url( 'wp-admin/user/', $scheme );
3592  
3593      if ( $path && is_string( $path ) ) {
3594          $url .= ltrim( $path, '/' );
3595      }
3596  
3597      /**
3598       * Filters the user admin URL for the current user.
3599       *
3600       * @since 3.1.0
3601       *
3602       * @param string $url  The complete URL including scheme and path.
3603       * @param string $path Path relative to the URL. Blank string if
3604       *                     no path is specified.
3605       */
3606      return apply_filters( 'user_admin_url', $url, $path );
3607  }
3608  
3609  /**
3610   * Retrieves the URL to the admin area for either the current site or the network depending on context.
3611   *
3612   * @since 3.1.0
3613   *
3614   * @param string $path   Optional. Path relative to the admin URL. Default empty.
3615   * @param string $scheme Optional. The scheme to use. Default is 'admin', which obeys force_ssl_admin()
3616   *                       and is_ssl(). 'http' or 'https' can be passed to force those schemes.
3617   * @return string Admin URL link with optional path appended.
3618   */
3619  function self_admin_url( $path = '', $scheme = 'admin' ) {
3620      if ( is_network_admin() ) {
3621          $url = network_admin_url( $path, $scheme );
3622      } elseif ( is_user_admin() ) {
3623          $url = user_admin_url( $path, $scheme );
3624      } else {
3625          $url = admin_url( $path, $scheme );
3626      }
3627  
3628      /**
3629       * Filters the admin URL for the current site or network depending on context.
3630       *
3631       * @since 4.9.0
3632       *
3633       * @param string $url    The complete URL including scheme and path.
3634       * @param string $path   Path relative to the URL. Blank string if no path is specified.
3635       * @param string $scheme The scheme to use.
3636       */
3637      return apply_filters( 'self_admin_url', $url, $path, $scheme );
3638  }
3639  
3640  /**
3641   * Sets the scheme for a URL.
3642   *
3643   * @since 3.4.0
3644   * @since 4.4.0 The 'rest' scheme was added.
3645   *
3646   * @param string      $url    Absolute URL that includes a scheme
3647   * @param string|null $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login',
3648   *                            'login_post', 'admin', 'relative', 'rest', 'rpc', or null. Default null.
3649   * @return string URL with chosen scheme.
3650   */
3651  function set_url_scheme( $url, $scheme = null ) {
3652      $orig_scheme = $scheme;
3653  
3654      if ( ! $scheme ) {
3655          $scheme = is_ssl() ? 'https' : 'http';
3656      } elseif ( 'admin' === $scheme || 'login' === $scheme || 'login_post' === $scheme || 'rpc' === $scheme ) {
3657          $scheme = is_ssl() || force_ssl_admin() ? 'https' : 'http';
3658      } elseif ( 'http' !== $scheme && 'https' !== $scheme && 'relative' !== $scheme ) {
3659          $scheme = is_ssl() ? 'https' : 'http';
3660      }
3661  
3662      $url = trim( $url );
3663      if ( substr( $url, 0, 2 ) === '//' ) {
3664          $url = 'http:' . $url;
3665      }
3666  
3667      if ( 'relative' === $scheme ) {
3668          $url = ltrim( preg_replace( '#^\w+://[^/]*#', '', $url ) );
3669          if ( '' !== $url && '/' === $url[0] ) {
3670              $url = '/' . ltrim( $url, "/ \t\n\r\0\x0B" );
3671          }
3672      } else {
3673          $url = preg_replace( '#^\w+://#', $scheme . '://', $url );
3674      }
3675  
3676      /**
3677       * Filters the resulting URL after setting the scheme.
3678       *
3679       * @since 3.4.0
3680       *
3681       * @param string      $url         The complete URL including scheme and path.
3682       * @param string      $scheme      Scheme applied to the URL. One of 'http', 'https', or 'relative'.
3683       * @param string|null $orig_scheme Scheme requested for the URL. One of 'http', 'https', 'login',
3684       *                                 'login_post', 'admin', 'relative', 'rest', 'rpc', or null.
3685       */
3686      return apply_filters( 'set_url_scheme', $url, $scheme, $orig_scheme );
3687  }
3688  
3689  /**
3690   * Retrieves the URL to the user's dashboard.
3691   *
3692   * If a user does not belong to any site, the global user dashboard is used. If the user
3693   * belongs to the current site, the dashboard for the current site is returned. If the user
3694   * cannot edit the current site, the dashboard to the user's primary site is returned.
3695   *
3696   * @since 3.1.0
3697   *
3698   * @param int    $user_id Optional. User ID. Defaults to current user.
3699   * @param string $path    Optional path relative to the dashboard. Use only paths known to
3700   *                        both site and user admins. Default empty.
3701   * @param string $scheme  The scheme to use. Default is 'admin', which obeys force_ssl_admin()
3702   *                        and is_ssl(). 'http' or 'https' can be passed to force those schemes.
3703   * @return string Dashboard URL link with optional path appended.
3704   */
3705  function get_dashboard_url( $user_id = 0, $path = '', $scheme = 'admin' ) {
3706      $user_id = $user_id ? (int) $user_id : get_current_user_id();
3707  
3708      $blogs = get_blogs_of_user( $user_id );
3709  
3710      if ( is_multisite() && ! user_can( $user_id, 'manage_network' ) && empty( $blogs ) ) {
3711          $url = user_admin_url( $path, $scheme );
3712      } elseif ( ! is_multisite() ) {
3713          $url = admin_url( $path, $scheme );
3714      } else {
3715          $current_blog = get_current_blog_id();
3716  
3717          if ( $current_blog && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blog, array_keys( $blogs ), true ) ) ) {
3718              $url = admin_url( $path, $scheme );
3719          } else {
3720              $active = get_active_blog_for_user( $user_id );
3721              if ( $active ) {
3722                  $url = get_admin_url( $active->blog_id, $path, $scheme );
3723              } else {
3724                  $url = user_admin_url( $path, $scheme );
3725              }
3726          }
3727      }
3728  
3729      /**
3730       * Filters the dashboard URL for a user.
3731       *
3732       * @since 3.1.0
3733       *
3734       * @param string $url     The complete URL including scheme and path.
3735       * @param int    $user_id The user ID.
3736       * @param string $path    Path relative to the URL. Blank string if no path is specified.
3737       * @param string $scheme  Scheme to give the URL context. Accepts 'http', 'https', 'login',
3738       *                        'login_post', 'admin', 'relative' or null.
3739       */
3740      return apply_filters( 'user_dashboard_url', $url, $user_id, $path, $scheme );
3741  }
3742  
3743  /**
3744   * Retrieves the URL to the user's profile editor.
3745   *
3746   * @since 3.1.0
3747   *
3748   * @param int    $user_id Optional. User ID. Defaults to current user.
3749   * @param string $scheme  Optional. The scheme to use. Default is 'admin', which obeys force_ssl_admin()
3750   *                        and is_ssl(). 'http' or 'https' can be passed to force those schemes.
3751   * @return string Dashboard URL link with optional path appended.
3752   */
3753  function get_edit_profile_url( $user_id = 0, $scheme = 'admin' ) {
3754      $user_id = $user_id ? (int) $user_id : get_current_user_id();
3755  
3756      if ( is_user_admin() ) {
3757          $url = user_admin_url( 'profile.php', $scheme );
3758      } elseif ( is_network_admin() ) {
3759          $url = network_admin_url( 'profile.php', $scheme );
3760      } else {
3761          $url = get_dashboard_url( $user_id, 'profile.php', $scheme );
3762      }
3763  
3764      /**
3765       * Filters the URL for a user's profile editor.
3766       *
3767       * @since 3.1.0
3768       *
3769       * @param string $url     The complete URL including scheme and path.
3770       * @param int    $user_id The user ID.
3771       * @param string $scheme  Scheme to give the URL context. Accepts 'http', 'https', 'login',
3772       *                        'login_post', 'admin', 'relative' or null.
3773       */
3774      return apply_filters( 'edit_profile_url', $url, $user_id, $scheme );
3775  }
3776  
3777  /**
3778   * Returns the canonical URL for a post.
3779   *
3780   * When the post is the same as the current requested page the function will handle the
3781   * pagination arguments too.
3782   *
3783   * @since 4.6.0
3784   *
3785   * @param int|WP_Post $post Optional. Post ID or object. Default is global `$post`.
3786   * @return string|false The canonical URL, or false if the post does not exist or has not
3787   *                      been published yet.
3788   */
3789  function wp_get_canonical_url( $post = null ) {
3790      $post = get_post( $post );
3791  
3792      if ( ! $post ) {
3793          return false;
3794      }
3795  
3796      if ( 'publish' !== $post->post_status ) {
3797          return false;
3798      }
3799  
3800      $canonical_url = get_permalink( $post );
3801  
3802      // If a canonical is being generated for the current page, make sure it has pagination if needed.
3803      if ( get_queried_object_id() === $post->ID ) {
3804          $page = get_query_var( 'page', 0 );
3805          if ( $page >= 2 ) {
3806              if ( ! get_option( 'permalink_structure' ) ) {
3807                  $canonical_url = add_query_arg( 'page', $page, $canonical_url );
3808              } else {
3809                  $canonical_url = trailingslashit( $canonical_url ) . user_trailingslashit( $page, 'single_paged' );
3810              }
3811          }
3812  
3813          $cpage = get_query_var( 'cpage', 0 );
3814          if ( $cpage ) {
3815              $canonical_url = get_comments_pagenum_link( $cpage );
3816          }
3817      }
3818  
3819      /**
3820       * Filters the canonical URL for a post.
3821       *
3822       * @since 4.6.0
3823       *
3824       * @param string  $canonical_url The post's canonical URL.
3825       * @param WP_Post $post          Post object.
3826       */
3827      return apply_filters( 'get_canonical_url', $canonical_url, $post );
3828  }
3829  
3830  /**
3831   * Outputs rel=canonical for singular queries.
3832   *
3833   * @since 2.9.0
3834   * @since 4.6.0 Adjusted to use `wp_get_canonical_url()`.
3835   */
3836  function rel_canonical() {
3837      if ( ! is_singular() ) {
3838          return;
3839      }
3840  
3841      $id = get_queried_object_id();
3842  
3843      if ( 0 === $id ) {
3844          return;
3845      }
3846  
3847      $url = wp_get_canonical_url( $id );
3848  
3849      if ( ! empty( $url ) ) {
3850          echo '<link rel="canonical" href="' . esc_url( $url ) . '" />' . "\n";
3851      }
3852  }
3853  
3854  /**
3855   * Returns a shortlink for a post, page, attachment, or site.
3856   *
3857   * This function exists to provide a shortlink tag that all themes and plugins can target.
3858   * A plugin must hook in to provide the actual shortlinks. Default shortlink support is
3859   * limited to providing ?p= style links for posts. Plugins can short-circuit this function
3860   * via the {@see 'pre_get_shortlink'} filter or filter the output via the {@see 'get_shortlink'}
3861   * filter.
3862   *
3863   * @since 3.0.0
3864   *
3865   * @param int    $id          Optional. A post or site ID. Default is 0, which means the current post or site.
3866   * @param string $context     Optional. Whether the ID is a 'site' id, 'post' id, or 'media' id. If 'post',
3867   *                            the post_type of the post is consulted. If 'query', the current query is consulted
3868   *                            to determine the ID and context. Default 'post'.
3869   * @param bool   $allow_slugs Optional. Whether to allow post slugs in the shortlink. It is up to the plugin how
3870   *                            and whether to honor this. Default true.
3871   * @return string A shortlink or an empty string if no shortlink exists for the requested resource or if shortlinks
3872   *                are not enabled.
3873   */
3874  function wp_get_shortlink( $id = 0, $context = 'post', $allow_slugs = true ) {
3875      /**
3876       * Filters whether to preempt generating a shortlink for the given post.
3877       *
3878       * Returning a truthy value from the filter will effectively short-circuit
3879       * the shortlink generation process, returning that value instead.
3880       *
3881       * @since 3.0.0
3882       *
3883       * @param false|string $return      Short-circuit return value. Either false or a URL string.
3884       * @param int          $id          Post ID, or 0 for the current post.
3885       * @param string       $context     The context for the link. One of 'post' or 'query',
3886       * @param bool         $allow_slugs Whether to allow post slugs in the shortlink.
3887       */
3888      $shortlink = apply_filters( 'pre_get_shortlink', false, $id, $context, $allow_slugs );
3889  
3890      if ( false !== $shortlink ) {
3891          return $shortlink;
3892      }
3893  
3894      $post_id = 0;
3895      if ( 'query' === $context && is_singular() ) {
3896          $post_id = get_queried_object_id();
3897          $post    = get_post( $post_id );
3898      } elseif ( 'post' === $context ) {
3899          $post = get_post( $id );
3900          if ( ! empty( $post->ID ) ) {
3901              $post_id = $post->ID;
3902          }
3903      }
3904  
3905      $shortlink = '';
3906  
3907      // Return `?p=` link for all public post types.
3908      if ( ! empty( $post_id ) ) {
3909          $post_type = get_post_type_object( $post->post_type );
3910  
3911          if ( 'page' === $post->post_type && get_option( 'page_on_front' ) == $post->ID && 'page' === get_option( 'show_on_front' ) ) {
3912              $shortlink = home_url( '/' );
3913          } elseif ( $post_type->public ) {
3914              $shortlink = home_url( '?p=' . $post_id );
3915          }
3916      }
3917  
3918      /**
3919       * Filters the shortlink for a post.
3920       *
3921       * @since 3.0.0
3922       *
3923       * @param string $shortlink   Shortlink URL.
3924       * @param int    $id          Post ID, or 0 for the current post.
3925       * @param string $context     The context for the link. One of 'post' or 'query',
3926       * @param bool   $allow_slugs Whether to allow post slugs in the shortlink. Not used by default.
3927       */
3928      return apply_filters( 'get_shortlink', $shortlink, $id, $context, $allow_slugs );
3929  }
3930  
3931  /**
3932   * Injects rel=shortlink into the head if a shortlink is defined for the current page.
3933   *
3934   * Attached to the {@see 'wp_head'} action.
3935   *
3936   * @since 3.0.0
3937   */
3938  function wp_shortlink_wp_head() {
3939      $shortlink = wp_get_shortlink( 0, 'query' );
3940  
3941      if ( empty( $shortlink ) ) {
3942          return;
3943      }
3944  
3945      echo "<link rel='shortlink' href='" . esc_url( $shortlink ) . "' />\n";
3946  }
3947  
3948  /**
3949   * Sends a Link: rel=shortlink header if a shortlink is defined for the current page.
3950   *
3951   * Attached to the {@see 'wp'} action.
3952   *
3953   * @since 3.0.0
3954   */
3955  function wp_shortlink_header() {
3956      if ( headers_sent() ) {
3957          return;
3958      }
3959  
3960      $shortlink = wp_get_shortlink( 0, 'query' );
3961  
3962      if ( empty( $shortlink ) ) {
3963          return;
3964      }
3965  
3966      header( 'Link: <' . $shortlink . '>; rel=shortlink', false );
3967  }
3968  
3969  /**
3970   * Displays the shortlink for a post.
3971   *
3972   * Must be called from inside "The Loop"
3973   *
3974   * Call like the_shortlink( __( 'Shortlinkage FTW' ) )
3975   *
3976   * @since 3.0.0
3977   *
3978   * @param string $text   Optional The link text or HTML to be displayed. Defaults to 'This is the short link.'
3979   * @param string $title  Optional The tooltip for the link. Must be sanitized. Defaults to the sanitized post title.
3980   * @param string $before Optional HTML to display before the link. Default empty.
3981   * @param string $after  Optional HTML to display after the link. Default empty.
3982   */
3983  function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) {
3984      $post = get_post();
3985  
3986      if ( empty( $text ) ) {
3987          $text = __( 'This is the short link.' );
3988      }
3989  
3990      if ( empty( $title ) ) {
3991          $title = the_title_attribute( array( 'echo' => false ) );
3992      }
3993  
3994      $shortlink = wp_get_shortlink( $post->ID );
3995  
3996      if ( ! empty( $shortlink ) ) {
3997          $link = '<a rel="shortlink" href="' . esc_url( $shortlink ) . '" title="' . $title . '">' . $text . '</a>';
3998  
3999          /**
4000           * Filters the short link anchor tag for a post.
4001           *
4002           * @since 3.0.0
4003           *
4004           * @param string $link      Shortlink anchor tag.
4005           * @param string $shortlink Shortlink URL.
4006           * @param string $text      Shortlink's text.
4007           * @param string $title     Shortlink's title attribute.
4008           */
4009          $link = apply_filters( 'the_shortlink', $link, $shortlink, $text, $title );
4010          echo $before, $link, $after;
4011      }
4012  }
4013  
4014  
4015  /**
4016   * Retrieves the avatar URL.
4017   *
4018   * @since 4.2.0
4019   *
4020   * @param mixed $id_or_email The Gravatar to retrieve a URL for. Accepts a user_id, gravatar md5 hash,
4021   *                           user email, WP_User object, WP_Post object, or WP_Comment object.
4022   * @param array $args {
4023   *     Optional. Arguments to return instead of the default arguments.
4024   *
4025   *     @type int    $size           Height and width of the avatar in pixels. Default 96.
4026   *     @type string $default        URL for the default image or a default type. Accepts '404' (return
4027   *                                  a 404 instead of a default image), 'retro' (8bit), 'monsterid' (monster),
4028   *                                  'wavatar' (cartoon face), 'indenticon' (the "quilt"), 'mystery', 'mm',
4029   *                                  or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF), or
4030   *                                  'gravatar_default' (the Gravatar logo). Default is the value of the
4031   *                                  'avatar_default' option, with a fallback of 'mystery'.
4032   *     @type bool   $force_default  Whether to always show the default image, never the Gravatar. Default false.
4033   *     @type string $rating         What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are
4034   *                                  judged in that order. Default is the value of the 'avatar_rating' option.
4035   *     @type string $scheme         URL scheme to use. See set_url_scheme() for accepted values.
4036   *                                  Default null.
4037   *     @type array  $processed_args When the function returns, the value will be the processed/sanitized $args
4038   *                                  plus a "found_avatar" guess. Pass as a reference. Default null.
4039   * }
4040   * @return string|false The URL of the avatar on success, false on failure.
4041   */
4042  function get_avatar_url( $id_or_email, $args = null ) {
4043      $args = get_avatar_data( $id_or_email, $args );
4044      return $args['url'];
4045  }
4046  
4047  
4048  /**
4049   * Check if this comment type allows avatars to be retrieved.
4050   *
4051   * @since 5.1.0
4052   *
4053   * @param string $comment_type Comment type to check.
4054   * @return bool Whether the comment type is allowed for retrieving avatars.
4055   */
4056  function is_avatar_comment_type( $comment_type ) {
4057      /**
4058       * Filters the list of allowed comment types for retrieving avatars.
4059       *
4060       * @since 3.0.0
4061       *
4062       * @param array $types An array of content types. Default only contains 'comment'.
4063       */
4064      $allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) );
4065  
4066      return in_array( $comment_type, (array) $allowed_comment_types, true );
4067  }
4068  
4069  
4070  /**
4071   * Retrieves default data about the avatar.
4072   *
4073   * @since 4.2.0
4074   *
4075   * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash,
4076   *                           user email, WP_User object, WP_Post object, or WP_Comment object.
4077   * @param array $args {
4078   *     Optional. Arguments to return instead of the default arguments.
4079   *
4080   *     @type int    $size           Height and width of the avatar image file in pixels. Default 96.
4081   *     @type int    $height         Display height of the avatar in pixels. Defaults to $size.
4082   *     @type int    $width          Display width of the avatar in pixels. Defaults to $size.
4083   *     @type string $default        URL for the default image or a default type. Accepts '404' (return
4084   *                                  a 404 instead of a default image), 'retro' (8bit), 'monsterid' (monster),
4085   *                                  'wavatar' (cartoon face), 'indenticon' (the "quilt"), 'mystery', 'mm',
4086   *                                  or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF), or
4087   *                                  'gravatar_default' (the Gravatar logo). Default is the value of the
4088   *                                  'avatar_default' option, with a fallback of 'mystery'.
4089   *     @type bool   $force_default  Whether to always show the default image, never the Gravatar. Default false.
4090   *     @type string $rating         What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are
4091   *                                  judged in that order. Default is the value of the 'avatar_rating' option.
4092   *     @type string $scheme         URL scheme to use. See set_url_scheme() for accepted values.
4093   *                                  Default null.
4094   *     @type array  $processed_args When the function returns, the value will be the processed/sanitized $args
4095   *                                  plus a "found_avatar" guess. Pass as a reference. Default null.
4096   *     @type string $extra_attr     HTML attributes to insert in the IMG element. Is not sanitized. Default empty.
4097   * }
4098   * @return array {
4099   *     Along with the arguments passed in `$args`, this will contain a couple of extra arguments.
4100   *
4101   *     @type bool   $found_avatar True if we were able to find an avatar for this user,
4102   *                                false or not set if we couldn't.
4103   *     @type string $url          The URL of the avatar we found.
4104   * }
4105   */
4106  function get_avatar_data( $id_or_email, $args = null ) {
4107      $args = wp_parse_args(
4108          $args,
4109          array(
4110              'size'           => 96,
4111              'height'         => null,
4112              'width'          => null,
4113              'default'        => get_option( 'avatar_default', 'mystery' ),
4114              'force_default'  => false,
4115              'rating'         => get_option( 'avatar_rating' ),
4116              'scheme'         => null,
4117              'processed_args' => null, // If used, should be a reference.
4118              'extra_attr'     => '',
4119          )
4120      );
4121  
4122      if ( is_numeric( $args['size'] ) ) {
4123          $args['size'] = absint( $args['size'] );
4124          if ( ! $args['size'] ) {
4125              $args['size'] = 96;
4126          }
4127      } else {
4128          $args['size'] = 96;
4129      }
4130  
4131      if ( is_numeric( $args['height'] ) ) {
4132          $args['height'] = absint( $args['height'] );
4133          if ( ! $args['height'] ) {
4134              $args['height'] = $args['size'];
4135          }
4136      } else {
4137          $args['height'] = $args['size'];
4138      }
4139  
4140      if ( is_numeric( $args['width'] ) ) {
4141          $args['width'] = absint( $args['width'] );
4142          if ( ! $args['width'] ) {
4143              $args['width'] = $args['size'];
4144          }
4145      } else {
4146          $args['width'] = $args['size'];
4147      }
4148  
4149      if ( empty( $args['default'] ) ) {
4150          $args['default'] = get_option( 'avatar_default', 'mystery' );
4151      }
4152  
4153      switch ( $args['default'] ) {
4154          case 'mm':
4155          case 'mystery':
4156          case 'mysteryman':
4157              $args['default'] = 'mm';
4158              break;
4159          case 'gravatar_default':
4160              $args['default'] = false;
4161              break;
4162      }
4163  
4164      $args['force_default'] = (bool) $args['force_default'];
4165  
4166      $args['rating'] = strtolower( $args['rating'] );
4167  
4168      $args['found_avatar'] = false;
4169  
4170      /**
4171       * Filters whether to retrieve the avatar URL early.
4172       *
4173       * Passing a non-null value in the 'url' member of the return array will
4174       * effectively short circuit get_avatar_data(), passing the value through
4175       * the {@see 'get_avatar_data'} filter and returning early.
4176       *
4177       * @since 4.2.0
4178       *
4179       * @param array $args        Arguments passed to get_avatar_data(), after processing.
4180       * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash,
4181       *                           user email, WP_User object, WP_Post object, or WP_Comment object.
4182       */
4183      $args = apply_filters( 'pre_get_avatar_data', $args, $id_or_email );
4184  
4185      if ( isset( $args['url'] ) ) {
4186          /** This filter is documented in wp-includes/link-template.php */
4187          return apply_filters( 'get_avatar_data', $args, $id_or_email );
4188      }
4189  
4190      $email_hash = '';
4191      $user       = false;
4192      $email      = false;
4193  
4194      if ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) {
4195          $id_or_email = get_comment( $id_or_email );
4196      }
4197  
4198      // Process the user identifier.
4199      if ( is_numeric( $id_or_email ) ) {
4200          $user = get_user_by( 'id', absint( $id_or_email ) );
4201      } elseif ( is_string( $id_or_email ) ) {
4202          if ( strpos( $id_or_email, '@md5.gravatar.com' ) ) {
4203              // MD5 hash.
4204              list( $email_hash ) = explode( '@', $id_or_email );
4205          } else {
4206              // Email address.
4207              $email = $id_or_email;
4208          }
4209      } elseif ( $id_or_email instanceof WP_User ) {
4210          // User object.
4211          $user = $id_or_email;
4212      } elseif ( $id_or_email instanceof WP_Post ) {
4213          // Post object.
4214          $user = get_user_by( 'id', (int) $id_or_email->post_author );
4215      } elseif ( $id_or_email instanceof WP_Comment ) {
4216          if ( ! is_avatar_comment_type( get_comment_type( $id_or_email ) ) ) {
4217              $args['url'] = false;
4218              /** This filter is documented in wp-includes/link-template.php */
4219              return apply_filters( 'get_avatar_data', $args, $id_or_email );
4220          }
4221  
4222          if ( ! empty( $id_or_email->user_id ) ) {
4223              $user = get_user_by( 'id', (int) $id_or_email->user_id );
4224          }
4225          if ( ( ! $user || is_wp_error( $user ) ) && ! empty( $id_or_email->comment_author_email ) ) {
4226              $email = $id_or_email->comment_author_email;
4227          }
4228      }
4229  
4230      if ( ! $email_hash ) {
4231          if ( $user ) {
4232              $email = $user->user_email;
4233          }
4234  
4235          if ( $email ) {
4236              $email_hash = md5( strtolower( trim( $email ) ) );
4237          }
4238      }
4239  
4240      if ( $email_hash ) {
4241          $args['found_avatar'] = true;
4242          $gravatar_server      = hexdec( $email_hash[0] ) % 3;
4243      } else {
4244          $gravatar_server = rand( 0, 2 );
4245      }
4246  
4247      $url_args = array(
4248          's' => $args['size'],
4249          'd' => $args['default'],
4250          'f' => $args['force_default'] ? 'y' : false,
4251          'r' => $args['rating'],
4252      );
4253  
4254      if ( is_ssl() ) {
4255          $url = 'https://secure.gravatar.com/avatar/' . $email_hash;
4256      } else {
4257          $url = sprintf( 'http://%d.gravatar.com/avatar/%s', $gravatar_server, $email_hash );
4258      }
4259  
4260      $url = add_query_arg(
4261          rawurlencode_deep( array_filter( $url_args ) ),
4262          set_url_scheme( $url, $args['scheme'] )
4263      );
4264  
4265      /**
4266       * Filters the avatar URL.
4267       *
4268       * @since 4.2.0
4269       *
4270       * @param string $url         The URL of the avatar.
4271       * @param mixed  $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash,
4272       *                            user email, WP_User object, WP_Post object, or WP_Comment object.
4273       * @param array  $args        Arguments passed to get_avatar_data(), after processing.
4274       */
4275      $args['url'] = apply_filters( 'get_avatar_url', $url, $id_or_email, $args );
4276  
4277      /**
4278       * Filters the avatar data.
4279       *
4280       * @since 4.2.0
4281       *
4282       * @param array $args        Arguments passed to get_avatar_data(), after processing.
4283       * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash,
4284       *                           user email, WP_User object, WP_Post object, or WP_Comment object.
4285       */
4286      return apply_filters( 'get_avatar_data', $args, $id_or_email );
4287  }
4288  
4289  /**
4290   * Retrieves the URL of a file in the theme.
4291   *
4292   * Searches in the stylesheet directory before the template directory so themes
4293   * which inherit from a parent theme can just override one file.
4294   *
4295   * @since 4.7.0
4296   *
4297   * @param string $file Optional. File to search for in the stylesheet directory.
4298   * @return string The URL of the file.
4299   */
4300  function get_theme_file_uri( $file = '' ) {
4301      $file = ltrim( $file, '/' );
4302  
4303      if ( empty( $file ) ) {
4304          $url = get_stylesheet_directory_uri();
4305      } elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
4306          $url = get_stylesheet_directory_uri() . '/' . $file;
4307      } else {
4308          $url = get_template_directory_uri() . '/' . $file;
4309      }
4310  
4311      /**
4312       * Filters the URL to a file in the theme.
4313       *
4314       * @since 4.7.0
4315       *
4316       * @param string $url  The file URL.
4317       * @param string $file The requested file to search for.
4318       */
4319      return apply_filters( 'theme_file_uri', $url, $file );
4320  }
4321  
4322  /**
4323   * Retrieves the URL of a file in the parent theme.
4324   *
4325   * @since 4.7.0
4326   *
4327   * @param string $file Optional. File to return the URL for in the template directory.
4328   * @return string The URL of the file.
4329   */
4330  function get_parent_theme_file_uri( $file = '' ) {
4331      $file = ltrim( $file, '/' );
4332  
4333      if ( empty( $file ) ) {
4334          $url = get_template_directory_uri();
4335      } else {
4336          $url = get_template_directory_uri() . '/' . $file;
4337      }
4338  
4339      /**
4340       * Filters the URL to a file in the parent theme.
4341       *
4342       * @since 4.7.0
4343       *
4344       * @param string $url  The file URL.
4345       * @param string $file The requested file to search for.
4346       */
4347      return apply_filters( 'parent_theme_file_uri', $url, $file );
4348  }
4349  
4350  /**
4351   * Retrieves the path of a file in the theme.
4352   *
4353   * Searches in the stylesheet directory before the template directory so themes
4354   * which inherit from a parent theme can just override one file.
4355   *
4356   * @since 4.7.0
4357   *
4358   * @param string $file Optional. File to search for in the stylesheet directory.
4359   * @return string The path of the file.
4360   */
4361  function get_theme_file_path( $file = '' ) {
4362      $file = ltrim( $file, '/' );
4363  
4364      if ( empty( $file ) ) {
4365          $path = get_stylesheet_directory();
4366      } elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
4367          $path = get_stylesheet_directory() . '/' . $file;
4368      } else {
4369          $path = get_template_directory() . '/' . $file;
4370      }
4371  
4372      /**
4373       * Filters the path to a file in the theme.
4374       *
4375       * @since 4.7.0
4376       *
4377       * @param string $path The file path.
4378       * @param string $file The requested file to search for.
4379       */
4380      return apply_filters( 'theme_file_path', $path, $file );
4381  }
4382  
4383  /**
4384   * Retrieves the path of a file in the parent theme.
4385   *
4386   * @since 4.7.0
4387   *
4388   * @param string $file Optional. File to return the path for in the template directory.
4389   * @return string The path of the file.
4390   */
4391  function get_parent_theme_file_path( $file = '' ) {
4392      $file = ltrim( $file, '/' );
4393  
4394      if ( empty( $file ) ) {
4395          $path = get_template_directory();
4396      } else {
4397          $path = get_template_directory() . '/' . $file;
4398      }
4399  
4400      /**
4401       * Filters the path to a file in the parent theme.
4402       *
4403       * @since 4.7.0
4404       *
4405       * @param string $path The file path.
4406       * @param string $file The requested file to search for.
4407       */
4408      return apply_filters( 'parent_theme_file_path', $path, $file );
4409  }
4410  
4411  /**
4412   * Retrieves the URL to the privacy policy page.
4413   *
4414   * @since 4.9.6
4415   *
4416   * @return string The URL to the privacy policy page. Empty string if it doesn't exist.
4417   */
4418  function get_privacy_policy_url() {
4419      $url            = '';
4420      $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
4421  
4422      if ( ! empty( $policy_page_id ) && get_post_status( $policy_page_id ) === 'publish' ) {
4423          $url = (string) get_permalink( $policy_page_id );
4424      }
4425  
4426      /**
4427       * Filters the URL of the privacy policy page.
4428       *
4429       * @since 4.9.6
4430       *
4431       * @param string $url            The URL to the privacy policy page. Empty string
4432       *                               if it doesn't exist.
4433       * @param int    $policy_page_id The ID of privacy policy page.
4434       */
4435      return apply_filters( 'privacy_policy_url', $url, $policy_page_id );
4436  }
4437  
4438  /**
4439   * Displays the privacy policy link with formatting, when applicable.
4440   *
4441   * @since 4.9.6
4442   *
4443   * @param string $before Optional. Display before privacy policy link. Default empty.
4444   * @param string $after  Optional. Display after privacy policy link. Default empty.
4445   */
4446  function the_privacy_policy_link( $before = '', $after = '' ) {
4447      echo get_the_privacy_policy_link( $before, $after );
4448  }
4449  
4450  /**
4451   * Returns the privacy policy link with formatting, when applicable.
4452   *
4453   * @since 4.9.6
4454   *
4455   * @param string $before Optional. Display before privacy policy link. Default empty.
4456   * @param string $after  Optional. Display after privacy policy link. Default empty.
4457   * @return string Markup for the link and surrounding elements. Empty string if it
4458   *                doesn't exist.
4459   */
4460  function get_the_privacy_policy_link( $before = '', $after = '' ) {
4461      $link               = '';
4462      $privacy_policy_url = get_privacy_policy_url();
4463      $policy_page_id     = (int) get_option( 'wp_page_for_privacy_policy' );
4464      $page_title         = ( $policy_page_id ) ? get_the_title( $policy_page_id ) : '';
4465  
4466      if ( $privacy_policy_url && $page_title ) {
4467          $link = sprintf(
4468              '<a class="privacy-policy-link" href="%s">%s</a>',
4469              esc_url( $privacy_policy_url ),
4470              esc_html( $page_title )
4471          );
4472      }
4473  
4474      /**
4475       * Filters the privacy policy link.
4476       *
4477       * @since 4.9.6
4478       *
4479       * @param string $link               The privacy policy link. Empty string if it
4480       *                                   doesn't exist.
4481       * @param string $privacy_policy_url The URL of the privacy policy. Empty string
4482       *                                   if it doesn't exist.
4483       */
4484      $link = apply_filters( 'the_privacy_policy_link', $link, $privacy_policy_url );
4485  
4486      if ( $link ) {
4487          return $before . $link . $after;
4488      }
4489  
4490      return '';
4491  }


Generated : Mon Aug 3 08:20:02 2020 Cross-referenced by PHPXref