\WP_Buoy_Team

Main class for a Buoy Team.

Teams are groups/lists of potential responders managed by one user who invites them to join said team. They are implemented as a WP custom post type.

Summary

Methods
Properties
Constants
register()
registerL10n()
initialize()
activate()
checkPrereqs()
install_plugin_dependency()
rest_api_install_failure_notice()
get_minimum_wordpress_version()
deactivate()
enqueueFrontEndScripts()
addHelpTab()
addHelpSidebar()
renderWebAppManifest()
renderWebAppHTML()
registerDashboardWidget()
renderDashboardWidget()
__construct()
get_members_in_states()
is_default()
set_default()
unset_default()
get_team_owner()
get_member_ids()
get_invited_members()
is_member()
invite_user()
add_member()
remove_member()
confirm_member()
unconfirm_member()
is_confirmed()
has_responder()
get_confirmed_members()
get_unconfirmed_members()
registerMetaBoxes()
renderAddTeamMemberMetaBox()
renderCurrentTeamMetaBox()
renderDefaultTeamMetaBox()
renderTxtMessagesMetaBox()
renderTeamMembershipPage()
processTeamTableActions()
renderAdminNotices()
postUpdated()
saveTeam()
deletedPostMeta()
checkMemberCount()
registerAdminMenu()
filterCaps()
filterTitlePlaceholder()
filterTeamPostsColumns()
filterSortableColumns()
orderTeamPosts()
renderTeamPostsColumn()
filterTeamPostsList()
filterTeamPostViews()
postRowActions()
checkInvitations()
createTeamTemplates()
getAllTeamPosts()
$prefix
$wp_post
No constants found
debug_log()
No protected properties found
N/A
error_msg()
$author
$members
$invitees
N/A

Properties

$prefix

$prefix : string

Type

string — String to prefix option names, settings, etc.

$wp_post

$wp_post : \WP_Post

The team post.

Type

\WP_Post

$author

$author : \WP_User

The team owner.

Type

\WP_User

$members

$members : array<mixed,\WP_User>

An array of WP_User objects representing the team membership.

The members list include those who are not yet confirmed (pending).

Type

array<mixed,\WP_User>

$invitees

$invitees : array<mixed,string>

Addresses of people without accounts who were invited to join.

Type

array<mixed,string>

Methods

register()

register() : void

Entry point for the WordPress framework into plugin code.

This is the method called when WordPress loads the plugin file. It is responsible for "registering" the plugin's main functions with the WordPress Plugin API.

registerL10n()

registerL10n() : void

Loads localization files from plugin's languages directory.

initialize()

initialize() : void

Loads plugin componentry and calls that component's register() method. Called at the WordPress `init` hook.

activate()

activate(boolean  $network_wide) : void

Method to run when the plugin is activated by a user in the WordPress Dashboard admin screen.

Parameters

boolean $network_wide

checkPrereqs()

checkPrereqs() : void

Checks system requirements and exits if they are not met.

This first checks to ensure minimum WordPress and PHP versions have been satisfied. If not, the plugin deactivates and exits.

install_plugin_dependency()

install_plugin_dependency(string  $slug, string  $version = '') 

Automates installation of other plugins that we need.

We only use this for the WP REST API at the moment. It's the 1 and only dependency we have on other plugins. When that plugin gets added to WP Core, we can remove this code.

As a result, note that this code is SPECIFIC to the rest-api plugin. It will not work as-is for other plugins.

Parameters

string $slug
string $version

rest_api_install_failure_notice()

rest_api_install_failure_notice() 

get_minimum_wordpress_version()

get_minimum_wordpress_version() : string

Returns the "Requires at least" value from plugin's readme.txt.

Returns

string

deactivate()

deactivate() : void

Method to run when the plugin is deactivated by a user in the WordPress Dashboard admin screen.

enqueueFrontEndScripts()

enqueueFrontEndScripts() : void

Enqueues globally relevant scripts and stylesheets.

addHelpTab()

addHelpTab() : void

Attaches on-screen help tabs to the WordPress built-in help.

Loads the appropriate document from the localized help folder and inserts it as a help tab on the current screen.

addHelpSidebar()

addHelpSidebar() : void

Appends appropriate sidebar content based on current screen.

renderWebAppManifest()

renderWebAppManifest() : void

Prints the Web App manifest file.

renderWebAppHTML()

renderWebAppHTML() : void

Prints meta tag indicators for native-like functionality.

