2

Is it possible in wordpress to specify where to update plugins instead of the repository, for example, from a specific folder in google drive?

1 Answer 1

1

It is possible!

An example code below is for the specific plugin (let's name it my-plugin), but You can do exact the same for all of the plugins on Your site. You have to just modify $data->response as it is done for "my-plugin/my-plugin.php" plugin below

add_filter( 'pre_set_site_transient_update_plugins', 'my_plugin_update_feed' );

function my_plugin_update_feed( $data ) {
    
    if ( empty( $data ) ) {
        return $data;
    }

    $url = 'https://drive.google.com/path/to/my-plugin/release.json?' . time();

    $request = wp_remote_get( $url );

    if ( is_wp_error( $request ) ) {
        return $data;
    }

    $response = wp_remote_retrieve_body( $request );

    $response = json_decode( $response );

    if ( ! isset( $response->slug ) || ! isset( $response->new_version ) || ! isset( $response->url ) || ! isset( $response->package ) ) {
        return $data;
    }

    if ( version_compare( MY_PLUGIN_VERSION, $response->new_version, '<' ) ) {

        $data->response[ 'my-plugin/my-plugin.php' ] = $response;
    }

    return $data;
}

and release.json would be something like this:

{
    "slug": "my-plugin",
    "new_version": "0.0.3",
    "url": "https://drive.google.com/path/to/my-plugin/",
    "package": "https://drive.google.com/path/to/my-plugin/my-plugin-0.0.3.zip"
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.