private function display_editor_ui()
 {
     //Prepare a bunch of parameters for the editor.
     $editor_data = array('message' => isset($this->get['message']) ? intval($this->get['message']) : null, 'images_url' => plugins_url('images', $this->plugin_file), 'hide_advanced_settings' => $this->options['hide_advanced_settings'], 'show_extra_icons' => $this->options['show_extra_icons'], 'settings_page_url' => $this->get_settings_page_url(), 'show_deprecated_hide_button' => $this->options['show_deprecated_hide_button'], 'dashicons_available' => wp_style_is('dashicons', 'done'));
     //Build a tree struct. for the default menu
     $default_tree = ameMenu::wp2tree($this->default_wp_menu, $this->default_wp_submenu);
     $default_menu = ameMenu::load_array($default_tree);
     //Is there a custom menu?
     if (!empty($this->merged_custom_menu)) {
         $custom_menu = $this->merged_custom_menu;
     } else {
         //Start out with the default menu if there is no user-created one
         $custom_menu = $default_menu;
     }
     //The editor doesn't use the color CSS. Including it would just make the page bigger and waste bandwidth.
     unset($custom_menu['color_css']);
     unset($custom_menu['color_css_modified']);
     //Encode both menus as JSON
     $editor_data['default_menu_js'] = ameMenu::to_json($default_menu);
     $editor_data['custom_menu_js'] = ameMenu::to_json($custom_menu);
     //Create a list of all known capabilities and roles. Used for the drop-down list on the access field.
     $all_capabilities = ameRoleUtils::get_all_capabilities();
     //"level_X" capabilities are deprecated so we don't want people using them.
     //This would look better with array_filter() and an anonymous function as a callback.
     for ($level = 0; $level <= 10; $level++) {
         $cap = 'level_' . $level;
         if (isset($all_capabilities[$cap])) {
             unset($all_capabilities[$cap]);
         }
     }
     $all_capabilities = array_keys($all_capabilities);
     natcasesort($all_capabilities);
     //Multi-site installs also get the virtual "Super Admin" cap, but only the Super Admin sees it.
     if (is_multisite() && !isset($all_capabilities['super_admin']) && is_super_admin()) {
         array_unshift($all_capabilities, 'super_admin');
     }
     $editor_data['all_capabilities'] = $all_capabilities;
     //Create a list of all roles, too.
     $all_roles = ameRoleUtils::get_role_names();
     asort($all_roles);
     $editor_data['all_roles'] = $all_roles;
     //Include hint visibility settings
     $editor_data['show_hints'] = $this->get_hint_visibility();
     require dirname(__FILE__) . '/editor-page.php';
 }
 /**
  * Get user roles by parsing their capabilities.
  *
  * This method is reliable because it determines user roles the same way that WordPress does. However, it's also
  * relatively "slow" (~ 25 microseconds on my dev. system). Don't call it directly. Use get_user_roles() instead -
  * it caches results.
  *
  * @see WP_User::get_role_caps
  *
  * @param WP_User $user
  * @return array
  */
 private function extract_user_roles($user)
 {
     if (empty($user->caps) || !is_array($user->caps)) {
         return !empty($user->roles) ? $user->roles : array();
     }
     $wp_roles = ameRoleUtils::get_roles();
     return array_filter(array_keys($user->caps), array($wp_roles, 'is_role'));
 }
 private function display_editor_ui()
 {
     //Prepare a bunch of parameters for the editor.
     $editor_data = array('message' => isset($this->get['message']) ? intval($this->get['message']) : null, 'images_url' => $this->plugin_dir_url . '/images', 'hide_advanced_settings' => $this->options['hide_advanced_settings']);
     //Build a tree struct. for the default menu
     $default_tree = ameMenu::wp2tree($this->default_wp_menu, $this->default_wp_submenu);
     $default_menu = ameMenu::load_array($default_tree);
     //Is there a custom menu?
     if (!empty($this->merged_custom_menu)) {
         $custom_menu = $this->merged_custom_menu;
     } else {
         //Start out with the default menu if there is no user-created one
         $custom_menu = $default_menu;
     }
     //Encode both menus as JSON
     $editor_data['default_menu_js'] = ameMenu::to_json($default_menu);
     $editor_data['custom_menu_js'] = ameMenu::to_json($custom_menu);
     //Create a list of all known capabilities and roles. Used for the drop-down list on the access field.
     $all_capabilities = ameRoleUtils::get_all_capabilities();
     //"level_X" capabilities are deprecated so we don't want people using them.
     //This would look better with array_filter() and an anonymous function as a callback.
     for ($level = 0; $level <= 10; $level++) {
         $cap = 'level_' . $level;
         if (isset($all_capabilities[$cap])) {
             unset($all_capabilities[$cap]);
         }
     }
     $all_capabilities = array_keys($all_capabilities);
     natcasesort($all_capabilities);
     $editor_data['all_capabilities'] = $all_capabilities;
     //Create a list of all roles, too.
     $all_roles = ameRoleUtils::get_role_names();
     //Multi-site installs also get the virtual "Super Admin" role
     if (is_multisite() && !isset($all_roles['super_admin'])) {
         $all_roles['super_admin'] = 'Super Admin';
     }
     asort($all_roles);
     $editor_data['all_roles'] = $all_roles;
     //Include hint visibility settings
     $editor_data['show_hints'] = $this->get_hint_visibility();
     require dirname(__FILE__) . '/editor-page.php';
 }
 public function getScriptData()
 {
     //Pass the list of installed plugins and their state (active/inactive) to UI JavaScript.
     $installedPlugins = get_plugins();
     $activePlugins = array_map('plugin_basename', wp_get_active_and_valid_plugins());
     $activeNetworkPlugins = array();
     if (function_exists('wp_get_active_network_plugins')) {
         //This function is only available on Multisite.
         $activeNetworkPlugins = array_map('plugin_basename', wp_get_active_network_plugins());
     }
     $plugins = array();
     foreach ($installedPlugins as $pluginFile => $header) {
         $isActiveForNetwork = in_array($pluginFile, $activeNetworkPlugins);
         $isActive = in_array($pluginFile, $activePlugins);
         $plugins[] = array('fileName' => $pluginFile, 'name' => $header['Name'], 'description' => isset($header['Description']) ? $header['Description'] : '', 'isActive' => $isActive || $isActiveForNetwork);
     }
     //Flag roles that can manage plugins.
     $canManagePlugins = array();
     $wpRoles = ameRoleUtils::get_roles();
     foreach ($wpRoles->role_objects as $id => $role) {
         $canManagePlugins[$id] = $this->canManagePlugins($id, $role);
     }
     return array('settings' => $this->getSettings(), 'installedPlugins' => $plugins, 'canManagePlugins' => $canManagePlugins, 'isMultisite' => is_multisite(), 'isProVersion' => $this->menuEditor->is_pro_version(), 'dismissNoticeNonce' => wp_create_nonce('ws_ame_dismiss_pv_usage_notice'), 'adminAjaxUrl' => admin_url('admin-ajax.php'));
 }
Exemple #5
0
 /**
  * Check if a role has a specific capability, ignoring virtual capabilities.
  *
  * @param string $role_id
  * @param string $capability
  * @return bool
  */
 private function role_has_real_cap($role_id, $capability)
 {
     $roles = ameRoleUtils::get_roles();
     $role = $roles->get_role($role_id);
     /** @var WP_Role $role */
     $this->disable_virtual_caps = true;
     $has_cap = $role && ($role->has_cap($capability) || $capability == $role->name);
     $this->disable_virtual_caps = false;
     return $has_cap;
 }