The "activate alert" screen is intended to be the web app "install" screen for Buoy. We insert special mobile browser specific tags in order to create a native-like "installer" for the user. We only want to do this on this specific screen.

registerDashboardWidget()

registerDashboardWidget() : void

Register the Dashboard widget.

renderDashboardWidget()

renderDashboardWidget() : void

Renders the Buoy Dashboard widget.

__construct()

__construct(integer  $team_id) : \WP_Buoy_Team

Constructor.

Parameters

integer $team_id

The post ID of the team.

Returns

\WP_Buoy_Team

get_members_in_states()

get_members_in_states(array  $states = array()) : array<mixed,array>|\WP_Error

Gets team member IDs by state.

For the "invited" state, an ID is an email address.

Parameters

array $states

Defaults to array('confirmed', 'unconfirmed', 'invited').

Returns

array<mixed,array>|\WP_Error —

2D array of state => IDs

is_default()

is_default() : boolean

Checks whether or not this team is one of user's default teams.

Returns

boolean

set_default()

set_default() : \WP_Buoy_Team

Makes this team part a default team of the author.

Returns

\WP_Buoy_Team

unset_default()

unset_default() : \WP_Buoy_Team

Removes this team from the list of default teams.

Refuses to remove the team from the list of default teams if the team's author does not have any other default teams. This ensures that a user always has at least one default team.

Returns

\WP_Buoy_Team

get_team_owner()

get_team_owner() : \WP_Buoy_User

Gets the Team's owner.

Returns

\WP_Buoy_User

get_member_ids()

get_member_ids() : array<mixed,string>

Gets a list of all the user IDs associated with this team.

This does not do any checking about whether the given user ID is "confirmed" or not.

Returns

array<mixed,string> —

IDs are actually returned as string values.

get_invited_members()

get_invited_members() : array<mixed,string>

Gets a list of all email addresses invited to join this team.

Returns

array<mixed,string>

is_member()

is_member(integer  $user_id) : boolean

Checks whether or not the given user ID is on the team.

This does not check whether the user is confirmed or not, only whether the user has been at least invited to be a member of a team.

Parameters

integer $user_id

Returns

boolean

invite_user()

invite_user(string  $email) 

Adds an invitation for this email address to this team.

Parameters

string $email

add_member()

add_member(integer  $user_id, boolean  $notify = true) : \WP_Buoy_Team

Adds a user to this team (a new member).

Parameters

integer $user_id
boolean $notify

Whether or not to trigger a notification when adding.

Returns

\WP_Buoy_Team

remove_member()

remove_member(integer  $user_id) : \WP_Buoy_Team

Removes a member from this team.

Parameters

integer $user_id

Returns

\WP_Buoy_Team

confirm_member()

confirm_member(integer  $user_id) : \WP_Buoy_Team

Sets the confirmation flag for a user on this team.

Parameters

integer $user_id

Returns

\WP_Buoy_Team

unconfirm_member()

unconfirm_member(integer  $user_id) : \WP_Buoy_Team

Unsets the confirmation flag for a user on this team.

Parameters

integer $user_id

Returns

\WP_Buoy_Team

is_confirmed()

is_confirmed(integer  $user_id) : boolean

Checks whether or not a user is "confirmed" to be on the team.

"Confirmation" consists of a flag in the team post's metadata.

Parameters

integer $user_id

Returns

boolean

has_responder()

has_responder() : boolean

Checks to ensure there is at least one confirmed member on the team.

A "responder" in this context is a confirmed team member.

Returns

boolean

get_confirmed_members()

get_confirmed_members() : array<mixed,integer>

Gets the confirmed members of this team.

Returns

array<mixed,integer>

get_unconfirmed_members()

get_unconfirmed_members() : array<mixed,integer>

Gets the unconfirmed members of this team.

Returns

array<mixed,integer>

registerMetaBoxes()

registerMetaBoxes(\WP_Post  $post) : void

Parameters

\WP_Post $post

renderAddTeamMemberMetaBox()

renderAddTeamMemberMetaBox(\WP_Post  $post) : void

Parameters

\WP_Post $post

renderCurrentTeamMetaBox()

renderCurrentTeamMetaBox(\WP_Post  $post) : void

Parameters

\WP_Post $post

renderDefaultTeamMetaBox()

renderDefaultTeamMetaBox(\WP_Post  $post) : void

Displays the "default team" meta box.

Parameters

\WP_Post $post

renderTxtMessagesMetaBox()

renderTxtMessagesMetaBox(\WP_Post  $post) : void

