/** * Update the extension * * @return string * * @access public */ public function update() { $extension = AAM_Core_Request::post('extension'); $list = AAM_Core_API::getOption('aam-extension-license', array()); if (isset($list[$extension])) { $response = $this->install($list[$extension]); } else { $response = json_encode(array('status' => 'failure', 'error' => __('License key is missing.', AAM_KEY))); } return $response; }
/** * * @return type */ protected function getCurrentSubject() { $userId = AAM_Core_Request::get('user'); if ($userId) { $u = get_user_by('id', $userId); $subject = array('type' => 'user', 'id' => $userId, 'name' => $u->display_name ? $u->display_name : $u->user_nicename); } else { $roles = array_keys(get_editable_roles()); $role = array_shift($roles); $subject = array('type' => 'role', 'id' => $role, 'name' => AAM_Core_API::getRoles()->get_role($role)->name); } return (object) $subject; }
/** * Save AAM options * * Important notice! This function excepts "value" to be only boolean value * * @return string * * @access public */ public function save() { $object = AAM_Core_Request::post('object'); $objectId = AAM_Core_Request::post('objectId', 0); $param = AAM_Core_Request::post('param'); $value = filter_var(AAM_Core_Request::post('value'), FILTER_VALIDATE_BOOLEAN); $result = $this->getSubject()->save($param, $value, $object, $objectId); return json_encode(array('status' => $result ? 'success' : 'failure')); }
/** * Make sure that AAM UI Page is used * * @return boolean * * @access public */ public static function isAAM() { $page = AAM_Core_Request::get('page'); $action = AAM_Core_Request::post('action'); $intersect = array_intersect(array('aam', 'aamc'), array($page, $action)); return is_admin() && count($intersect); }
/** * Initiate HTTP request * * @param string $url Requested URL * @param bool $send_cookies Wheather send cookies or not * * @return WP_Error|array * * @access public */ public static function cURL($url, $send_cookies = TRUE) { $header = array('User-Agent' => AAM_Core_Request::server('HTTP_USER_AGENT')); $cookies = AAM_Core_Request::cookie(null, array()); $requestCookies = array(); if (is_array($cookies) && $send_cookies) { foreach ($cookies as $key => $value) { //SKIP PHPSESSID - some servers don't like it for security reason if ($key !== session_name()) { $requestCookies[] = new WP_Http_Cookie(array('name' => $key, 'value' => $value)); } } } return wp_remote_request($url, array('headers' => $header, 'cookies' => $requestCookies, 'timeout' => 5)); }
/** * Add new capability * * @return string * * @access public */ public function add() { $capability = trim(AAM_Core_Request::post('capability')); if ($capability) { //add the capability to administrator's role as default behavior AAM_Core_API::getRoles()->add_cap('administrator', $capability); $response = array('status' => 'success'); } else { $response = array('status' => 'failure'); } return json_encode($response); }
/** * Reset the object settings * * @return string * * @access public */ public function reset() { $type = trim(AAM_Core_Request::post('type')); $id = intval(AAM_Core_Request::post('id', 0)); $object = AAM_Backend_View::getSubject()->getObject($type, $id); if ($object instanceof AAM_Core_Object) { $result = $object->reset(); //clear cache do_action('aam-clear-cache-action', AAM_Backend_View::getSubject()); } else { $result = false; } return json_encode(array('status' => $result ? 'success' : 'failure')); }
/** * Make sure that AAM UI Page is used * * @return boolean * * @access public */ public static function isAAM() { $page = AAM_Core_Request::get('page'); $action = AAM_Core_Request::post('action'); return is_admin() && in_array('aam', array($page, $action)); }
/** * Save post properties * * @return string * * @access public */ public function save() { if ($this->checkLimit()) { $object = AAM_Core_Request::post('object'); $objectId = AAM_Core_Request::post('objectId', 0); $param = AAM_Core_Request::post('param'); $value = filter_var(AAM_Core_Request::post('value'), FILTER_VALIDATE_BOOLEAN); $result = AAM_Backend_View::getSubject()->save($param, $value, $object, $objectId); } else { $result = false; $error = __('You reached your limitation.', AAM_KEY); } return json_encode(array('status' => $result ? 'success' : 'failure', 'error' => empty($error) ? '' : $error)); }
/** * Edit role name * * @return string * * @access public */ public function edit() { $result = AAM_Backend_View::getSubject()->update(trim(AAM_Core_Request::post('name'))); return json_encode(array('status' => $result ? 'success' : 'failure')); }
/** * Query database for list of users * * Based on filters and settings get the list of users from database * * @return \WP_User_Query * * @access public */ public function query() { $search = trim(AAM_Core_Request::request('search.value')); $args = array('number' => '', 'blog_id' => get_current_blog_id(), 'role' => AAM_Core_Request::request('role'), 'fields' => 'all', 'number' => AAM_Core_Request::request('length'), 'offset' => AAM_Core_Request::request('start'), 'search' => $search ? $search . '*' : '', 'search_columns' => array('user_login', 'user_email', 'display_name'), 'orderby' => 'user_nicename', 'order' => 'ASC'); return new WP_User_Query($args); }
/** * Make sure that AAM UI Page is used * * @return boolean * * @access public */ public static function isAAM() { return AAM_Core_Request::get('page') == 'aam'; }
/** * Get Post ID * * Replication of the same mechanism that is in wp-admin/post.php * * @return WP_Post|null * * @access public */ public function getPost() { if (get_post()) { $post = get_post(); } elseif ($post_id = AAM_Core_Request::get('post')) { $post = get_post($post_id); } elseif ($post_id = AAM_Core_Request::get('post_ID')) { $post = get_post($post_id); } else { $post = null; } return $post; }
/** * Save AAM utility options * * Important notice! This function excepts "value" to be only boolean value * * @return string * * @access protected */ protected function save() { $param = AAM_Core_Request::post('param'); $value = filter_var(AAM_Core_Request::post('value'), FILTER_VALIDATE_BOOLEAN); $data = AAM_Core_API::getOption('aam-utilities', array()); $data[$param] = $value; AAM_Core_API::updateOption('aam-utilities', $data); if ($param == 'caching' && !$value) { //clear cache if turned off AAM_Core_API::updateOption('aam-cache', array()); } return json_encode(array('status' => 'success')); }
/** * Print plugin localization * * @param string $localKey * * @return void * * @access protected */ protected function printLocalization($localKey) { $user = AAM_Core_Request::get('user'); $roles = array_keys(get_editable_roles()); $role = array_shift($roles); wp_localize_script($localKey, 'aamLocal', array('nonce' => wp_create_nonce('aam_ajax'), 'ajaxurl' => admin_url('admin-ajax.php'), 'url' => array('site' => admin_url('index.php'), 'jsbase' => AAM_MEDIA . '/js/aam', 'editUser' => admin_url('user-edit.php'), 'addUser' => admin_url('user-new.php')), 'subject' => array('type' => $user ? 'user' : 'role', 'id' => $user ? $user : $role, 'blog' => get_current_blog_id()), 'welcome' => AAM_Core_API::getOption('aam-welcome', 1))); }