WordPressを読む 36-2 /blog/wp-includes/link-template.php 2
2014/12/18
目次
- 1 /blog/wp-includes/link-template.php 2
- 2 関数 get_day_link()
- 3 関数 the_feed_link()
- 4 関数 get_feed_link()
- 5 関数 get_post_comments_feed_link()
- 6 関数 post_comments_feed_link()
- 7 関数 get_author_feed_link()
- 8 関数 get_category_feed_link()
- 9 関数 get_term_feed_link()
- 10 関数 get_tag_feed_link()
- 11 関数 get_edit_tag_link()
- 12 関数 edit_tag_link()
- 13 関数 get_edit_term_link()
- 14 関数 edit_term_link()
- 15 関数 get_search_link()
/blog/wp-includes/link-template.php 2
関数 get_day_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | /** * Retrieve the permalink for the day archives with year and month. * * @since 1.0.0 * * @param bool|int $year False for current year. Integer of year. * @param bool|int $month False for current month. Integer of month. * @param bool|int $day False for current day. Integer of day. * @return string */ function get_day_link($year, $month, $day) { global $wp_rewrite; if ( !$year ) $year = gmdate('Y', current_time('timestamp')); if ( !$month ) $month = gmdate('m', current_time('timestamp')); if ( !$day ) $day = gmdate('j', current_time('timestamp')); $daylink = $wp_rewrite->get_day_permastruct(); if ( !empty($daylink) ) { $daylink = str_replace('%year%', $year, $daylink); $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink); $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink); $daylink = home_url( user_trailingslashit( $daylink, 'day' ) ); } else { $daylink = home_url( '?m=' . $year . zeroise( $month, 2 ) . zeroise( $day, 2 ) ); } /** * Filter the day archive permalink. * * @since 1.5.0 * * @param string $daylink Permalink for the day archive. * @param int $year Year for the archive. * @param int $month Month for the archive. * @param int $day The day for the archive. */ return apply_filters( 'day_link', $daylink, $year, $month, $day ); } |
関数 the_feed_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | /** * Display the permalink for the feed type. * * @since 3.0.0 * * @param string $anchor The link's anchor text. * @param string $feed Optional, defaults to default feed. Feed type. */ function the_feed_link( $anchor, $feed = '' ) { $link = '<a href="' . esc_url( get_feed_link( $feed ) ) . '">' . $anchor . '</a>'; /** * Filter the feed link anchor tag. * * @since 3.0.0 * * @param string $link The complete anchor tag for a feed link. * @param string $feed The feed type, or an empty string for the * default feed type. */ echo apply_filters( 'the_feed_link', $link, $feed ); } |
関数 get_feed_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | /** * Retrieve the permalink for the feed type. * * @since 1.5.0 * * @param string $feed Optional, defaults to default feed. Feed type. * @return string */ function get_feed_link($feed = '') { global $wp_rewrite; $permalink = $wp_rewrite->get_feed_permastruct(); if ( '' != $permalink ) { if ( false !== strpos($feed, 'comments_') ) { $feed = str_replace('comments_', '', $feed); $permalink = $wp_rewrite->get_comment_feed_permastruct(); } if ( get_default_feed() == $feed ) $feed = ''; $permalink = str_replace('%feed%', $feed, $permalink); $permalink = preg_replace('#/+#', '/', "/$permalink"); $output = home_url( user_trailingslashit($permalink, 'feed') ); } else { if ( empty($feed) ) $feed = get_default_feed(); if ( false !== strpos($feed, 'comments_') ) $feed = str_replace('comments_', 'comments-', $feed); $output = home_url("?feed={$feed}"); } /** * Filter the feed type permalink. * * @since 1.5.0 * * @param string $output The feed permalink. * @param string $feed Feed type. */ return apply_filters( 'feed_link', $output, $feed ); } |
関数 get_post_comments_feed_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | /** * Retrieve the permalink for the post comments feed. * * @since 2.2.0 * * @param int $post_id Optional. Post ID. * @param string $feed Optional. Feed type. * @return string */ function get_post_comments_feed_link($post_id = 0, $feed = '') { $post_id = absint( $post_id ); if ( ! $post_id ) $post_id = get_the_ID(); if ( empty( $feed ) ) $feed = get_default_feed(); if ( '' != get_option('permalink_structure') ) { if ( 'page' == get_option('show_on_front') && $post_id == get_option('page_on_front') ) $url = _get_page_link( $post_id ); else $url = get_permalink($post_id); $url = trailingslashit($url) . 'feed'; if ( $feed != get_default_feed() ) $url .= "/$feed"; $url = user_trailingslashit($url, 'single_feed'); } else { $type = get_post_field('post_type', $post_id); if ( 'page' == $type ) $url = add_query_arg( array( 'feed' => $feed, 'page_id' => $post_id ), home_url( '/' ) ); else $url = add_query_arg( array( 'feed' => $feed, 'p' => $post_id ), home_url( '/' ) ); } /** * Filter the post comments feed permalink. * * @since 1.5.1 * * @param string $url Post comments feed permalink. */ return apply_filters( 'post_comments_feed_link', $url ); } |
関数 post_comments_feed_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | /** * Display the comment feed link for a post. * * Prints out the comment feed link for a post. Link text is placed in the * anchor. If no link text is specified, default text is used. If no post ID is * specified, the current post is used. * * @since 2.5.0 * * @param string $link_text Descriptive text. * @param int $post_id Optional post ID. Default to current post. * @param string $feed Optional. Feed format. * @return string Link to the comment feed for the current post. */ function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) { $url = esc_url( get_post_comments_feed_link( $post_id, $feed ) ); if ( empty($link_text) ) $link_text = __('Comments Feed'); /** * Filter the post comment feed link anchor tag. * * @since 2.8.0 * * @param string $link The complete anchor tag for the comment feed link. * @param int $post_id Post ID. * @param string $feed The feed type, or an empty string for the default feed type. */ echo apply_filters( 'post_comments_feed_link_html', "<a href='$url'>$link_text</a>", $post_id, $feed ); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | /** * Retrieve the feed link for a given author. * * Returns a link to the feed for all posts by a given author. A specific feed * can be requested or left blank to get the default feed. * * @since 2.5.0 * * @param int $author_id ID of an author. * @param string $feed Optional. Feed type. * @return string Link to the feed for the author specified by $author_id. */ function get_author_feed_link( $author_id, $feed = '' ) { $author_id = (int) $author_id; $permalink_structure = get_option('permalink_structure'); if ( empty($feed) ) $feed = get_default_feed(); if ( '' == $permalink_structure ) { $link = home_url("?feed=$feed&author=" . $author_id); } else { $link = get_author_posts_url($author_id); if ( $feed == get_default_feed() ) $feed_link = 'feed'; else $feed_link = "feed/$feed"; $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed'); } /** * Filter the feed link for a given author. * * @since 1.5.1 * * @param string $link The author feed link. * @param string $feed Feed type. */ $link = apply_filters( 'author_feed_link', $link, $feed ); return $link; } |
関数 get_category_feed_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | /** * Retrieve the feed link for a category. * * Returns a link to the feed for all posts in a given category. A specific feed * can be requested or left blank to get the default feed. * * @since 2.5.0 * * @param int $cat_id ID of a category. * @param string $feed Optional. Feed type. * @return string Link to the feed for the category specified by $cat_id. */ function get_category_feed_link($cat_id, $feed = '') { return get_term_feed_link($cat_id, 'category', $feed); } |
関数 get_term_feed_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | /** * Retrieve the feed link for a term. * * Returns a link to the feed for all posts in a given term. A specific feed * can be requested or left blank to get the default feed. * * @since 3.0.0 * * @param int $term_id ID of a category. * @param string $taxonomy Optional. Taxonomy of $term_id * @param string $feed Optional. Feed type. * @return string Link to the feed for the term specified by $term_id and $taxonomy. */ function get_term_feed_link( $term_id, $taxonomy = 'category', $feed = '' ) { $term_id = ( int ) $term_id; $term = get_term( $term_id, $taxonomy ); if ( empty( $term ) || is_wp_error( $term ) ) return false; if ( empty( $feed ) ) $feed = get_default_feed(); $permalink_structure = get_option( 'permalink_structure' ); if ( '' == $permalink_structure ) { if ( 'category' == $taxonomy ) { $link = home_url("?feed=$feed&cat=$term_id"); } elseif ( 'post_tag' == $taxonomy ) { $link = home_url("?feed=$feed&tag=$term->slug"); } else { $t = get_taxonomy( $taxonomy ); $link = home_url("?feed=$feed&$t->query_var=$term->slug"); } } else { $link = get_term_link( $term_id, $term->taxonomy ); if ( $feed == get_default_feed() ) $feed_link = 'feed'; else $feed_link = "feed/$feed"; $link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' ); } if ( 'category' == $taxonomy ) { /** * Filter the category feed link. * * @since 1.5.1 * * @param string $link The category feed link. * @param string $feed Feed type. */ $link = apply_filters( 'category_feed_link', $link, $feed ); } elseif ( 'post_tag' == $taxonomy ) { /** * Filter the post tag feed link. * * @since 2.3.0 * * @param string $link The tag feed link. * @param string $feed Feed type. */ $link = apply_filters( 'tag_feed_link', $link, $feed ); } else { /** * Filter the feed link for a taxonomy other than 'category' or 'post_tag'. * * @since 3.0.0 * * @param string $link The taxonomy feed link. * @param string $feed Feed type. * @param string $feed The taxonomy name. */ $link = apply_filters( 'taxonomy_feed_link', $link, $feed, $taxonomy ); } return $link; } |
関数 get_tag_feed_link()
1 2 3 4 5 6 7 8 9 10 11 12 | /** * Retrieve permalink for feed of tag. * * @since 2.3.0 * * @param int $tag_id Tag ID. * @param string $feed Optional. Feed type. * @return string */ function get_tag_feed_link($tag_id, $feed = '') { return get_term_feed_link($tag_id, 'post_tag', $feed); } |
関数 get_edit_tag_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /** * Retrieve edit tag link. * * @since 2.7.0 * * @param int $tag_id Tag ID * @param string $taxonomy Taxonomy * @return string */ function get_edit_tag_link( $tag_id, $taxonomy = 'post_tag' ) { /** * Filter the edit link for a tag (or term in another taxonomy). * * @since 2.7.0 * * @param string $link The term edit link. */ return apply_filters( 'get_edit_tag_link', get_edit_term_link( $tag_id, $taxonomy ) ); } |
関数 edit_tag_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | /** * Display or retrieve edit tag link with formatting. * * @since 2.7.0 * * @param string $link Optional. Anchor text. * @param string $before Optional. Display before edit link. * @param string $after Optional. Display after edit link. * @param object $tag Tag object. * @return string HTML content. */ function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) { $link = edit_term_link( $link, '', '', $tag, false ); /** * Filter the anchor tag for the edit link for a tag (or term in another taxonomy). * * @since 2.7.0 * * @param string $link The anchor tag for the edit link. */ echo $before . apply_filters( 'edit_tag_link', $link ) . $after; } |
関数 get_edit_term_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | /** * Retrieve edit term url. * * @since 3.1.0 * * @param int $term_id Term ID * @param string $taxonomy Taxonomy * @param string $object_type The object type * @return string */ function get_edit_term_link( $term_id, $taxonomy, $object_type = '' ) { $tax = get_taxonomy( $taxonomy ); if ( !current_user_can( $tax->cap->edit_terms ) ) return; $term = get_term( $term_id, $taxonomy ); $args = array( 'action' => 'edit', 'taxonomy' => $taxonomy, 'tag_ID' => $term->term_id, ); if ( $object_type ) $args['post_type'] = $object_type; $location = add_query_arg( $args, admin_url( 'edit-tags.php' ) ); /** * Filter the edit link for a term. * * @since 3.1.0 * * @param string $location The edit link. * @param int $term_id Term ID. * @param string $taxonomy Taxonomy name. * @param string $object_type The object type (eg. the post type). */ return apply_filters( 'get_edit_term_link', $location, $term_id, $taxonomy, $object_type ); } |
関数 edit_term_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | /** * Display or retrieve edit term link with formatting. * * @since 3.1.0 * * @param string $link Optional. Anchor text. * @param string $before Optional. Display before edit link. * @param string $after Optional. Display after edit link. * @param object $term Term object. * @return string HTML content. */ function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) { if ( is_null( $term ) ) $term = get_queried_object(); if ( ! $term ) return; $tax = get_taxonomy( $term->taxonomy ); if ( ! current_user_can( $tax->cap->edit_terms ) ) return; if ( empty( $link ) ) $link = __('Edit This'); $link = '<a href="' . get_edit_term_link( $term->term_id, $term->taxonomy ) . '">' . $link . '</a>'; /** * Filter the anchor tag for the edit link of a term. * * @since 3.1.0 * * @param string $link The anchor tag for the edit link. * @param int $term_id Term ID. */ $link = $before . apply_filters( 'edit_term_link', $link, $term->term_id ) . $after; if ( $echo ) echo $link; else return $link; } |
関数 get_search_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | /** * Retrieve permalink for search. * * @since 3.0.0 * * @param string $query Optional. The query string to use. If empty the current query is used. * @return string */ function get_search_link( $query = '' ) { global $wp_rewrite; if ( empty($query) ) $search = get_search_query( false ); else $search = stripslashes($query); $permastruct = $wp_rewrite->get_search_permastruct(); if ( empty( $permastruct ) ) { $link = home_url('?s=' . urlencode($search) ); } else { $search = urlencode($search); $search = str_replace('%2F', '/', $search); // %2F(/) is not valid within a URL, send it unencoded. $link = str_replace( '%search%', $search, $permastruct ); $link = home_url( user_trailingslashit( $link, 'search' ) ); } /** * Filter the search permalink. * * @since 3.0.0 * * @param string $link Search permalink. * @param string $search The URL-encoded search term. */ return apply_filters( 'search_link', $link, $search ); } |