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