如何使用wp插件作为主题部分而不是插件?

时间:2018-03-26 13:12:19

标签: wordpress plugins themes

我正在开发一个word press主题,我有一个免费的插件,可以帮助我为我的主题添加新功能。我想在这个主题中使用这个插件,但我不想将它用作插件,必须在插件部分激活。我想将它用作主题部分并禁用激活或停用它。主题设置时会自动激活。

2 个答案:

答案 0 :(得分:0)

如果您的主题已上传到某处,请参阅 - > https://wordimpress.com/how-to-easily-require-plugins-for-your-wordpress-themes/

add_action( 'admin_notices', 'my_theme_dependencies' );

function my_theme_dependencies() {
  if( ! function_exists('plugin_function') )
    echo '<div class="error"><p>' . __( 'Warning: The theme needs Plugin X to function', 'my-theme' ) . '</p></div>';
}

OR
如果你的主题是在本地设置,那么你可以使用必须插件,为那个参考 - &gt; https://codex.wordpress.org/Must_Use_Plugins

答案 1 :(得分:0)

因此,如果我理解正确,您希望您的插件在Wordpress中,但您不希望它被显示给其他人或能够停用它吗?

尝试使用此插件,它会隐藏每个人的插件({3}}。

将此添加到您的functions.php文件中:

function hide_plugin_trickspanda() {
  global $wp_list_table;
  $hidearr = array('plugin-directory/plugin-file.php');
  $myplugins = $wp_list_table->items;
  foreach ($myplugins as $key => $val) {
    if (in_array($key,$hidearr)) {
      unset($wp_list_table->items[$key]);
    }
  }
}

add_action('pre_current_active_plugins', 'hide_plugin_trickspanda');

使用此代码的信息:在第一行重命名插件名称,也将“plugin-directory / plugin-file.php”更改为插件的插件文件,并在最后一行也改变了插件名称。

相关问题