diff --git a/gravity-pdf-updater.php b/gravity-pdf-updater.php index c615a7fb5..6787b3a98 100644 --- a/gravity-pdf-updater.php +++ b/gravity-pdf-updater.php @@ -25,18 +25,31 @@ add_action( 'init', function () { - new EDD_SL_Plugin_Updater( + $plugin_updater = new EDD_SL_Plugin_Updater( GPDF_API_URL, GPDF_PLUGIN_FILE, [ - 'version' => PDF_EXTENDED_VERSION, - 'item_id' => 137043, - 'license' => md5( site_url() ), - 'author' => 'Blue Liquid Designs', - 'beta' => false, + 'version' => PDF_EXTENDED_VERSION, + 'item_name' => 'Gravity PDF', + 'item_id' => 137043, + 'license' => md5( site_url() ), + 'author' => 'Blue Liquid Designs', + 'beta' => false, + 'wp_override' => current_user_can( 'update_plugins' ) && ! empty( $_GET['force-check'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended ] ); - } + + $plugin_updater->init(); + + /* Only make plugin updater available when fully initialized */ + if ( ! class_exists( 'GPDFAPI' ) ) { + return; + } + + $data = \GPDFAPI::get_data_class(); + $data->updater = $plugin_updater; + }, + 1 ); /** @@ -45,8 +58,8 @@ function () { add_action( 'http_api_debug', function ( $response, $context, $class_object, $parsed_args, $url ) { - /* Log only Gravity PDF requests */ - if ( $url !== GPDF_API_URL ) { + /* Log only Gravity PDF requests. The self-update check posts to a trailingslashit()'d URL, so normalise both sides. */ + if ( untrailingslashit( $url ) !== untrailingslashit( GPDF_API_URL ) ) { return; } @@ -57,27 +70,23 @@ function ( $response, $context, $class_object, $parsed_args, $url ) { $logger = \GPDFAPI::get_log_class(); - $request_body = $parsed_args['body'] ?? []; - if ( isset( $request_body['license'] ) && is_string( $request_body['license'] ) && strlen( $request_body['license'] ) > 2 ) { - /* mask the license key, if exists */ - $license = $request_body['license']; - $request_body['license'] = substr( $license, 0, 1 ) . str_repeat( '*', strlen( $license ) - 2 ) . substr( $license, -1, 1 ); - } - $logger->notice( 'Gravity PDF License Check API Request', [ 'url' => $url, 'method' => $parsed_args['method'] ?? '', - 'body' => $request_body, + 'body' => $parsed_args['body'] ?? [], ] ); - $response_code = wp_remote_retrieve_response_code( $response ); + $response_code = wp_remote_retrieve_response_code( $response ); + $response_body = wp_remote_retrieve_body( $response ); + $response_body_json = json_decode( $response_body, true ); + $response_context = [ 'status' => $response_code, - 'headers' => wp_remote_retrieve_headers( $response ), - 'body' => wp_remote_retrieve_body( $response ), + 'headers' => (array) wp_remote_retrieve_headers( $response ), + 'body' => $response_body_json ?? $response_body, ]; if ( $response_code >= 300 ) { @@ -121,15 +130,15 @@ function ( $plugin_file, $plugin_data ) { printf( '
'; - echo esc_html__( 'This is the non-canonical release of Gravity PDF.', 'gravity-pdf' ); + echo esc_html__( 'This is the non-canonical release of Gravity PDF which can be deleted.', 'gravity-pdf' ); echo '