From b2f4cfc9511b3a76512c48f307700533364436e8 Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Thu, 29 May 2025 19:45:26 +0100 Subject: [PATCH 01/19] Re-enabled PHPCS and added fixes for code style. --- plugins/hwp-previews/ACTIONS_AND_FILTERS.md | 2 +- plugins/hwp-previews/composer.json | 197 +++++++++--------- plugins/hwp-previews/hwp-previews.php | 10 +- .../Admin/Settings/Helper/Settings_Group.php | 125 +++++++---- .../Admin/Settings/Helper/Settings_Helper.php | 36 +++- .../src/Admin/Settings/Menu/Menu_Page.php | 2 +- .../src/Admin/Settings/Settings_Section.php | 6 +- .../Settings/Templates/settings-page-main.php | 2 +- .../hwp-previews/src/Admin/Settings_Page.php | 56 +++-- plugins/hwp-previews/src/Autoloader.php | 5 +- .../hwp-previews/src/Hooks/Preview_Hooks.php | 47 +++-- plugins/hwp-previews/src/Plugin.php | 18 +- .../Parameter/Preview_Parameter_Registry.php | 29 +-- 13 files changed, 300 insertions(+), 235 deletions(-) diff --git a/plugins/hwp-previews/ACTIONS_AND_FILTERS.md b/plugins/hwp-previews/ACTIONS_AND_FILTERS.md index 134fbcbf..492fc9e0 100644 --- a/plugins/hwp-previews/ACTIONS_AND_FILTERS.md +++ b/plugins/hwp-previews/ACTIONS_AND_FILTERS.md @@ -16,7 +16,7 @@ - `hwp_previews_settings_group_settings_group` - Filter to modify the settings group name. Default is HWP_PREVIEWS_SETTINGS_GROUP - `hwp_previews_settings_group_settings_config` - Filter to modify the settings array. See `Settings_Group` - `hwp_previews_settings_group_cache_groups` - Filter to modify cache groups for `Settings_Group` -- `hwp_preview_get_post_types_config` - Filter for generating the instance of `Post_Types_Config_Interface` +- `hwp_previews_get_post_types_config` - Filter for generating the instance of `Post_Types_Config_Interface` - `hwp_previews_hooks_post_type_config` - Filter for post type config service for the Hook class - `hwp_previews_hooks_post_status_config` - Filter for post status config service for the Hook class - `hwp_previews_hooks_preview_link_service` - Filter for preview link service for the Hook class diff --git a/plugins/hwp-previews/composer.json b/plugins/hwp-previews/composer.json index c3973645..36e5ed26 100644 --- a/plugins/hwp-previews/composer.json +++ b/plugins/hwp-previews/composer.json @@ -1,106 +1,95 @@ { - "name": "hwp/previews", - "type": "wordpress-plugin", - "description": "A WordPress plugin for headless previews.", - "license": "GPL-3.0-or-later", - "authors": [ - { - "name": "WP Engine Headless OSS Development Team", - "email": "headless-oss@wpengine.com", - "homepage": "https://wpengine.com/" - } - ], - "keywords": [ - "package", - "dependency", - "autoload" - ], - "require": { - "php": "^7.4 || ^8.0" - }, - "minimum-stability": "dev", - "prefer-stable": true, - "require-dev": { - "automattic/vipwpcs": "^3.0", - "dealerdirect/phpcodesniffer-composer-installer": "^1.0", - "humanmade/psalm-plugin-wordpress": "^3.1", - "johnpbloch/wordpress-core": "^6.8", - "phpcompatibility/phpcompatibility-wp": "^2.0", - "phpstan/phpstan-strict-rules": "^2.0", - "slevomat/coding-standard": "^8.0", - "szepeviktor/phpstan-wordpress": "^2.0" - }, - "config": { - "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true, - "phpstan/extension-installer": true - }, - "optimize-autoloader": true, - "platform": { - "php": "7.4" - }, - "preferred-install": "dist", - "sort-packages": true - }, - "extra": { - "phpstan": { - "includes": [ - "phpstan/rules.neon" - ] - } - }, - "archive": { - "exclude": [ - "vendor/", - "phpcs/", - "phpstan/", - ".gitignore", - ".editorconfig", - "composer.json", - "composer.lock", - "*.xml", - "*.dist", - "*.md" - ] - }, - "autoload": { - "psr-4": { - "HWP\\Previews\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "HWP\\Previews\\Unit\\": "tests/unit/", - "HWP\\Previews\\Integration\\": "tests/integration/", - "HWP\\Previews\\PHPStan\\": "phpstan/", - "HWPStandard\\": "phpcs/HWPStandard" - } - }, - "scripts": { - "lint": "vendor/bin/phpcs", - "phpcs-i": [ - "php ./vendor/bin/phpcs -i" - ], - "check-cs": [ - "php ./vendor/bin/phpcs" - ], - "fix-cs": [ - "php ./vendor/bin/phpcbf" - ], - "phpstan": [ - "vendor/bin/phpstan analyze --ansi --memory-limit=1G" - ], - "psalm": [ - "vendor/bin/psalm --no-progress --show-info=false" - ] - }, - "scripts-descriptions": { - }, - "support": { - "docs": "https://github.com/wpengine/hwptoolkit/tree/main/docs", - "email": "headless-oss@wpengine.com", - "forum": "https://github.com/wpengine/hwptoolkit/discussions", - "issues": "https://github.com/wpengine/hwptoolkit/issues?q=is%3Aissue%20state%3Aopen%20label%3Atopic%3Apreviews", - "security": "https://github.com/wpengine/hwptoolkit/blob/main/SECURITY.md" - } + "name": "hwp/previews", + "type": "wordpress-plugin", + "description": "A WordPress plugin for headless previews.", + "license": "GPL-3.0-or-later", + "authors": [ + { + "name": "WP Engine Headless OSS Development Team", + "email": "headless-oss@wpengine.com", + "homepage": "https://wpengine.com/" + } + ], + "keywords": [ + "package", + "dependency", + "autoload" + ], + "require": { + "php": "^7.4 || ^8.0" + }, + "minimum-stability": "dev", + "prefer-stable": true, + "require-dev": { + "automattic/vipwpcs": "^3.0", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "humanmade/psalm-plugin-wordpress": "^3.1", + "johnpbloch/wordpress-core": "^6.8", + "phpcompatibility/phpcompatibility-wp": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", + "slevomat/coding-standard": "^8.0", + "szepeviktor/phpstan-wordpress": "^2.0" + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true, + "phpstan/extension-installer": true + }, + "optimize-autoloader": true, + "platform": { + "php": "7.4" + }, + "preferred-install": "dist", + "sort-packages": true + }, + "extra": { + "phpstan": { + "includes": [ + "phpstan/rules.neon" + ] + } + }, + "archive": { + "exclude": [ + "vendor/", + "phpcs/", + "phpstan/", + ".gitignore", + ".editorconfig", + "composer.json", + "composer.lock", + "*.xml", + "*.dist", + "*.md" + ] + }, + "autoload": { + "psr-4": { + "HWP\\Previews\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "HWP\\Previews\\Unit\\": "tests/unit/", + "HWP\\Previews\\Integration\\": "tests/integration/", + "HWP\\Previews\\PHPStan\\": "phpstan/", + "HWPStandard\\": "phpcs/HWPStandard" + } + }, + "scripts": { + "phpcbf": "./vendor/bin/phpcbf -s", + "phpcs": "./vendor/bin/phpcs", + "phpstan": "./vendor/bin/phpstan analyse --memory-limit=-1", + "phpstan-strict": "./vendor/bin/phpstan analyse --memory-limit=-1 --level=8", + "psalm": "vendor/bin/psalm --no-progress --show-info=false" + }, + "scripts-descriptions": { + }, + "support": { + "docs": "https://github.com/wpengine/hwptoolkit/tree/main/docs", + "email": "headless-oss@wpengine.com", + "forum": "https://github.com/wpengine/hwptoolkit/discussions", + "issues": "https://github.com/wpengine/hwptoolkit/issues?q=is%3Aissue%20state%3Aopen%20label%3Atopic%3Apreviews", + "security": "https://github.com/wpengine/hwptoolkit/blob/main/SECURITY.md" + } } diff --git a/plugins/hwp-previews/hwp-previews.php b/plugins/hwp-previews/hwp-previews.php index f4f16fae..e3ad1775 100644 --- a/plugins/hwp-previews/hwp-previews.php +++ b/plugins/hwp-previews/hwp-previews.php @@ -19,7 +19,7 @@ * @package HWP\Previews */ -declare( strict_types=1 ); +declare(strict_types=1); use HWP\Previews\Plugin; @@ -72,12 +72,6 @@ function hwp_previews_constants(): void { define( 'HWP_PREVIEWS_AUTOLOAD', true ); } - // Text Domain - if ( ! defined( 'HWP_PREVIEWS_TEXT_DOMAIN' ) ) { - define( 'HWP_PREVIEWS_TEXT_DOMAIN', 'hwp-previews' ); - } - - // Plugin config settings group if ( ! defined( 'HWP_PREVIEWS_SETTINGS_GROUP' ) ) { define( 'HWP_PREVIEWS_SETTINGS_GROUP', 'hwp_previews_settings_group' ); } @@ -110,7 +104,7 @@ function hwp_previews_init(): void { add_action( 'admin_notices', - static function () { + static function (): void { ?>

