/** * Sets team parameters based on actions taken in Team admin UI. * * @link https://developer.wordpress.org/reference/hooks/current_screen/ * * @global $_POST * @global $_GET * * @uses WP_Screen::$post_type * @uses WP_Posts_List_Table::current_action() * @uses WP_Buoy_User_Settings::set() * @uses WP_Buoy_User_Settings::save() * @uses Buoy_Team_Membership_List_Table::current_action() * @uses wp_verify_nonce() * @uses WP_Buoy_Team::remove_member() * @uses WP_Buoy_Team::confirm_member() * * @param WP_Screen $current_screen * * @return void */ public static function processTeamTableActions($current_screen) { $post_type = self::$prefix . '_team'; if ($post_type !== $current_screen->post_type) { return; } if ('post' === $current_screen->base) { // The "My Teams" page. $table = new WP_Posts_List_Table(); if ('make_default' === $table->current_action()) { $team = new WP_Buoy_Team(absint($_GET['post'])); $team->make_default(); $msg = self::$prefix . '-default-team-updated'; wp_safe_redirect(admin_url("edit.php?post_type={$current_screen->post_type}&msg={$msg}")); exit; } } else { if ("{$post_type}_page_{$post_type}_membership") { // The "Team Membership" page. $table = new Buoy_Team_Membership_List_Table($post_type); $teams = array(); if (isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'single-' . $table->_args['plural'])) { $teams[] = $_GET['team_id']; } else { if (isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'bulk-' . $table->_args['plural'])) { $teams = array_merge($teams, $_POST['teams']); } } if (!empty($teams)) { foreach ($teams as $team_id) { $team = new self($team_id); if ('leave' === $table->current_action()) { $team->remove_member(get_current_user_id()); } if ('join' === $table->current_action()) { $team->confirm_member(get_current_user_id()); } } wp_safe_redirect(admin_url('edit.php?page=' . urlencode($_GET['page']) . '&post_type=' . urlencode($_GET['post_type']))); exit; } } } }