Skip to content

Commit

Permalink
Tracked down problem with plugin install screen, checking for existen…
Browse files Browse the repository at this point in the history
…ce of args->slug before returning false. Closes #15

Moved WordPress user agent check to contain all checks otherwise getting notices if visiting api page from browser.
Made testing easier made packages.php contain test-plugin-update slug by default.
  • Loading branch information
jeremyclark13 committed Jan 24, 2013
1 parent 12de4cd commit 86fedc5
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 54 deletions.
104 changes: 52 additions & 52 deletions api/index.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,74 +33,74 @@
// Process API requests // Process API requests
$action = $_POST['action']; $action = $_POST['action'];
$args = unserialize( $_POST['request'] ); $args = unserialize( $_POST['request'] );

if ( is_array( $args ) ) if ( is_array( $args ) )
$args = array_to_object( $args ); $args = array_to_object( $args );


$latest_package = array_shift( $packages[$args->slug]['versions'] ); $latest_package = array_shift( $packages[$args->slug]['versions'] );
} else {
/*
An error message can be displayed to users who go directly to the update url
*/

echo 'Whoops, this page doesn\'t exist';
}


// basic_check // basic_check


if ( $action == 'basic_check' ) { if ( $action == 'basic_check' ) {
$update_info = array_to_object( $latest_package ); $update_info = array_to_object( $latest_package );
$update_info->slug = $args->slug; $update_info->slug = $args->slug;


if ( version_compare( $args->version, $latest_package['version'], '<' ) ) { if ( version_compare( $args->version, $latest_package['version'], '<' ) ) {
$update_info->new_version = $update_info->version; $update_info->new_version = $update_info->version;
print serialize( $update_info ); print serialize( $update_info );
}
} }
}


// plugin_information // plugin_information


if ( $action == 'plugin_information' ) { if ( $action == 'plugin_information' ) {
$data = new stdClass; $data = new stdClass;


$data->slug = $args->slug; $data->slug = $args->slug;
$data->version = $latest_package['version']; $data->version = $latest_package['version'];
$data->last_updated = $latest_package['date']; $data->last_updated = $latest_package['date'];
$data->download_link = $latest_package['package']; $data->download_link = $latest_package['package'];
$data->author = $latest_package['author']; $data->author = $latest_package['author'];
$data->external = $latest_package['external']; $data->external = $latest_package['external'];
$data->requires = $latest_package['requires']; $data->requires = $latest_package['requires'];
$data->tested = $latest_package['tested']; $data->tested = $latest_package['tested'];
$data->homepage = $latest_package['homepage']; $data->homepage = $latest_package['homepage'];
$data->downloaded = $latest_package['downloaded']; $data->downloaded = $latest_package['downloaded'];
$data->sections = $latest_package['sections']; $data->sections = $latest_package['sections'];
print serialize( $data ); print serialize( $data );
} }


// theme_update // theme_update


if ( $action == 'theme_update' ) { if ( $action == 'theme_update' ) {
$update_info = array_to_object( $latest_package ); $update_info = array_to_object( $latest_package );
$update_data = array( ); $update_data = array( );
$update_data['package'] = $update_info->package; $update_data['package'] = $update_info->package;
$update_data['new_version'] = $update_info->version; $update_data['new_version'] = $update_info->version;
$update_data['url'] = $packages[$args->slug]['info']['url']; $update_data['url'] = $packages[$args->slug]['info']['url'];
if ( version_compare( $args->version, $latest_package['version'], '<' ) ) if ( version_compare( $args->version, $latest_package['version'], '<' ) )
print serialize( $update_data ); print serialize( $update_data );
} }


if ( $action == 'theme_information' ) { if ( $action == 'theme_information' ) {
$data = new stdClass; $data = new stdClass;
$data->slug = $args->slug; $data->slug = $args->slug;
$data->name = $latest_package['name']; $data->name = $latest_package['name'];
$data->version = $latest_package['version']; $data->version = $latest_package['version'];
$data->last_updated = $latest_package['date']; $data->last_updated = $latest_package['date'];
$data->download_link = $latest_package['package']; $data->download_link = $latest_package['package'];
$data->author = $latest_package['author']; $data->author = $latest_package['author'];
$data->requires = $latest_package['requires']; $data->requires = $latest_package['requires'];
$data->tested = $latest_package['tested']; $data->tested = $latest_package['tested'];
$data->screenshot_url = $latest_package['screenshot_url']; $data->screenshot_url = $latest_package['screenshot_url'];
print serialize( $data ); print serialize( $data );
}
} else {
/*
An error message can be displayed to users who go directly to the update url
*/

echo 'Whoops, this page doesn\'t exist';
} }


function array_to_object( $array = array( ) ) { function array_to_object( $array = array( ) ) {
Expand Down
2 changes: 1 addition & 1 deletion api/packages.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
); );


// Plugin with update info // Plugin with update info
$packages['plugin'] = array( //Replace plugin with the plugin slug that updates will be checking for $packages['test-plugin-update'] = array( //Replace plugin with the plugin slug that updates will be checking for
'versions' => array( 'versions' => array(
'1.0' => array( //Array name should be set to current version of update '1.0' => array( //Array name should be set to current version of update
'version' => '1.0', //Current version available 'version' => '1.0', //Current version available
Expand Down
2 changes: 1 addition & 1 deletion plugin/test-plugin-update/test-plugin-update.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function check_for_plugin_update($checked_data) {
function plugin_api_call($def, $action, $args) { function plugin_api_call($def, $action, $args) {
global $plugin_slug, $api_url, $wp_version; global $plugin_slug, $api_url, $wp_version;


if (isset($args->slug) && ($args->slug != $plugin_slug)) if (!isset($args->slug) || ($args->slug != $plugin_slug))
return false; return false;


// Get the current version // Get the current version
Expand Down

0 comments on commit 86fedc5

Please sign in to comment.