當(dāng)前位置:首頁>WordPress建站>WordPress開發(fā)>如何自動提醒WordPress主題使用者安裝必要插件

如何自動提醒WordPress主題使用者安裝必要插件

作為WordPress主題開發(fā)者,如果你的主題的某些功能需要借助某些插件才能實現(xiàn),那你需要提醒主題使用者安裝這些插件。在倡萌看來,最合理的提醒方法,就是啟用主題后,在后臺頂部提醒安裝,如下圖所示:

wpdaxue.com-201303364

如何在WordPress后臺頂部添加錯誤提醒信息或升級提醒信息 中已經(jīng)介紹了通過 admin_notices 掛鉤 顯示提醒信息的方法,那么接我們只需要借助 is_plugin_active() 函數(shù)來檢測所需的插件是否已安裝并啟用,如果沒有安裝就進行提醒。

is_plugin_active() 函數(shù)簡介

is_plugin_active() 函數(shù)是專門用來檢測插件是否已經(jīng)安裝并啟用的,使用的方法很簡單,只需要添加對應(yīng)的插件的主文件路徑即可:

if(!is_plugin_active( 'wordpress-popular-posts/wordpress-popular-posts.php' ))
	{
	echo '需要顯示的內(nèi)容';
	}

上面的代碼的作用就是:如果沒有啟用 WordPress Popular Posts,就顯示一段提醒文字。’wordpress-popular-posts/wordpress-popular-posts.php’ 就是 WordPress Popular Posts 插件的主文件的路徑。

提示安裝必要插件

只需要在主題的 functions.php 中添加類似代碼,就可以達到本文配圖的效果:

add_action('admin_notices', 'showAdminMessages');
function showAdminMessages()
{
	$plugin_messages = array();
	include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
	// Download the Yoast WordPress SEO plugin
	if(!is_plugin_active( 'wordpress-seo/wp-seo.php' ))
	{
		$plugin_messages[] = 'This theme requires you to install the Yoast WordPress SEO plugin, <a href="https://wordpress.org/extend/plugins/wordpress-seo/">download it from here</a>.';
	}
	// Download the Disqus comment system
	if(!is_plugin_active( 'disqus-comment-system/disqus.php' ))
	{
		$plugin_messages[] = 'This theme requires you to install the Disqus comment system plugin, <a href="https://wordpress.org/extend/plugins/disqus-comment-system/">download it from here</a>.';
	}
	// Download the WordPress popular posts plugin
	if(!is_plugin_active( 'wordpress-popular-posts/wordpress-popular-posts.php' ))
	{
		$plugin_messages[] = 'This theme requires you to install the WordPress Popular Post plugin, <a href="https://wordpress.org/extend/plugins/wordpress-popular-posts/">download it from here</a>.';
	}
	if(count($plugin_messages) > 0)
	{
		echo '
<div id="message" class="error">';
			foreach($plugin_messages as $message)
			{
				echo '
<strong>'.$message.'</strong>
';
			}
		echo '</div>
';
	}
}

參考資料:http://www.paulund.co.uk/theme-users-required-plugins

聲明:本站所有文章,如無特殊說明或標注,均為本站原創(chuàng)發(fā)布。任何個人或組織,在未征得本站同意時,禁止復(fù)制、盜用、采集、發(fā)布本站內(nèi)容到任何網(wǎng)站、書籍等各類媒體平臺。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進行處理。

給TA打賞
共{{data.count}}人
人已打賞
歡迎關(guān)注WordPress大學(xué)公眾號 WPDAXUE
WordPress開發(fā)

如何在WordPress后臺頂部添加錯誤提醒信息或升級提醒信息

2013-3-7 6:44:00

WordPress開發(fā)

WordPress函數(shù):get_extended(獲取擴展信息)

2013-3-19 20:40:00

4 條回復(fù) A文章作者 M管理員
  1. 路勁 => 路徑

    • 已修正,謝謝提醒

  2. 這個功能很實用啊

  3. 我不太喜歡要用插件的主題,最好多多集成

?
個人中心
購物車
優(yōu)惠劵
今日簽到
有新私信 私信列表
搜索

社会| 芦溪县| 卢湾区| 玛纳斯县| 黄冈市| 南安市| 卢氏县| 萨嘎县| 盐边县| 邹城市| 平武县| 镇雄县| 定日县| 米林县| 西藏| 乐亭县| 鄂尔多斯市| 湄潭县| 阜康市| 怀仁县| 明水县| 缙云县| 诸城市| 临安市| 呼伦贝尔市| 静乐县| 长岭县| 乐亭县| 永城市| 牡丹江市| 开化县| 五常市| 霍州市| 冷水江市| 江安县| 登封市| 喀喇| 玉林市| 南靖县| 扶风县| 承德县|