How can I install and activate a predefined list of WP plugins using the WP API using Php please?
Asked
Active
Viewed 3,245 times
1
-
please share more informations...would you provide plugins with your theme..or what? – Tobias Apr 22 '18 at 18:42
-
No it's not plugins associated with a theme. What additional information do you need? I don't know how the WP API works, I'm hoping that a php script can connect to the API and run some code to install and activate a list of plugins. – Nick W Apr 22 '18 at 22:54
-
I see that Wordpress core now includes a REST API, but whilst it can retrieve data I don't see any method to install and activate a specifired plugin. Maybe I can adapt wp-quick-install https://github.com/GeekPress/WP-Quick-Install/blob/master/wp-quick-install/index.php – Nick W Apr 24 '18 at 10:25
-
Maybe a php script in a plugin in the mu-plugins directory could download, unzip, install and activate a list of plugins. Maybe this script could be adapted https://gist.github.com/davejamesmiller/1966425 – Nick W Apr 24 '18 at 10:36
-
Although not required for a theme, maybe the TGM-Plugin-Activation Php Library at https://github.com/TGMPA/TGM-Plugin-Activation could be useful. I'll investigate further at wordpress.stackexchange.com – Nick W Apr 24 '18 at 11:01
1 Answers
2
The REST API doesn't support plugin based actions yet. See the API handbook reference for information on what endpoints are currently available.
Posts /wp/v2/posts
Post Revisions /wp/v2/revisions
Categories /wp/v2/categories
Tags /wp/v2/tags
Pages /wp/v2/pages
Comments /wp/v2/comments
Taxonomies /wp/v2/taxonomies
Media /wp/v2/media
Users /wp/v2/users
Post Types /wp/v2/types
Post Statuses /wp/v2/statuses
Settings /wp/v2/settings
You can add custom endpoints though which would open this up for you, but due to the authentication methods available in the REST API at the moment (cookies), it does mean you have to be careful about who can access the endpoint.
A better approach to all of this is to use WP-CLI. It's an official WordPress project that lets you control the site from the command line. This is the best approach I think.
-
2That's not true anymore - the plugin endpoint is '/wp/v2/plugins' - see https://developer.wordpress.org/rest-api/reference/#rest-api-developer-endpoint-reference – lgersman Mar 16 '22 at 05:53