From d96e05c77505d74cba5d6e0066f8c4bb2deebb13 Mon Sep 17 00:00:00 2001 From: Konstantinos Galanakis Date: Mon, 14 Aug 2023 10:54:28 +0300 Subject: [PATCH 1/5] Add a check to ensure we have a valid PHP version before loading plugin functionality and output an admin notice if needed --- insert-special-characters.php | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/insert-special-characters.php b/insert-special-characters.php index 788a9aa..53804a9 100644 --- a/insert-special-characters.php +++ b/insert-special-characters.php @@ -17,6 +17,53 @@ namespace InsertSpecialCharacters; +/** + * Get the minimum version of PHP required by this plugin. + * + * @since 1.0.8 + * + * @return string Minimum version required. + */ +function minimum_php_requirement(): string { + return '7.4'; +} + +/** + * Whether PHP installation meets the minimum requirements + * + * @since 1.0.8 + * + * @return bool True if meets minimum requirements, false otherwise. + */ +function site_meets_php_requirements(): bool { + return version_compare( phpversion(), minimum_php_requirement(), '>=' ); +} + +// Try to load the plugin files, ensuring our PHP version is met first. +if ( ! site_meets_php_requirements() ) { + add_action( + 'admin_notices', + function() { + ?> +
+

+ +

+
+ Date: Fri, 15 Sep 2023 18:11:35 +0300 Subject: [PATCH 2/5] Make main plugin file PHP 5.6 compatible and move main plugin functionality in a separate file --- inc/plugin.php | 170 +++++++++++++++++++++++++++++++++ insert-special-characters.php | 174 ++-------------------------------- 2 files changed, 179 insertions(+), 165 deletions(-) create mode 100644 inc/plugin.php diff --git a/inc/plugin.php b/inc/plugin.php new file mode 100644 index 0000000..803e6c5 --- /dev/null +++ b/inc/plugin.php @@ -0,0 +1,170 @@ + get_most_used_palette_setting(), + ) + ) + ) + ); +} +add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\gcm_block_enqueue_scripts' ); + +/** + * Registers settings fields. + */ +function register_settings_fields() { + register_setting( + 'writing', + 'tenup_isc_most_read_palette', + array( + 'type' => 'boolean', + 'show_in_rest' => true, + 'default' => false, + ) + ); + + add_settings_section( + 'tenup_isc_writing_section', + esc_html__( 'Insert Special Characters', 'insert-special-characters' ), + null, + 'writing' + ); + + add_settings_field( + 'tenup_isc_most_read_palette', + esc_html__( 'Most used characters palette', 'insert-special-characters' ), + __NAMESPACE__ . '\render_isc_writing_setting', + 'writing', + 'tenup_isc_writing_section', + array( + 'label_for' => 'tenup_isc_most_read_palette', + ) + ); +} +add_action( 'admin_init', __NAMESPACE__ . '\register_settings_fields' ); + +/** + * Renders settings fields. + */ +function render_isc_writing_setting() { + $option = get_most_used_palette_setting(); + ?> +

+ +

+ + +

+ +   + +

+ __( 'Palette cleared', 'insert-special-characters' ), + ) + ); +} +add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\load_admin_scripts' ); diff --git a/insert-special-characters.php b/insert-special-characters.php index 53804a9..abd292b 100644 --- a/insert-special-characters.php +++ b/insert-special-characters.php @@ -17,6 +17,9 @@ namespace InsertSpecialCharacters; +define( 'ISC_PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); +define( 'ISC_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); + /** * Get the minimum version of PHP required by this plugin. * @@ -24,7 +27,7 @@ * * @return string Minimum version required. */ -function minimum_php_requirement(): string { +function minimum_php_requirement() { return '7.4'; } @@ -35,7 +38,7 @@ function minimum_php_requirement(): string { * * @return bool True if meets minimum requirements, false otherwise. */ -function site_meets_php_requirements(): bool { +function site_meets_php_requirements() { return version_compare( phpversion(), minimum_php_requirement(), '>=' ); } @@ -50,7 +53,7 @@ function() { get_most_used_palette_setting(), - ) - ) - ) - ); -} -add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\gcm_block_enqueue_scripts' ); - -/** - * Registers settings fields. - */ -function register_settings_fields() { - register_setting( - 'writing', - 'tenup_isc_most_read_palette', - array( - 'type' => 'boolean', - 'show_in_rest' => true, - 'default' => false, - ) - ); - - add_settings_section( - 'tenup_isc_writing_section', - esc_html__( 'Insert Special Characters', 'insert-special-characters' ), - null, - 'writing' - ); - - add_settings_field( - 'tenup_isc_most_read_palette', - esc_html__( 'Most used characters palette', 'insert-special-characters' ), - __NAMESPACE__ . '\render_isc_writing_setting', - 'writing', - 'tenup_isc_writing_section', - array( - 'label_for' => 'tenup_isc_most_read_palette', - ) - ); -} -add_action( 'admin_init', __NAMESPACE__ . '\register_settings_fields' ); - -/** - * Renders settings fields. - */ -function render_isc_writing_setting() { - $option = get_most_used_palette_setting(); - ?> -

- -

- - -

- -   - -

- __( 'Palette cleared', 'insert-special-characters' ), - ) - ); -} -add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\load_admin_scripts' ); +require_once __DIR__ . '/inc/plugin.php'; From 501dc62c0dc2998bb48d0735d17e70b074d6fcb7 Mon Sep 17 00:00:00 2001 From: Konstantinos Galanakis Date: Fri, 15 Sep 2023 18:13:10 +0300 Subject: [PATCH 3/5] Add PHP Compatibility check for 5.6 on the main file and fo 7.4 for the rest of the plugin --- .github/workflows/php-compatibility.yml | 7 ++++-- inc/plugin.php | 33 ++++++++++++++----------- insert-special-characters.php | 2 +- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.github/workflows/php-compatibility.yml b/.github/workflows/php-compatibility.yml index 09aa667..73f6a54 100644 --- a/.github/workflows/php-compatibility.yml +++ b/.github/workflows/php-compatibility.yml @@ -29,5 +29,8 @@ jobs: - name: Install dependencies run: composer install - - name: Run PHP Compatibility - run: vendor/bin/phpcs insert-special-characters.php --standard=PHPCompatibilityWP --extensions=php --runtime-set testVersion 7.4- \ No newline at end of file + - name: Run PHP Compatibility on all files. + run: vendor/bin/phpcs inc --standard=PHPCompatibilityWP --extensions=php --runtime-set testVersion 7.4- + + - name: Run PHP Compatibility on main file. + run: vendor/bin/phpcs insert-special-characters.php --standard=PHPCompatibilityWP --extensions=php --runtime-set testVersion 5.6- diff --git a/inc/plugin.php b/inc/plugin.php index 803e6c5..89cb689 100644 --- a/inc/plugin.php +++ b/inc/plugin.php @@ -1,7 +1,10 @@ -

-

+ +

-

- -   + +   -

- + Date: Tue, 19 Sep 2023 10:37:04 +1000 Subject: [PATCH 4/5] CS: Whitespace cleanup. --- inc/plugin.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inc/plugin.php b/inc/plugin.php index 89cb689..318561f 100644 --- a/inc/plugin.php +++ b/inc/plugin.php @@ -106,9 +106,9 @@ function render_isc_writing_setting() {