0

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?

1
  • as per checking your code there ar many events that create error most of the time due to permission so is there way we can connect and fix it thank you
    – yash patel
    Jan 23 at 10:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.