Displays the "SMS/txt Messages" meta box.

Parameters

\WP_Post $post

renderTeamMembershipPage()

renderTeamMembershipPage() : void

processTeamTableActions()

processTeamTableActions(\WP_Screen  $current_screen) : void

Sets team parameters based on actions taken in Team admin UI.

Parameters

\WP_Screen $current_screen

renderAdminNotices()

renderAdminNotices() : void

Prints an admin notice for the given message code.

postUpdated()

postUpdated(integer  $post_id, \WP_Post  $post_after, \WP_Post  $post_before) : void

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.

Parameters

integer $post_id
\WP_Post $post_after
\WP_Post $post_before

saveTeam()

saveTeam(integer  $post_id, \WP_Post  $post) : void

Updates the team metadata (mostly membership list).

This is called by WordPress's save_post_{$post->post_type} hook.

Parameters

integer $post_id
\WP_Post $post

deletedPostMeta()

deletedPostMeta(array  $meta_ids, integer  $post_id, string  $meta_key, mixed  $meta_value) : void

Hooks the `deleted_post_meta` action.

This is used primarily to detect when a user is removed from a team and, when this occurrs, remove the confirmation flag, too.

Parameters

array $meta_ids
integer $post_id
string $meta_key
mixed $meta_value

checkMemberCount()

checkMemberCount(integer  $user_id,   $team) 

Checks if a team no longer has any members.

If a team is emptied for any reason, whether because the user has removed all their members or the members themselves decide to leave, this will fire a "{$post->post_type}_emptied" hook.

Parameters

integer $user_id

The user who was just removed.

$team

registerAdminMenu()

registerAdminMenu() : void

filterCaps()

filterCaps(array  $caps) : array

Dynamically configures user capabilities.

This dynamism prevents the need to write capabilities into the database's options table's wp_user_roles record itself.

Currently simply unconditionally gives every user the required capabilities to manage their own crisis response teams.

Called by the user_has_cap filter.

Parameters

array $caps

The user's actual capabilities.

Returns

array —

$caps

filterTitlePlaceholder()

filterTitlePlaceholder(string  $text, \WP_Post  $post) : string

Sets the placeholder text for the "New Team" page.

Parameters

string $text
\WP_Post $post

Returns

string

filterTeamPostsColumns()

filterTeamPostsColumns(array  $post_columns) : array

Add custom columns shown in the "My Teams" admin UI.

Parameters

array $post_columns

Returns

array

filterSortableColumns()

filterSortableColumns(array  $sortable_columns) : array

Makes the custom columns sortable in the "My Teams" admin UI.

Parameters

array $sortable_columns

Returns

array

orderTeamPosts()

orderTeamPosts(\WP  $wp) : void

Re-orders the query results based on the team member count.

This changes the global $wp_query->posts array directly.

Parameters

\WP $wp

renderTeamPostsColumn()

renderTeamPostsColumn(string  $column_name, integer  $post_id) : void

Add the column content for custom columns in the "My Teams" UI.

Parameters

string $column_name
integer $post_id

filterTeamPostsList()

filterTeamPostsList(\WP_Query  $query) : void

Ensures that users can only see their own crisis teams in the WP admin view when viewing their "My Teams" dashboard page.

Parameters

\WP_Query $query

filterTeamPostViews()

filterTeamPostViews(array  $items) : array

Removes the views links in the Team posts table.

Parameters

array $items

Returns

array

postRowActions()

postRowActions(array  $items, \WP_Post  $post) : array

Customizes the post row actions in the "My Teams" admin UI.

Parameters

array $items
\WP_Post $post

Returns

array —

$items

checkInvitations()

checkInvitations(integer  $user_id) : void

Adds a user to teams they were invited to join before they had created an account.

Parameters

integer $user_id

createTeamTemplates()

createTeamTemplates(integer  $user_id) : void

Creates teams for newly-registered users.

Parameters

integer $user_id

getAllTeamPosts()

getAllTeamPosts() : array<mixed,\WP_Post>

Gets a list of all team posts.

Returns

array<mixed,\WP_Post>

debug_log()

debug_log(string  $message) : void

Prints a message to the WordPress debug log if the plugin's "detailed debugging" setting is enabled.

By default, the WordPress debug log is wp-content/debug.log relative to the WordPress installation root (ABSPATH).

Parameters

string $message

error_msg()

error_msg(string  $message) : string

Prepares an error message for logging.

Parameters

string $message

Returns

string