YahnisElsts/wp-update-server

Sudenly I get: Update failed: You have the latest version of the plugin.

cristian-dan-f opened this issue · 10 comments

Hi, please help me with this. Everything was working fine, and sudenly when I click "Update now" on the WP Plugins list, i get the message:
"Update failed: You have the latest version of the plugin."

I didn't make any recent changes, and since the begining the only modification was creating a new PHP file:
download-auth.php


class UpdateServerAuth extends Wpup_UpdateServer {

	protected $license_key = "my-secret-license-key-xD";

	public function __construct() {
		parent::__construct();
	}

	protected function filterMetadata($meta, $request) {

		$meta = parent::filterMetadata($meta, $request);

		//Include license information in the update metadata. This saves an HTTP request
		//or two since the plugin doesn't need to explicitly fetch license details.
		if( $request->param('license_key') && $request->param('license_key') == $this->license_key ){
			$meta['license_status'] = 'License valid';
		} else {
			//No license = no download link.
			$meta['license_status'] = 'License invalid';
			//unset($meta['download_url']);
		}

		return $meta;

	}

	protected function checkAuthorization($request) {

		parent::checkAuthorization($request);

		if( $request->action==='download' ) {

			//Prevent download if the user doesn't have a valid license.
			if( empty($request->param('license_key')) || $request->param('license_key') != $this->license_key ){
				// Provided @license_key not valid
				$message = 'Sorry, your license is not valid.';
				//$this->exitWithError($message, 403);
			}

		}

	}

}

As you can see I tried to comment the line unset($meta['download_url']); and $this->exitWithError($message, 403); which could be causing some problem, but with no luck.

Try opening the metadata URL and the download URL in the browser. Does it work fine when you do that? Is all of the update metadata that you see correct, and are does the download URL return the correct file?

Yes, metada URL is working fine, and the information displayed is correct, and the download URL inside it point to the correct file.

Just to be clear, are you saying that the download URL looks correct, or that it actually downloads the correct file when you try to open it?

Another thing to check would be the version number of the currently installed version and the version number in the update ZIP file. Normally, the updated version should be higher. Also, if there's anything that modifies or filters the plugin version number (in the plugin itself, not the update server), that could be worth investigating.

The url is something like:
"https://domain.com/updater-folder/?action=download&slug=my-plugin-slug"

I open it in the browser and i get the correct plugin file

The version number is hardcoded in the bgining of the plugin file:

/**
* @wordpress-plugin
* Plugin Name: 
* Plugin URI: 
* Description: 
* Version: 0.5.8.3
* Author: 
* Author URI: 
* Text Domain: 
**/

There is no filter to modify the version. I even tried to change the versioning and go directly to version 1, i tried several combinations but no change, the error message after clicking "Update now" and waiting a while is that "I already have the latest version"

It sounds like the update server is working fine. I'm not sure why you're suddenly getting an error when trying to install the update. Perhaps there's something wrong with the site where the plugin is installed?

Here are a few more ideas:

  • Install the Debug Bar plugin and look at the information shown in the "PUC (your-plugin-slug)" section. Does everything look correct? Try clicking the "Check Now" and "Request Info" buttons and see if it successfully returns the update information.
  • Temporarily deactivate all other plugins and switch to the default theme to check if there's a conflict of some kind.
  • See if the server that's running the WordPress site has some kind of firewall that could be blocking some outgoing requests.
  • Try updating through the "Dashboard -> Updates" page instead. Does it show the same error, or does something different happen?

Thank you for your time.

  • Updating through the "Dashboard -> Updates" page WORKS perfectly, but not in plugins list.

  • I already tried Debug Bar some time ago but it doesn't show "PUC (your-plugin-slug)" section. I tried it again just now and it still doesn't show anything besides "Wp_Http" and "Object cache"

  • I already tried deactivating everything and switching to default template, did again now, deleted every cache file, and browser cache, but no luck.

  • The update server and the WP site is the same server.

That's interesting, and gives me another idea: Is there, by any chance, some kind of an if-condition that controls when your plugin initializes the update checker? If so, try removing that condition so that the update checker instance is always created.

Edit: This also applies to anything that might prevent your plugin from being loaded in some circumstances. For example, if it's designed not to run during an AJAX request, disable that check for now.

Yes, you are right, problem solved!

I did my best to always load only strictly necessary files, depending on several conditions, so the update checker was running strictly on admin, and not on ajax requests.

The truth is this never crossed my mind, I wasted 2 weeks, looking in every file, doing all kinds of tests before writing here, and it never occurred to me that the update was an Ajax request.

Thank you for your time.

All right, sounds good. I'll close this issue now.