3 * WordPress Link Template Functions
10 * Display the permalink for the current post.
13 * @uses apply_filters() Calls 'the_permalink' filter on the permalink string.
15 function the_permalink() {
16 echo apply_filters('the_permalink', get_permalink());
20 * Retrieve trailing slash string, if blog set for adding trailing slashes.
22 * Conditionally adds a trailing slash if the permalink structure has a trailing
23 * slash, strips the trailing slash if not. The string is passed through the
24 * 'user_trailingslashit' filter. Will remove trailing slash from string, if
25 * blog is not set to have them.
30 * @param $string String a URL with or without a trailing slash.
31 * @param $type_of_url String the type of URL being considered (e.g. single, category, etc) for use in the filter.
34 function user_trailingslashit($string, $type_of_url = '') {
36 if ( $wp_rewrite->use_trailing_slashes )
37 $string = trailingslashit($string);
39 $string = untrailingslashit($string);
41 // Note that $type_of_url can be one of following:
42 // single, single_trackback, single_feed, single_paged, feed, category, page, year, month, day, paged
43 $string = apply_filters('user_trailingslashit', $string, $type_of_url);
48 * Display permalink anchor for current post.
50 * The permalink mode title will use the post title for the 'a' element 'id'
51 * attribute. The id mode uses 'post-' with the post ID for the 'id' attribute.
55 * @param string $mode Permalink mode can be either 'title', 'id', or default, which is 'id'.
57 function permalink_anchor($mode = 'id') {
59 switch ( strtolower($mode) ) {
61 $title = sanitize_title($post->post_title) . '-' . $post->ID;
62 echo '<a id="'.$title.'"></a>';
66 echo '<a id="post-' . $post->ID . '"></a>';
72 * Retrieve full permalink for current post or post ID.
76 * @param int $id Optional. Post ID.
77 * @param bool $leavename Optional, defaults to false. Whether to keep post name or page name.
80 function get_permalink($id = 0, $leavename = false) {
88 $leavename? '' : '%postname%',
92 $leavename? '' : '%pagename%',
95 if ( is_object($id) && isset($id->filter) && 'sample' == $id->filter ) {
99 $post = &get_post($id);
103 if ( empty($post->ID) ) return false;
105 if ( $post->post_type == 'page' )
106 return get_page_link($post->ID, $leavename, $sample);
107 elseif ($post->post_type == 'attachment')
108 return get_attachment_link($post->ID);
110 $permalink = get_option('permalink_structure');
112 if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending')) ) {
113 $unixtime = strtotime($post->post_date);
116 if ( strpos($permalink, '%category%') !== false ) {
117 $cats = get_the_category($post->ID);
119 usort($cats, '_usort_terms_by_ID'); // order by ID
120 $category = $cats[0]->slug;
121 if ( $parent = $cats[0]->parent )
122 $category = get_category_parents($parent, false, '/', true) . $category;
124 // show default category in permalinks, without
125 // having to assign it explicitly
126 if ( empty($category) ) {
127 $default_category = get_category( get_option( 'default_category' ) );
128 $category = is_wp_error( $default_category ) ? '' : $default_category->slug;
133 if ( strpos($permalink, '%author%') !== false ) {
134 $authordata = get_userdata($post->post_author);
135 $author = $authordata->user_nicename;
138 $date = explode(" ",date('Y m d H i s', $unixtime));
153 $permalink = get_option('home') . str_replace($rewritecode, $rewritereplace, $permalink);
154 $permalink = user_trailingslashit($permalink, 'single');
155 return apply_filters('post_link', $permalink, $post, $leavename);
156 } else { // if they're not using the fancy permalink option
157 $permalink = trailingslashit(get_option('home')) . '?p=' . $post->ID;
158 return apply_filters('post_link', $permalink, $post, $leavename);
163 * Retrieve permalink from post ID.
167 * @param int $post_id Optional. Post ID.
168 * @param mixed $deprecated Not used.
171 function post_permalink($post_id = 0, $deprecated = '') {
172 return get_permalink($post_id);
176 * Retrieve the permalink for current page or page ID.
178 * Respects page_on_front. Use this one.
182 * @param int $id Optional. Post ID.
183 * @param bool $leavename Optional, defaults to false. Whether to keep page name.
184 * @param bool $sample Optional, defaults to false. Is it a sample permalink.
187 function get_page_link( $id = false, $leavename = false, $sample = false ) {
192 $id = (int) $post->ID;
194 if ( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') )
195 $link = get_option('home');
197 $link = _get_page_link( $id , $leavename, $sample );
199 return apply_filters('page_link', $link, $id);
203 * Retrieve the page permalink.
205 * Ignores page_on_front. Internal use only.
210 * @param int $id Optional. Post ID.
211 * @param bool $leavename Optional. Leave name.
212 * @param bool $sample Optional. Sample permalink.
215 function _get_page_link( $id = false, $leavename = false, $sample = false ) {
216 global $post, $wp_rewrite;
219 $id = (int) $post->ID;
221 $post = &get_post($id);
223 $pagestruct = $wp_rewrite->get_page_permastruct();
225 if ( '' != $pagestruct && ( ( isset($post->post_status) && 'draft' != $post->post_status ) || $sample ) ) {
226 $link = get_page_uri($id);
227 $link = ( $leavename ) ? $pagestruct : str_replace('%pagename%', $link, $pagestruct);
228 $link = trailingslashit(get_option('home')) . "$link";
229 $link = user_trailingslashit($link, 'page');
231 $link = trailingslashit(get_option('home')) . "?page_id=$id";
234 return apply_filters( '_get_page_link', $link, $id );
238 * Retrieve permalink for attachment.
240 * This can be used in the WordPress Loop or outside of it.
244 * @param int $id Optional. Post ID.
247 function get_attachment_link($id = false) {
248 global $post, $wp_rewrite;
253 $id = (int) $post->ID;
256 $object = get_post($id);
257 if ( $wp_rewrite->using_permalinks() && ($object->post_parent > 0) && ($object->post_parent != $id) ) {
258 $parent = get_post($object->post_parent);
259 if ( 'page' == $parent->post_type )
260 $parentlink = _get_page_link( $object->post_parent ); // Ignores page_on_front
262 $parentlink = get_permalink( $object->post_parent );
263 if ( is_numeric($object->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') )
264 $name = 'attachment/' . $object->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker
266 $name = $object->post_name;
267 if (strpos($parentlink, '?') === false)
268 $link = user_trailingslashit( trailingslashit($parentlink) . $name );
272 $link = trailingslashit(get_bloginfo('url')) . "?attachment_id=$id";
275 return apply_filters('attachment_link', $link, $id);
279 * Retrieve the permalink for the year archives.
283 * @param int|bool $year False for current year or year for permalink.
286 function get_year_link($year) {
289 $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600));
290 $yearlink = $wp_rewrite->get_year_permastruct();
291 if ( !empty($yearlink) ) {
292 $yearlink = str_replace('%year%', $year, $yearlink);
293 return apply_filters('year_link', get_option('home') . user_trailingslashit($yearlink, 'year'), $year);
295 return apply_filters('year_link', trailingslashit(get_option('home')) . '?m=' . $year, $year);
300 * Retrieve the permalink for the month archives with year.
304 * @param bool|int $year False for current year. Integer of year.
305 * @param bool|int $month False for current month. Integer of month.
308 function get_month_link($year, $month) {
311 $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600));
313 $month = gmdate('m', time()+(get_option('gmt_offset') * 3600));
314 $monthlink = $wp_rewrite->get_month_permastruct();
315 if ( !empty($monthlink) ) {
316 $monthlink = str_replace('%year%', $year, $monthlink);
317 $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
318 return apply_filters('month_link', get_option('home') . user_trailingslashit($monthlink, 'month'), $year, $month);
320 return apply_filters('month_link', trailingslashit(get_option('home')) . '?m=' . $year . zeroise($month, 2), $year, $month);
325 * Retrieve the permalink for the day archives with year and month.
329 * @param bool|int $year False for current year. Integer of year.
330 * @param bool|int $month False for current month. Integer of month.
331 * @param bool|int $day False for current day. Integer of day.
334 function get_day_link($year, $month, $day) {
337 $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600));
339 $month = gmdate('m', time()+(get_option('gmt_offset') * 3600));
341 $day = gmdate('j', time()+(get_option('gmt_offset') * 3600));
343 $daylink = $wp_rewrite->get_day_permastruct();
344 if ( !empty($daylink) ) {
345 $daylink = str_replace('%year%', $year, $daylink);
346 $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
347 $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
348 return apply_filters('day_link', get_option('home') . user_trailingslashit($daylink, 'day'), $year, $month, $day);
350 return apply_filters('day_link', trailingslashit(get_option('home')) . '?m=' . $year . zeroise($month, 2) . zeroise($day, 2), $year, $month, $day);
355 * Retrieve the permalink for the feed type.
359 * @param string $feed Optional, defaults to default feed. Feed type.
362 function get_feed_link($feed = '') {
365 $permalink = $wp_rewrite->get_feed_permastruct();
366 if ( '' != $permalink ) {
367 if ( false !== strpos($feed, 'comments_') ) {
368 $feed = str_replace('comments_', '', $feed);
369 $permalink = $wp_rewrite->get_comment_feed_permastruct();
372 if ( get_default_feed() == $feed )
375 $permalink = str_replace('%feed%', $feed, $permalink);
376 $permalink = preg_replace('#/+#', '/', "/$permalink");
377 $output = get_option('home') . user_trailingslashit($permalink, 'feed');
380 $feed = get_default_feed();
382 if ( false !== strpos($feed, 'comments_') )
383 $feed = str_replace('comments_', 'comments-', $feed);
385 $output = trailingslashit(get_option('home')) . "?feed={$feed}";
388 return apply_filters('feed_link', $output, $feed);
392 * Retrieve the permalink for the post comments feed.
396 * @param int $post_id Optional. Post ID.
397 * @param string $feed Optional. Feed type.
400 function get_post_comments_feed_link($post_id = '', $feed = '') {
403 if ( empty($post_id) )
404 $post_id = (int) $id;
407 $feed = get_default_feed();
409 if ( '' != get_option('permalink_structure') ) {
410 $url = trailingslashit( get_permalink($post_id) ) . 'feed';
411 if ( $feed != get_default_feed() )
413 $url = user_trailingslashit($url, 'single_feed');
415 $type = get_post_field('post_type', $post_id);
416 if ( 'page' == $type )
417 $url = trailingslashit(get_option('home')) . "?feed=$feed&page_id=$post_id";
419 $url = trailingslashit(get_option('home')) . "?feed=$feed&p=$post_id";
422 return apply_filters('post_comments_feed_link', $url);
426 * Display the comment feed link for a post.
428 * Prints out the comment feed link for a post. Link text is placed in the
429 * anchor. If no link text is specified, default text is used. If no post ID is
430 * specified, the current post is used.
436 * @param string $link_text Descriptive text.
437 * @param int $post_id Optional post ID. Default to current post.
438 * @param string $feed Optional. Feed format.
439 * @return string Link to the comment feed for the current post.
441 function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) {
442 $url = get_post_comments_feed_link($post_id, $feed);
443 if ( empty($link_text) )
444 $link_text = __('Comments Feed');
446 echo apply_filters( 'post_comments_feed_link_html', "<a href='$url'>$link_text</a>", $post_id, $feed );
450 * Retrieve the feed link for a given author.
452 * Returns a link to the feed for all posts by a given author. A specific feed
453 * can be requested or left blank to get the default feed.
459 * @param int $author_id ID of an author.
460 * @param string $feed Optional. Feed type.
461 * @return string Link to the feed for the author specified by $author_id.
463 function get_author_feed_link( $author_id, $feed = '' ) {
464 $author_id = (int) $author_id;
465 $permalink_structure = get_option('permalink_structure');
468 $feed = get_default_feed();
470 if ( '' == $permalink_structure ) {
471 $link = trailingslashit(get_option('home')) . "?feed=$feed&author=" . $author_id;
473 $link = get_author_posts_url($author_id);
474 if ( $feed == get_default_feed() )
477 $feed_link = "feed/$feed";
479 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
482 $link = apply_filters('author_feed_link', $link, $feed);
488 * Retrieve the feed link for a category.
490 * Returns a link to the feed for all post in a given category. A specific feed
491 * can be requested or left blank to get the default feed.
497 * @param int $cat_id ID of a category.
498 * @param string $feed Optional. Feed type.
499 * @return string Link to the feed for the category specified by $cat_id.
501 function get_category_feed_link($cat_id, $feed = '') {
502 $cat_id = (int) $cat_id;
504 $category = get_category($cat_id);
506 if ( empty($category) || is_wp_error($category) )
510 $feed = get_default_feed();
512 $permalink_structure = get_option('permalink_structure');
514 if ( '' == $permalink_structure ) {
515 $link = trailingslashit(get_option('home')) . "?feed=$feed&cat=" . $cat_id;
517 $link = get_category_link($cat_id);
518 if( $feed == get_default_feed() )
521 $feed_link = "feed/$feed";
523 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
526 $link = apply_filters('category_feed_link', $link, $feed);
532 * Retrieve permalink for feed of tag.
536 * @param int $tag_id Tag ID.
537 * @param string $feed Optional. Feed type.
540 function get_tag_feed_link($tag_id, $feed = '') {
541 $tag_id = (int) $tag_id;
543 $tag = get_tag($tag_id);
545 if ( empty($tag) || is_wp_error($tag) )
548 $permalink_structure = get_option('permalink_structure');
551 $feed = get_default_feed();
553 if ( '' == $permalink_structure ) {
554 $link = trailingslashit(get_option('home')) . "?feed=$feed&tag=" . $tag->slug;
556 $link = get_tag_link($tag->term_id);
557 if ( $feed == get_default_feed() )
560 $feed_link = "feed/$feed";
561 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
564 $link = apply_filters('tag_feed_link', $link, $feed);
570 * Retrieve edit tag link.
574 * @param int $tag_id Tag ID
577 function get_edit_tag_link( $tag_id = 0, $taxonomy = 'post_tag' ) {
578 $tag = get_term($tag_id, $taxonomy);
580 if ( !current_user_can('manage_categories') )
583 $location = admin_url('edit-tags.php?action=edit&taxonomy=' . $taxonomy . '&tag_ID=' . $tag->term_id);
584 return apply_filters( 'get_edit_tag_link', $location );
588 * Display or retrieve edit tag link with formatting.
592 * @param string $link Optional. Anchor text.
593 * @param string $before Optional. Display before edit link.
594 * @param string $after Optional. Display after edit link.
595 * @param int|object $tag Tag object or ID
596 * @return string|null HTML content, if $echo is set to false.
598 function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) {
599 $tag = get_term($tag, 'post_tag');
601 if ( !current_user_can('manage_categories') )
605 $link = __('Edit This');
607 $link = '<a href="' . get_edit_tag_link( $tag->term_id ) . '" title="' . __( 'Edit tag' ) . '">' . $link . '</a>';
608 echo $before . apply_filters( 'edit_tag_link', $link, $tag->term_id ) . $after;
612 * Retrieve the permalink for the feed of the search results.
616 * @param string $search_query Optional. Search query.
617 * @param string $feed Optional. Feed type.
620 function get_search_feed_link($search_query = '', $feed = '') {
621 if ( empty($search_query) )
622 $search = esc_attr(get_search_query());
624 $search = esc_attr(stripslashes($search_query));
627 $feed = get_default_feed();
629 $link = trailingslashit(get_option('home')) . "?s=$search&feed=$feed";
631 $link = apply_filters('search_feed_link', $link);
637 * Retrieve the permalink for the comments feed of the search results.
641 * @param string $search_query Optional. Search query.
642 * @param string $feed Optional. Feed type.
645 function get_search_comments_feed_link($search_query = '', $feed = '') {
646 if ( empty($search_query) )
647 $search = esc_attr(get_search_query());
649 $search = esc_attr(stripslashes($search_query));
652 $feed = get_default_feed();
654 $link = trailingslashit(get_option('home')) . "?s=$search&feed=comments-$feed";
656 $link = apply_filters('search_feed_link', $link);
662 * Retrieve edit posts link for post.
664 * Can be used within the WordPress loop or outside of it. Can be used with
665 * pages, posts, attachments, and revisions.
669 * @param int $id Optional. Post ID.
670 * @param string $context Optional, default to display. How to write the '&', defaults to '&'.
673 function get_edit_post_link( $id = 0, $context = 'display' ) {
674 if ( !$post = &get_post( $id ) )
677 if ( 'display' == $context )
678 $action = 'action=edit&';
680 $action = 'action=edit&';
682 switch ( $post->post_type ) :
684 if ( !current_user_can( 'edit_page', $post->ID ) )
690 if ( !current_user_can( 'edit_post', $post->ID ) )
693 $var = 'attachment_id';
696 if ( !current_user_can( 'edit_post', $post->ID ) )
703 if ( !current_user_can( 'edit_post', $post->ID ) )
710 return apply_filters( 'get_edit_post_link', admin_url("$file.php?{$action}$var=$post->ID"), $post->ID, $context );
714 * Display edit post link for post.
718 * @param string $link Optional. Anchor text.
719 * @param string $before Optional. Display before edit link.
720 * @param string $after Optional. Display after edit link.
721 * @param int $id Optional. Post ID.
723 function edit_post_link( $link = 'Edit This', $before = '', $after = '', $id = 0 ) {
724 if ( !$post = &get_post( $id ) )
727 if ( !$url = get_edit_post_link( $post->ID ) )
730 $link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr( __( 'Edit post' ) ) . '">' . $link . '</a>';
731 echo $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after;
735 * Retrieve edit comment link.
739 * @param int $comment_id Optional. Comment ID.
742 function get_edit_comment_link( $comment_id = 0 ) {
743 $comment = &get_comment( $comment_id );
744 $post = &get_post( $comment->comment_post_ID );
746 if ( $post->post_type == 'page' ) {
747 if ( !current_user_can( 'edit_page', $post->ID ) )
750 if ( !current_user_can( 'edit_post', $post->ID ) )
754 $location = admin_url('comment.php?action=editcomment&c=') . $comment->comment_ID;
755 return apply_filters( 'get_edit_comment_link', $location );
759 * Display or retrieve edit comment link with formatting.
763 * @param string $link Optional. Anchor text.
764 * @param string $before Optional. Display before edit link.
765 * @param string $after Optional. Display after edit link.
766 * @return string|null HTML content, if $echo is set to false.
768 function edit_comment_link( $link = 'Edit This', $before = '', $after = '' ) {
769 global $comment, $post;
771 if ( $post->post_type == 'page' ) {
772 if ( !current_user_can( 'edit_page', $post->ID ) )
775 if ( !current_user_can( 'edit_post', $post->ID ) )
779 $link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . __( 'Edit comment' ) . '">' . $link . '</a>';
780 echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after;
784 * Display edit bookmark (literally a URL external to blog) link.
788 * @param int $link Optional. Bookmark ID.
791 function get_edit_bookmark_link( $link = 0 ) {
792 $link = get_bookmark( $link );
794 if ( !current_user_can('manage_links') )
797 $location = admin_url('link.php?action=edit&link_id=') . $link->link_id;
798 return apply_filters( 'get_edit_bookmark_link', $location, $link->link_id );
802 * Display edit bookmark (literally a URL external to blog) link anchor content.
806 * @param string $link Optional. Anchor text.
807 * @param string $before Optional. Display before edit link.
808 * @param string $after Optional. Display after edit link.
809 * @param int $bookmark Optional. Bookmark ID.
811 function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = null ) {
812 $bookmark = get_bookmark($bookmark);
814 if ( !current_user_can('manage_links') )
818 $link = __('Edit This');
820 $link = '<a href="' . get_edit_bookmark_link( $link ) . '" title="' . __( 'Edit link' ) . '">' . $link . '</a>';
821 echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after;
827 * Retrieve previous post link that is adjacent to current post.
831 * @param bool $in_same_cat Optional. Whether link should be in same category.
832 * @param string $excluded_categories Optional. Excluded categories IDs.
835 function get_previous_post($in_same_cat = false, $excluded_categories = '') {
836 return get_adjacent_post($in_same_cat, $excluded_categories);
840 * Retrieve next post link that is adjacent to current post.
844 * @param bool $in_same_cat Optional. Whether link should be in same category.
845 * @param string $excluded_categories Optional. Excluded categories IDs.
848 function get_next_post($in_same_cat = false, $excluded_categories = '') {
849 return get_adjacent_post($in_same_cat, $excluded_categories, false);
853 * Retrieve adjacent post link.
855 * Can either be next or previous post link.
859 * @param bool $in_same_cat Optional. Whether link should be in same category.
860 * @param string $excluded_categories Optional. Excluded categories IDs.
861 * @param bool $previous Optional. Whether to retrieve previous post.
864 function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true) {
867 if ( empty($post) || !is_single() || is_attachment() )
870 $current_post_date = $post->post_date;
873 $posts_in_ex_cats_sql = '';
874 if ( $in_same_cat || !empty($excluded_categories) ) {
875 $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";
877 if ( $in_same_cat ) {
878 $cat_array = wp_get_object_terms($post->ID, 'category', 'fields=ids');
879 $join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")";
882 $posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'";
883 if ( !empty($excluded_categories) ) {
884 $excluded_categories = array_map('intval', explode(' and ', $excluded_categories));
885 if ( !empty($cat_array) ) {
886 $excluded_categories = array_diff($excluded_categories, $cat_array);
887 $posts_in_ex_cats_sql = '';
890 if ( !empty($excluded_categories) ) {
891 $posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')';
896 $adjacent = $previous ? 'previous' : 'next';
897 $op = $previous ? '<' : '>';
898 $order = $previous ? 'DESC' : 'ASC';
900 $join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories );
901 $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = 'post' AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date), $in_same_cat, $excluded_categories );
902 $sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" );
904 $query = "SELECT p.* FROM $wpdb->posts AS p $join $where $sort";
905 $query_key = 'adjacent_post_' . md5($query);
906 $result = wp_cache_get($query_key, 'counts');
907 if ( false !== $result )
910 $result = $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p $join $where $sort");
911 if ( null === $result )
914 wp_cache_set($query_key, $result, 'counts');
919 * Get adjacent post relational link.
921 * Can either be next or previous post relational link.
925 * @param string $title Optional. Link title format.
926 * @param bool $in_same_cat Optional. Whether link should be in same category.
927 * @param string $excluded_categories Optional. Excluded categories IDs.
928 * @param bool $previous Optional, default is true. Whether display link to previous post.
931 function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true) {
932 if ( $previous && is_attachment() )
933 $post = & get_post($GLOBALS['post']->post_parent);
935 $post = get_adjacent_post($in_same_cat,$excluded_categories,$previous);
940 if ( empty($post->post_title) )
941 $post->post_title = $previous ? __('Previous Post') : __('Next Post');
943 $date = mysql2date(get_option('date_format'), $post->post_date);
945 $title = str_replace('%title', $post->post_title, $title);
946 $title = str_replace('%date', $date, $title);
947 $title = apply_filters('the_title', $title, $post);
949 $link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
950 $link .= esc_attr( $title );
951 $link .= "' href='" . get_permalink($post) . "' />\n";
953 $adjacent = $previous ? 'previous' : 'next';
954 return apply_filters( "{$adjacent}_post_rel_link", $link );
958 * Display relational links for the posts adjacent to the current post.
962 * @param string $title Optional. Link title format.
963 * @param bool $in_same_cat Optional. Whether link should be in same category.
964 * @param string $excluded_categories Optional. Excluded categories IDs.
966 function adjacent_posts_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
967 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true);
968 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false);
972 * Display relational link for the next post adjacent to the current post.
976 * @param string $title Optional. Link title format.
977 * @param bool $in_same_cat Optional. Whether link should be in same category.
978 * @param string $excluded_categories Optional. Excluded categories IDs.
980 function next_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
981 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false);
985 * Display relational link for the previous post adjacent to the current post.
989 * @param string $title Optional. Link title format.
990 * @param bool $in_same_cat Optional. Whether link should be in same category.
991 * @param string $excluded_categories Optional. Excluded categories IDs.
993 function prev_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
994 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true);
998 * Retrieve boundary post.
1000 * Boundary being either the first or last post by publish date within the contraitns specified
1001 * by in same category or excluded categories.
1005 * @param bool $in_same_cat Optional. Whether returned post should be in same category.
1006 * @param string $excluded_categories Optional. Excluded categories IDs.
1007 * @param bool $previous Optional. Whether to retrieve first post.
1010 function get_boundary_post($in_same_cat = false, $excluded_categories = '', $start = true) {
1011 global $post, $wpdb;
1013 if ( empty($post) || !is_single() || is_attachment() )
1016 $cat_array = array();
1017 $excluded_categories = array();
1018 if ( !empty($in_same_cat) || !empty($excluded_categories) ) {
1019 if ( !empty($in_same_cat) ) {
1020 $cat_array = wp_get_object_terms($post->ID, 'category', 'fields=ids');
1023 if ( !empty($excluded_categories) ) {
1024 $excluded_categories = array_map('intval', explode(',', $excluded_categories));
1026 if ( !empty($cat_array) )
1027 $excluded_categories = array_diff($excluded_categories, $cat_array);
1029 $inverse_cats = array();
1030 foreach ( $excluded_categories as $excluded_category)
1031 $inverse_cats[] = $excluded_category * -1;
1032 $excluded_categories = $inverse_cats;
1036 $categories = implode(',', array_merge($cat_array, $excluded_categories) );
1038 $order = $start ? 'ASC' : 'DESC';
1040 return get_posts( array('numberposts' => 1, 'order' => $order, 'orderby' => 'ID', 'category' => $categories) );
1044 * Get boundary post relational link.
1046 * Can either be start or end post relational link.
1050 * @param string $title Optional. Link title format.
1051 * @param bool $in_same_cat Optional. Whether link should be in same category.
1052 * @param string $excluded_categories Optional. Excluded categories IDs.
1053 * @param bool $start Optional, default is true. Whether display link to first post.
1056 function get_boundary_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $start = true) {
1057 $posts = get_boundary_post($in_same_cat,$excluded_categories,$start);
1058 // Even though we limited get_posts to return only 1 item it still returns an array of objects.
1064 if ( empty($post->post_title) )
1065 $post->post_title = $start ? __('First Post') : __('Last Post');
1067 $date = mysql2date(get_option('date_format'), $post->post_date);
1069 $title = str_replace('%title', $post->post_title, $title);
1070 $title = str_replace('%date', $date, $title);
1071 $title = apply_filters('the_title', $title, $post);
1073 $link = $start ? "<link rel='start' title='" : "<link rel='end' title='";
1074 $link .= esc_attr($title);
1075 $link .= "' href='" . get_permalink($post) . "' />\n";
1077 $boundary = $start ? 'start' : 'end';
1078 return apply_filters( "{$boundary}_post_rel_link", $link );
1082 * Display relational link for the first post.
1086 * @param string $title Optional. Link title format.
1087 * @param bool $in_same_cat Optional. Whether link should be in same category.
1088 * @param string $excluded_categories Optional. Excluded categories IDs.
1090 function start_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
1091 echo get_boundary_post_rel_link($title, $in_same_cat, $excluded_categories, true);
1095 * Get site index relational link.
1101 function get_index_rel_link() {
1102 $link = "<link rel='index' title='" . esc_attr(get_bloginfo('name')) . "' href='" . get_bloginfo('siteurl') . "' />\n";
1103 return apply_filters( "index_rel_link", $link );
1107 * Display relational link for the site index.
1111 function index_rel_link() {
1112 echo get_index_rel_link();
1116 * Get parent post relational link.
1120 * @param string $title Optional. Link title format.
1123 function get_parent_post_rel_link($title = '%title') {
1124 if ( ! empty( $GLOBALS['post'] ) && ! empty( $GLOBALS['post']->post_parent ) )
1125 $post = & get_post($GLOBALS['post']->post_parent);
1130 $date = mysql2date(get_option('date_format'), $post->post_date);
1132 $title = str_replace('%title', $post->post_title, $title);
1133 $title = str_replace('%date', $date, $title);
1134 $title = apply_filters('the_title', $title, $post);
1136 $link = "<link rel='up' title='";
1137 $link .= esc_attr( $title );
1138 $link .= "' href='" . get_permalink($post) . "' />\n";
1140 return apply_filters( "parent_post_rel_link", $link );
1144 * Display relational link for parent item
1148 function parent_post_rel_link($title = '%title') {
1149 echo get_parent_post_rel_link($title);
1153 * Display previous post link that is adjacent to the current post.
1157 * @param string $format Optional. Link anchor format.
1158 * @param string $link Optional. Link permalink format.
1159 * @param bool $in_same_cat Optional. Whether link should be in same category.
1160 * @param string $excluded_categories Optional. Excluded categories IDs.
1162 function previous_post_link($format='« %link', $link='%title', $in_same_cat = false, $excluded_categories = '') {
1163 adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true);
1167 * Display next post link that is adjacent to the current post.
1171 * @param string $format Optional. Link anchor format.
1172 * @param string $link Optional. Link permalink format.
1173 * @param bool $in_same_cat Optional. Whether link should be in same category.
1174 * @param string $excluded_categories Optional. Excluded categories IDs.
1176 function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '') {
1177 adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false);
1181 * Display adjacent post link.
1183 * Can be either next post link or previous.
1187 * @param string $format Link anchor format.
1188 * @param string $link Link permalink format.
1189 * @param bool $in_same_cat Optional. Whether link should be in same category.
1190 * @param string $excluded_categories Optional. Excluded categories IDs.
1191 * @param bool $previous Optional, default is true. Whether display link to previous post.
1193 function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) {
1194 if ( $previous && is_attachment() )
1195 $post = & get_post($GLOBALS['post']->post_parent);
1197 $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
1202 $title = $post->post_title;
1204 if ( empty($post->post_title) )
1205 $title = $previous ? __('Previous Post') : __('Next Post');
1207 $title = apply_filters('the_title', $title, $post);
1208 $date = mysql2date(get_option('date_format'), $post->post_date);
1210 $string = '<a href="'.get_permalink($post).'">';
1211 $link = str_replace('%title', $title, $link);
1212 $link = str_replace('%date', $date, $link);
1213 $link = $string . $link . '</a>';
1215 $format = str_replace('%link', $link, $format);
1217 $adjacent = $previous ? 'previous' : 'next';
1218 echo apply_filters( "{$adjacent}_post_link", $format, $link );
1222 * Retrieve get links for page numbers.
1226 * @param int $pagenum Optional. Page ID.
1229 function get_pagenum_link($pagenum = 1) {
1232 $pagenum = (int) $pagenum;
1234 $request = remove_query_arg( 'paged' );
1236 $home_root = parse_url(get_option('home'));
1237 $home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
1238 $home_root = preg_quote( trailingslashit( $home_root ), '|' );
1240 $request = preg_replace('|^'. $home_root . '|', '', $request);
1241 $request = preg_replace('|^/+|', '', $request);
1243 if ( !$wp_rewrite->using_permalinks() || is_admin() ) {
1244 $base = trailingslashit( get_bloginfo( 'home' ) );
1246 if ( $pagenum > 1 ) {
1247 $result = add_query_arg( 'paged', $pagenum, $base . $request );
1249 $result = $base . $request;
1252 $qs_regex = '|\?.*?$|';
1253 preg_match( $qs_regex, $request, $qs_match );
1255 if ( !empty( $qs_match[0] ) ) {
1256 $query_string = $qs_match[0];
1257 $request = preg_replace( $qs_regex, '', $request );
1262 $request = preg_replace( '|page/\d+/?$|', '', $request);
1263 $request = preg_replace( '|^index\.php|', '', $request);
1264 $request = ltrim($request, '/');
1266 $base = trailingslashit( get_bloginfo( 'url' ) );
1268 if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) )
1269 $base .= 'index.php/';
1271 if ( $pagenum > 1 ) {
1272 $request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( 'page/' . $pagenum, 'paged' );
1275 $result = $base . $request . $query_string;
1278 $result = apply_filters('get_pagenum_link', $result);
1284 * Retrieve next posts pages link.
1286 * Backported from 2.1.3 to 2.0.10.
1290 * @param int $max_page Optional. Max pages.
1293 function get_next_posts_page_link($max_page = 0) {
1296 if ( !is_single() ) {
1299 $nextpage = intval($paged) + 1;
1300 if ( !$max_page || $max_page >= $nextpage )
1301 return get_pagenum_link($nextpage);
1306 * Display or return the next posts pages link.
1310 * @param int $max_page Optional. Max pages.
1311 * @param boolean $echo Optional. Echo or return;
1313 function next_posts( $max_page = 0, $echo = true ) {
1314 $output = esc_url( get_next_posts_page_link( $max_page ) );
1323 * Return the next posts pages link.
1327 * @param string $label Content for link text.
1328 * @param int $max_page Optional. Max pages.
1329 * @return string|null
1331 function get_next_posts_link( $label = 'Next Page »', $max_page = 0 ) {
1332 global $paged, $wp_query;
1335 $max_page = $wp_query->max_num_pages;
1341 $nextpage = intval($paged) + 1;
1343 if ( !is_single() && ( empty($paged) || $nextpage <= $max_page) ) {
1344 $attr = apply_filters( 'next_posts_link_attributes', '' );
1345 return '<a href="' . next_posts( $max_page, false ) . "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
1350 * Display the next posts pages link.
1353 * @uses get_next_posts_link()
1355 * @param string $label Content for link text.
1356 * @param int $max_page Optional. Max pages.
1358 function next_posts_link( $label = 'Next Page »', $max_page = 0 ) {
1359 echo get_next_posts_link( $label, $max_page );
1363 * Retrieve previous post pages link.
1365 * Will only return string, if not on a single page or post.
1367 * Backported to 2.0.10 from 2.1.3.
1371 * @return string|null
1373 function get_previous_posts_page_link() {
1376 if ( !is_single() ) {
1377 $nextpage = intval($paged) - 1;
1378 if ( $nextpage < 1 )
1380 return get_pagenum_link($nextpage);
1385 * Display or return the previous posts pages link.
1389 * @param boolean $echo Optional. Echo or return;
1391 function previous_posts( $echo = true ) {
1392 $output = esc_url( get_previous_posts_page_link() );
1401 * Return the previous posts pages link.
1405 * @param string $label Optional. Previous page link text.
1406 * @return string|null
1408 function get_previous_posts_link( $label = '« Previous Page' ) {
1411 if ( !is_single() && $paged > 1 ) {
1412 $attr = apply_filters( 'previous_posts_link_attributes', '' );
1413 return '<a href="' . previous_posts( false ) . "\" $attr>". preg_replace( '/&([^#])(?![a-z]{1,8};)/', '&$1', $label ) .'</a>';
1418 * Display the previous posts page link.
1421 * @uses get_previous_posts_link()
1423 * @param string $label Optional. Previous page link text.
1425 function previous_posts_link( $label = '« Previous Page' ) {
1426 echo get_previous_posts_link( $label );
1430 * Return post pages link navigation for previous and next pages.
1434 * @param string|array $args Optional args.
1435 * @return string The posts link navigation.
1437 function get_posts_nav_link( $args = array() ) {
1442 if ( !is_singular() ) {
1444 'sep' => ' — ',
1445 'prelabel' => __('« Previous Page'),
1446 'nxtlabel' => __('Next Page »'),
1448 $args = wp_parse_args( $args, $defaults );
1450 $max_num_pages = $wp_query->max_num_pages;
1451 $paged = get_query_var('paged');
1453 //only have sep if there's both prev and next results
1454 if ($paged < 2 || $paged >= $max_num_pages) {
1458 if ( $max_num_pages > 1 ) {
1459 $return = get_previous_posts_link($args['prelabel']);
1460 $return .= preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $args['sep']);
1461 $return .= get_next_posts_link($args['nxtlabel']);
1469 * Display post pages link navigation for previous and next pages.
1473 * @param string $sep Optional. Separator for posts navigation links.
1474 * @param string $prelabel Optional. Label for previous pages.
1475 * @param string $nxtlabel Optional Label for next pages.
1477 function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) {
1478 $args = array_filter( compact('sep', 'prelabel', 'nxtlabel') );
1479 echo get_posts_nav_link($args);
1483 * Retrieve page numbers links.
1487 * @param int $pagenum Optional. Page number.
1490 function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) {
1491 global $post, $wp_rewrite;
1493 $pagenum = (int) $pagenum;
1495 $result = get_permalink( $post->ID );
1497 if ( 'newest' == get_option('default_comments_page') ) {
1498 if ( $pagenum != $max_page ) {
1499 if ( $wp_rewrite->using_permalinks() )
1500 $result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged');
1502 $result = add_query_arg( 'cpage', $pagenum, $result );
1504 } elseif ( $pagenum > 1 ) {
1505 if ( $wp_rewrite->using_permalinks() )
1506 $result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged');
1508 $result = add_query_arg( 'cpage', $pagenum, $result );
1511 $result .= '#comments';
1513 $result = apply_filters('get_comments_pagenum_link', $result);
1519 * Return the link to next comments pages.
1523 * @param string $label Optional. Label for link text.
1524 * @param int $max_page Optional. Max page.
1525 * @return string|null
1527 function get_next_comments_link( $label = '', $max_page = 0 ) {
1530 if ( !is_singular() || !get_option('page_comments') )
1533 $page = get_query_var('cpage');
1535 $nextpage = intval($page) + 1;
1537 if ( empty($max_page) )
1538 $max_page = $wp_query->max_num_comment_pages;
1540 if ( empty($max_page) )
1541 $max_page = get_comment_pages_count();
1543 if ( $nextpage > $max_page )
1546 if ( empty($label) )
1547 $label = __('Newer Comments »');
1549 return '<a href="' . esc_url( get_comments_pagenum_link( $nextpage, $max_page ) ) . '" ' . apply_filters( 'next_comments_link_attributes', '' ) . '>'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
1553 * Display the link to next comments pages.
1557 * @param string $label Optional. Label for link text.
1558 * @param int $max_page Optional. Max page.
1560 function next_comments_link( $label = '', $max_page = 0 ) {
1561 echo get_next_comments_link( $label, $max_page );
1565 * Return the previous comments page link.
1569 * @param string $label Optional. Label for comments link text.
1570 * @return string|null
1572 function get_previous_comments_link( $label = '' ) {
1573 if ( !is_singular() || !get_option('page_comments') )
1576 $page = get_query_var('cpage');
1578 if ( intval($page) <= 1 )
1581 $prevpage = intval($page) - 1;
1583 if ( empty($label) )
1584 $label = __('« Older Comments');
1586 return '<a href="' . esc_url( get_comments_pagenum_link( $prevpage ) ) . '" ' . apply_filters( 'previous_comments_link_attributes', '' ) . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
1590 * Display the previous comments page link.
1594 * @param string $label Optional. Label for comments link text.
1596 function previous_comments_link( $label = '' ) {
1597 echo get_previous_comments_link( $label );
1601 * Create pagination links for the comments on the current post.
1603 * @see paginate_links()
1606 * @param string|array $args Optional args. See paginate_links.
1607 * @return string Markup for pagination links.
1609 function paginate_comments_links($args = array()) {
1610 global $wp_query, $wp_rewrite;
1612 if ( !is_singular() || !get_option('page_comments') )
1615 $page = get_query_var('cpage');
1618 $max_page = get_comment_pages_count();
1620 'base' => add_query_arg( 'cpage', '%#%' ),
1622 'total' => $max_page,
1625 'add_fragment' => '#comments'
1627 if ( $wp_rewrite->using_permalinks() )
1628 $defaults['base'] = user_trailingslashit(trailingslashit(get_permalink()) . 'comment-page-%#%', 'commentpaged');
1630 $args = wp_parse_args( $args, $defaults );
1631 $page_links = paginate_links( $args );
1633 if ( $args['echo'] )
1640 * Retrieve shortcut link.
1642 * Use this in 'a' element 'href' attribute.
1648 function get_shortcut_link() {
1649 $link = "javascript:
1655 s=(e?e():(k)?k():(x?x.createRange().text:0)),
1656 f='" . admin_url('press-this.php') . "',
1658 e=encodeURIComponent,
1659 g=f+'?u='+e(l.href)+'&t='+e(d.title)+'&s='+e(s)+'&v=2';
1661 if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=720,height=570')){
1665 if (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false)
1666 $link .= 'setTimeout(a,0);';
1670 $link .= "void(0);";
1672 $link = str_replace(array("\r", "\n", "\t"), '', $link);
1674 return apply_filters('shortcut_link', $link);
1678 * Retrieve the site url.
1680 * Returns the 'site_url' option with the appropriate protocol, 'https' if
1681 * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
1684 * @package WordPress
1687 * @param string $path Optional. Path relative to the site url.
1688 * @param string $scheme Optional. Scheme to give the site url context. Currently 'http','https', 'login', 'login_post', or 'admin'.
1689 * @return string Site url link with optional path appended.
1691 function site_url($path = '', $scheme = null) {
1692 // should the list of allowed schemes be maintained elsewhere?
1693 $orig_scheme = $scheme;
1694 if ( !in_array($scheme, array('http', 'https')) ) {
1695 if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) )
1697 elseif ( ('login' == $scheme) && ( force_ssl_admin() ) )
1699 elseif ( ('admin' == $scheme) && force_ssl_admin() )
1702 $scheme = ( is_ssl() ? 'https' : 'http' );
1705 $url = str_replace( 'http://', "{$scheme}://", get_option('siteurl') );
1707 if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
1708 $url .= '/' . ltrim($path, '/');
1710 return apply_filters('site_url', $url, $path, $orig_scheme);
1714 * Retrieve the url to the admin area.
1716 * @package WordPress
1719 * @param string $path Optional path relative to the admin url
1720 * @return string Admin url link with optional path appended
1722 function admin_url($path = '') {
1723 $url = site_url('wp-admin/', 'admin');
1725 if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
1726 $url .= ltrim($path, '/');
1728 return apply_filters('admin_url', $url, $path);
1732 * Retrieve the url to the includes directory.
1734 * @package WordPress
1737 * @param string $path Optional. Path relative to the includes url.
1738 * @return string Includes url link with optional path appended.
1740 function includes_url($path = '') {
1741 $url = site_url() . '/' . WPINC . '/';
1743 if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
1744 $url .= ltrim($path, '/');
1746 return apply_filters('includes_url', $url, $path);
1750 * Retrieve the url to the content directory.
1752 * @package WordPress
1755 * @param string $path Optional. Path relative to the content url.
1756 * @return string Content url link with optional path appended.
1758 function content_url($path = '') {
1759 $scheme = ( is_ssl() ? 'https' : 'http' );
1760 $url = WP_CONTENT_URL;
1761 if ( 0 === strpos($url, 'http') ) {
1763 $url = str_replace( 'http://', "{$scheme}://", $url );
1766 if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
1767 $url .= '/' . ltrim($path, '/');
1769 return apply_filters('content_url', $url, $path);
1773 * Retrieve the url to the plugins directory or to a specific file within that directory.
1774 * You can hardcode the plugin slug in $path or pass __FILE__ as a second argument to get the correct folder name.
1776 * @package WordPress
1779 * @param string $path Optional. Path relative to the plugins url.
1780 * @param string $plugin Optional. The plugin file that you want to be relative to - i.e. pass in __FILE__
1781 * @return string Plugins url link with optional path appended.
1783 function plugins_url($path = '', $plugin = '') {
1784 $scheme = ( is_ssl() ? 'https' : 'http' );
1786 if ( $plugin !== '' && preg_match('#^' . preg_quote(WPMU_PLUGIN_DIR . DIRECTORY_SEPARATOR, '#') . '#', $plugin) ) {
1787 $url = WPMU_PLUGIN_URL;
1789 $url = WP_PLUGIN_URL;
1792 if ( 0 === strpos($url, 'http') ) {
1794 $url = str_replace( 'http://', "{$scheme}://", $url );
1797 if ( !empty($plugin) && is_string($plugin) ) {
1798 $folder = dirname(plugin_basename($plugin));
1800 $url .= '/' . ltrim($folder, '/');
1803 if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
1804 $url .= '/' . ltrim($path, '/');
1806 return apply_filters('plugins_url', $url, $path, $plugin);