Skip to content

Commit

Permalink
Merge pull request #70 from t-hamano/wp6.3
Browse files Browse the repository at this point in the history
Version 3.3.0 (Release for WP6.3)
  • Loading branch information
t-hamano authored Jul 23, 2023
2 parents 1e71959 + 84a4304 commit fa2b31d
Show file tree
Hide file tree
Showing 278 changed files with 35,339 additions and 19,372 deletions.
3 changes: 0 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ module.exports = {
extends: [ 'plugin:@wordpress/eslint-plugin/recommended' ],
parser: '@babel/eslint-parser',
globals: {
chbeObj: true,
Blob: true,
FileReader: true,
jQuery: true,
},
rules: {
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/run-test-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ jobs:
strategy:
matrix:
php-versions: [
'7.3',
'7.4',
'8.0'
]
wp-versions: [
'WordPress#5.9.4',
'WordPress#6.0.3',
'WordPress#6.1',
'WordPress#6.1.3',
'WordPress#6.2.2',
'WordPress'
]
name: PHP ${{ matrix.php-versions }} / ${{ matrix.wp-versions }} Test
Expand Down
14 changes: 10 additions & 4 deletions .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ jobs:
strategy:
matrix:
php-versions: [
'7.3',
'7.4',
'8.0'
]
wp-versions: [
'WordPress#5.9.4',
'WordPress#6.0.3',
'WordPress#6.1',
'WordPress#6.1.3',
'WordPress#6.2.2',
'WordPress'
]
name: PHP ${{ matrix.php-versions }} / ${{ matrix.wp-versions }} Test
Expand Down Expand Up @@ -57,3 +55,11 @@ jobs:
- name: Running e2e tests
run: npm run test:e2e

- name: Archive debug artifacts
uses: actions/upload-artifact@v3
if: always()
with:
name: failures-artifacts
path: artifacts
if-no-files-found: ignore
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14
16
10 changes: 7 additions & 3 deletions .wp-env.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
".",
"https://downloads.wordpress.org/plugin/classic-editor.zip"
],
"config": {
"WP_DEBUG": true,
"SCRIPT_DEBUG": true
"env": {
"tests": {
"config": {
"WP_DEBUG": true,
"SCRIPT_DEBUG": true
}
}
}
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Custom HTML Block Extension
# Custom HTML Block Extension

[![Tests](https://github.com/t-hamano/custom-html-block-extension/actions/workflows/run-test.yml/badge.svg)](https://github.com/t-hamano/custom-html-block-extension/actions/workflows/run-test.yml)
[![Tests and Deploy](https://github.com/t-hamano/custom-html-block-extension/actions/workflows/run-test-and-deploy.yml/badge.svg)](https://github.com/t-hamano/custom-html-block-extension/actions/workflows/run-test-and-deploy.yml)

![Custom HTML Block Extension](https://raw.githubusercontent.com/t-hamano/custom-html-block-extension/main/assets/images/admin/welcome-guide/slide_1.gif)

Custom HTML Block Extension extends "Custom HTML block" to evolve into an advanced code editor.
Custom HTML Block Extension extends Custom HTML block to evolve into the advanced code editor.

## Features

Expand Down Expand Up @@ -33,7 +33,7 @@ Supports the classic editor, the theme/plugin editor, import/export editor setti

You can use your own favorite fonts in addition to the default fonts.

### STEP1: Place font files
### STEP1: Place font files

Place the font files in **the public directory** of the server where WordPress is installed.
It is recommended to create `fonts` folder directly under the theme and place the fonts there.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion classes/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function admin_enqueue_scripts( $hook_suffix ) {
$content = '<h3>' . __( 'Custom HTML Block Extension', 'custom-html-block-extension' ) . '</h3>';
$content .= '<p>';
$content .= sprintf(
/* translators: 1: setting page url */
/* translators: %s is replaced with the setting page url. */
__(
'Custom HTML Block Extension enabled. You can customize the editor in <a href="%s">setting page</a>.',
'custom-html-block-extension'
Expand Down Expand Up @@ -113,6 +113,7 @@ public function admin_enqueue_scripts( $hook_suffix ) {
'editorSettings' => Settings::get_editor_settings(),
'editorOptions' => Settings::get_editor_options(),
'options' => Settings::get_options(),
'userRoles' => Settings::get_user_roles(),
'fontFamily' => Settings::get_font_families(),
'dismissWelcomeGuide' => get_option( Settings::OPTION_NAME['dismiss_welcome_guide'] ),
)
Expand Down
2 changes: 1 addition & 1 deletion classes/class-block-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function enqueue_editor_scripts() {
// Abort the process if permission is disabled.
$options = Settings::get_options();

if ( ! $options['permissionBlockEditor'] ) {
if ( ! $options['permissionBlockEditor'] || ! Settings::is_allowed_user() ) {
return;
}

Expand Down
42 changes: 20 additions & 22 deletions classes/class-classic-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,45 +133,43 @@ public function admin_footer() {
// phpcs:disable Generic.ControlStructures.InlineControlStructure
?>
<div id="chbe-replace-indent-dialog" class="chbe-dialog__inner">
<p class="chbe-dialog__ttl"><?php echo esc_attr_e( 'Change Indentation', 'custom-html-block-extension' ); ?></p>
<h2 class="chbe-dialog__title"><?php echo esc_attr_e( 'Change Indentation', 'custom-html-block-extension' ); ?></h2>
<div class="chbe-dialog__row">
<div class="chbe-dialog__col chbe-dialog__col--setting">
<p class="chbe-dialog__subttl"><?php esc_html_e( 'Current Indent', 'custom-html-block-extension' ); ?></p>
<p>
<strong><?php esc_html_e( 'Indent type', 'custom-html-block-extension' ); ?></strong>
<div class="chbe-dialog__setting">
<h3 class="chbe-dialog__subtitle"><?php esc_html_e( 'Current Indent', 'custom-html-block-extension' ); ?></h3>
<fieldset>
<legend><?php esc_html_e( 'Current indent type', 'custom-html-block-extension' ); ?></legend>
<label>
<?php esc_html_e( 'Space', 'custom-html-block-extension' ); ?>
<input type="radio" name="before_insert_spaces" value="1" <?php if ( $settings['insertSpaces'] ) echo 'checked'; ?>>
<input type="radio" name="before_insert_spaces" value="1" <?php checked( $settings['insertSpaces'] ); ?>>
</label>
<label>
<?php esc_html_e( 'Tab', 'custom-html-block-extension' ); ?>
<input type="radio" name="before_insert_spaces" value="0" <?php if ( ! $settings['insertSpaces'] ) echo 'checked'; ?>>
<input type="radio" name="before_insert_spaces" value="0" <?php checked( ! $settings['insertSpaces'] ); ?>>
</label>
</p>
</fieldset>
<p id="chbe-item-before-tab-size" style="<?php if ( ! $settings['insertSpaces'] ) echo 'display:none;'; ?>">
<strong><?php esc_html_e( 'Indent width', 'custom-html-block-extension' ); ?></strong>
<input type="number" name="before_tab_size" min="1" max="8" value="<?php echo esc_attr( $settings['tabSize'] ); ?>">
<label for="chbe_before_tab_size"><strong><?php esc_html_e( 'Current indent width', 'custom-html-block-extension' ); ?></strong></label>
<input type="number" id="chbe_before_tab_size" name="before_tab_size" min="1" max="8" value="<?php echo esc_attr( $settings['tabSize'] ); ?>">
</p>
</div>
<div class="chbe-dialog__col chbe-dialog__col--arrow">
<span class="dashicons dashicons-arrow-right-alt">
</div>
<div class="chbe-dialog__col chbe-dialog__col--setting">
<p class="chbe-dialog__subttl"><?php esc_html_e( 'New Indent', 'custom-html-block-extension' ); ?></p>
<p>
<strong><?php esc_html_e( 'Indent type', 'custom-html-block-extension' ); ?></strong>
<span class="chbe-dialog__arrow dashicons dashicons-arrow-right-alt"></span>
<div class="chbe-dialog__setting">
<h3 class="chbe-dialog__subtitle"><?php esc_html_e( 'New Indent', 'custom-html-block-extension' ); ?></h3>
<fieldset>
<legend><?php esc_html_e( 'New indent type', 'custom-html-block-extension' ); ?></legend>
<label>
<?php esc_html_e( 'Space', 'custom-html-block-extension' ); ?>
<input type="radio" name="after_insert_spaces" value="1" <?php if ( $settings['insertSpaces'] ) echo 'checked'; ?>>
<input type="radio" name="after_insert_spaces" value="1" <?php checked( $settings['insertSpaces'] ); ?>>
</label>
<label>
<?php esc_html_e( 'Tab', 'custom-html-block-extension' ); ?>
<input type="radio" name="after_insert_spaces" value="0" <?php if ( ! $settings['insertSpaces'] ) echo 'checked'; ?>>
<input type="radio" name="after_insert_spaces" value="0" <?php checked( ! $settings['insertSpaces'] ); ?>>
</label>
</p>
</fieldset>
<p id="chbe-item-after-tab-size" style="<?php if ( ! $settings['insertSpaces'] ) echo 'display:none;'; ?>">
<strong><?php esc_html_e( 'Indent width', 'custom-html-block-extension' ); ?></strong>
<input type="number" name="after_tab_size" min="1" max="8" value="<?php echo esc_attr( $settings['tabSize'] ); ?>">
<label for="chbe_after_tab_size"><strong><?php esc_html_e( 'New indent width', 'custom-html-block-extension' ); ?></strong></label>
<input type="number" id="chbe_after_tab_size" name="after_tab_size" min="1" max="8" value="<?php echo esc_attr( $settings['tabSize'] ); ?>">
</p>
</div>
</div>
Expand Down
46 changes: 46 additions & 0 deletions classes/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,10 @@ class Settings {
'type' => 'boolean',
'default' => true,
),
'permissionRoles' => array(
'type' => 'array',
'default' => array( 'administrator', 'editor', 'author', 'contributor' ),
),
);

// Default font family variations.
Expand Down Expand Up @@ -575,6 +579,48 @@ public static function get_font_families() {
$additional_font_families = apply_filters( 'chbe_additional_font_families', array() );
return array_merge( $default_font_families, $additional_font_families );
}

/**
* Get all user roles.
*/
public static function get_user_roles() {
global $wp_roles;
if ( empty( $wp_roles ) ) {
$wp_roles = new WP_Roles();
}

$roles = $wp_roles->get_names();
$translated_roles = array();

foreach ( $roles as $name => $display_name ) {
$translated_roles[] = array(
'label' => translate_user_role( $display_name ),
'value' => $name,
);
}

return $translated_roles;
}

/**
* Whether the user is authorized to use the extension.
*/
public static function is_allowed_user() {
$options = self::get_options();
$user_meta = get_userdata( get_current_user_id() );

if ( ! $user_meta ) {
return false;
}

foreach ( $user_meta->roles as $role ) {
if ( in_array( $role, $options['permissionRoles'], true ) ) {
return true;
}
}

return false;
}
}

new Settings();
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "t-hamano/custom-html-block-extension",
"description": "Extend custom HTML blocks to evolve into an advanced code editor.",
"description": "Extend Custom HTML block to evolve into the advanced code editor.",
"license": "GPL-2.0-or-later",
"authors": [
{
Expand All @@ -9,7 +9,7 @@
],
"require-dev": {
"squizlabs/php_codesniffer": "*",
"wp-coding-standards/wpcs": "*"
"wp-coding-standards/wpcs": "*"
},
"scripts": {
"phpcs": "phpcs --config-set installed_paths vendor/wp-coding-standards/wpcs",
Expand Down
8 changes: 4 additions & 4 deletions custom-html-block-extension.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
/**
* Plugin Name: Custom HTML Block Extension
* Description: Extend custom HTML blocks to evolve into an advanced code editor.
* Requires at least: 5.9
* Requires PHP: 7.3
* Version: 3.2.1
* Description: Extend Custom HTML block to evolve into the advanced code editor.
* Requires at least: 6.1
* Requires PHP: 7.4
* Version: 3.3.0
* Author: Aki Hamano
* Author URI: https://github.com/t-hamano
* License: GPL2 or later
Expand Down
Loading

0 comments on commit fa2b31d

Please sign in to comment.