public function menu_editor() { if (!$this->can_edit_role_menus()) { $this->main->permission_denied(); die; } global $wp_roles; $this->roles = $wp_roles->get_names(); if (isset($this->roles[self::ADMINISTRATOR_ROLE_KEY])) { unset($this->roles[self::ADMINISTRATOR_ROLE_KEY]); } natcasesort($this->roles); $this->current_role = NULL; if (!empty($_GET['role'])) { $role = $_GET['role']; if (array_key_exists($role, $this->roles)) { $this->current_role = get_role($role); } } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $this->main->verify_nonce(); if (!empty($_POST['role'])) { $role = $_POST['role']; if (array_key_exists($role, $this->roles)) { $this->current_role = get_role($role); if ($this->current_role !== NULL) { if (!empty($_POST['submit']) && !empty($_POST['parent-menu']) && !empty($_POST['child-menu'])) { $parent_menu = $_POST['parent-menu']; $child_menu = $_POST['child-menu']; if (!is_array($parent_menu)) { $parent_menu = array(); } if (!is_array($child_menu)) { $child_menu = array(); } $this->override_type = self::OVERRIDE_TYPE_SOFT; if (!empty($_POST['override-type'])) { $this->override_type = $_POST['override-type']; if ($this->override_type !== self::OVERRIDE_TYPE_HARD) { $this->override_type = self::OVERRIDE_TYPE_SOFT; } } $this->set_override_type($this->current_role, $this->override_type); if (!empty($_POST['hide-new-menus'])) { $this->set_hide_new_menus($this->current_role, 1); } else { $this->set_hide_new_menus($this->current_role, 0); } if (!empty($_POST['disable-for-secondary-role'])) { $this->set_disable_for_secondary_role($this->current_role, 1); } else { $this->set_disable_for_secondary_role($this->current_role, 0); } $entity = new WPFront_User_Role_Editor_Entity_Menu_Editor(); $table_data = $entity->get_all_by_role($this->current_role->name); $table_data = $this->index_table_data($table_data); foreach ($parent_menu as $key => $value) { $key = $this->decode_menu_key($key); $entity = NULL; if (isset($table_data[$key])) { $entity = $table_data[$key]->entity; } if ($entity === NULL) { $entity = new WPFront_User_Role_Editor_Entity_Menu_Editor(); } $entity->set_role($this->current_role->name); $entity->set_menu_slug($key); $entity->set_parent_menu_slug(''); $entity->set_enabled($value === 'true'); $entity->save(); } foreach ($child_menu as $parent_key => $submenus) { $parent_key = $this->decode_menu_key($parent_key); foreach ($submenus as $child_key => $value) { $child_key = $this->decode_menu_key($child_key); $entity = NULL; if (isset($table_data[$parent_key])) { if (isset($table_data[$parent_key]->children[$child_key])) { $entity = $table_data[$parent_key]->children[$child_key]->entity; } } if ($entity === NULL) { $entity = new WPFront_User_Role_Editor_Entity_Menu_Editor(); } $entity->set_role($this->current_role->name); $entity->set_menu_slug($child_key); $entity->set_parent_menu_slug($parent_key); $entity->set_enabled($value === 'true'); $entity->save(); } } $this->result = (object) array('status' => TRUE, 'message' => $this->__('Menu changes saved.')); } if (!empty($_POST['doaction'])) { if (!empty($_POST['copyfrom'])) { if ($_POST['copyfrom'] === '_restore_') { $this->delete_override_type($this->current_role); $this->delete_hide_new_menus($this->current_role); $this->delete_disable_for_secondary_role($this->current_role); $entity = new WPFront_User_Role_Editor_Entity_Menu_Editor(); $entity->delete_all($this->current_role->name); $this->result = (object) array('status' => TRUE, 'message' => $this->__('Menu defaults restored.')); } } } } } } } if (!empty($this->roles) && $this->current_role === NULL) { reset($this->roles); $this->current_role = get_role(key($this->roles)); } if ($this->current_role === NULL) { wp_die($this->__('No editable roles found on this site.')); return; } $this->override_type = $this->get_override_type($this->current_role); $this->hide_new_menu = $this->get_hide_new_menus($this->current_role); $this->disable_for_secondary_role = $this->get_disable_for_secondary_role($this->current_role); $menu = $this->wp_menu; $submenu = $this->wp_submenu; $this->menu = array(); $entity = new WPFront_User_Role_Editor_Entity_Menu_Editor(); $table_data = $entity->get_all_by_role($this->current_role->name); $table_data = $this->index_table_data($table_data); foreach ($menu as $pos => $value) { if ($this->is_menu_separator($value)) { $this->menu[] = NULL; } else { $parent_slug = $this->escape_customize_slug($value[2]); $parent_cap = $this->escape_customize_capability($value[1]); $obj = (object) array('slug' => $parent_slug, 'name' => $this->remove_html($value[0]), 'capability' => $parent_cap, 'page' => $value[3], 'has_capability' => $this->current_role->has_cap($parent_cap), 'children' => array(), 'disabled' => !$this->current_role->has_cap($parent_cap), 'has_access' => $this->has_access($this->current_role, $this->hide_new_menu, $table_data, $parent_slug)); if (array_key_exists($obj->slug, $submenu)) { $children = $submenu[$obj->slug]; foreach ($children as $key => $sub) { $child_slug = $this->escape_customize_slug($sub[2]); $child_cap = $this->escape_customize_capability($sub[1]); $obj->children[] = (object) array('name' => $this->remove_html($sub[0]), 'capability' => $child_cap, 'page' => '', 'slug' => $child_slug, 'has_capability' => $this->current_role->has_cap($child_cap), 'disabled' => !$this->current_role->has_cap($child_cap), 'has_access' => $this->has_access($this->current_role, $this->hide_new_menu, $table_data, $child_slug, $value[2])); if ($this->current_role->has_cap($child_cap)) { $obj->disabled = FALSE; } } } $this->menu[] = $obj; } } include $this->main->pluginDIR() . 'templates/personal-pro/menu-editor.php'; }