Created
October 29, 2011 02:06
-
-
Save danlamanna/1323994 to your computer and use it in GitHub Desktop.
Adding specific pods to the admin bar menu
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
add_filter('show_admin_bar', 'pods_admin_bar_displaying'); | |
/** | |
* Checks if the admin bar is being displayed for current user. | |
* | |
* @global bool $podsAdminBarEnabled | |
* @param bool $currentStatus | |
* @return bool | |
*/ | |
function pods_admin_bar_displaying($currentStatus) { | |
// If it is, we trigger the rest of the functionality from within here, | |
// not a huge fan of doing it this way, however lack of a decisive way to tell | |
// whether or not an admin bar is showing at the runtime of plugins. | |
if ($currentStatus === true) { | |
pods_admin_bar_check(); | |
} | |
return $currentStatus; | |
} | |
/** | |
* Checks to see if any pods are applicable to be added to the admin bar, | |
* if so, it adds the action to add them before it's rendered. | |
* | |
* @return bool Whether or not it came back with items to add. | |
*/ | |
function pods_admin_bar_check() { | |
global $adminBarPods; | |
// This assumes there will be a column in the table indicating the pod is included on the admin bar | |
$podsApi = new PodsAPI(); | |
$adminBarPods = $podsApi->load_pods(array('options' => array('use_admin_bar' => 1))); | |
if (!empty($adminBarPods)) { | |
add_action('wp_before_admin_bar_render', 'pods_admin_bar_items'); | |
return true; | |
} else { | |
return false; | |
} | |
} | |
/** | |
* Loops through all pods that have 'use_admin_bar' enabled, and adds them to the "Add New" | |
* menu on the admin bar front-end. | |
* | |
* @global obj $wp_admin_bar | |
* @global array $adminBarPods | |
*/ | |
function pods_admin_bar_items() { | |
global $wp_admin_bar, $adminBarPods; | |
foreach ($adminBarPods as $adminBarPod) { | |
// Determine the label, defaults to the actual label, falls back on the name. | |
$podTitle = ($adminBarPod['label']) ? $adminBarPod['label'] : $adminBarPod['name']; | |
$wp_admin_bar->add_menu(array('parent' => 'new-content', | |
'id' => 'wp-admin-bar-new' . $adminBarPod['name'], | |
'href' => get_admin_url() . 'admin.php?page=pod-' . $adminBarPod['name'] . '&action=add', | |
'title' => $podTitle, | |
'meta' => array('title' => 'Add New ' . $podTitle))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment