/** * Prints HTML for the "activate alert" page. * * @uses get_current_user_id() * @uses WP_Buoy_User::has_responder() * * @return void */ public static function renderActivateAlertPage() { $buoy_user = new WP_Buoy_User(get_current_user_id()); if (!$buoy_user->has_responder()) { require_once 'pages/no-responders-available.php'; } else { require_once 'pages/activate-alert.php'; } }
/** * Checks to ensure a user doesn't leave themselves without any * responders. * * Teams are only "active" is they are in the "publish" status. * This checks a team transition and if the action leaves a user * without any responders, it will re-set the team's status. * * @link https://developer.wordpress.org/reference/hooks/post_updated/ * * @uses WP_Buoy_User::has_responder() * @uses WP_Buoy_Team::is_default() * @uses WP_Buoy_Team::make_default() * * @param int $post_id * @param WP_Post $post_after * @param WP_Post $post_before * * @return void */ public static function postUpdated($post_id, $post_after, $post_before) { if (self::$prefix . '_team' !== $post_after->post_type) { return; } $buoy_user = new WP_Buoy_User($post_before->post_author); // Prevent the user from trashing their last responder team. if ('publish' === $post_before->post_status && 'publish' !== $post_after->post_status) { if (!$buoy_user->has_responder()) { wp_update_post(array('ID' => $post_id, 'post_status' => 'publish')); } } // Re-set the default team if the default team is trashed. $team = new WP_Buoy_Team($post_id); if ('trash' === $post_after->post_status && $team->is_default()) { $teams = $buoy_user->get_teams(); $next_team = new WP_Buoy_Team(array_pop($teams)); $next_team->make_default(); } }