Thursday, January 19, 2023
HomeWordPress Developmentphp - Getting newest plugin updates programatically

php – Getting newest plugin updates programatically


I am making an attempt to get all the newest out there plugin updates programatically in a REST API endpoint. Here’s what I’ve received (shortened for readability):

add_action( 'rest_api_init', perform() {
    register_rest_route( 'MY-ENDPOINT/v1', '/site-info', array(
        'strategies'             => WP_REST_Server::READABLE,
        'callback'            => 'get_site_info',
        'permission_callback' => "__return_true",
    ) );
});

perform get_site_info( WP_REST_Request $request ) {
    // Some validation

    $return = array();

    $all_plugins     = get_plugins();
    $upgrade_plugins = array();
    $present         = get_site_transient( 'update_plugins' );
    foreach ( (array) $all_plugins as $plugin_file => $plugin_data ) {
        if ( isset( $current->response[ $plugin_file ] ) ) {
            $upgrade_plugins[ $plugin_file ]         = (object) $plugin_data;
            $upgrade_plugins[ $plugin_file ]->replace = $current->response[ $plugin_file ];
        }
    }

    $return['plugins'] = $upgrade_plugins;
    
    $response = new WP_REST_Response($return);
    $response->set_status(200);

    return $response;
}

So to start with, I can see in admin that there can be found updates – however the API name provides me none.

The half that typically would not appear to work is get_site_transient( 'update_plugins' ); – after I took the mission domestically I received the newest updates however on the dwell server, it appears to be caught and will not give me the newest plugin updates correctly.

Anyone received any concept what is likely to be mistaken right here?

EDIT: The 2 updates I’ve are two paid plugins, unsure if that has something to do with it?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments