From afce3c207bcc96ed33c9a3a943b3b07dcabd40b5 Mon Sep 17 00:00:00 2001 From: Johannes Kinast Date: Fri, 2 Jun 2023 10:24:25 +0200 Subject: [PATCH 1/3] Gutenberg for Term Description --- blocks-everywhere.php | 8 +++- classes/handlers/class-terms.php | 79 ++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 classes/handlers/class-terms.php diff --git a/blocks-everywhere.php b/blocks-everywhere.php index cea3d8f..a276879 100644 --- a/blocks-everywhere.php +++ b/blocks-everywhere.php @@ -16,6 +16,7 @@ require_once __DIR__ . '/classes/handlers/class-bbpress.php'; require_once __DIR__ . '/classes/handlers/class-buddypress.php'; require_once __DIR__ . '/classes/handlers/class-comments.php'; +require_once __DIR__ . '/classes/handlers/class-terms.php'; class Blocks_Everywhere { const VERSION = '1.18.0'; @@ -72,6 +73,7 @@ public function load_handlers() { $default_comments = defined( 'BLOCKS_EVERYWHERE_COMMENTS' ) ? BLOCKS_EVERYWHERE_COMMENTS : false; $default_bbpress = defined( 'BLOCKS_EVERYWHERE_BBPRESS' ) ? BLOCKS_EVERYWHERE_BBPRESS : false; $default_buddypress = defined( 'BLOCKS_EVERYWHERE_BUDDYPRESS' ) ? BLOCKS_EVERYWHERE_BUDDYPRESS : false; + $default_terms = defined( 'BLOCKS_EVERYWHERE_TERMS' ) ? BLOCKS_EVERYWHERE_TERMS : false; if ( apply_filters( 'blocks_everywhere_comments', $default_comments ) ) { $this->handlers['Comments'] = new Handler\Comments(); @@ -84,12 +86,16 @@ public function load_handlers() { if ( apply_filters( 'blocks_everywhere_buddypress', $default_buddypress ) ) { $this->handlers['BuddyPress'] = new Handler\BuddyPress(); } + + if ( apply_filters( 'blocks_everywhere_terms', $default_terms ) ) { + $this->handlers['Terms'] = new Handler\Terms(); + } } /** * Get the instantiated handler class for the specified type, or null if it isn't configured or known. * - * @param 'Comments'|'bbPress'|'BuddyPress' $which The handler type. + * @param 'Comments'|'bbPress'|'BuddyPress'|'Terms' $which The handler type. * @return Handler\Handler|null object or null it not configured. */ public function get_handler( $which ) { diff --git a/classes/handlers/class-terms.php b/classes/handlers/class-terms.php new file mode 100644 index 0000000..5a624b5 --- /dev/null +++ b/classes/handlers/class-terms.php @@ -0,0 +1,79 @@ + true, + 'public' => true, + ] ); + foreach ( $taxonomies as $taxonomy ) { + add_action( $taxonomy . '_edit_form_fields', [ $this, 'add_to_terms_edit' ], 1, 2 ); + add_action( $taxonomy . '_add_form_fields', [ $this, 'add_to_terms_add' ], 1, 1 ); + } + + // Ensure blocks are processed when displaying + add_filter( + 'term_description', + function( $content ) { + return $this->do_blocks( $content, 'term_description' ); + }, + 8 + ); + } + + public function can_show_admin_editor( $hook ) { + return $hook === 'term.php'; + } + + public function get_editor_type() { + return 'core'; + } + + /** + * Get the HTML that the editor uses on the page + * + * @return void + */ + public function add_to_terms_edit() { + $this->load_editor( '#description' ); + } + + /** + * Get the HTML that the editor uses on the page + * + * @return void + */ + public function add_to_terms_add() { + $this->load_editor( '#tag-description' ); + } + + public function wp_editor_settings( $settings ) { + $settings['tinymce'] = true; + $settings['quicktags'] = true; + return $settings; + } +} From a93b210669cce0fa97e41c10746e1955cb16ffaf Mon Sep 17 00:00:00 2001 From: Johannes Kinast Date: Fri, 2 Jun 2023 10:37:26 +0200 Subject: [PATCH 2/3] Hide Textarea --- src/styles/style.scss | 1 + src/styles/terms.scss | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 src/styles/terms.scss diff --git a/src/styles/style.scss b/src/styles/style.scss index e01c7b8..cab1a8b 100644 --- a/src/styles/style.scss +++ b/src/styles/style.scss @@ -21,3 +21,4 @@ @import "./comments.scss"; @import "./bbpress.scss"; @import "./editor.scss"; +@import "./terms.scss"; diff --git a/src/styles/terms.scss b/src/styles/terms.scss new file mode 100644 index 0000000..281f55b --- /dev/null +++ b/src/styles/terms.scss @@ -0,0 +1,6 @@ +// Terms +.gutenberg-support-loaded { + textarea#description, textarea#tag-description { + display: none; + } +} From 51e74abfdd30e041e16a6755458926b15a326f68 Mon Sep 17 00:00:00 2001 From: Johannes Kinast Date: Tue, 21 May 2024 13:24:19 +0200 Subject: [PATCH 3/3] Enable Image upload and all blocks --- classes/handlers/class-terms.php | 87 +++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 13 deletions(-) diff --git a/classes/handlers/class-terms.php b/classes/handlers/class-terms.php index 5a624b5..25449cf 100644 --- a/classes/handlers/class-terms.php +++ b/classes/handlers/class-terms.php @@ -1,11 +1,16 @@ enabled_blocks = array_values( array_map( function( $block ) { + return $block->name; + }, WP_Block_Type_Registry::get_instance()->get_all_registered() ) ); + + $this->enabled_blocks[] = 'blocks-everywhere/support-content'; + + /* Loop through the taxonomies, adding actions */ + $taxonomies = get_taxonomies( [ + 'show_ui' => true, + 'public' => true, + ] ); + foreach ( $taxonomies as $taxonomy ) { + add_action( $taxonomy . '_edit_form_fields', [ $this, 'add_to_terms_edit' ], 1, 2 ); + add_action( $taxonomy . '_add_form_fields', [ $this, 'add_to_terms_add' ], 1, 1 ); + } + } ); - /* Loop through the taxonomies, adding actions */ - $taxonomies = get_taxonomies( [ - 'show_ui' => true, - 'public' => true, - ] ); - foreach ( $taxonomies as $taxonomy ) { - add_action( $taxonomy . '_edit_form_fields', [ $this, 'add_to_terms_edit' ], 1, 2 ); - add_action( $taxonomy . '_add_form_fields', [ $this, 'add_to_terms_add' ], 1, 1 ); } + add_filter( 'pre_term_description', [ $this, 'remove_blocks' ] ); + // Ensure blocks are processed when displaying add_filter( 'term_description', @@ -43,16 +58,62 @@ function( $content ) { }, 8 ); + + add_filter( 'blocks_everywhere_editor_settings', [ $this, 'settings' ], 1, 1 ); + add_filter( 'blocks_everywhere_allowed_blocks', [ $this, 'allowed_blocks' ], 1, 1 ); + + add_filter( 'body_class', [ $this, 'body_class' ] ); + + } + + public function body_class( $classes ) { + $classes[] = 'gutenberg-support'; + + $can_upload = false; + if ( isset( $this->settings['editor']['hasUploadPermissions'] ) && $this->settings['editor']['hasUploadPermissions'] ) { + $can_upload = true; + } + + if ( $can_upload ) { + $classes[] = 'gutenberg-support-upload'; + } + + return $classes; } public function can_show_admin_editor( $hook ) { - return $hook === 'term.php'; + return false; //$hook === 'term.php'; } public function get_editor_type() { return 'core'; } + public function allowed_blocks( $blocks ) { + return $this->enabled_blocks; + } + + public function settings( $settings ) { + + $settings['iso']['moreMenu'] = array( + 'editor' => true, + 'fullscreen' => true, + 'preview' => true, + 'topToolbar' => true + ); + + $settings['iso']['sidebar'] = array( + 'inserter' => false, + 'inspector' => false + ); + + $settings['editor']['hasUploadPermissions'] = true; + $settings['editor']['reusableBlocks'] = true; + + + return $settings; + } + /** * Get the HTML that the editor uses on the page * @@ -72,8 +133,8 @@ public function add_to_terms_add() { } public function wp_editor_settings( $settings ) { - $settings['tinymce'] = true; + $settings['tinymce'] = false; $settings['quicktags'] = true; return $settings; } -} +} \ No newline at end of file