>本教程演示了構(gòu)建一個(gè)WordPress插件,該插件在註釋中添加了類似Twitter的@Mention功能。 用戶可以互相標(biāo)記,改善註釋互動(dòng)。
密鑰功能:
- @mention功能:插件使用戶可以使用“@”符號(hào)標(biāo)記其他評(píng)論者,類似於Twitter。
- 電子郵件通知:提到的用戶收到有關(guān)新評(píng)論的電子郵件警報(bào)。
- WordPress集成:
與WordPress的評(píng)論Meneration System無縫集成。 自定義: - 輕鬆調(diào)整@mention文本顏色和其他設(shè)置。
插件,,位於
>目錄中。 插件標(biāo)頭對(duì)於WordPress識(shí)別至關(guān)重要:
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(); ?>掛鉤來管理提及和通知。 切記在電子郵件主體中用網(wǎng)站的名稱替換
。 comment_text
>
wp_set_comment_status
wp_insert_comment
"MyBlog.com"
>
以上是通過提及功能增強(qiáng)您的WordPress評(píng)論的詳細(xì)內(nèi)容。更多資訊請(qǐng)關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

熱AI工具

Undress AI Tool
免費(fèi)脫衣圖片

Undresser.AI Undress
人工智慧驅(qū)動(dòng)的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片

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

Clothoff.io
AI脫衣器

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

熱門文章

熱工具

記事本++7.3.1
好用且免費(fèi)的程式碼編輯器

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

禪工作室 13.0.1
強(qiáng)大的PHP整合開發(fā)環(huán)境

Dreamweaver CS6
視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版
神級(jí)程式碼編輯軟體(SublimeText3)

熱門話題

使用Git管理WordPress項(xiàng)目時(shí),應(yīng)只將主題、自定義插件和配置文件納入版本控制;設(shè)置.gitignore文件以忽略上傳目錄、緩存和敏感配置;利用webhook或CI工具實(shí)現(xiàn)自動(dòng)部署並註意數(shù)據(jù)庫處理;採用兩分支策略(main/develop)進(jìn)行協(xié)作開發(fā)。這樣做可避免衝突、保障安全,並提升協(xié)作與部署效率。

使用WordPress測(cè)試環(huán)境是為了確保新功能、插件或主題在正式上線前的安全性和兼容性,避免影響真實(shí)網(wǎng)站。搭建測(cè)試環(huán)境的步驟包括:下載安裝本地服務(wù)器軟件(如LocalWP、XAMPP),創(chuàng)建站點(diǎn)、設(shè)置數(shù)據(jù)庫和管理員賬號(hào),安裝主題和插件進(jìn)行測(cè)試;複製正式網(wǎng)站到測(cè)試環(huán)境的方法是通過插件導(dǎo)出站點(diǎn)、導(dǎo)入測(cè)試環(huán)境並替換域名;使用時(shí)應(yīng)注意不使用真實(shí)用戶數(shù)據(jù)、定期清理無用數(shù)據(jù)、備份測(cè)試狀態(tài)、適時(shí)重置環(huán)境,並統(tǒng)一團(tuán)隊(duì)配置以減少差異問題。

創(chuàng)建Gutenberg塊的關(guān)鍵在於理解其基本結(jié)構(gòu)並正確連接前後端資源。 1.準(zhǔn)備開發(fā)環(huán)境:安裝本地WordPress、Node.js和@wordpress/scripts;2.使用PHP註冊(cè)塊並用JavaScript定義塊的編輯和顯示邏輯;3.通過npm構(gòu)建JS文件以使更改生效;4.遇到問題時(shí)檢查路徑、圖標(biāo)是否正確或使用實(shí)時(shí)監(jiān)聽構(gòu)建避免重複手動(dòng)編譯。按照這些步驟,可以逐步實(shí)現(xiàn)一個(gè)簡單的Gutenberg塊。

在WordPress中,當(dāng)新增自定義文章類型或修改固定鏈接結(jié)構(gòu)後,需手動(dòng)刷新重寫規(guī)則,此時(shí)可通過代碼調(diào)用flush_rewrite_rules()函數(shù)實(shí)現(xiàn)。 1.可在主題或插件激活鉤子中添加該函數(shù)以自動(dòng)刷新;2.僅在必要時(shí)執(zhí)行一次,如添加CPT、分類法或修改鏈接結(jié)構(gòu)後;3.避免頻繁調(diào)用以免影響性能;4.多站點(diǎn)環(huán)境下需視情況為每個(gè)站點(diǎn)單獨(dú)刷新;5.某些託管環(huán)境可能限制規(guī)則保存。此外,訪問“設(shè)置>固定鏈接”頁麵點(diǎn)擊保存也可觸髮刷新,適合非自動(dòng)化場(chǎng)景。

要實(shí)現(xiàn)響應(yīng)式WordPress主題設(shè)計(jì),首先要使用HTML5和移動(dòng)優(yōu)先的Meta標(biāo)籤,在header.php中添加viewport設(shè)置以確保移動(dòng)端正確顯示,並用HTML5結(jié)構(gòu)標(biāo)籤組織佈局;其次,利用CSS媒體查詢實(shí)現(xiàn)不同屏幕寬度下的樣式適配,按移動(dòng)優(yōu)先原則編寫樣式,常用斷點(diǎn)包括480px、768px和1024px;第三,彈性處理圖片和佈局,為圖片設(shè)置max-width:100%並使用Flexbox或Grid佈局替代固定寬度;最後,通過瀏覽器開發(fā)者工具和真實(shí)設(shè)備進(jìn)行充分測(cè)試,優(yōu)化加載性能,確保響應(yīng)

tosetupredirectsinwordpressingthe.htaccessfile,locateThEfileInyourSite'sRootDirectorectoryAndDrectRectrulesabovethe#beginWordPresssection.forbasic301redirects,USETHEETHEETERECTREFTATRECTATREDERTREFTATREDERTREFTATRECTRECTATRECTRECTATREDECT301/OLD-PAGEHTTPS:

TOINTEGRATETHIRD-PARTYAPISINTOWORDPRESS,關(guān)注臺(tái)詞:1.SelectAutableabepianDobtainCredentialslikeapikeYsoroAuthtoKensByEnterRegisteringThemSecure.2.ChooseBeteBetB????eteBetB????eteBetB????etebetInpliCityOorcustimplicityOrcustomPliCoseTompliCoseTomploomcoseusionfunctionfunctionfunctibunitiacuciencipuity forfunigation。

UsingsMtpForWordPresseMailSimProvesDeliverabilitialComparedComparedTothEdeDefaultPhpMail()函數(shù).1.smtpauthenticateswithyouremailserver.2.somemomehostsdisablesablephpmail()
