/** * Resets roles to WordPress defaults. * * @return void */ function backupToolReset() { check_admin_referer('capsman-reset-defaults'); require_once ABSPATH . 'wp-admin/includes/schema.php'; if (!function_exists('populate_roles')) { ak_admin_error(__('Needed function to create default roles not found!', 'capsman-enhanced')); return; } $roles = array_keys(ak_get_roles(true)); foreach ($roles as $role) { remove_role($role); } populate_roles(); $this->cm->setAdminCapability(); $msg = __('Roles and Capabilities reset to WordPress defaults', 'capsman-enhanced'); if (function_exists('pp_populate_roles')) { pp_populate_roles(); } else { // force PP to repopulate roles $pp_ver = get_option('pp_c_version', true); if ($pp_ver && is_array($pp_ver)) { $pp_ver['version'] = preg_match("/dev|alpha|beta|rc/i", $pp_ver['version']) ? '0.1-beta' : 0.1; } else { $pp_ver = array('version' => '0.1', 'db_version' => '1.0'); } update_option('pp_c_version', $pp_ver); delete_option('ppperm_added_role_caps_10beta'); } ak_admin_notify($msg); }
/** * Manages global settings admin. * * @hook add_submenu_page * @return void */ function generalManager() { if (!current_user_can('manage_capabilities') && !current_user_can('administrator')) { // TODO: Implement exceptions. wp_die('<strong>' . __('What do you think you\'re doing?!?', 'capsman-enhanced') . '</strong>'); } if ('POST' == $_SERVER['REQUEST_METHOD']) { if (empty($_REQUEST['SaveRole']) && empty($_REQUEST['AddCap'])) { check_admin_referer('capsman-general-manager'); $this->processAdminGeneral(); } elseif (!empty($_REQUEST['SaveRole'])) { ak_admin_notify($this->message); // moved update operation to earlier action to avoid UI refresh issues. But outputting notification there breaks styling. } elseif (!empty($_REQUEST['AddCap'])) { ak_admin_notify($this->message); } } $this->generateNames(); $roles = array_keys($this->roles); if (isset($_GET['action']) && 'delete' == $_GET['action']) { require_once dirname(__FILE__) . '/handler.php'; $capsman_modify = new CapsmanHandler($this); $capsman_modify->adminDeleteRole(); } if (!in_array($this->current, $roles)) { // Current role has been deleted. $this->current = array_shift($roles); } include AK_CMAN_LIB . '/admin.php'; }
/** * Deletes a role. * The role comes from the $_GET['role'] var and the nonce has already been checked. * Default WordPress role cannot be deleted and if trying to do it, throws an error. * Users with the deleted role, are moved to the WordPress default role. * * @return void */ function adminDeleteRole() { global $wpdb, $wp_roles; check_admin_referer('delete-role_' . $_GET['role']); $this->cm->current = $_GET['role']; $default = get_option('default_role'); if ($default == $this->cm->current) { ak_admin_error(sprintf(__('Cannot delete default role. You <a href="%s">have to change it first</a>.', $this->cm->ID), 'options-general.php')); return; } $query = "SELECT ID FROM {$wpdb->usermeta} INNER JOIN {$wpdb->users} " . "ON {$wpdb->usermeta}.user_id = {$wpdb->users}.ID " . "WHERE meta_key='{$wpdb->prefix}capabilities' AND meta_value LIKE '%{$this->cm->current}%';"; $users = $wpdb->get_results($query); // Array of all roles except the one being deleted, for use below $role_names = array_diff_key(array_keys($wp_roles->role_names), array($this->cm->current => true)); $count = 0; foreach ($users as $u) { $skip_role_set = false; $user = new WP_User($u->ID); if ($user->has_cap($this->cm->current)) { // Check again the user has the deleting role // Role may have been assigned supplementally. Don't move a user to default role if they still have one or more roles following the deletion. foreach ($role_names as $_role_name) { if ($user->has_cap($_role_name)) { $skip_role_set = true; break; } } if (!$skip_role_set) { $user->set_role($default); $count++; } } } remove_role($this->cm->current); unset($this->cm->roles[$this->cm->current]); if ($customized_roles = get_option('pp_customized_roles')) { if (isset($customized_roles[$this->cm->current])) { unset($customized_roles[$this->cm->current]); update_option('pp_customized_roles', $customized_roles); } } ak_admin_notify(sprintf(__('Role has been deleted. %1$d users moved to default role %2$s.', $this->cm->ID), $count, $this->cm->roles[$default])); $this->cm->current = $default; }
/** * Saves activity settings from admin page. * * @return void */ private function saveAdminSettings() { check_admin_referer('alkivia-activity-settings'); if (isset($_POST['action']) && 'update' == $_POST['action']) { $post = stripslashes_deep($_POST['settings']); $post = array_merge($this->defaultOptions(), $post); $settings = array('timeout' => intval($post['timeout']), 'list_items' => intval($post['list_items']), 'avatar_size' => intval($post['avatar_size']), 'global_wall' => intval($post['global_wall']), 'wall_template' => $post['wall_template'], 'user_template' => $post['user_template']); $this->setNewOptions($settings); ak_admin_notify(); } else { // Missing action wp_die('Bad form received.', $this->PID); } }
/** * Saves settings from admin form. * TODO: Check settings with intval. * * @return void */ private function saveAdminSettings() { check_admin_referer('alkivia-profile-settings'); if (isset($_POST['action']) && 'update' == $_POST['action']) { $options = stripslashes_deep($_POST['profiles']); $this->setNewOptions($options); ak_admin_notify(); } else { // Missing action ak_admin_error(__('Bad form received.', $this->PID)); } }
/** * Deletes a role. * The role comes from the $_GET['role'] var and the nonce has already been checked. * Default WordPress role cannot be deleted and if trying to do it, throws an error. * Users with the deleted role, are moved to the WordPress default role. * * @return void */ function adminDeleteRole() { global $wpdb; check_admin_referer('delete-role_' . $_GET['role']); $this->cm->current = $_GET['role']; $default = get_option('default_role'); if ($default == $this->cm->current) { ak_admin_error(sprintf(__('Cannot delete default role. You <a href="%s">have to change it first</a>.', $this->cm->ID), 'options-general.php')); return; } $query = "SELECT ID FROM {$wpdb->usermeta} INNER JOIN {$wpdb->users} " . "ON {$wpdb->usermeta}.user_id = {$wpdb->users}.ID " . "WHERE meta_key='{$wpdb->prefix}capabilities' AND meta_value LIKE '%{$this->cm->current}%';"; $users = $wpdb->get_results($query); $count = count($users); foreach ($users as $u) { $user = new WP_User($u->ID); if ($user->has_cap($this->cm->current)) { // Check again the user has the deleting role $user->set_role($default); } } remove_role($this->cm->current); unset($this->cm->roles[$this->cm->current]); if ($customized_roles = get_option('pp_customized_roles')) { if (isset($customized_roles[$this->cm->current])) { unset($customized_roles[$this->cm->current]); update_option('pp_customized_roles', $customized_roles); } } ak_admin_notify(sprintf(__('Role has been deleted. %1$d users moved to default role %2$s.', $this->cm->ID), $count, $this->cm->roles[$default])); $this->cm->current = $default; }
/** * Process the uploaded image in the settings form. * @return void */ private function uploadLogo() { check_admin_referer('upload-login-image'); if (isset($_POST['action']) && 'upload' == $_POST['action']) { // Process uploaded file require_once AK_VENDOR . '/upload/class.upload.php'; $handle = new akUpload($_FILES['login_image'], $this->PID); if ($handle->uploaded) { $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_x = 326; $handle->file_overwrite = true; $handle->file_auto_rename = false; $handle->file_new_name_body = 'login'; $handle->image_convert = 'png'; $uploads = wp_upload_dir(); $folder = trailingslashit($uploads['basedir']) . 'alkivia'; $handle->Process($folder); if ($handle->processed) { ak_admin_notify(__('File uploaded.', $this->PID)); } else { ak_admin_error(__('Error', $this->PID) . ': ' . $handle->error); } } else { ak_admin_error(__('No file received.', $this->PID)); } } else { // Missing action ak_admin_error(__('Bad form received.', $this->PID)); } }
/** * Uploads a user image to gallery. * * @uses do_action() Calls 'aoc_gallery_first_upload' action hook on user ID. * @param object $user User Object to manage. * @return void */ private function uploadUserImage($user) { check_admin_referer('photo-gallery-upload'); $gallery = $this->getUserGallery($user->ID); $notices = ''; $errors = ''; $cur_num = 0; foreach ($_FILES as $user_picture) { $up_name = trim($user->user_nicename) . ($gallery['lastID'] + 1); $handle = new aocGalleryUpload($user_picture, $this->PID); ++$cur_num; if ($handle->uploaded) { // Upload big size. if ($handle->uploadImage($up_name)) { // Success upload. if (!empty($notices)) { $notices .= '<br />'; } if (!empty($errors)) { $errors .= '<br />'; } $notices .= sprintf(__('File %d uploaded.', $this->PID), $cur_num) . ' '; $generated_name = $handle->file_dst_name_body; // Create Thumbnail. if ($handle->createThumb()) { $notices .= sprintf(__('Thumbnail %d created.', $this->PID), $cur_num) . ' '; } else { $errors .= sprintf(__('Thumbnail %d error', $this->PID), $cur_num) . ': ' . $handle->error . ' '; } // Create AVATAR if ($handle->createAvatar()) { $notices .= sprintf(__('Avatar %d created.', $this->PID), $cur_num) . ' '; } else { $errors .= sprintf(__('Avatar %d error', $this->PID), $cur_num) . ': ' . $handle->error . ' '; } // Save the image name to user meta. ++$gallery['lastID']; if (0 == count($gallery['images'])) { // Loading first file $gallery['main'] = $gallery['lastID']; $gallery['avatar'] = $gallery['lastID']; } $approved = current_user_can('aoc_unmoderated') || current_user_can('aoc_manage_galleries') ? 1 : 0; $gallery['images'][$gallery['lastID']] = array('approved' => $approved, 'caption' => '', 'name' => $generated_name); update_usermeta($user->ID, $this->ID, $gallery); if ($approved) { // Set the last update time. Since 0.5.3 if (1 == $this->countApprovedImages($gallery)) { // Just uploaded first picture do_action('aoc_gallery_first_upload', $user->ID); } update_usermeta($user->ID, $this->ID . '_update', gmdate('Y-m-d H:i:s')); // Record activity log $activity = array('owner_id' => $user->ID, 'object_type' => 'gallery', 'object_action' => 'upload', 'object_id' => $user->ID, 'event_hook' => 'aoc_wall_gallery'); do_action('aoc_generic_event', $activity); } else { $hostname = preg_replace('#^www\\.#', '', strtolower($_SERVER['SERVER_NAME'])); $mail_headers = 'From: ' . get_bloginfo('name') . ' <' . 'wordpress@' . $hostname . ">\n"; $mail_subject = get_bloginfo('name') . ' ' . __('Please moderate user gallery', $this->PID); $mail_body = sprintf(__('A new image has been uploaded to the gallery for %s', $this->PID), $user->user_login) . "\n\n"; $mail_body .= __('Please, moderate it at', $this->PID) . ' ' . get_bloginfo('wpurl') . "/wp-admin/users.php?user_id={$user->ID}&page={$this->slug}-my-gallery"; wp_mail(get_bloginfo('admin_email'), $mail_subject, $mail_body, $mail_headers); } } else { $errors .= sprintf(__('Image %d error', $this->PID), $cur_num) . ': ' . $handle->error . ' '; } } } if (!empty($notices)) { ak_admin_notify($notices); } if (!empty($errors)) { ak_admin_error($errors); } }
/** * Includes global settings admin. * * @hook add_submenu_page * @return void */ function settingsAdmin() { if (!current_user_can('aoc_manage_settings')) { // Verify user permissions. wp_die('<strong>' . __('What do you think you\'re doing?!?', $this->ID) . '</strong>'); } global $wp_rewrite; $wp_rewrite->flush_rules(); // Force save rules. if ('POST' == $_SERVER['REQUEST_METHOD']) { $this->saveSettingsForm(); ak_admin_notify(); } require AOC_PATH . '/includes/admin.php'; }
/** * Resets roles to WordPress defaults. * * @return void */ private function backupToolReset() { require_once ABSPATH . 'wp-admin/includes/schema.php'; if (!function_exists('populate_roles')) { ak_admin_error(__('Needed function to create default roles not found!', $this->ID)); return; } $roles = array_keys($this->roles); foreach ($roles as $role) { remove_role($role); } populate_roles(); $this->setAdminCapability(); ak_admin_notify(__('Roles and Capabilities reset to WordPress defaults', $this->ID)); }