>本教程演示了構建一個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中文網其他相關文章!

WordPressPluginsscmscmscapabilities byferingCustomization和Functionality.1)超過50,000pluginsallowuserstailostailortheortheortheortheirsiteforseo,電子商務和蘇聯。 2)pluginScaneCanextendCoreFeatures,likeaddingcustompostposttypes.3bully.3 burl

是的,WordPress非常适合做电商。1)通过WooCommerce插件,WordPress可以快速变成功能全面的在线商店。2)需要关注性能优化和安全性,定期更新和使用缓存、安全插件是关键。3)WordPress提供了丰富的定制选项,提升用户体验和SEO优化效果显著。

您想將您的網站連接到Yandex網站管理員工具嗎? Google搜索控制台、Bing和Yandex等網站管理員工具可幫助您優化網站、監控流量、管理robots.txt、檢查網站錯誤等。在本文中,我們將分享如何在Yandex網站管理員工具中添加您的WordPress網站來監控您的搜索引擎流量。什麼是Yandex? Yandex是一個位於俄羅斯的流行搜索引擎,類似於Google和Bing。您可以在Yandex中優

您需要修復WordPress中的HTTP圖片上傳錯誤嗎?當您在WordPress中創建內容時,此錯誤可能會特別令人沮喪。當您使用內置WordPress媒體庫將圖像或其他文件上傳到CMS時,通常會發生這種情況。在本文中,我們將向您展示如何輕鬆修復WordPress中的HTTP圖片上傳錯誤。 WordPress媒體上傳過程中出現HTTP錯誤的原因是什麼?當您嘗試使用WordPress媒體上傳器將文件上傳到Wo

最近,我們的一位讀者報告說,他們的WordPress網站上的“添加媒體”按鈕突然停止工作。此經典編輯器問題不會顯示任何錯誤或警告,這使用戶不知道為什麼他們的“添加媒體”按鈕不起作用。在本文中,我們將向您展示如何輕鬆修復WordPress中的“添加媒體”按鈕不起作用的問題。是什麼導致WordPress“添加媒體”按鈕停止工作?如果您仍在使用舊的經典WordPress編輯器,那麼“添加媒體”按鈕允許您將圖像、視頻等插入博客文章中。

您想了解如何在WordPress網站上使用cookie嗎? Cookie是在用戶瀏覽器中存儲臨時信息的有用工具。您可以使用此信息通過個性化和行為定位來增強用戶體驗。在本終極指南中,我們將向您展示如何像專業人士一樣設置、獲取和刪除WordPresscookie。注意:這是一個高級教程。它要求您精通HTML、CSS、WordPress網站和PHP。什麼是Cookie? Cookie是用戶訪問網站時創建並存儲在用戶瀏覽

您是否在WordPress網站上看到“429請求過多”錯誤?此錯誤消息意味著用戶向您網站的服務器發送了太多HTTP請求。此錯誤可能會非常令人沮喪,因為很難找出導致該錯誤的原因。在本文中,我們將向您展示如何輕鬆修復“WordPress429TooManyRequests”錯誤。是什麼原因導致WordPress429請求過多錯誤? “429TooManyRequests”錯誤的最常見原因是用戶、機器人或腳本嘗試向網站

WordPressCanHandLeLArgeWebsiteswithCareFulplanningAndOptimization.1)USECACHINGTOREDUCESERVERVERLOAD.2)優化YourDataBaseRegularly.3)actimentAcdNtododistibuteContent.4))


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

記事本++7.3.1
好用且免費的程式碼編輯器

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。