0

i have a curios problem what i cannot fix.

On the plugin mainfile i defined:

add_filter('pre_set_site_transient_update_plugins', array('moreads_update','check_4_updates'));
add_filter('plugins_api', array('moreads_update','plugin_api_info'),10,3);

The Class Functions:

static public function check_4_updates($checkdata) {
    global $wp_version;

    //var_dump($checkdata);return $checkdata;

    $options = get_option(MABASENAME);
    $options = is_serialized($options) ? unserialize($options) : $options;
    if (empty($checkdata->checked)) {return $checkdata;}
    $args = array(
        'slug' => MASLUG,
        'version' => @$checkdata->checked[MASLUG]
    );
    $request_post = array(
        'body' => array(
            'action' => 'plugin_update_check',
            'token' => !empty($options['token']) ? trim($options['token']) : '',
            'domain' => !empty($options['domain']) ? trim($options['domain']) : '',
            'request' => serialize($args)
        ),
        'user-agent' => 'WordPress/'.$wp_version.'; '.get_bloginfo('url')
    );
    $raw_response = wp_remote_post('http://api.domain.tld/',$request_post);
    $response = false;
    if (!is_wp_error($raw_response) && ($raw_response['response']['code'] == 200)) {
        $response = is_serialized($raw_response['body']) ? unserialize($raw_response['body']) : $raw_response['body'];
    }
    if (!empty($response)) {
        if(strpos(@$response->package, self::$_apiurl) !== false) { // Only API Domain for Update Server allowed
            @$checkdata->response[MASLUG] = $response;
        }
    }
    return $checkdata;
}
static public function plugin_api_info($def, $action, $args) {
    global $wp_version;

    if (!isset($args->slug) || ($args->slug != MASLUG)) {
        return false;
    }

    $options = get_option(MABASENAME);
    $options = is_serialized($options) ? unserialize($options) : $options;
    $plugin_info = get_site_transient('update_plugins');
    $current_version = @$plugin_info->checked[MASLUG];
    $args->version = $current_version;

    $request_post = array(
        'body' => array(
            'action' => $action,
            'token' => !empty($options['token']) ? trim($options['token']) : '',
            'domain' => !empty($options['domain']) ? trim($options['domain']) : '',
            'request' => serialize($args)
        ),
        'user-agent' => 'WordPress/'.$wp_version.'; '.get_bloginfo('url')
    );
    $response = wp_remote_post('http://api.domain.tld/',$request_post);
    if (is_wp_error($response)) {
        $res = new WP_Error('plugins_api_failed', __('An unknown error occured while connecting the plugin-API.').'</p><p><a href="?" onclick="document.location.reload();return false;">'.__('Try again?').'</a>', $response->get_error_message());
    } else {
        $res = unserialize($response['body']);
        if ($res === false) {
            $res = new WP_Error('plugins_api_failed', __('Unknown error.'), $response['body']);
        }
    }
    return $res;
}

The API returned follow objects:

Update:
$erg->slug,
$erg->package,
$erg->new_version,

Plugin-Info:
$erg->slug=array(
    'homepage',
    'name',
    'version',
    'author',
    'last_updated',
    'external',
    'requires',
    'tested',
    'downloaded',
    'package',
    'download_link',
    'sections' => array(
        'description',
        'change_log',
        'other_notes'
    )
);

On the single blog all works fine. If i set a new version, the update will shown on Wordpress Update Page.

But on a multisite Blog i see nothings. I have tried only in one blog on multisite, networkwide and also activate into the first blog, no update available.

If i will check it with

set_site_transient('update_plugins', null);
add_filter('plugins_api_result',function($res,$action,$args){print_r(array($res,$action,$args));return $res;});

my update routine "check_4_updates()" will not call on multisite!

What are happend here, what's wrong?

Thanks, Stefan

0

Ok, the problem was, that the token / domain on Multisite was empty and the API returns NULL.

Have anyone an idea, how i can inspect the Request / Response with this API Calls over WordPress Updates?

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.