>本教程演示了构建一个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中文网其他相关文章!

是的,wordpressisisexcellentforcortingaportfoliowebsite.1)itoffersnumeroversnumeroverportfolio-spificthemeslike'astra'astra'astra'astra'astra'astra'astra'astra'astra'elementor'Enelementor'enableIntiviveSiveSign,Thoughtemanycanslowthesite.3)

WordPressisadvantageousovercodingawebsitefromscratchdueto:1)easeofuseandfasterdevelopment,2)flexibilityandscalability,3)strongcommunitysupport,4)built-inSEOandmarketingtools,5)cost-effectiveness,and6)regularsecurityupdates.Thesefeaturesallowforquicke

WordPressIsAcmsDuetoItseAsofuse,自定义,USERMANAMECTION,SEO和COMMUNITYSUPPORT.1)ITSIMPLIFIESCONTENTMANGAMEWITHANINTUISIDERFEEFFECE.2)提供extentensiveCustomizationThroughThroughTheMesandPlugins.3)supportrobustuserrolesandplugins.4)supportrobustuserrolesandpermissions.4)增强

在 WordPress 网站上启用评论功能,可以为访客提供参与讨论和分享反馈的平台。为此,请按照以下步骤操作:启用评论:在仪表盘中,导航至“设置”>“讨论”,并选中“允许评论”复选框。创建评论表单:在编辑器中,单击“添加块”并搜索“评论”块,将其添加到内容中。自定义评论表单:通过设置标题、标签、占位符和按钮文本来定制评论块。保存更改:单击“更新”以保存评论框并将其添加到页面或文章中。

如何复制 WordPress 子站?步骤:在主站创建子站。在主站克隆子站。将克隆导入目标位置。更新域名(可选)。分开插件和主题。

在WordPress中创建自定义页头的步骤如下:编辑主题文件“header.php”。添加您的网站名称和描述。创建导航菜单。添加搜索栏。保存更改并查看您的自定义页头。

WordPress 网站中启用评论功能:1. 登录管理面板,转到 "设置"-"讨论",勾选 "允许评论";2. 选择显示评论的位置;3. 自定义评论表单;4. 管理评论,批准、拒绝或删除;5. 使用 <?php comments_template(); ?> 标签显示评论;6. 启用嵌套评论;7. 调整评论外形;8. 使用插件和验证码防止垃圾评论;9. 鼓励用户使用 Gravatar 头像;10. 创建评论指

可以通过 WordPress 安装 FTP 插件,配置 FTP 连接,然后使用文件管理器上传源码。步骤包括:安装 FTP 插件、配置连接、浏览上传位置、上传文件、检查上传成功。


热AI工具

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

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

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

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

热门文章

热工具

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

Atom编辑器mac版下载
最流行的的开源编辑器

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。