admin管理员组文章数量:1126117
I'm using a custom Php script to install WordPress via the Softaculous API. Once installed, what's the best way to programmatically install and activate a plugin? I could try setting up a custom WP script in Softaculous with a PHP script in a custom plugin in an mu-plugins folder, but I would prefer not to do that, and instead install/activate the plugin after the WP installation.
So what I would like to do after the WP main install and from an external PHP script if possible is:
- authenticate with admin credentials via PHP
- download a specific plugin from the repository
- install the plugin
- activate the plugin
Maybe I could use the TGM-Plugin-Activation
to install/activate another plugin, but I would need to be able to install/activate that plugin itself. Is this possible without any admin user clicks and without using the mu-plugins folder pre-install?
I've read these posts:
Activating a single plugin via php
Plugin to install a plugin
I'm using a custom Php script to install WordPress via the Softaculous API. Once installed, what's the best way to programmatically install and activate a plugin? I could try setting up a custom WP script in Softaculous with a PHP script in a custom plugin in an mu-plugins folder, but I would prefer not to do that, and instead install/activate the plugin after the WP installation.
So what I would like to do after the WP main install and from an external PHP script if possible is:
- authenticate with admin credentials via PHP
- download a specific plugin from the repository
- install the plugin
- activate the plugin
Maybe I could use the TGM-Plugin-Activation
to install/activate another plugin, but I would need to be able to install/activate that plugin itself. Is this possible without any admin user clicks and without using the mu-plugins folder pre-install?
I've read these posts:
Activating a single plugin via php
Plugin to install a plugin
Share Improve this question edited Mar 26, 2024 at 1:37 Jesse Nickles 7357 silver badges19 bronze badges asked Apr 26, 2018 at 10:13 Nick WNick W 1231 silver badge6 bronze badges 2- Why not use WP CLI to install, active the plugin? – bueltge Commented Apr 26, 2018 at 11:54
- Related: wordpress.stackexchange.com/questions/179963/… – Jesse Nickles Commented Dec 12, 2022 at 18:28
1 Answer
Reset to default 7WP CLI
The easy way; use the WP CLI (also available as wp-cli.phar
) to get a solid, maintainable solution for this requirement. More for this topic you will find at the command
wp plugin <command>
WP API
If you will need a custom script is is necessary to load the WP API, via wp-load.php
and look for the function activate_plugin($path_to_the_plugin)
.
Activation
As example what you need to get all requirements to activate a plugin see below
define( 'WP_ADMIN', TRUE );
define( 'WP_NETWORK_ADMIN', TRUE ); // Need for Multisite
define( 'WP_USER_ADMIN', TRUE );
require_once('../wp-load.php');
require_once( '../wp-admin/includes/admin.php' );
require_once( '../wp-admin/includes/plugin.php' );
activate_plugin( 'PATH_TO_THE_PLUGIN' );
Installation
The installation of a plugin is also possible via the API of WP, also code thats should helps a little bit to run in the right direction.
// Include required libs for installation
require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
require_once( ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php' );
require_once( ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php' );
// Get Plugin Info
$api = plugins_api( 'plugin_information',
array(
'slug' => $plugin,
'fields' => array(
'short_description' => false,
'sections' => false,
'requires' => false,
'rating' => false,
'ratings' => false,
'downloaded' => false,
'last_updated' => false,
'added' => false,
'tags' => false,
'compatibility' => false,
'homepage' => false,
'donate_link' => false,
),
)
);
$skin = new WP_Ajax_Upgrader_Skin();
$upgrader = new Plugin_Upgrader( $skin );
$upgrader->install( $api->download_link );
A example that install and activate see you in this class.
本文标签:
版权声明:本文标题:How to install and activate a plugin using an external PHP script? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736603378a1945271.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论