I’d like to know if there’s any way to hook into WordPress update process and send $_POST
variable to update server?
I’m delivering plugin/theme updates from private server and I hook into this:
add_filter('pre_set_site_transient_update_themes', 'check_for_update');
which works just fine. Newer version of theme/plugin appears under Dashboard > Updates and I can update. But the problem is – I want users to only be able to download/update if they provided correct login/password (first via add_option()
). Ideally, direct link should never work unless client sends $_POST
with login/password to update.php (the files on update server that will send plugin.ZIP in return).
I’m looking for something like this:
add_filter('updating', 'my_func');
function my_func($request){
$request['login'] = get_option('login');
$request['pass'] = get_option('pass');
return $request;
}
And WordPress, while updating theme/plugin, should send $_POST['login']
and $_POST['pass']
to http://example.com/update.php and update.php should only allow downloading/updating if login matches the one defined there (update.php is the file on update server that sends ZIP package with newer plugin to WordPress).
I hope that it’s clear 🙂
Update & the internal WP HTTP API
A slightly modified version of my answer to this question, but also as a plugin that shows how it could work.
Note: The code is not tested – I don’t know your server setup, etc. – and just written out of my head. You’ll have to test it, find the proper position for merging the arguments and set your URL, etc.
The initial test (#1) could be improved if the custom remote repository sends back usable headers (which isn’t often the case). So if it does, you’re better off using
wp_remote_head()
instead as it makes the HTTP request more lightweight.Good luck. 🙂