diff --git a/blocks-everywhere.php b/blocks-everywhere.php index 8ad93d0..052a607 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.23.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..25449cf --- /dev/null +++ b/classes/handlers/class-terms.php @@ -0,0 +1,140 @@ +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 ); + } + } ); + + } + + add_filter( 'pre_term_description', [ $this, 'remove_blocks' ] ); + + // Ensure blocks are processed when displaying + add_filter( + 'term_description', + function( $content ) { + return $this->do_blocks( $content, 'term_description' ); + }, + 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 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 + * + * @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'] = false; + $settings['quicktags'] = true; + return $settings; + } +} \ No newline at end of file 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; + } +}