• Resolved Marc Lacroix

    (@marcusig)


    Hi David,

    I’ve received a good number of support requests saying that “they cannot update the add-on”, as a general error is displayed, saying that the ZIP is not valid.

    I checked the cause of that, and in Updraft_Manager_Plugin, the pinfo_download method just dies if there is no valid license or the license has expired.

    So on the website requesting to download the ZIP, this results in an empty file but with a valid header (200).

    Is there any reason for not setting a different header, like is done in the other checks?

    I’ve updated the class on my side to have a 403 or 402 error, which translates on the update screen as a more appropriate message:

    if (empty($entitlements) && !$this->downloadable_base_plugin) {
    header($_SERVER['SERVER_PROTOCOL'] . ' 403 No valid license found', true, 403);
    die;
    }

    if ('expired' === $entitlements && !$this->downloadable_base_plugin) {
    header($_SERVER['SERVER_PROTOCOL'] . ' 402 License expired', true, 402);
    die;
    }

    Error 402 gives this result in WP when trying to update:

    What do you think?

    Marc

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author David Anderson / Team Updraft

    (@davidanderson)

    Hi Marc,

    I can see it would be helpful to display a better message. I’ve seen plugins that do this – but which then display their message for *all* plugins. It’s many years since I looked into it, but if I remember rightly, the existing hooks in WP didn’t make it easy.

    Looks like “Payment Required” comes from get_status_header_desc() in wp-includes/functions.php. I think the most appropriate one generally would be 401 (Unauthorized), since that’s always true; whether payment is needed may depend upon different sites’ use cases. But “Unauthorized’ is not adding a lot of useful info to the user.

    I’m happy to add a filter if you know you’d be happy just with a specific HTTP code in the response. Or maybe you have time to look at the client-side of things to see if there are better ways of providing a custom message than I found when I looked several years ago?

    David

    Thread Starter Marc Lacroix

    (@marcusig)

    Hi David,

    A filter would be great, and I would separate the “no entitlement” response from “entitlement expired” if possible (or have a way to send a different response.

    I was looking at changing this on the client side, but I didn’t find anywhere to hook into, at least in the ZIP download request.

    I’ve also noticed that somehow there is no “expired license” warning at all in the admin.
    I checked the admin_menu method of the updater class, where the warning is supposed to be displayed. The data used never contains x-spm-expiry (or anything x-spm-* for that matter).
    I haven’t investigated more though, so i’m not sure why that data is missing, even though it is present in the responses from the license server.

    Marc

    Thread Starter Marc Lacroix

    (@marcusig)

    I’ve also noticed that somehow there is no “expired license” warning at all in the admin.

    Ignore this part. I had just updated the upgrader class, but the data had not reflected yet. It looks like it is working again.

    Plugin Author David Anderson / Team Updraft

    (@davidanderson)

    It looks like it is working again.

    Yes, sorry about that – towards the end of last year someone discovered that the x-spm- headers weren’t getting passed along correctly.

    A filter would be great, and I would separate the “no entitlement” response from “entitlement expired” if possible (or have a way to send a different response.

    If you send me a patch (here in this thread is fine) I’m happy to include it (filters are harmless).

    Thread Starter Marc Lacroix

    (@marcusig)

    Hi David,

    Here’s the Diff which:

    • adds a header before die ing, with default code of 401
    • adds a filter to potentially alter the response code
    --- a/classes/updraftmanager-plugin.php
    +++ b/classes/updraftmanager-plugin.php
    @@ -317,7 +317,14 @@ class Updraft_Manager_Plugin {

    // Find out what they are entitled to
    $entitlements = $this->get_user_addon_entitlements($download_info['id'], $download_info['sid'], true);
    - if ((empty($entitlements) || 'expired' === $entitlements) && !$this->downloadable_base_plugin) die;
    + if ((empty($entitlements) || 'expired' === $entitlements) && !$this->downloadable_base_plugin) {
    + header(
    + $_SERVER['SERVER_PROTOCOL'] . ' No valid entitlement found',
    + true,
    + apply_filters('updraftmanager_no_entitlement_error_code', 401, $entitlements)
    + );
    + die;
    + }

    $ent_keys = array();
    if (is_array($entitlements)) {

    Marc

    • This reply was modified 2 weeks, 3 days ago by Marc Lacroix.
    Thread Starter Marc Lacroix

    (@marcusig)

    I can’t edit the above, but the code above doesn’t work. The code must be changed both in the first and last parameter:

    --- a/classes/updraftmanager-plugin.php
    +++ b/classes/updraftmanager-plugin.php
    @@ -317,7 +317,15 @@ class Updraft_Manager_Plugin {

    // Find out what they are entitled to
    $entitlements = $this->get_user_addon_entitlements($download_info['id'], $download_info['sid'], true);
    - if ((empty($entitlements) || 'expired' === $entitlements) && !$this->downloadable_base_plugin) die;
    + if ((empty($entitlements) || 'expired' === $entitlements) && !$this->downloadable_base_plugin) {
    + $response_code = (int) apply_filters('updraftmanager_no_entitlement_error_code', 401, $entitlements);
    + header(
    + $_SERVER['SERVER_PROTOCOL'] . ' ' . $response_code . ' No valid license found',
    + true,
    + $response_code
    + );
    + die;
    + }

    Plugin Author David Anderson / Team Updraft

    (@davidanderson)

    Thanks Marc… I’ve added this to. Again, if you put that in your current install, the same filter will be there next time there’s an update release.

    David

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.