Further restrict media access

This commit is contained in:
Tetrakern 2023-08-15 19:03:43 +02:00
parent 5e746bcc2d
commit 9466b9d444
3 changed files with 25 additions and 8 deletions

View File

@ -647,7 +647,7 @@ function fictioneer_enqueue_block_editor_scripts() {
wp_register_script( wp_register_script(
'fictioneer-block-editor-scripts', 'fictioneer-block-editor-scripts',
get_template_directory_uri() . '/js/block-editor.min.js', 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, FICTIONEER_VERSION,
true true
); );

View File

@ -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)})); 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})}}));

View File

@ -6,6 +6,7 @@
// https://github.com/WordPress/gutenberg/tree/trunk/packages/edit-post/src/components/sidebar // https://github.com/WordPress/gutenberg/tree/trunk/packages/edit-post/src/components/sidebar
wp.domReady(() => { wp.domReady(() => {
// Page attributes // Page attributes
if (!fictioneerData.userCapabilities?.manage_options) { if (!fictioneerData.userCapabilities?.manage_options) {
wp.data.dispatch('core/edit-post').removeEditorPanel('page-attributes'); wp.data.dispatch('core/edit-post').removeEditorPanel('page-attributes');
@ -20,12 +21,8 @@ wp.domReady(() => {
if (!fictioneerData.userCapabilities?.fcn_select_page_template) { if (!fictioneerData.userCapabilities?.fcn_select_page_template) {
wp.data.dispatch('core/edit-post').removeEditorPanel('template'); wp.data.dispatch('core/edit-post').removeEditorPanel('template');
} }
});
wp.domReady(function() {
// Sticky checkbox and pink-/trackbacks
setTimeout(() => { setTimeout(() => {
document.querySelectorAll('label').forEach(element => { document.querySelectorAll('label').forEach(element => {
if (element.textContent === 'Stick to the top of the blog') { if (element.textContent === 'Stick to the top of the blog') {
@ -38,6 +35,26 @@ wp.domReady(function() {
element.closest('.components-panel__row').remove(); 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 }
);
}
}); });