作為主題開發(fā)者wordpress本地安裝插件,如果您的主題的某些功能需要某些插件的幫助wordpress做網(wǎng)站,您需要提醒主題用戶安裝這些插件。在常萌看來,最合理的提醒方式是啟用主題后在后臺頂部提醒安裝,如下圖所示:
通過鉤子顯示提醒信息的方法在后臺頂部如何添加錯誤提醒信息或升級提醒信息中已經(jīng)介紹過,那么我們只需要使用()函數(shù)來檢測需要的插件是否已經(jīng)安裝并啟用wordpress網(wǎng)站建設(shè),如果未安裝,則予以提醒。
() 函數(shù)介紹
() 該功能專門用于檢測插件是否已安裝并啟用。使用的方法很簡單wordpress本地安裝插件,只需添加對應(yīng)插件的主文件路徑即可:
if(!is_plugin_active( 'wordpress-popular-posts/wordpress-popular-posts.php' ))
{

echo '需要顯示的內(nèi)容';
}
上述代碼的作用是:如果沒有啟用 Posts,則顯示一個提醒文本。'--posts/--posts.php' 是 Posts 插件主文件的路徑。
提示安裝必要的插件
只需要在主題的.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, download it from here.';
}
// 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, download it from here.';
}
// 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, download it from here.';

}
if(count($plugin_messages) > 0)
{
echo '
';
foreach($plugin_messages as $message)
{
echo '

'.$message.'
';
}
echo '
';
}
}
參考:
免責(zé)聲明:本站所有文章,除非另有說明或注明,均在本站原創(chuàng)發(fā)表。任何個人或組織未經(jīng)本站同意,不得將本站內(nèi)容復(fù)制、盜用、收集、發(fā)布到任何網(wǎng)站、圖書等媒體平臺。本站內(nèi)容如有侵犯原作者合法權(quán)益的,您可以聯(lián)系我們處理。
文章來自互聯(lián)網(wǎng),侵權(quán)請聯(lián)系刪除,文章闡述觀點來自文章出處,并不代表本站觀點。
www.bjcthy.com