Permalink
Browse files

Tracked down problem with plugin install screen, checking for existen…

…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...
1 parent 12de4cd commit 86fedc50ec9e808b2f21ecac0b8d3345115a0422 @jeremyclark13 committed Jan 24, 2013
Showing with 54 additions and 54 deletions.
  1. +52 −52 api/index.php
  2. +1 −1 api/packages.php
  3. +1 −1 plugin/test-plugin-update/test-plugin-update.php
View
@@ -33,74 +33,74 @@
// Process API requests
$action = $_POST['action'];
$args = unserialize( $_POST['request'] );
-
+
if ( is_array( $args ) )
$args = array_to_object( $args );
$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
-if ( $action == 'basic_check' ) {
- $update_info = array_to_object( $latest_package );
- $update_info->slug = $args->slug;
+ if ( $action == 'basic_check' ) {
+ $update_info = array_to_object( $latest_package );
+ $update_info->slug = $args->slug;
- if ( version_compare( $args->version, $latest_package['version'], '<' ) ) {
- $update_info->new_version = $update_info->version;
- print serialize( $update_info );
+ if ( version_compare( $args->version, $latest_package['version'], '<' ) ) {
+ $update_info->new_version = $update_info->version;
+ print serialize( $update_info );
+ }
}
-}
// plugin_information
-if ( $action == 'plugin_information' ) {
- $data = new stdClass;
-
- $data->slug = $args->slug;
- $data->version = $latest_package['version'];
- $data->last_updated = $latest_package['date'];
- $data->download_link = $latest_package['package'];
- $data->author = $latest_package['author'];
- $data->external = $latest_package['external'];
- $data->requires = $latest_package['requires'];
- $data->tested = $latest_package['tested'];
- $data->homepage = $latest_package['homepage'];
- $data->downloaded = $latest_package['downloaded'];
- $data->sections = $latest_package['sections'];
- print serialize( $data );
-}
+ if ( $action == 'plugin_information' ) {
+ $data = new stdClass;
+
+ $data->slug = $args->slug;
+ $data->version = $latest_package['version'];
+ $data->last_updated = $latest_package['date'];
+ $data->download_link = $latest_package['package'];
+ $data->author = $latest_package['author'];
+ $data->external = $latest_package['external'];
+ $data->requires = $latest_package['requires'];
+ $data->tested = $latest_package['tested'];
+ $data->homepage = $latest_package['homepage'];
+ $data->downloaded = $latest_package['downloaded'];
+ $data->sections = $latest_package['sections'];
+ print serialize( $data );
+ }
// theme_update
-if ( $action == 'theme_update' ) {
- $update_info = array_to_object( $latest_package );
- $update_data = array( );
- $update_data['package'] = $update_info->package;
- $update_data['new_version'] = $update_info->version;
- $update_data['url'] = $packages[$args->slug]['info']['url'];
- if ( version_compare( $args->version, $latest_package['version'], '<' ) )
- print serialize( $update_data );
-}
+ if ( $action == 'theme_update' ) {
+ $update_info = array_to_object( $latest_package );
+ $update_data = array( );
+ $update_data['package'] = $update_info->package;
+ $update_data['new_version'] = $update_info->version;
+ $update_data['url'] = $packages[$args->slug]['info']['url'];
+ if ( version_compare( $args->version, $latest_package['version'], '<' ) )
+ print serialize( $update_data );
+ }
-if ( $action == 'theme_information' ) {
- $data = new stdClass;
- $data->slug = $args->slug;
- $data->name = $latest_package['name'];
- $data->version = $latest_package['version'];
- $data->last_updated = $latest_package['date'];
- $data->download_link = $latest_package['package'];
- $data->author = $latest_package['author'];
- $data->requires = $latest_package['requires'];
- $data->tested = $latest_package['tested'];
- $data->screenshot_url = $latest_package['screenshot_url'];
- print serialize( $data );
+ if ( $action == 'theme_information' ) {
+ $data = new stdClass;
+ $data->slug = $args->slug;
+ $data->name = $latest_package['name'];
+ $data->version = $latest_package['version'];
+ $data->last_updated = $latest_package['date'];
+ $data->download_link = $latest_package['package'];
+ $data->author = $latest_package['author'];
+ $data->requires = $latest_package['requires'];
+ $data->tested = $latest_package['tested'];
+ $data->screenshot_url = $latest_package['screenshot_url'];
+ 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( ) ) {
View
@@ -22,7 +22,7 @@
);
// 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(
'1.0' => array( //Array name should be set to current version of update
'version' => '1.0', //Current version available
@@ -74,7 +74,7 @@ function check_for_plugin_update($checked_data) {
function plugin_api_call($def, $action, $args) {
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;
// Get the current version

0 comments on commit 86fedc5

Please sign in to comment.