WP_Widget_Recent_Comments{}

用于实现Recent Comments小部件的核心类。

描述

另请参见

方法

姓名描述
WP_Widget_Recent_Comments::__construct设置新的“最近的评论”小部件实例。
WP_Widget_Recent_Comments::flush_Widget_cache刷新“最近的评论”小部件缓存-已弃用
WP_Widget_Recent_Comments::表单输出“最近的评论”小部件的设置表单。
WP_Widget_Recent_Comments::Recent_Comments_style输出“最近的评论”小部件的默认样式。
WP_Widget_Recent_Comments::更新处理当前“最近的评论”小部件实例的更新设置。
WP_Widget_Recent_Comments::小部件输出当前“最近的评论”小部件实例的内容。

来源

类WP_Widget_Recent_Comments扩展了WP_Widlet{/***设置新的“最近的评论”小部件实例。**@自2.8.0起*/公共函数__construct(){$widget_ops=数组(“classname”=>“widget_recent_comments”,“description”=>__(“您的站点的最新评论。”),“customize_selective_refresh”=>true,“show_instance_in_rest”=>true,);parent::__construct('recent-comments',__('recent comments'),$widget_ops);$this->alt_option_name='widget_recent_comments';if(is_active_widget(false,false,$this->id_base)||is_customize_preview()){add_action('wp_head',数组($this,'recent_comments_style');}}/***输出“最近的评论”小部件的默认样式。**@自2.8.0起*/公共函数recent_comments_style(){/***过滤“最近的评论”默认小部件样式。**@自3.1.0起**@param bool$active小部件是否处于活动状态。默认为true。*@param string$id_base小部件id。*/if(!current_theme_supports('widgets')//临时黑客#14876。|| ! apply_filters('show_recent_comments_widet_style',true,$this->id_base)){回报;}$type_attr=current_theme_supports('html5','style')?'':'type=“text/css”';打印('<style%s>.recentcomments a{display:inline!important;padding:0!importent;margin:0!重要;}</style>',$类型属性);}/***输出当前“最近的评论”小部件实例的内容。**@自2.8.0起*@since 5.4.0为`<ul>`元素创建唯一的HTML ID*如果页面上显示多个实例。**@param array$args显示参数,包括“before_title”、“after_title”、,*'before_widget'和'after_widget]。*当前“最近的评论”小部件实例的@param array$instance设置。*/公共功能小部件($args,$instance){静态$first_instance=true;if(!isset($args['widgetid']){$args['widget_id']=$this->id;}$output=“”;$default_title=__(“最近的评论”);$title=(!空($instance['title']))$实例[“标题”]:$default_title;/**该过滤器记录在wp-includes/widgets/class-wp-widget-pages.php中*/$title=应用过滤器('widget_title',$title,$instance,$this->id_base);$number=(!空($instance['number']))?absint($instance['number']):5;if(!$number){$number=5;}$comments=获取评论(/***过滤“最近的评论”小部件的参数。**@自3.4.0起*@since 4.9.0添加了`$instance`参数。**@有关已接受参数的信息,请参阅WP_Comment_Query::Query()。**@param array$comment_args用于检索最近评论的参数数组。*@param array$instance当前小部件的设置数组。*/应用程序筛选器(“widget_comments_args”,阵列(“number”=>$number,“status”=>“approve”,“post_status”=>“发布”,),$实例));$输出。=$args[“小部件之前”];如果($title){$输出。=$args[“标题之前”]$标题$args['after_title'];}$recent_comments_id=($first_instance)?'recentcomments':“recentcommments-{$this->number}”;$first_instance=假;$format=current_theme_supports('html5','navigation-widgets')?'html5':'xhtml';/**该过滤器记录在wp-includes/widgets/class-wp-nav-menu-widget.php中*/$format=应用过滤器('navigation_widgets_format',$format);if('html5'===$format){//标题可能会被过滤:去掉HTML并确保aria-label永远不为空。$title=修剪(strip_tags($title));$aria_label=$title$标题:$default_title;$output.='<nav aria-label=“'.esc_attr($aria_label).'”>';}$output.='<ul id=“'.esc_attr($recent_comments_id).'”>';if(is_array($comments)&&$comment斯){//相关帖子的主缓存。(如果我们需要永久链接,则提供定期后缓存。)$post_ids=数组唯一(wp_list_pluck($comments,'comment_post_ID'));_prime_post_caches($post_id,strpos(get_option('permalink_structure'),'%category%'),false);foreach((数组)$comments作为$comment){$output.='<li class=“recentcomments”>';$输出。=冲刺(/*翻译人员:“注释”小部件。1:评论作者,2:帖子链接*/_x(“%2$s上的%1$s”,“小部件”),'<span class=“comment-author-link”>'。get_comment_author_link($comment)。”</span>','<a href=“'.esc_url(get_comment_link($comment)).'”>'。get_the_title($comment->comment_post_ID)。”</a> ');$output=‘</li>';}}$output.='</ul>';if('html5'===$format){$output.='</导航>';}$输出。=$args['after_widget'];echo$output;}/***处理当前“最近的评论”小部件实例的更新设置。**@自2.8.0起**@param array$new_instance用户通过输入此实例的新设置*WP_Widget::form()。*@param array$old_instance此实例的旧设置。*@return array更新了要保存的设置。*/公共函数更新($new_instance,$old_instance){$instance=$old_instance;$instance['title']=清理文本字段($new_instance['标题']);$instance['number']=absint($new_instance['编号']);return$instance;}/***输出“最近的评论”小部件的设置表单。**@自2.8.0起**@param array$instance当前设置。*/公共函数窗体($instance){$title=isset($instance['title'])$实例[“标题”]:“”;$number=isset($instance['number'])?absint($instance['number']):5;?><p><label for=“<?php echo$this->get_field_id('title');?>”><?php_e('标题:');?></标签><input class=“widefat”id=“<?php echo$this->get_field_id('title');?>”name=“<?php echo$this->get_field_name('titel');”>“type=”text“value=”<?php-echo esc_attr($title);?>>“/></p><p><label for=“<?php echo$this->get_field_id('number');?>”><?php_e('要显示的注释数:');?></标签><input class=“tiny-text”id=“<?php echo$this->get_field_id('number');?>”name=“<?php echo$this->get_field_name('number’);?>>”type=“number”step=“1”min=“1</p><?php(电话)}/***刷新“最近的评论”小部件缓存。**@自2.8.0起**为了支持拆分查询,删除了@deprecated 4.4.0碎片缓存。*/公共函数flush_widget_cache(){_deprecated_function(__METHOD__,'4.4.0');}}

变更日志

版本描述
2.8.0介绍。

用户贡献的笔记

你必须登录在能够发表注释或反馈之前。