protected function comment($comment, $depth, $args) { // each comment markup, without </li>! $classes = implode(' ', get_comment_class()) . ($comment->comment_author_email == get_the_author_meta('email') ? ' author-comment' : ''); // get typical wp comment classes and if comment belong post autor add "author-comment" class echo '<li id="li-comment-' . get_comment_ID() . '" class="' . $classes . '">' . "\n"; // parent tag with classes and uniq id echo '<div id="comment-' . get_comment_ID() . '">' . "\n"; // anchor element with this id need to anchor links on comments works echo get_avatar($comment, 64) . "\n"; // show avatar with size 64x64 px echo '<p class="meta">Posted by: ' . get_comment_author() . "\n"; // comment autor name echo ' ' . get_comment_author_email(); // comment autor email echo ' ' . get_comment_author_url(); // comment autor url echo ' On ' . get_comment_date('F j, Y') . ' at ' . get_comment_time() . '</p>' . "\n"; // date and time of comment creating if ('0' == $comment->comment_approved) { echo '<em class="comment-awaiting-moderation">Your comment is awaiting moderation</em>' . "\n"; } // if comment is not approved notify of it comment_text() . "\n"; // display comment text $reply_link_args = array('depth' => $depth, 'reply_text' => 'Reply on it', 'login_text' => 'You must be logged to post comments'); echo get_comment_reply_link(array_merge($args, $reply_link_args)); // display reply link echo '</div>' . "\n"; // anchor element end }
function dsq_render_single_comment($comment, $args, $depth) { $GLOBALS['comment'] = $comment; ?> <li id="dsq-comment-<?php echo (int) get_comment_ID(); ?> "> <div id="dsq-comment-header-<?php echo (int) get_comment_ID(); ?> " class="dsq-comment-header"> <cite id="dsq-cite-<?php echo (int) get_comment_ID(); ?> "> <?php if (comment_author_url()) { ?> <a id="dsq-author-user-<?php echo (int) get_comment_ID(); ?> " href="<?php echo esc_url(get_comment_author_url()); ?> " target="_blank" rel="nofollow"><?php echo esc_html(get_comment_author()); ?> </a> <?php } else { ?> <span id="dsq-author-user-<?php echo (int) get_comment_ID(); ?> "><?php echo esc_html(get_comment_author()); ?> </span> <?php } ?> </cite> </div> <div id="dsq-comment-body-<?php echo (int) get_comment_ID(); ?> " class="dsq-comment-body"> <div id="dsq-comment-message-<?php echo (int) get_comment_ID(); ?> " class="dsq-comment-message"><?php wp_filter_kses(comment_text()); ?> </div> </div> </li> <?php }
protected function comment($comment, $depth, $args) { // разметка каждого комментария, без закрывающего </li>! $classes = implode(' ', get_comment_class()) . ($comment->comment_author_email == get_the_author_meta('email') ? ' author-comment' : ''); // берем стандартные классы комментария и если коммент пренадлежит автору поста добавляем класс author-comment echo '<li id="li-comment-' . get_comment_ID() . '" class="' . $classes . '">' . "\n"; // родительский тэг комментария с классами выше и уникальным id echo '<div id="comment-' . get_comment_ID() . '">' . "\n"; // элемент с таким id нужен для якорных ссылок на коммент echo get_avatar($comment, 64) . "\n"; // покажем аватар с размером 64х64 echo '<p class="meta">Автор: ' . get_comment_author() . "\n"; // имя автора коммента //echo ' '.get_comment_author_email(); // email автора коммента echo ' ' . get_comment_author_url(); // url автора коммента echo ' <br>Добавлено ' . get_comment_date('F j, Y') . ' в ' . get_comment_time() . "\n"; // дата и время комментирования if ('0' == $comment->comment_approved) { echo '<em class="comment-awaiting-moderation">Ваш комментарий будет опубликован после проверки модератором.</em>' . "\n"; } // если комментарий должен пройти проверку comment_text() . "\n"; // текст коммента $reply_link_args = array('depth' => $depth, 'reply_text' => 'Ответить', 'login_text' => 'Вы должны быть залогинены'); echo get_comment_reply_link(array_merge($args, $reply_link_args)); // выводим ссылку ответить echo '</div>' . "\n"; // закрываем див }
/** * widget function. * * @see WP_Widget * * @param array $args * @param array $instance */ public function widget($args, $instance) { global $comments, $comment; if ($this->get_cached_widget($args)) { return; } ob_start(); $number = !empty($instance['number']) ? absint($instance['number']) : $this->settings['number']['std']; $comments = get_comments(array('number' => $number, 'status' => 'approve', 'post_status' => 'publish', 'post_type' => 'product')); if ($comments) { $this->widget_start($args, $instance); echo '<ul class="product_list_widget">'; foreach ((array) $comments as $comment) { $_product = wc_get_product($comment->comment_post_ID); $rating = intval(get_comment_meta($comment->comment_ID, 'rating', true)); $rating_html = $_product->get_rating_html($rating); echo '<li><a href="' . esc_url(get_comment_link($comment->comment_ID)) . '">'; echo $_product->get_image(); echo $_product->get_title() . '</a>'; echo $rating_html; printf('<span class="reviewer">' . _x('by %1$s', 'by comment author', 'woocommerce') . '</span>', get_comment_author()); echo '</li>'; } echo '</ul>'; $this->widget_end($args); } $content = ob_get_clean(); echo $content; $this->cache_widget($args, $content); }
/** * widget function. * * @see WP_Widget * @access public * @param array $args * @param array $instance * @return void */ public function widget($args, $instance) { global $comments, $comment, $woocommerce; if ($this->get_cached_widget($args)) { return; } ob_start(); extract($args); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); $number = absint($instance['number']); $comments = get_comments(array('number' => $number, 'status' => 'approve', 'post_status' => 'publish', 'post_type' => 'product')); if ($comments) { echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } echo '<ul class="product_list_widget">'; foreach ((array) $comments as $comment) { $_product = get_product($comment->comment_post_ID); $rating = intval(get_comment_meta($comment->comment_ID, 'rating', true)); $rating_html = $_product->get_rating_html($rating); echo '<li><a href="' . esc_url(get_comment_link($comment->comment_ID)) . '">'; echo $_product->get_image(); echo $_product->get_title() . '</a>'; echo $rating_html; printf('<span class="reviewer">' . _x('by %1$s', 'by comment author', 'woocommerce') . '</span>', get_comment_author()); echo '</li>'; } echo '</ul>'; echo $after_widget; } $content = ob_get_clean(); echo $content; $this->cache_widget($args, $content); }
function mysiteapp_get_member_for_comment() { $need_g_avatar = true; $user = array(); $user['author'] = get_comment_author(); $user['link'] = get_comment_author_url(); $options = get_option('uppsite_options'); if (isset($options['disqus'])) { $user['avatar'] = mysiteapp_get_pic_from_fb_profile($user['link']); if ($user['avatar']) { $need_g_avatar = false; } } if ($need_g_avatar) { if (function_exists('get_avatar') && function_exists('htmlspecialchars_decode')) { $user['avatar'] = htmlspecialchars_decode(uppsite_extract_src_url(get_avatar(get_comment_author_email()))); } } ?> <member> <name><![CDATA[<?php echo $user['author']; ?> ]]></name> <member_link><![CDATA[<?php echo $user['link']; ?> ]]></member_link> <avatar><![CDATA[<?php echo $user['avatar']; ?> ]]></avatar> </member><?php }
/** * The search function * * @return array of results */ protected function do_search() { global $wpdb; $commentsresults = array(); if (isset($wpdb->base_prefix)) { $_prefix = $wpdb->base_prefix; } else { $_prefix = $wpdb->prefix; } $options = $this->options; $searchData = $this->searchData; $s = $this->s; $_s = $this->_s; if ($options['set_incomments'] && count($_s) > 0) { $like = "lower({$wpdb->comments}.comment_content) REGEXP '" . implode('|', $_s) . "'"; $querystr = "\r\n \t\tSELECT \r\n {$wpdb->comments}.comment_ID as id,\r\n {$wpdb->comments}.comment_post_ID as post_id,\r\n {$wpdb->comments}.user_id as user_id,\r\n {$wpdb->comments}.comment_content as content,\r\n 'comment' as content_type,\r\n {$wpdb->comments}.comment_date as date\r\n \t\tFROM {$wpdb->comments}\r\n \t\tWHERE\r\n ({$wpdb->comments}.comment_approved=1)\r\n AND\r\n (" . $like . ")\r\n \t\tORDER BY {$wpdb->comments}.comment_ID DESC\r\n \t\tLIMIT " . $searchData['maxresults']; //var_dump($querystr); $commentsresults = $wpdb->get_results($querystr, OBJECT); if (is_array($commentsresults)) { foreach ($commentsresults as $k => $v) { $commentsresults[$k]->link = get_comment_link($v->id); $commentsresults[$k]->author = get_comment_author($v->id); $commentsresults[$k]->title = wd_substr_at_word($commentsresults[$k]->content, 40) . "..."; } } } $this->results = $commentsresults; return $commentsresults; }
function my_custom_comments($comment, $args, $depth) { $GLOBALS['comment'] = $comment; ?> <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?> "> <?php if ($comment->comment_approved == '0') { ?> <em><?php _e('Your comment is awaiting moderation.'); ?> </em> <?php } ?> <?php echo '<div class="pull-left"><div class="commentor-avatar" style="height: 90px; width: 90px; background: url(' . get_avatar_url($comment) . ') no-repeat center center; background-size: cover;"><div class="commentor-name">' . get_comment_author() . '</div></div></div>'; comment_text(); echo '<div class="clearfix"></div>'; }
/** * Set the content width based on the theme's design and stylesheet. * * Used to set the width of images and content. Should be equal to the width the theme * is designed for, generally via the style.css stylesheet. */ function comment_author_profile_link() { /* Get the comment author information */ global $comment; $comment_ID = $comment->user_id; $author = get_comment_author($comment_ID); $url = get_comment_author_url($comment_ID); /* Check if commenter is registered or not */ /* Registered Commenter */ $registeredID = get_userdata($comment_ID); $authorName = $registeredID->display_name; $authorLevel = $registeredID->user_level; $authorURL = $registeredID->user_url; $authorID = $registeredID->ID; /* Check if they have edit posts capabilities & is author or higher */ if ($authorLevel > 1 && user_can($authorID, 'edit_posts') == true && count_user_posts($authorID) > 0) { /* Author+ with Posts */ $return = '<a href="' . home_url() . '/?author=' . $authorID . '">' . $authorName . '</a>'; } else { /* Below Author */ if (empty($authorURL) || 'http://' == $authorURL) { $return = $authorName; } else { $return = "<a href='{$authorURL}' rel='external nofollow' class='url' target='_blank'>{$authorName}</a>"; } } return $return; }
function mydesign($comment, $args, $depth) { $GLOBALS['comment'] = $comment; $users = get_users(); ?> <li id="comment-<?php echo comment_id(); ?> " class="compost"> <?php // ユーザーIDを引っ張る foreach ($users as $user) { //echo $user->display_name.'<br />'; //echo get_comment_author(); if ($user->display_name == get_comment_author()) { break; } } ?> <span class="trick_rounded-img icon_image" style="background: url(<?php echo ps_get_user_profile_image_src($user->ID, 'standard'); ?> ) no-repeat center center; width: 50px; height: 50px;></span> <span class="trick_thumbnail_Image"> <?php ps_user_profile_image($user->ID, 'thumbnail'); ?> </span> <?php ?> <div class="commentarea"> <?php //改行表示 $commentstr = '<p>' . get_comment_text() . '</p>'; $commentstr = preg_replace("/\n/", "<br />", $commentstr); echo $commentstr; //comment_text(); ?> </div> <p class="cominfo"> <?php comment_date(); ?> <?php comment_time(); ?> | <?php comment_author_link(); ?> <?php comment_reply_link(array_merge($args, array('depth' => $depth, 'reply_text' => '返信', 'before' => ' | ', 'after' => ''))); ?> </p> </li> <?php }
function framework_comment_avatar($avatar = true, $gravatar_size = 50) { $author = get_comment_author(); $url = get_comment_author_url(); if (!empty($url) || 'http://' == !$url) { $uri = ' href="' . $url . '" '; } else { $uri = NULL; } if ($avatar) { // Get author's gavatar $gravatar_email = get_comment_author_email(); $gravatar_size = apply_filters('framework_gravatar_size', (int) $gravatar_size); // Available filter: framework_gravatar_size $gravatar = get_avatar($gravatar_email, $gravatar_size); // get the $src data from $gavatar if (preg_match('/src=\'(.*?)\'/i', $gravatar, $matches)) { $src = $matches[1]; } // Rebuild Gravatar link because get_avatar() produces invalid code :/ (P.S. adds "gravatar" class) $output = "<a class=\"avatar-link\"{$uri}><img class=\"avatar gravatar gravatar-{$gravatar_size}\" alt=\"{$author}'s Gravatar\" src=\"{$src}\" width=\"{$gravatar_size}\" height=\"{$gravatar_size}\" /></a>"; return apply_filters('framework_comment_avatar', (string) $output); // Available filter: framework_comment_avatar } }
function tokopress_comments($comment, $args, $depth) { $GLOBALS['comment'] = $comment; ?> <li itemprop="reviews" itemscope="" itemtype="http://schema.org/Review" class="comment even thread-even depth-1" id="li-comment-105"> <div id="comment-105" class="comment_container"> <?php echo get_avatar($comment, $size = '60'); ?> <div class="comment-text"> <div class="entry-meta"> <span class="author vcard"><a class="url fn n" rel="author" href="<?php echo get_comment_author_url(); ?> " title="<?php echo get_comment_author(); ?> <?php _e('Says', 'tokopress'); ?> "><?php echo get_comment_author(); ?> </a></span> <time class="published" datetime="<?php echo get_comment_date('c'); ?> " title="<?php echo get_comment_date('l, F jS, Y, g:i a'); ?> "><?php echo get_comment_date(); ?> </time> <?php comment_reply_link(array_merge($args, array('reply_text' => __('. Reply', 'tokopress'), 'after' => '', 'depth' => $depth, 'max_depth' => $args['max_depth']))); ?> </div> <div itemprop="description" class="description"> <?php if ($comment->comment_approved == '0') { ?> <div class="alert alert-moderation"> <p><em><?php _e('Your comment is awaiting moderation.', 'tokopress'); ?> </em></p> </div> <?php } ?> <?php comment_text(); ?> </div> </div> </div> </li><!-- #comment-## --> <?php }
/** * @param object $comment * @param int $depth * @param array $args */ protected function comment($comment, $depth, $args) { ?> <li <?php comment_class($this->has_children ? 'parent' : '', $comment->comment_ID); ?> id="comment-<?php comment_ID(); ?> "> <?php if (1 === $depth) { ?> <div class="row"><?php } ?> <div class="media media--nofloat"> <div class="img"> <?php $avatar_size = 1 === $depth ? 100 : 70; echo get_avatar($comment, $avatar_size, '', get_comment_author()); ?> </div> <div class="bd"> <div class="comment-author"> <?php printf(__('By <cite class="fn">%s</cite> <span class="date">on %s</span>', 'yoast-theme'), get_comment_author_link(), get_comment_date()); ?> </div> <div class="comment-content"> <?php if ($comment->comment_approved == '0') { ?> <p class="alert"><?php echo apply_filters('genesis_comment_awaiting_moderation', __('Your comment is awaiting moderation.', 'genesis')); ?> </p> <?php } ?> <?php comment_text(); ?> </div> </div> </div> <div class="reply"> <?php comment_reply_link(array_merge($args, array('add_below' => 'comment', 'depth' => $depth, 'max_depth' => $args['max_depth']))); ?> <?php edit_comment_link('edit', ' | ', ''); ?> </div> <?php }
/** * strip the link off the name if comment is in moderation * @param string $authorlink * @return string */ function gasp_get_comment_author($authorlink) { global $comment; if ($comment->comment_approved == '0') { return get_comment_author(); } return $authorlink; }
function outdoor_comment_template($comment, $args, $depth) { $GLOBALS['comment'] = $comment; // End php code ?> <li <?php comment_class(''); ?> id="li-comment-<?php comment_ID(); ?> "> <div id="comment-<?php comment_ID(); ?> "> <?php if (0 != $args['avatar_size']) { echo get_avatar($comment, $args['avatar_size']); } ?> <div class="meta"> <?php printf(__('<cite class="fn">%s</cite>'), get_comment_author()); ?> <?php /* translators: 1: date, 2: time */ printf(__('<time> — %1$s at %2$s</time>'), get_comment_date(), get_comment_time()); edit_comment_link(__('(Edit)'), ' ', ''); ?> <?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth'], 'before' => '', 'after' => ''))); ?> </div> <?php if ('0' == $comment->comment_approved) { ?> <em class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.'); ?> </em> <br> <?php } ?> <?php comment_text(get_comment_id(), array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth']))); ?> </div> <?php // Start php code }
protected function do_search() { global $wpdb; if (isset($wpdb->base_prefix)) { $_prefix = $wpdb->base_prefix; } else { $_prefix = $wpdb->prefix; } $options = $this->options; $searchData = $this->searchData; $s = $this->s; $_s = $this->_s; $allcommentsresults = array(); if ($options['set_incomments']) { $like = ""; if ($not_exactonly) { $sr = implode("%' OR lower({$wpdb->comments}.comment_content) like '%", $_s); if ($like != "") { $sr = " OR lower({$wpdb->comments}.comment_content) like '%" . $sr . "%'"; } else { $sr = " lower({$wpdb->comments}.comment_content) like '%" . $sr . "%'"; } } else { if ($like != "") { $sr = " OR lower({$wpdb->comments}.comment_content) like '%" . $s . "%'"; } else { $sr = " lower({$wpdb->comments}.comment_content) like '%" . $s . "%'"; } } $like .= $sr; $querystr = "\n \t\tSELECT \n {$wpdb->comments}.comment_ID as id,\n {$wpdb->comments}.comment_post_ID as post_id,\n {$wpdb->comments}.user_id as user_id,\n {$wpdb->comments}.comment_content as content,\n {$wpdb->comments}.comment_date as date\n \t\tFROM {$wpdb->comments}\n \t\tWHERE\n ({$wpdb->comments}.comment_approved=1)\n AND\n (" . $like . ")\n \t\tORDER BY {$wpdb->comments}.comment_ID DESC\n \t\tLIMIT " . $searchData['maxresults']; $commentsresults = $wpdb->get_results($querystr, OBJECT); if (is_array($commentsresults)) { foreach ($commentsresults as $k => $v) { $commentsresults[$k]->link = get_comment_link($v->id); $commentsresults[$k]->author = get_comment_author($v->id); if ($searchData['settings-imagesettings']['show'] == 1) { $imgs = $searchData['settings-imagesettings']; ksort($imgs['from']); foreach ($imgs['from'] as $kk => $source) { $img = new wpdreamsImageCache($v->content, "comment" . $v->id, AJAXSEARCHPRO_PATH . DIRECTORY_SEPARATOR . "cache" . DIRECTORY_SEPARATOR, $imgs['width'], $imgs['height'], $imgs['imagenum'], $searchData['imagebg']); $res = $img->get_image(); if ($res != '') { $commentsresults[$k]->image = plugins_url('/ajax-search-pro/cache/' . $res); break; } } } $commentsresults[$k]->title = substr($commentsresults[$k]->content, 0, 15) . "..."; } } $allcommentsresults = array_merge($allcommentsresults, $commentsresults); } $this->results = $allcommentsresults; return $allcommentsresults; }
function ct_apex_customize_comments($comment, $args, $depth) { $GLOBALS['comment'] = $comment; global $post; ?> <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?> "> <article id="comment-<?php comment_ID(); ?> " class="comment"> <div class="comment-author"> <?php echo get_avatar(get_comment_author_email(), 48, '', get_comment_author()); ?> <span class="author-name"><?php comment_author_link(); ?> </span> </div> <div class="comment-content"> <?php if ($comment->comment_approved == '0') { ?> <em><?php _e('Your comment is awaiting moderation.', 'apex'); ?> </em> <br/> <?php } ?> <?php comment_text(); ?> </div> <div class="comment-footer"> <span class="comment-date"><?php comment_date(); ?> </span> <?php comment_reply_link(array_merge($args, array('reply_text' => __('Reply', 'apex'), 'depth' => $depth, 'max_depth' => $args['max_depth']))); ?> <?php edit_comment_link(__('Edit', 'apex')); ?> </div> </article> <?php }
/** * Remove post author URL * * @since 1.0.0 * @access public * @return string remove the author's url from comment post */ function remove_post_author_weburl($return) { global $comment, $post; if (!is_admin()) { $author = get_comment_author(get_comment_ID()); return $author; } else { return $return; } }
/** * @see CPAC_Column::get_value() * @since 2.0 */ public function get_value($id) { $value = ''; $parent = $this->get_raw_value($id); if ($parent) { $parent = get_comment($parent); $value = sprintf('<a href="%1$s">%2$s</a>', esc_url(get_comment_link($parent)), get_comment_author($parent->comment_ID)); } return $value; }
function at_comment_parent($comment_text) { global $comment; $return = ''; if ($comment->comment_parent != 0) { $return .= '<a class="at_parent_comment_author" href="' . htmlspecialchars(get_comment_link($comment->comment_parent)) . '">@' . get_comment_author($comment->comment_parent) . '</a>'; } $return .= $comment_text; return $return; }
function wpi_comment_copy_cc() { $date = (int) get_comment_date('Y'); $cur = date('Y', $_SERVER['REQUEST_TIME']); if ($cur > $date) { $date = $date . ' - ' . $cur; } $cc = _t('small', '(cc)'); $cc .= _t('span', ' ' . $date . ' ' . get_comment_author()); t('p', $cc, array('class' => 'ta-r')); }
public static function getCommentAuthor($commentID) { if (class_exists(InnThemeComment::class) && method_exists(InnThemeComment::class, 'getCommentAuthor')) { return InnThemeComment::getCommentAuthor($commentID); } static $cache = []; if (!isset($cache[$commentID])) { $cache[$commentID] = htmlspecialchars(\get_comment_author($commentID)); } return $cache[$commentID]; }
function widget($args, $instance) { global $comments, $comment, $woocommerce; $cache = wp_cache_get('widget_recent_reviews', 'widget'); if (!is_array($cache)) { $cache = array(); } if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return; } ob_start(); extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Reviews', 'woocommerce') : $instance['title'], $instance, $this->id_base); if (!($number = absint($instance['number']))) { $number = 5; } $comments = get_comments(array('number' => $number, 'status' => 'approve', 'post_status' => 'publish', 'post_type' => 'product')); if ($comments) { echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } echo '<ul class="ratings-small">'; foreach ((array) $comments as $comment) { $_product = get_product($comment->comment_post_ID); $rating = intval(get_comment_meta($comment->comment_ID, 'rating', true)); $rating_html = $_product->get_rating_html($rating); echo '<li>'; echo '<div class="image"> <a href="' . esc_url(get_comment_link($comment->comment_ID)) . '" title="' . esc_attr($_product->get_title()) . '"> <img src="http://www.gravatar.com/avatar/' . md5(get_comment_author_email()) . '?s=60&d=retro&r=g" alt="" /> </a> </div>'; echo '<div class="desc"> <h6>' . get_comment_author() . '</h6><small>' . get_comment_date() . '</small>'; echo '<div class="rating rating-' . (int) $_product->get_average_rating() . '">'; for ($i = 1; $i <= (int) $_product->get_average_rating(); $i++) { echo '<i class="icon-heart"></i>' . "\n"; } echo '</div>'; echo '</div> </li>'; } echo '</ul>'; echo $after_widget; } $content = ob_get_clean(); if (isset($args['widget_id'])) { $cache[$args['widget_id']] = $content; } echo $content; wp_cache_set('widget_recent_reviews', $cache, 'widget'); }
function __construct($wp_comment) { $content = apply_filters('comment_text', $wp_comment->comment_content); $this->id = (int) $wp_comment->comment_ID; $this->name = $wp_comment->comment_author; $this->url = $wp_comment->comment_author_url; $this->date = $wp_comment->comment_date; $this->content = $content; $this->parent = (int) $wp_comment->comment_parent; $this->author = get_comment_author($this->id); }
function get_comment_author_link() { global $comment; $url = get_comment_author_url(); $author = get_comment_author(); if ( empty( $url ) || 'http://' == $url ) $return = $author; else $return = "<a href='$url' rel='external nofollow'>$author</a>"; return apply_filters('get_comment_author_link', $return); }
/** * 小工具的渲染方法,这里就是输出评论 */ function widget($args, $instance) { global $wpdb, $comments, $comment; $cache = wp_cache_get('f_comment', 'widget'); if (!is_array($cache)) { $cache = array(); } if (!isset($args['widget_id'])) { $args['widget_id'] = $this->id; } if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return; } extract($args, EXTR_SKIP); $output = ''; $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title'], $instance, $this->id_base); if (empty($instance['number']) || !($number = absint($instance['number']))) { $number = 5; } //获取评论,过滤掉管理员自己 $comments = $wpdb->get_results("SELECT * FROM {$wpdb->comments} WHERE user_id !=1 and comment_approved = '1' and comment_type not in ('pingback','trackback') ORDER BY comment_date_gmt DESC LIMIT {$number}"); $output .= $before_widget; if ($title) { $output .= $before_title . $title . $after_title; } $output .= '<div class="all-comments">'; if ($comments) { // Prime cache for associated posts. (Prime post term cache if we need it for permalinks.) $post_ids = array_unique(wp_list_pluck($comments, 'comment_post_ID')); _prime_post_caches($post_ids, strpos(get_option('permalink_structure'), '%category%'), false); foreach ((array) $comments as $comment) { if ($comment->comment_author_email != $my_email) { //头像 $avatar = get_avatar($comment, 36); //作者名称 $author = get_comment_author(); //评论内容 $content = apply_filters('get_comment_text', $comment->comment_content); $content = mb_strimwidth(strip_tags($content), 0, '65', '...', 'UTF-8'); $content = convert_smilies($content); //评论的文章 $post = '<a href="' . esc_url(get_comment_link($comment->comment_ID)) . '">' . $avatar . $author . '<span class="muted">' . timeago($comment->comment_date_gmt) . ':<br>' . $content . '</span></a>'; //这里就是输出的html,可以根据需要自行修改 $output .= $post; } } } $output .= '</div>'; $output .= $after_widget; echo $output; $cache[$args['widget_id']] = $output; wp_cache_set('my_widget_recent_comments', $cache, 'widget'); }
function wildcat_recent_comments() { $comments = get_comments(array('number' => 5, 'date_query' => array(array('column' => 'comment_date', 'after' => '1 year ago')))); echo '<ul>'; foreach ($comments as $comment) { $link = get_comment_link($comment->comment_ID); $author = get_comment_author($comment->comment_ID); $excerpt = get_comment_excerpt($comment->comment_ID); echo "<li><a href=\"{$link}\">{$author}</a>: {$excerpt}</li>"; } echo "</ul>\n"; }
function evolve_comment_avatar() { global $default; $gravatar_email = get_comment_author_email(); $author = get_comment_author(); $output = get_avatar($gravatar_email, 45, $default, $author); if (get_option('show_avatars')) { // Avatars enabled? return apply_filters('evolve_comment_avatar', (string) $output); // Available filter: evolve_comment_avatar } }
function skillcrush_comments($comment, $args, $depth) { $comment = '<li class="comment">'; $comment .= '<header class="comment-head">'; $comment .= '<span class="comment-author">' . get_comment_author() . '</span>'; $comment .= '<span class="comment-meta">' . get_comment_date('m/d/Y') . ' | ' . get_comment_reply_link(array('depth' => $depth, 'max_depth' => 5)) . '</span>'; $comment .= '</header>'; $comment .= '<div class="comment-body">'; $comment .= '<p>' . get_comment_text() . '</p>'; $comment .= '</div>'; $comment .= '</li>'; echo $comment; }
function check_follow($matches) { #support of "meta=follow" option for admins. disabled by default to minify processing. if (!$this->options['dont_mask_admin_follow']) { return false; } $id = array(get_comment_ID(), get_the_ID()); //it is either page or post if ($id[0]) { $this->debug_info('It is a comment. id ' . $id[0]); } elseif ($id[1]) { $this->debug_info('It is a page. id ' . $id[1]); } $author = false; if ($id[0]) { $author = get_comment_author($id[0]); } else { if ($id[1]) { $author = get_the_author_meta('ID'); } } if (!$author) { $this->debug_info('it is neither post or page, applying usual rules'); } elseif (user_can($author, 'manage_options') && (stripos($matches[0], 'rel="follow"') !== FALSE || stripos($matches[0], "rel='follow'") !== FALSE)) { $this->debug_info('This link has a follow atribute and is posted by admin, not masking it.'); #wordpress adds rel="nofollow" by itself when posting new link in comments. get rid of it! Also, remove our follow attibute - it is unneccesary. return str_ireplace(array('rel="follow"', "rel='follow'", 'rel="nofollow"'), '', $matches[0]); } else { $this->debug_info('it does not have rel follow or is not posted by admin, masking it'); } return false; }