-
estacion.visual
Dear support
Do you have any code to disable or hide this box in all Posts, Pages and CPTs for non-admin users?
Looking forward to your comments.
Best regards -
Fernando
Hi there,
It’s possible but you’ll need to use a Child theme because a JS file needs to be enqueued.
We’ll be referring to this thread to do this: https://wordpress.stackexchange.com/questions/339436/removing-panels-meta-boxes-in-the-block-editor/339437#339437
You need to create a js directory in your Child theme with this file inside:
block-script.js
.The code should be something like this:
<script> wp.domReady( function() { var unregisterPlugin = wp.plugins.unregisterPlugin; unregisterPlugin( 'generatepress-elements-info-panel' ); } ); </script>
Then, you need to add a PHP like this to enqueue your JS file:
function cc_gutenberg_register_files() { if (!current_user_can('activate_plugins')) { // script file wp_register_script( 'cc-block-script', get_stylesheet_directory_uri() .'/js/block-script.js', // adjust the path to the JS file array( 'wp-blocks', 'wp-edit-post' ) ); // register block editor script register_block_type( 'cc/ma-block-files', array( 'editor_script' => 'cc-block-script' ) ); } } add_action( 'init', 'cc_gutenberg_register_files' );
Adding PHP: https://docs.generatepress.com/article/adding-php/
-
estacion.visual
Hi Fernando
Thanks for replying so fast.
Is this possible to do through a code inserted into the plugin ‘Code Snippet’ instead to use a child theme?
Here greeting you another Fernando.
Best regards -
Hi there,
with the Code Snippet plugin, you could try this snippet to simply hide the panel:
function hide_gpp_element_panel() { if (!current_user_can('activate_plugins')) { ?> <style> .gpp-element-info-panel { display: none !important; } </style> <?php } } add_action('admin_footer', 'hide_gpp_element_panel');
-
estacion.visual
Hi David
Thanks for replying so fast.
Yes, that works, but I am wondering if is it possible by avoiding using CSS and do it through Code Snippet. -
If you want to remove the Elements Info panel in post editor entirely for non-admin users then try this snippet:
function inline_custom_gutenberg_script() { if (!current_user_can('activate_plugins')) { ?> <script> document.addEventListener('DOMContentLoaded', function () { if (typeof wp !== 'undefined' && typeof wp.plugins !== 'undefined') { var unregisterPlugin = wp.plugins.unregisterPlugin; unregisterPlugin('generatepress-elements-info-panel'); } }); </script> <?php } } add_action('admin_footer', 'inline_custom_gutenberg_script');
-
estacion.visual
Excellent David. That works!
Thanks so much.
Have a nice day. -
Glad to hear that
- You must be logged in to reply to this topic.