From 57d4d1f46907342fa6c1ef42978bbe3ae180f0c7 Mon Sep 17 00:00:00 2001 From: Akshit Sethi Date: Mon, 25 Apr 2022 15:50:28 +0530 Subject: [PATCH 01/11] Added Settings UI for the plugin utilising Settings API --- config.php | 2 + includes/ConvertToBlocks/Plugin.php | 1 + includes/ConvertToBlocks/Settings.php | 221 ++++++++++++++++++++++++++ 3 files changed, 224 insertions(+) create mode 100644 includes/ConvertToBlocks/Settings.php diff --git a/config.php b/config.php index b101817..52a2608 100644 --- a/config.php +++ b/config.php @@ -17,6 +17,8 @@ convert_to_blocks_define( 'CONVERT_TO_BLOCKS_VERSION', $plugin_version ); convert_to_blocks_define( 'CONVERT_TO_BLOCKS_DIR', plugin_dir_path( __FILE__ ) ); convert_to_blocks_define( 'CONVERT_TO_BLOCKS_URL', plugin_dir_url( __FILE__ ) ); +convert_to_blocks_define( 'CONVERT_TO_BLOCKS_SLUG', 'convert-to-blocks' ); +convert_to_blocks_define( 'CONVERT_TO_BLOCKS_PREFIX', 'convert_to_blocks' ); /* Labels */ diff --git a/includes/ConvertToBlocks/Plugin.php b/includes/ConvertToBlocks/Plugin.php index 446be68..06428ed 100644 --- a/includes/ConvertToBlocks/Plugin.php +++ b/includes/ConvertToBlocks/Plugin.php @@ -101,6 +101,7 @@ public function init() { $this->register_objects( [ new RESTSupport(), + new Settings(), ] ); } diff --git a/includes/ConvertToBlocks/Settings.php b/includes/ConvertToBlocks/Settings.php new file mode 100644 index 0000000..75ee3e6 --- /dev/null +++ b/includes/ConvertToBlocks/Settings.php @@ -0,0 +1,221 @@ +init(); + + add_action( 'admin_menu', [ $this, 'add_menu' ] ); + add_action( 'admin_init', [ $this, 'register_section' ], 10 ); + add_action( 'admin_init', [ $this, 'register_fields' ], 20 ); + } + + /** + * Only registers on admin context. + */ + public function can_register() { + return is_admin(); + } + + /** + * Configures variables and fetches post types. + * + * @return void + */ + public function init() { + // Configure variables. + $this->settings_page = sprintf( $this->settings_page, CONVERT_TO_BLOCKS_SLUG ); + $this->settings_section = sprintf( $this->settings_section, CONVERT_TO_BLOCKS_SLUG ); + $this->settings_group = sprintf( $this->settings_group, CONVERT_TO_BLOCKS_PREFIX ); + + // Get post types. + $this->post_types = $this->get_post_types(); + } + + /** + * Retrieves all public post types. + * + * @return array + */ + public function get_post_types() { + $post_types = get_post_types( + [ 'public' => true ] + ); + + if ( ! empty( $post_types['attachment'] ) ) { + unset( $post_types['attachment'] ); + } + + return $post_types; + } + + /** + * Adds a submenu item for the `Settings` menu. + * + * @return void + */ + public function add_menu() { + add_options_page( + esc_html__( 'Convert to Blocks', 'convert-to-blocks' ), + esc_html__( 'Convert to Blocks', 'convert-to-blocks' ), + $this->capability, + CONVERT_TO_BLOCKS_SLUG, + [ $this, 'settings_page' ] + ); + } + + /** + * Registers the settings page. + * + * @return void + */ + public function settings_page() { + ?> +
+

+ +

+
+ +

+ +

+ +
+ settings_group ); + do_settings_sections( CONVERT_TO_BLOCKS_SLUG ); + submit_button(); + ?> +
+
+ settings_section, + '', + '', + CONVERT_TO_BLOCKS_SLUG + ); + } + + /** + * Registers setting fields. + * + * @return void + */ + public function register_fields() { + // Supported post types. + add_settings_field( + sprintf( '%s_post_types', CONVERT_TO_BLOCKS_PREFIX ), + esc_html__( 'Supported Post Types', 'convert-to-blocks' ), + [ $this, 'field_post_types' ], + CONVERT_TO_BLOCKS_SLUG, + $this->settings_section, + [ + 'label_for' => sprintf( '%s_post_types', CONVERT_TO_BLOCKS_PREFIX ), + ] + ); + + register_setting( + $this->settings_group, + sprintf( '%s_post_types', CONVERT_TO_BLOCKS_PREFIX ), + [ + 'sanitize_callback' => [ $this, 'sanitize_post_types' ], + ] + ); + } + + /** + * Renders the post_types field. + * + * @return void + */ + public function field_post_types() { + $post_types = get_option( sprintf( '%s_post_types', CONVERT_TO_BLOCKS_PREFIX ), [] ); + + echo '
'; + foreach ( $this->post_types as $post_type ) { + printf( + '
', + sprintf( '%s_post_types', esc_attr( CONVERT_TO_BLOCKS_PREFIX ) ), + checked( in_array( $post_type, $post_types, true ), 1, false ), + esc_attr( $post_type ), + esc_attr( ucfirst( $post_type ) ) + ); + } + echo '
'; + } + + /** + * Sanitizes post_types values. + * + * @param array $input Array containing checked values. + * + * @return array Sanitized array. + */ + public function sanitize_post_types( $input ) { + if ( ! is_array( $input ) ) { + return []; + } + + return array_map( 'sanitize_text_field', $input ); + } + +} From 7f4c3ec4f5a70ac2d3e8e7f3cc51e620f773a33b Mon Sep 17 00:00:00 2001 From: Akshit Sethi Date: Mon, 25 Apr 2022 16:51:39 +0530 Subject: [PATCH 02/11] Add phpunit-polyfills to enable running unit tests --- composer.json | 8 ++++++- composer.lock | 65 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 4a6cf7c..8320062 100644 --- a/composer.json +++ b/composer.json @@ -21,12 +21,18 @@ }, "require-dev": { "phpunit/phpunit": "~7.5.0", - "10up/phpcs-composer": "dev-master" + "10up/phpcs-composer": "dev-master", + "yoast/phpunit-polyfills": "^1.0" }, "scripts": { "lint": "phpcs .", "lint-fix": "phpcbf .", "test": "phpunit", "setup-local-tests": "bash bin/install-wp-tests.sh convert_to_blocks_test root password mysql trunk" + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } } } diff --git a/composer.lock b/composer.lock index ccdcfaa..5eeb5b4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1f24cca40831949ecee93ccde21b0fc2", + "content-hash": "22c0509918945d9eda56aa8fc0b55f7b", "packages": [], "packages-dev": [ { @@ -2013,6 +2013,67 @@ "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki" }, "time": "2020-05-13T23:57:56+00:00" + }, + { + "name": "yoast/phpunit-polyfills", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/Yoast/PHPUnit-Polyfills.git", + "reference": "5ea3536428944955f969bc764bbe09738e151ada" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Yoast/PHPUnit-Polyfills/zipball/5ea3536428944955f969bc764bbe09738e151ada", + "reference": "5ea3536428944955f969bc764bbe09738e151ada", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + }, + "require-dev": { + "yoast/yoastcs": "^2.2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "autoload": { + "files": [ + "phpunitpolyfills-autoload.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Team Yoast", + "email": "support@yoast.com", + "homepage": "https://yoast.com" + }, + { + "name": "Contributors", + "homepage": "https://github.com/Yoast/PHPUnit-Polyfills/graphs/contributors" + } + ], + "description": "Set of polyfills for changed PHPUnit functionality to allow for creating PHPUnit cross-version compatible tests", + "homepage": "https://github.com/Yoast/PHPUnit-Polyfills", + "keywords": [ + "phpunit", + "polyfill", + "testing" + ], + "support": { + "issues": "https://github.com/Yoast/PHPUnit-Polyfills/issues", + "source": "https://github.com/Yoast/PHPUnit-Polyfills" + }, + "time": "2021-11-23T01:37:03+00:00" } ], "aliases": [], @@ -2026,5 +2087,5 @@ "php": ">=7.2" }, "platform-dev": [], - "plugin-api-version": "2.0.0" + "plugin-api-version": "2.1.0" } From 54414385eb6174f9697426724f0b4f1650307c3e Mon Sep 17 00:00:00 2001 From: Akshit Sethi Date: Mon, 25 Apr 2022 17:04:02 +0530 Subject: [PATCH 03/11] Improvements to variables and checkbox rendering --- includes/ConvertToBlocks/Settings.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/includes/ConvertToBlocks/Settings.php b/includes/ConvertToBlocks/Settings.php index 75ee3e6..014b10e 100644 --- a/includes/ConvertToBlocks/Settings.php +++ b/includes/ConvertToBlocks/Settings.php @@ -24,21 +24,21 @@ class Settings { * * @var string */ - private $settings_page = '%s-settings-page'; + private $settings_page = 'settings-page'; /** * Settings section name. * * @var string */ - private $settings_section = '%s-settings-section'; + private $settings_section = 'settings-section'; /** * Settings group name. * * @var string */ - private $settings_group = '%s_settings'; + private $settings_group = 'settings'; /** * Post types. @@ -73,9 +73,9 @@ public function can_register() { */ public function init() { // Configure variables. - $this->settings_page = sprintf( $this->settings_page, CONVERT_TO_BLOCKS_SLUG ); - $this->settings_section = sprintf( $this->settings_section, CONVERT_TO_BLOCKS_SLUG ); - $this->settings_group = sprintf( $this->settings_group, CONVERT_TO_BLOCKS_PREFIX ); + $this->settings_page = sprintf( '%s-%s', CONVERT_TO_BLOCKS_SLUG, $this->settings_page ); + $this->settings_section = sprintf( '%s-%s', CONVERT_TO_BLOCKS_SLUG, $this->settings_section ); + $this->settings_group = sprintf( '%s_%s', CONVERT_TO_BLOCKS_PREFIX, $this->settings_group ); // Get post types. $this->post_types = $this->get_post_types(); @@ -193,7 +193,8 @@ public function field_post_types() { echo '
'; foreach ( $this->post_types as $post_type ) { printf( - '
', + '
', + sprintf( '%s_post_types_%s', esc_attr( CONVERT_TO_BLOCKS_PREFIX ), esc_attr( $post_type ) ), sprintf( '%s_post_types', esc_attr( CONVERT_TO_BLOCKS_PREFIX ) ), checked( in_array( $post_type, $post_types, true ), 1, false ), esc_attr( $post_type ), From b8ed9f30a9ca76edc967910320f32d91c4fe3e9d Mon Sep 17 00:00:00 2001 From: Akshit Sethi Date: Tue, 10 May 2022 13:40:48 +0530 Subject: [PATCH 04/11] Add filter to configure supported post types --- config.php | 1 - includes/ConvertToBlocks/Settings.php | 58 +++++++++++++++++++++------ 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/config.php b/config.php index 52a2608..7308516 100644 --- a/config.php +++ b/config.php @@ -18,7 +18,6 @@ convert_to_blocks_define( 'CONVERT_TO_BLOCKS_DIR', plugin_dir_path( __FILE__ ) ); convert_to_blocks_define( 'CONVERT_TO_BLOCKS_URL', plugin_dir_url( __FILE__ ) ); convert_to_blocks_define( 'CONVERT_TO_BLOCKS_SLUG', 'convert-to-blocks' ); -convert_to_blocks_define( 'CONVERT_TO_BLOCKS_PREFIX', 'convert_to_blocks' ); /* Labels */ diff --git a/includes/ConvertToBlocks/Settings.php b/includes/ConvertToBlocks/Settings.php index 014b10e..313d598 100644 --- a/includes/ConvertToBlocks/Settings.php +++ b/includes/ConvertToBlocks/Settings.php @@ -57,6 +57,8 @@ public function register() { add_action( 'admin_menu', [ $this, 'add_menu' ] ); add_action( 'admin_init', [ $this, 'register_section' ], 10 ); add_action( 'admin_init', [ $this, 'register_fields' ], 20 ); + + add_filter( 'post_type_supports_convert_to_blocks', [ $this, 'supported_post_types' ], 10, 2 ); } /** @@ -75,7 +77,7 @@ public function init() { // Configure variables. $this->settings_page = sprintf( '%s-%s', CONVERT_TO_BLOCKS_SLUG, $this->settings_page ); $this->settings_section = sprintf( '%s-%s', CONVERT_TO_BLOCKS_SLUG, $this->settings_section ); - $this->settings_group = sprintf( '%s_%s', CONVERT_TO_BLOCKS_PREFIX, $this->settings_group ); + $this->settings_group = sprintf( '%s_%s', CONVERT_TO_BLOCKS_SLUG, $this->settings_group ); // Get post types. $this->post_types = $this->get_post_types(); @@ -149,8 +151,8 @@ public function settings_page() { public function register_section() { add_settings_section( $this->settings_section, - '', - '', + false, + false, CONVERT_TO_BLOCKS_SLUG ); } @@ -163,19 +165,19 @@ public function register_section() { public function register_fields() { // Supported post types. add_settings_field( - sprintf( '%s_post_types', CONVERT_TO_BLOCKS_PREFIX ), + sprintf( '%s_post_types', CONVERT_TO_BLOCKS_SLUG ), esc_html__( 'Supported Post Types', 'convert-to-blocks' ), [ $this, 'field_post_types' ], CONVERT_TO_BLOCKS_SLUG, $this->settings_section, [ - 'label_for' => sprintf( '%s_post_types', CONVERT_TO_BLOCKS_PREFIX ), + 'label_for' => sprintf( '%s_post_types', CONVERT_TO_BLOCKS_SLUG ), ] ); register_setting( $this->settings_group, - sprintf( '%s_post_types', CONVERT_TO_BLOCKS_PREFIX ), + sprintf( '%s_post_types', CONVERT_TO_BLOCKS_SLUG ), [ 'sanitize_callback' => [ $this, 'sanitize_post_types' ], ] @@ -183,25 +185,29 @@ public function register_fields() { } /** - * Renders the post_types field. + * Renders the `post_types` field. * * @return void */ public function field_post_types() { - $post_types = get_option( sprintf( '%s_post_types', CONVERT_TO_BLOCKS_PREFIX ), [] ); + $post_types = get_option( sprintf( '%s_post_types', CONVERT_TO_BLOCKS_SLUG ), [] ); + $output_html = ''; - echo '
'; foreach ( $this->post_types as $post_type ) { - printf( + $output_html .= sprintf( '
', - sprintf( '%s_post_types_%s', esc_attr( CONVERT_TO_BLOCKS_PREFIX ), esc_attr( $post_type ) ), - sprintf( '%s_post_types', esc_attr( CONVERT_TO_BLOCKS_PREFIX ) ), + sprintf( '%s_post_types_%s', esc_attr( CONVERT_TO_BLOCKS_SLUG ), esc_attr( $post_type ) ), + sprintf( '%s_post_types', esc_attr( CONVERT_TO_BLOCKS_SLUG ) ), checked( in_array( $post_type, $post_types, true ), 1, false ), esc_attr( $post_type ), esc_attr( ucfirst( $post_type ) ) ); } - echo '
'; + ?> +
+ +
+ Date: Tue, 10 May 2022 14:01:00 +0530 Subject: [PATCH 05/11] Move filter to the end --- includes/ConvertToBlocks/Settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/ConvertToBlocks/Settings.php b/includes/ConvertToBlocks/Settings.php index 313d598..4f6a411 100644 --- a/includes/ConvertToBlocks/Settings.php +++ b/includes/ConvertToBlocks/Settings.php @@ -58,7 +58,7 @@ public function register() { add_action( 'admin_init', [ $this, 'register_section' ], 10 ); add_action( 'admin_init', [ $this, 'register_fields' ], 20 ); - add_filter( 'post_type_supports_convert_to_blocks', [ $this, 'supported_post_types' ], 10, 2 ); + add_filter( 'post_type_supports_convert_to_blocks', [ $this, 'supported_post_types' ], PHP_INT_MAX, 2 ); } /** From e05f49bae64a45f85ed3f5442f97e676c352e903 Mon Sep 17 00:00:00 2001 From: Akshit Sethi Date: Tue, 10 May 2022 14:12:36 +0530 Subject: [PATCH 06/11] Fix nitpicks --- includes/ConvertToBlocks/Settings.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/includes/ConvertToBlocks/Settings.php b/includes/ConvertToBlocks/Settings.php index 4f6a411..66afee9 100644 --- a/includes/ConvertToBlocks/Settings.php +++ b/includes/ConvertToBlocks/Settings.php @@ -236,10 +236,17 @@ public function sanitize_post_types( $input ) { public function supported_post_types( $supports, $post_type ) { $supported_post_types = get_option( sprintf( '%s_post_types', CONVERT_TO_BLOCKS_SLUG ) ); - if ( ! $supported_post_types ) { + // If the settings option does not exist in DB. + if ( false === $supported_post_types ) { return $supports; } + // If no post_type is selected. + if ( empty( $supported_post_types ) ) { + return false; + } + + // Check if post_type is selected by the user. if ( in_array( $post_type, $supported_post_types, true ) ) { return true; } From d33e248866170f2d0372b72e83d8340b1eb13d11 Mon Sep 17 00:00:00 2001 From: Akshit Sethi Date: Thu, 12 May 2022 14:15:02 +0530 Subject: [PATCH 07/11] Apply suggested PR changes --- config.php | 1 + includes/ConvertToBlocks/Plugin.php | 24 +++++++++-- includes/ConvertToBlocks/Settings.php | 59 +++++++++++++-------------- 3 files changed, 50 insertions(+), 34 deletions(-) diff --git a/config.php b/config.php index 7308516..8333bc9 100644 --- a/config.php +++ b/config.php @@ -18,6 +18,7 @@ convert_to_blocks_define( 'CONVERT_TO_BLOCKS_DIR', plugin_dir_path( __FILE__ ) ); convert_to_blocks_define( 'CONVERT_TO_BLOCKS_URL', plugin_dir_url( __FILE__ ) ); convert_to_blocks_define( 'CONVERT_TO_BLOCKS_SLUG', 'convert-to-blocks' ); +convert_to_blocks_define( 'CONVERT_TO_BLOCKS_DEFAULT_POST_TYPES', [ 'post', 'page' ] ); /* Labels */ diff --git a/includes/ConvertToBlocks/Plugin.php b/includes/ConvertToBlocks/Plugin.php index 06428ed..93f87ce 100644 --- a/includes/ConvertToBlocks/Plugin.php +++ b/includes/ConvertToBlocks/Plugin.php @@ -183,14 +183,30 @@ public function init_locale() { * @return bool */ public function post_type_supports_convert_to_blocks( $post_type ) { - $supports = post_type_supports( $post_type, 'convert-to-blocks' ); - $use_defaults = apply_filters( 'convert_to_blocks_defaults', true ); - $default_post_types = $this->get_default_post_types(); + $supports = post_type_supports( $post_type, 'convert-to-blocks' ); + $use_defaults = apply_filters( 'convert_to_blocks_defaults', true ); + $default_post_types = $this->get_default_post_types(); + $user_selected_post_types = get_option( sprintf( '%s_post_types', CONVERT_TO_BLOCKS_SLUG ), $default_post_types ); if ( ! $supports && $use_defaults && in_array( $post_type, $default_post_types, true ) ) { $supports = true; } + // For user-selected option via the Settings UI. + if ( false !== $user_selected_post_types ) { + $supports = false; + + // If no post_type is selected. + if ( empty( $user_selected_post_types ) ) { + $supports = false; + } + + // Check if post_type is selected by the user. + if ( in_array( $post_type, $user_selected_post_types, true ) ) { + $supports = true; + } + } + $supports = apply_filters( 'post_type_supports_convert_to_blocks', $supports, $post_type ); return $supports; @@ -256,7 +272,7 @@ public function is_classic_editor_post( $post_id ) { * @return array */ public function get_default_post_types() { - return apply_filters( 'convert_to_blocks_default_post_types', [ 'post', 'page' ] ); + return apply_filters( 'convert_to_blocks_default_post_types', CONVERT_TO_BLOCKS_DEFAULT_POST_TYPES ); } /** diff --git a/includes/ConvertToBlocks/Settings.php b/includes/ConvertToBlocks/Settings.php index 66afee9..224ea2d 100644 --- a/includes/ConvertToBlocks/Settings.php +++ b/includes/ConvertToBlocks/Settings.php @@ -57,8 +57,7 @@ public function register() { add_action( 'admin_menu', [ $this, 'add_menu' ] ); add_action( 'admin_init', [ $this, 'register_section' ], 10 ); add_action( 'admin_init', [ $this, 'register_fields' ], 20 ); - - add_filter( 'post_type_supports_convert_to_blocks', [ $this, 'supported_post_types' ], PHP_INT_MAX, 2 ); + add_action( 'admin_notices', [ $this, 'filter_notice' ], 10 ); } /** @@ -190,7 +189,10 @@ public function register_fields() { * @return void */ public function field_post_types() { - $post_types = get_option( sprintf( '%s_post_types', CONVERT_TO_BLOCKS_SLUG ), [] ); + $post_types = get_option( + sprintf( '%s_post_types', CONVERT_TO_BLOCKS_SLUG ), + apply_filters( 'convert_to_blocks_default_post_types', CONVERT_TO_BLOCKS_DEFAULT_POST_TYPES ) + ); $output_html = ''; foreach ( $this->post_types as $post_type ) { @@ -226,36 +228,33 @@ public function sanitize_post_types( $input ) { } /** - * Adds support for supported post types to the plugin. - * - * @param bool $supports Whether the post_type is supported or not. - * @param string $post_type Post type to be be checked. - * - * @return bool + * Adds an admin notice if a filter is active for `post_type_supports_convert_to_blocks` as + * this might overwrite the outcome of the settings stored in DB. */ - public function supported_post_types( $supports, $post_type ) { - $supported_post_types = get_option( sprintf( '%s_post_types', CONVERT_TO_BLOCKS_SLUG ) ); - - // If the settings option does not exist in DB. - if ( false === $supported_post_types ) { - return $supports; - } - - // If no post_type is selected. - if ( empty( $supported_post_types ) ) { - return false; - } - - // Check if post_type is selected by the user. - if ( in_array( $post_type, $supported_post_types, true ) ) { - return true; + public function filter_notice() { + if ( ! has_filter( 'post_type_supports_convert_to_blocks' ) ) { + return; } - /** - * This also overrides default post_types since we have the option to de-select the - * default ones via the settings panel. - */ - return false; + // URL to the settings panel. + $settings_url = add_query_arg( + [ 'page' => CONVERT_TO_BLOCKS_SLUG ], + admin_url( 'options-general.php' ) + ); + ?> +
+

+ ', + '' + ); + ?> +

+
+ Date: Thu, 5 Jan 2023 17:18:08 +0530 Subject: [PATCH 08/11] fix phpcs workflow --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b9aa285..cd840fb 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -36,7 +36,7 @@ jobs: - name: Set PHP version uses: shivammathur/setup-php@v1 with: - php-version: '7.2' + php-version: '7.4' coverage: none - name: composer install run: composer install From 4b5ffef72502b0fb0a8720d1688eb1bc0098605b Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Thu, 5 Jan 2023 17:19:21 +0530 Subject: [PATCH 09/11] fix phpunit workflow --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 76db3b1..8162158 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,7 +22,7 @@ jobs: - name: Set PHP version uses: shivammathur/setup-php@v1 with: - php-version: '7.2' + php-version: '7.4' coverage: none - name: Install dependencies From f857e2728e92e63460e9763592fa2bca05399916 Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Thu, 5 Jan 2023 17:22:45 +0530 Subject: [PATCH 10/11] remove deprecated workflow action --- .github/workflows/lint.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index cd840fb..9b9896d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -38,9 +38,8 @@ jobs: with: php-version: '7.4' coverage: none + tools: phpcs - name: composer install run: composer install - name: PHPCS check - uses: chekalsky/phpcs-action@v1 - with: - phpcs_bin_path: './vendor/bin/phpcs .' + run: './vendor/bin/phpcs .' From 4b94306202d9d8b4d44b015846a9e40ec92d7c12 Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Thu, 5 Jan 2023 18:31:19 +0530 Subject: [PATCH 11/11] add code review changes --- includes/ConvertToBlocks/Settings.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/includes/ConvertToBlocks/Settings.php b/includes/ConvertToBlocks/Settings.php index 224ea2d..6ad58c0 100644 --- a/includes/ConvertToBlocks/Settings.php +++ b/includes/ConvertToBlocks/Settings.php @@ -191,7 +191,7 @@ public function register_fields() { public function field_post_types() { $post_types = get_option( sprintf( '%s_post_types', CONVERT_TO_BLOCKS_SLUG ), - apply_filters( 'convert_to_blocks_default_post_types', CONVERT_TO_BLOCKS_DEFAULT_POST_TYPES ) + Plugin::get_instance()->get_default_post_types() ); $output_html = ''; @@ -236,20 +236,27 @@ public function filter_notice() { return; } - // URL to the settings panel. - $settings_url = add_query_arg( - [ 'page' => CONVERT_TO_BLOCKS_SLUG ], - admin_url( 'options-general.php' ) + $show_on_pages = array( + 'settings_page_convert-to-blocks', + 'plugins', ); + + $screen = get_current_screen(); + + if ( is_null( $screen ) ) { + return; + } + + if ( ! ( ! empty( $screen->post_type ) || in_array( $screen->id, $show_on_pages, true ) ) ) { + return; + } + ?>

', - '' + esc_html__( 'A filter hook (post_type_supports_convert_to_blocks) is already active.', 'convert-to-blocks' ), ); ?>