44
44
* for use in the filter. Default empty string.
45
45
* @return string The URL with the trailing slash appended or stripped.
47
function user_trailingslashit($string, $type_of_url = '') {
47
function user_trailingslashit( $string, $type_of_url = '' ) {
48
48
global $wp_rewrite;
49
if ( $wp_rewrite->use_trailing_slashes )
50
$string = trailingslashit($string);
52
$string = untrailingslashit($string);
49
if ( $wp_rewrite->use_trailing_slashes ) {
50
$string = trailingslashit( $string );
52
$string = untrailingslashit( $string );
55
56
* Filters the trailing-slashed string, depending on whether the site is set to use trailing slashes.
126
$leavename? '' : '%postname%',
127
$leavename ? '' : '%postname%',
130
$leavename? '' : '%pagename%',
131
$leavename ? '' : '%pagename%',
133
134
if ( is_object( $post ) && isset( $post->filter ) && 'sample' == $post->filter ) {
136
$post = get_post( $post );
137
$post = get_post( $post );
140
if ( empty($post->ID) )
141
if ( empty( $post->ID ) ) {
143
if ( $post->post_type == 'page' )
144
return get_page_link($post, $leavename, $sample);
145
elseif ( $post->post_type == 'attachment' )
145
if ( $post->post_type == 'page' ) {
146
return get_page_link( $post, $leavename, $sample );
147
} elseif ( $post->post_type == 'attachment' ) {
146
148
return get_attachment_link( $post, $leavename );
147
elseif ( in_array($post->post_type, get_post_types( array('_builtin' => false) ) ) )
148
return get_post_permalink($post, $leavename, $sample);
149
} elseif ( in_array( $post->post_type, get_post_types( array( '_builtin' => false ) ) ) ) {
150
return get_post_permalink( $post, $leavename, $sample );
150
$permalink = get_option('permalink_structure');
153
$permalink = get_option( 'permalink_structure' );
153
156
* Filters the permalink structure for a post before token replacement occurs.
163
166
$permalink = apply_filters( 'pre_post_link', $permalink, $post, $leavename );
165
if ( '' != $permalink && !in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ) ) ) {
166
$unixtime = strtotime($post->post_date);
168
if ( '' != $permalink && ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ) ) ) {
169
$unixtime = strtotime( $post->post_date );
169
if ( strpos($permalink, '%category%') !== false ) {
170
$cats = get_the_category($post->ID);
172
if ( strpos( $permalink, '%category%' ) !== false ) {
173
$cats = get_the_category( $post->ID );
172
$cats = wp_list_sort( $cats, array(
175
$cats = wp_list_sort(
177
183
* Filters the category that gets used in the %category% permalink token.
185
191
$category_object = apply_filters( 'post_link_category', $cats[0], $cats, $post );
187
193
$category_object = get_term( $category_object, 'category' );
188
$category = $category_object->slug;
189
if ( $parent = $category_object->parent )
190
$category = get_category_parents($parent, false, '/', true) . $category;
194
$category = $category_object->slug;
195
if ( $category_object->parent ) {
196
$category = get_category_parents( $category_object->parent, false, '/', true ) . $category;
192
199
// show default category in permalinks, without
193
200
// having to assign it explicitly
194
if ( empty($category) ) {
201
if ( empty( $category ) ) {
195
202
$default_category = get_term( get_option( 'default_category' ), 'category' );
196
203
if ( $default_category && ! is_wp_error( $default_category ) ) {
197
204
$category = $default_category->slug;
255
262
function get_post_permalink( $id = 0, $leavename = false, $sample = false ) {
256
263
global $wp_rewrite;
258
$post = get_post($id);
265
$post = get_post( $id );
260
if ( is_wp_error( $post ) )
267
if ( is_wp_error( $post ) ) {
263
$post_link = $wp_rewrite->get_extra_permastruct($post->post_type);
271
$post_link = $wp_rewrite->get_extra_permastruct( $post->post_type );
265
273
$slug = $post->post_name;
267
275
$draft_or_pending = get_post_status( $post ) && in_array( get_post_status( $post ), array( 'draft', 'pending', 'auto-draft', 'future' ) );
269
$post_type = get_post_type_object($post->post_type);
277
$post_type = get_post_type_object( $post->post_type );
271
279
if ( $post_type->hierarchical ) {
272
280
$slug = get_page_uri( $post );
275
if ( !empty($post_link) && ( !$draft_or_pending || $sample ) ) {
283
if ( ! empty( $post_link ) && ( ! $draft_or_pending || $sample ) ) {
276
284
if ( ! $leavename ) {
277
$post_link = str_replace("%$post->post_type%", $slug, $post_link);
285
$post_link = str_replace( "%$post->post_type%", $slug, $post_link );
279
$post_link = home_url( user_trailingslashit($post_link) );
287
$post_link = home_url( user_trailingslashit( $post_link ) );
281
if ( $post_type->query_var && ( isset($post->post_status) && !$draft_or_pending ) )
282
$post_link = add_query_arg($post_type->query_var, $slug, '');
284
$post_link = add_query_arg(array('post_type' => $post->post_type, 'p' => $post->ID), '');
285
$post_link = home_url($post_link);
289
if ( $post_type->query_var && ( isset( $post->post_status ) && ! $draft_or_pending ) ) {
290
$post_link = add_query_arg( $post_type->query_var, $slug, '' );
292
$post_link = add_query_arg(
294
'post_type' => $post->post_type,
300
$post_link = home_url( $post_link );
357
373
$link = $wp_rewrite->get_page_permastruct();
359
if ( !empty($link) && ( ( isset($post->post_status) && !$draft_or_pending ) || $sample ) ) {
375
if ( ! empty( $link ) && ( ( isset( $post->post_status ) && ! $draft_or_pending ) || $sample ) ) {
360
376
if ( ! $leavename ) {
361
$link = str_replace('%pagename%', get_page_uri( $post ), $link);
377
$link = str_replace( '%pagename%', get_page_uri( $post ), $link );
364
$link = home_url($link);
365
$link = user_trailingslashit($link, 'page');
380
$link = home_url( $link );
381
$link = user_trailingslashit( $link, 'page' );
367
383
$link = home_url( '?page_id=' . $post->ID );
399
$post = get_post( $post );
415
$post = get_post( $post );
400
416
$parent = ( $post->post_parent > 0 && $post->post_parent != $post->ID ) ? get_post( $post->post_parent ) : false;
401
417
if ( $parent && ! in_array( $parent->post_type, get_post_types() ) ) {
405
421
if ( $wp_rewrite->using_permalinks() && $parent ) {
406
if ( 'page' == $parent->post_type )
422
if ( 'page' == $parent->post_type ) {
407
423
$parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front
409
425
$parentlink = get_permalink( $post->post_parent );
411
if ( is_numeric($post->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') )
428
if ( is_numeric( $post->post_name ) || false !== strpos( get_option( 'permalink_structure' ), '%category%' ) ) {
412
429
$name = 'attachment/' . $post->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker
414
431
$name = $post->post_name;
416
if ( strpos($parentlink, '?') === false )
417
$link = user_trailingslashit( trailingslashit($parentlink) . '%postname%' );
434
if ( strpos( $parentlink, '?' ) === false ) {
435
$link = user_trailingslashit( trailingslashit( $parentlink ) . '%postname%' );
438
if ( ! $leavename ) {
420
439
$link = str_replace( '%postname%', $name, $link );
421
441
} elseif ( $wp_rewrite->using_permalinks() && ! $leavename ) {
422
442
$link = home_url( user_trailingslashit( $post->post_name ) );
426
446
$link = home_url( '/?attachment_id=' . $post->ID );
429
450
* Filters the permalink for an attachment.
449
470
function get_year_link( $year ) {
450
471
global $wp_rewrite;
452
$year = gmdate('Y', current_time('timestamp'));
473
$year = gmdate( 'Y', current_time( 'timestamp' ) );
453
475
$yearlink = $wp_rewrite->get_year_permastruct();
454
if ( !empty($yearlink) ) {
455
$yearlink = str_replace('%year%', $year, $yearlink);
476
if ( ! empty( $yearlink ) ) {
477
$yearlink = str_replace( '%year%', $year, $yearlink );
456
478
$yearlink = home_url( user_trailingslashit( $yearlink, 'year' ) );
458
480
$yearlink = home_url( '?m=' . $year );
480
502
* @param bool|int $month False for current month. Integer of month.
481
503
* @return string The permalink for the specified month and year archive.
483
function get_month_link($year, $month) {
505
function get_month_link( $year, $month ) {
484
506
global $wp_rewrite;
486
$year = gmdate('Y', current_time('timestamp'));
488
$month = gmdate('m', current_time('timestamp'));
508
$year = gmdate( 'Y', current_time( 'timestamp' ) );
511
$month = gmdate( 'm', current_time( 'timestamp' ) );
489
513
$monthlink = $wp_rewrite->get_month_permastruct();
490
if ( !empty($monthlink) ) {
491
$monthlink = str_replace('%year%', $year, $monthlink);
492
$monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
514
if ( ! empty( $monthlink ) ) {
515
$monthlink = str_replace( '%year%', $year, $monthlink );
516
$monthlink = str_replace( '%monthnum%', zeroise( intval( $month ), 2 ), $monthlink );
493
517
$monthlink = home_url( user_trailingslashit( $monthlink, 'month' ) );
495
519
$monthlink = home_url( '?m=' . $year . zeroise( $month, 2 ) );
519
543
* @param bool|int $day False for current day. Integer of day.
520
544
* @return string The permalink for the specified day, month, and year archive.
522
function get_day_link($year, $month, $day) {
546
function get_day_link( $year, $month, $day ) {
523
547
global $wp_rewrite;
525
$year = gmdate('Y', current_time('timestamp'));
527
$month = gmdate('m', current_time('timestamp'));
529
$day = gmdate('j', current_time('timestamp'));
549
$year = gmdate( 'Y', current_time( 'timestamp' ) );
552
$month = gmdate( 'm', current_time( 'timestamp' ) );
555
$day = gmdate( 'j', current_time( 'timestamp' ) );
531
558
$daylink = $wp_rewrite->get_day_permastruct();
532
if ( !empty($daylink) ) {
533
$daylink = str_replace('%year%', $year, $daylink);
534
$daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
535
$daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
559
if ( ! empty( $daylink ) ) {
560
$daylink = str_replace( '%year%', $year, $daylink );
561
$daylink = str_replace( '%monthnum%', zeroise( intval( $month ), 2 ), $daylink );
562
$daylink = str_replace( '%day%', zeroise( intval( $day ), 2 ), $daylink );
536
563
$daylink = home_url( user_trailingslashit( $daylink, 'day' ) );
538
565
$daylink = home_url( '?m=' . $year . zeroise( $month, 2 ) . zeroise( $day, 2 ) );
590
617
$permalink = $wp_rewrite->get_feed_permastruct();
591
618
if ( '' != $permalink ) {
592
if ( false !== strpos($feed, 'comments_') ) {
593
$feed = str_replace('comments_', '', $feed);
619
if ( false !== strpos( $feed, 'comments_' ) ) {
620
$feed = str_replace( 'comments_', '', $feed );
594
621
$permalink = $wp_rewrite->get_comment_feed_permastruct();
597
if ( get_default_feed() == $feed )
624
if ( get_default_feed() == $feed ) {
600
$permalink = str_replace('%feed%', $feed, $permalink);
601
$permalink = preg_replace('#/+#', '/', "/$permalink");
602
$output = home_url( user_trailingslashit($permalink, 'feed') );
628
$permalink = str_replace( '%feed%', $feed, $permalink );
629
$permalink = preg_replace( '#/+#', '/', "/$permalink" );
630
$output = home_url( user_trailingslashit( $permalink, 'feed' ) );
632
if ( empty( $feed ) ) {
605
633
$feed = get_default_feed();
607
if ( false !== strpos($feed, 'comments_') )
608
$feed = str_replace('comments_', 'comments-', $feed);
610
$output = home_url("?feed={$feed}");
636
if ( false !== strpos( $feed, 'comments_' ) ) {
637
$feed = str_replace( 'comments_', 'comments-', $feed );
640
$output = home_url( "?feed={$feed}" );
633
663
function get_post_comments_feed_link( $post_id = 0, $feed = '' ) {
634
664
$post_id = absint( $post_id );
637
667
$post_id = get_the_ID();
639
if ( empty( $feed ) )
670
if ( empty( $feed ) ) {
640
671
$feed = get_default_feed();
642
$post = get_post( $post_id );
674
$post = get_post( $post_id );
643
675
$unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent;
645
if ( '' != get_option('permalink_structure') ) {
646
if ( 'page' == get_option('show_on_front') && $post_id == get_option('page_on_front') )
677
if ( '' != get_option( 'permalink_structure' ) ) {
678
if ( 'page' == get_option( 'show_on_front' ) && $post_id == get_option( 'page_on_front' ) ) {
647
679
$url = _get_page_link( $post_id );
649
$url = get_permalink($post_id);
681
$url = get_permalink( $post_id );
651
684
if ( $unattached ) {
652
$url = home_url( '/feed/' );
685
$url = home_url( '/feed/' );
653
686
if ( $feed !== get_default_feed() ) {
654
687
$url .= "$feed/";
656
689
$url = add_query_arg( 'attachment_id', $post_id, $url );
658
$url = trailingslashit($url) . 'feed';
659
if ( $feed != get_default_feed() )
691
$url = trailingslashit( $url ) . 'feed';
692
if ( $feed != get_default_feed() ) {
660
693
$url .= "/$feed";
661
$url = user_trailingslashit($url, 'single_feed');
695
$url = user_trailingslashit( $url, 'single_feed' );
664
698
if ( $unattached ) {
665
$url = add_query_arg( array( 'feed' => $feed, 'attachment_id' => $post_id ), home_url( '/' ) );
699
$url = add_query_arg(
702
'attachment_id' => $post_id,
666
706
} elseif ( 'page' == $post->post_type ) {
667
$url = add_query_arg( array( 'feed' => $feed, 'page_id' => $post_id ), home_url( '/' ) );
707
$url = add_query_arg(
710
'page_id' => $post_id,
669
$url = add_query_arg( array( 'feed' => $feed, 'p' => $post_id ), home_url( '/' ) );
715
$url = add_query_arg(
725
777
* @return string Link to the feed for the author specified by $author_id.
727
779
function get_author_feed_link( $author_id, $feed = '' ) {
728
$author_id = (int) $author_id;
729
$permalink_structure = get_option('permalink_structure');
780
$author_id = (int) $author_id;
781
$permalink_structure = get_option( 'permalink_structure' );
783
if ( empty( $feed ) ) {
732
784
$feed = get_default_feed();
734
787
if ( '' == $permalink_structure ) {
735
$link = home_url("?feed=$feed&author=" . $author_id);
788
$link = home_url( "?feed=$feed&author=" . $author_id );
737
$link = get_author_posts_url($author_id);
738
if ( $feed == get_default_feed() )
790
$link = get_author_posts_url( $author_id );
791
if ( $feed == get_default_feed() ) {
739
792
$feed_link = 'feed';
741
794
$feed_link = "feed/$feed";
743
$link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
797
$link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' );
786
840
* @return string|false Link to the feed for the term specified by $term_id and $taxonomy.
788
842
function get_term_feed_link( $term_id, $taxonomy = 'category', $feed = '' ) {
789
$term_id = ( int ) $term_id;
791
$term = get_term( $term_id, $taxonomy );
793
if ( empty( $term ) || is_wp_error( $term ) )
843
$term_id = (int) $term_id;
845
$term = get_term( $term_id, $taxonomy );
847
if ( empty( $term ) || is_wp_error( $term ) ) {
796
if ( empty( $feed ) )
851
if ( empty( $feed ) ) {
797
852
$feed = get_default_feed();
799
855
$permalink_structure = get_option( 'permalink_structure' );
801
857
if ( '' == $permalink_structure ) {
802
858
if ( 'category' == $taxonomy ) {
803
$link = home_url("?feed=$feed&cat=$term_id");
805
elseif ( 'post_tag' == $taxonomy ) {
806
$link = home_url("?feed=$feed&tag=$term->slug");
859
$link = home_url( "?feed=$feed&cat=$term_id" );
860
} elseif ( 'post_tag' == $taxonomy ) {
861
$link = home_url( "?feed=$feed&tag=$term->slug" );
808
$t = get_taxonomy( $taxonomy );
809
$link = home_url("?feed=$feed&$t->query_var=$term->slug");
863
$t = get_taxonomy( $taxonomy );
864
$link = home_url( "?feed=$feed&$t->query_var=$term->slug" );
812
867
$link = get_term_link( $term_id, $term->taxonomy );
813
if ( $feed == get_default_feed() )
868
if ( $feed == get_default_feed() ) {
814
869
$feed_link = 'feed';
816
871
$feed_link = "feed/$feed";
818
874
$link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' );
979
1035
* @return string|void HTML content.
981
1037
function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) {
982
if ( is_null( $term ) )
1038
if ( is_null( $term ) ) {
983
1039
$term = get_queried_object();
988
1046
$tax = get_taxonomy( $term->taxonomy );
989
1047
if ( ! current_user_can( 'edit_term', $term->term_id ) ) {
993
if ( empty( $link ) )
994
$link = __('Edit This');
1051
if ( empty( $link ) ) {
1052
$link = __( 'Edit This' );
996
1055
$link = '<a href="' . get_edit_term_link( $term->term_id, $term->taxonomy ) . '">' . $link . '</a>';
1024
1084
function get_search_link( $query = '' ) {
1025
1085
global $wp_rewrite;
1027
if ( empty($query) )
1087
if ( empty( $query ) ) {
1028
1088
$search = get_search_query( false );
1030
$search = stripslashes($query);
1090
$search = stripslashes( $query );
1032
1093
$permastruct = $wp_rewrite->get_search_permastruct();
1034
1095
if ( empty( $permastruct ) ) {
1035
$link = home_url('?s=' . urlencode($search) );
1096
$link = home_url( '?s=' . urlencode( $search ) );
1037
$search = urlencode($search);
1038
$search = str_replace('%2F', '/', $search); // %2F(/) is not valid within a URL, send it un-encoded.
1039
$link = str_replace( '%search%', $search, $permastruct );
1040
$link = home_url( user_trailingslashit( $link, 'search' ) );
1098
$search = urlencode( $search );
1099
$search = str_replace( '%2F', '/', $search ); // %2F(/) is not valid within a URL, send it un-encoded.
1100
$link = str_replace( '%search%', $search, $permastruct );
1101
$link = home_url( user_trailingslashit( $link, 'search' ) );
1062
1123
* @param string $feed Optional. Feed type. Default empty.
1063
1124
* @return string The search results feed permalink.
1065
function get_search_feed_link($search_query = '', $feed = '') {
1126
function get_search_feed_link( $search_query = '', $feed = '' ) {
1066
1127
global $wp_rewrite;
1067
$link = get_search_link($search_query);
1128
$link = get_search_link( $search_query );
1130
if ( empty( $feed ) ) {
1070
1131
$feed = get_default_feed();
1072
1134
$permastruct = $wp_rewrite->get_search_permastruct();
1074
if ( empty($permastruct) ) {
1075
$link = add_query_arg('feed', $feed, $link);
1136
if ( empty( $permastruct ) ) {
1137
$link = add_query_arg( 'feed', $feed, $link );
1077
$link = trailingslashit($link);
1139
$link = trailingslashit( $link );
1078
1140
$link .= "feed/$feed/";
1101
1163
* @param string $feed Optional. Feed type. Default empty.
1102
1164
* @return string The comments feed search results permalink.
1104
function get_search_comments_feed_link($search_query = '', $feed = '') {
1166
function get_search_comments_feed_link( $search_query = '', $feed = '' ) {
1105
1167
global $wp_rewrite;
1169
if ( empty( $feed ) ) {
1108
1170
$feed = get_default_feed();
1110
$link = get_search_feed_link($search_query, $feed);
1173
$link = get_search_feed_link( $search_query, $feed );
1112
1175
$permastruct = $wp_rewrite->get_search_permastruct();
1114
if ( empty($permastruct) )
1115
$link = add_query_arg('feed', 'comments-' . $feed, $link);
1117
$link = add_query_arg('withcomments', 1, $link);
1177
if ( empty( $permastruct ) ) {
1178
$link = add_query_arg( 'feed', 'comments-' . $feed, $link );
1180
$link = add_query_arg( 'withcomments', 1, $link );
1119
1183
/** This filter is documented in wp-includes/link-template.php */
1120
1184
return apply_filters( 'search_feed_link', $link, $feed, 'comments' );
1149
1214
return apply_filters( 'post_type_archive_link', $link, $post_type );
1152
if ( ! $post_type_obj->has_archive )
1217
if ( ! $post_type_obj->has_archive ) {
1155
1221
if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) ) {
1156
1222
$struct = ( true === $post_type_obj->has_archive ) ? $post_type_obj->rewrite['slug'] : $post_type_obj->has_archive;
1157
if ( $post_type_obj->rewrite['with_front'] )
1223
if ( $post_type_obj->rewrite['with_front'] ) {
1158
1224
$struct = $wp_rewrite->front . $struct;
1160
1226
$struct = $wp_rewrite->root . $struct;
1161
1228
$link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) );
1163
1230
$link = home_url( '?post_type=' . $post_type );
1186
1253
function get_post_type_archive_feed_link( $post_type, $feed = '' ) {
1187
1254
$default_feed = get_default_feed();
1188
if ( empty( $feed ) )
1255
if ( empty( $feed ) ) {
1189
1256
$feed = $default_feed;
1191
if ( ! $link = get_post_type_archive_link( $post_type ) )
1259
if ( ! $link = get_post_type_archive_link( $post_type ) ) {
1194
1263
$post_type_obj = get_post_type_object( $post_type );
1195
1264
if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) && $post_type_obj->rewrite['feeds'] ) {
1196
$link = trailingslashit( $link );
1265
$link = trailingslashit( $link );
1197
1266
$link .= 'feed/';
1198
if ( $feed != $default_feed )
1267
if ( $feed != $default_feed ) {
1199
1268
$link .= "$feed/";
1201
1271
$link = add_query_arg( 'feed', $feed, $link );
1268
1338
* not allow an editing UI.
1270
1340
function get_edit_post_link( $id = 0, $context = 'display' ) {
1271
if ( ! $post = get_post( $id ) )
1341
if ( ! $post = get_post( $id ) ) {
1274
if ( 'revision' === $post->post_type )
1345
if ( 'revision' === $post->post_type ) {
1276
elseif ( 'display' == $context )
1347
} elseif ( 'display' == $context ) {
1277
1348
$action = '&action=edit';
1279
1350
$action = '&action=edit';
1281
1353
$post_type_object = get_post_type_object( $post->post_type );
1282
if ( !$post_type_object )
1354
if ( ! $post_type_object ) {
1285
if ( !current_user_can( 'edit_post', $post->ID ) )
1358
if ( ! current_user_can( 'edit_post', $post->ID ) ) {
1288
1362
if ( $post_type_object->_edit_link ) {
1289
1363
$link = admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) );
1356
1430
* @return string|void The delete post link URL for the given post.
1358
1432
function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) {
1359
if ( ! empty( $deprecated ) )
1433
if ( ! empty( $deprecated ) ) {
1360
1434
_deprecated_argument( __FUNCTION__, '3.0.0' );
1362
if ( !$post = get_post( $id ) )
1437
if ( ! $post = get_post( $id ) ) {
1365
1441
$post_type_object = get_post_type_object( $post->post_type );
1366
if ( !$post_type_object )
1369
if ( !current_user_can( 'delete_post', $post->ID ) )
1372
$action = ( $force_delete || !EMPTY_TRASH_DAYS ) ? 'delete' : 'trash';
1442
if ( ! $post_type_object ) {
1446
if ( ! current_user_can( 'delete_post', $post->ID ) ) {
1450
$action = ( $force_delete || ! EMPTY_TRASH_DAYS ) ? 'delete' : 'trash';
1374
1452
$delete_link = add_query_arg( 'action', $action, admin_url( sprintf( $post_type_object->_edit_link, $post->ID ) ) );
1513
1595
* @return string URL to edit user page or empty string.
1515
1597
function get_edit_user_link( $user_id = null ) {
1517
1599
$user_id = get_current_user_id();
1519
if ( empty( $user_id ) || ! current_user_can( 'edit_user', $user_id ) )
1602
if ( empty( $user_id ) || ! current_user_can( 'edit_user', $user_id ) ) {
1522
1606
$user = get_userdata( $user_id );
1527
if ( get_current_user_id() == $user->ID )
1612
if ( get_current_user_id() == $user->ID ) {
1528
1613
$link = get_edit_profile_url( $user->ID );
1530
1615
$link = add_query_arg( 'user_id', $user->ID, self_admin_url( 'user-edit.php' ) );
1533
1619
* Filters the user edit link.
1591
1677
function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
1594
if ( ( ! $post = get_post() ) || ! taxonomy_exists( $taxonomy ) )
1680
if ( ( ! $post = get_post() ) || ! taxonomy_exists( $taxonomy ) ) {
1597
1684
$current_post_date = $post->post_date;
1601
1688
$adjacent = $previous ? 'previous' : 'next';
1690
if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) {
1691
// back-compat, $excluded_terms used to be $excluded_terms with IDs separated by " and "
1692
if ( false !== strpos( $excluded_terms, ' and ' ) ) {
1693
_deprecated_argument( __FUNCTION__, '3.3.0', sprintf( __( 'Use commas instead of %s to separate excluded terms.' ), "'and'" ) );
1694
$excluded_terms = explode( ' and ', $excluded_terms );
1696
$excluded_terms = explode( ',', $excluded_terms );
1699
$excluded_terms = array_map( 'intval', $excluded_terms );
1703
* Filters the IDs of terms excluded from adjacent post queries.
1705
* The dynamic portion of the hook name, `$adjacent`, refers to the type
1706
* of adjacency, 'next' or 'previous'.
1710
* @param array $excluded_terms Array of excluded term IDs.
1712
$excluded_terms = apply_filters( "get_{$adjacent}_post_excluded_terms", $excluded_terms );
1603
1714
if ( $in_same_term || ! empty( $excluded_terms ) ) {
1604
if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) {
1605
// back-compat, $excluded_terms used to be $excluded_terms with IDs separated by " and "
1606
if ( false !== strpos( $excluded_terms, ' and ' ) ) {
1607
_deprecated_argument( __FUNCTION__, '3.3.0', sprintf( __( 'Use commas instead of %s to separate excluded terms.' ), "'and'" ) );
1608
$excluded_terms = explode( ' and ', $excluded_terms );
1610
$excluded_terms = explode( ',', $excluded_terms );
1613
$excluded_terms = array_map( 'intval', $excluded_terms );
1616
1715
if ( $in_same_term ) {
1617
$join .= " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";
1618
$where .= $wpdb->prepare( "AND tt.taxonomy = %s", $taxonomy );
1716
$join .= " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";
1717
$where .= $wpdb->prepare( 'AND tt.taxonomy = %s', $taxonomy );
1620
if ( ! is_object_in_taxonomy( $post->post_type, $taxonomy ) )
1719
if ( ! is_object_in_taxonomy( $post->post_type, $taxonomy ) ) {
1622
1722
$term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
1624
1724
// Remove any exclusions from the term array to include.
1625
1725
$term_array = array_diff( $term_array, (array) $excluded_terms );
1626
1726
$term_array = array_map( 'intval', $term_array );
1628
if ( ! $term_array || is_wp_error( $term_array ) )
1728
if ( ! $term_array || is_wp_error( $term_array ) ) {
1631
$where .= " AND tt.term_id IN (" . implode( ',', $term_array ) . ")";
1732
$where .= ' AND tt.term_id IN (' . implode( ',', $term_array ) . ')';
1635
* Filters the IDs of terms excluded from adjacent post queries.
1637
* The dynamic portion of the hook name, `$adjacent`, refers to the type
1638
* of adjacency, 'next' or 'previous'.
1642
* @param string $excluded_terms Array of excluded term IDs.
1644
$excluded_terms = apply_filters( "get_{$adjacent}_post_excluded_terms", $excluded_terms );
1646
1735
if ( ! empty( $excluded_terms ) ) {
1647
1736
$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 ) ) . ') )';
1665
1754
* current user has the 'read_private_posts' cap.
1667
1756
$private_states = get_post_stati( array( 'private' => true ) );
1668
$where .= " AND ( p.post_status = 'publish'";
1757
$where .= " AND ( p.post_status = 'publish'";
1669
1758
foreach ( (array) $private_states as $state ) {
1670
1759
if ( current_user_can( $read_private_cap ) ) {
1671
$where .= $wpdb->prepare( " OR p.post_status = %s", $state );
1760
$where .= $wpdb->prepare( ' OR p.post_status = %s', $state );
1673
$where .= $wpdb->prepare( " OR (p.post_author = %d AND p.post_status = %s)", $user_id, $state );
1762
$where .= $wpdb->prepare( ' OR (p.post_author = %d AND p.post_status = %s)', $user_id, $state );
1678
1767
$where .= " AND p.post_status = 'publish'";
1681
$op = $previous ? '<' : '>';
1770
$op = $previous ? '<' : '>';
1682
1771
$order = $previous ? 'DESC' : 'ASC';
1729
1818
* @param WP_Post $post WP_Post object.
1730
1819
* @param string $order Sort order. 'DESC' for previous post, 'ASC' for next.
1732
$sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1", $post, $order );
1821
$sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1", $post, $order );
1734
$query = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort";
1823
$query = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort";
1735
1824
$query_key = 'adjacent_post_' . md5( $query );
1736
$result = wp_cache_get( $query_key, 'counts' );
1825
$result = wp_cache_get( $query_key, 'counts' );
1737
1826
if ( false !== $result ) {
1739
1828
$result = get_post( $result );
1740
1830
return $result;
1743
1833
$result = $wpdb->get_var( $query );
1744
if ( null === $result )
1834
if ( null === $result ) {
1747
1838
wp_cache_set( $query_key, $result, 'counts' );
1750
1841
$result = get_post( $result );
1752
1844
return $result;
1767
1859
* @return string|void The adjacent post relational link URL.
1769
1861
function get_adjacent_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
1770
if ( $previous && is_attachment() && $post = get_post() )
1862
if ( $previous && is_attachment() && $post = get_post() ) {
1771
1863
$post = get_post( $post->post_parent );
1773
1865
$post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy );
1775
if ( empty( $post ) )
1868
if ( empty( $post ) ) {
1778
$post_title = the_title_attribute( array( 'echo' => false, 'post' => $post ) );
1780
if ( empty( $post_title ) )
1872
$post_title = the_title_attribute(
1879
if ( empty( $post_title ) ) {
1781
1880
$post_title = $previous ? __( 'Previous Post' ) : __( 'Next Post' );
1783
1883
$date = mysql2date( get_option( 'date_format' ), $post->post_date );
1785
1885
$title = str_replace( '%title', $post_title, $title );
1786
1886
$title = str_replace( '%date', $date, $title );
1788
$link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
1888
$link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
1789
1889
$link .= esc_attr( $title );
1790
1890
$link .= "' href='" . get_permalink( $post ) . "' />\n";
1887
1987
function get_boundary_post( $in_same_term = false, $excluded_terms = '', $start = true, $taxonomy = 'category' ) {
1888
1988
$post = get_post();
1889
if ( ! $post || ! is_single() || is_attachment() || ! taxonomy_exists( $taxonomy ) )
1989
if ( ! $post || ! is_single() || is_attachment() || ! taxonomy_exists( $taxonomy ) ) {
1892
1993
$query_args = array(
1893
'posts_per_page' => 1,
1894
'order' => $start ? 'ASC' : 'DESC',
1994
'posts_per_page' => 1,
1995
'order' => $start ? 'ASC' : 'DESC',
1895
1996
'update_post_term_cache' => false,
1896
'update_post_meta_cache' => false
1997
'update_post_meta_cache' => false,
1899
2000
$term_array = array();
1901
2002
if ( ! is_array( $excluded_terms ) ) {
1902
if ( ! empty( $excluded_terms ) )
2003
if ( ! empty( $excluded_terms ) ) {
1903
2004
$excluded_terms = explode( ',', $excluded_terms );
1905
2006
$excluded_terms = array();
1908
2010
if ( $in_same_term || ! empty( $excluded_terms ) ) {
1909
if ( $in_same_term )
2011
if ( $in_same_term ) {
1910
2012
$term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
1912
2015
if ( ! empty( $excluded_terms ) ) {
1913
2016
$excluded_terms = array_map( 'intval', $excluded_terms );
1914
2017
$excluded_terms = array_diff( $excluded_terms, $term_array );
1916
2019
$inverse_terms = array();
1917
foreach ( $excluded_terms as $excluded_term )
2020
foreach ( $excluded_terms as $excluded_term ) {
1918
2021
$inverse_terms[] = $excluded_term * -1;
1919
2023
$excluded_terms = $inverse_terms;
1922
$query_args[ 'tax_query' ] = array( array(
1923
'taxonomy' => $taxonomy,
1924
'terms' => array_merge( $term_array, $excluded_terms )
2026
$query_args['tax_query'] = array(
2028
'taxonomy' => $taxonomy,
2029
'terms' => array_merge( $term_array, $excluded_terms ),
1928
2034
return get_posts( $query_args );
2009
2115
* @return string The link URL of the previous or next post in relation to the current post.
2011
2117
function get_adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
2012
if ( $previous && is_attachment() )
2118
if ( $previous && is_attachment() ) {
2013
2119
$post = get_post( get_post()->post_parent );
2015
2121
$post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy );
2017
2124
if ( ! $post ) {
2020
2127
$title = $post->post_title;
2022
if ( empty( $post->post_title ) )
2129
if ( empty( $post->post_title ) ) {
2023
2130
$title = $previous ? __( 'Previous Post' ) : __( 'Next Post' );
2025
2133
/** This filter is documented in wp-includes/post-template.php */
2026
2134
$title = apply_filters( 'the_title', $title, $post->ID );
2028
2136
$date = mysql2date( get_option( 'date_format' ), $post->post_date );
2029
$rel = $previous ? 'prev' : 'next';
2137
$rel = $previous ? 'prev' : 'next';
2031
$string = '<a href="' . get_permalink( $post ) . '" rel="'.$rel.'">';
2139
$string = '<a href="' . get_permalink( $post ) . '" rel="' . $rel . '">';
2032
2140
$inlink = str_replace( '%title', $title, $link );
2033
2141
$inlink = str_replace( '%date', $date, $inlink );
2034
2142
$inlink = $string . $inlink . '</a>';
2084
2192
* @param int $pagenum Optional. Page ID. Default 1.
2085
2193
* @param bool $escape Optional. Whether to escape the URL for display, with esc_url(). Defaults to true.
2086
* Otherwise, prepares the URL with esc_url_raw().
2194
* Otherwise, prepares the URL with esc_url_raw().
2087
2195
* @return string The link URL for the given page number.
2089
function get_pagenum_link($pagenum = 1, $escape = true ) {
2197
function get_pagenum_link( $pagenum = 1, $escape = true ) {
2090
2198
global $wp_rewrite;
2092
2200
$pagenum = (int) $pagenum;
2094
2202
$request = remove_query_arg( 'paged' );
2096
$home_root = parse_url(home_url());
2097
$home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
2204
$home_root = parse_url( home_url() );
2205
$home_root = ( isset( $home_root['path'] ) ) ? $home_root['path'] : '';
2098
2206
$home_root = preg_quote( $home_root, '|' );
2100
$request = preg_replace('|^'. $home_root . '|i', '', $request);
2101
$request = preg_replace('|^/+|', '', $request);
2208
$request = preg_replace( '|^' . $home_root . '|i', '', $request );
2209
$request = preg_replace( '|^/+|', '', $request );
2103
if ( !$wp_rewrite->using_permalinks() || is_admin() ) {
2211
if ( ! $wp_rewrite->using_permalinks() || is_admin() ) {
2104
2212
$base = trailingslashit( get_bloginfo( 'url' ) );
2106
2214
if ( $pagenum > 1 ) {
2112
2220
$qs_regex = '|\?.*?$|';
2113
2221
preg_match( $qs_regex, $request, $qs_match );
2115
if ( !empty( $qs_match[0] ) ) {
2223
if ( ! empty( $qs_match[0] ) ) {
2116
2224
$query_string = $qs_match[0];
2117
$request = preg_replace( $qs_regex, '', $request );
2225
$request = preg_replace( $qs_regex, '', $request );
2119
2227
$query_string = '';
2122
$request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request);
2123
$request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request);
2124
$request = ltrim($request, '/');
2230
$request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request );
2231
$request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request );
2232
$request = ltrim( $request, '/' );
2126
2234
$base = trailingslashit( get_bloginfo( 'url' ) );
2128
if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) )
2236
if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) ) {
2129
2237
$base .= $wp_rewrite->index . '/';
2131
2240
if ( $pagenum > 1 ) {
2132
$request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . "/" . $pagenum, 'paged' );
2241
$request = ( ( ! empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . '/' . $pagenum, 'paged' );
2135
2244
$result = $base . $request . $query_string;
2351
if ( !is_singular() ) {
2470
if ( ! is_singular() ) {
2352
2471
$defaults = array(
2353
'sep' => ' — ',
2354
'prelabel' => __('« Previous Page'),
2355
'nxtlabel' => __('Next Page »'),
2472
'sep' => ' — ',
2473
'prelabel' => __( '« Previous Page' ),
2474
'nxtlabel' => __( 'Next Page »' ),
2357
$args = wp_parse_args( $args, $defaults );
2476
$args = wp_parse_args( $args, $defaults );
2359
2478
$max_num_pages = $wp_query->max_num_pages;
2360
$paged = get_query_var('paged');
2479
$paged = get_query_var( 'paged' );
2362
2481
//only have sep if there's both prev and next results
2363
if ($paged < 2 || $paged >= $max_num_pages) {
2482
if ( $paged < 2 || $paged >= $max_num_pages ) {
2364
2483
$args['sep'] = '';
2367
2486
if ( $max_num_pages > 1 ) {
2368
$return = get_previous_posts_link($args['prelabel']);
2369
$return .= preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $args['sep']);
2370
$return .= get_next_posts_link($args['nxtlabel']);
2487
$return = get_previous_posts_link( $args['prelabel'] );
2488
$return .= preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $args['sep'] );
2489
$return .= get_next_posts_link( $args['nxtlabel'] );
2373
2492
return $return;
2479
2601
// Don't print empty markup if there's only one page.
2480
2602
if ( $GLOBALS['wp_query']->max_num_pages > 1 ) {
2481
$args = wp_parse_args( $args, array(
2482
'prev_text' => __( 'Older posts' ),
2483
'next_text' => __( 'Newer posts' ),
2484
'screen_reader_text' => __( 'Posts navigation' ),
2603
$args = wp_parse_args(
2606
'prev_text' => __( 'Older posts' ),
2607
'next_text' => __( 'Newer posts' ),
2608
'screen_reader_text' => __( 'Posts navigation' ),
2487
2612
$next_link = get_previous_posts_link( $args['next_text'] );
2488
2613
$prev_link = get_next_posts_link( $args['prev_text'] );
2532
2657
// Don't print empty markup if there's only one page.
2533
2658
if ( $GLOBALS['wp_query']->max_num_pages > 1 ) {
2534
$args = wp_parse_args( $args, array(
2536
'prev_text' => _x( 'Previous', 'previous set of posts' ),
2537
'next_text' => _x( 'Next', 'next set of posts' ),
2538
'screen_reader_text' => __( 'Posts navigation' ),
2659
$args = wp_parse_args(
2663
'prev_text' => _x( 'Previous', 'previous set of posts' ),
2664
'next_text' => _x( 'Next', 'next set of posts' ),
2665
'screen_reader_text' => __( 'Posts navigation' ),
2541
2669
// Make sure we get a string back. Plain is the next best thing.
2542
2670
if ( isset( $args['type'] ) && 'array' == $args['type'] ) {
2630
2758
$result = get_permalink();
2632
if ( 'newest' == get_option('default_comments_page') ) {
2760
if ( 'newest' == get_option( 'default_comments_page' ) ) {
2633
2761
if ( $pagenum != $max_page ) {
2634
if ( $wp_rewrite->using_permalinks() )
2635
$result = user_trailingslashit( trailingslashit($result) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged');
2762
if ( $wp_rewrite->using_permalinks() ) {
2763
$result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' );
2637
2765
$result = add_query_arg( 'cpage', $pagenum, $result );
2639
2768
} elseif ( $pagenum > 1 ) {
2640
if ( $wp_rewrite->using_permalinks() )
2641
$result = user_trailingslashit( trailingslashit($result) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged');
2769
if ( $wp_rewrite->using_permalinks() ) {
2770
$result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' );
2643
2772
$result = add_query_arg( 'cpage', $pagenum, $result );
2646
2776
$result .= '#comments';
2669
2799
function get_next_comments_link( $label = '', $max_page = 0 ) {
2670
2800
global $wp_query;
2672
if ( ! is_singular() )
2802
if ( ! is_singular() ) {
2675
$page = get_query_var('cpage');
2806
$page = get_query_var( 'cpage' );
2677
2808
if ( ! $page ) {
2681
$nextpage = intval($page) + 1;
2812
$nextpage = intval( $page ) + 1;
2683
if ( empty($max_page) )
2814
if ( empty( $max_page ) ) {
2684
2815
$max_page = $wp_query->max_num_comment_pages;
2686
if ( empty($max_page) )
2818
if ( empty( $max_page ) ) {
2687
2819
$max_page = get_comment_pages_count();
2689
if ( $nextpage > $max_page )
2822
if ( $nextpage > $max_page ) {
2692
if ( empty($label) )
2693
$label = __('Newer Comments »');
2826
if ( empty( $label ) ) {
2827
$label = __( 'Newer Comments »' );
2696
2831
* Filters the anchor tag attributes for the next comments page link.
2723
2858
* @return string|void HTML-formatted link for the previous page of comments.
2725
2860
function get_previous_comments_link( $label = '' ) {
2726
if ( ! is_singular() )
2729
$page = get_query_var('cpage');
2731
if ( intval($page) <= 1 )
2734
$prevpage = intval($page) - 1;
2736
if ( empty($label) )
2737
$label = __('« Older Comments');
2861
if ( ! is_singular() ) {
2865
$page = get_query_var( 'cpage' );
2867
if ( intval( $page ) <= 1 ) {
2871
$prevpage = intval( $page ) - 1;
2873
if ( empty( $label ) ) {
2874
$label = __( '« Older Comments' );
2740
2878
* Filters the anchor tag attributes for the previous comments page link.
2766
2904
* @global WP_Rewrite $wp_rewrite
2768
2906
* @param string|array $args Optional args. See paginate_links(). Default empty array.
2769
* @return string|void Markup for pagination links.
2907
* @return string|array|void Markup for comment page links or array of comment page links.
2771
2909
function paginate_comments_links( $args = array() ) {
2772
2910
global $wp_rewrite;
2774
if ( ! is_singular() )
2912
if ( ! is_singular() ) {
2777
$page = get_query_var('cpage');
2916
$page = get_query_var( 'cpage' );
2780
2920
$max_page = get_comment_pages_count();
2781
2921
$defaults = array(
2782
'base' => add_query_arg( 'cpage', '%#%' ),
2784
'total' => $max_page,
2787
'add_fragment' => '#comments'
2922
'base' => add_query_arg( 'cpage', '%#%' ),
2924
'total' => $max_page,
2928
'add_fragment' => '#comments',
2789
if ( $wp_rewrite->using_permalinks() )
2790
$defaults['base'] = user_trailingslashit(trailingslashit(get_permalink()) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged');
2930
if ( $wp_rewrite->using_permalinks() ) {
2931
$defaults['base'] = user_trailingslashit( trailingslashit( get_permalink() ) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged' );
2792
$args = wp_parse_args( $args, $defaults );
2934
$args = wp_parse_args( $args, $defaults );
2793
2935
$page_links = paginate_links( $args );
2795
if ( $args['echo'] )
2937
if ( $args['echo'] && 'array' !== $args['type'] ) {
2796
2938
echo $page_links;
2798
2940
return $page_links;
2820
2963
// Are there comments to navigate through?
2821
2964
if ( get_comment_pages_count() > 1 ) {
2822
$args = wp_parse_args( $args, array(
2823
'prev_text' => __( 'Older comments' ),
2824
'next_text' => __( 'Newer comments' ),
2825
'screen_reader_text' => __( 'Comments navigation' ),
2965
$args = wp_parse_args(
2968
'prev_text' => __( 'Older comments' ),
2969
'next_text' => __( 'Newer comments' ),
2970
'screen_reader_text' => __( 'Comments navigation' ),
2828
2974
$prev_link = get_previous_comments_link( $args['prev_text'] );
2829
2975
$next_link = get_next_comments_link( $args['next_text'] );
3063
3215
* @return string Admin URL link with optional path appended.
3065
3217
function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' ) {
3066
$url = get_site_url($blog_id, 'wp-admin/', $scheme);
3218
$url = get_site_url( $blog_id, 'wp-admin/', $scheme );
3068
if ( $path && is_string( $path ) )
3220
if ( $path && is_string( $path ) ) {
3069
3221
$url .= ltrim( $path, '/' );
3072
3225
* Filters the admin area URL.
3151
3306
function plugins_url( $path = '', $plugin = '' ) {
3153
$path = wp_normalize_path( $path );
3154
$plugin = wp_normalize_path( $plugin );
3308
$path = wp_normalize_path( $path );
3309
$plugin = wp_normalize_path( $plugin );
3155
3310
$mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );
3157
if ( !empty($plugin) && 0 === strpos($plugin, $mu_plugin_dir) )
3312
if ( ! empty( $plugin ) && 0 === strpos( $plugin, $mu_plugin_dir ) ) {
3158
3313
$url = WPMU_PLUGIN_URL;
3160
3315
$url = WP_PLUGIN_URL;
3163
3318
$url = set_url_scheme( $url );
3165
if ( !empty($plugin) && is_string($plugin) ) {
3166
$folder = dirname(plugin_basename($plugin));
3167
if ( '.' != $folder )
3168
$url .= '/' . ltrim($folder, '/');
3320
if ( ! empty( $plugin ) && is_string( $plugin ) ) {
3321
$folder = dirname( plugin_basename( $plugin ) );
3322
if ( '.' != $folder ) {
3323
$url .= '/' . ltrim( $folder, '/' );
3171
if ( $path && is_string( $path ) )
3172
$url .= '/' . ltrim($path, '/');
3327
if ( $path && is_string( $path ) ) {
3328
$url .= '/' . ltrim( $path, '/' );
3175
3332
* Filters the URL to the plugins directory.
3202
3359
* @return string Site URL link with optional path appended.
3204
3361
function network_site_url( $path = '', $scheme = null ) {
3205
if ( ! is_multisite() )
3206
return site_url($path, $scheme);
3362
if ( ! is_multisite() ) {
3363
return site_url( $path, $scheme );
3208
3366
$current_network = get_network();
3210
if ( 'relative' == $scheme )
3368
if ( 'relative' == $scheme ) {
3211
3369
$url = $current_network->path;
3213
3371
$url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme );
3215
if ( $path && is_string( $path ) )
3374
if ( $path && is_string( $path ) ) {
3216
3375
$url .= ltrim( $path, '/' );
3219
3379
* Filters the network site URL.
3244
3404
* @return string Home URL link with optional path appended.
3246
3406
function network_home_url( $path = '', $scheme = null ) {
3247
if ( ! is_multisite() )
3248
return home_url($path, $scheme);
3407
if ( ! is_multisite() ) {
3408
return home_url( $path, $scheme );
3250
3411
$current_network = get_network();
3251
$orig_scheme = $scheme;
3412
$orig_scheme = $scheme;
3253
if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) )
3414
if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) {
3254
3415
$scheme = is_ssl() && ! is_admin() ? 'https' : 'http';
3256
if ( 'relative' == $scheme )
3418
if ( 'relative' == $scheme ) {
3257
3419
$url = $current_network->path;
3259
3421
$url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme );
3261
if ( $path && is_string( $path ) )
3424
if ( $path && is_string( $path ) ) {
3262
3425
$url .= ltrim( $path, '/' );
3265
3429
* Filters the network home URL.
3286
3450
* @return string Admin URL link with optional path appended.
3288
3452
function network_admin_url( $path = '', $scheme = 'admin' ) {
3289
if ( ! is_multisite() )
3453
if ( ! is_multisite() ) {
3290
3454
return admin_url( $path, $scheme );
3292
$url = network_site_url('wp-admin/network/', $scheme);
3294
if ( $path && is_string( $path ) )
3295
$url .= ltrim($path, '/');
3457
$url = network_site_url( 'wp-admin/network/', $scheme );
3459
if ( $path && is_string( $path ) ) {
3460
$url .= ltrim( $path, '/' );
3298
3464
* Filters the network admin URL.
3317
3483
* @return string Admin URL link with optional path appended.
3319
3485
function user_admin_url( $path = '', $scheme = 'admin' ) {
3320
$url = network_site_url('wp-admin/user/', $scheme);
3486
$url = network_site_url( 'wp-admin/user/', $scheme );
3322
if ( $path && is_string( $path ) )
3323
$url .= ltrim($path, '/');
3488
if ( $path && is_string( $path ) ) {
3489
$url .= ltrim( $path, '/' );
3326
3493
* Filters the user admin URL for the current user.
3390
3557
$url = trim( $url );
3391
if ( substr( $url, 0, 2 ) === '//' )
3558
if ( substr( $url, 0, 2 ) === '//' ) {
3392
3559
$url = 'http:' . $url;
3394
3562
if ( 'relative' == $scheme ) {
3395
3563
$url = ltrim( preg_replace( '#^\w+://[^/]*#', '', $url ) );
3396
if ( $url !== '' && $url[0] === '/' )
3397
$url = '/' . ltrim($url , "/ \t\n\r\0\x0B" );
3564
if ( $url !== '' && $url[0] === '/' ) {
3565
$url = '/' . ltrim( $url, "/ \t\n\r\0\x0B" );
3399
3568
$url = preg_replace( '#^\w+://#', $scheme . '://', $url );
3432
3601
$user_id = $user_id ? (int) $user_id : get_current_user_id();
3434
3603
$blogs = get_blogs_of_user( $user_id );
3435
if ( is_multisite() && ! user_can( $user_id, 'manage_network' ) && empty($blogs) ) {
3604
if ( is_multisite() && ! user_can( $user_id, 'manage_network' ) && empty( $blogs ) ) {
3436
3605
$url = user_admin_url( $path, $scheme );
3437
3606
} elseif ( ! is_multisite() ) {
3438
3607
$url = admin_url( $path, $scheme );
3440
3609
$current_blog = get_current_blog_id();
3441
if ( $current_blog && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blog, array_keys( $blogs ) ) ) ) {
3610
if ( $current_blog && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blog, array_keys( $blogs ) ) ) ) {
3442
3611
$url = admin_url( $path, $scheme );
3444
3613
$active = get_active_blog_for_user( $user_id );
3446
3615
$url = get_admin_url( $active->blog_id, $path, $scheme );
3448
3617
$url = user_admin_url( $path, $scheme );
3760
3937
return $args['url'];
3942
* Check if this comment type allows avatars to be retrieved.
3946
* @param string $comment_type Comment type to check.
3947
* @return bool Whether the comment type is allowed for retrieving avatars.
3949
function is_avatar_comment_type( $comment_type ) {
3951
* Filters the list of allowed comment types for retrieving avatars.
3955
* @param array $types An array of content types. Default only contains 'comment'.
3957
$allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) );
3959
return in_array( $comment_type, (array) $allowed_comment_types, true );
3764
3964
* Retrieves default data about the avatar.
3799
3999
function get_avatar_data( $id_or_email, $args = null ) {
3800
$args = wp_parse_args( $args, array(
3804
'default' => get_option( 'avatar_default', 'mystery' ),
3805
'force_default' => false,
3806
'rating' => get_option( 'avatar_rating' ),
3808
'processed_args' => null, // if used, should be a reference
4000
$args = wp_parse_args(
4006
'default' => get_option( 'avatar_default', 'mystery' ),
4007
'force_default' => false,
4008
'rating' => get_option( 'avatar_rating' ),
4010
'processed_args' => null, // if used, should be a reference
3812
4015
if ( is_numeric( $args['size'] ) ) {
3813
4016
$args['size'] = absint( $args['size'] );
3903
4106
$user = get_user_by( 'id', (int) $id_or_email->post_author );
3904
4107
} elseif ( $id_or_email instanceof WP_Comment ) {
3906
* Filters the list of allowed comment types for retrieving avatars.
3910
* @param array $types An array of content types. Default only contains 'comment'.
3912
$allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) );
3913
if ( ! empty( $id_or_email->comment_type ) && ! in_array( $id_or_email->comment_type, (array) $allowed_comment_types ) ) {
4108
if ( ! is_avatar_comment_type( get_comment_type( $id_or_email ) ) ) {
3914
4109
$args['url'] = false;
3915
4110
/** This filter is documented in wp-includes/link-template.php */
3916
4111
return apply_filters( 'get_avatar_data', $args, $id_or_email );