WordPressを読む 46-2 /blog/wp-includes/comment-template.php 2
2015/01/14
目次
- 1 /blog/wp-includes/comment-template.php 2
- 2 関数 get_comment_excerpt()
- 3 関数 comment_excerpt()
- 4 関数 get_comment_ID()
- 5 関数 comment_ID()
- 6 関数 get_comment_link()
- 7 関数 get_comments_link()
- 8 関数 comments_link()
- 9 関数 get_comments_number()
- 10 関数 comments_number()
- 11 関数 get_comment_text()
- 12 関数 comment_text()
- 13 関数 get_comment_time()
- 14 関数 comment_time()
- 15 関数 get_comment_type()
- 16 関数 comment_type()
- 17 関数 get_trackback_url()
- 18 関数 trackback_url()
- 19 関数 trackback_rdf()
- 20 関数 comments_open()
/blog/wp-includes/comment-template.php 2
関数 get_comment_excerpt()
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 | /** * Retrieve the excerpt of the current comment. * * Will cut each word and only output the first 20 words with '…' at the end. * If the word count is less than 20, then no truncating is done and no '…' * will appear. * * @since 1.5.0 * * @param int $comment_ID ID of the comment for which to get the excerpt. * Default current comment. * @return string The maybe truncated comment with 20 words or less. */ function get_comment_excerpt( $comment_ID = 0 ) { $comment = get_comment( $comment_ID ); $comment_text = strip_tags($comment->comment_content); $blah = explode(' ', $comment_text); if (count($blah) > 20) { $k = 20; $use_dotdotdot = 1; } else { $k = count($blah); $use_dotdotdot = 0; } $excerpt = ''; for ($i=0; $i<$k; $i++) { $excerpt .= $blah[$i] . ' '; } $excerpt .= ($use_dotdotdot) ? '…' : ''; /** * Filter the retrieved comment excerpt. * * @since 1.5.0 * * @param string $excerpt The comment excerpt text. */ return apply_filters( 'get_comment_excerpt', $excerpt ); } |
関数 comment_excerpt()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /** * Display the excerpt of the current comment. * * @since 1.2.0 * * @param int $comment_ID ID of the comment for which to print the excerpt. * Default current comment. */ function comment_excerpt( $comment_ID = 0 ) { $comment_excerpt = get_comment_excerpt($comment_ID); /** * Filter the comment excerpt for display. * * @since 1.2.0 * * @param string $comment_excerpt The comment excerpt text. */ echo apply_filters( 'comment_excerpt', $comment_excerpt ); } |
関数 get_comment_ID()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | /** * Retrieve the comment id of the current comment. * * @since 1.5.0 * * @return int The comment ID. */ function get_comment_ID() { global $comment; /** * Filter the returned comment ID. * * @since 1.5.0 * * @param int $comment_ID The current comment ID. */ return apply_filters( 'get_comment_ID', $comment->comment_ID ); } |
関数 comment_ID()
1 2 3 4 5 6 7 8 | /** * Display the comment id of the current comment. * * @since 0.71 */ function comment_ID() { echo get_comment_ID(); } |
関数 get_comment_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 | /** * Retrieve the link to a given comment. * * @since 1.5.0 * * @see get_page_of_comment() * * @param mixed $comment Comment to retrieve. Default current comment. * @param array $args Optional. An array of arguments to override the defaults. * @return string The permalink to the given comment. */ function get_comment_link( $comment = null, $args = array() ) { global $wp_rewrite, $in_comment_loop; $comment = get_comment($comment); // Backwards compat if ( ! is_array( $args ) ) { $args = array( 'page' => $args ); } $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' ); $args = wp_parse_args( $args, $defaults ); if ( '' === $args['per_page'] && get_option('page_comments') ) $args['per_page'] = get_option('comments_per_page'); if ( empty($args['per_page']) ) { $args['per_page'] = 0; $args['page'] = 0; } if ( $args['per_page'] ) { if ( '' == $args['page'] ) $args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args ); if ( $wp_rewrite->using_permalinks() ) $link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . 'comment-page-' . $args['page'], 'comment' ); else $link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) ); } else { $link = get_permalink( $comment->comment_post_ID ); } $link = $link . '#comment-' . $comment->comment_ID; /** * Filter the returned single comment permalink. * * @since 2.8.0 * * @see get_page_of_comment() * * @param string $link The comment permalink with '#comment-$id' appended. * @param object $comment The current comment object. * @param array $args An array of arguments to override the defaults. */ return apply_filters( 'get_comment_link', $link, $comment, $args ); } |
関数 get_comments_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | /** * Retrieve the link to the current post comments. * * @since 1.5.0 * * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post. * @return string The link to the comments. */ function get_comments_link( $post_id = 0 ) { $comments_link = get_permalink( $post_id ) . '#comments'; /** * Filter the returned post comments permalink. * * @since 3.6.0 * * @param string $comments_link Post comments permalink with '#comments' appended. * @param int|WP_Post $post_id Post ID or WP_Post object. */ return apply_filters( 'get_comments_link', $comments_link, $post_id ); } |
関数 comments_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | /** * Display the link to the current post comments. * * @since 0.71 * * @param string $deprecated Not Used. * @param bool $deprecated_2 Not Used. */ function comments_link( $deprecated = '', $deprecated_2 = '' ) { if ( !empty( $deprecated ) ) _deprecated_argument( __FUNCTION__, '0.72' ); if ( !empty( $deprecated_2 ) ) _deprecated_argument( __FUNCTION__, '1.3' ); echo esc_url( get_comments_link() ); } |
関数 get_comments_number()
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 | /** * Retrieve the amount of comments a post has. * * @since 1.5.0 * * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post. * @return int The number of comments a post has. */ function get_comments_number( $post_id = 0 ) { $post_id = absint( $post_id ); if ( !$post_id ) $post_id = get_the_ID(); $post = get_post($post_id); if ( ! isset($post->comment_count) ) $count = 0; else $count = $post->comment_count; /** * Filter the returned comment count for a post. * * @since 1.5.0 * * @param int $count Nnumber of comments a post has. * @param int|WP_Post $post_id Post ID or WP_Post object. */ return apply_filters( 'get_comments_number', $count, $post_id ); } |
関数 comments_number()
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 | /** * Display the language string for the number of comments the current post has. * * @since 0.71 * * @param string $zero Optional. Text for no comments. Default false. * @param string $one Optional. Text for one comment. Default false. * @param string $more Optional. Text for more than one comment. Default false. * @param string $deprecated Not used. */ function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) { if ( !empty( $deprecated ) ) _deprecated_argument( __FUNCTION__, '1.3' ); $number = get_comments_number(); if ( $number > 1 ) $output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('% Comments') : $more); elseif ( $number == 0 ) $output = ( false === $zero ) ? __('No Comments') : $zero; else // must be one $output = ( false === $one ) ? __('1 Comment') : $one; /** * Filter the comments count for display. * * @since 1.5.0 * * @see _n() * * @param string $output A translatable string formatted based on whether the count * is equal to 0, 1, or 1+. * @param int $number The number of post comments. */ echo apply_filters( 'comments_number', $output, $number ); } |
関数 get_comment_text()
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 | /** * Retrieve the text of the current comment. * * @since 1.5.0 * * @see Walker_Comment::comment() * * @param int $comment_ID ID of the comment for which to get the text. Default current comment. * @param array $args Optional. An array of arguments. Default empty. * @return string The comment content. */ function get_comment_text( $comment_ID = 0, $args = array() ) { $comment = get_comment( $comment_ID ); /** * Filter the text of a comment. * * @since 1.5.0 * * @see Walker_Comment::comment() * * @param string $comment_content Text of the comment. * @param object $comment The comment object. * @param array $args An array of arguments. */ return apply_filters( 'get_comment_text', $comment->comment_content, $comment, $args ); } |
関数 comment_text()
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 | /** * Display the text of the current comment. * * @since 0.71 * * @see Walker_Comment::comment() * * @param int $comment_ID ID of the comment for which to print the text. Default 0. * @param array $args Optional. An array of arguments. Default empty array. Default empty. */ function comment_text( $comment_ID = 0, $args = array() ) { $comment = get_comment( $comment_ID ); $comment_text = get_comment_text( $comment_ID , $args ); /** * Filter the text of a comment to be displayed. * * @since 1.2.0 * * @see Walker_Comment::comment() * * @param string $comment_text Text of the current comment. * @param object $comment The comment object. * @param array $args An array of arguments. */ echo apply_filters( 'comment_text', $comment_text, $comment, $args ); } |
関数 get_comment_time()
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 | /** * Retrieve the comment time of the current comment. * * @since 1.5.0 * * @param string $d Optional. The format of the time. Default user's settings. * @param bool $gmt Optional. Whether to use the GMT date. Default false. * @param bool $translate Optional. Whether to translate the time (for use in feeds). * Default true. * @return string The formatted time. */ function get_comment_time( $d = '', $gmt = false, $translate = true ) { global $comment; $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date; if ( '' == $d ) $date = mysql2date(get_option('time_format'), $comment_date, $translate); else $date = mysql2date($d, $comment_date, $translate); /** * Filter the returned comment time. * * @since 1.5.0 * * @param string|int $date The comment time, formatted as a date string or Unix timestamp. * @param string $d Date format. * @param bool $gmt Whether the GMT date is in use. * @param bool $translate Whether the time is translated. * @param object $comment The comment object. */ return apply_filters( 'get_comment_time', $date, $d, $gmt, $translate, $comment ); } |
関数 comment_time()
1 2 3 4 5 6 7 8 9 10 | /** * Display the comment time of the current comment. * * @since 0.71 * * @param string $d Optional. The format of the time. Default user's settings. */ function comment_time( $d = '' ) { echo get_comment_time($d); } |
関数 get_comment_type()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | /** * Retrieve the comment type of the current comment. * * @since 1.5.0 * * @param int $comment_ID ID of the comment for which to get the type. Default current comment. * @return string The comment type. */ function get_comment_type( $comment_ID = 0 ) { $comment = get_comment( $comment_ID ); if ( '' == $comment->comment_type ) $comment->comment_type = 'comment'; /** * Filter the returned comment type. * * @since 1.5.0 * * @param string $comment_type The type of comment, such as 'comment', 'pingback', or 'trackback'. */ return apply_filters( 'get_comment_type', $comment->comment_type ); } |
関数 comment_type()
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 | /** * Display the comment type of the current comment. * * @since 0.71 * * @param string $commenttxt Optional. String to display for comment type. Default false. * @param string $trackbacktxt Optional. String to display for trackback type. Default false. * @param string $pingbacktxt Optional. String to display for pingback type. Default false. */ function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false ) { if ( false === $commenttxt ) $commenttxt = _x( 'Comment', 'noun' ); if ( false === $trackbacktxt ) $trackbacktxt = __( 'Trackback' ); if ( false === $pingbacktxt ) $pingbacktxt = __( 'Pingback' ); $type = get_comment_type(); switch( $type ) { case 'trackback' : echo $trackbacktxt; break; case 'pingback' : echo $pingbacktxt; break; default : echo $commenttxt; } } |
関数 get_trackback_url()
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 | /** * Retrieve The current post's trackback URL. * * There is a check to see if permalink's have been enabled and if so, will * retrieve the pretty path. If permalinks weren't enabled, the ID of the * current post is used and appended to the correct page to go to. * * @since 1.5.0 * * @return string The trackback URL after being filtered. */ function get_trackback_url() { if ( '' != get_option('permalink_structure') ) $tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback'); else $tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . get_the_ID(); /** * Filter the returned trackback URL. * * @since 2.2.0 * * @param string $tb_url The trackback URL. */ return apply_filters( 'trackback_url', $tb_url ); } |
関数 trackback_url()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | /** * Display the current post's trackback URL. * * @since 0.71 * * @param bool $deprecated_echo Not used. * @return void|string Should only be used to echo the trackback URL, use get_trackback_url() * for the result instead. */ function trackback_url( $deprecated_echo = true ) { if ( $deprecated_echo !== true ) _deprecated_argument( __FUNCTION__, '2.5', __('Use <code>get_trackback_url()</code> instead if you do not want the value echoed.') ); if ( $deprecated_echo ) echo get_trackback_url(); else return get_trackback_url(); } |
関数 trackback_rdf()
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 | /** * Generate and display the RDF for the trackback information of current post. * * Deprecated in 3.0.0, and restored in 3.0.1. * * @since 0.71 * * @param int $deprecated Not used (Was $timezone = 0). */ function trackback_rdf( $deprecated = '' ) { if ( ! empty( $deprecated ) ) { _deprecated_argument( __FUNCTION__, '2.5' ); } if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && false !== stripos( $_SERVER['HTTP_USER_AGENT'], 'W3C_Validator' ) ) { return; } echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"> <rdf:Description rdf:about="'; the_permalink(); echo '"'."\n"; echo ' dc:identifier="'; the_permalink(); echo '"'."\n"; echo ' dc:title="'.str_replace('--', '--', wptexturize(strip_tags(get_the_title()))).'"'."\n"; echo ' trackback:ping="'.get_trackback_url().'"'." />\n"; echo '</rdf:RDF>'; } |
関数 comments_open()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | /** * Whether the current post is open for comments. * * @since 1.5.0 * * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post. * @return bool True if the comments are open. */ function comments_open( $post_id = null ) { $_post = get_post($post_id); $open = ( 'open' == $_post->comment_status ); /** * Filter whether the current post is open for comments. * * @since 2.5.0 * * @param bool $open Whether the current post is open for comments. * @param int|WP_Post $post_id The post ID or WP_Post object. */ return apply_filters( 'comments_open', $open, $post_id ); } |