[wp-trac] [WordPress Trac] #57379: A Way to Disable Export Theme
WordPress Trac
noreply at wordpress.org
Fri Oct 18 20:41:15 UTC 2024
#57379: A Way to Disable Export Theme
-------------------------------------+-------------------------------------
Reporter: unsalkorkmaz | Owner: (none)
Type: defect (bug) | Status: closed
Priority: normal | Milestone: 6.7
Component: Administration | Version: 6.1.1
Severity: major | Resolution: invalid
Keywords: needs-patch needs- | Focuses: accessibility,
design has-unit-tests | javascript, css, php-compatibility
-------------------------------------+-------------------------------------
Changes (by dilip2615):
* keywords: has-patch needs-unit-tests => needs-patch needs-design has-
unit-tests
* status: new => closed
* focuses: => accessibility, javascript, css, php-compatibility
* resolution: => invalid
Comment:
To disable the "Export Theme" button in WordPress, especially in the
context of the Gutenberg editor, you could take a few approaches. The
"Export Theme" button was added to help developers export their themes,
but it can cause issues if large directories like node_modules are
included.
Here are a few potential solutions:
1. Remove the Button via Filters
WordPress provides filters and hooks that can be used to modify the admin
area. You can try to remove the button by unhooking it or using JavaScript
to hide it.
Here’s an example of how you can hide the button using JavaScript or CSS:
a. Hide the Button with CSS
You can add custom CSS to your theme or via a plugin to hide the button:
{{{
/* Hide the Export Theme button */
button.editor-styles-wrapper .components-button.is-secondary[href*="theme-
export"] {
display: none !important;
}
}}}
b. Remove the Button Using JavaScript
You could also use JavaScript to remove the button when the editor loads.
Add the following JavaScript code to your theme or a custom plugin:
{{{
document.addEventListener('DOMContentLoaded', function() {
const exportButton = document.querySelector('button.components-button
.is-secondary[href*="theme-export"]');
if (exportButton) {
exportButton.style.display = 'none';
}
});
}}}
Customize the Theme Export Behavior
{{{
function exclude_large_folders_from_export( $theme_directory ) {
// Logic to exclude node_modules or other large directories
$exclude = array( 'node_modules', 'some-other-large-folder' );
return array_filter( $theme_directory, function ( $folder ) use (
$exclude ) {
return ! in_array( basename( $folder ), $exclude );
} );
}
add_filter( 'some_export_filter', 'exclude_large_folders_from_export' );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/57379#comment:15>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list