Browse Source

deny blocks

windhamdavid 1 week ago
parent
commit
0b8da4eec3
2 changed files with 58 additions and 9 deletions
  1. 4 0
      functions.php
  2. 54 9
      js/deny-list-blocks.js

+ 4 - 0
functions.php

@@ -268,6 +268,10 @@ function render_offcanvas_menu($attributes, $content) {
 remove_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' );
 remove_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' );
 add_filter('should_load_remote_block_patterns', '__return_false');
 add_filter('should_load_remote_block_patterns', '__return_false');
 add_filter('block_directory_enabled', '__return_false');
 add_filter('block_directory_enabled', '__return_false');
+add_filter( 'block_editor_settings_all', function( $settings, $context ) {
+	$settings['enableOpenverseMediaCategory'] = false;
+	return $settings;
+}, 10, 2 );
 
 
 /***********************************************************
 /***********************************************************
 ############### Disable Some Blocks ########################
 ############### Disable Some Blocks ########################

+ 54 - 9
js/deny-list-blocks.js

@@ -1,12 +1,6 @@
 wp.domReady(() => {
 wp.domReady(() => {
+    // Remove specific non-embed blocks
     const removeBlocks = [
     const removeBlocks = [
-        // Remove specific embeds
-        'core/embed-facebook',
-        'core/embed-instagram',
-        'core/embed-scribd',
-        'core/embed-tiktok',
-        'core/embed-twitter',
-        // Remove some core blocks
         'core/verse',
         'core/verse',
         'core/freeform',
         'core/freeform',
         'core/archives',
         'core/archives',
@@ -14,12 +8,20 @@ wp.domReady(() => {
         'core/tag-cloud',
         'core/tag-cloud',
         'core/rss',
         'core/rss',
         'core/latest-comments',
         'core/latest-comments',
-        'core/social-links'
+        'core/social-links',
+        'core/tags',
+        'core/comments',
+        'core/post-comments-form'
     ];
     ];
 
 
+    // Log available blocks for debugging
+    console.log('Available blocks:', wp.blocks.getBlockTypes().map(block => block.name));
+
+    // Remove specified core blocks
     removeBlocks.forEach(blockName => {
     removeBlocks.forEach(blockName => {
         try {
         try {
-            if (wp.blocks.getBlockType(blockName)) {
+            const block = wp.blocks.getBlockType(blockName);
+            if (block) {
                 wp.blocks.unregisterBlockType(blockName);
                 wp.blocks.unregisterBlockType(blockName);
                 console.log(`Successfully removed block: ${blockName}`);
                 console.log(`Successfully removed block: ${blockName}`);
             }
             }
@@ -27,4 +29,47 @@ wp.domReady(() => {
             console.warn(`Failed to remove block ${blockName}:`, error);
             console.warn(`Failed to remove block ${blockName}:`, error);
         }
         }
     });
     });
+
+    // Only remove specific embed variations
+    const removeEmbeds = [
+        'facebook',
+        'instagram',
+        'scribd',
+        'tiktok',
+        'twitter',
+        'tumblr',
+        'reddit',
+        'pinterest',
+        'smugmug',
+        'crowdsignal',
+        'kickstarter',
+        'mixcloud',
+        'spotify',
+        'soundcloud',
+        'bandcamp',
+        'flickr',
+        'wordpress',
+        'dailymotion',
+        'imgur',
+        'issuu',
+        'wolfram',
+        'reverbnation',
+        'cloudup',
+        'animoto',
+        'ted',
+        'bluesky',
+        'pocket',
+        'speaker-deck',
+        'videopress',
+        'pocket-casts',
+        'amazon-kindle',
+        'wolfram-cloud',
+        'wordpress-tv'
+    ];
+    wp.blocks.getBlockVariations('core/embed')?.forEach(variation => {
+        if (removeEmbeds.includes(variation.name)) {
+            wp.blocks.unregisterBlockVariation('core/embed', variation.name);
+            console.log(`Removed embed variation: ${variation.name}`);
+        }
+    });
 });
 });