• Hi wordpress experts,

    I have an application in cakePHP i need to get all wordpress themes from the api and activate and deactivate those from the cakephp panel through the api.

    Is it possible? if possible then how i can do that?

    Any help will be appreciated.

    Thanks
    Krishna

    • This topic was modified 6 years, 7 months ago by krishna9720.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The WordPress REST API doesn’t have any endpoints for anything to with themes. You can see the list of available endpoints here: https://developer.www.ads-software.com/rest-api/reference/

    If you want to be able to list, activate or deactivate themes via the API you will need to create your own endpoint. Documentation for that is here: https://developer.www.ads-software.com/rest-api/extending-the-rest-api/adding-custom-endpoints/

    Thread Starter krishna9720

    (@krishna9720)

    Hi Jacob,

    Thanks for the response.

    Yes, I have created my custom end points for getting data from the custom tables but as a Beginner to working with WordPress API’s I really don’t know what functions i need to use to create custom end points for handling Word press themes.

    Can you please tell how can i create custom end points for the Themes.

    Many thanks
    Krishna

    Thread Starter krishna9720

    (@krishna9720)

    Here is the custom end points What i have created here for getting all themes.
    But in json it’s not returning result as expected.

    If I can see simply the wp_get_themes() function it will return all the themes and its description in arrays. and It’s return fine in arrays but when i am encoding this into json to pass data its returning only array keys.

    add_action( 'rest_api_init', function () {
        //Path to rest endpoint
        register_rest_route( 'theme/v1', '/get_theme_list/', array(
                'methods' => 'GET',
                'callback' => 'theme_list_function'
        ) );
    });
    // Our function to get the themes
    function theme_list_function(){
        // Get a list of themes
        $list = wp_get_themes();
        // Return the value
        return $list;
    }
    
    ?>
    • This reply was modified 6 years, 7 months ago by bcworkz. Reason: code fixed, otherwise syntax errors occur
    Moderator bcworkz

    (@bcworkz)

    I’m not sure why your array is incomplete. Whether it had worked or not, it’s recommended you return either a single value or an object. Generally, returned data should be wrapped in a WP_HTTP_Response object. One way of doing so is by using rest_ensure_response().

    In case you missed it, there is another route and endpoint section farther down in Jacob’s link to the REST API Handbook. There might be something useful there not mentioned in the previous section. https://developer.www.ads-software.com/rest-api/extending-the-rest-api/routes-and-endpoints/

    BTW, please demarcate code samples with backticks or use the code button. When you don’t do this, the forums’s parser corrupts your code and makes it difficult for others to test out your code snippet.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to activate and deactivate wordpress themes from API?’ is closed to new replies.