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
7 changes: 4 additions & 3 deletions src/Helper/Helper_Interface_Deprecated_Features.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ interface Helper_Interface_Deprecated_Features {
* - `group` (string) Deprecation::GROUP_UNSUPPORTED or Deprecation::GROUP_DEPRECATED
* - `removed_in` (string) The Gravity PDF version the feature is, or will be, removed in
* - `url` (string) Where the upgrade instructions live
* - `detect` (callable) Returns what was found on this site, and an empty array when the feature is unused
* - `detect` (callable) Returns what was found on this site, and an empty array when the feature is unused.
* Optional when `hooks` is declared
*
* A feature the default sentence describes badly declares one more:
*
* - `notice` (string) What becomes of the feature, taking the removal version as `%s`. Read by every
* surface, so it has to make sense with nothing else around it
*
* A feature made up of hooks declares more, so the detector can name the hooks and their replacements:
* A feature made up of hooks declares more. Without a `detect`, it's detected as hook name mapped to listener count:
*
* - `hooks` (array<string, string>) Each removed hook mapped to its replacement, '' when none exists
* - `hooks` (array<string, string>) Each deprecated hook mapped to its replacement, '' when none exists
* - `deprecated_in` (string) Optional. The Gravity PDF version the hooks were deprecated in,
* read by Deprecation::apply_filters() while they still fire
* - `hook_prefix` (string) Optional. Claims any hook starting with it as well, which is
Expand Down
45 changes: 41 additions & 4 deletions src/Statics/Deprecation.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Deprecation {
protected static function get_providers(): array {
return [
Deprecation_V3::class,
Deprecation_Tools_Tab::class,
Deprecation_Hooks::class,
];
}

Expand Down Expand Up @@ -120,7 +120,7 @@ public static function get_signals(): array {
$detected = [];

foreach ( static::get_features() as $feature_key => $feature ) {
$detected[ $feature_key ] = call_user_func( $feature['detect'] );
$detected[ $feature_key ] = static::detect_feature( $feature );
}

static::$signals[ $key ] = array_filter( $detected );
Expand All @@ -129,6 +129,32 @@ public static function get_signals(): array {
return static::$signals[ $key ];
}

/**
* Run a feature's detector, or count the listeners on its hooks when it has none
*
* @param array $feature The feature's registration
*
* @since 6.19.0
*/
protected static function detect_feature( array $feature ): array {
if ( static::is_hook_only( $feature ) ) {
return static::get_hooks_with_listeners( $feature['hooks'], $feature['hook_prefix'] ?? '', $feature['internal_callbacks'] ?? [] );
}

return call_user_func( $feature['detect'] );
}

/**
* Whether a feature is detected purely by the listeners on its hooks
*
* @param array $feature The feature's registration
*
* @since 6.19.0
*/
public static function is_hook_only( array $feature ): bool {
return isset( $feature['hooks'] ) && ! isset( $feature['detect'] );
}

/**
* Forget what the detectors found this request, here and in every provider
*
Expand Down Expand Up @@ -358,12 +384,23 @@ public static function apply_filters( string $hook_name, array $args, string $re
$replacement,
$removed_in === '' ? '' : sprintf(
/* translators: %s: The Gravity PDF version the filter is removed in */
esc_html__( 'This filter is removed in Gravity PDF %s.', 'gravity-pdf' ),
esc_html__( 'This hook is removed in Gravity PDF %s.', 'gravity-pdf' ),
$removed_in
)
);
}

/**
* Fire one of the deprecated actions, warning any third party still listening to it
*
* @param string $hook_name The deprecated action to fire
*
* @since 6.19.0
*/
public static function do_action( string $hook_name ): void {
static::apply_filters( $hook_name, [ '' ] );
}

