Created
February 4, 2013 21:48
-
-
Save WebBaker/4710011 to your computer and use it in GitHub Desktop.
Can be inserted inside your theme's functions.php file to conditionally hide Eventbrite Tickets user profile fields for users who do not need that functionality.
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
/** | |
* Hides the Eventbrite Tickets fields from user profiles, unless the user is on the exception | |
* list. | |
*/ | |
class EventbriteProfileFieldsHider { | |
protected $exceptionList = array(1); | |
/** | |
* Any users who still need to see the Eventbrite Tickets fields in their profile should be | |
* specified as an array of integers. By default, if no arguments are passed in, it is assumed | |
* that they should still be visible for user #1 (the normal root admin). | |
* | |
* @param array $exceptions | |
*/ | |
public function __construct(array $exceptions = null) { | |
// Change the default exception list (which is just user #1 - the default admin in most cases) | |
if ($exceptions !== null) $this->exceptionList = $exceptions; | |
// Conditionally remove the Eventbrite Tickets fields from the user profile | |
add_action('admin_init', array($this, 'maybeRemoveFields'), 50); | |
} | |
public function maybeRemoveFields() { | |
$user = wp_get_current_user(); | |
if (is_object($user) and isset($user->ID) and !in_array($user->ID, $this->exceptionList)) { | |
$eventbriteTickets = Event_Tickets_PRO::instance(); | |
remove_action('show_user_profile', array($eventbriteTickets, 'userProfilePage')); | |
remove_action('edit_user_profile', array($eventbriteTickets, 'userProfilePage')); | |
} | |
} | |
} | |
// Let the (Eventbrite Tickets profile) fields be visible for the following users (by ID) | |
$allow = array(1, 2, 3, 4); | |
// Hide the fields for everyone else | |
new EventbriteProfileFieldsHider($allow); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment