Skip to content

Instantly share code, notes, and snippets.

@stingray82
Created December 2, 2025 23:21
Show Gist options
  • Select an option

  • Save stingray82/8b50498c62dff571eda8945a8ba43112 to your computer and use it in GitHub Desktop.

Select an option

Save stingray82/8b50498c62dff571eda8945a8ba43112 to your computer and use it in GitHub Desktop.
Updated Requests for dplugin updater hotfix
// Add this to the main file
// Disable requests only for devkit/devkit.php.
//add_filter( 'devkit_dpupdatechecker_enable_request_devkit_devkit_php', '__return_false' );
//Then update inc/update.php with this
public function request() {
// 0) Allow disabling / short-circuiting the request via filters.
// Global toggle for all plugins using this updater.
$enabled = apply_filters(
'devkit_dpupdatechecker_enable_request',
true,
$this->slug,
$this
);
// Scoped toggle per plugin slug, e.g. devkit/devkit.php -> devkit_devkit_php.
$filter_slug = str_replace( array( '/', '.', '\\' ), '_', $this->slug );
$enabled = apply_filters(
"devkit_dpupdatechecker_enable_request_{$filter_slug}",
$enabled,
$this->slug,
$this
);
if ( ! $enabled ) {
return false;
}
// 1) Check cache first.
$remote = get_transient( $this->cache_key );
// If we have any cached value (success OR failure) take note.
if ( false !== $remote ) {
if ( ! is_array( $remote ) && ! is_object( $remote ) ) {
$decoded = json_decode( $remote );
if ( json_last_error() === JSON_ERROR_NONE ) {
$remote = $decoded;
}
}
return $remote;
}
// 2) No cache yet – do a live request.
$response = wp_remote_get(
$this->remote_url,
array(
'timeout' => 10,
'headers' => array( 'Accept' => 'application/json' ),
)
);
$code = wp_remote_retrieve_response_code( $response );
$body = wp_remote_retrieve_body( $response );
if (
is_wp_error( $response )
|| 200 !== $code
|| empty( $body )
) {
// Add more details to the error log rather than just "Hoster update check error:".
$debug = array(
'url' => $this->remote_url,
'http_code' => $code,
'body' => $body,
'wp_error' => is_wp_error( $response ) ? $response->get_error_message() : null,
'reason' => (
is_wp_error( $response ) ? 'wp_error' :
( $code !== 200 ? 'non_200_status' :
( empty( $body ) ? 'empty_body' :
'unknown_error' ))
),
);
// Respects which plugin it is being used for i.e. devkit/devkit.php.
error_log( $this->slug . ' Updater error: ' . json_encode( $debug ) );
// Prevent request spam – cache the failure for 1 hour.
set_transient( $this->cache_key, json_encode( array( 'error' => $debug ) ), HOUR_IN_SECONDS );
return false;
}
// 3) Successful response – cache for 6 hours and decode.
set_transient( $this->cache_key, $body, 6 * HOUR_IN_SECONDS );
$remote = json_decode( $body );
if ( json_last_error() !== JSON_ERROR_NONE ) {
// Log bad JSON and treat as failure, but still back off for an hour.
$debug = array(
'url' => $this->remote_url,
'http_code' => $code,
'body' => $body,
'wp_error' => null,
'reason' => 'invalid_json',
);
error_log( $this->slug . ' Updater error: ' . json_encode( $debug ) );
set_transient( $this->cache_key, json_encode( array( 'error' => $debug ) ), HOUR_IN_SECONDS );
return false;
}
return $remote;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment