I am trying to update plugins from a dashboard app that will authenticate with connected sites and update plugins.
To do this, I am using the following function on my connected site.
<?php
function dashboard_remote_update() {
header("Content-Type: application/json");
wp_update_plugins();
$plugin_slug = $_GET['plugin'];
$auth = get_field( 'remote_update_auth', 'option');
$get_auth = $_GET['auth'];
$data = array();
if ( $get_auth == $auth ) {
include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
include_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php';
include_once ABSPATH . 'wp-admin/includes/plugin.php';
include_once ABSPATH . 'wp-admin/includes/file.php';
include_once ABSPATH . 'wp-admin/includes/misc.php';
$skin = new WP_Upgrader_Skin();
$upgrader = new Plugin_Upgrader( $skin );
$result = $upgrader->bulk_upgrade( array($plugin_slug) );
$data['result'] = $result;
echo json_encode( $data );
}
die();
}
If I do file_get_contents from the URL of the connected site, it doesn't update the plugin.
Here is the output
{
"result": {
"tracking-code-manager/index.php": {
"errors": {
"copy_failed_ziparchive": [
"Could not copy file."
]
},
"error_data": {
"copy_failed_ziparchive": "tracking-code-manager/autoload.php"
}
}
}
}
However, if directly access the URL from a browser and logged in, it works perfectly.
How can I make it to work without the logged in status?
Update
I was getting the error only on WPEngine hosted sites while not logged in. Other hosts seems to work without problem. Any clue why it's happening on WPEngine?