Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 32 additions & 23 deletions gravity-pdf-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

/**
Expand All @@ -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;
}

Expand All @@ -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 ) {
Expand Down Expand Up @@ -121,15 +130,15 @@ function ( $plugin_file, $plugin_data ) {

printf(
'<tr class="plugin-update-tr %3$s" id="%1$s-update" data-slug="%1$s" data-plugin="%2$s">',
esc_attr( $plugin_data['slug'] ?? '' ),
esc_attr( $plugin_data['plugin'] ?? '' ),
esc_attr( 'gravity-forms-pdf-extended' ),
esc_attr( 'gravity-forms-pdf-extended/pdf.php' ),
'inactive'
);

echo '<td colspan="4" class="plugin-update colspanchange">';
echo '<div class="notice inline notice-warning notice-alt"><p>';

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 '</p></div>';
echo '</td>';
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedCatch"/>
<exclude name="PSR12.Files.FileHeader.IncorrectOrder"/>
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed"/>
<exclude name="Universal.Operators.DisallowShortTernary.Found"/>

<exclude-pattern>/tests/*</exclude-pattern>
</rule>
Expand Down Expand Up @@ -97,6 +98,5 @@
<exclude-pattern>/vendor/*</exclude-pattern>
<exclude-pattern>/vendor_prefixed/*</exclude-pattern>
<exclude-pattern>/node_modules/*</exclude-pattern>
<exclude-pattern>/src/helper/licensing/EDD_SL_Plugin_Updater.php</exclude-pattern>
<exclude-pattern>/.php-scoper/*</exclude-pattern>
</ruleset>
2 changes: 2 additions & 0 deletions src/Controller/Controller_Activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public static function deactivation() {

/* Remove our scheduled tasks */
wp_clear_scheduled_hook( 'gfpdf_cleanup_tmp_dir' );
wp_clear_scheduled_hook( 'gfpdf_network_update_check' );
wp_clear_scheduled_hook( 'gfpdf_bulk_license_check' );

/* Flush caches */
$templates = \GPDFAPI::get_templates_class();
Expand Down
51 changes: 51 additions & 0 deletions src/Controller/Controller_Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,27 @@ public function add_actions() {
* Add AJAX Action Endpoints
*/
add_action( 'wp_ajax_gfpdf_deactivate_license', [ $this->model, 'process_license_deactivation' ] );

/* Schedule License Check for all add-ons */
add_action(
'init',
function () {
if ( empty( $this->data->addon ) ) {
return;
}

if ( $this->misc->is_secondary_network_site( PDF_PLUGIN_BASENAME ) ) {
return;
}

add_action( 'gfpdf_bulk_license_check', [ $this->model, 'licensing_bulk_license_check' ] );
if ( ! wp_next_scheduled( 'gfpdf_bulk_license_check' ) ) {
wp_schedule_single_event( strtotime( '+1 week' ), 'gfpdf_bulk_license_check' );
}
}
);

$this->maybe_schedule_network_update_check();
}

/**
Expand Down Expand Up @@ -200,6 +221,8 @@ public function add_filters() {
/* Register add-ons for licensing page */
add_filter( 'gfpdf_settings_licenses', [ $this->model, 'register_addons_for_licensing' ] );
add_filter( 'gfpdf_settings_license_sanitize', [ $this->model, 'maybe_active_licenses' ] );
add_filter( 'gpdf_sl_plugin_updater_api_params', [ $this->model, 'licensing_bulk_get_version_api_params' ] );
add_filter( 'gpdf_sl_plugin_updater_api_response', [ $this->model, 'licensing_bulk_get_version_api_response' ], 10, 3 );
}

/**
Expand Down Expand Up @@ -284,4 +307,32 @@ public function disable_tools_on_view_cap( $nav ) {

return $nav;
}

/**
* On a Multisite installation where Gravity PDF isn't network/primary site activated,
* add a scheduled task to display an update nag in the network admin on a best-effort basis
*
* @return void
*
* @since 6.16.0
*/
protected function maybe_schedule_network_update_check() {
if ( ! is_multisite() || is_main_site() ) {
return;
}

/* Network-activated installs already receive update checks through the normal flow */
if ( $this->misc->is_secondary_network_site( PDF_PLUGIN_BASENAME ) ) {
return;
}

add_action( 'gfpdf_network_update_check', [ $this->model, 'run_network_update_check' ] );

/* skip if event already scheduled; run_network_update_check() re-arms it each cycle */
if ( wp_next_scheduled( 'gfpdf_network_update_check' ) ) {
return;
}

$this->model->schedule_network_update_check();
}
}
21 changes: 21 additions & 0 deletions src/Controller/Controller_Upgrade_Routines.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public function maybe_run_upgrade( string $old_version, string $current_version
if ( version_compare( $current_version, '6.13.2', '>=' ) && version_compare( $old_version, '6.13.2', '<' ) ) {
$this->fix_tmp_folder_permissions();
}

if ( version_compare( $current_version, '6.16.0', '>=' ) && version_compare( $old_version, '6.16.0', '<' ) ) {
$this->remove_legacy_update_cache();
}
}

/**
Expand Down Expand Up @@ -142,4 +146,21 @@ function ( $current, $key, $iterator ) {
}
}
}

/**
* Remove Gravity PDF's legacy edd_sl_* update cache options left behind by the previous plugin updater
*
* @since 6.16.0
*/
protected function remove_legacy_update_cache() {
global $wpdb;

$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'edd_sl_%' AND option_value LIKE '%gravity-pdf%'" );

/* The failure-backoff option stores a bare timestamp, so the value filter above can't match it — target both
the historical (≤6.14.x) and the 6.15.0 API hosts by exact name. 6.15.0's key was autoloaded, so a site that
ever hit an API failure would otherwise carry a stale autoloaded option forever. */
delete_option( 'edd_sl_failed_http_' . md5( 'https://gravitypdf.com?api=1' ) );
delete_option( 'edd_sl_failed_http_' . md5( GPDF_API_URL ) );
}
}
Loading
Loading