Open JoPed opened 11 months ago
addQueryArgFilter
is the correct way to do this with PUC. The code formatting is a bit messed up in your post, but at a glance, how you're doing it seems mostly correct. The only minor issue I see is that you're urlencode
-ing the value: you don't need to do that here, PUC will do it automatically.
I know it has been some time since my initial post - but thank you for the response! Most likely I will end up using the GitHub implementation for updating my plugin. While using the GitHub implementation, can I then still prevent plugin updates, if the user has no valid license? I already have the functionality to create and validate licenses, but I'm unsure as to how to use it together with the GitHub implementation of the plugin-update-checker.
Hope this makes sense, and that you can point me in the right direction!
I don't think that's really possible with GitHub. To do it securely, you need to validate the license on the server, not just in the plugin. And you can't run your custom license validation code on GitHub's API servers, so that's not going to work.
Technically, you could try something like giving each licensed user their own API token, but I don't know how practical that would be (does GitHub even allow generating arbitrarily many tokens?).
I feared you would say that, but thanks for the quick response. I honestly don't know if GitHub allows that.
I just started using the plugin-update-checker, the thing is that there is already licens management in my plugin and for that to work I have to add a query arg to to the file specified in the buildUpdateChecker function, I need this because the existing license management is handled in that file.
For context: I'm executing the below code from my main plugin file, without using any hooks as recommended in the getting started section.
Here is the old way of how I send the license_key with the requested file.
`if ( ! function_exists( 'remote_get_info' ) ) { function remote_get_info( $info_url, $license_key, $args = array() ) {
}`
I have tried to add it directly to the url like this:
$myUpdateChecker = PucFactory::buildUpdateChecker( 'link-to-file.php?license_key=' . urlencode( 'the-license-key-value' ), __FILE__, 'my-plugin-slug' );
And I have tried using the addQueryArgFilter function like this:
`$myUpdateChecker->addQueryArgFilter( function ($args) { $args['license_key'] = urlencode( 'the-license-key-value' );
} );`
This might very well just be me not properly understanding the plugin-update-checker. But can someone point me in the correct direction of achieving something similar to what I was doing with the remote_get_info function.