/** * {@inheritdoc } */ public function saveConfig() { $options = (object) array('menu' => $this->getMenu(), 'metaboxes' => $this->getMetaboxes(), 'capabilities' => $this->getCapabilities(), 'menu_order' => $this->getMenuOrder(), 'restrictions' => $this->getRestrictions(), 'excludes' => $this->getExcludes()); update_user_meta($this->getID(), WPACCESS_PREFIX . 'config', $options); mvb_Model_Cache::clearCache(); do_action(WPACCESS_PREFIX . 'do_save'); }
/** * {@inheritdoc } */ public function saveConfig() { $roles = mvb_Model_API::getRoleList(FALSE); if (isset($roles[$this->getID()])) { $roles[$this->getID()]['capabilities'] = $this->getCapabilities(); mvb_Model_API::updateBlogOption('user_roles', $roles); } $options = (object) array('menu' => $this->getMenu(), 'metaboxes' => $this->getMetaboxes(), 'menu_order' => $this->getMenuOrder(), 'restrictions' => $this->getRestrictions(), 'excludes' => $this->getExcludes()); mvb_Model_API::updateBlogOption(WPACCESS_PREFIX . 'config_' . $this->getID(), $options); mvb_Model_Cache::clearCache(); do_action(WPACCESS_PREFIX . 'do_save'); }
/** * Get User Access Config Object * * @param int $user_id * @param array $force_roles * @return object */ public static function getUserAccessConfig($user_id, $force_roles = FALSE) { if ($force_roles || !($config = mvb_Model_Cache::getCacheData('user', $user_id))) { $config = new mvb_Model_UserConfig($user_id); if (!$config->getID()) { //user is logged in $config = new mvb_Model_RoleConfig('_visitor'); } else { if (is_array($force_roles)) { $role_list = $force_roles; } else { $role_list = $config->getUser()->getRoles(); } //get first role and use as base //TODO - probably implement multirole support $r_config = mvb_Model_API::getRoleAccessConfig(array_shift($role_list)); if (!count($config->getMenu())) { $config->setMenu($r_config->getMenu()); } if (!count($config->getMetaboxes())) { $config->setMetaboxes($r_config->getMetaboxes()); } if (!count($config->getMenuOrder())) { $config->setMenuOrder($r_config->getMenuOrder()); } if (!count($config->getCapabilities())) { $config->setCapabilities($r_config->getCapabilities()); } //merge restrictions $role_restrs = $r_config->getRestrictions(); if (count($role_restrs)) { if (isset($role_restrs['post'])) { foreach ($role_restrs['post'] as $id => $data) { if (!$config->hasRestriction('post', $id)) { $config->addRestriction('post', $id, $data); } } } if (isset($role_restrs['taxonomy'])) { foreach ($role_restrs['taxonomy'] as $id => $data) { if (!$config->hasRestriction('taxonomy', $id)) { $config->addRestriction('taxonomy', $id, $data); } } } } if (!$force_roles) { mvb_Model_Cache::saveCacheData('user', $user_id, $config); } } } return $config; }
/** * * @param type $user_id */ public function edit_user_profile_update($user_id) { mvb_Model_Cache::removeUserCache($user_id); }
/** * Save menu order * * @return array */ protected function save_order() { $apply_all = $_POST['apply_all']; $role = $_POST['role']; $user = $_POST['user']; if ($user) { $config = mvb_Model_API::getUserAccessConfig($user); $config->setMenuOrder($_POST['menu']); $config->saveConfig(); } else { if ($apply_all) { foreach (mvb_Model_API::getRoleList() as $role => $dummy) { $config = mvb_Model_API::getRoleAccessConfig($role); $config->setMenuOrder($_POST['menu']); $config->saveConfig(); } } else { $config = mvb_Model_API::getRoleAccessConfig($role); $config->setMenuOrder($_POST['menu']); $config->saveConfig(); } } mvb_Model_Cache::clearCache(); return array('status' => 'success'); }