/**
* Whether anything worth reporting is listening to a deprecated hook
*
Expand Down Expand Up @@ -453,7 +490,7 @@ protected static function log_deprecated_filter( string $hook_name, string $repl

$log->warning(
sprintf(
'The %1$s filter has a third-party listener attached%2$s.%3$s',
'The %1$s hook has a third-party listener attached%2$s.%3$s',
$hook_name,
$removed_in !== '' ? sprintf( ' and is removed in Gravity PDF %s', $removed_in ) : '',
$replacement !== '' ? sprintf( ' Use the %s filter instead.', $replacement ) : ''
Expand Down
62 changes: 62 additions & 0 deletions src/Statics/Deprecation_Hooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare( strict_types=1 );

namespace GFPDF\Statics;

use GFPDF\Helper\Helper_Interface_Deprecated_Features;

/**
* @package Gravity PDF
* @copyright Copyright (c) 2026, Blue Liquid Designs
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
*/

/* Exit if accessed directly */
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* Removals that leave nothing behind but the hooks they fired
*
* @since 6.19.0
*/
class Deprecation_Hooks implements Helper_Interface_Deprecated_Features {

/**
* @inheritDoc
* @since 6.19.0
*/
public static function get_features(): array {
return [
'tools_tab_hooks' => [
'label' => __( 'Tools Tab Actions and Filters', 'gravity-pdf' ),
'group' => Deprecation::GROUP_DEPRECATED,
'deprecated_in' => '6.19.0',
'removed_in' => '7.0',
'url' => 'https://docs.gravitypdf.com/developers/filters/gfpdf_settings_tools/',
/* translators: %s: The Gravity PDF version the Tools tab hooks stop running in */
'notice' => __( 'Settings a plugin or custom code added to the Gravity PDF Tools tab now appear at the bottom of the General tab and will be removed in version %s. Ask your developer to update the code.', 'gravity-pdf' ),
'hooks' => [
'gfpdf_settings_tools' => 'gfpdf_settings_general',
'gfpdf_post_tools_settings_page' => 'gfpdf_post_general_settings_page',
],
],
];
}

/**
* @inheritDoc
* @since 6.19.0
*/
public static function get_stored_options(): array {
return [];
}

/**
* @inheritDoc
* @since 6.19.0
*/
public static function flush_cache(): void {}
}
88 changes: 0 additions & 88 deletions src/Statics/Deprecation_Tools_Tab.php

This file was deleted.

