Last active
May 18, 2023 13:37
-
-
Save zackpyle/ab72b8b819130de1b5d46b4b9fda1469 to your computer and use it in GitHub Desktop.
Remove All Custom Taxonomy Sidebar Metaboxes #cptui #wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // ignore - for formatting only | |
// Useful if you are creating custom taxonomines and controlling them with ACF. This will remove all the metaboxes for your custom taxonomies | |
function edit_taxonomy_args( $args, $tax_slug, $cptui_tax_args ) { | |
// Set to false for all taxonomies created with CPTUI. | |
$args['meta_box_cb'] = false; | |
return $args; | |
} | |
add_filter( 'cptui_pre_register_taxonomy', 'edit_taxonomy_args', 10, 3 ); | |
add_filter( 'rest_prepare_taxonomy', function( $response, $taxonomy, $request ){ | |
$context = ! empty( $request['context'] ) ? $request['context'] : 'view'; | |
// Context is edit in the editor | |
if( $context === 'edit' && $taxonomy->meta_box_cb === false ){ | |
$data_response = $response->get_data(); | |
$data_response['visibility']['show_ui'] = false; | |
$response->set_data( $data_response ); | |
} | |
return $response; | |
}, 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment