Domanda

I'm trying out adding WordPress REST API endpoints. I would now like to add an endpoint that retrieves a list of available plugin, theme and core updates.

I found the following functions: get_plugin_updates(), get_theme_updates() and get_core_updates(). With these functions I could retrieve info about which plugins to update.

How do I start the update proces for a plugin/theme/core? I'm especially looking for updating an individual item. Similar to WP Manage and GoDaddy Hub.

It would be great if someone could tell me how to implement this and how to start the update process!

È stato utile?

Soluzione

REST or anything RESTful is a generally adhered to standard of getting things done via API. It also has the capability of documenting itself.

Now I had expected to write an answer here about how it's not a great idea to allow endpoints to update or modify any of your codebase but I see it seems the good folks at Automattic have thought it ok and they know the core a lot better than I do, I also presume you need to be authenticated before using it.

Go to [yourwordpresswebsite.com]/wp-json/

It brings up a sort of library of endpoints and how to use them

If you go to routes then find "/wp/v2/plugins/(?P<plugin>[^.\/]+(?:\/[^.\/]+)?)" and endpoints

You can see the following

    0   "GET"
        args    {…}
    1   
        methods 
        0   "POST"
        1   "PUT"
        2   "PATCH"
        args    {…}
    2   
        methods 
        0   "DELETE"

Which you can match up in the REST API docs on plugins

This sort of updating via API should IMO only be done for ease of something like mass-rollout. Say you have a hundred servers running the same core setup and your testing has concluded it's safe.

You can also just set up WordPress to update itself automatically instead and save yourself the bother.

There are some interesting examples of using composer to install / update WordPress. Look at johnpbloch, satispress. Also off the shelf Wordfence Central

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange
scroll top