diff --git a/includes/functions/_theme_setup.php b/includes/functions/_theme_setup.php index 868fd716..e0252281 100644 --- a/includes/functions/_theme_setup.php +++ b/includes/functions/_theme_setup.php @@ -647,7 +647,7 @@ function fictioneer_enqueue_block_editor_scripts() { wp_register_script( 'fictioneer-block-editor-scripts', get_template_directory_uri() . '/js/block-editor.min.js', - ['wp-blocks', 'wp-element', 'wp-components', 'wp-editor', 'wp-data', 'jquery'], + ['wp-dom-ready', 'wp-edit-post', 'wp-blocks', 'wp-element', 'wp-components', 'wp-editor', 'wp-data', 'jquery'], FICTIONEER_VERSION, true ); diff --git a/js/block-editor.min.js b/js/block-editor.min.js index 1aadb0d7..4465cb86 100644 --- a/js/block-editor.min.js +++ b/js/block-editor.min.js @@ -1 +1 @@ -wp.domReady((()=>{fictioneerData.userCapabilities?.manage_options||wp.data.dispatch("core/edit-post").removeEditorPanel("page-attributes"),fictioneerData.userCapabilities?.fcn_edit_permalink||wp.data.dispatch("core/edit-post").removeEditorPanel("post-link"),fictioneerData.userCapabilities?.fcn_select_page_template||wp.data.dispatch("core/edit-post").removeEditorPanel("template")})),wp.domReady((function(){setTimeout((()=>{document.querySelectorAll("label").forEach((e=>{"Stick to the top of the blog"===e.textContent&&(fictioneerData.userCapabilities?.fcn_make_sticky||e.closest(".components-panel__row").remove()),"Allow pingbacks & trackbacks"===e.textContent&&e.closest(".components-panel__row").remove()}))}),200)})); \ No newline at end of file +wp.domReady((()=>{if(fictioneerData.userCapabilities?.manage_options||wp.data.dispatch("core/edit-post").removeEditorPanel("page-attributes"),fictioneerData.userCapabilities?.fcn_edit_permalink||wp.data.dispatch("core/edit-post").removeEditorPanel("post-link"),fictioneerData.userCapabilities?.fcn_select_page_template||wp.data.dispatch("core/edit-post").removeEditorPanel("template"),setTimeout((()=>{document.querySelectorAll("label").forEach((e=>{"Stick to the top of the blog"===e.textContent&&(fictioneerData.userCapabilities?.fcn_make_sticky||e.closest(".components-panel__row").remove()),"Allow pingbacks & trackbacks"===e.textContent&&e.closest(".components-panel__row").remove()}))}),200),!fictioneerData.userCapabilities?.fcn_read_others_files){new MutationObserver((e=>{e.forEach((e=>{if(e.addedNodes&&e.addedNodes.length>0){const e=document.querySelector(".block-editor-inserter__tabs > .components-tab-panel__tabs");e&&e.remove()}}))})).observe(document.querySelector("#editor"),{childList:!0,subtree:!0})}})); \ No newline at end of file diff --git a/src/js/block-editor.js b/src/js/block-editor.js index df2749cd..73e395ea 100644 --- a/src/js/block-editor.js +++ b/src/js/block-editor.js @@ -6,6 +6,7 @@ // https://github.com/WordPress/gutenberg/tree/trunk/packages/edit-post/src/components/sidebar wp.domReady(() => { + // Page attributes if (!fictioneerData.userCapabilities?.manage_options) { wp.data.dispatch('core/edit-post').removeEditorPanel('page-attributes'); @@ -20,12 +21,8 @@ wp.domReady(() => { if (!fictioneerData.userCapabilities?.fcn_select_page_template) { wp.data.dispatch('core/edit-post').removeEditorPanel('template'); } -}); - - - -wp.domReady(function() { + // Sticky checkbox and pink-/trackbacks setTimeout(() => { document.querySelectorAll('label').forEach(element => { if (element.textContent === 'Stick to the top of the blog') { @@ -38,6 +35,26 @@ wp.domReady(function() { element.closest('.components-panel__row').remove(); } }); - }, 200); // Wait for async; not great, not terrible solution + }, 200); + + // Inserter media tab (insufficient but I cannot do better =/) + if (!fictioneerData.userCapabilities?.fcn_read_others_files) { + const fcn_editorObserver = new MutationObserver(mutations => { + mutations.forEach(mutation => { + if (mutation.addedNodes && mutation.addedNodes.length > 0) { + const hasMediaTab = document.querySelector('.block-editor-inserter__tabs > .components-tab-panel__tabs'); + + if (hasMediaTab) { + hasMediaTab.remove(); + } + } + }); + }); + + fcn_editorObserver.observe( + document.querySelector('#editor'), + { childList: true, subtree: true } + ); + } });