static function do_userlabel_actions() { if (!current_user_can('promote_users')) { wp_die(__('You do not have permission to do this.', 'wp-access-areas')); } wp_enqueue_style('disclosure-admin'); $table = new UserLabel_List_Table(); $table->process_bulk_action(); $redirect_url = false; if (isset($_REQUEST['action'])) { // do actions $data = self::_sanitize_userlabel_data($_POST); // integrity check. if (!empty($_POST) && !$data['cap_title']) { wp_die(__('Please enter a Label.', 'wp-access-areas')); } if (!empty($_POST) && !wp_verify_nonce(@$_REQUEST['_wpnonce'], 'userlabel-' . $_REQUEST['action']) || !$data['blog_id'] && !current_user_can('manage_network_users')) { wp_die(__('You do not have permission to edit network wide user labels.', 'wp-access-areas')); } switch ($_REQUEST['action']) { case 'new': // do create action if (!empty($_POST)) { if ($edit_id = UndisclosedUserlabel::create_userlabel($data)) { $redirect_url = add_query_arg(array('page' => 'user_labels', 'action' => 'new', 'message' => 1), $_SERVER['SCRIPT_NAME']); } else { $redirect_url = add_query_arg(array('page' => 'user_labels', 'action' => 'new', 'message' => UndisclosedUserlabel::what_went_wrong(), 'cap_title' => $_POST['cap_title']), $_SERVER['SCRIPT_NAME']); } } break; case 'edit': // update and redirect if (!empty($_POST)) { if ($edit_id = UndisclosedUserlabel::update_userlabel($data)) { $redirect_url = add_query_arg(array('id' => $edit_id, 'message' => 2)); } else { $redirect_url = add_query_arg(array('id' => $edit_id, 'message' => UndisclosedUserlabel::what_went_wrong(), 'cap_title' => $_POST['cap_title'])); } } if (!isset($_GET['id'])) { $redirect_url = add_query_arg(array('page' => 'user_labels'), $_SERVER['SCRIPT_NAME']); } break; case 'delete': // delete and redirect if (isset($_REQUEST['id'])) { if ($deleted = UndisclosedUserlabel::delete_userlabel($_REQUEST['id'])) { $redirect_url = add_query_arg(array('page' => 'user_labels', 'message' => 3, 'deleted' => $deleted), $_SERVER['SCRIPT_NAME']); } else { $redirect_url = add_query_arg(array('page' => 'user_labels', 'message' => UndisclosedUserlabel::what_went_wrong()), $_SERVER['SCRIPT_NAME']); } } break; default: wp_redirect(remove_query_arg('action')); } } if ($redirect_url) { wp_redirect($redirect_url); } }
function process_bulk_action() { //Detect when a bulk action is being triggered... $action = $this->current_action(); $nonce = isset($_REQUEST['_wpnonce']) ? $_REQUEST['_wpnonce'] : false; if (!$nonce) { return; } if (-1 !== $action && wp_verify_nonce($nonce, 'bulk-' . $this->_args['plural'])) { switch ($action) { case 'delete': foreach ($_REQUEST[$this->_args['plural']] as $ul_id) { if ($ul = UndisclosedUserlabel::get_userlabel(intval($ul_id))) { UndisclosedUserlabel::delete_userlabel(intval($ul_id)); } } return wp_redirect(add_query_arg(array('page' => 'user_labels', 'message' => 3, 'deleted' => count($_REQUEST[$this->_args['plural']])), $_SERVER['SCRIPT_NAME'])); default: } } }