本文整理汇总了PHP中WP_Admin_Bar::get_nodes方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Admin_Bar::get_nodes方法的具体用法?PHP WP_Admin_Bar::get_nodes怎么用?PHP WP_Admin_Bar::get_nodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Admin_Bar
的用法示例。
在下文中一共展示了WP_Admin_Bar::get_nodes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: remove_all_non_snapshot_admin_bar_links
/**
* Remove all admin bar nodes that have links and which aren't for snapshots.
*
* @param \WP_Admin_Bar $wp_admin_bar Admin bar.
*/
public function remove_all_non_snapshot_admin_bar_links($wp_admin_bar)
{
if (empty($this->snapshot)) {
return;
}
$snapshot_admin_bar_node_ids = array('customize', 'exit-customize-snapshot', 'inspect-customize-snapshot');
foreach ($wp_admin_bar->get_nodes() as $node) {
if (in_array($node->id, $snapshot_admin_bar_node_ids, true) || '#' === substr($node->href, 0, 1)) {
continue;
}
$parsed_link_url = wp_parse_url($node->href);
$parsed_home_url = wp_parse_url(home_url('/'));
$is_external_link = isset($parsed_link_url['host']) && $parsed_link_url['host'] !== $parsed_home_url['host'] || isset($parsed_link_url['path']) && 0 !== strpos($parsed_link_url['path'], $parsed_home_url['path']) || (!isset($parsed_link_url['query']) || !preg_match('#(^|&)customize_snapshot_uuid=#', $parsed_link_url['query']));
if ($is_external_link) {
$wp_admin_bar->remove_node($node->id);
}
}
}
示例2: setAdminBarOrder
/**
* Sort admin bar nodes according to a list of IDs.
*
* This method will re-arrange the admin bar to match the key order of the $order array.
* Any nodes that don't have a matching key will be moved to the end of the admin bar.
*
* @param WP_Admin_Bar $adminBar
* @param array $order An array indexed by node ID.
*/
protected function setAdminBarOrder($adminBar, $order)
{
//Unfortunately, WP_Admin_Bar has no "sort" or "move_node" method, and it is not possible
//to add one because the $nodes array is private. So we'll have to do this the hard way.
$nodes = $adminBar->get_nodes();
//1. Remove all nodes.
foreach ($nodes as $wpNode) {
$adminBar->remove_node($wpNode->id);
}
//2. Add them back in the right order.
foreach ($order as $id => $unusedValue) {
if (isset($nodes[$id])) {
//Hidden nodes have been removed by this point.
$wpNode = $nodes[$id];
$adminBar->add_node($wpNode);
unset($nodes[$id]);
}
}
//3. Add back any left-over nodes (theoretically, this should never happen).
if (!empty($nodes)) {
foreach ($nodes as $wpNode) {
$adminBar->add_node($wpNode);
}
}
}