在不激活它们的情况下自动在 wordpress 中执行插件?
Automatically execute plugin in wordpress without activating them?
每当我们在 wordpress 中使用任何插件时,我们都需要转到插件选项,然后我们必须激活它们才能使用它们,很好!
现在我的问题是
what if someone wants to execute the plugin by default without activating them ?
这意味着只需安装该插件,该插件将在我们的网站上自动执行,无需任何激活。
您可以使用此代码自动激活 WordPress 插件,这将帮助您解决自动激活插件问题。
<?php
// example on admin init, control about register_activation_hook()
add_action( 'admin_init', 'your_activate_plugins_function' );
// the exmple function
function your_activate_plugins_function() {
if ( ! current_user_can('activate_plugins') )
wp_die(__('You do not have sufficient permissions to activate plugins for this site.'));
$plugins = FALSE;
$plugins = get_option('active_plugins'); // get active plugins
if ( $plugins ){
// plugins to active
$pugins_to_active = array(
'hello.php', // Hello Dolly
'adminimize/adminimize.php', // Adminimize
'akismet/akismet.php', // Akismet
'find-any-think/create-plugin-index.php' // Find any think Plugin
);
foreach ( $pugins_to_active as $plugin ) {
if ( ! in_array( $plugin, $plugins ) ) {
array_push( $plugins, $plugin );
update_option( 'active_plugins', $plugins );
}
}
} // end if $plugins
}
?>
谢谢,我希望您的问题将通过此代码得到解决。
感谢 Mubeen 的回答,但我刚刚找到了另一个非常简单易懂的解决方案!
只创建一个文件夹名称
mu-plugins
文件夹目录应该是
/wp-content/mu-plugins
只需从 www.wordpress.com 下载任何插件并解压缩并简单地将它们复制到此文件夹中,您将在 wordpress 插件选项中看到一个新选项卡
Must-Use
此选项卡下的插件将在您的网站上自动执行,但存在一个问题,如果您想停用该插件,则必须从 mu-plugins 文件夹中删除该插件。
来源:
http://justintadlock.com/archives/2011/02/02/creating-a-custom-functions-plugin-for-end-users
每当我们在 wordpress 中使用任何插件时,我们都需要转到插件选项,然后我们必须激活它们才能使用它们,很好!
现在我的问题是
what if someone wants to execute the plugin by default without activating them ?
这意味着只需安装该插件,该插件将在我们的网站上自动执行,无需任何激活。
您可以使用此代码自动激活 WordPress 插件,这将帮助您解决自动激活插件问题。
<?php
// example on admin init, control about register_activation_hook()
add_action( 'admin_init', 'your_activate_plugins_function' );
// the exmple function
function your_activate_plugins_function() {
if ( ! current_user_can('activate_plugins') )
wp_die(__('You do not have sufficient permissions to activate plugins for this site.'));
$plugins = FALSE;
$plugins = get_option('active_plugins'); // get active plugins
if ( $plugins ){
// plugins to active
$pugins_to_active = array(
'hello.php', // Hello Dolly
'adminimize/adminimize.php', // Adminimize
'akismet/akismet.php', // Akismet
'find-any-think/create-plugin-index.php' // Find any think Plugin
);
foreach ( $pugins_to_active as $plugin ) {
if ( ! in_array( $plugin, $plugins ) ) {
array_push( $plugins, $plugin );
update_option( 'active_plugins', $plugins );
}
}
} // end if $plugins
}
?>
谢谢,我希望您的问题将通过此代码得到解决。
感谢 Mubeen 的回答,但我刚刚找到了另一个非常简单易懂的解决方案!
只创建一个文件夹名称
mu-plugins
文件夹目录应该是
/wp-content/mu-plugins
只需从 www.wordpress.com 下载任何插件并解压缩并简单地将它们复制到此文件夹中,您将在 wordpress 插件选项中看到一个新选项卡
Must-Use
此选项卡下的插件将在您的网站上自动执行,但存在一个问题,如果您想停用该插件,则必须从 mu-plugins 文件夹中删除该插件。
来源: http://justintadlock.com/archives/2011/02/02/creating-a-custom-functions-plugin-for-end-users