Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.3.1 #75

Merged
merged 4 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions .github/workflows/run-test-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: [
'7.4',
'8.0'
]
wp-versions: [
'WordPress#6.1.3',
'WordPress#6.2.2',
'WordPress'
]
name: PHP ${{ matrix.php-versions }} / ${{ matrix.wp-versions }} Test
include:
- php: '7.4'
wp: WordPress
- php: '7.4'
wp: WordPress#6.2.2
- php: '7.4'
wp: WordPress#6.1.3
- php: '8.0'
wp: WordPress
- php: '8.0'
wp: WordPress#6.2.2
- php: '8.0'
wp: WordPress#6.1.3
- php: '8.2'
wp: WordPress
- php: '8.2'
wp: WordPress#6.2.2
name: PHP ${{ matrix.php }} / ${{ matrix.wp }} Test

steps:
- uses: actions/checkout@v3
Expand All @@ -46,7 +54,7 @@ jobs:

- name: Install WordPress
run: |
WP_ENV_CORE=WordPress/${{ matrix.wp-versions }} WP_ENV_PHP_VERSION=${{ matrix.php-versions }} npm run wp-env start
WP_ENV_CORE=WordPress/${{ matrix.wp }} WP_ENV_PHP_VERSION=${{ matrix.php }} npm run wp-env start
npm run wp-env run cli wp core version
npm run wp-env run cli wp cli info

Expand Down
30 changes: 19 additions & 11 deletions .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,24 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: [
'7.4',
'8.0'
]
wp-versions: [
'WordPress#6.1.3',
'WordPress#6.2.2',
'WordPress'
]
name: PHP ${{ matrix.php-versions }} / ${{ matrix.wp-versions }} Test
include:
- php: '7.4'
wp: WordPress
- php: '7.4'
wp: WordPress#6.2.2
- php: '7.4'
wp: WordPress#6.1.3
- php: '8.0'
wp: WordPress
- php: '8.0'
wp: WordPress#6.2.2
- php: '8.0'
wp: WordPress#6.1.3
- php: '8.2'
wp: WordPress
- php: '8.2'
wp: WordPress#6.2.2
name: PHP ${{ matrix.php }} / ${{ matrix.wp }} Test

steps:
- uses: actions/checkout@v3
Expand All @@ -49,7 +57,7 @@ jobs:

- name: Install WordPress
run: |
WP_ENV_CORE=WordPress/${{ matrix.wp-versions }} WP_ENV_PHP_VERSION=${{ matrix.php-versions }} npm run wp-env start
WP_ENV_CORE=WordPress/${{ matrix.wp }} WP_ENV_PHP_VERSION=${{ matrix.php }} npm run wp-env start
npm run wp-env run cli wp core version
npm run wp-env run cli wp cli info

Expand Down
59 changes: 41 additions & 18 deletions classes/class-block-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,23 @@ class BlockEditor {
* Constructor
*/
function __construct() {
// Abort the process if the editor isn't allowed to use this extension.
$options = Settings::get_options();
if ( ! $options['permissionBlockEditor'] ) {
return;
}

// Enqueue block editor scripts
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_editor_scripts' ) );

// Enqueue block editor styles
// TODO: Remove this conditional statement and unify it with `enqueue_block_assets` hook
// when the supported minimum WordPress version is 6.3 or higher.
if ( is_wp_version_compatible( '6.3' ) && is_admin() ) {
add_action( 'enqueue_block_assets', array( $this, 'enqueue_editor_styles' ) );
} else {
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_editor_styles' ) );
}
}

/**
Expand All @@ -23,27 +38,11 @@ function __construct() {
public function enqueue_editor_scripts() {
$asset_file = include( CHBE_PATH . '/build/block-editor.asset.php' );

// Abort the process if permission is disabled.
$options = Settings::get_options();

if ( ! $options['permissionBlockEditor'] || ! Settings::is_allowed_user() ) {
// Abort the process if the user role isn't allowed to use this extension.
if ( ! Settings::is_allowed_user() ) {
return;
}

wp_enqueue_style(
CHBE_NAMESPACE,
CHBE_URL . '/build/style-block-editor.css',
array(),
filemtime( CHBE_PATH . '/build/style-block-editor.css' )
);

wp_enqueue_style(
CHBE_NAMESPACE . '-font',
CHBE_URL . '/assets/css/fira-code.css',
array(),
filemtime( CHBE_PATH . '/assets/css/fira-code.css' )
);

wp_enqueue_script(
CHBE_NAMESPACE,
CHBE_URL . '/build/block-editor.js',
Expand All @@ -64,6 +63,30 @@ public function enqueue_editor_scripts() {

wp_set_script_translations( CHBE_NAMESPACE, CHBE_NAMESPACE );
}

/**
* Enqueue block editor styles
*/
public function enqueue_editor_styles() {
// Abort the process if the user role permission is disabled.
if ( ! Settings::is_allowed_user() ) {
return;
}

wp_enqueue_style(
CHBE_NAMESPACE,
CHBE_URL . '/build/style-block-editor.css',
array(),
filemtime( CHBE_PATH . '/build/style-block-editor.css' )
);

wp_enqueue_style(
CHBE_NAMESPACE . '-font',
CHBE_URL . '/assets/css/fira-code.css',
array(),
filemtime( CHBE_PATH . '/assets/css/fira-code.css' )
);
}
}

