Plugin Directory

Changeset 2588465


Ignore:
Timestamp:
08/25/2021 12:17:59 PM (5 years ago)
Author:
modernplugins
Message:

Removed duotone, link color, and major cleanup

Location:
safe-block-editor
Files:
9 added
4 edited

Legend:

Unmodified
Added
Removed
  • safe-block-editor/trunk/js/block-editor.js

    r2317115 r2588465  
    11wp.domReady(function () {
    22    // 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)) {
    55            if (false == value) {
    66                wp.richText.unregisterFormatType(format);
    77            }
    88        }
     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        };
    918    }
    1019});
     
    2635
    2736    // 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 }); 
    3738
    3839    return blockSettings;
  • safe-block-editor/trunk/readme.txt

    r2441357 r2588465  
    33Contributors: modernplugins, vincentdubroeucq
    44Tags: editor, blocks, block editor
    5 Requires at least: 5.0
    6 Tested up to: 5.5.3
    7 Stable tag: 1.1
     5Requires at least: 5.8
     6Tested up to: 5.8
     7Stable tag: 1.2
    88Requires PHP: 5.6
    99License: GPL v3 or later
     
    2020* Font size picker and custom font size
    2121* 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
    2325* Gradients
    2426* Wide and full alignments
     
    3032* Columns
    3133* Media & Text
    32 * Group
    3334* Custom HTML
    3435* Verse
    3536* 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.
    3742
    3843Toolbar formats removed :
     
    4045* Inline image
    4146* H1 removed
     47* Superscript
     48* Subscript
     49* Keyboard input
    4250
    4351Block styles removed :
     
    7381== Changelog ==
    7482
     83= 1.2 =
     84* Removed blocks related to theme/template editing
     85* Refactored removal of support for previous experimental features 
     86
    7587= 1.1 =
    7688* Remove custom units, custom paddings, dropcap image editing, and block patterns
     
    8193== Upgrade Notice ==
    8294
     95= 1.2 =
     96* Removed blocks related to theme/template editing
     97* Refactored removal of support for previous experimental features 
     98
    8399= 1.1 =
    84100* Remove custom units, custom paddings, dropcap image editing, and block patterns
  • safe-block-editor/trunk/safe-block-editor.php

    r2441357 r2588465  
    33 * Plugin Name:        Safe Block Editor by WPMarmite
    44 * Description:        Simplifies your authoring experience by removing distracting options in the WordPress editor.
    5  * Version:            1.1
     5 * Version:            1.2
    66 * Author:             Modern Plugins
    77 * Author URI:         https://modernplugins.com/
     
    1111 * Text Domain:        safe-block-editor
    1212 * 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
    1516 */
    1617
     
    3839add_action( 'after_setup_theme', 'safe_block_editor_setup', 999 );
    3940/**
    40  * Disable the custom color picker.
     41 * Override theme settings
    4142 */
    4243function safe_block_editor_setup() {
    4344
    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() );
    5147    add_theme_support( 'disable-custom-font-sizes' );
    5248
    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() );
    6051    add_theme_support( 'disable-custom-colors' );
    6152   
    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.
    6954    add_theme_support( 'editor-gradient-presets', array() );
    70     add_theme_support( '__experimental-editor-gradient-presets', array() );
    7155    add_theme_support( 'disable-custom-gradients' );
    72     add_theme_support( '__experimental-disable-custom-gradients' );
    7356   
    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
     66add_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 */
     74function safe_block_editor_block_editor_settings( $settings, $context ){
     75    $settings['alignWide']    = false;
     76    $settings['fontSizes']    = false;
     77    $settings['colors']       = false;
     78    $settings['gradients']    = false;
    10279    $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;
    10393    return $settings;
    10494}
     
    10696
    10797/**
    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.
    12499 * Passing false to a format will disable it.
     100 *
     101 * @return  array  $formats
    125102 */
    126103function safe_block_editor_get_richtext_formats(){
    127104    $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,
    129110    );
    130111    return apply_filters( 'safe_block_editor_richtext_formats', $formats );
     
    134115/**
    135116 * Returns blocks to remove
     117 *
     118 * @return  array  $blocks
    136119 */
    137120function 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
    138137    $blocks = array(
    139         'core/cover',
    140         'core/html',
    141         'core/verse',
    142         'core/pullquote',
    143         'core/group',
    144138        'core/column',
    145139        'core/columns',
     140        'core/cover',
    146141        '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
    159167    return apply_filters( 'safe_block_editor_blocks_blacklist', $blocks );
    160168}
     
    162170
    163171/**
    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
    166176 */
    167177function safe_block_editor_get_styles_blacklist(){
     
    179189/**
    180190 * Returns the supports overrides
     191 *
     192 * @return  array  $supports
    181193 */
    182194function safe_block_editor_get_supports(){
    183195    $supports = array(
    184196        'anchor'          => false,
    185         // 'customClassName' => false,
    186         // 'lightBlockWrapper' => true,
    187197        'html'            => false,
    188198        'reusable'        => false,
    189         '__experimentalLineheight' => false,
    190         '__experimentalEnableRichImageEditing' => false,
    191         '__experimentalFeatures' => array(
    192             'typography' => array(
    193                 'dropCap' => false
    194             ),
    195         ),
    196199    );
    197200    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 */
     209function 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 );
    198217}
    199218
     
    205224function safe_block_editor_block_editor_scripts() {
    206225    $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 );
    208227    wp_enqueue_style( 'safe-block-editor', SAFE_BLOCK_EDITOR_URL . 'css/block-editor.css', array(), $version );
    209228    wp_localize_script( 'safe-block-editor-js', 'safeEditorSettings', safe_block_editor_get_settings() );
Note: See TracChangeset for help on using the changeset viewer.