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 new file mode 100644 index 0000000..318561f --- /dev/null +++ b/inc/plugin.php @@ -0,0 +1,173 @@ + 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 788a9aa..a0dd527 100644 --- a/insert-special-characters.php +++ b/insert-special-characters.php @@ -17,167 +17,58 @@ namespace InsertSpecialCharacters; -/** - * Registers JS and CSS assets. - */ -function register_assets() { - $asset_data_file = trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/index.asset.php'; - - if ( ! file_exists( $asset_data_file ) ) { - return; - } - - $script_data = include $asset_data_file; - - wp_register_script( - 'insert-special-characters', - plugin_dir_url( __FILE__ ) . 'build/index.js', - $script_data['dependencies'], - $script_data['version'], - true - ); - - wp_register_style( - 'insert-special-characters-css', - plugin_dir_url( __FILE__ ) . 'build/index.css', - array(), - $script_data['version'] - ); - - wp_set_script_translations( 'insert-special-characters', 'insert-special-characters', plugin_dir_path( __FILE__ ) . 'languages' ); -} - -add_action( 'init', __NAMESPACE__ . '\register_assets' ); - +define( 'ISC_PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); +define( 'ISC_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); /** - * Enqueue the admin JavaScript assets. - */ -function gcm_block_enqueue_scripts() { - - wp_enqueue_script( 'insert-special-characters' ); - - wp_enqueue_style( 'insert-special-characters-css' ); - - wp_add_inline_script( - 'insert-special-characters', - sprintf( - 'var tenupIscVars = window.tenupIscVars || {}; tenupIscVars = %1$s', - wp_json_encode( - array( - 'most_read_palette' => 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(); - ?> -

- -

- - -

- -   - -

- =' ); +} - wp_enqueue_script( - 'insert-special-characters-admin-js', - plugin_dir_url( __FILE__ ) . 'build/admin.js', - $script_data['dependencies'], - $script_data['version'], - true +// Try to load the plugin files, ensuring our PHP version is met first. +if ( ! site_meets_php_requirements() ) { + add_action( + 'admin_notices', + function() { + ?> +
+

+ +

+
+ __( 'Palette cleared', 'insert-special-characters' ), - ) - ); +if ( ! site_meets_php_requirements() ) { + return; } -add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\load_admin_scripts' ); + +require_once __DIR__ . '/inc/plugin.php'; diff --git a/package-lock.json b/package-lock.json index b91ed29..3d9bd6d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13176,9 +13176,16 @@ "license": "ISC" }, "node_modules/nanoid": { - "version": "3.3.4", + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz", + "integrity": "sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==", "dev": true, - "license": "MIT", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], "bin": { "nanoid": "bin/nanoid.cjs" }, @@ -14145,7 +14152,9 @@ } }, "node_modules/postcss": { - "version": "8.4.20", + "version": "8.4.31", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz", + "integrity": "sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==", "dev": true, "funding": [ { @@ -14155,11 +14164,14 @@ { "type": "tidelift", "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" } ], - "license": "MIT", "dependencies": { - "nanoid": "^3.3.4", + "nanoid": "^3.3.6", "picocolors": "^1.0.0", "source-map-js": "^1.0.2" }, @@ -27436,7 +27448,9 @@ "dev": true }, "nanoid": { - "version": "3.3.4", + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz", + "integrity": "sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==", "dev": true }, "natural-compare": { @@ -28052,10 +28066,12 @@ } }, "postcss": { - "version": "8.4.20", + "version": "8.4.31", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz", + "integrity": "sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==", "dev": true, "requires": { - "nanoid": "^3.3.4", + "nanoid": "^3.3.6", "picocolors": "^1.0.0", "source-map-js": "^1.0.2" }