new BlockEditor();
21 changes: 18 additions & 3 deletions classes/class-classic-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ClassicEditor {
* Constructor
*/
public function __construct() {
// Abort the process if permission is disabled.
// Abort the process if the editor isn't allowed to use this extenson.
$options = Settings::get_options();
if ( ! $options['permissionClassicEditor'] ) {
return;
Expand Down Expand Up @@ -42,14 +42,19 @@ public function admin_enqueue_scripts( $hook_suffix ) {
return;
}

// Abort the process if block editor is enabled.
// Abort the process if the block editor is enabled.
if ( ! function_exists( 'get_current_screen' ) ) {
return;
}
if ( get_current_screen()->is_block_editor ) {
return;
}

// Abort the process if the user role isn't allowed to use this extension.
if ( ! Settings::is_allowed_user() ) {
return;
}

wp_enqueue_style(
CHBE_NAMESPACE,
CHBE_URL . '/build/style-classic-editor.css',
Expand Down Expand Up @@ -106,6 +111,11 @@ public function media_buttons( $editor_id ) {
return;
}

// Abort the process if the user role isn't allowed to use this extension.
if ( ! Settings::is_allowed_user() ) {
return;
}

printf(
'<button type="button" class="button chbe-replace-indent" id="chbe-replace-indent-button">' . Settings::ICON . ' %s' . '</button>',
__( 'Change Indentation', 'custom-html-block-extension' )
Expand All @@ -116,7 +126,7 @@ public function media_buttons( $editor_id ) {
* Add dialog
*/
public function admin_footer() {
// Abort the process if block editor is enabled.
// Abort the process if the block editor is enabled.
if ( ! function_exists( 'get_current_screen' ) ) {
return;
}
Expand All @@ -129,6 +139,11 @@ public function admin_footer() {
return;
}

// Abort the process if the user role isn't allowed to use this extension.
if ( ! Settings::is_allowed_user() ) {
return;
}

$settings = Settings::get_editor_settings();
// phpcs:disable Generic.ControlStructures.InlineControlStructure
?>
Expand Down
7 changes: 6 additions & 1 deletion classes/class-theme-plugin-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ThemePluginEditor {
* Constructor
*/
public function __construct() {
// Abort the process if permission is disabled.
// Abort the process if the editor isn't allowed to use this extenson.
$options = Settings::get_options();
if ( ! $options['permissionThemePluginEditor'] ) {
return;
Expand All @@ -32,6 +32,11 @@ public function admin_enqueue_scripts( $hook_suffix ) {
return;
}

// Abort the process if the user role isn't allowed to use this extension.
if ( ! Settings::is_allowed_user() ) {
return;
}

// Correspondence between the file extension and the language specified in the Monaco Editor
$map_to_lang = array(
'css' => 'css',
Expand Down
2 changes: 1 addition & 1 deletion custom-html-block-extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Description: Extend Custom HTML block to evolve into the advanced code editor.
* Requires at least: 6.1
* Requires PHP: 7.4
* Version: 3.3.1
* Version: 3.3.2
* Author: Aki Hamano
* Author URI: https://github.com/t-hamano
* License: GPL2 or later
Expand Down
7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: gutenberg, block, html, highlighting, emmet
Donate link: https://www.paypal.me/thamanoJP
Requires at least: 6.1
Tested up to: 6.3
Stable tag: 3.3.1
Stable tag: 3.3.2
Requires PHP: 7.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -69,6 +69,11 @@ Source: https://www.marksimonson.com/fonts/view/anonymous-pro

== Changelog ==

= 3.3.2 =

* Fix: Browser warning error in WordPress 6.3
* Fix: User role settings are not applied to all editors

= 3.3.1 =

* Fix: some typos
Expand Down