Error while trying to access WordPress API
-
Hello π
I am currently implementing an API that checks for plugin updates in our wordpress instance.
While trying to access the plugin-update API route(https://api.wordpress.org/plugins/update-check/1.1/), i always get a 200 response with a simple string as a body: “error”.Since the API documentation is without any information (it does not even specify what parameters this route needs), i tried using the code wordpress itself uses for the wp_update_plugins() function (https://developer.wordpress.org/reference/functions/wp_update_plugins/). This is what i currently have in my testing environment(local):
$current->last_checked = time(); set_site_transient('update_plugins', $current); $to_send = compact('pluginsForUpdates', 'active'); $locales = array_values(get_available_languages()); $locales = apply_filters('plugins_update_check_locales', $locales); $locales = array_unique($locales); $options = array( 'timeout' => $timeout, 'body' => array( 'plugins' => wp_json_encode($to_send), 'translations' => wp_json_encode($translations), 'locale' => wp_json_encode($locales), 'all' => wp_json_encode(true), ), 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url('/'), ); $url = 'http://api.wordpress.org/plugins/update-check/1.1/'; $http_url = $url; $ssl = wp_http_supports(array('ssl')); if ($ssl) { $url = set_url_scheme($url, 'https'); } $raw_response = wp_remote_post($url, $options); if ($ssl && is_wp_error($raw_response)) { trigger_error( sprintf( /* translators: %s: Support forums URL. */ __('An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.'), __('https://wordpress.org/support/forums/') ) . ' ' . __('(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)'), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE ); $raw_response = wp_remote_post($http_url, $options); } if (is_wp_error($raw_response) || 200 !== wp_remote_retrieve_response_code($raw_response)) { return; } $raw_response = wp_remote_post($url, $options); $response = json_decode(wp_remote_retrieve_body($raw_response), true); if ($response && is_array($response)) { $updates->response = $response['plugins']; $updates->translations = $response['translations']; $updates->no_update = $response['no_update']; } var_dump($updates);I still get a simple “error” response as a body.
Thank you for your help.
- This topic was modified 3 years, 7 months ago by .
- This topic was modified 3 years, 7 months ago by .
The page I need help with: [log in to see the link]
The topic ‘Error while trying to access WordPress API’ is closed to new replies.