作为主题开发者wordpress本地安装插件,如果您的主题的某些功能需要某些插件的帮助wordpress做网站,您需要提醒主题用户安装这些插件。在常萌看来,最合理的提醒方式是启用主题后在后台顶部提醒安装,如下图所示:
通过钩子显示提醒信息的方法在后台顶部如何添加错误提醒信息或升级提醒信息中已经介绍过,那么我们只需要使用()函数来检测需要的插件是否已经安装并启用wordpress网站建设,如果未安装,则予以提醒。
() 函数介绍
() 该功能专门用于检测插件是否已安装并启用。使用的方法很简单wordpress本地安装插件,只需添加对应插件的主文件路径即可:
if(!is_plugin_active( 'wordpress-popular-posts/wordpress-popular-posts.php' ))
{

echo '需要显示的内容';
}
上述代码的作用是:如果没有启用 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 '
';
}
}
参考:
免责声明:本站所有文章,除非另有说明或注明,均在本站原创发表。任何个人或组织未经本站同意,不得将本站内容复制、盗用、收集、发布到任何网站、图书等媒体平台。本站内容如有侵犯原作者合法权益的,您可以联系我们处理。
文章来自互联网,侵权请联系删除,文章阐述观点来自文章出处,并不代表本站观点。
www.8001717.cn