-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
validating a "key" #30
Comments
I think i`m getting a bit confused here. Just the get_metadata ? |
There are multiple ways to do that. The quickest approach would be to use the
The only action you have to validate in the update server is Personally, I let all users see update details, but I remove the |
I like your approach and i think thats what i'd like to achieve too. In my server extended class i'd have a Or if i understood from your approach validate the key in the get_metadata action and if the key is invalid just remove the download_url ? |
My protected function checkAuthorization($request) {
parent::checkAuthorization($request);
//Prevent download if the user doesn't have a valid license.
$license = somehowLoadLicense();
if ( $request->action === 'download' && ! ($license && $license->isValid()) ) {
if ( !isset($license) ) {
$message = 'You must provide a license key to download this plugin.';
} else {
$error = $license->get('error');
$message = $error ? $error : 'Sorry, your license is not valid.';
}
$this->exitWithError($message, 403);
}
} I remove the protected function filterMetadata($meta, $request) {
$meta = parent::filterMetadata($meta, $request);
//Only include the download URL if the license is valid.
$license = somehowLoadLicense();
if ( $license && $license->isValid() ) {
//Append the license key the automatically generated download URL.
$args = array(
'license_key' => $request->param('license_key'),
'license_site_url' => $request->param('license_site_url'),
);
$meta['download_url'] = self::addQueryArg($args, $meta['download_url']);
} else {
unset($meta['download_url']);
}
return $meta;
} I hope that helps. |
sorry to bump an old issue but i need some assistance. this is the checkAuthorization function
is_valid_license is a function that returns false or true and the download_url is appended correctly if the license is valid. |
Interesting. Some ideas:
|
the update server is inside an updates/ directory on the same main public_html/ where the WordPress is.
then the updating works just fine. |
BTW i'm using just this inside my plugin: https://github.com/YahnisElsts/plugin-update-checker/blob/master/plugin-update-checker.php without the other files |
And I would recommend Chrome Dev Tools before Wireshark. I think Wireshark is a little more low level than is needed here. (IMHO. It's a little overwhelming if you haven't played with it before.) |
Also, on the WordPress side: |
Yeah i got debug enabled. No errors at all. |
Correct me if I'm wrong, but Chrome Dev tools isn't going to work here. It only catches AJAX requests. It won't show requests sent by PHP scripts via the WordPress HTTP API or something like Curl.
Hmm, are you 100% sure you're looking at the right file? What happens if you intentionally trigger an error? |
@YahnisElsts, Sorry, I re-read his comment after posting my own and realized it was happening on the WordPress side. I guess I have to actually read things before I can try to be helpful! |
this is really erally weird..tested the same plugin code on a different plugin and its working just fine. Could be that specific plugin with issues ? possibly the "updater" or the server side are having issues when the plugin has a pretty huge directory structure ? |
Maybe, but that's a separate issue. It probably wouldn't cause a "download failed" error. Does the first plugin use any hooks that could affect how HTTP requests are handled? Anything that would add or change query parameters, or modify URLs, or anything else the other plugin doesn't do? How about other plugins that are active on the same site? Could one of them be interfering with the download? |
I think its something in my code. I left my extended class empty without any functions and its working correctly. Any way i can send u my extended server to take a look at it ? Its really small and easy but there might be something i`m missing there. |
Sure. My email is [email protected] Edit: However, it's pretty late, so I probably won't get a chance to look at the code today. |
Is there a filter similar to puc_pre_inject_update-$slug for themes.
Same issue, but with a theme. |
Yes, it's something like $updateChecker->addFilter('pre_inject_update', 'my_callback') |
Thank you. This filter is running 5-6 times? |
I've never counted, but that seems plausible. It would run every time some code requests the |
I did some testing and it looks like it would run at least 4 times on every admin page. This is because WordPress shows the number of available updates in the admin menu and the Toolbar (a.k.a Admin Bar). To get that information, WP core calls the Pages that show update-related information in more places - like "Plugins -> Installed Plugins" or "Dashboard -> Updates" - will trigger the filter several more times. So seeing it go off 5-6 times is not that surprising. |
Here is my hacky solution to add license key to the download url. Is there a better way?
|
You can use the |
Hey.
Got a small issue.
I`m using addQueryArgFilter to add a license_key param in the plugin file.
I can see that the param hits the update server when checking for updates but when clicking Update Now for a plugin the license field is not sent in the request.
Is there something else that needs to run to add the param to the download action ?
The text was updated successfully, but these errors were encountered: