Support

Home Forums Event Espresso Premium Removing EE Screen Options and Metaboxes programatically (for all users).

Removing EE Screen Options and Metaboxes programatically (for all users).

Posted: May 14, 2015 at 9:12 pm


Dan

May 14, 2015 at 9:12 pm

Hey EE –

I’ve spent a long few hours trying to solve this, and I hope you have a simple, easy answer for me. ๐Ÿ™‚

How can I hook into the admin page load for your CPTs (specifically Events and Venues) to remove support for certain metaboxes – YOUR metaboxes?

I’m trying to lock down the admin interface for my client. For their uses, Venues will only need a Title, Slug, Physical Location (City, State), and a custom field. Events will have similar limits.

I am familiar with the remove_post_type_support function and remove_meta_box and I’ve successfully used both to remove default metaboxes from both Venues and Events (author, tags, editor, etc). But, I’m unsure of how to return a list of metabox objects for a given admin screen, so that I can remove them programmatically. I would very much prefer not to hide anything with CSS, but rather remove the metaboxes entirely when the admin page loads.

FWIW, this customization can be applied for all users and roles in the site.

Can you help me with this?
Thanks in advance.


Dean

May 15, 2015 at 8:45 am

Hi Phil,

I understand how you felt! I roped one of our developers into helping me track down what to do to save some time.

The EE Admin system has a lot of complicated functionality in it to support the feature requests customers have made so for some things its not as straightforward as normal WordPress admin page routes/functions.

Here’s some example code to remove metaboxes from the Events and Venue routes:

PLEASE NOTE: Currently EE expects data from the forms in those boxes when an event/venue is saved, and will likely throw an error if that data is not present. So removing the metaboxes completely will likely result in errors. If you want to retain any data that’s already on an event, or prevent the errors, you will need to ensure you print hidden form fields in the loaded page that have the existing data (or default data on new events/venues) OR you will need to hook into the save/update process to handle when there’s no expected data (and either preserve existing data in related tables or add default data that EE expects for other systems). If you need further help with this use case, it falls outside the services we provide with a support license and you will need to request custom development for more detailed assistance.

Please use this provided code with caution and test your changes thoroughly on a development server first!

https://github.com/eventespresso/ee-code-snippet-library/tree/master/admin


function remove_em_all_venues() {
  //ee related
  remove_meta_box( 'espresso_venue_gmap_options', 'espresso_venues', 'side' );
  remove_meta_box( 'espresso_venue_virtual_loc_options', 'espresso_venues', 'side' );
  remove_meta_box( 'espresso_venue_categoriesdiv', 'espresso_venues', 'side' );
  remove_meta_box( 'espresso_venue_address_options', 'espresso_venues', 'side' );
}
add_action( 'add_meta_boxes', 'remove_em_all_venues', 20);

function remove_em_all_events() {
  
  //options
  remove_meta_box( 'espresso_event_editor_event_options', 'espresso_events', 'side' );

  //categories
  remove_meta_box( 'espresso_event_categoriesdiv', 'espresso_events', 'side' );

  //primary questions
  remove_meta_box( 'espresso_events_Registration_Form_Hooks_Extend_primary_questions_metabox', 'espresso_events', 'side' );

  //additional qquestions
  remove_meta_box( 'espresso_events_Registration_Form_Hooks_Extend_additional_questions_metabox', 'espresso_events', 'side' );

  //venue
  remove_meta_box( 'espresso_events_Venues_Hooks_venue_metabox_metabox', 'espresso_events', 'normal' );

  //tickets
  remove_meta_box( 'espresso_events_Pricing_Hooks_pricing_metabox_metabox', 'espresso_events', 'normal' );

  //notifications
  remove_meta_box( 'espresso_events_Messages_Hooks_Extend_messages_metabox_metabox', 'espresso_events', 'advanced' );

}
add_action( 'admin_enqueue_scripts', 'remove_em_all_events', 30);


Dan

May 15, 2015 at 9:48 am

Woot!

Used the snippet for Venues (so far) and it works perfectly. Thanks for the quick and complete response.

Related Followup: For a couple of these metaboxes/groups, I would like to hide partial information.

i.e. for Venues:
1) for Physical location, all I want to show is the City, State, and country – hiding the Address lines, and zip code.
2) in the Publish box, all I want to show is Status, Visibility, and Published date – hiding the Venue Website, Capacity, and Phone.

Is there a filter to do this?


Lorenzo Orlando Caum

  • Support Staff

May 15, 2015 at 10:14 am

Hi Phil, hiding parts of those metaboxes isn’t available at this time via a filter. However, that may be possible by adding some CSS to target specific areas with display none.


Lorenzo


Dan

May 15, 2015 at 10:57 am

Got it. I will give that a try. Thank you!

The support post ‘Removing EE Screen Options and Metaboxes programatically (for all users).’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso