Changeset 2588465
- Timestamp:
- 08/25/2021 12:17:59 PM (5 years ago)
- Location:
- safe-block-editor
- Files:
-
- 9 added
- 4 edited
-
assets/screenshot-1.png (modified) (previous)
-
tags/1.2 (added)
-
tags/1.2/css (added)
-
tags/1.2/css/block-editor.css (added)
-
tags/1.2/index.php (added)
-
tags/1.2/js (added)
-
tags/1.2/js/block-editor.js (added)
-
tags/1.2/licence.txt (added)
-
tags/1.2/readme.txt (added)
-
tags/1.2/safe-block-editor.php (added)
-
trunk/js/block-editor.js (modified) (2 diffs)
-
trunk/readme.txt (modified) (6 diffs)
-
trunk/safe-block-editor.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
safe-block-editor/trunk/js/block-editor.js
r2317115 r2588465 1 1 wp.domReady(function () { 2 2 // Disable the richtext formats 3 if (safeEditorSettings.formats ) {4 for ( let [format, value] of Object.entries(safeEditorSettings.formats)) {3 if (safeEditorSettings.formatsBlacklist) { 4 for (const [format, value] of Object.entries(safeEditorSettings.formatsBlacklist)) { 5 5 if (false == value) { 6 6 wp.richText.unregisterFormatType(format); 7 7 } 8 8 } 9 } 10 11 // Disable styles 12 if(safeEditorSettings.stylesBlackList){ 13 for (const [block, styles] of Object.entries(safeEditorSettings.stylesBlackList)) { 14 styles.forEach(style => { 15 wp.blocks.unregisterBlockStyle( block, style ); 16 }); 17 }; 9 18 } 10 19 }); … … 26 35 27 36 // Override block settings 28 blockSettings = Object.assign({}, blockSettings, { supports: supports, }); 29 30 // Maybe override styles 31 if (safeEditorSettings.stylesBlackList.hasOwnProperty(blockName)) { 32 const blacklistedStyles = safeEditorSettings.stylesBlackList[blockName]; 33 blockSettings.styles = blockSettings.styles.filter(function (style) { 34 return blacklistedStyles.indexOf(style.name) === -1; 35 }); 36 } 37 blockSettings = Object.assign({}, blockSettings, { supports }); 37 38 38 39 return blockSettings; -
safe-block-editor/trunk/readme.txt
r2441357 r2588465 3 3 Contributors: modernplugins, vincentdubroeucq 4 4 Tags: editor, blocks, block editor 5 Requires at least: 5. 06 Tested up to: 5. 5.37 Stable tag: 1. 15 Requires at least: 5.8 6 Tested up to: 5.8 7 Stable tag: 1.2 8 8 Requires PHP: 5.6 9 9 License: GPL v3 or later … … 20 20 * Font size picker and custom font size 21 21 * Custom padding and units 22 * Color palette, and color picker 22 * Custom spacing 23 * Color palette, color picker, and duotone filters 24 * Link color and text color 23 25 * Gradients 24 26 * Wide and full alignments … … 30 32 * Columns 31 33 * Media & Text 32 * Group33 34 * Custom HTML 34 35 * Verse 35 36 * Pullquote 36 * All widgets, including Shortcode 37 * Site Logo 38 * Site Title 39 * Site Tagline 40 * All blocks related to theme/template editing 41 * All widgets, including Shortcode, except on widgets admin page and customizer. 37 42 38 43 Toolbar formats removed : … … 40 45 * Inline image 41 46 * H1 removed 47 * Superscript 48 * Subscript 49 * Keyboard input 42 50 43 51 Block styles removed : … … 73 81 == Changelog == 74 82 83 = 1.2 = 84 * Removed blocks related to theme/template editing 85 * Refactored removal of support for previous experimental features 86 75 87 = 1.1 = 76 88 * Remove custom units, custom paddings, dropcap image editing, and block patterns … … 81 93 == Upgrade Notice == 82 94 95 = 1.2 = 96 * Removed blocks related to theme/template editing 97 * Refactored removal of support for previous experimental features 98 83 99 = 1.1 = 84 100 * Remove custom units, custom paddings, dropcap image editing, and block patterns -
safe-block-editor/trunk/safe-block-editor.php
r2441357 r2588465 3 3 * Plugin Name: Safe Block Editor by WPMarmite 4 4 * Description: Simplifies your authoring experience by removing distracting options in the WordPress editor. 5 * Version: 1. 15 * Version: 1.2 6 6 * Author: Modern Plugins 7 7 * Author URI: https://modernplugins.com/ … … 11 11 * Text Domain: safe-block-editor 12 12 * Domain Path: languages/ 13 * Requires at least: 5.0 14 * Tested up to: 5.5.3 13 * Requires at least: 5.8 14 * Requires PHP : 7.0 15 * Tested up to: 5.8 15 16 */ 16 17 … … 38 39 add_action( 'after_setup_theme', 'safe_block_editor_setup', 999 ); 39 40 /** 40 * Disable the custom color picker.41 * Override theme settings 41 42 */ 42 43 function safe_block_editor_setup() { 43 44 44 // Disable font sizes. Keep theme font sizes only 45 // $theme_font_sizes = get_theme_support( 'editor-font-sizes' ); 46 // $disable_font_sizes = apply_filters( 'safe_block_editor_disable_font_sizes', empty( $theme_font_sizes ) ); 47 // if( $disable_font_sizes ) { 48 // add_theme_support( 'editor-font-sizes' ); 49 // } 50 add_theme_support( 'editor-font-sizes' ); 45 // Disable all font sizes settings. 46 add_theme_support( 'editor-font-sizes', array() ); 51 47 add_theme_support( 'disable-custom-font-sizes' ); 52 48 53 // Disable colors. By default, keep theme's palette. 54 // $theme_palette = get_theme_support( 'editor-color-palette' ); 55 // $disable_palette = apply_filters( 'safe_block_editor_disable_color_palette', empty( $theme_palette ) ); 56 // if( $disable_palette ) { 57 // add_theme_support( 'editor-color-palette' ); 58 // } 59 add_theme_support( 'editor-color-palette' ); 49 // Disable all color settings. 50 add_theme_support( 'editor-color-palette', array() ); 60 51 add_theme_support( 'disable-custom-colors' ); 61 52 62 // Disable gradients. By default keep theme's gradients 63 // $theme_gradients = get_theme_support( 'editor-gradient-presets' ); 64 // $disable_gradients = apply_filters( 'safe_block_editor_disable_gradient_presets', empty( $theme_gradients ) ); 65 // if( $disable_gradients ) { 66 // add_theme_support( 'editor-gradient-presets', array() ); 67 // add_theme_support( '__experimental-editor-gradient-presets', array() ); 68 // } 53 // Disable gradients. 69 54 add_theme_support( 'editor-gradient-presets', array() ); 70 add_theme_support( '__experimental-editor-gradient-presets', array() );71 55 add_theme_support( 'disable-custom-gradients' ); 72 add_theme_support( '__experimental-disable-custom-gradients' );73 56 74 // Disable unneeded functionnality 75 if( get_theme_support( 'align-wide' ) ){ 76 remove_theme_support( 'align-wide' ); 77 } 78 if( get_theme_support( 'custom-line-height' ) ){ 79 remove_theme_support( 'custom-line-height' ); 80 } 81 if( get_theme_support( 'custom-units' ) ){ 82 add_theme_support( 'custom-units', array() ); 83 } 84 if( get_theme_support( 'custom-spacing' ) ){ 85 remove_theme_support('custom-spacing'); 86 } 87 if( get_theme_support( 'core-block-patterns' ) ){ 88 remove_theme_support( 'core-block-patterns' ); 89 } 90 } 91 92 93 add_filter( 'block_editor_settings', 'safe_block_editor_editor_settings', 10, 2 ); 94 /** 95 * Disables image editing 96 * 97 * @param array $settings Settings of the editor. 98 * @param WP_Post $post Current post 99 * @return array $settings 100 */ 101 function safe_block_editor_editor_settings( $settings, $post ){ 57 // Disable other functionnalities. 58 remove_theme_support( 'align-wide' ); 59 remove_theme_support( 'custom-line-height' ); 60 remove_theme_support( 'core-block-patterns' ); 61 remove_theme_support( 'custom-spacing' ); 62 add_theme_support( 'custom-units', array() ); 63 } 64 65 66 add_filter( 'block_editor_settings_all', 'safe_block_editor_block_editor_settings', 100, 2 ); 67 /** 68 * Overrides default editor settings 69 * 70 * @param array $settings Settings of the editor. 71 * @param WP_Block_Editor_Context $context Block editor context 72 * @return array $settings 73 */ 74 function safe_block_editor_block_editor_settings( $settings, $context ){ 75 $settings['alignWide'] = false; 76 $settings['fontSizes'] = false; 77 $settings['colors'] = false; 78 $settings['gradients'] = false; 102 79 $settings['imageEditing'] = false; 80 $settings['disableCustomColors'] = true; 81 $settings['disableCustomFontSizes'] = true; 82 $settings['disableCustomGradients'] = true; 83 $settings['enableCustomLineHeight'] = false; 84 $settings['enableCustomSpacing'] = false; 85 $settings['enableCustomUnits'] = false; 86 $settings['__experimentalBlockPatterns'] = array(); 87 $settings['__experimentalBlockPatternCategories'] = array(); 88 $settings['__experimentalFeatures']['typography']['dropCap'] = false; 89 $settings['__experimentalFeatures']['spacing']['customMargin'] = false; 90 $settings['__experimentalFeatures']['color']['duotone'] = false; 91 $settings['__experimentalFeatures']['color']['customDuotone'] = false; 92 $settings['__experimentalFeatures']['color']['link'] = false; 103 93 return $settings; 104 94 } … … 106 96 107 97 /** 108 * Returns an array of block editor settings to override 109 */ 110 function safe_block_editor_get_settings(){ 111 $settings = [ 112 'supports' => safe_block_editor_get_supports(), 113 'formats' => safe_block_editor_get_richtext_formats(), 114 'stylesBlackList' => safe_block_editor_get_styles_blacklist(), 115 'blocksBlacklist' => safe_block_editor_get_blocks_blacklist(), 116 ]; 117 return apply_filters( 'safe_block_editor_settings', $settings ); 118 } 119 120 121 /** 122 * Returns rich text formats to override 123 * 98 * Returns rich text formats to de-register. 124 99 * Passing false to a format will disable it. 100 * 101 * @return array $formats 125 102 */ 126 103 function safe_block_editor_get_richtext_formats(){ 127 104 $formats = array( 128 'core/image' => false, 105 'core/image' => false, 106 'core/text-color' => false, 107 'core/superscript' => false, 108 'core/subscript' => false, 109 'core/keyboard' => false, 129 110 ); 130 111 return apply_filters( 'safe_block_editor_richtext_formats', $formats ); … … 134 115 /** 135 116 * Returns blocks to remove 117 * 118 * @return array $blocks 136 119 */ 137 120 function safe_block_editor_get_blocks_blacklist(){ 121 $widgets = array( 122 'core/shortcode', 123 'core/archives', 124 'core/calendar', 125 'core/categories', 126 'core/html', 127 'core/latest-comments', 128 'core/latest-posts', 129 'core/page-list', 130 'core/rss', 131 'core/social-links', 132 'core/social-link', 133 'core/tag-cloud', 134 'core/search', 135 ); 136 138 137 $blocks = array( 139 'core/cover',140 'core/html',141 'core/verse',142 'core/pullquote',143 'core/group',144 138 'core/column', 145 139 'core/columns', 140 'core/cover', 146 141 'core/media-text', 147 'core/categories', 148 'core/latest-comments', 149 'core/latest-posts', 150 'core/calendar', 151 'core/rss', 152 'core/search', 153 'core/social-links', 154 'core/social-link', 155 'core/archives', 156 'core/shortcode', 157 'core/tag-cloud', 158 ); 142 'core/pullquote', 143 'core/verse', 144 'core/site-logo', 145 'core/site-title', 146 'core/site-tagline', 147 'core/query', 148 'core/query-title', 149 'core/query-pagination', 150 'core/query-pagination-next', 151 'core/query-pagination-previous', 152 'core/query-pagination-number', 153 'core/post-title', 154 'core/post-content', 155 'core/post-date', 156 'core/post-excerpt', 157 'core/post-featured-image', 158 'core/post-terms', 159 'core/loginout', 160 ); 161 162 $screen = get_current_screen(); 163 if( 'post' === $screen->base ){ 164 $blocks = array_merge( $blocks, $widgets ); 165 } 166 159 167 return apply_filters( 'safe_block_editor_blocks_blacklist', $blocks ); 160 168 } … … 162 170 163 171 /** 164 * Returns block styles to override 165 * Passing an empty array will disable all styles. 172 * Returns block styles to de-register 173 * Passing an empty array will disable all styles. 174 * 175 * @return array $styles 166 176 */ 167 177 function safe_block_editor_get_styles_blacklist(){ … … 179 189 /** 180 190 * Returns the supports overrides 191 * 192 * @return array $supports 181 193 */ 182 194 function safe_block_editor_get_supports(){ 183 195 $supports = array( 184 196 'anchor' => false, 185 // 'customClassName' => false,186 // 'lightBlockWrapper' => true,187 197 'html' => false, 188 198 'reusable' => false, 189 '__experimentalLineheight' => false,190 '__experimentalEnableRichImageEditing' => false,191 '__experimentalFeatures' => array(192 'typography' => array(193 'dropCap' => false194 ),195 ),196 199 ); 197 200 return apply_filters( 'safe_block_editor_supports', $supports ); 201 } 202 203 204 /** 205 * Returns an array of block editor settings to override or de-register 206 * 207 * @return array $settings 208 */ 209 function safe_block_editor_get_settings(){ 210 $settings = [ 211 'supports' => safe_block_editor_get_supports(), 212 'formatsBlacklist' => safe_block_editor_get_richtext_formats(), 213 'stylesBlackList' => safe_block_editor_get_styles_blacklist(), 214 'blocksBlacklist' => safe_block_editor_get_blocks_blacklist(), 215 ]; 216 return apply_filters( 'safe_block_editor_settings', $settings ); 198 217 } 199 218 … … 205 224 function safe_block_editor_block_editor_scripts() { 206 225 $version = get_plugin_data( __FILE__, false, false )['Version']; 207 wp_enqueue_script( 'safe-block-editor-js', SAFE_BLOCK_EDITOR_URL . 'js/block-editor.js', array( 'wp- blocks', 'wp-hooks', 'wp-dom-ready', 'wp-edit-post' ), $version, true );226 wp_enqueue_script( 'safe-block-editor-js', SAFE_BLOCK_EDITOR_URL . 'js/block-editor.js', array( 'wp-hooks', 'wp-dom-ready' ), $version, true ); 208 227 wp_enqueue_style( 'safe-block-editor', SAFE_BLOCK_EDITOR_URL . 'css/block-editor.css', array(), $version ); 209 228 wp_localize_script( 'safe-block-editor-js', 'safeEditorSettings', safe_block_editor_get_settings() );
Note: See TracChangeset
for help on using the changeset viewer.