0

Is there a way to take a plugin slug (e.g. 'akismet') of a plugin that is NOT currently installed and somehow retrieve the download URL of the current version (e.g. 'http://downloads.wordpress.org/plugin/akismet.2.5.3.zip')?

This is for a command line script I am trying to develop that will enable plugin installation from the command line.

2 Answers 2

2

I forget exactly if the plugin slug is a reliable method to get the url, it might be in most cases but not all due to how plugins are named.

You can query the api @wordpress.org for the plugins xml file which also contains the download link.

For example:

$plugin_slug = 'akismet'; 
$return_plugin_info = "http://api.wordpress.org/plugins/info/1.0/$plugin_slug.xml"

It will return an XML file you can parse for the download link, which is in <download_link type="string">the link...akismet.zip</download>

1

I think I am late but as per new guidelines I found this is best possible solution

   // Set the arguments. For brevity of code, I will set only a few fields.
    $args = array(
        'slug' => 'akismet', // or any plugin slug
        'fields' => array(
            'version' => true
        )
    );

    // Make request and extract plug-in object. Action is query_plugins
    $response = wp_remote_post(
        'http://api.wordpress.org/plugins/info/1.0/',
        array(
            'body' => array(
                'action' => 'plugin_information',
                'request' => serialize((object)$args)
            )
        )
    );
    //
    if ( !is_wp_error($response) ) {
        $returned_object = unserialize(wp_remote_retrieve_body($response));   

        if ($returned_object) {
            $downloaded = $returned_object->downloaded;
            print_r($downloaded);
        }
        else {
            // Response body does not contain an object/array
            echo "An error has occurred.";
        }
    }
    else {
        // Error object returned
        echo "An error has occurred";
    }
1

Your Answer

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

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