/** * Add New Role * * @return string * * @access public */ public function add() { $name = trim(aam_Core_Request::post('name')); $roles = new WP_Roles(); if (aam_Core_ConfigPress::getParam('aam.native_role_id') === 'true') { $role_id = strtolower($name); } else { ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////// SIGOES ////////////////////////////////////////////////////////////////////////// //$role_id = 'aamrole_' . uniqid(); // QUITA EL CODIGO DEL ROL EN WP_CAPABILITIES $role_id = $name; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } //if inherited role is set get capabilities from it $parent = trim(aam_Core_Request::post('inherit')); if ($parent && $roles->get_role($parent)) { $caps = $roles->get_role($parent)->capabilities; } else { $caps = array(); } if ($roles->add_role($role_id, $name, $caps)) { $response = array('status' => 'success', 'role' => $role_id); } else { $response = array('status' => 'failure'); } return json_encode($response); }
/** * Register feature * * @return void * * @access protected */ protected function registerFeature() { //add feature $capability = aam_Core_ConfigPress::getParam('aam.feature.my_feature.capability', 'administrator'); if (current_user_can($capability)) { add_action('admin_print_scripts', array($this, 'printScripts')); add_action('admin_print_styles', array($this, 'printStyles')); aam_View_Collection::registerFeature((object) array('uid' => 'my_feature', 'position' => 100, 'title' => __('My Feature', 'aam'), 'subjects' => array(aam_Control_Subject_Role::UID, aam_Control_Subject_User::UID, aam_Control_Subject_Visitor::UID), 'controller' => $this)); } }
/** * Register new UI feature * * @return void * * @access protected */ protected function registerFeature() { $capability = aam_Core_ConfigPress::getParam('aam.feature.activity_log.capability', 'administrator'); if (current_user_can($capability)) { add_action('admin_print_scripts', array($this, 'printScripts')); add_action('admin_print_styles', array($this, 'printStyles')); add_filter('aam_ajax_call', array($this, 'ajax'), 10, 2); add_action('aam_localization_labels', array($this, 'localizationLabels')); aam_View_Collection::registerFeature((object) array('uid' => 'activity_log', 'position' => 35, 'title' => __('Activity Log', 'aam'), 'subjects' => array(aam_Control_Subject_Role::UID, aam_Control_Subject_User::UID), 'controller' => $this)); } }
/** * Load active extensions * * @return void * * @access public */ public function load() { //iterate through each active extension and load it foreach (scandir($this->_basedir) as $module) { if (!in_array($module, array('.', '..'))) { $status = aam_Core_ConfigPress::getParam("aam.extension.{$module}.status"); if (strtolower($status) !== 'off') { $this->bootstrapExtension($module); } } } }
/** * Constructor * * @param aam $parent * * @return void * * @access public */ public function __construct(aam $parent) { parent::__construct($parent); if (is_admin()) { add_action('admin_print_scripts', array($this, 'printScripts')); add_action('aam_post_features_render', array($this, 'postFeatureRender')); add_filter('aam_ajax_call', array($this, 'ajax'), 10, 2); add_filter('aam_capability_groups', array($this, 'capabilityGroups')); add_filter('aam_capability_group', array($this, 'capabilityGroup'), 10, 2); add_filter('comment_row_actions', array($this, 'commentRowActions'), 10, 2); add_filter('aam_core_setting', array($this, 'coreSettings'), 10, 2); //control post type registration for ADD action add_action('registered_post_type', array($this, 'registredPostType'), 999, 2); //legacy add_filter('wpaccess_restrict_limit', array($this, 'extendAccess')); } add_filter('aam_post_access_option', array($this, 'postAccessOption'), 10, 2); add_filter('aam_term_access_option', array($this, 'termAccessOption'), 10, 2); if (aam_Core_ConfigPress::getParam('aam.page_category', 'true') == 'true') { register_taxonomy('page_category', 'page', array('hierarchical' => TRUE, 'rewrite' => TRUE, 'public' => TRUE, 'show_ui' => TRUE, 'show_in_nav_menus' => TRUE)); } //add post filter for LIST restriction add_filter('the_posts', array($this, 'thePosts'), 999, 2); }
/** * Filter old activities * * Based on aam.extension.AAM_Activity_Log.date config, filter old activities * * @return void * * @access public */ public function filter() { $date = strtotime(aam_Core_ConfigPress::getParam('aam.extension.AAM_Activity_Log.date', 'today - 30 days')); foreach ($this->_option as $user_id => $activities) { if (is_array($activities)) { foreach ($activities as $timestamp => $activity) { if ($timestamp < $date) { unset($this->_option[$user_id][$timestamp]); } } } } }
/** * Save ConfigPress * * @return string * * @access protected */ protected function saveConfigPress() { $result = aam_Core_ConfigPress::write(aam_Core_Request::post('config')); return json_encode(array('status' => $result === false ? 'failure' : 'success')); }
/** * Save ConfigPress * * @return string * * @access public */ public function saveConfigPress() { if (current_user_can(aam_Core_ConfigPress::getParam('aam.menu.configpress.capability', 'administrator'))) { $result = aam_Core_ConfigPress::write(aam_Core_Request::post('config')); } else { $result = false; } return json_encode(array('status' => $result === false ? 'failure' : 'success')); }
/** * Desctruct the subject * * Execute extra actions during application shutdown * * @return void * * @access public */ public function saveCache() { $caching = aam_Core_ConfigPress::getParam('aam.caching', 'false'); if ($this->_updateCache === true && $caching === "true") { $this->updateCache(); } }
/** * Register Admin Menu * * @return void * * @access public */ public function adminMenu() { //register the menu add_menu_page(__('AAM', 'aam'), __('AAM', 'aam'), aam_Core_ConfigPress::getParam('aam.page.access_control.capability', 'administrator'), 'aam', array($this, 'content'), AAM_BASE_URL . 'active-menu.png'); //register submenus add_submenu_page('aam', __('Access Control', 'aam'), __('Access Control', 'aam'), aam_Core_ConfigPress::getParam('aam.page.access_control.capability', 'administrator'), 'aam', array($this, 'content')); add_submenu_page('aam', __('ConfigPress', 'aam'), __('ConfigPress', 'aam'), aam_Core_ConfigPress::getParam('aam.page.configpress.capability', 'administrator'), 'aam-configpress', array($this, 'configPressContent')); add_submenu_page('aam', __('Extensions', 'aam'), __('Extensions', 'aam'), aam_Core_ConfigPress::getParam('aam.page.extensions.capability', 'administrator'), 'aam-ext', array($this, 'extensionContent')); }
/** * Register feature * * The Feature Example Extension has UI interface. That is why it is very * important to make sure that it is backend (there is no need to load this * Extension if user is browsing frontend). * * From release 2.5, each Extension has its own capability assigned to it. By * default all Extensions have capability "Administrator" but this can be changed * with ConfigPress setting aam.feature.[you feature ID].capability. * For more information about this part of functionality chech official AAM * tutorial "AAM Super Admin" http://wpaam.com/tutorials/aam-super-admin/ * * @return void * * @access protected */ protected function registerFeature() { //add feature $capability = aam_Core_ConfigPress::getParam('aam.feature.' . self::FEATURE_ID . '.capability', 'administrator'); //makre sure that current user has access to current Extension. This is //mandatory check and should be obeyed by all developers if (current_user_can($capability)) { //register the Extension's javascript add_action('admin_print_scripts', array($this, 'printScripts')); //register the Extension's stylesheet add_action('admin_print_styles', array($this, 'printStyles')); //register the Feature aam_View_Collection::registerFeature((object) array('uid' => self::FEATURE_ID, 'position' => 150, 'title' => __('Feature Example', 'aam'), 'subjects' => array(aam_Control_Subject_Role::UID, aam_Control_Subject_User::UID, aam_Control_Subject_Visitor::UID), 'controller' => $this)); } }
/** * Take control over wp_die function * * @param callback $function * * @return void * * @access public */ public function wpDie($function) { $redirect = aam_Core_ConfigPress::getParam('backend.access.deny.redirect'); $message = aam_Core_ConfigPress::getParam('backend.access.deny.message', __('Access denied', 'aam')); if (filter_var($redirect, FILTER_VALIDATE_URL)) { wp_redirect($redirect); exit; } elseif (is_int($redirect)) { wp_redirect(get_post_permalink($redirect)); exit; } else { call_user_func($function, $message, '', array()); } }
/** * * @return type */ public function isLoginLockoutOn() { $login_lock = aam_Core_ConfigPress::getParam('security.login.lockout', 'false'); return $login_lock == 'true' ? true : false; }
/** * Check if current user is super admin * * Super admin is someone who is allowed to manage all roles and users. This * user is defined in ConfigPress parameter aam.super_admin * * @return boolean * * @access public * @static */ public static function isSuperAdmin() { if (is_multisite()) { $response = is_super_admin(); } else { $super_admin = aam_Core_ConfigPress::getParam('aam.super_admin', 0); $response = $super_admin == get_current_user_id() ? true : false; } return $response; }
/** * Parse ConfigPress file and create an object * * @param string $filename * * @return void * * @access protected * @static */ protected static function parseConfig($filename) { //include third party library if (!class_exists('Zend_Config')) { require_once AAM_LIBRARY_DIR . 'Zend/Exception.php'; require_once AAM_LIBRARY_DIR . 'Zend/Config/Exception.php'; require_once AAM_LIBRARY_DIR . 'Zend/Config.php'; require_once AAM_LIBRARY_DIR . 'Zend/Config/Ini.php'; } //parse ini file try { self::$_config = new Zend_Config_Ini($filename); } catch (Zend_Config_Exception $e) { //do nothing } }
/** * Register Admin Menu * * @return void * * @access public */ public function adminMenu() { //register submenus add_submenu_page('aam', __('Security', 'aam'), __('Security', 'aam'), aam_Core_ConfigPress::getParam('aam.page.security.capability', 'administrator'), 'aam-security', array($this, 'content')); }
/** * Read the Post AAM Metadata * * Get all settings related to specified post * * @return void * * @access public */ public function read() { $option = get_post_meta($this->getPost()->ID, $this->getOptionName(), true); //try to inherit it from parent category if (empty($option) && aam_Core_ConfigPress::getParam('aam.post.inherit', 'true') == 'true') { $terms = $this->retrievePostTerms(); //use only first term for inheritance $term_id = array_shift($terms); //try to get any parent access $option = $this->inheritAccess($term_id); } //even if parent category is empty, try to read the parent subject if (empty($option)) { $option = $this->getSubject()->readParentSubject(self::UID, $this->getPost()->ID); } $this->setOption(apply_filters('aam_post_access_option', $option, $this)); }
/** * * @param type $object_id */ public function init($object_id) { if ($object_id) { //initialize term first $term = get_term($object_id, $this->getTaxonomy($object_id)); if ($term && !is_wp_error($term)) { $this->setTerm($term); $access = $this->getSubject()->readOption(self::UID, $this->getTerm()->term_id); $inherit = aam_Core_ConfigPress::getParam('aam.term.inherit', 'true'); if (empty($access) && $inherit == 'true') { //try to get any parent restriction $access = $this->inheritAccess($this->getTerm()->parent); } //even if parent category is empty, try to read the parent subject if (empty($access)) { $access = $this->getSubject()->readParentSubject(self::UID, $this->getTerm()->term_id); } $this->setOption(apply_filters('aam_term_access_option', $access, $this)); } } }