Skip to content
Open
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
8 changes: 7 additions & 1 deletion blocks-everywhere.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand All @@ -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 ) {
Expand Down
140 changes: 140 additions & 0 deletions classes/handlers/class-terms.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?php

namespace Automattic\Blocks_Everywhere\Handler;
use WP_Block_Type;
use WP_Block_Type_Registry;

class Terms extends Handler {
/**
* Constructor
*/

private $enabled_blocks;

public function __construct() {
parent::__construct();

/* Only users with the "publish_posts" capability can use this feature */
if ( current_user_can( 'publish_posts' ) ) {

/* Remove the filters which disallow HTML in term descriptions */
remove_filter( 'pre_term_description', 'wp_filter_kses' );
remove_filter( 'term_description', 'wp_kses_data' );

/* Add filters to disallow unsafe HTML tags */
if ( ! current_user_can( 'unfiltered_html' ) ) {
add_filter( 'pre_term_description', 'wp_kses_post' );
add_filter( 'term_description', 'wp_kses_post' );
}

add_action( 'current_screen', function() {

$this->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;
}
}
1 change: 1 addition & 0 deletions src/styles/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
@import "./comments.scss";
@import "./bbpress.scss";
@import "./editor.scss";
@import "./terms.scss";
6 changes: 6 additions & 0 deletions src/styles/terms.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Terms
.gutenberg-support-loaded {
textarea#description, textarea#tag-description {
display: none;
}
}