6 changes: 3 additions & 3 deletions src/Statics/Deprecation_V3.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ public static function get_features(): array {
'group' => Deprecation::GROUP_UNSUPPORTED,
'removed_in' => static::REMOVED_IN,
'url' => 'https://docs.gravitypdf.com/upgrade/deprecated-filters/',
'detect' => [ static::class, 'get_active_deprecated_filters' ],
/* The label is a category, so out of its report row the fallback would read as the whole hook API */
/* translators: %s: The Gravity PDF version the hooks were removed in */
'notice' => __( 'Custom code on this site uses Gravity PDF hooks that were removed in version %s and has stopped running. Update it to use the current hooks.', 'gravity-pdf' ),
Expand Down Expand Up @@ -175,12 +174,13 @@ protected static function get_deprecated_filters(): array {
/**
* Get the removed v3 hooks that still have a listener attached
*
* Nothing in core registers on these any more, so every callback found is third party.
*
* @return array<string, int> Hook name mapped to the number of listeners
* @since 6.17.0
* @deprecated 6.19.0 Read `deprecated_filters` from Deprecation::get_signals()
*/
public static function get_active_deprecated_filters(): array {
_deprecated_function( __METHOD__, '6.19.0', Deprecation::class . '::get_signals()' );

return Deprecation::get_hooks_with_listeners( static::get_deprecated_filters(), static::HOOK_PREFIX );
}

Expand Down
21 changes: 21 additions & 0 deletions src/View/View_Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use GFPDF\Helper\Helper_Misc;
use GFPDF\Helper\Helper_Options_Fields;
use GFPDF\Helper\Helper_Templates;
use GFPDF\Statics\Deprecation;
use GFPDF_Major_Compatibility_Checks;
use GFPDF_Vendor\Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -270,6 +271,26 @@ public function general() {
},
];

if ( $vars['edit_cap'] ) {
$this->options->register_settings( [ 'tools' => Deprecation::apply_filters( 'gfpdf_settings_tools', [ [] ] ) ] );
}

if ( $markup->get_section_fields( 'gfpdf_settings_tools' ) !== [] ) {
$tools_section = [
'id' => 'gfpdf_settings_tools',
'width' => 'full',
'title' => __( 'Tools', 'gravity-pdf' ),
'callback' => static function () use ( $markup ) {
$markup->output_settings_fields( 'gfpdf_settings_tools', $markup::ENABLE_PANEL_TITLE );
},
'content_class' => 'gform_settings_form',
];

$vars['tools_callback'] = static function () use ( $markup, $tools_section ) {
$markup->fieldset( $tools_section, true );
};
}

/* load the system status view */
$this->load( 'general', $vars );
}
Expand Down
17 changes: 9 additions & 8 deletions src/View/View_System_Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,13 @@ public function get_deprecated_feature( string $key, array $signal ): array {
$feature = Deprecation::get_feature( $key );
$descriptions = $this->get_deprecated_feature_descriptions();

$description = isset( $descriptions[ $key ] )
? call_user_func( $descriptions[ $key ], $signal, $feature )
: $this->get_default_feature_description( $signal );
if ( isset( $descriptions[ $key ] ) ) {
$description = call_user_func( $descriptions[ $key ], $signal, $feature );
} elseif ( Deprecation::is_hook_only( $feature ) ) {
$description = $this->get_deprecated_filter_feature( $signal );
} else {
$description = $this->get_default_feature_description( $signal );
}

/* Whatever the description leaves out, the feature's own registration answers */
return $description + [
Expand All @@ -201,8 +205,7 @@ public function get_deprecated_feature( string $key, array $signal ): array {
/**
* The method that describes each feature's detections, keyed by the feature it describes
*
* A feature with no entry here is described generically, so a newly registered one reports something usable
* before it has copy of its own.
* A feature with no entry here is described by its listener counts if it's hook-only, otherwise generically.
*
* @return array<string, callable>
* @since 6.17.0
Expand All @@ -212,8 +215,6 @@ protected function get_deprecated_feature_descriptions(): array {
'legacy_templates' => [ $this, 'get_legacy_templates_feature' ],
'business_plus_templates' => [ $this, 'get_legacy_templates_feature' ],
'legacy_endpoint' => [ $this, 'get_legacy_endpoint_feature' ],
'deprecated_filters' => [ $this, 'get_deprecated_filter_feature' ],
'tools_tab_hooks' => [ $this, 'get_deprecated_filter_feature' ],
];
}

Expand Down Expand Up @@ -315,7 +316,7 @@ static function ( $form_id ) {
}

/**
* Describe the removed hooks that still have a listener attached
* Describe the deprecated hooks that still have a listener attached
*
* @param array $filters Hook name mapped to the number of listeners
*
Expand Down
12 changes: 12 additions & 0 deletions src/View/html/Settings/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,16 @@
/* See https://docs.gravitypdf.com/developers/actions/gfpdf_post_general_settings_page for more details about this action */
do_action( 'gfpdf_post_general_settings_page' );
?>

<?php if ( $args['edit_cap'] ): ?>
<?php if ( isset( $args['tools_callback'] ) ): ?>
<?php /* Posts to this page, not options.php: these fields aren't saved settings */ ?>
<form name="gfpdf-settings-form-<?php echo esc_attr( wp_rand() ); ?>" method="post" class="gform_settings_form gforms_edit_form">
<?php settings_fields( 'gfpdf_settings' ); ?>
<?php call_user_func( $args['tools_callback'] ); ?>
</form>
<?php endif; ?>

<?php \GFPDF\Statics\Deprecation::do_action( 'gfpdf_post_tools_settings_page' ); ?>
<?php endif; ?>
</div>
Loading