当前位置: 首页>>代码示例>>PHP>>正文


PHP WP_Admin_Bar::get_nodes方法代码示例

本文整理汇总了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);
         }
     }
 }
开发者ID:xwp,项目名称:wp-customize-snapshots,代码行数:23,代码来源:class-customize-snapshot-manager.php

示例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);
         }
     }
 }
开发者ID:thejimbirch,项目名称:randy,代码行数:34,代码来源:AdminBarEditor.php


注:本文中的WP_Admin_Bar::get_nodes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。