要激活插件,您必须在插件中编写几行代码。
WordPress安装从wp admin/install运行。php。我们希望在安装成功后触发某些操作,因此插入代码的好地方就在下面:
<h1><?php _e( \'Success!\' ); ?></h1>
我们看到一个以以下内容开头的代码块:
if ( $error === false ) {
$wpdb->show_errors();
$result = wp_install($weblog_title, $user_name, $admin_email, $public, \'\', $admin_password);
extract( $result, EXTR_SKIP );
我选择在最后一个摘录语句之后插入我们的操作。为了激活插件,我添加了:
require_once( dirname( dirname( __FILE__ ) ) . \'/wp-admin/includes/plugin.php\' );
activate_plugin( dirname( dirname( __FILE__ ) ) . \'/wp-content/plugins/plugin-dir-name/pluginfile.php\' );
对于从插件列表中隐藏插件:
/**
* Filter the list of plugins according to user_login
*
* Usage: configure the variable $plugin_credentials, which holds a list of users and their plugins.
* To give full access, put a simple string "ALL"
* To grant only for some plugins, create an array with the Plugin Slug,
* which is the file name without extension (akismet.php, hello.php)
*
* @return array List of plugins
*/
function wdm_plugin_permissions( $plugins )
{
// Config
$plugin_credentials = array(
\'admin\' => "ALL",
\'other-admin\' => array(
\'akismet\',
),
\'another-admin\' => array(
\'akismet\',
\'hello\',
),
);
// Current user
global $current_user;
$username = $current_user->user_login;
// Super admin, return everything
if ( "ALL" == $plugin_credentials[ $username ] )
return $plugins;
// Filter the plugins of the user
foreach ( $plugins as $key => $value )
{
// Get the file name minus extension
$plugin_slug = basename( $key, \'.php\' );
// If not in the list of allowed plugins, remove from array
if( !in_array( $plugin_slug, $plugin_credentials[ $username ] ) )
unset( $plugins[ $key ] );
}
return $plugins;
}
add_filter( \'all_plugins\', \'wdm_plugin_permissions\' );
您需要根据用户角色修改代码。
关于插件隐藏代码,您可以参考this