通过提及功能增强您的WordPress评论
>本教程演示了构建一个WordPress插件,该插件在注释中添加了类似Twitter的@Mention功能。 用户可以互相标记,改善注释互动。
密钥功能:
- @mention功能:插件使用户可以使用“@”符号标记其他评论者,类似于Twitter。
- 电子邮件通知:提到的用户收到有关新评论的电子邮件警报。
- WordPress集成:
与WordPress的评论Meneration System无缝集成。 自定义: - 轻松调整@mention文本颜色和其他设置。
插件,,位于
>目录中。 插件标头对于WordPress识别至关重要:
wp-mention-plugin.php
/wp-content/plugins/
核心功能被封装在
<?php /** * Plugin Name: WP Mention Plugin * Plugin URI: https://sitepoint.com * Description: Mention registered and unregistered comment authors. * Version: 1.0.0 * Author: John Doe * Author URI: https://sitepoint.com * License: GPLv2 */ ?>
>插件使用wp_mention_plugin
>,
class wp_mention_plugin { public static function initialize() { add_filter( 'comment_text', array( 'wp_mention_plugin', 'wpmp_mod_comment' ) ); add_action( 'wp_set_comment_status', array( 'wp_mention_plugin', 'wpmp_approved' ), 10, 2 ); add_action( 'wp_insert_comment', array( 'wp_mention_plugin', 'wpmp_no_approve' ), 10, 2 ); } public static function wpmp_mod_comment( $comment ) { $color_code = '#00BFFF'; // Deep sky blue $pattern = "/(^|\s)@(\w+)/"; $replacement = "<span style='color:$color_code;'>@</span>"; //Style the mention $mod_comment = preg_replace( $pattern, $replacement, $comment ); return $mod_comment; } private static function wpmp_send_mail( $comment ) { $the_related_post = $comment->comment_post_ID; $the_related_comment = $comment->comment_ID; $the_related_post_url = get_permalink( $the_related_post ); $the_related_comment_url = get_comment_link( $the_related_comment ); $the_comment = $comment->comment_content; $pattern = "/(^|\s)@(\w+)/"; if ( preg_match_all( $pattern, $the_comment, $match ) ) { foreach ( $match[2] as $m ) { $email_owner_name[] = preg_replace( '/@/', '', $m ); } if ( preg_match_all( '/\w+__\w+/', implode( '', $email_owner_name ) ) ) { $email_owner_name = str_ireplace( '__', ' ', $email_owner_name ); } $author_emails = array_map( 'self::wpmp_gen_email', $email_owner_name ); if ( ! is_null( $author_emails ) ) { $subj = '[' . get_bloginfo( 'name' ) . '] You were mentioned in a comment!'; $email_body = "You were mentioned in a comment! See it here: $the_related_comment_url\n\nRelated Post: $the_related_post_url"; wp_mail( $author_emails, $subj, $email_body ); } } } public static function wpmp_gen_email( $name ) { global $wpdb; $name = sanitize_text_field( $name ); $query = "SELECT comment_author_email FROM {$wpdb->comments} WHERE comment_author = %s"; $prepare_email_address = $wpdb->prepare( $query, $name ); return $wpdb->get_var( $prepare_email_address ); } public static function wpmp_approved( $comment_id, $status ) { $comment = get_comment( $comment_id, OBJECT ); ( $comment && $status == 'approve' ? self::wpmp_send_mail( $comment ) : null ); } public static function wpmp_no_approve( $comment_id, $comment_object ) { ( wp_get_comment_status( $comment_id ) == 'approved' ? self::wpmp_send_mail( $comment_object ) : null ); } } $wp_mention_plugin = new wp_mention_plugin; $wp_mention_plugin->initialize(); ?>
。comment_text
>
wp_set_comment_status
wp_insert_comment
"MyBlog.com"
>
以上是通过提及功能增强您的WordPress评论的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

博客是人们在网上表达观点、意见和见解的理想平台。许多新手渴望建立自己的网站,却因担心技术障碍或成本问题而犹豫不决。然而,随着平台不断发展以满足初学者的能力和需求,现在开始变得比以往任何时候都更容易。 本文将逐步指导您如何建立一个WordPress博客,从主题选择到使用插件提升安全性和性能,助您轻松创建自己的网站。 选择博客主题和方向 在购买域名或注册主机之前,最好先确定您计划涵盖的主题。个人网站可以围绕旅行、烹饪、产品评论、音乐或任何激发您兴趣的爱好展开。专注于您真正感兴趣的领域可以鼓励持续写作

WordPress对初学者来说容易上手。1.登录后台后,用户界面直观,简洁的仪表板提供所有必要功能链接。2.基本操作包括创建和编辑内容,所见即所得的编辑器简化了内容创建。3.初学者可以通过插件和主题扩展网站功能,学习曲线存在但可以通过实践掌握。

您想了解如何在父分类存档页面上显示子分类吗?在自定义分类存档页面时,您可能需要执行此操作,以使其对访问者更有用。在本文中,我们将向您展示如何在父分类存档页面上轻松显示子分类。为什么在父分类存档页面上显示子分类?通过在父分类存档页面上显示所有子分类,您可以使其不那么通用,对访问者更有用。例如,如果您运行一个关于书籍的WordPress博客,并且有一个名为“主题”的分类法,那么您可以添加“小说”、“非小说”等子分类法,以便您的读者可以

最近,我们向您展示了如何通过允许用户将自己喜欢的帖子保存在个性化库中来为用户创建个性化体验。您可以通过在某些地方(即欢迎屏幕)使用他们的名字,将个性化结果提升到另一个水平。幸运的是,WordPress使获取登录用户的信息变得非常容易。在本文中,我们将向您展示如何检索与当前登录用户相关的信息。我们将利用get_currentuserinfo(); 功能。这可以在主题中的任何地方使用(页眉、页脚、侧边栏、页面模板等)。为了使其工作,用户必须登录。因此我们需要使用

过去,我们分享过如何使用PostExpirator插件使WordPress中的帖子过期。好吧,在创建活动列表网站时,我们发现这个插件非常有用。我们可以轻松删除过期的活动列表。其次,多亏了这个插件,按帖子过期日期对帖子进行排序也非常容易。在本文中,我们将向您展示如何在WordPress中按帖子过期日期对帖子进行排序。更新了代码以反映插件中更改自定义字段名称的更改。感谢Tajim在评论中让我们知道。在我们的特定项目中,我们将事件作为自定义帖子类型。现在

我们的一位用户询问其他网站如何在页脚中显示查询数量和页面加载时间。您经常会在网站的页脚中看到这一点,它可能会显示类似以下内容:“1.248秒内64个查询”。在本文中,我们将向您展示如何在WordPress中显示查询数量和页面加载时间。只需将以下代码粘贴到主题文件中您喜欢的任何位置(例如footer.php)。queriesin

有四种方法可以调整 WordPress 文章列表:使用主题选项、使用插件(如 Post Types Order、WP Post List、Boxy Stuff)、使用代码(在 functions.php 文件中添加设置)或直接修改 WordPress 数据库。

wordpressgood forvortalyanewebprojectDuetoItsAsatilityAsacms.itexcelsin:1)用户友好性,允许Aeserywebsitesetup; 2)sexibility andcustomized andcustomization and numerthemesandplugins; 3)seoop timigimization; and4)and4)
