35 * {@see 'user_trailingslashit'} filter. Will remove trailing slash from string, if |
35 * {@see 'user_trailingslashit'} filter. Will remove trailing slash from string, if |
36 * site is not set to have them. |
36 * site is not set to have them. |
37 * |
37 * |
38 * @since 2.2.0 |
38 * @since 2.2.0 |
39 * |
39 * |
40 * @global WP_Rewrite $wp_rewrite |
40 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
41 * |
41 * |
42 * @param string $string URL with or without a trailing slash. |
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) |
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. |
44 * for use in the filter. Default empty string. |
45 * @return string The URL with the trailing slash appended or stripped. |
45 * @return string The URL with the trailing slash appended or stripped. |
129 '%category%', |
128 '%category%', |
130 '%author%', |
129 '%author%', |
131 $leavename ? '' : '%pagename%', |
130 $leavename ? '' : '%pagename%', |
132 ); |
131 ); |
133 |
132 |
134 if ( is_object( $post ) && isset( $post->filter ) && 'sample' == $post->filter ) { |
133 if ( is_object( $post ) && isset( $post->filter ) && 'sample' === $post->filter ) { |
135 $sample = true; |
134 $sample = true; |
136 } else { |
135 } else { |
137 $post = get_post( $post ); |
136 $post = get_post( $post ); |
138 $sample = false; |
137 $sample = false; |
139 } |
138 } |
140 |
139 |
141 if ( empty( $post->ID ) ) { |
140 if ( empty( $post->ID ) ) { |
142 return false; |
141 return false; |
143 } |
142 } |
144 |
143 |
145 if ( $post->post_type == 'page' ) { |
144 if ( 'page' === $post->post_type ) { |
146 return get_page_link( $post, $leavename, $sample ); |
145 return get_page_link( $post, $leavename, $sample ); |
147 } elseif ( $post->post_type == 'attachment' ) { |
146 } elseif ( 'attachment' === $post->post_type ) { |
148 return get_attachment_link( $post, $leavename ); |
147 return get_attachment_link( $post, $leavename ); |
149 } elseif ( in_array( $post->post_type, get_post_types( array( '_builtin' => false ) ) ) ) { |
148 } elseif ( in_array( $post->post_type, get_post_types( array( '_builtin' => false ) ), true ) ) { |
150 return get_post_permalink( $post, $leavename, $sample ); |
149 return get_post_permalink( $post, $leavename, $sample ); |
151 } |
150 } |
152 |
151 |
153 $permalink = get_option( 'permalink_structure' ); |
152 $permalink = get_option( 'permalink_structure' ); |
154 |
153 |
163 * @param WP_Post $post The post in question. |
162 * @param WP_Post $post The post in question. |
164 * @param bool $leavename Whether to keep the post name. |
163 * @param bool $leavename Whether to keep the post name. |
165 */ |
164 */ |
166 $permalink = apply_filters( 'pre_post_link', $permalink, $post, $leavename ); |
165 $permalink = apply_filters( 'pre_post_link', $permalink, $post, $leavename ); |
167 |
166 |
168 if ( '' != $permalink && ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ) ) ) { |
167 if ( $permalink && ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ), true ) ) { |
169 $unixtime = strtotime( $post->post_date ); |
|
170 |
168 |
171 $category = ''; |
169 $category = ''; |
172 if ( strpos( $permalink, '%category%' ) !== false ) { |
170 if ( strpos( $permalink, '%category%' ) !== false ) { |
173 $cats = get_the_category( $post->ID ); |
171 $cats = get_the_category( $post->ID ); |
174 if ( $cats ) { |
172 if ( $cats ) { |
194 $category = $category_object->slug; |
192 $category = $category_object->slug; |
195 if ( $category_object->parent ) { |
193 if ( $category_object->parent ) { |
196 $category = get_category_parents( $category_object->parent, false, '/', true ) . $category; |
194 $category = get_category_parents( $category_object->parent, false, '/', true ) . $category; |
197 } |
195 } |
198 } |
196 } |
199 // show default category in permalinks, without |
197 // Show default category in permalinks, |
200 // having to assign it explicitly |
198 // without having to assign it explicitly. |
201 if ( empty( $category ) ) { |
199 if ( empty( $category ) ) { |
202 $default_category = get_term( get_option( 'default_category' ), 'category' ); |
200 $default_category = get_term( get_option( 'default_category' ), 'category' ); |
203 if ( $default_category && ! is_wp_error( $default_category ) ) { |
201 if ( $default_category && ! is_wp_error( $default_category ) ) { |
204 $category = $default_category->slug; |
202 $category = $default_category->slug; |
205 } |
203 } |
250 /** |
252 /** |
251 * Retrieves the permalink for a post of a custom post type. |
253 * Retrieves the permalink for a post of a custom post type. |
252 * |
254 * |
253 * @since 3.0.0 |
255 * @since 3.0.0 |
254 * |
256 * |
255 * @global WP_Rewrite $wp_rewrite |
257 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
256 * |
258 * |
257 * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. |
259 * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. |
258 * @param bool $leavename Optional, defaults to false. Whether to keep post name. Default false. |
260 * @param bool $leavename Optional. Whether to keep post name. Default false. |
259 * @param bool $sample Optional, defaults to false. Is it a sample permalink. Default false. |
261 * @param bool $sample Optional. Is it a sample permalink. Default false. |
260 * @return string|WP_Error The post permalink. |
262 * @return string|WP_Error The post permalink. |
261 */ |
263 */ |
262 function get_post_permalink( $id = 0, $leavename = false, $sample = false ) { |
264 function get_post_permalink( $id = 0, $leavename = false, $sample = false ) { |
263 global $wp_rewrite; |
265 global $wp_rewrite; |
264 |
266 |
270 |
272 |
271 $post_link = $wp_rewrite->get_extra_permastruct( $post->post_type ); |
273 $post_link = $wp_rewrite->get_extra_permastruct( $post->post_type ); |
272 |
274 |
273 $slug = $post->post_name; |
275 $slug = $post->post_name; |
274 |
276 |
275 $draft_or_pending = get_post_status( $post ) && in_array( get_post_status( $post ), array( 'draft', 'pending', 'auto-draft', 'future' ) ); |
277 $draft_or_pending = get_post_status( $post ) && in_array( get_post_status( $post ), array( 'draft', 'pending', 'auto-draft', 'future' ), true ); |
276 |
278 |
277 $post_type = get_post_type_object( $post->post_type ); |
279 $post_type = get_post_type_object( $post->post_type ); |
278 |
280 |
279 if ( $post_type->hierarchical ) { |
281 if ( $post_type->hierarchical ) { |
280 $slug = get_page_uri( $post ); |
282 $slug = get_page_uri( $post ); |
366 function _get_page_link( $post = false, $leavename = false, $sample = false ) { |
368 function _get_page_link( $post = false, $leavename = false, $sample = false ) { |
367 global $wp_rewrite; |
369 global $wp_rewrite; |
368 |
370 |
369 $post = get_post( $post ); |
371 $post = get_post( $post ); |
370 |
372 |
371 $draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ); |
373 $draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ), true ); |
372 |
374 |
373 $link = $wp_rewrite->get_page_permastruct(); |
375 $link = $wp_rewrite->get_page_permastruct(); |
374 |
376 |
375 if ( ! empty( $link ) && ( ( isset( $post->post_status ) && ! $draft_or_pending ) || $sample ) ) { |
377 if ( ! empty( $link ) && ( ( isset( $post->post_status ) && ! $draft_or_pending ) || $sample ) ) { |
376 if ( ! $leavename ) { |
378 if ( ! $leavename ) { |
412 |
414 |
413 $link = false; |
415 $link = false; |
414 |
416 |
415 $post = get_post( $post ); |
417 $post = get_post( $post ); |
416 $parent = ( $post->post_parent > 0 && $post->post_parent != $post->ID ) ? get_post( $post->post_parent ) : false; |
418 $parent = ( $post->post_parent > 0 && $post->post_parent != $post->ID ) ? get_post( $post->post_parent ) : false; |
417 if ( $parent && ! in_array( $parent->post_type, get_post_types() ) ) { |
419 if ( $parent && ! in_array( $parent->post_type, get_post_types(), true ) ) { |
418 $parent = false; |
420 $parent = false; |
419 } |
421 } |
420 |
422 |
421 if ( $wp_rewrite->using_permalinks() && $parent ) { |
423 if ( $wp_rewrite->using_permalinks() && $parent ) { |
422 if ( 'page' == $parent->post_type ) { |
424 if ( 'page' === $parent->post_type ) { |
423 $parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front |
425 $parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front. |
424 } else { |
426 } else { |
425 $parentlink = get_permalink( $post->post_parent ); |
427 $parentlink = get_permalink( $post->post_parent ); |
426 } |
428 } |
427 |
429 |
428 if ( is_numeric( $post->post_name ) || false !== strpos( get_option( 'permalink_structure' ), '%category%' ) ) { |
430 if ( is_numeric( $post->post_name ) || false !== strpos( get_option( 'permalink_structure' ), '%category%' ) ) { |
429 $name = 'attachment/' . $post->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker |
431 $name = 'attachment/' . $post->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker. |
430 } else { |
432 } else { |
431 $name = $post->post_name; |
433 $name = $post->post_name; |
432 } |
434 } |
433 |
435 |
434 if ( strpos( $parentlink, '?' ) === false ) { |
436 if ( strpos( $parentlink, '?' ) === false ) { |
534 /** |
536 /** |
535 * Retrieves the permalink for the day archives with year and month. |
537 * Retrieves the permalink for the day archives with year and month. |
536 * |
538 * |
537 * @since 1.0.0 |
539 * @since 1.0.0 |
538 * |
540 * |
539 * @global WP_Rewrite $wp_rewrite |
541 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
540 * |
542 * |
541 * @param bool|int $year False for current year. Integer of year. |
543 * @param int|false $year Integer of year. False for current year. |
542 * @param bool|int $month False for current month. Integer of month. |
544 * @param int|false $month Integer of month. False for current month. |
543 * @param bool|int $day False for current day. Integer of day. |
545 * @param int|false $day Integer of day. False for current day. |
544 * @return string The permalink for the specified day, month, and year archive. |
546 * @return string The permalink for the specified day, month, and year archive. |
545 */ |
547 */ |
546 function get_day_link( $year, $month, $day ) { |
548 function get_day_link( $year, $month, $day ) { |
547 global $wp_rewrite; |
549 global $wp_rewrite; |
548 if ( ! $year ) { |
550 if ( ! $year ) { |
582 * Displays the permalink for the feed type. |
584 * Displays the permalink for the feed type. |
583 * |
585 * |
584 * @since 3.0.0 |
586 * @since 3.0.0 |
585 * |
587 * |
586 * @param string $anchor The link's anchor text. |
588 * @param string $anchor The link's anchor text. |
587 * @param string $feed Optional. Feed type. Default empty. |
589 * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
|
590 * Default is the value of get_default_feed(). |
588 */ |
591 */ |
589 function the_feed_link( $anchor, $feed = '' ) { |
592 function the_feed_link( $anchor, $feed = '' ) { |
590 $link = '<a href="' . esc_url( get_feed_link( $feed ) ) . '">' . $anchor . '</a>'; |
593 $link = '<a href="' . esc_url( get_feed_link( $feed ) ) . '">' . $anchor . '</a>'; |
591 |
594 |
592 /** |
595 /** |
593 * Filters the feed link anchor tag. |
596 * Filters the feed link anchor tag. |
594 * |
597 * |
595 * @since 3.0.0 |
598 * @since 3.0.0 |
596 * |
599 * |
597 * @param string $link The complete anchor tag for a feed link. |
600 * @param string $link The complete anchor tag for a feed link. |
598 * @param string $feed The feed type, or an empty string for the |
601 * @param string $feed The feed type. Possible values include 'rss2', 'atom', |
599 * default feed type. |
602 * or an empty string for the default feed type. |
600 */ |
603 */ |
601 echo apply_filters( 'the_feed_link', $link, $feed ); |
604 echo apply_filters( 'the_feed_link', $link, $feed ); |
602 } |
605 } |
603 |
606 |
604 /** |
607 /** |
605 * Retrieves the permalink for the feed type. |
608 * Retrieves the permalink for the feed type. |
606 * |
609 * |
607 * @since 1.5.0 |
610 * @since 1.5.0 |
608 * |
611 * |
609 * @global WP_Rewrite $wp_rewrite |
612 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
610 * |
613 * |
611 * @param string $feed Optional. Feed type. Default empty. |
614 * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
|
615 * Default is the value of get_default_feed(). |
612 * @return string The feed permalink. |
616 * @return string The feed permalink. |
613 */ |
617 */ |
614 function get_feed_link( $feed = '' ) { |
618 function get_feed_link( $feed = '' ) { |
615 global $wp_rewrite; |
619 global $wp_rewrite; |
616 |
620 |
617 $permalink = $wp_rewrite->get_feed_permastruct(); |
621 $permalink = $wp_rewrite->get_feed_permastruct(); |
618 if ( '' != $permalink ) { |
622 |
|
623 if ( '' !== $permalink ) { |
619 if ( false !== strpos( $feed, 'comments_' ) ) { |
624 if ( false !== strpos( $feed, 'comments_' ) ) { |
620 $feed = str_replace( 'comments_', '', $feed ); |
625 $feed = str_replace( 'comments_', '', $feed ); |
621 $permalink = $wp_rewrite->get_comment_feed_permastruct(); |
626 $permalink = $wp_rewrite->get_comment_feed_permastruct(); |
622 } |
627 } |
623 |
628 |
644 * Filters the feed type permalink. |
649 * Filters the feed type permalink. |
645 * |
650 * |
646 * @since 1.5.0 |
651 * @since 1.5.0 |
647 * |
652 * |
648 * @param string $output The feed permalink. |
653 * @param string $output The feed permalink. |
649 * @param string $feed Feed type. |
654 * @param string $feed The feed type. Possible values include 'rss2', 'atom', |
|
655 * or an empty string for the default feed type. |
650 */ |
656 */ |
651 return apply_filters( 'feed_link', $output, $feed ); |
657 return apply_filters( 'feed_link', $output, $feed ); |
652 } |
658 } |
653 |
659 |
654 /** |
660 /** |
655 * Retrieves the permalink for the post comments feed. |
661 * Retrieves the permalink for the post comments feed. |
656 * |
662 * |
657 * @since 2.2.0 |
663 * @since 2.2.0 |
658 * |
664 * |
659 * @param int $post_id Optional. Post ID. Default is the ID of the global `$post`. |
665 * @param int $post_id Optional. Post ID. Default is the ID of the global `$post`. |
660 * @param string $feed Optional. Feed type. Default empty. |
666 * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
|
667 * Default is the value of get_default_feed(). |
661 * @return string The permalink for the comments feed for the given post. |
668 * @return string The permalink for the comments feed for the given post. |
662 */ |
669 */ |
663 function get_post_comments_feed_link( $post_id = 0, $feed = '' ) { |
670 function get_post_comments_feed_link( $post_id = 0, $feed = '' ) { |
664 $post_id = absint( $post_id ); |
671 $post_id = absint( $post_id ); |
665 |
672 |
672 } |
679 } |
673 |
680 |
674 $post = get_post( $post_id ); |
681 $post = get_post( $post_id ); |
675 $unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent; |
682 $unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent; |
676 |
683 |
677 if ( '' != get_option( 'permalink_structure' ) ) { |
684 if ( get_option( 'permalink_structure' ) ) { |
678 if ( 'page' == get_option( 'show_on_front' ) && $post_id == get_option( 'page_on_front' ) ) { |
685 if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post_id ) { |
679 $url = _get_page_link( $post_id ); |
686 $url = _get_page_link( $post_id ); |
680 } else { |
687 } else { |
681 $url = get_permalink( $post_id ); |
688 $url = get_permalink( $post_id ); |
682 } |
689 } |
683 |
690 |
684 if ( $unattached ) { |
691 if ( $unattached ) { |
685 $url = home_url( '/feed/' ); |
692 $url = home_url( '/feed/' ); |
686 if ( $feed !== get_default_feed() ) { |
693 if ( get_default_feed() !== $feed ) { |
687 $url .= "$feed/"; |
694 $url .= "$feed/"; |
688 } |
695 } |
689 $url = add_query_arg( 'attachment_id', $post_id, $url ); |
696 $url = add_query_arg( 'attachment_id', $post_id, $url ); |
690 } else { |
697 } else { |
691 $url = trailingslashit( $url ) . 'feed'; |
698 $url = trailingslashit( $url ) . 'feed'; |
692 if ( $feed != get_default_feed() ) { |
699 if ( get_default_feed() != $feed ) { |
693 $url .= "/$feed"; |
700 $url .= "/$feed"; |
694 } |
701 } |
695 $url = user_trailingslashit( $url, 'single_feed' ); |
702 $url = user_trailingslashit( $url, 'single_feed' ); |
696 } |
703 } |
697 } else { |
704 } else { |
741 * |
748 * |
742 * @since 2.5.0 |
749 * @since 2.5.0 |
743 * |
750 * |
744 * @param string $link_text Optional. Descriptive link text. Default 'Comments Feed'. |
751 * @param string $link_text Optional. Descriptive link text. Default 'Comments Feed'. |
745 * @param int $post_id Optional. Post ID. Default is the ID of the global `$post`. |
752 * @param int $post_id Optional. Post ID. Default is the ID of the global `$post`. |
746 * @param string $feed Optional. Feed format. Default empty. |
753 * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
|
754 * Default is the value of get_default_feed(). |
747 */ |
755 */ |
748 function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) { |
756 function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) { |
749 $url = get_post_comments_feed_link( $post_id, $feed ); |
757 $url = get_post_comments_feed_link( $post_id, $feed ); |
750 if ( empty( $link_text ) ) { |
758 if ( empty( $link_text ) ) { |
751 $link_text = __( 'Comments Feed' ); |
759 $link_text = __( 'Comments Feed' ); |
771 * can be requested or left blank to get the default feed. |
780 * can be requested or left blank to get the default feed. |
772 * |
781 * |
773 * @since 2.5.0 |
782 * @since 2.5.0 |
774 * |
783 * |
775 * @param int $author_id Author ID. |
784 * @param int $author_id Author ID. |
776 * @param string $feed Optional. Feed type. Default empty. |
785 * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
|
786 * Default is the value of get_default_feed(). |
777 * @return string Link to the feed for the author specified by $author_id. |
787 * @return string Link to the feed for the author specified by $author_id. |
778 */ |
788 */ |
779 function get_author_feed_link( $author_id, $feed = '' ) { |
789 function get_author_feed_link( $author_id, $feed = '' ) { |
780 $author_id = (int) $author_id; |
790 $author_id = (int) $author_id; |
781 $permalink_structure = get_option( 'permalink_structure' ); |
791 $permalink_structure = get_option( 'permalink_structure' ); |
782 |
792 |
783 if ( empty( $feed ) ) { |
793 if ( empty( $feed ) ) { |
784 $feed = get_default_feed(); |
794 $feed = get_default_feed(); |
785 } |
795 } |
786 |
796 |
787 if ( '' == $permalink_structure ) { |
797 if ( ! $permalink_structure ) { |
788 $link = home_url( "?feed=$feed&author=" . $author_id ); |
798 $link = home_url( "?feed=$feed&author=" . $author_id ); |
789 } else { |
799 } else { |
790 $link = get_author_posts_url( $author_id ); |
800 $link = get_author_posts_url( $author_id ); |
791 if ( $feed == get_default_feed() ) { |
801 if ( get_default_feed() == $feed ) { |
792 $feed_link = 'feed'; |
802 $feed_link = 'feed'; |
793 } else { |
803 } else { |
794 $feed_link = "feed/$feed"; |
804 $feed_link = "feed/$feed"; |
795 } |
805 } |
796 |
806 |
817 * can be requested or left blank to get the default feed. |
827 * can be requested or left blank to get the default feed. |
818 * |
828 * |
819 * @since 2.5.0 |
829 * @since 2.5.0 |
820 * |
830 * |
821 * @param int $cat_id Category ID. |
831 * @param int $cat_id Category ID. |
822 * @param string $feed Optional. Feed type. Default empty. |
832 * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
|
833 * Default is the value of get_default_feed(). |
823 * @return string Link to the feed for the category specified by $cat_id. |
834 * @return string Link to the feed for the category specified by $cat_id. |
824 */ |
835 */ |
825 function get_category_feed_link( $cat_id, $feed = '' ) { |
836 function get_category_feed_link( $cat_id, $feed = '' ) { |
826 return get_term_feed_link( $cat_id, 'category', $feed ); |
837 return get_term_feed_link( $cat_id, 'category', $feed ); |
827 } |
838 } |
834 * |
845 * |
835 * @since 3.0.0 |
846 * @since 3.0.0 |
836 * |
847 * |
837 * @param int $term_id Term ID. |
848 * @param int $term_id Term ID. |
838 * @param string $taxonomy Optional. Taxonomy of `$term_id`. Default 'category'. |
849 * @param string $taxonomy Optional. Taxonomy of `$term_id`. Default 'category'. |
839 * @param string $feed Optional. Feed type. Default empty. |
850 * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
|
851 * Default is the value of get_default_feed(). |
840 * @return string|false Link to the feed for the term specified by $term_id and $taxonomy. |
852 * @return string|false Link to the feed for the term specified by $term_id and $taxonomy. |
841 */ |
853 */ |
842 function get_term_feed_link( $term_id, $taxonomy = 'category', $feed = '' ) { |
854 function get_term_feed_link( $term_id, $taxonomy = 'category', $feed = '' ) { |
843 $term_id = (int) $term_id; |
855 $term_id = (int) $term_id; |
844 |
856 |
852 $feed = get_default_feed(); |
864 $feed = get_default_feed(); |
853 } |
865 } |
854 |
866 |
855 $permalink_structure = get_option( 'permalink_structure' ); |
867 $permalink_structure = get_option( 'permalink_structure' ); |
856 |
868 |
857 if ( '' == $permalink_structure ) { |
869 if ( ! $permalink_structure ) { |
858 if ( 'category' == $taxonomy ) { |
870 if ( 'category' === $taxonomy ) { |
859 $link = home_url( "?feed=$feed&cat=$term_id" ); |
871 $link = home_url( "?feed=$feed&cat=$term_id" ); |
860 } elseif ( 'post_tag' == $taxonomy ) { |
872 } elseif ( 'post_tag' === $taxonomy ) { |
861 $link = home_url( "?feed=$feed&tag=$term->slug" ); |
873 $link = home_url( "?feed=$feed&tag=$term->slug" ); |
862 } else { |
874 } else { |
863 $t = get_taxonomy( $taxonomy ); |
875 $t = get_taxonomy( $taxonomy ); |
864 $link = home_url( "?feed=$feed&$t->query_var=$term->slug" ); |
876 $link = home_url( "?feed=$feed&$t->query_var=$term->slug" ); |
865 } |
877 } |
866 } else { |
878 } else { |
867 $link = get_term_link( $term_id, $term->taxonomy ); |
879 $link = get_term_link( $term_id, $term->taxonomy ); |
868 if ( $feed == get_default_feed() ) { |
880 if ( get_default_feed() == $feed ) { |
869 $feed_link = 'feed'; |
881 $feed_link = 'feed'; |
870 } else { |
882 } else { |
871 $feed_link = "feed/$feed"; |
883 $feed_link = "feed/$feed"; |
872 } |
884 } |
873 |
885 |
874 $link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' ); |
886 $link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' ); |
875 } |
887 } |
876 |
888 |
877 if ( 'category' == $taxonomy ) { |
889 if ( 'category' === $taxonomy ) { |
878 /** |
890 /** |
879 * Filters the category feed link. |
891 * Filters the category feed link. |
880 * |
892 * |
881 * @since 1.5.1 |
893 * @since 1.5.1 |
882 * |
894 * |
883 * @param string $link The category feed link. |
895 * @param string $link The category feed link. |
884 * @param string $feed Feed type. |
896 * @param string $feed Feed type. Possible values include 'rss2', 'atom'. |
885 */ |
897 */ |
886 $link = apply_filters( 'category_feed_link', $link, $feed ); |
898 $link = apply_filters( 'category_feed_link', $link, $feed ); |
887 } elseif ( 'post_tag' == $taxonomy ) { |
899 } elseif ( 'post_tag' === $taxonomy ) { |
888 /** |
900 /** |
889 * Filters the post tag feed link. |
901 * Filters the post tag feed link. |
890 * |
902 * |
891 * @since 2.3.0 |
903 * @since 2.3.0 |
892 * |
904 * |
893 * @param string $link The tag feed link. |
905 * @param string $link The tag feed link. |
894 * @param string $feed Feed type. |
906 * @param string $feed Feed type. Possible values include 'rss2', 'atom'. |
895 */ |
907 */ |
896 $link = apply_filters( 'tag_feed_link', $link, $feed ); |
908 $link = apply_filters( 'tag_feed_link', $link, $feed ); |
897 } else { |
909 } else { |
898 /** |
910 /** |
899 * Filters the feed link for a taxonomy other than 'category' or 'post_tag'. |
911 * Filters the feed link for a taxonomy other than 'category' or 'post_tag'. |
900 * |
912 * |
901 * @since 3.0.0 |
913 * @since 3.0.0 |
902 * |
914 * |
903 * @param string $link The taxonomy feed link. |
915 * @param string $link The taxonomy feed link. |
904 * @param string $feed Feed type. |
916 * @param string $feed Feed type. Possible values include 'rss2', 'atom'. |
905 * @param string $taxonomy The taxonomy name. |
917 * @param string $taxonomy The taxonomy name. |
906 */ |
918 */ |
907 $link = apply_filters( 'taxonomy_feed_link', $link, $feed, $taxonomy ); |
919 $link = apply_filters( 'taxonomy_feed_link', $link, $feed, $taxonomy ); |
908 } |
920 } |
909 |
921 |
914 * Retrieves the permalink for a tag feed. |
926 * Retrieves the permalink for a tag feed. |
915 * |
927 * |
916 * @since 2.3.0 |
928 * @since 2.3.0 |
917 * |
929 * |
918 * @param int $tag_id Tag ID. |
930 * @param int $tag_id Tag ID. |
919 * @param string $feed Optional. Feed type. Default empty. |
931 * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
|
932 * Default is the value of get_default_feed(). |
920 * @return string The feed permalink for the given tag. |
933 * @return string The feed permalink for the given tag. |
921 */ |
934 */ |
922 function get_tag_feed_link( $tag_id, $feed = '' ) { |
935 function get_tag_feed_link( $tag_id, $feed = '' ) { |
923 return get_term_feed_link( $tag_id, 'post_tag', $feed ); |
936 return get_term_feed_link( $tag_id, 'post_tag', $feed ); |
924 } |
937 } |
1025 /** |
1038 /** |
1026 * Displays or retrieves the edit term link with formatting. |
1039 * Displays or retrieves the edit term link with formatting. |
1027 * |
1040 * |
1028 * @since 3.1.0 |
1041 * @since 3.1.0 |
1029 * |
1042 * |
1030 * @param string $link Optional. Anchor text. Default empty. |
1043 * @param string $link Optional. Anchor text. If empty, default is 'Edit This'. Default empty. |
1031 * @param string $before Optional. Display before edit link. Default empty. |
1044 * @param string $before Optional. Display before edit link. Default empty. |
1032 * @param string $after Optional. Display after edit link. Default empty. |
1045 * @param string $after Optional. Display after edit link. Default empty. |
1033 * @param object $term Optional. Term object. If null, the queried object will be inspected. Default null. |
1046 * @param WP_Term $term Optional. Term object. If null, the queried object will be inspected. Default null. |
1034 * @param bool $echo Optional. Whether or not to echo the return. Default true. |
1047 * @param bool $echo Optional. Whether or not to echo the return. Default true. |
1035 * @return string|void HTML content. |
1048 * @return string|void HTML content. |
1036 */ |
1049 */ |
1037 function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) { |
1050 function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) { |
1038 if ( is_null( $term ) ) { |
1051 if ( is_null( $term ) ) { |
1039 $term = get_queried_object(); |
1052 $term = get_queried_object(); |
1115 /** |
1128 /** |
1116 * Retrieves the permalink for the search results feed. |
1129 * Retrieves the permalink for the search results feed. |
1117 * |
1130 * |
1118 * @since 2.5.0 |
1131 * @since 2.5.0 |
1119 * |
1132 * |
1120 * @global WP_Rewrite $wp_rewrite |
1133 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
1121 * |
1134 * |
1122 * @param string $search_query Optional. Search query. Default empty. |
1135 * @param string $search_query Optional. Search query. Default empty. |
1123 * @param string $feed Optional. Feed type. Default empty. |
1136 * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
|
1137 * Default is the value of get_default_feed(). |
1124 * @return string The search results feed permalink. |
1138 * @return string The search results feed permalink. |
1125 */ |
1139 */ |
1126 function get_search_feed_link( $search_query = '', $feed = '' ) { |
1140 function get_search_feed_link( $search_query = '', $feed = '' ) { |
1127 global $wp_rewrite; |
1141 global $wp_rewrite; |
1128 $link = get_search_link( $search_query ); |
1142 $link = get_search_link( $search_query ); |
1144 * Filters the search feed link. |
1158 * Filters the search feed link. |
1145 * |
1159 * |
1146 * @since 2.5.0 |
1160 * @since 2.5.0 |
1147 * |
1161 * |
1148 * @param string $link Search feed link. |
1162 * @param string $link Search feed link. |
1149 * @param string $feed Feed type. |
1163 * @param string $feed Feed type. Possible values include 'rss2', 'atom'. |
1150 * @param string $type The search type. One of 'posts' or 'comments'. |
1164 * @param string $type The search type. One of 'posts' or 'comments'. |
1151 */ |
1165 */ |
1152 return apply_filters( 'search_feed_link', $link, $feed, 'posts' ); |
1166 return apply_filters( 'search_feed_link', $link, $feed, 'posts' ); |
1153 } |
1167 } |
1154 |
1168 |
1155 /** |
1169 /** |
1156 * Retrieves the permalink for the search results comments feed. |
1170 * Retrieves the permalink for the search results comments feed. |
1157 * |
1171 * |
1158 * @since 2.5.0 |
1172 * @since 2.5.0 |
1159 * |
1173 * |
1160 * @global WP_Rewrite $wp_rewrite |
1174 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
1161 * |
1175 * |
1162 * @param string $search_query Optional. Search query. Default empty. |
1176 * @param string $search_query Optional. Search query. Default empty. |
1163 * @param string $feed Optional. Feed type. Default empty. |
1177 * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
|
1178 * Default is the value of get_default_feed(). |
1164 * @return string The comments feed search results permalink. |
1179 * @return string The comments feed search results permalink. |
1165 */ |
1180 */ |
1166 function get_search_comments_feed_link( $search_query = '', $feed = '' ) { |
1181 function get_search_comments_feed_link( $search_query = '', $feed = '' ) { |
1167 global $wp_rewrite; |
1182 global $wp_rewrite; |
1168 |
1183 |
1188 * Retrieves the permalink for a post type archive. |
1203 * Retrieves the permalink for a post type archive. |
1189 * |
1204 * |
1190 * @since 3.1.0 |
1205 * @since 3.1.0 |
1191 * @since 4.5.0 Support for posts was added. |
1206 * @since 4.5.0 Support for posts was added. |
1192 * |
1207 * |
1193 * @global WP_Rewrite $wp_rewrite |
1208 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
1194 * |
1209 * |
1195 * @param string $post_type Post type. |
1210 * @param string $post_type Post type. |
1196 * @return string|false The post type archive permalink. |
1211 * @return string|false The post type archive permalink. |
1197 */ |
1212 */ |
1198 function get_post_type_archive_link( $post_type ) { |
1213 function get_post_type_archive_link( $post_type ) { |
1199 global $wp_rewrite; |
1214 global $wp_rewrite; |
1200 if ( ! $post_type_obj = get_post_type_object( $post_type ) ) { |
1215 |
|
1216 $post_type_obj = get_post_type_object( $post_type ); |
|
1217 if ( ! $post_type_obj ) { |
1201 return false; |
1218 return false; |
1202 } |
1219 } |
1203 |
1220 |
1204 if ( 'post' === $post_type ) { |
1221 if ( 'post' === $post_type ) { |
1205 $show_on_front = get_option( 'show_on_front' ); |
1222 $show_on_front = get_option( 'show_on_front' ); |
1206 $page_for_posts = get_option( 'page_for_posts' ); |
1223 $page_for_posts = get_option( 'page_for_posts' ); |
1207 |
1224 |
1208 if ( 'page' == $show_on_front && $page_for_posts ) { |
1225 if ( 'page' === $show_on_front && $page_for_posts ) { |
1209 $link = get_permalink( $page_for_posts ); |
1226 $link = get_permalink( $page_for_posts ); |
1210 } else { |
1227 } else { |
1211 $link = get_home_url(); |
1228 $link = get_home_url(); |
1212 } |
1229 } |
1213 /** This filter is documented in wp-includes/link-template.php */ |
1230 /** This filter is documented in wp-includes/link-template.php */ |
1245 * Retrieves the permalink for a post type archive feed. |
1262 * Retrieves the permalink for a post type archive feed. |
1246 * |
1263 * |
1247 * @since 3.1.0 |
1264 * @since 3.1.0 |
1248 * |
1265 * |
1249 * @param string $post_type Post type |
1266 * @param string $post_type Post type |
1250 * @param string $feed Optional. Feed type. Default empty. |
1267 * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
|
1268 * Default is the value of get_default_feed(). |
1251 * @return string|false The post type feed permalink. |
1269 * @return string|false The post type feed permalink. |
1252 */ |
1270 */ |
1253 function get_post_type_archive_feed_link( $post_type, $feed = '' ) { |
1271 function get_post_type_archive_feed_link( $post_type, $feed = '' ) { |
1254 $default_feed = get_default_feed(); |
1272 $default_feed = get_default_feed(); |
1255 if ( empty( $feed ) ) { |
1273 if ( empty( $feed ) ) { |
1256 $feed = $default_feed; |
1274 $feed = $default_feed; |
1257 } |
1275 } |
1258 |
1276 |
1259 if ( ! $link = get_post_type_archive_link( $post_type ) ) { |
1277 $link = get_post_type_archive_link( $post_type ); |
|
1278 if ( ! $link ) { |
1260 return false; |
1279 return false; |
1261 } |
1280 } |
1262 |
1281 |
1263 $post_type_obj = get_post_type_object( $post_type ); |
1282 $post_type_obj = get_post_type_object( $post_type ); |
1264 if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) && $post_type_obj->rewrite['feeds'] ) { |
1283 if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) && $post_type_obj->rewrite['feeds'] ) { |
1336 * @param string $context Optional. How to output the '&' character. Default '&'. |
1355 * @param string $context Optional. How to output the '&' character. Default '&'. |
1337 * @return string|null The edit post link for the given post. null if the post type is invalid or does |
1356 * @return string|null The edit post link for the given post. null if the post type is invalid or does |
1338 * not allow an editing UI. |
1357 * not allow an editing UI. |
1339 */ |
1358 */ |
1340 function get_edit_post_link( $id = 0, $context = 'display' ) { |
1359 function get_edit_post_link( $id = 0, $context = 'display' ) { |
1341 if ( ! $post = get_post( $id ) ) { |
1360 $post = get_post( $id ); |
|
1361 if ( ! $post ) { |
1342 return; |
1362 return; |
1343 } |
1363 } |
1344 |
1364 |
1345 if ( 'revision' === $post->post_type ) { |
1365 if ( 'revision' === $post->post_type ) { |
1346 $action = ''; |
1366 $action = ''; |
1347 } elseif ( 'display' == $context ) { |
1367 } elseif ( 'display' === $context ) { |
1348 $action = '&action=edit'; |
1368 $action = '&action=edit'; |
1349 } else { |
1369 } else { |
1350 $action = '&action=edit'; |
1370 $action = '&action=edit'; |
1351 } |
1371 } |
1352 |
1372 |
1389 * @param string $after Optional. Display after edit link. Default empty. |
1409 * @param string $after Optional. Display after edit link. Default empty. |
1390 * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. |
1410 * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. |
1391 * @param string $class Optional. Add custom class to link. Default 'post-edit-link'. |
1411 * @param string $class Optional. Add custom class to link. Default 'post-edit-link'. |
1392 */ |
1412 */ |
1393 function edit_post_link( $text = null, $before = '', $after = '', $id = 0, $class = 'post-edit-link' ) { |
1413 function edit_post_link( $text = null, $before = '', $after = '', $id = 0, $class = 'post-edit-link' ) { |
1394 if ( ! $post = get_post( $id ) ) { |
1414 $post = get_post( $id ); |
|
1415 if ( ! $post ) { |
1395 return; |
1416 return; |
1396 } |
1417 } |
1397 |
1418 |
1398 if ( ! $url = get_edit_post_link( $post->ID ) ) { |
1419 $url = get_edit_post_link( $post->ID ); |
|
1420 if ( ! $url ) { |
1399 return; |
1421 return; |
1400 } |
1422 } |
1401 |
1423 |
1402 if ( null === $text ) { |
1424 if ( null === $text ) { |
1403 $text = __( 'Edit This' ); |
1425 $text = __( 'Edit This' ); |
1424 * |
1446 * |
1425 * @since 2.9.0 |
1447 * @since 2.9.0 |
1426 * |
1448 * |
1427 * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. |
1449 * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. |
1428 * @param string $deprecated Not used. |
1450 * @param string $deprecated Not used. |
1429 * @param bool $force_delete Optional. Whether to bypass trash and force deletion. Default false. |
1451 * @param bool $force_delete Optional. Whether to bypass Trash and force deletion. Default false. |
1430 * @return string|void The delete post link URL for the given post. |
1452 * @return string|void The delete post link URL for the given post. |
1431 */ |
1453 */ |
1432 function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) { |
1454 function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) { |
1433 if ( ! empty( $deprecated ) ) { |
1455 if ( ! empty( $deprecated ) ) { |
1434 _deprecated_argument( __FUNCTION__, '3.0.0' ); |
1456 _deprecated_argument( __FUNCTION__, '3.0.0' ); |
1435 } |
1457 } |
1436 |
1458 |
1437 if ( ! $post = get_post( $id ) ) { |
1459 $post = get_post( $id ); |
|
1460 if ( ! $post ) { |
1438 return; |
1461 return; |
1439 } |
1462 } |
1440 |
1463 |
1441 $post_type_object = get_post_type_object( $post->post_type ); |
1464 $post_type_object = get_post_type_object( $post->post_type ); |
1442 if ( ! $post_type_object ) { |
1465 if ( ! $post_type_object ) { |
1555 /** |
1578 /** |
1556 * Displays the edit bookmark link anchor content. |
1579 * Displays the edit bookmark link anchor content. |
1557 * |
1580 * |
1558 * @since 2.7.0 |
1581 * @since 2.7.0 |
1559 * |
1582 * |
1560 * @param string $link Optional. Anchor text. Default empty. |
1583 * @param string $link Optional. Anchor text. If empty, default is 'Edit This'. Default empty. |
1561 * @param string $before Optional. Display before edit link. Default empty. |
1584 * @param string $before Optional. Display before edit link. Default empty. |
1562 * @param string $after Optional. Display after edit link. Default empty. |
1585 * @param string $after Optional. Display after edit link. Default empty. |
1563 * @param int $bookmark Optional. Bookmark ID. Default is the current bookmark. |
1586 * @param int $bookmark Optional. Bookmark ID. Default is the current bookmark. |
1564 */ |
1587 */ |
1565 function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = null ) { |
1588 function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = null ) { |
1688 $adjacent = $previous ? 'previous' : 'next'; |
1714 $adjacent = $previous ? 'previous' : 'next'; |
1689 |
1715 |
1690 if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) { |
1716 if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) { |
1691 // Back-compat, $excluded_terms used to be $excluded_categories with IDs separated by " and ". |
1717 // Back-compat, $excluded_terms used to be $excluded_categories with IDs separated by " and ". |
1692 if ( false !== strpos( $excluded_terms, ' and ' ) ) { |
1718 if ( false !== strpos( $excluded_terms, ' and ' ) ) { |
1693 _deprecated_argument( __FUNCTION__, '3.3.0', sprintf( __( 'Use commas instead of %s to separate excluded terms.' ), "'and'" ) ); |
1719 _deprecated_argument( |
|
1720 __FUNCTION__, |
|
1721 '3.3.0', |
|
1722 sprintf( |
|
1723 /* translators: %s: The word 'and'. */ |
|
1724 __( 'Use commas instead of %s to separate excluded terms.' ), |
|
1725 "'and'" |
|
1726 ) |
|
1727 ); |
1694 $excluded_terms = explode( ' and ', $excluded_terms ); |
1728 $excluded_terms = explode( ' and ', $excluded_terms ); |
1695 } else { |
1729 } else { |
1696 $excluded_terms = explode( ',', $excluded_terms ); |
1730 $excluded_terms = explode( ',', $excluded_terms ); |
1697 } |
1731 } |
1698 |
1732 |
1857 * @param bool $previous Optional. Whether to display link to previous or next post. Default true. |
1891 * @param bool $previous Optional. Whether to display link to previous or next post. Default true. |
1858 * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
1892 * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
1859 * @return string|void The adjacent post relational link URL. |
1893 * @return string|void The adjacent post relational link URL. |
1860 */ |
1894 */ |
1861 function get_adjacent_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { |
1895 function get_adjacent_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { |
1862 if ( $previous && is_attachment() && $post = get_post() ) { |
1896 $post = get_post(); |
|
1897 if ( $previous && is_attachment() && $post ) { |
1863 $post = get_post( $post->post_parent ); |
1898 $post = get_post( $post->post_parent ); |
1864 } else { |
1899 } else { |
1865 $post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy ); |
1900 $post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy ); |
1866 } |
1901 } |
1867 |
1902 |
2231 $request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request ); |
2267 $request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request ); |
2232 $request = ltrim( $request, '/' ); |
2268 $request = ltrim( $request, '/' ); |
2233 |
2269 |
2234 $base = trailingslashit( get_bloginfo( 'url' ) ); |
2270 $base = trailingslashit( get_bloginfo( 'url' ) ); |
2235 |
2271 |
2236 if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) ) { |
2272 if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' !== $request ) ) { |
2237 $base .= $wp_rewrite->index . '/'; |
2273 $base .= $wp_rewrite->index . '/'; |
2238 } |
2274 } |
2239 |
2275 |
2240 if ( $pagenum > 1 ) { |
2276 if ( $pagenum > 1 ) { |
2241 $request = ( ( ! empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . '/' . $pagenum, 'paged' ); |
2277 $request = ( ( ! empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . '/' . $pagenum, 'paged' ); |
2512 /** |
2548 /** |
2513 * Retrieves the navigation to next/previous post, when applicable. |
2549 * Retrieves the navigation to next/previous post, when applicable. |
2514 * |
2550 * |
2515 * @since 4.1.0 |
2551 * @since 4.1.0 |
2516 * @since 4.4.0 Introduced the `in_same_term`, `excluded_terms`, and `taxonomy` arguments. |
2552 * @since 4.4.0 Introduced the `in_same_term`, `excluded_terms`, and `taxonomy` arguments. |
|
2553 * @since 5.3.0 Added the `aria_label` parameter. |
|
2554 * @since 5.5.0 Added the `class` parameter. |
2517 * |
2555 * |
2518 * @param array $args { |
2556 * @param array $args { |
2519 * Optional. Default post navigation arguments. Default empty array. |
2557 * Optional. Default post navigation arguments. Default empty array. |
2520 * |
2558 * |
2521 * @type string $prev_text Anchor text to display in the previous post link. Default '%title'. |
2559 * @type string $prev_text Anchor text to display in the previous post link. Default '%title'. |
2522 * @type string $next_text Anchor text to display in the next post link. Default '%title'. |
2560 * @type string $next_text Anchor text to display in the next post link. Default '%title'. |
2523 * @type bool $in_same_term Whether link should be in a same taxonomy term. Default false. |
2561 * @type bool $in_same_term Whether link should be in a same taxonomy term. Default false. |
2524 * @type array|string $excluded_terms Array or comma-separated list of excluded term IDs. Default empty. |
2562 * @type array|string $excluded_terms Array or comma-separated list of excluded term IDs. Default empty. |
2525 * @type string $taxonomy Taxonomy, if `$in_same_term` is true. Default 'category'. |
2563 * @type string $taxonomy Taxonomy, if `$in_same_term` is true. Default 'category'. |
2526 * @type string $screen_reader_text Screen reader text for nav element. Default 'Post navigation'. |
2564 * @type string $screen_reader_text Screen reader text for the nav element. Default 'Post navigation'. |
|
2565 * @type string $aria_label ARIA label text for the nav element. Default 'Posts'. |
|
2566 * @type string $class Custom class for the nav element. Default 'post-navigation'. |
2527 * } |
2567 * } |
2528 * @return string Markup for post links. |
2568 * @return string Markup for post links. |
2529 */ |
2569 */ |
2530 function get_the_post_navigation( $args = array() ) { |
2570 function get_the_post_navigation( $args = array() ) { |
|
2571 // Make sure the nav element has an aria-label attribute: fallback to the screen reader text. |
|
2572 if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { |
|
2573 $args['aria_label'] = $args['screen_reader_text']; |
|
2574 } |
|
2575 |
2531 $args = wp_parse_args( |
2576 $args = wp_parse_args( |
2532 $args, |
2577 $args, |
2533 array( |
2578 array( |
2534 'prev_text' => '%title', |
2579 'prev_text' => '%title', |
2535 'next_text' => '%title', |
2580 'next_text' => '%title', |
2536 'in_same_term' => false, |
2581 'in_same_term' => false, |
2537 'excluded_terms' => '', |
2582 'excluded_terms' => '', |
2538 'taxonomy' => 'category', |
2583 'taxonomy' => 'category', |
2539 'screen_reader_text' => __( 'Post navigation' ), |
2584 'screen_reader_text' => __( 'Post navigation' ), |
|
2585 'aria_label' => __( 'Posts' ), |
|
2586 'class' => 'post-navigation', |
2540 ) |
2587 ) |
2541 ); |
2588 ); |
2542 |
2589 |
2543 $navigation = ''; |
2590 $navigation = ''; |
2544 |
2591 |
2580 |
2627 |
2581 /** |
2628 /** |
2582 * Returns the navigation to next/previous set of posts, when applicable. |
2629 * Returns the navigation to next/previous set of posts, when applicable. |
2583 * |
2630 * |
2584 * @since 4.1.0 |
2631 * @since 4.1.0 |
|
2632 * @since 5.3.0 Added the `aria_label` parameter. |
|
2633 * @since 5.5.0 Added the `class` parameter. |
2585 * |
2634 * |
2586 * @global WP_Query $wp_query WordPress Query object. |
2635 * @global WP_Query $wp_query WordPress Query object. |
2587 * |
2636 * |
2588 * @param array $args { |
2637 * @param array $args { |
2589 * Optional. Default posts navigation arguments. Default empty array. |
2638 * Optional. Default posts navigation arguments. Default empty array. |
2590 * |
2639 * |
2591 * @type string $prev_text Anchor text to display in the previous posts link. |
2640 * @type string $prev_text Anchor text to display in the previous posts link. |
2592 * Default 'Older posts'. |
2641 * Default 'Older posts'. |
2593 * @type string $next_text Anchor text to display in the next posts link. |
2642 * @type string $next_text Anchor text to display in the next posts link. |
2594 * Default 'Newer posts'. |
2643 * Default 'Newer posts'. |
2595 * @type string $screen_reader_text Screen reader text for nav element. |
2644 * @type string $screen_reader_text Screen reader text for the nav element. |
2596 * Default 'Posts navigation'. |
2645 * Default 'Posts navigation'. |
|
2646 * @type string $aria_label ARIA label text for the nav element. Default 'Posts'. |
|
2647 * @type string $class Custom class for the nav element. Default 'posts-navigation'. |
2597 * } |
2648 * } |
2598 * @return string Markup for posts links. |
2649 * @return string Markup for posts links. |
2599 */ |
2650 */ |
2600 function get_the_posts_navigation( $args = array() ) { |
2651 function get_the_posts_navigation( $args = array() ) { |
2601 $navigation = ''; |
2652 $navigation = ''; |
2602 |
2653 |
2603 // Don't print empty markup if there's only one page. |
2654 // Don't print empty markup if there's only one page. |
2604 if ( $GLOBALS['wp_query']->max_num_pages > 1 ) { |
2655 if ( $GLOBALS['wp_query']->max_num_pages > 1 ) { |
|
2656 // Make sure the nav element has an aria-label attribute: fallback to the screen reader text. |
|
2657 if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { |
|
2658 $args['aria_label'] = $args['screen_reader_text']; |
|
2659 } |
|
2660 |
2605 $args = wp_parse_args( |
2661 $args = wp_parse_args( |
2606 $args, |
2662 $args, |
2607 array( |
2663 array( |
2608 'prev_text' => __( 'Older posts' ), |
2664 'prev_text' => __( 'Older posts' ), |
2609 'next_text' => __( 'Newer posts' ), |
2665 'next_text' => __( 'Newer posts' ), |
2610 'screen_reader_text' => __( 'Posts navigation' ), |
2666 'screen_reader_text' => __( 'Posts navigation' ), |
|
2667 'aria_label' => __( 'Posts' ), |
|
2668 'class' => 'posts-navigation', |
2611 ) |
2669 ) |
2612 ); |
2670 ); |
2613 |
2671 |
2614 $next_link = get_previous_posts_link( $args['next_text'] ); |
2672 $next_link = get_previous_posts_link( $args['next_text'] ); |
2615 $prev_link = get_next_posts_link( $args['prev_text'] ); |
2673 $prev_link = get_next_posts_link( $args['prev_text'] ); |
2642 |
2700 |
2643 /** |
2701 /** |
2644 * Retrieves a paginated navigation to next/previous set of posts, when applicable. |
2702 * Retrieves a paginated navigation to next/previous set of posts, when applicable. |
2645 * |
2703 * |
2646 * @since 4.1.0 |
2704 * @since 4.1.0 |
|
2705 * @since 5.3.0 Added the `aria_label` parameter. |
|
2706 * @since 5.5.0 Added the `class` parameter. |
2647 * |
2707 * |
2648 * @param array $args { |
2708 * @param array $args { |
2649 * Optional. Default pagination arguments, see paginate_links(). |
2709 * Optional. Default pagination arguments, see paginate_links(). |
2650 * |
2710 * |
2651 * @type string $screen_reader_text Screen reader text for navigation element. |
2711 * @type string $screen_reader_text Screen reader text for navigation element. |
2652 * Default 'Posts navigation'. |
2712 * Default 'Posts navigation'. |
|
2713 * @type string $aria_label ARIA label text for the nav element. Default 'Posts'. |
|
2714 * @type string $class Custom class for the nav element. Default 'pagination'. |
2653 * } |
2715 * } |
2654 * @return string Markup for pagination links. |
2716 * @return string Markup for pagination links. |
2655 */ |
2717 */ |
2656 function get_the_posts_pagination( $args = array() ) { |
2718 function get_the_posts_pagination( $args = array() ) { |
2657 $navigation = ''; |
2719 $navigation = ''; |
2658 |
2720 |
2659 // Don't print empty markup if there's only one page. |
2721 // Don't print empty markup if there's only one page. |
2660 if ( $GLOBALS['wp_query']->max_num_pages > 1 ) { |
2722 if ( $GLOBALS['wp_query']->max_num_pages > 1 ) { |
|
2723 // Make sure the nav element has an aria-label attribute: fallback to the screen reader text. |
|
2724 if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { |
|
2725 $args['aria_label'] = $args['screen_reader_text']; |
|
2726 } |
|
2727 |
2661 $args = wp_parse_args( |
2728 $args = wp_parse_args( |
2662 $args, |
2729 $args, |
2663 array( |
2730 array( |
2664 'mid_size' => 1, |
2731 'mid_size' => 1, |
2665 'prev_text' => _x( 'Previous', 'previous set of posts' ), |
2732 'prev_text' => _x( 'Previous', 'previous set of posts' ), |
2666 'next_text' => _x( 'Next', 'next set of posts' ), |
2733 'next_text' => _x( 'Next', 'next set of posts' ), |
2667 'screen_reader_text' => __( 'Posts navigation' ), |
2734 'screen_reader_text' => __( 'Posts navigation' ), |
|
2735 'aria_label' => __( 'Posts' ), |
|
2736 'class' => 'pagination', |
2668 ) |
2737 ) |
2669 ); |
2738 ); |
2670 |
2739 |
2671 // Make sure we get a string back. Plain is the next best thing. |
2740 // Make sure we get a string back. Plain is the next best thing. |
2672 if ( isset( $args['type'] ) && 'array' == $args['type'] ) { |
2741 if ( isset( $args['type'] ) && 'array' === $args['type'] ) { |
2673 $args['type'] = 'plain'; |
2742 $args['type'] = 'plain'; |
2674 } |
2743 } |
2675 |
2744 |
2676 // Set up paginated links. |
2745 // Set up paginated links. |
2677 $links = paginate_links( $args ); |
2746 $links = paginate_links( $args ); |
2678 |
2747 |
2679 if ( $links ) { |
2748 if ( $links ) { |
2680 $navigation = _navigation_markup( $links, 'pagination', $args['screen_reader_text'] ); |
2749 $navigation = _navigation_markup( $links, $args['class'], $args['screen_reader_text'], $args['aria_label'] ); |
2681 } |
2750 } |
2682 } |
2751 } |
2683 |
2752 |
2684 return $navigation; |
2753 return $navigation; |
2685 } |
2754 } |
2698 |
2767 |
2699 /** |
2768 /** |
2700 * Wraps passed links in navigational markup. |
2769 * Wraps passed links in navigational markup. |
2701 * |
2770 * |
2702 * @since 4.1.0 |
2771 * @since 4.1.0 |
|
2772 * @since 5.3.0 Added the `aria_label` parameter. |
2703 * @access private |
2773 * @access private |
2704 * |
2774 * |
2705 * @param string $links Navigational links. |
2775 * @param string $links Navigational links. |
2706 * @param string $class Optional. Custom class for nav element. Default: 'posts-navigation'. |
2776 * @param string $class Optional. Custom class for the nav element. |
2707 * @param string $screen_reader_text Optional. Screen reader text for nav element. Default: 'Posts navigation'. |
2777 * Default 'posts-navigation'. |
|
2778 * @param string $screen_reader_text Optional. Screen reader text for the nav element. |
|
2779 * Default 'Posts navigation'. |
|
2780 * @param string $aria_label Optional. ARIA label for the nav element. |
|
2781 * Defaults to the value of `$screen_reader_text`. |
2708 * @return string Navigation template tag. |
2782 * @return string Navigation template tag. |
2709 */ |
2783 */ |
2710 function _navigation_markup( $links, $class = 'posts-navigation', $screen_reader_text = '' ) { |
2784 function _navigation_markup( $links, $class = 'posts-navigation', $screen_reader_text = '', $aria_label = '' ) { |
2711 if ( empty( $screen_reader_text ) ) { |
2785 if ( empty( $screen_reader_text ) ) { |
2712 $screen_reader_text = __( 'Posts navigation' ); |
2786 $screen_reader_text = __( 'Posts navigation' ); |
2713 } |
2787 } |
|
2788 if ( empty( $aria_label ) ) { |
|
2789 $aria_label = $screen_reader_text; |
|
2790 } |
2714 |
2791 |
2715 $template = ' |
2792 $template = ' |
2716 <nav class="navigation %1$s" role="navigation"> |
2793 <nav class="navigation %1$s" role="navigation" aria-label="%4$s"> |
2717 <h2 class="screen-reader-text">%2$s</h2> |
2794 <h2 class="screen-reader-text">%2$s</h2> |
2718 <div class="nav-links">%3$s</div> |
2795 <div class="nav-links">%3$s</div> |
2719 </nav>'; |
2796 </nav>'; |
2720 |
2797 |
2721 /** |
2798 /** |
2722 * Filters the navigation markup template. |
2799 * Filters the navigation markup template. |
2723 * |
2800 * |
2724 * Note: The filtered template HTML must contain specifiers for the navigation |
2801 * Note: The filtered template HTML must contain specifiers for the navigation |
2725 * class (%1$s), the screen-reader-text value (%2$s), and placement of the |
2802 * class (%1$s), the screen-reader-text value (%2$s), placement of the navigation |
2726 * navigation links (%3$s): |
2803 * links (%3$s), and ARIA label text if screen-reader-text does not fit that (%4$s): |
2727 * |
2804 * |
2728 * <nav class="navigation %1$s" role="navigation"> |
2805 * <nav class="navigation %1$s" role="navigation" aria-label="%4$s"> |
2729 * <h2 class="screen-reader-text">%2$s</h2> |
2806 * <h2 class="screen-reader-text">%2$s</h2> |
2730 * <div class="nav-links">%3$s</div> |
2807 * <div class="nav-links">%3$s</div> |
2731 * </nav> |
2808 * </nav> |
2732 * |
2809 * |
2733 * @since 4.4.0 |
2810 * @since 4.4.0 |
2736 * @param string $class The class passed by the calling function. |
2813 * @param string $class The class passed by the calling function. |
2737 * @return string Navigation template. |
2814 * @return string Navigation template. |
2738 */ |
2815 */ |
2739 $template = apply_filters( 'navigation_markup_template', $template, $class ); |
2816 $template = apply_filters( 'navigation_markup_template', $template, $class ); |
2740 |
2817 |
2741 return sprintf( $template, sanitize_html_class( $class ), esc_html( $screen_reader_text ), $links ); |
2818 return sprintf( $template, sanitize_html_class( $class ), esc_html( $screen_reader_text ), $links, esc_html( $aria_label ) ); |
2742 } |
2819 } |
2743 |
2820 |
2744 /** |
2821 /** |
2745 * Retrieves the comments page number link. |
2822 * Retrieves the comments page number link. |
2746 * |
2823 * |
2747 * @since 2.7.0 |
2824 * @since 2.7.0 |
2748 * |
2825 * |
2749 * @global WP_Rewrite $wp_rewrite |
2826 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
2750 * |
2827 * |
2751 * @param int $pagenum Optional. Page number. Default 1. |
2828 * @param int $pagenum Optional. Page number. Default 1. |
2752 * @param int $max_page Optional. The maximum number of comment pages. Default 0. |
2829 * @param int $max_page Optional. The maximum number of comment pages. Default 0. |
2753 * @return string The comments page number link URL. |
2830 * @return string The comments page number link URL. |
2754 */ |
2831 */ |
2757 |
2834 |
2758 $pagenum = (int) $pagenum; |
2835 $pagenum = (int) $pagenum; |
2759 |
2836 |
2760 $result = get_permalink(); |
2837 $result = get_permalink(); |
2761 |
2838 |
2762 if ( 'newest' == get_option( 'default_comments_page' ) ) { |
2839 if ( 'newest' === get_option( 'default_comments_page' ) ) { |
2763 if ( $pagenum != $max_page ) { |
2840 if ( $pagenum != $max_page ) { |
2764 if ( $wp_rewrite->using_permalinks() ) { |
2841 if ( $wp_rewrite->using_permalinks() ) { |
2765 $result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' ); |
2842 $result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' ); |
2766 } else { |
2843 } else { |
2767 $result = add_query_arg( 'cpage', $pagenum, $result ); |
2844 $result = add_query_arg( 'cpage', $pagenum, $result ); |
2901 * Displays or retrieves pagination links for the comments on the current post. |
2978 * Displays or retrieves pagination links for the comments on the current post. |
2902 * |
2979 * |
2903 * @see paginate_links() |
2980 * @see paginate_links() |
2904 * @since 2.7.0 |
2981 * @since 2.7.0 |
2905 * |
2982 * |
2906 * @global WP_Rewrite $wp_rewrite |
2983 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
2907 * |
2984 * |
2908 * @param string|array $args Optional args. See paginate_links(). Default empty array. |
2985 * @param string|array $args Optional args. See paginate_links(). Default empty array. |
2909 * @return string|array|void Markup for comment page links or array of comment page links. |
2986 * @return void|string|array Void if 'echo' argument is true and 'type' is not an array, |
|
2987 * or if the query is not for an existing single post of any post type. |
|
2988 * Otherwise, markup for comment page links or array of comment page links, |
|
2989 * depending on 'type' argument. |
2910 */ |
2990 */ |
2911 function paginate_comments_links( $args = array() ) { |
2991 function paginate_comments_links( $args = array() ) { |
2912 global $wp_rewrite; |
2992 global $wp_rewrite; |
2913 |
2993 |
2914 if ( ! is_singular() ) { |
2994 if ( ! is_singular() ) { |
2945 |
3025 |
2946 /** |
3026 /** |
2947 * Retrieves navigation to next/previous set of comments, when applicable. |
3027 * Retrieves navigation to next/previous set of comments, when applicable. |
2948 * |
3028 * |
2949 * @since 4.4.0 |
3029 * @since 4.4.0 |
|
3030 * @since 5.3.0 Added the `aria_label` parameter. |
|
3031 * @since 5.5.0 Added the `class` parameter. |
2950 * |
3032 * |
2951 * @param array $args { |
3033 * @param array $args { |
2952 * Optional. Default comments navigation arguments. |
3034 * Optional. Default comments navigation arguments. |
2953 * |
3035 * |
2954 * @type string $prev_text Anchor text to display in the previous comments link. |
3036 * @type string $prev_text Anchor text to display in the previous comments link. |
2955 * Default 'Older comments'. |
3037 * Default 'Older comments'. |
2956 * @type string $next_text Anchor text to display in the next comments link. |
3038 * @type string $next_text Anchor text to display in the next comments link. |
2957 * Default 'Newer comments'. |
3039 * Default 'Newer comments'. |
2958 * @type string $screen_reader_text Screen reader text for nav element. Default 'Comments navigation'. |
3040 * @type string $screen_reader_text Screen reader text for the nav element. Default 'Comments navigation'. |
|
3041 * @type string $aria_label ARIA label text for the nav element. Default 'Comments'. |
|
3042 * @type string $class Custom class for the nav element. Default 'comment-navigation'. |
2959 * } |
3043 * } |
2960 * @return string Markup for comments links. |
3044 * @return string Markup for comments links. |
2961 */ |
3045 */ |
2962 function get_the_comments_navigation( $args = array() ) { |
3046 function get_the_comments_navigation( $args = array() ) { |
2963 $navigation = ''; |
3047 $navigation = ''; |
2964 |
3048 |
2965 // Are there comments to navigate through? |
3049 // Are there comments to navigate through? |
2966 if ( get_comment_pages_count() > 1 ) { |
3050 if ( get_comment_pages_count() > 1 ) { |
|
3051 // Make sure the nav element has an aria-label attribute: fallback to the screen reader text. |
|
3052 if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { |
|
3053 $args['aria_label'] = $args['screen_reader_text']; |
|
3054 } |
|
3055 |
2967 $args = wp_parse_args( |
3056 $args = wp_parse_args( |
2968 $args, |
3057 $args, |
2969 array( |
3058 array( |
2970 'prev_text' => __( 'Older comments' ), |
3059 'prev_text' => __( 'Older comments' ), |
2971 'next_text' => __( 'Newer comments' ), |
3060 'next_text' => __( 'Newer comments' ), |
2972 'screen_reader_text' => __( 'Comments navigation' ), |
3061 'screen_reader_text' => __( 'Comments navigation' ), |
|
3062 'aria_label' => __( 'Comments' ), |
|
3063 'class' => 'comment-navigation', |
2973 ) |
3064 ) |
2974 ); |
3065 ); |
2975 |
3066 |
2976 $prev_link = get_previous_comments_link( $args['prev_text'] ); |
3067 $prev_link = get_previous_comments_link( $args['prev_text'] ); |
2977 $next_link = get_next_comments_link( $args['next_text'] ); |
3068 $next_link = get_next_comments_link( $args['next_text'] ); |
3003 |
3094 |
3004 /** |
3095 /** |
3005 * Retrieves a paginated navigation to next/previous set of comments, when applicable. |
3096 * Retrieves a paginated navigation to next/previous set of comments, when applicable. |
3006 * |
3097 * |
3007 * @since 4.4.0 |
3098 * @since 4.4.0 |
|
3099 * @since 5.3.0 Added the `aria_label` parameter. |
|
3100 * @since 5.5.0 Added the `class` parameter. |
3008 * |
3101 * |
3009 * @see paginate_comments_links() |
3102 * @see paginate_comments_links() |
3010 * |
3103 * |
3011 * @param array $args { |
3104 * @param array $args { |
3012 * Optional. Default pagination arguments. |
3105 * Optional. Default pagination arguments. |
3013 * |
3106 * |
3014 * @type string $screen_reader_text Screen reader text for nav element. Default 'Comments navigation'. |
3107 * @type string $screen_reader_text Screen reader text for the nav element. Default 'Comments navigation'. |
|
3108 * @type string $aria_label ARIA label text for the nav element. Default 'Comments'. |
|
3109 * @type string $class Custom class for the nav element. Default 'comments-pagination'. |
3015 * } |
3110 * } |
3016 * @return string Markup for pagination links. |
3111 * @return string Markup for pagination links. |
3017 */ |
3112 */ |
3018 function get_the_comments_pagination( $args = array() ) { |
3113 function get_the_comments_pagination( $args = array() ) { |
3019 $navigation = ''; |
3114 $navigation = ''; |
|
3115 |
|
3116 // Make sure the nav element has an aria-label attribute: fallback to the screen reader text. |
|
3117 if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { |
|
3118 $args['aria_label'] = $args['screen_reader_text']; |
|
3119 } |
|
3120 |
3020 $args = wp_parse_args( |
3121 $args = wp_parse_args( |
3021 $args, |
3122 $args, |
3022 array( |
3123 array( |
3023 'screen_reader_text' => __( 'Comments navigation' ), |
3124 'screen_reader_text' => __( 'Comments navigation' ), |
|
3125 'aria_label' => __( 'Comments' ), |
|
3126 'class' => 'comments-pagination', |
3024 ) |
3127 ) |
3025 ); |
3128 ); |
3026 $args['echo'] = false; |
3129 $args['echo'] = false; |
3027 |
3130 |
3028 // Make sure we get a string back. Plain is the next best thing. |
3131 // Make sure we get a string back. Plain is the next best thing. |
3029 if ( isset( $args['type'] ) && 'array' == $args['type'] ) { |
3132 if ( isset( $args['type'] ) && 'array' === $args['type'] ) { |
3030 $args['type'] = 'plain'; |
3133 $args['type'] = 'plain'; |
3031 } |
3134 } |
3032 |
3135 |
3033 $links = paginate_comments_links( $args ); |
3136 $links = paginate_comments_links( $args ); |
3034 |
3137 |
3035 if ( $links ) { |
3138 if ( $links ) { |
3036 $navigation = _navigation_markup( $links, 'comments-pagination', $args['screen_reader_text'] ); |
3139 $navigation = _navigation_markup( $links, $args['class'], $args['screen_reader_text'], $args['aria_label'] ); |
3037 } |
3140 } |
3038 |
3141 |
3039 return $navigation; |
3142 return $navigation; |
3040 } |
3143 } |
3041 |
3144 |
3057 * if is_ssl() evaluates to true; otherwise, it will be the same as the 'home' option. |
3160 * if is_ssl() evaluates to true; otherwise, it will be the same as the 'home' option. |
3058 * If `$scheme` is 'http' or 'https', is_ssl() is overridden. |
3161 * If `$scheme` is 'http' or 'https', is_ssl() is overridden. |
3059 * |
3162 * |
3060 * @since 3.0.0 |
3163 * @since 3.0.0 |
3061 * |
3164 * |
3062 * @param string $path Optional. Path relative to the home URL. Default empty. |
3165 * @param string $path Optional. Path relative to the home URL. Default empty. |
3063 * @param string|null $scheme Optional. Scheme to give the home URL context. Accepts |
3166 * @param string|null $scheme Optional. Scheme to give the home URL context. Accepts |
3064 * 'http', 'https', 'relative', 'rest', or null. Default null. |
3167 * 'http', 'https', 'relative', 'rest', or null. Default null. |
3065 * @return string Home URL link with optional path appended. |
3168 * @return string Home URL link with optional path appended. |
3066 */ |
3169 */ |
3067 function home_url( $path = '', $scheme = null ) { |
3170 function home_url( $path = '', $scheme = null ) { |
3068 return get_home_url( null, $path, $scheme ); |
3171 return get_home_url( null, $path, $scheme ); |
3069 } |
3172 } |
3077 * |
3180 * |
3078 * @since 3.0.0 |
3181 * @since 3.0.0 |
3079 * |
3182 * |
3080 * @global string $pagenow |
3183 * @global string $pagenow |
3081 * |
3184 * |
3082 * @param int $blog_id Optional. Site ID. Default null (current site). |
3185 * @param int $blog_id Optional. Site ID. Default null (current site). |
3083 * @param string $path Optional. Path relative to the home URL. Default empty. |
3186 * @param string $path Optional. Path relative to the home URL. Default empty. |
3084 * @param string|null $scheme Optional. Scheme to give the home URL context. Accepts |
3187 * @param string|null $scheme Optional. Scheme to give the home URL context. Accepts |
3085 * 'http', 'https', 'relative', 'rest', or null. Default null. |
3188 * 'http', 'https', 'relative', 'rest', or null. Default null. |
3086 * @return string Home URL link with optional path appended. |
3189 * @return string Home URL link with optional path appended. |
3087 */ |
3190 */ |
3088 function get_home_url( $blog_id = null, $path = '', $scheme = null ) { |
3191 function get_home_url( $blog_id = null, $path = '', $scheme = null ) { |
3089 global $pagenow; |
3192 global $pagenow; |
3090 |
3193 |
3296 * |
3399 * |
3297 * Defaults to the plugins directory URL if no arguments are supplied. |
3400 * Defaults to the plugins directory URL if no arguments are supplied. |
3298 * |
3401 * |
3299 * @since 2.6.0 |
3402 * @since 2.6.0 |
3300 * |
3403 * |
3301 * @param string $path Optional. Extra path appended to the end of the URL, including |
3404 * @param string $path Optional. Extra path appended to the end of the URL, including |
3302 * the relative directory if $plugin is supplied. Default empty. |
3405 * the relative directory if $plugin is supplied. Default empty. |
3303 * @param string $plugin Optional. A full path to a file inside a plugin or mu-plugin. |
3406 * @param string $plugin Optional. A full path to a file inside a plugin or mu-plugin. |
3304 * The URL will be relative to its directory. Default empty. |
3407 * The URL will be relative to its directory. Default empty. |
3305 * Typically this is done by passing `__FILE__` as the argument. |
3408 * Typically this is done by passing `__FILE__` as the argument. |
3306 * @return string Plugins URL link with optional paths appended. |
3409 * @return string Plugins URL link with optional paths appended. |
3307 */ |
3410 */ |
3308 function plugins_url( $path = '', $plugin = '' ) { |
3411 function plugins_url( $path = '', $plugin = '' ) { |
3309 |
3412 |
3310 $path = wp_normalize_path( $path ); |
3413 $path = wp_normalize_path( $path ); |
3398 * and 'http' otherwise. If `$scheme` is 'http' or 'https', `is_ssl()` is |
3501 * and 'http' otherwise. If `$scheme` is 'http' or 'https', `is_ssl()` is |
3399 * overridden. |
3502 * overridden. |
3400 * |
3503 * |
3401 * @since 3.0.0 |
3504 * @since 3.0.0 |
3402 * |
3505 * |
3403 * @param string $path Optional. Path relative to the home URL. Default empty. |
3506 * @param string $path Optional. Path relative to the home URL. Default empty. |
3404 * @param string $scheme Optional. Scheme to give the home URL context. Accepts |
3507 * @param string $scheme Optional. Scheme to give the home URL context. Accepts |
3405 * 'http', 'https', or 'relative'. Default null. |
3508 * 'http', 'https', or 'relative'. Default null. |
3406 * @return string Home URL link with optional path appended. |
3509 * @return string Home URL link with optional path appended. |
3407 */ |
3510 */ |
3408 function network_home_url( $path = '', $scheme = null ) { |
3511 function network_home_url( $path = '', $scheme = null ) { |
3409 if ( ! is_multisite() ) { |
3512 if ( ! is_multisite() ) { |
3410 return home_url( $path, $scheme ); |
3513 return home_url( $path, $scheme ); |
3411 } |
3514 } |
3412 |
3515 |
3413 $current_network = get_network(); |
3516 $current_network = get_network(); |
3414 $orig_scheme = $scheme; |
3517 $orig_scheme = $scheme; |
3415 |
3518 |
3416 if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) { |
3519 if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ), true ) ) { |
3417 $scheme = is_ssl() && ! is_admin() ? 'https' : 'http'; |
3520 $scheme = is_ssl() && ! is_admin() ? 'https' : 'http'; |
3418 } |
3521 } |
3419 |
3522 |
3420 if ( 'relative' == $scheme ) { |
3523 if ( 'relative' === $scheme ) { |
3421 $url = $current_network->path; |
3524 $url = $current_network->path; |
3422 } else { |
3525 } else { |
3423 $url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme ); |
3526 $url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme ); |
3424 } |
3527 } |
3425 |
3528 |
3541 * @since 4.4.0 The 'rest' scheme was added. |
3644 * @since 4.4.0 The 'rest' scheme was added. |
3542 * |
3645 * |
3543 * @param string $url Absolute URL that includes a scheme |
3646 * @param string $url Absolute URL that includes a scheme |
3544 * @param string|null $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login', |
3647 * @param string|null $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login', |
3545 * 'login_post', 'admin', 'relative', 'rest', 'rpc', or null. Default null. |
3648 * 'login_post', 'admin', 'relative', 'rest', 'rpc', or null. Default null. |
3546 * @return string $url URL with chosen scheme. |
3649 * @return string URL with chosen scheme. |
3547 */ |
3650 */ |
3548 function set_url_scheme( $url, $scheme = null ) { |
3651 function set_url_scheme( $url, $scheme = null ) { |
3549 $orig_scheme = $scheme; |
3652 $orig_scheme = $scheme; |
3550 |
3653 |
3551 if ( ! $scheme ) { |
3654 if ( ! $scheme ) { |
3552 $scheme = is_ssl() ? 'https' : 'http'; |
3655 $scheme = is_ssl() ? 'https' : 'http'; |
3553 } elseif ( $scheme === 'admin' || $scheme === 'login' || $scheme === 'login_post' || $scheme === 'rpc' ) { |
3656 } elseif ( 'admin' === $scheme || 'login' === $scheme || 'login_post' === $scheme || 'rpc' === $scheme ) { |
3554 $scheme = is_ssl() || force_ssl_admin() ? 'https' : 'http'; |
3657 $scheme = is_ssl() || force_ssl_admin() ? 'https' : 'http'; |
3555 } elseif ( $scheme !== 'http' && $scheme !== 'https' && $scheme !== 'relative' ) { |
3658 } elseif ( 'http' !== $scheme && 'https' !== $scheme && 'relative' !== $scheme ) { |
3556 $scheme = is_ssl() ? 'https' : 'http'; |
3659 $scheme = is_ssl() ? 'https' : 'http'; |
3557 } |
3660 } |
3558 |
3661 |
3559 $url = trim( $url ); |
3662 $url = trim( $url ); |
3560 if ( substr( $url, 0, 2 ) === '//' ) { |
3663 if ( substr( $url, 0, 2 ) === '//' ) { |
3561 $url = 'http:' . $url; |
3664 $url = 'http:' . $url; |
3562 } |
3665 } |
3563 |
3666 |
3564 if ( 'relative' == $scheme ) { |
3667 if ( 'relative' === $scheme ) { |
3565 $url = ltrim( preg_replace( '#^\w+://[^/]*#', '', $url ) ); |
3668 $url = ltrim( preg_replace( '#^\w+://[^/]*#', '', $url ) ); |
3566 if ( $url !== '' && $url[0] === '/' ) { |
3669 if ( '' !== $url && '/' === $url[0] ) { |
3567 $url = '/' . ltrim( $url, "/ \t\n\r\0\x0B" ); |
3670 $url = '/' . ltrim( $url, "/ \t\n\r\0\x0B" ); |
3568 } |
3671 } |
3569 } else { |
3672 } else { |
3570 $url = preg_replace( '#^\w+://#', $scheme . '://', $url ); |
3673 $url = preg_replace( '#^\w+://#', $scheme . '://', $url ); |
3571 } |
3674 } |
3601 */ |
3704 */ |
3602 function get_dashboard_url( $user_id = 0, $path = '', $scheme = 'admin' ) { |
3705 function get_dashboard_url( $user_id = 0, $path = '', $scheme = 'admin' ) { |
3603 $user_id = $user_id ? (int) $user_id : get_current_user_id(); |
3706 $user_id = $user_id ? (int) $user_id : get_current_user_id(); |
3604 |
3707 |
3605 $blogs = get_blogs_of_user( $user_id ); |
3708 $blogs = get_blogs_of_user( $user_id ); |
|
3709 |
3606 if ( is_multisite() && ! user_can( $user_id, 'manage_network' ) && empty( $blogs ) ) { |
3710 if ( is_multisite() && ! user_can( $user_id, 'manage_network' ) && empty( $blogs ) ) { |
3607 $url = user_admin_url( $path, $scheme ); |
3711 $url = user_admin_url( $path, $scheme ); |
3608 } elseif ( ! is_multisite() ) { |
3712 } elseif ( ! is_multisite() ) { |
3609 $url = admin_url( $path, $scheme ); |
3713 $url = admin_url( $path, $scheme ); |
3610 } else { |
3714 } else { |
3611 $current_blog = get_current_blog_id(); |
3715 $current_blog = get_current_blog_id(); |
3612 if ( $current_blog && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blog, array_keys( $blogs ) ) ) ) { |
3716 |
|
3717 if ( $current_blog && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blog, array_keys( $blogs ), true ) ) ) { |
3613 $url = admin_url( $path, $scheme ); |
3718 $url = admin_url( $path, $scheme ); |
3614 } else { |
3719 } else { |
3615 $active = get_active_blog_for_user( $user_id ); |
3720 $active = get_active_blog_for_user( $user_id ); |
3616 if ( $active ) { |
3721 if ( $active ) { |
3617 $url = get_admin_url( $active->blog_id, $path, $scheme ); |
3722 $url = get_admin_url( $active->blog_id, $path, $scheme ); |
3693 } |
3798 } |
3694 |
3799 |
3695 $canonical_url = get_permalink( $post ); |
3800 $canonical_url = get_permalink( $post ); |
3696 |
3801 |
3697 // If a canonical is being generated for the current page, make sure it has pagination if needed. |
3802 // If a canonical is being generated for the current page, make sure it has pagination if needed. |
3698 if ( $post->ID === get_queried_object_id() ) { |
3803 if ( get_queried_object_id() === $post->ID ) { |
3699 $page = get_query_var( 'page', 0 ); |
3804 $page = get_query_var( 'page', 0 ); |
3700 if ( $page >= 2 ) { |
3805 if ( $page >= 2 ) { |
3701 if ( '' == get_option( 'permalink_structure' ) ) { |
3806 if ( ! get_option( 'permalink_structure' ) ) { |
3702 $canonical_url = add_query_arg( 'page', $page, $canonical_url ); |
3807 $canonical_url = add_query_arg( 'page', $page, $canonical_url ); |
3703 } else { |
3808 } else { |
3704 $canonical_url = trailingslashit( $canonical_url ) . user_trailingslashit( $page, 'single_paged' ); |
3809 $canonical_url = trailingslashit( $canonical_url ) . user_trailingslashit( $page, 'single_paged' ); |
3705 } |
3810 } |
3706 } |
3811 } |
3755 * via the {@see 'pre_get_shortlink'} filter or filter the output via the {@see 'get_shortlink'} |
3860 * via the {@see 'pre_get_shortlink'} filter or filter the output via the {@see 'get_shortlink'} |
3756 * filter. |
3861 * filter. |
3757 * |
3862 * |
3758 * @since 3.0.0 |
3863 * @since 3.0.0 |
3759 * |
3864 * |
3760 * @param int $id Optional. A post or site id. Default is 0, which means the current post or site. |
3865 * @param int $id Optional. A post or site ID. Default is 0, which means the current post or site. |
3761 * @param string $context Optional. Whether the id is a 'site' id, 'post' id, or 'media' id. If 'post', |
3866 * @param string $context Optional. Whether the ID is a 'site' id, 'post' id, or 'media' id. If 'post', |
3762 * the post_type of the post is consulted. If 'query', the current query is consulted |
3867 * the post_type of the post is consulted. If 'query', the current query is consulted |
3763 * to determine the id and context. Default 'post'. |
3868 * to determine the ID and context. Default 'post'. |
3764 * @param bool $allow_slugs Optional. Whether to allow post slugs in the shortlink. It is up to the plugin how |
3869 * @param bool $allow_slugs Optional. Whether to allow post slugs in the shortlink. It is up to the plugin how |
3765 * and whether to honor this. Default true. |
3870 * and whether to honor this. Default true. |
3766 * @return string A shortlink or an empty string if no shortlink exists for the requested resource or if shortlinks |
3871 * @return string A shortlink or an empty string if no shortlink exists for the requested resource or if shortlinks |
3767 * are not enabled. |
3872 * are not enabled. |
3768 */ |
3873 */ |
3769 function wp_get_shortlink( $id = 0, $context = 'post', $allow_slugs = true ) { |
3874 function wp_get_shortlink( $id = 0, $context = 'post', $allow_slugs = true ) { |
3770 /** |
3875 /** |
3771 * Filters whether to preempt generating a shortlink for the given post. |
3876 * Filters whether to preempt generating a shortlink for the given post. |
3772 * |
3877 * |
3773 * Passing a truthy value to the filter will effectively short-circuit the |
3878 * Returning a truthy value from the filter will effectively short-circuit |
3774 * shortlink-generation process, returning that value instead. |
3879 * the shortlink generation process, returning that value instead. |
3775 * |
3880 * |
3776 * @since 3.0.0 |
3881 * @since 3.0.0 |
3777 * |
3882 * |
3778 * @param bool|string $return Short-circuit return value. Either false or a URL string. |
3883 * @param false|string $return Short-circuit return value. Either false or a URL string. |
3779 * @param int $id Post ID, or 0 for the current post. |
3884 * @param int $id Post ID, or 0 for the current post. |
3780 * @param string $context The context for the link. One of 'post' or 'query', |
3885 * @param string $context The context for the link. One of 'post' or 'query', |
3781 * @param bool $allow_slugs Whether to allow post slugs in the shortlink. |
3886 * @param bool $allow_slugs Whether to allow post slugs in the shortlink. |
3782 */ |
3887 */ |
3783 $shortlink = apply_filters( 'pre_get_shortlink', false, $id, $context, $allow_slugs ); |
3888 $shortlink = apply_filters( 'pre_get_shortlink', false, $id, $context, $allow_slugs ); |
3784 |
3889 |
3785 if ( false !== $shortlink ) { |
3890 if ( false !== $shortlink ) { |
3786 return $shortlink; |
3891 return $shortlink; |
3787 } |
3892 } |
3788 |
3893 |
3789 $post_id = 0; |
3894 $post_id = 0; |
3790 if ( 'query' == $context && is_singular() ) { |
3895 if ( 'query' === $context && is_singular() ) { |
3791 $post_id = get_queried_object_id(); |
3896 $post_id = get_queried_object_id(); |
3792 $post = get_post( $post_id ); |
3897 $post = get_post( $post_id ); |
3793 } elseif ( 'post' == $context ) { |
3898 } elseif ( 'post' === $context ) { |
3794 $post = get_post( $id ); |
3899 $post = get_post( $id ); |
3795 if ( ! empty( $post->ID ) ) { |
3900 if ( ! empty( $post->ID ) ) { |
3796 $post_id = $post->ID; |
3901 $post_id = $post->ID; |
3797 } |
3902 } |
3798 } |
3903 } |
3799 |
3904 |
3800 $shortlink = ''; |
3905 $shortlink = ''; |
3801 |
3906 |
3802 // Return p= link for all public post types. |
3907 // Return `?p=` link for all public post types. |
3803 if ( ! empty( $post_id ) ) { |
3908 if ( ! empty( $post_id ) ) { |
3804 $post_type = get_post_type_object( $post->post_type ); |
3909 $post_type = get_post_type_object( $post->post_type ); |
3805 |
3910 |
3806 if ( 'page' === $post->post_type && $post->ID == get_option( 'page_on_front' ) && 'page' == get_option( 'show_on_front' ) ) { |
3911 if ( 'page' === $post->post_type && get_option( 'page_on_front' ) == $post->ID && 'page' === get_option( 'show_on_front' ) ) { |
3807 $shortlink = home_url( '/' ); |
3912 $shortlink = home_url( '/' ); |
3808 } elseif ( $post_type->public ) { |
3913 } elseif ( $post_type->public ) { |
3809 $shortlink = home_url( '?p=' . $post_id ); |
3914 $shortlink = home_url( '?p=' . $post_id ); |
3810 } |
3915 } |
3811 } |
3916 } |
3930 * @type string $scheme URL scheme to use. See set_url_scheme() for accepted values. |
4035 * @type string $scheme URL scheme to use. See set_url_scheme() for accepted values. |
3931 * Default null. |
4036 * Default null. |
3932 * @type array $processed_args When the function returns, the value will be the processed/sanitized $args |
4037 * @type array $processed_args When the function returns, the value will be the processed/sanitized $args |
3933 * plus a "found_avatar" guess. Pass as a reference. Default null. |
4038 * plus a "found_avatar" guess. Pass as a reference. Default null. |
3934 * } |
4039 * } |
3935 * @return false|string The URL of the avatar we found, or false if we couldn't find an avatar. |
4040 * @return string|false The URL of the avatar on success, false on failure. |
3936 */ |
4041 */ |
3937 function get_avatar_url( $id_or_email, $args = null ) { |
4042 function get_avatar_url( $id_or_email, $args = null ) { |
3938 $args = get_avatar_data( $id_or_email, $args ); |
4043 $args = get_avatar_data( $id_or_email, $args ); |
3939 return $args['url']; |
4044 return $args['url']; |
3940 } |
4045 } |
3965 /** |
4070 /** |
3966 * Retrieves default data about the avatar. |
4071 * Retrieves default data about the avatar. |
3967 * |
4072 * |
3968 * @since 4.2.0 |
4073 * @since 4.2.0 |
3969 * |
4074 * |
3970 * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash, |
4075 * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash, |
3971 * user email, WP_User object, WP_Post object, or WP_Comment object. |
4076 * user email, WP_User object, WP_Post object, or WP_Comment object. |
3972 * @param array $args { |
4077 * @param array $args { |
3973 * Optional. Arguments to return instead of the default arguments. |
4078 * Optional. Arguments to return instead of the default arguments. |
3974 * |
4079 * |
3975 * @type int $size Height and width of the avatar image file in pixels. Default 96. |
4080 * @type int $size Height and width of the avatar image file in pixels. Default 96. |
3976 * @type int $height Display height of the avatar in pixels. Defaults to $size. |
4081 * @type int $height Display height of the avatar in pixels. Defaults to $size. |
3988 * Default null. |
4093 * Default null. |
3989 * @type array $processed_args When the function returns, the value will be the processed/sanitized $args |
4094 * @type array $processed_args When the function returns, the value will be the processed/sanitized $args |
3990 * plus a "found_avatar" guess. Pass as a reference. Default null. |
4095 * plus a "found_avatar" guess. Pass as a reference. Default null. |
3991 * @type string $extra_attr HTML attributes to insert in the IMG element. Is not sanitized. Default empty. |
4096 * @type string $extra_attr HTML attributes to insert in the IMG element. Is not sanitized. Default empty. |
3992 * } |
4097 * } |
3993 * @return array $processed_args { |
4098 * @return array { |
3994 * Along with the arguments passed in `$args`, this will contain a couple of extra arguments. |
4099 * Along with the arguments passed in `$args`, this will contain a couple of extra arguments. |
3995 * |
4100 * |
3996 * @type bool $found_avatar True if we were able to find an avatar for this user, |
4101 * @type bool $found_avatar True if we were able to find an avatar for this user, |
3997 * false or not set if we couldn't. |
4102 * false or not set if we couldn't. |
3998 * @type string $url The URL of the avatar we found. |
4103 * @type string $url The URL of the avatar we found. |
4069 * effectively short circuit get_avatar_data(), passing the value through |
4174 * effectively short circuit get_avatar_data(), passing the value through |
4070 * the {@see 'get_avatar_data'} filter and returning early. |
4175 * the {@see 'get_avatar_data'} filter and returning early. |
4071 * |
4176 * |
4072 * @since 4.2.0 |
4177 * @since 4.2.0 |
4073 * |
4178 * |
4074 * @param array $args Arguments passed to get_avatar_data(), after processing. |
4179 * @param array $args Arguments passed to get_avatar_data(), after processing. |
4075 * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash, |
4180 * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash, |
4076 * user email, WP_User object, WP_Post object, or WP_Comment object. |
4181 * user email, WP_User object, WP_Post object, or WP_Comment object. |
4077 */ |
4182 */ |
4078 $args = apply_filters( 'pre_get_avatar_data', $args, $id_or_email ); |
4183 $args = apply_filters( 'pre_get_avatar_data', $args, $id_or_email ); |
4079 |
4184 |
4080 if ( isset( $args['url'] ) ) { |
4185 if ( isset( $args['url'] ) ) { |
4081 /** This filter is documented in wp-includes/link-template.php */ |
4186 /** This filter is documented in wp-includes/link-template.php */ |
4082 return apply_filters( 'get_avatar_data', $args, $id_or_email ); |
4187 return apply_filters( 'get_avatar_data', $args, $id_or_email ); |
4083 } |
4188 } |
4084 |
4189 |
4085 $email_hash = ''; |
4190 $email_hash = ''; |
4086 $user = $email = false; |
4191 $user = false; |
|
4192 $email = false; |
4087 |
4193 |
4088 if ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) { |
4194 if ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) { |
4089 $id_or_email = get_comment( $id_or_email ); |
4195 $id_or_email = get_comment( $id_or_email ); |
4090 } |
4196 } |
4091 |
4197 |
4092 // Process the user identifier. |
4198 // Process the user identifier. |
4093 if ( is_numeric( $id_or_email ) ) { |
4199 if ( is_numeric( $id_or_email ) ) { |
4094 $user = get_user_by( 'id', absint( $id_or_email ) ); |
4200 $user = get_user_by( 'id', absint( $id_or_email ) ); |
4095 } elseif ( is_string( $id_or_email ) ) { |
4201 } elseif ( is_string( $id_or_email ) ) { |
4096 if ( strpos( $id_or_email, '@md5.gravatar.com' ) ) { |
4202 if ( strpos( $id_or_email, '@md5.gravatar.com' ) ) { |
4097 // md5 hash |
4203 // MD5 hash. |
4098 list( $email_hash ) = explode( '@', $id_or_email ); |
4204 list( $email_hash ) = explode( '@', $id_or_email ); |
4099 } else { |
4205 } else { |
4100 // email address |
4206 // Email address. |
4101 $email = $id_or_email; |
4207 $email = $id_or_email; |
4102 } |
4208 } |
4103 } elseif ( $id_or_email instanceof WP_User ) { |
4209 } elseif ( $id_or_email instanceof WP_User ) { |
4104 // User Object |
4210 // User object. |
4105 $user = $id_or_email; |
4211 $user = $id_or_email; |
4106 } elseif ( $id_or_email instanceof WP_Post ) { |
4212 } elseif ( $id_or_email instanceof WP_Post ) { |
4107 // Post Object |
4213 // Post object. |
4108 $user = get_user_by( 'id', (int) $id_or_email->post_author ); |
4214 $user = get_user_by( 'id', (int) $id_or_email->post_author ); |
4109 } elseif ( $id_or_email instanceof WP_Comment ) { |
4215 } elseif ( $id_or_email instanceof WP_Comment ) { |
4110 if ( ! is_avatar_comment_type( get_comment_type( $id_or_email ) ) ) { |
4216 if ( ! is_avatar_comment_type( get_comment_type( $id_or_email ) ) ) { |
4111 $args['url'] = false; |
4217 $args['url'] = false; |
4112 /** This filter is documented in wp-includes/link-template.php */ |
4218 /** This filter is documented in wp-includes/link-template.php */ |
4160 * Filters the avatar URL. |
4266 * Filters the avatar URL. |
4161 * |
4267 * |
4162 * @since 4.2.0 |
4268 * @since 4.2.0 |
4163 * |
4269 * |
4164 * @param string $url The URL of the avatar. |
4270 * @param string $url The URL of the avatar. |
4165 * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash, |
4271 * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash, |
4166 * user email, WP_User object, WP_Post object, or WP_Comment object. |
4272 * user email, WP_User object, WP_Post object, or WP_Comment object. |
4167 * @param array $args Arguments passed to get_avatar_data(), after processing. |
4273 * @param array $args Arguments passed to get_avatar_data(), after processing. |
4168 */ |
4274 */ |
4169 $args['url'] = apply_filters( 'get_avatar_url', $url, $id_or_email, $args ); |
4275 $args['url'] = apply_filters( 'get_avatar_url', $url, $id_or_email, $args ); |
4170 |
4276 |
4171 /** |
4277 /** |
4172 * Filters the avatar data. |
4278 * Filters the avatar data. |
4173 * |
4279 * |
4174 * @since 4.2.0 |
4280 * @since 4.2.0 |
4175 * |
4281 * |
4176 * @param array $args Arguments passed to get_avatar_data(), after processing. |
4282 * @param array $args Arguments passed to get_avatar_data(), after processing. |
4177 * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash, |
4283 * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash, |
4178 * user email, WP_User object, WP_Post object, or WP_Comment object. |
4284 * user email, WP_User object, WP_Post object, or WP_Comment object. |
4179 */ |
4285 */ |
4180 return apply_filters( 'get_avatar_data', $args, $id_or_email ); |
4286 return apply_filters( 'get_avatar_data', $args, $id_or_email ); |
4181 } |
4287 } |
4182 |
4288 |
4183 /** |
4289 /** |