diff --git a/plugins/hwp-previews/src/Admin/Settings/Helper/Settings_Group.php b/plugins/hwp-previews/src/Admin/Settings/Helper/Settings_Group.php index 0ec93dbf..bf01aed0 100644 --- a/plugins/hwp-previews/src/Admin/Settings/Helper/Settings_Group.php +++ b/plugins/hwp-previews/src/Admin/Settings/Helper/Settings_Group.php @@ -1,22 +1,38 @@ $settings_config The settings configuration. + */ protected array $settings_config = []; + /** + * The settings helper instance. + * + * @var \HWP\Previews\Admin\Settings\Helper\Settings_Group|null + */ + protected static $instance = null; + + /** + * Class initializer. + */ public function __construct() { $this->option_key = $this->get_option_key(); $this->settings_group = $this->get_settings_group(); @@ -24,64 +40,72 @@ public function __construct() { $this->set_cache_group(); } - protected function get_option_key(): string { - return apply_filters( 'hwp_previews_settings_group_option_key', HWP_PREVIEWS_SETTINGS_KEY ); - } + /** + * Get Singleton instance of the Settings_Group class. + */ + public static function get_instance(): self { - protected function get_settings_group(): string { - return apply_filters( 'hwp_previews_settings_group_settings_group', HWP_PREVIEWS_SETTINGS_GROUP ); - } + $instance = self::$instance; + + if ( $instance instanceof self ) { + return $instance; + } + + self::$instance = new self(); + return self::$instance; + } + /** + * Setting key for the enabled status. + */ public function get_settings_key_enabled(): string { return 'enabled'; } + /** + * Setting key for unique post slugs. + */ public function get_settings_key_unique_post_slugs(): string { return 'unique_post_slugs'; } + /** + * Setting key for post-statuses as parent. + */ public function get_settings_key_post_statuses_as_parent(): string { return 'post_statuses_as_parent'; } + /** + * Setting key for the preview URL. + */ public function get_settings_key_preview_url(): string { return 'preview_url'; } + /** + * Setting key for is the preview in an iframe. + */ public function get_settings_key_in_iframe(): string { return 'in_iframe'; } + /** + * Gets the settings configuration for the settings group. + * + * @return array The settings configuration. + */ public function get_settings_config(): array { return apply_filters( 'hwp_previews_settings_group_settings_config', [ - $this->get_settings_key_enabled() => 'bool', - $this->get_settings_key_unique_post_slugs() => 'bool', + $this->get_settings_key_enabled() => 'bool', + $this->get_settings_key_unique_post_slugs() => 'bool', $this->get_settings_key_post_statuses_as_parent() => 'bool', - $this->get_settings_key_preview_url() => 'string', - $this->get_settings_key_in_iframe() => 'bool', + $this->get_settings_key_preview_url() => 'string', + $this->get_settings_key_in_iframe() => 'bool', ] ); } - protected function set_cache_group(): void { - $groups = apply_filters( 'hwp_previews_settings_group_cache_groups', [ $this->settings_group ] ); - wp_cache_add_non_persistent_groups( $groups ); - } - - - public static function get_instance(): self { - - $instance = self::$instance; - - if ( $instance instanceof self ) { - return $instance; - } - - self::$instance = new self(); - - return self::$instance; - } - /** * Gets settings from the cache or database. * @@ -105,14 +129,12 @@ public function get_cached_settings(): array { * * @param string $name The setting name. * @param string $post_type The post type slug. - * @param bool $default_value The default value to return if the setting is not found. - * - * @return bool + * @param bool $default_value The default value to return if the setting is not found. */ public function get_post_type_boolean_value( string $name, string $post_type, bool $default_value = false ): bool { $settings = $this->get_cached_settings(); $type = $this->settings_config[ $name ] ?? null; - if ( $type === 'bool' && isset( $settings[ $post_type ][ $name ] ) ) { + if ( 'bool' === $type && isset( $settings[ $post_type ][ $name ] ) ) { return (bool) $settings[ $post_type ][ $name ]; } @@ -125,17 +147,36 @@ public function get_post_type_boolean_value( string $name, string $post_type, bo * @param string $name The setting name. * @param string $post_type The post type slug. * @param string $default_value The default value to return if the setting is not found. - * - * @return string */ public function get_post_type_string_value( string $name, string $post_type, string $default_value = '' ): string { $settings = $this->get_cached_settings(); $type = $this->settings_config[ $name ] ?? null; - if ( $type === 'string' && isset( $settings[ $post_type ][ $name ] ) ) { + if ( 'string' === $type && isset( $settings[ $post_type ][ $name ] ) ) { return (string) $settings[ $post_type ][ $name ]; } return $default_value; } + /** + * Gets the option key for the settings group. + */ + protected function get_option_key(): string { + return apply_filters( 'hwp_previews_settings_group_option_key', HWP_PREVIEWS_SETTINGS_KEY ); + } + + /** + * Gets the settings group name. + */ + protected function get_settings_group(): string { + return apply_filters( 'hwp_previews_settings_group_settings_group', HWP_PREVIEWS_SETTINGS_GROUP ); + } + + /** + * Sets the cache group for the settings. + */ + protected function set_cache_group(): void { + $groups = apply_filters( 'hwp_previews_settings_group_cache_groups', [ $this->settings_group ] ); + wp_cache_add_non_persistent_groups( $groups ); + } } diff --git a/plugins/hwp-previews/src/Admin/Settings/Helper/Settings_Helper.php b/plugins/hwp-previews/src/Admin/Settings/Helper/Settings_Helper.php index e71ec308..d633598c 100644 --- a/plugins/hwp-previews/src/Admin/Settings/Helper/Settings_Helper.php +++ b/plugins/hwp-previews/src/Admin/Settings/Helper/Settings_Helper.php @@ -1,26 +1,36 @@ settings_group = $settings_group; } + /** + * Get an instance of the Settings_Helper class. + * + * @return \HWP\Previews\Admin\Settings\Helper\Settings_Helper + */ public static function get_instance(): self { $instance = self::$instance; @@ -34,7 +44,12 @@ public static function get_instance(): self { return self::$instance; } - public function get_settings_config() : array { + /** + * Get the settings group. + * + * @return array + */ + public function get_settings_config(): array { return $this->settings_group->get_settings_config(); } @@ -64,7 +79,7 @@ public function post_types_enabled( array $default_value = [] ): array { * Get Unique Post Slugs setting value for the given post type. * * @param string $post_type The post type to get the setting for. - * @param bool $default_value The default value to return if the setting is not set. + * @param bool $default_value The default value to return if the setting is not set. */ public function unique_post_slugs( string $post_type, bool $default_value = false ): bool { @@ -77,7 +92,7 @@ public function unique_post_slugs( string $post_type, bool $default_value = fals * Get Post Statuses as Parent setting value for the given post type. * * @param string $post_type The post type to get the setting for. - * @param bool $default_value The default value to return if the setting is not set. + * @param bool $default_value The default value to return if the setting is not set. */ public function post_statuses_as_parent( string $post_type, bool $default_value = false ): bool { $key = $this->settings_group->get_settings_key_post_statuses_as_parent(); @@ -89,7 +104,7 @@ public function post_statuses_as_parent( string $post_type, bool $default_value * Show In iframe value for the given post type. * * @param string $post_type The post type to get the setting for. - * @param bool $default_value The default value to return if the setting is not set. + * @param bool $default_value The default value to return if the setting is not set. */ public function in_iframe( string $post_type, bool $default_value = false ): bool { @@ -109,5 +124,4 @@ public function url_template( string $post_type, string $default_value = '' ): s return $this->settings_group->get_post_type_string_value( $key, $post_type, $default_value ); } - } diff --git a/plugins/hwp-previews/src/Admin/Settings/Menu/Menu_Page.php b/plugins/hwp-previews/src/Admin/Settings/Menu/Menu_Page.php index 68fe515f..b8167c9f 100644 --- a/plugins/hwp-previews/src/Admin/Settings/Menu/Menu_Page.php +++ b/plugins/hwp-previews/src/Admin/Settings/Menu/Menu_Page.php @@ -83,7 +83,7 @@ public function register_page(): void { add_submenu_page( 'options-general.php', $this->page_title, - __($this->menu_title, HWP_PREVIEWS_TEXT_DOMAIN), + $this->menu_title, 'manage_options', $this->menu_slug, [ $this, 'registration_callback' ], diff --git a/plugins/hwp-previews/src/Admin/Settings/Settings_Section.php b/plugins/hwp-previews/src/Admin/Settings/Settings_Section.php index e2a144f5..41f49897 100644 --- a/plugins/hwp-previews/src/Admin/Settings/Settings_Section.php +++ b/plugins/hwp-previews/src/Admin/Settings/Settings_Section.php @@ -36,9 +36,9 @@ class Settings_Section { /** * Constructor. * - * @param string $id Page slug. - * @param string $title Settings section title. - * @param string $page The slug of the settings page. + * @param string $id Page slug. + * @param string $title Settings section title. + * @param string $page The slug of the settings page. * @param array<\HWP\Previews\Admin\Settings\Fields\Abstract_Settings_Field> $fields Array of fields to be registered in the section. */ public function __construct( diff --git a/plugins/hwp-previews/src/Admin/Settings/Templates/settings-page-main.php b/plugins/hwp-previews/src/Admin/Settings/Templates/settings-page-main.php index 5c26957d..ab59c525 100644 --- a/plugins/hwp-previews/src/Admin/Settings/Templates/settings-page-main.php +++ b/plugins/hwp-previews/src/Admin/Settings/Templates/settings-page-main.php @@ -1,6 +1,6 @@ get_public_post_types() ); self::create_settings_page( $post_types )->register_page(); - } ); } + /** + * Registers the settings fields for each post type. + */ public static function register_settings_fields(): void { - add_action( 'admin_init', function (): void { + add_action( 'admin_init', static function (): void { /** * Array of post types where key is the post type slug and value is the label. @@ -74,7 +92,7 @@ public static function register_settings_fields(): void { * Enqueues the JavaScript and the CSS file for the plugin admin area. */ public static function load_scripts_styles(): void { - add_action( 'admin_enqueue_scripts', function ( string $hook ): void { + add_action( 'admin_enqueue_scripts', static function ( string $hook ): void { if ( 'settings_page_' . self::PLUGIN_MENU_SLUG !== $hook ) { return; @@ -104,7 +122,7 @@ public static function load_scripts_styles(): void { */ public static function create_settings_page( array $post_types ): Menu_Page { return new Menu_Page( - __( 'HWP Previews Settings', HWP_PREVIEWS_TEXT_DOMAIN ), + __( 'HWP Previews Settings', 'hwp-previews' ), 'HWP Previews', self::PLUGIN_MENU_SLUG, trailingslashit( HWP_PREVIEWS_TEMPLATE_DIR ) . 'settings-page-main.php', @@ -139,7 +157,7 @@ public static function create_setting_section( string $post_type, string $label * * @param string $post_type The post type slug. * @param string $label The label for the post type. - * @param bool $is_hierarchical Whether the post type is hierarchical. + * @param bool $is_hierarchical Whether the post type is hierarchical. * * @return array<\HWP\Previews\Admin\Settings\Fields\Abstract_Settings_Field> */ @@ -148,33 +166,33 @@ public static function create_settings_fields( string $post_type, string $label, $fields[] = new Checkbox_Field( 'enabled', // translators: %s is the label of the post type. - sprintf( __( 'Enable HWP Previews for %s', HWP_PREVIEWS_TEXT_DOMAIN ), $label ), - __( 'Turn preview functionality on or off for this public post type.', HWP_PREVIEWS_TEXT_DOMAIN ) + sprintf( __( 'Enable HWP Previews for %s', 'hwp-previews' ), $label ), + __( 'Turn preview functionality on or off for this public post type.', 'hwp-previews' ) ); $fields[] = new Checkbox_Field( 'unique_post_slugs', - __( 'Enable unique post slugs for all post statuses', HWP_PREVIEWS_TEXT_DOMAIN ), - __( 'By default WordPress adds unique post slugs to the published posts. This option enforces unique slugs for all post statuses.', HWP_PREVIEWS_TEXT_DOMAIN ) + __( 'Enable unique post slugs for all post statuses', 'hwp-previews' ), + __( 'By default WordPress adds unique post slugs to the published posts. This option enforces unique slugs for all post statuses.', 'hwp-previews' ) ); if ( $is_hierarchical ) { $fields[] = new Checkbox_Field( 'post_statuses_as_parent', - __( 'Allow all post statuses in parents option', HWP_PREVIEWS_TEXT_DOMAIN ), - __( 'By default WordPress only allows published posts to be parents. This option allows posts of all statuses to be used as parent within hierarchical post types.', HWP_PREVIEWS_TEXT_DOMAIN ) + __( 'Allow all post statuses in parents option', 'hwp-previews' ), + __( 'By default WordPress only allows published posts to be parents. This option allows posts of all statuses to be used as parent within hierarchical post types.', 'hwp-previews' ) ); } $fields[] = new Checkbox_Field( 'in_iframe', - sprintf( __( 'Load previews in iframe', HWP_PREVIEWS_TEXT_DOMAIN ), $label ), - __( 'With this option enabled, headless previews will be displayed inside an iframe on the preview page, without leaving WordPress.', HWP_PREVIEWS_TEXT_DOMAIN ) + sprintf( __( 'Load previews in iframe', 'hwp-previews' ), $label ), + __( 'With this option enabled, headless previews will be displayed inside an iframe on the preview page, without leaving WordPress.', 'hwp-previews' ) ); $fields[] = new Text_Input_Field( 'preview_url', // translators: %s is the label of the post type. - sprintf( __( 'Preview URL for %s', HWP_PREVIEWS_TEXT_DOMAIN ), $label ), - __( 'Construct your preview URL using the tags on the right. You can add any parameters needed to support headless previews.', HWP_PREVIEWS_TEXT_DOMAIN ), + sprintf( __( 'Preview URL for %s', 'hwp-previews' ), $label ), + __( 'Construct your preview URL using the tags on the right. You can add any parameters needed to support headless previews.', 'hwp-previews' ), "https://localhost:3000/{$post_type}?preview=true&post_id={ID}&name={slug}", 'code hwp-previews-url' // The class is being used as a query for the JS. ); @@ -202,7 +220,7 @@ public static function create_tabbed_settings( array $post_types ): Tabbed_Setti * Get the current tab for the settings page. * * @param array $post_types The post types to be used in the settings page. - * @param string $tab The name of the tab. + * @param string $tab The name of the tab. */ public static function get_current_tab( $post_types, string $tab = 'tab' ): string { // phpcs:disable WordPress.Security.NonceVerification.Recommended diff --git a/plugins/hwp-previews/src/Autoloader.php b/plugins/hwp-previews/src/Autoloader.php index 7847d037..f23766c1 100644 --- a/plugins/hwp-previews/src/Autoloader.php +++ b/plugins/hwp-previews/src/Autoloader.php @@ -3,10 +3,11 @@ * Includes the composer Autoloader used for packages and classes in the src/ directory. * * @package HWP\Previews + * * @since 0.0.1 */ -declare( strict_types = 1 ); +declare(strict_types=1); namespace HWP\Previews; @@ -75,7 +76,7 @@ protected static function missing_autoloader_notice(): void { /** @psalm-suppress HookNotFound */ add_action( $hook, - static function () use ( $error_message ) { + static function () use ( $error_message ): void { ?>

diff --git a/plugins/hwp-previews/src/Hooks/Preview_Hooks.php b/plugins/hwp-previews/src/Hooks/Preview_Hooks.php index 7a7c0fcd..b21bb84d 100644 --- a/plugins/hwp-previews/src/Hooks/Preview_Hooks.php +++ b/plugins/hwp-previews/src/Hooks/Preview_Hooks.php @@ -1,5 +1,7 @@ + */ public static function get_post_statuses(): array { $post_statuses = [ 'publish', @@ -123,7 +133,7 @@ public static function get_post_statuses(): array { 'draft', 'pending', 'private', - 'auto-draft' + 'auto-draft', ]; return apply_filters( 'hwp_previews_hooks_post_statuses', $post_statuses ); @@ -134,10 +144,10 @@ public static function get_post_statuses(): array { * * @link https://developer.wordpress.org/reference/hooks/wp_insert_post_data/ * - * @param array $data - * @param array $postarr + * @param array $data + * @param array $postarr * - * @return array + * @return array */ public static function enable_unique_post_slug( array $data, array $postarr ): array { $post = new WP_Post( new Post_Data_Model( $data, (int) ( $postarr['ID'] ?? 0 ) ) ); @@ -160,13 +170,13 @@ public static function enable_unique_post_slug( array $data, array $postarr ): a return $data; } - /** * Enable post statuses as parent for the post types specified in the post types config. * - * @param array $args The arguments for the dropdown pages + * @param array $args The arguments for the dropdown pages. + * + * @return array The modified dropdown arguments with post statuses as parent if applicable. * - * @return array The modified dropdown arguments with post statuses as parent if applicable. * @link https://developer.wordpress.org/reference/hooks/page_attributes_dropdown_pages_args/. * * @link https://developer.wordpress.org/reference/hooks/quick_edit_dropdown_pages_args/ @@ -195,9 +205,6 @@ public static function enable_post_statuses_as_parent( array $args ): array { /** * Replace the preview link in the REST response. - * - * @param \WP_REST_Response $response The REST response object. - * @param \WP_Post $post The post object. */ public static function filter_rest_prepare_link( WP_REST_Response $response, WP_Post $post ): WP_REST_Response { if ( self::$settings_helper->in_iframe( $post->post_type ) ) { @@ -244,8 +251,6 @@ public static function add_iframe_preview_template( string $template ): string { $preview_template = $template_resolver->resolve_template_path( $post, $template_dir_path ); if ( empty( $preview_template ) ) { - error_log( 'Preview template not found for post type' . (string) $post->post_type ); - return $template; } @@ -258,8 +263,6 @@ public static function add_iframe_preview_template( string $template ): string { * Enables preview functionality when iframe option is disabled. * * @link https://developer.wordpress.org/reference/hooks/preview_post_link/ - * - * @return void */ public static function update_preview_post_link( string $preview_link, WP_Post $post ): string { diff --git a/plugins/hwp-previews/src/Plugin.php b/plugins/hwp-previews/src/Plugin.php index ad4da209..b4344530 100644 --- a/plugins/hwp-previews/src/Plugin.php +++ b/plugins/hwp-previews/src/Plugin.php @@ -1,13 +1,12 @@ register( - new Preview_Parameter( 'ID', static fn( WP_Post $post ) => (string) $post->ID, __( 'Post ID.', HWP_PREVIEWS_TEXT_DOMAIN ) ) + new Preview_Parameter( 'ID', static fn( WP_Post $post ) => (string) $post->ID, __( 'Post ID.', 'hwp-previews' ) ) )->register( - new Preview_Parameter( 'author_ID', static fn( WP_Post $post ) => $post->post_author, __( 'ID of post author..', HWP_PREVIEWS_TEXT_DOMAIN ) ) + new Preview_Parameter( 'author_ID', static fn( WP_Post $post ) => $post->post_author, __( 'ID of post author..', 'hwp-previews' ) ) )->register( - new Preview_Parameter( 'status', static fn( WP_Post $post ) => $post->post_status, __( 'The post\'s status..', HWP_PREVIEWS_TEXT_DOMAIN ) ) + new Preview_Parameter( 'status', static fn( WP_Post $post ) => $post->post_status, __( 'The post\'s status..', 'hwp-previews' ) ) )->register( - new Preview_Parameter( 'slug', static fn( WP_Post $post ) => $post->post_name, __( 'The post\'s slug.', HWP_PREVIEWS_TEXT_DOMAIN ) ) + new Preview_Parameter( 'slug', static fn( WP_Post $post ) => $post->post_name, __( 'The post\'s slug.', 'hwp-previews' ) ) )->register( - new Preview_Parameter( 'parent_ID', static fn( WP_Post $post ) => (string) $post->post_parent, __( 'ID of a post\'s parent post.', HWP_PREVIEWS_TEXT_DOMAIN ) ) + new Preview_Parameter( 'parent_ID', static fn( WP_Post $post ) => (string) $post->post_parent, __( 'ID of a post\'s parent post.', 'hwp-previews' ) ) )->register( - new Preview_Parameter( 'type', static fn( WP_Post $post ) => $post->post_type, __( 'The post\'s type, like post or page.', HWP_PREVIEWS_TEXT_DOMAIN ) ) + new Preview_Parameter( 'type', static fn( WP_Post $post ) => $post->post_type, __( 'The post\'s type, like post or page.', 'hwp-previews' ) ) )->register( - new Preview_Parameter( 'uri', static fn( WP_Post $post ) => (string) get_page_uri( $post ), __( 'The URI path for a page.', HWP_PREVIEWS_TEXT_DOMAIN ) ) + new Preview_Parameter( 'uri', static fn( WP_Post $post ) => (string) get_page_uri( $post ), __( 'The URI path for a page.', 'hwp-previews' ) ) )->register( - new Preview_Parameter( 'template', static fn( WP_Post $post ) => (string) get_page_template_slug( $post ), __( 'Specific template filename for a given post.', HWP_PREVIEWS_TEXT_DOMAIN ) ) + new Preview_Parameter( 'template', static fn( WP_Post $post ) => (string) get_page_template_slug( $post ), __( 'Specific template filename for a given post.', 'hwp-previews' ) ) ); // Allow users to register/unregister parameters. From adb541b588ba703c3aca33091fed206c3d9caf66 Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Thu, 29 May 2025 19:45:36 +0100 Subject: [PATCH 02/19] Forgot to add missing file. --- .../src/Post/Type/Post_Types_Config_Registry.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plugins/hwp-previews/src/Post/Type/Post_Types_Config_Registry.php b/plugins/hwp-previews/src/Post/Type/Post_Types_Config_Registry.php index f63f7ac8..2eacf296 100644 --- a/plugins/hwp-previews/src/Post/Type/Post_Types_Config_Registry.php +++ b/plugins/hwp-previews/src/Post/Type/Post_Types_Config_Registry.php @@ -1,6 +1,6 @@ set_post_types( Settings_Helper::get_instance()->post_types_enabled() ); - $instance = apply_filters( 'hwp_preview_get_post_types_config', $instance ); + $instance = apply_filters( 'hwp_previews_get_post_types_config', $instance ); self::$instance = $instance; return $instance; } - } From ef194756fc933071c43d9c375b25b5454f43bd41 Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Thu, 29 May 2025 21:05:26 +0100 Subject: [PATCH 03/19] Fixed PHP Psalm errors. --- plugins/hwp-previews/composer.json | 22 +++--------- plugins/hwp-previews/composer.lock | 14 ++++---- plugins/hwp-previews/hwp-previews.php | 9 +++-- plugins/hwp-previews/psalm.xml | 17 +++++++--- .../Admin/Settings/Helper/Settings_Group.php | 4 ++- .../hwp-previews/src/Admin/Settings_Page.php | 16 ++++++--- plugins/hwp-previews/src/Autoloader.php | 2 -- .../hwp-previews/src/Hooks/Preview_Hooks.php | 34 ++++++++++++++++++- .../src/Post/Slug/Post_Slug_Repository.php | 1 + 9 files changed, 78 insertions(+), 41 deletions(-) diff --git a/plugins/hwp-previews/composer.json b/plugins/hwp-previews/composer.json index 993d4d80..3c4d0ae3 100644 --- a/plugins/hwp-previews/composer.json +++ b/plugins/hwp-previews/composer.json @@ -50,7 +50,7 @@ } }, "archive": { - "name": "hwp-previews", + "name": "hwp-previews", "exclude": [ "/.*", "bin", @@ -87,22 +87,10 @@ } }, "scripts": { - "lint": "vendor/bin/phpcs", - "phpcs-i": [ - "php ./vendor/bin/phpcs -i" - ], - "check-cs": [ - "php ./vendor/bin/phpcs" - ], - "fix-cs": [ - "php ./vendor/bin/phpcbf" - ], - "phpstan": [ - "vendor/bin/phpstan analyze --ansi --memory-limit=1G" - ], - "psalm": [ - "vendor/bin/psalm --no-progress --show-info=false" - ] + "phpcbf": "./vendor/bin/phpcbf -s", + "phpcs": "./vendor/bin/phpcs", + "phpstan": "./vendor/bin/phpstan analyse --memory-limit=-1", + "psalm": "./vendor/bin/psalm --no-progress --show-info=false" }, "scripts-descriptions": { }, diff --git a/plugins/hwp-previews/composer.lock b/plugins/hwp-previews/composer.lock index 2aae8e21..bc8be856 100644 --- a/plugins/hwp-previews/composer.lock +++ b/plugins/hwp-previews/composer.lock @@ -1031,16 +1031,16 @@ }, { "name": "php-stubs/wordpress-stubs", - "version": "v6.8.0", + "version": "v6.8.1", "source": { "type": "git", "url": "https://github.com/php-stubs/wordpress-stubs.git", - "reference": "1824db4d1d00d32c0119175d2369d9425dbc4953" + "reference": "92e444847d94f7c30f88c60004648f507688acd5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/1824db4d1d00d32c0119175d2369d9425dbc4953", - "reference": "1824db4d1d00d32c0119175d2369d9425dbc4953", + "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/92e444847d94f7c30f88c60004648f507688acd5", + "reference": "92e444847d94f7c30f88c60004648f507688acd5", "shasum": "" }, "conflict": { @@ -1048,7 +1048,7 @@ }, "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "^1.0", - "nikic/php-parser": "^4.13", + "nikic/php-parser": "^5.4", "php": "^7.4 || ^8.0", "php-stubs/generator": "^0.8.3", "phpdocumentor/reflection-docblock": "^5.4.1", @@ -1076,9 +1076,9 @@ ], "support": { "issues": "https://github.com/php-stubs/wordpress-stubs/issues", - "source": "https://github.com/php-stubs/wordpress-stubs/tree/v6.8.0" + "source": "https://github.com/php-stubs/wordpress-stubs/tree/v6.8.1" }, - "time": "2025-04-17T15:13:53+00:00" + "time": "2025-05-02T12:33:34+00:00" }, { "name": "php-stubs/wp-cli-stubs", diff --git a/plugins/hwp-previews/hwp-previews.php b/plugins/hwp-previews/hwp-previews.php index e3ad1775..0815c7da 100644 --- a/plugins/hwp-previews/hwp-previews.php +++ b/plugins/hwp-previews/hwp-previews.php @@ -21,6 +21,7 @@ declare(strict_types=1); +use HWP\Previews\Autoloader; use HWP\Previews\Plugin; if ( ! defined( 'ABSPATH' ) ) { @@ -29,7 +30,7 @@ // Load the autoloader. require_once __DIR__ . '/src/Autoloader.php'; -if ( ! \HWP\Previews\Autoloader::autoload() ) { +if ( ! Autoloader::autoload() ) { return; } @@ -109,9 +110,7 @@ static function (): void {

@@ -123,4 +122,4 @@ static function (): void { } /** @psalm-suppress HookNotFound */ -add_action( 'plugins_loaded', 'hwp_previews_init', 15 ); +add_action( 'plugins_loaded', 'hwp_previews_init', 15, 0 ); diff --git a/plugins/hwp-previews/psalm.xml b/plugins/hwp-previews/psalm.xml index 97817e2e..768dec2e 100644 --- a/plugins/hwp-previews/psalm.xml +++ b/plugins/hwp-previews/psalm.xml @@ -9,12 +9,21 @@ findUnusedCode="false" > - - - + + + - + + + + + + + + + + diff --git a/plugins/hwp-previews/src/Admin/Settings/Helper/Settings_Group.php b/plugins/hwp-previews/src/Admin/Settings/Helper/Settings_Group.php index bf01aed0..8cbd36c8 100644 --- a/plugins/hwp-previews/src/Admin/Settings/Helper/Settings_Group.php +++ b/plugins/hwp-previews/src/Admin/Settings/Helper/Settings_Group.php @@ -19,7 +19,9 @@ class Settings_Group { protected string $settings_group; /** - * @param array $settings_config The settings configuration. + * The settings configuration. + * + * @var array */ protected array $settings_config = []; diff --git a/plugins/hwp-previews/src/Admin/Settings_Page.php b/plugins/hwp-previews/src/Admin/Settings_Page.php index 6fb1cec3..2fd79d97 100644 --- a/plugins/hwp-previews/src/Admin/Settings_Page.php +++ b/plugins/hwp-previews/src/Admin/Settings_Page.php @@ -51,12 +51,15 @@ public static function init_class_properties(): void { */ public static function register_settings_pages(): void { add_action( 'admin_menu', static function (): void { + + $post_types = ( null === self::$types_config ) ? [] : self::$types_config->get_post_types(); + /** * Array of post types where key is the post type slug and value is the label. * * @var array $post_types */ - $post_types = apply_filters( 'hwp_previews_filter_post_type_setting', self::$types_config->get_public_post_types() ); + $post_types = apply_filters( 'hwp_previews_filter_post_type_setting', $post_types ); self::create_settings_page( $post_types )->register_page(); } ); } @@ -67,12 +70,14 @@ public static function register_settings_pages(): void { public static function register_settings_fields(): void { add_action( 'admin_init', static function (): void { + $post_types = ( null === self::$types_config ) ? [] : self::$types_config->get_public_post_types(); + /** * Array of post types where key is the post type slug and value is the label. * * @var array $post_types */ - $post_types = apply_filters( 'hwp_previews_filter_post_type_setting', self::$types_config->get_public_post_types() ); + $post_types = apply_filters( 'hwp_previews_filter_post_type_setting', $post_types ); /** * Register setting itself. @@ -121,6 +126,10 @@ public static function load_scripts_styles(): void { * @param array $post_types The post types to be used in the settings page. */ public static function create_settings_page( array $post_types ): Menu_Page { + + $descriptions = ( null === self::$parameters ) ? [] : self::$parameters->get_descriptions(); + + return new Menu_Page( __( 'HWP Previews Settings', 'hwp-previews' ), 'HWP Previews', @@ -130,10 +139,9 @@ public static function create_settings_page( array $post_types ): Menu_Page { 'hwp_previews_main_page_config' => [ 'tabs' => $post_types, 'current_tab' => self::get_current_tab( $post_types ), - 'params' => self::$parameters->get_descriptions(), + 'params' => $descriptions, ], ], - 'dashicons-welcome-view-site' ); } diff --git a/plugins/hwp-previews/src/Autoloader.php b/plugins/hwp-previews/src/Autoloader.php index f23766c1..5c8c9501 100644 --- a/plugins/hwp-previews/src/Autoloader.php +++ b/plugins/hwp-previews/src/Autoloader.php @@ -13,8 +13,6 @@ /** * Class - Autoloader - * - * @internal */ class Autoloader { /** diff --git a/plugins/hwp-previews/src/Hooks/Preview_Hooks.php b/plugins/hwp-previews/src/Hooks/Preview_Hooks.php index b21bb84d..640dc79e 100644 --- a/plugins/hwp-previews/src/Hooks/Preview_Hooks.php +++ b/plugins/hwp-previews/src/Hooks/Preview_Hooks.php @@ -61,6 +61,10 @@ public static function init(): void { * Registers the filters and actions for the preview functionality. */ public static function add_filters_actions(): void { + if ( null === self::$types_config ) { + return; + } + // Enable the unique post slug functionality. add_filter( 'wp_insert_post_data', [ self::class, 'enable_unique_post_slug' ], 10, 2 ); @@ -152,6 +156,10 @@ public static function get_post_statuses(): array { public static function enable_unique_post_slug( array $data, array $postarr ): array { $post = new WP_Post( new Post_Data_Model( $data, (int) ( $postarr['ID'] ?? 0 ) ) ); + if ( null === self::$settings_helper || null === self::$types_config || null === self::$statuses_config ) { + return $data; + } + // Check if the correspondent setting is enabled. if ( ! self::$settings_helper->unique_post_slugs( $post->post_type ) ) { return $data; @@ -182,6 +190,11 @@ public static function enable_unique_post_slug( array $data, array $postarr ): a * @link https://developer.wordpress.org/reference/hooks/quick_edit_dropdown_pages_args/ */ public static function enable_post_statuses_as_parent( array $args ): array { + + if ( null === self::$settings_helper || null === self::$types_config || null === self::$statuses_config ) { + return $args; + } + $post_parent_manager = new Post_Parent_Manager( self::$types_config, self::$statuses_config ); if ( empty( $args['post_type'] ) ) { @@ -207,6 +220,10 @@ public static function enable_post_statuses_as_parent( array $args ): array { * Replace the preview link in the REST response. */ public static function filter_rest_prepare_link( WP_REST_Response $response, WP_Post $post ): WP_REST_Response { + if ( null === self::$settings_helper ) { + return $response; + } + if ( self::$settings_helper->in_iframe( $post->post_type ) ) { return $response; } @@ -223,6 +240,12 @@ public static function filter_rest_prepare_link( WP_REST_Response $response, WP_ * Enable preview functionality in iframe. */ public static function add_iframe_preview_template( string $template ): string { + + // Bail out if class not initialized or settings helper and link service are not set. + if ( null === self::$settings_helper || null === self::$link_service || null === self::$types_config || null === self::$statuses_config ) { + return $template; + } + if ( ! is_preview() ) { return $template; } @@ -266,6 +289,11 @@ public static function add_iframe_preview_template( string $template ): string { */ public static function update_preview_post_link( string $preview_link, WP_Post $post ): string { + // Bail out if class not initialized or settings helper and link service are not set. + if ( null === self::$settings_helper || null === self::$link_service ) { + return $preview_link; + } + // @TODO - Need to do more testing and add e2e tests for this filter. // If iframe option is enabled, we need to resolve preview on the template redirect level. @@ -289,10 +317,14 @@ public static function update_preview_post_link( string $preview_link, WP_Post $ * @return string The generated preview URL. */ public static function generate_preview_url( WP_Post $post ): string { + if ( null === self::$settings_helper ) { + return ''; + } + // Check if the correspondent setting is enabled. $url = self::$settings_helper->url_template( $post->post_type ); - if ( empty( $url ) ) { + if ( empty( $url ) || null === self::$link_service ) { return ''; } diff --git a/plugins/hwp-previews/src/Post/Slug/Post_Slug_Repository.php b/plugins/hwp-previews/src/Post/Slug/Post_Slug_Repository.php index 9e20ad88..68c2eeed 100644 --- a/plugins/hwp-previews/src/Post/Slug/Post_Slug_Repository.php +++ b/plugins/hwp-previews/src/Post/Slug/Post_Slug_Repository.php @@ -25,6 +25,7 @@ public function is_slug_taken( string $slug, string $post_type, int $post_id ): */ global $wpdb; + /** @psalm-suppress TooManyArguments */ return (bool) $wpdb->get_var( // phpcs:ignore WordPress.DB $wpdb->prepare( "SELECT post_name FROM {$wpdb->posts} WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1", From 4d398bcb874a49eb759251bf4b36ae28c4f6daeb Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Fri, 30 May 2025 10:48:35 +0100 Subject: [PATCH 04/19] PHPStan errors. --- plugins/hwp-previews/hwp-previews.php | 2 ++ plugins/hwp-previews/phpstan.neon.dist | 5 +++-- .../src/Admin/Settings/Helper/Settings_Helper.php | 7 +++++-- plugins/hwp-previews/src/Admin/Settings_Page.php | 3 +++ plugins/hwp-previews/src/Hooks/Preview_Hooks.php | 2 ++ .../hwp-previews/src/Post/Slug/Post_Slug_Repository.php | 1 + 6 files changed, 16 insertions(+), 4 deletions(-) diff --git a/plugins/hwp-previews/hwp-previews.php b/plugins/hwp-previews/hwp-previews.php index 0815c7da..e33d89de 100644 --- a/plugins/hwp-previews/hwp-previews.php +++ b/plugins/hwp-previews/hwp-previews.php @@ -36,11 +36,13 @@ if ( file_exists( __DIR__ . '/activation.php' ) ) { require_once __DIR__ . '/activation.php'; + // @phpstan-ignore-next-line register_activation_hook( __FILE__, 'hwp_previews_activation_callback' ); } if ( file_exists( __DIR__ . '/deactivation.php' ) ) { require_once __DIR__ . '/deactivation.php'; + // @phpstan-ignore-next-line register_deactivation_hook( __FILE__, 'hwp_previews_deactivation_callback' ); } diff --git a/plugins/hwp-previews/phpstan.neon.dist b/plugins/hwp-previews/phpstan.neon.dist index a14601d5..5681561c 100644 --- a/plugins/hwp-previews/phpstan.neon.dist +++ b/plugins/hwp-previews/phpstan.neon.dist @@ -29,8 +29,9 @@ parameters: max: 80400 paths: - hwp-previews.php - - vendor/autoload.php - src/ ignoreErrors: + - identifier: empty.notAllowed - - identifier: empty.notAllowed + message: '#Constant HWP_PREVIEWS.* not found\.#' + diff --git a/plugins/hwp-previews/src/Admin/Settings/Helper/Settings_Helper.php b/plugins/hwp-previews/src/Admin/Settings/Helper/Settings_Helper.php index d633598c..086f729b 100644 --- a/plugins/hwp-previews/src/Admin/Settings/Helper/Settings_Helper.php +++ b/plugins/hwp-previews/src/Admin/Settings/Helper/Settings_Helper.php @@ -67,12 +67,15 @@ public function post_types_enabled( array $default_value = [] ): array { $enabled_post_types = []; foreach ( $settings as $key => $item ) { - if ( $item[ $enabled_key ] ?? false ) { + if ( (bool) ( $item[ $enabled_key ] ?? false ) ) { $enabled_post_types[] = $key; } } - return $enabled_post_types ?: $default_value; + if ( ! empty( $enabled_post_types ) ) { + return $enabled_post_types; + } + return $default_value; } /** diff --git a/plugins/hwp-previews/src/Admin/Settings_Page.php b/plugins/hwp-previews/src/Admin/Settings_Page.php index 2fd79d97..41d3328d 100644 --- a/plugins/hwp-previews/src/Admin/Settings_Page.php +++ b/plugins/hwp-previews/src/Admin/Settings_Page.php @@ -15,6 +15,9 @@ use HWP\Previews\Preview\Parameter\Preview_Parameter_Registry; class Settings_Page { + /** + * @var string The slug for the plugin menu. + */ public const PLUGIN_MENU_SLUG = 'hwp-previews'; /** diff --git a/plugins/hwp-previews/src/Hooks/Preview_Hooks.php b/plugins/hwp-previews/src/Hooks/Preview_Hooks.php index 640dc79e..0129c3b9 100644 --- a/plugins/hwp-previews/src/Hooks/Preview_Hooks.php +++ b/plugins/hwp-previews/src/Hooks/Preview_Hooks.php @@ -118,7 +118,9 @@ public static function init_class_properties(): void { self::$link_service = apply_filters( 'hwp_previews_hooks_preview_link_service', new Preview_Link_Service( + // @phpstan-ignore-next-line self::$types_config, + // @phpstan-ignore-next-line self::$statuses_config, new Preview_Link_Placeholder_Resolver( Preview_Parameter_Registry::get_instance() ) ) diff --git a/plugins/hwp-previews/src/Post/Slug/Post_Slug_Repository.php b/plugins/hwp-previews/src/Post/Slug/Post_Slug_Repository.php index 68c2eeed..b05ba02c 100644 --- a/plugins/hwp-previews/src/Post/Slug/Post_Slug_Repository.php +++ b/plugins/hwp-previews/src/Post/Slug/Post_Slug_Repository.php @@ -28,6 +28,7 @@ public function is_slug_taken( string $slug, string $post_type, int $post_id ): /** @psalm-suppress TooManyArguments */ return (bool) $wpdb->get_var( // phpcs:ignore WordPress.DB $wpdb->prepare( + // @phpstan-ignore-next-line "SELECT post_name FROM {$wpdb->posts} WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1", $slug, $post_type, From d78fc070fed1d3206aa1be228f944e5fba06adae Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Fri, 30 May 2025 11:08:56 +0100 Subject: [PATCH 05/19] Adding code quality check for a PR. --- .github/workflows/code-quality.yml | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/code-quality.yml diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml new file mode 100644 index 00000000..c091a67e --- /dev/null +++ b/.github/workflows/code-quality.yml @@ -0,0 +1,46 @@ +name: Code Quality + +on: + pull_request: + paths: + - 'plugins/**' + +jobs: + run: + runs-on: ubuntu-latest + name: Check code quality + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Get changed plugin directory + id: plugin + run: | + git fetch --prune --unshallow + plugin=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^plugins/' | head -1 | cut -d/ -f2) + echo "slug=$plugin" >> $GITHUB_OUTPUT + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + tools: composer:v2 + coverage: none + + - name: Install dependencies + uses: ramsey/composer-install@v2 + with: + composer-options: "--no-progress" + + - name: Run PHP CodeSniffer + working-directory: plugins/${{ steps.plugin.outputs.slug }} + run: composer run-script phpcs + + - name: Run PHPStan + working-directory: plugins/${{ steps.plugin.outputs.slug }} + run: composer run-script phpstan + + - name: Run Psalm + working-directory: plugins/${{ steps.plugin.outputs.slug }} + run: composer run-script psalm \ No newline at end of file From 6b93890eae3c4126e4e9bb9411b471483c93f3f9 Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Fri, 30 May 2025 11:12:33 +0100 Subject: [PATCH 06/19] Updating composer commands to match webhooks. Added code quality workflow to run PHPStan, Psalm and PHP Codesniiffer. --- .github/workflows/code-quality.yml | 10 +++++----- plugins/hwp-previews/composer.json | 20 ++++++++++++++++---- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index c091a67e..ee105f91 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -33,14 +33,14 @@ jobs: with: composer-options: "--no-progress" - - name: Run PHP CodeSniffer - working-directory: plugins/${{ steps.plugin.outputs.slug }} - run: composer run-script phpcs - - name: Run PHPStan working-directory: plugins/${{ steps.plugin.outputs.slug }} run: composer run-script phpstan - name: Run Psalm working-directory: plugins/${{ steps.plugin.outputs.slug }} - run: composer run-script psalm \ No newline at end of file + run: composer run-script php:psalm + + - name: Run PHP CodeSniffer + working-directory: plugins/${{ steps.plugin.outputs.slug }} + run: composer run-script check-cs \ No newline at end of file diff --git a/plugins/hwp-previews/composer.json b/plugins/hwp-previews/composer.json index 3c4d0ae3..801bc2bf 100644 --- a/plugins/hwp-previews/composer.json +++ b/plugins/hwp-previews/composer.json @@ -87,10 +87,22 @@ } }, "scripts": { - "phpcbf": "./vendor/bin/phpcbf -s", - "phpcs": "./vendor/bin/phpcs", - "phpstan": "./vendor/bin/phpstan analyse --memory-limit=-1", - "psalm": "./vendor/bin/psalm --no-progress --show-info=false" + "lint": "vendor/bin/phpcs", + "phpcs-i": [ + "php ./vendor/bin/phpcs -i" + ], + "check-cs": [ + "php ./vendor/bin/phpcs" + ], + "fix-cs": [ + "php ./vendor/bin/phpcbf" + ], + "phpstan": [ + "vendor/bin/phpstan analyze --ansi --memory-limit=1G" + ], + "php:psalm": "psalm", + "php:psalm:info": "psalm --show-info=true", + "php:psalm:fix": "psalm --alter" }, "scripts-descriptions": { }, From 5c04e9caef03e2f61176ef58af699f889c622e2a Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Fri, 30 May 2025 11:14:34 +0100 Subject: [PATCH 07/19] Fix working directory for composer install. --- .github/workflows/code-quality.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index ee105f91..5005eccb 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -31,6 +31,7 @@ jobs: - name: Install dependencies uses: ramsey/composer-install@v2 with: + working-directory: plugins/${{ steps.plugin.outputs.slug }} composer-options: "--no-progress" - name: Run PHPStan From ec820921163723f7ab5ca2790d28e1165dad35cd Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Fri, 30 May 2025 11:18:16 +0100 Subject: [PATCH 08/19] Refactor of code quality workflow. --- .github/actions/code-quality/actions.yml | 36 ++++++++++++++++++++++++ .github/workflows/code-quality.yml | 26 ++--------------- 2 files changed, 39 insertions(+), 23 deletions(-) create mode 100644 .github/actions/code-quality/actions.yml diff --git a/.github/actions/code-quality/actions.yml b/.github/actions/code-quality/actions.yml new file mode 100644 index 00000000..d67ff17e --- /dev/null +++ b/.github/actions/code-quality/actions.yml @@ -0,0 +1,36 @@ +name: 'PHP Code Quality' +description: 'Sets up PHP and runs code quality tools' +inputs: + working-directory: + description: 'Directory to run composer and quality tools in' + required: true +runs: + using: "composite" + steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + tools: composer:v2 + coverage: none + + - name: Install dependencies + uses: ramsey/composer-install@v2 + with: + working-directory: ${{ inputs.working-directory }} + composer-options: "--no-progress" + + - name: Run PHPStan + working-directory: ${{ inputs.working-directory }} + run: composer run-script phpstan + shell: bash + + - name: Run Psalm + working-directory: ${{ inputs.working-directory }} + run: composer run-script php:psalm + shell: bash + + - name: Run PHP CodeSniffer + working-directory: ${{ inputs.working-directory }} + run: composer run-script check-cs + shell: bash \ No newline at end of file diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 5005eccb..557d65a5 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -21,27 +21,7 @@ jobs: plugin=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^plugins/' | head -1 | cut -d/ -f2) echo "slug=$plugin" >> $GITHUB_OUTPUT - - name: Setup PHP - uses: shivammathur/setup-php@v2 + - name: PHP Code Quality + uses: ./.github/actions/php-code-quality with: - php-version: '7.4' - tools: composer:v2 - coverage: none - - - name: Install dependencies - uses: ramsey/composer-install@v2 - with: - working-directory: plugins/${{ steps.plugin.outputs.slug }} - composer-options: "--no-progress" - - - name: Run PHPStan - working-directory: plugins/${{ steps.plugin.outputs.slug }} - run: composer run-script phpstan - - - name: Run Psalm - working-directory: plugins/${{ steps.plugin.outputs.slug }} - run: composer run-script php:psalm - - - name: Run PHP CodeSniffer - working-directory: plugins/${{ steps.plugin.outputs.slug }} - run: composer run-script check-cs \ No newline at end of file + working-directory: plugins/${{ steps.plugin.outputs.slug }} \ No newline at end of file From cfffa71ea2c462f5051eff708d4085284f10bfc3 Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Fri, 30 May 2025 11:19:00 +0100 Subject: [PATCH 09/19] Renamed file. --- .github/actions/code-quality/{actions.yml => action.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/actions/code-quality/{actions.yml => action.yml} (100%) diff --git a/.github/actions/code-quality/actions.yml b/.github/actions/code-quality/action.yml similarity index 100% rename from .github/actions/code-quality/actions.yml rename to .github/actions/code-quality/action.yml From edec4b08c0811b829529462239709c082e864091 Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Fri, 30 May 2025 11:20:07 +0100 Subject: [PATCH 10/19] Fixed path for action. --- .github/workflows/code-quality.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 557d65a5..80275d2d 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -22,6 +22,6 @@ jobs: echo "slug=$plugin" >> $GITHUB_OUTPUT - name: PHP Code Quality - uses: ./.github/actions/php-code-quality + uses: ./.github/actions/code-quality with: working-directory: plugins/${{ steps.plugin.outputs.slug }} \ No newline at end of file From d691982f6575997d70ae0a5b70e2d802454f3801 Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Fri, 30 May 2025 11:23:18 +0100 Subject: [PATCH 11/19] Fix for Psalm error. --- plugins/hwp-previews/src/Hooks/Preview_Hooks.php | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/hwp-previews/src/Hooks/Preview_Hooks.php b/plugins/hwp-previews/src/Hooks/Preview_Hooks.php index 0129c3b9..0fc89c18 100644 --- a/plugins/hwp-previews/src/Hooks/Preview_Hooks.php +++ b/plugins/hwp-previews/src/Hooks/Preview_Hooks.php @@ -92,6 +92,7 @@ public static function add_filters_actions(): void { * this must be removed when properly fixed https://github.com/WordPress/gutenberg/issues/13998. */ foreach ( self::$types_config->get_public_post_types() as $key => $label ) { + // @psalm-suppress PossiblyInvalidArgument add_filter( 'rest_prepare_' . $key, [ self::class, 'filter_rest_prepare_link' ], 10, 2 ); } } From 5ffc6ce58d9c328b8c99a4b74d2fc480c74f6e9b Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Fri, 30 May 2025 11:24:46 +0100 Subject: [PATCH 12/19] Psalm fix. --- plugins/hwp-previews/src/Hooks/Preview_Hooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hwp-previews/src/Hooks/Preview_Hooks.php b/plugins/hwp-previews/src/Hooks/Preview_Hooks.php index 0fc89c18..33e778a2 100644 --- a/plugins/hwp-previews/src/Hooks/Preview_Hooks.php +++ b/plugins/hwp-previews/src/Hooks/Preview_Hooks.php @@ -92,7 +92,7 @@ public static function add_filters_actions(): void { * this must be removed when properly fixed https://github.com/WordPress/gutenberg/issues/13998. */ foreach ( self::$types_config->get_public_post_types() as $key => $label ) { - // @psalm-suppress PossiblyInvalidArgument + // @psalm-suppress InvalidArgument add_filter( 'rest_prepare_' . $key, [ self::class, 'filter_rest_prepare_link' ], 10, 2 ); } } From 1277c0ca52866066e489edc37ee0678b2ec0cf87 Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Fri, 30 May 2025 15:04:54 +0100 Subject: [PATCH 13/19] Fix for Psalm. --- plugins/hwp-previews/psalm.xml | 5 +++++ plugins/hwp-previews/src/Hooks/Preview_Hooks.php | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/hwp-previews/psalm.xml b/plugins/hwp-previews/psalm.xml index 768dec2e..3405dd85 100644 --- a/plugins/hwp-previews/psalm.xml +++ b/plugins/hwp-previews/psalm.xml @@ -25,5 +25,10 @@ + + + + + diff --git a/plugins/hwp-previews/src/Hooks/Preview_Hooks.php b/plugins/hwp-previews/src/Hooks/Preview_Hooks.php index 33e778a2..0129c3b9 100644 --- a/plugins/hwp-previews/src/Hooks/Preview_Hooks.php +++ b/plugins/hwp-previews/src/Hooks/Preview_Hooks.php @@ -92,7 +92,6 @@ public static function add_filters_actions(): void { * this must be removed when properly fixed https://github.com/WordPress/gutenberg/issues/13998. */ foreach ( self::$types_config->get_public_post_types() as $key => $label ) { - // @psalm-suppress InvalidArgument add_filter( 'rest_prepare_' . $key, [ self::class, 'filter_rest_prepare_link' ], 10, 2 ); } } From 365401ece490e924611323aa279fe8cfae04b0a7 Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Fri, 30 May 2025 15:15:29 +0100 Subject: [PATCH 14/19] Fix for PHPCS to reduce complexity of defining constants. --- plugins/hwp-previews/hwp-previews.php | 48 +++++++++------------------ 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/plugins/hwp-previews/hwp-previews.php b/plugins/hwp-previews/hwp-previews.php index e33d89de..c389dda1 100644 --- a/plugins/hwp-previews/hwp-previews.php +++ b/plugins/hwp-previews/hwp-previews.php @@ -50,38 +50,22 @@ * Define plugin constants. */ function hwp_previews_constants(): void { - // Plugin version. - if ( ! defined( 'HWP_PREVIEWS_VERSION' ) ) { - define( 'HWP_PREVIEWS_VERSION', '0.0.1' ); - } - - // Plugin Folder Path. - if ( ! defined( 'HWP_PREVIEWS_PLUGIN_DIR' ) ) { - define( 'HWP_PREVIEWS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); - } - - // Plugin Folder URL. - if ( ! defined( 'HWP_PREVIEWS_PLUGIN_URL' ) ) { - define( 'HWP_PREVIEWS_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); - } - - // Plugin Root File. - if ( ! defined( 'HWP_PREVIEWS_PLUGIN_FILE' ) ) { - define( 'HWP_PREVIEWS_PLUGIN_FILE', __FILE__ ); - } - - // Whether to autoload the files or not. - if ( ! defined( 'HWP_PREVIEWS_AUTOLOAD' ) ) { - define( 'HWP_PREVIEWS_AUTOLOAD', true ); - } - - if ( ! defined( 'HWP_PREVIEWS_SETTINGS_GROUP' ) ) { - define( 'HWP_PREVIEWS_SETTINGS_GROUP', 'hwp_previews_settings_group' ); - } - - // Plugin config settings key. - if ( ! defined( 'HWP_PREVIEWS_SETTINGS_KEY' ) ) { - define( 'HWP_PREVIEWS_SETTINGS_KEY', 'hwp_previews_settings' ); + $constants = [ + 'HWP_PREVIEWS_VERSION' => '0.0.1', + 'HWP_PREVIEWS_PLUGIN_DIR' => plugin_dir_path( __FILE__ ), + 'HWP_PREVIEWS_PLUGIN_URL' => plugin_dir_url( __FILE__ ), + 'HWP_PREVIEWS_PLUGIN_FILE' => __FILE__, + 'HWP_PREVIEWS_AUTOLOAD' => true, + 'HWP_PREVIEWS_SETTINGS_GROUP' => 'hwp_previews_settings_group', + 'HWP_PREVIEWS_SETTINGS_KEY' => 'hwp_previews_settings', + ]; + + foreach ( $constants as $name => $value ) { + if ( ! defined( $name ) ) { + // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.VariableConstantNameFound + define( $name, $value ); + // phpcs:enable WordPress.NamingConventions.PrefixAllGlobals.VariableConstantNameFound + } } // Plugin Template Directory. From 414e3050c987c45c1f44a65583829bd0b5d7fab1 Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Fri, 30 May 2025 16:17:20 +0100 Subject: [PATCH 15/19] Added fix for settings page. --- plugins/hwp-previews/hwp-previews.php | 1 - plugins/hwp-previews/src/Admin/Settings_Page.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/hwp-previews/hwp-previews.php b/plugins/hwp-previews/hwp-previews.php index c389dda1..b232a94e 100644 --- a/plugins/hwp-previews/hwp-previews.php +++ b/plugins/hwp-previews/hwp-previews.php @@ -80,7 +80,6 @@ function hwp_previews_constants(): void { function hwp_previews_init(): void { hwp_previews_constants(); - if ( defined( 'HWP_PREVIEWS_PLUGIN_DIR' ) ) { require_once HWP_PREVIEWS_PLUGIN_DIR . 'src/Plugin.php'; Plugin::instance(); diff --git a/plugins/hwp-previews/src/Admin/Settings_Page.php b/plugins/hwp-previews/src/Admin/Settings_Page.php index 41d3328d..382d7598 100644 --- a/plugins/hwp-previews/src/Admin/Settings_Page.php +++ b/plugins/hwp-previews/src/Admin/Settings_Page.php @@ -55,7 +55,7 @@ public static function init_class_properties(): void { public static function register_settings_pages(): void { add_action( 'admin_menu', static function (): void { - $post_types = ( null === self::$types_config ) ? [] : self::$types_config->get_post_types(); + $post_types = ( null === self::$types_config ) ? [] : self::$types_config->get_public_post_types(); /** * Array of post types where key is the post type slug and value is the label. From 4596cf6936a3e1f6b1ea2ccdd63f82dd26285d16 Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Fri, 30 May 2025 16:26:58 +0100 Subject: [PATCH 16/19] Changed method name. --- plugins/hwp-previews/src/Hooks/Preview_Hooks.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/hwp-previews/src/Hooks/Preview_Hooks.php b/plugins/hwp-previews/src/Hooks/Preview_Hooks.php index 0129c3b9..c508b114 100644 --- a/plugins/hwp-previews/src/Hooks/Preview_Hooks.php +++ b/plugins/hwp-previews/src/Hooks/Preview_Hooks.php @@ -54,13 +54,13 @@ class Preview_Hooks { */ public static function init(): void { self::init_class_properties(); - self::add_filters_actions(); + self::add_hook_actions(); } /** - * Registers the filters and actions for the preview functionality. + * Registers the hooks for the preview functionality. */ - public static function add_filters_actions(): void { + public static function add_hook_actions(): void { if ( null === self::$types_config ) { return; } From 7c4bd8592bd322eceecffed4c6ed6173e98c0320 Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Fri, 30 May 2025 16:33:41 +0100 Subject: [PATCH 17/19] Text domain fixes. Thanks @josephfusco --- plugins/hwp-previews/hwp-previews.php | 2 +- plugins/hwp-previews/src/Plugin.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/hwp-previews/hwp-previews.php b/plugins/hwp-previews/hwp-previews.php index b232a94e..f801f96f 100644 --- a/plugins/hwp-previews/hwp-previews.php +++ b/plugins/hwp-previews/hwp-previews.php @@ -95,7 +95,7 @@ static function (): void {

diff --git a/plugins/hwp-previews/src/Plugin.php b/plugins/hwp-previews/src/Plugin.php index b4344530..3bdd7e99 100644 --- a/plugins/hwp-previews/src/Plugin.php +++ b/plugins/hwp-previews/src/Plugin.php @@ -65,7 +65,7 @@ public function setup(): void { */ public function __clone() { // Cloning instances of the class is forbidden. - _doing_it_wrong( __FUNCTION__, esc_html__( 'The plugin Plugin class should not be cloned.', 'hwp-previews' ), esc_attr( HWP_PREVIEWS_VERSION ) ); + _doing_it_wrong( __FUNCTION__, 'The plugin Plugin class should not be cloned.', '0.0.1' ); } /** @@ -75,7 +75,7 @@ public function __clone() { */ public function __wakeup(): void { // De-serializing instances of the class is forbidden. - _doing_it_wrong( __FUNCTION__, esc_html__( 'De-serializing instances of the plugin Main class is not allowed.', 'hwp-previews' ), esc_attr( HWP_PREVIEWS_VERSION ) ); + _doing_it_wrong( __FUNCTION__, 'De-serializing instances of the plugin Main class is not allowed.', '0.0.1' ); } } endif; From 0a6ece6e8b38aafe1c98214c9451b083ed4dc191 Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Fri, 30 May 2025 17:04:21 +0100 Subject: [PATCH 18/19] More fixes for the text domain. --- plugins/hwp-previews/hwp-previews.php | 9 +++++++++ plugins/hwp-previews/src/Autoloader.php | 2 +- .../Parameter/Preview_Parameter_Registry.php | 16 ++++++++-------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/plugins/hwp-previews/hwp-previews.php b/plugins/hwp-previews/hwp-previews.php index f801f96f..fa93991e 100644 --- a/plugins/hwp-previews/hwp-previews.php +++ b/plugins/hwp-previews/hwp-previews.php @@ -58,6 +58,7 @@ function hwp_previews_constants(): void { 'HWP_PREVIEWS_AUTOLOAD' => true, 'HWP_PREVIEWS_SETTINGS_GROUP' => 'hwp_previews_settings_group', 'HWP_PREVIEWS_SETTINGS_KEY' => 'hwp_previews_settings', + 'HWP_PREVIEWS_TEXT_DOMAIN' => 'hwp-previews', ]; foreach ( $constants as $name => $value ) { @@ -106,5 +107,13 @@ static function (): void { ); } +/** + * Load plugin textdomain. + */ +function hwp_previews_load_textdomain(): void { + load_plugin_textdomain( 'hwp-previews', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); +} +add_action( 'init', 'hwp_previews_load_textdomain', 1, 0); + /** @psalm-suppress HookNotFound */ add_action( 'plugins_loaded', 'hwp_previews_init', 15, 0 ); diff --git a/plugins/hwp-previews/src/Autoloader.php b/plugins/hwp-previews/src/Autoloader.php index 5c8c9501..056b1a0a 100644 --- a/plugins/hwp-previews/src/Autoloader.php +++ b/plugins/hwp-previews/src/Autoloader.php @@ -59,7 +59,7 @@ protected static function require_autoloader( string $autoloader_file ): bool { * Displays a notice if the autoloader is missing. */ protected static function missing_autoloader_notice(): void { - $error_message = __( 'HWP Previews: The Composer autoloader was not found. If you installed the plugin from the GitHub source, make sure to run `composer install`.', 'hwp-previews' ); + $error_message = 'HWP Previews: The Composer autoloader was not found. If you installed the plugin from the GitHub source, make sure to run `composer install`.'; if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { error_log( esc_html( $error_message ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- This is a development notice. diff --git a/plugins/hwp-previews/src/Preview/Parameter/Preview_Parameter_Registry.php b/plugins/hwp-previews/src/Preview/Parameter/Preview_Parameter_Registry.php index ba7d8df3..22ae02c7 100644 --- a/plugins/hwp-previews/src/Preview/Parameter/Preview_Parameter_Registry.php +++ b/plugins/hwp-previews/src/Preview/Parameter/Preview_Parameter_Registry.php @@ -50,21 +50,21 @@ public static function get_instance(): self { public static function add_initial_parameters( self $instance ): self { $instance ->register( - new Preview_Parameter( 'ID', static fn( WP_Post $post ) => (string) $post->ID, __( 'Post ID.', 'hwp-previews' ) ) + new Preview_Parameter( 'ID', static fn( WP_Post $post ) => (string) $post->ID, 'Post ID.' ) )->register( - new Preview_Parameter( 'author_ID', static fn( WP_Post $post ) => $post->post_author, __( 'ID of post author..', 'hwp-previews' ) ) + new Preview_Parameter( 'author_ID', static fn( WP_Post $post ) => $post->post_author, 'ID of post author.') )->register( - new Preview_Parameter( 'status', static fn( WP_Post $post ) => $post->post_status, __( 'The post\'s status..', 'hwp-previews' ) ) + new Preview_Parameter( 'status', static fn( WP_Post $post ) => $post->post_status, 'The post status.' ) )->register( - new Preview_Parameter( 'slug', static fn( WP_Post $post ) => $post->post_name, __( 'The post\'s slug.', 'hwp-previews' ) ) + new Preview_Parameter( 'slug', static fn( WP_Post $post ) => $post->post_name, 'The post slug.' ) )->register( - new Preview_Parameter( 'parent_ID', static fn( WP_Post $post ) => (string) $post->post_parent, __( 'ID of a post\'s parent post.', 'hwp-previews' ) ) + new Preview_Parameter( 'parent_ID', static fn( WP_Post $post ) => (string) $post->post_parent, 'ID of a post parent post.' ) )->register( - new Preview_Parameter( 'type', static fn( WP_Post $post ) => $post->post_type, __( 'The post\'s type, like post or page.', 'hwp-previews' ) ) + new Preview_Parameter( 'type', static fn( WP_Post $post ) => $post->post_type, 'The post type, like post or page.' ) )->register( - new Preview_Parameter( 'uri', static fn( WP_Post $post ) => (string) get_page_uri( $post ), __( 'The URI path for a page.', 'hwp-previews' ) ) + new Preview_Parameter( 'uri', static fn( WP_Post $post ) => (string) get_page_uri( $post ), 'The URI path for a page.' ) )->register( - new Preview_Parameter( 'template', static fn( WP_Post $post ) => (string) get_page_template_slug( $post ), __( 'Specific template filename for a given post.', 'hwp-previews' ) ) + new Preview_Parameter( 'template', static fn( WP_Post $post ) => (string) get_page_template_slug( $post ), 'Specific template filename for a given post.' ) ); // Allow users to register/unregister parameters. From d0fda919e42bcd2151c22facb9f434438d1f6ae9 Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Fri, 30 May 2025 17:06:43 +0100 Subject: [PATCH 19/19] Fixed PHP CS errors. --- plugins/hwp-previews/hwp-previews.php | 3 ++- .../src/Preview/Parameter/Preview_Parameter_Registry.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/hwp-previews/hwp-previews.php b/plugins/hwp-previews/hwp-previews.php index fa93991e..f1a428e8 100644 --- a/plugins/hwp-previews/hwp-previews.php +++ b/plugins/hwp-previews/hwp-previews.php @@ -113,7 +113,8 @@ static function (): void { function hwp_previews_load_textdomain(): void { load_plugin_textdomain( 'hwp-previews', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); } -add_action( 'init', 'hwp_previews_load_textdomain', 1, 0); + +add_action( 'init', 'hwp_previews_load_textdomain', 1, 0 ); /** @psalm-suppress HookNotFound */ add_action( 'plugins_loaded', 'hwp_previews_init', 15, 0 ); diff --git a/plugins/hwp-previews/src/Preview/Parameter/Preview_Parameter_Registry.php b/plugins/hwp-previews/src/Preview/Parameter/Preview_Parameter_Registry.php index 22ae02c7..08305b42 100644 --- a/plugins/hwp-previews/src/Preview/Parameter/Preview_Parameter_Registry.php +++ b/plugins/hwp-previews/src/Preview/Parameter/Preview_Parameter_Registry.php @@ -50,9 +50,9 @@ public static function get_instance(): self { public static function add_initial_parameters( self $instance ): self { $instance ->register( - new Preview_Parameter( 'ID', static fn( WP_Post $post ) => (string) $post->ID, 'Post ID.' ) + new Preview_Parameter( 'ID', static fn( WP_Post $post ) => (string) $post->ID, 'Post ID.' ) )->register( - new Preview_Parameter( 'author_ID', static fn( WP_Post $post ) => $post->post_author, 'ID of post author.') + new Preview_Parameter( 'author_ID', static fn( WP_Post $post ) => $post->post_author, 'ID of post author.' ) )->register( new Preview_Parameter( 'status', static fn( WP_Post $post ) => $post->post_status, 'The post status.' ) )->register(