functions.php
Table of Contents
Functions
- cb_is_get_request() : bool
- CB Is Get Request
- cb_is_post_request() : bool
- CB Is Post Request
- cb_is_patch_request() : bool
- CB Is Patch Request
- cb_is_delete_request() : bool
- CB Is Delete Request
- confetti_bits_admin_enqueue_script() : mixed
- cb_core_notifications_init() : mixed
- Initializes our notifications class.
- cb_user_birthday_anniversary_fields() : mixed
- Returns form markup that allows privileged users to manually input the birthday and anniversary dates for other users.
- cb_save_user_birthday_anniversary_fields() : mixed
- cb_core_set_reset_date_globals() : mixed
- CB Core Set Reset Date Globals
- cb_core_set_spot_bonus_global() : mixed
- Sets the amount for spot bonuses in our core class for easy access.
- cb_core_auto_reset() : mixed
- Automatically increments the reset date by 1 year.
- cb_core_current_date() : string
- CB Core Current Date
- str_starts_with() : bool
- Str Starts With
- str_ends_with() : bool
- Str Ends With
- str_contains() : bool
- Str Contains
- cb_flush_rewrite_rules() : mixed
- CB Flush Rewrite Rules
- cb_get_patch_data() : array<string|int, mixed>
- Gets PATCH data from an HTTP PATCH request.
- cb_get_delete_data() : array<string|int, mixed>
- Gets DELETE data from an HTTP DELETE request.
- cb_core_get_missing_users() : array<string|int, mixed>
- Gets a list of transactions for nonexistent users.
- cb_core_get_user_display_name() : string
- Gets the user display name.
- cb_core_get_user_email() : string
- Returns the email address for the given user.
- cb_core_is_multi_array() : bool
- Checks if the parameter is a multi-dimensional array.
- cb_core_send_sitewide_notice() : mixed
- Sends out a sitewide notice.
- cb_core_get_doomsday_clock() : int
- Returns the number of days remaining until the reset date.
- cb_core_sanitize_string() : string
- Washes away the sins of bad actors.
- cb_core_smtp_init() : mixed
- Injects our own config settings into PHPMailer.
- cb_core_admin_menu() : mixed
- Adds a menu item for our settings.
- cb_templates_get_admin_page() : string
- Formats markup for our admin settings page.
- cb_core_admin_page() : mixed
- Outputs markup for our admin settings page.
- cb_core_admin_settings_init() : mixed
- cb_core_admin_settings_sanitize() : string
- Will eventually be used to sanitize user input in the admin menu.
- cb_core_admin_settings_section_callback() : string
- Returns the content for our main settings section.
- cb_core_admin_reset_date_setting() : mixed
- Outputs the setting field for the reset date.
- cb_core_admin_volunteer_setting() : mixed
- Outputs the setting field for the volunteer amount per hour.
- cb_core_admin_spot_bonus_setting() : mixed
- Outputs the setting field for the volunteer amount per hour.
- cb_core_convert_scripts_to_modules() : mixed
- Replaces our default script tags with modules.
- cb_core_delete_user_data() : mixed
- Deletes all Confetti Bits data associated with deleted user.
- cb_core_do_spot_bonuses() : mixed
- cb_core_listify() : mixed
- cb_core_schedule_events() : mixed
- cb_core_utc_to_local() : mixed
- cb_core_ordinal_suffix() : string
- Adds an ordinal suffix to a given integer.
Functions
cb_is_get_request()
CB Is Get Request
cb_is_get_request() : bool
Checks if the current request is a GET request
Tags
Return values
bool —True if GET request, false otherwise
cb_is_post_request()
CB Is Post Request
cb_is_post_request() : bool
Checks if the current request is a POST request
Tags
Return values
bool —True if POST request, false otherwise
cb_is_patch_request()
CB Is Patch Request
cb_is_patch_request() : bool
Checks if the current request is a PATCH request
Tags
Return values
bool —True if PATCH request, false otherwise
cb_is_delete_request()
CB Is Delete Request
cb_is_delete_request() : bool
Checks if the current request is a DELETE request
Tags
Return values
bool —True if DELETE request, false otherwise
confetti_bits_admin_enqueue_script()
confetti_bits_admin_enqueue_script() : mixed
cb_core_notifications_init()
Initializes our notifications class.
cb_core_notifications_init() : mixed
So we can get those sweet, sweet noties.
Tags
cb_user_birthday_anniversary_fields()
Returns form markup that allows privileged users to manually input the birthday and anniversary dates for other users.
cb_user_birthday_anniversary_fields(mixed $user) : mixed
Parameters
- $user : mixed
Tags
cb_save_user_birthday_anniversary_fields()
cb_save_user_birthday_anniversary_fields(mixed $user_id, mixed $notify) : mixed
Parameters
- $user_id : mixed
- $notify : mixed
cb_core_set_reset_date_globals()
CB Core Set Reset Date Globals
cb_core_set_reset_date_globals() : mixed
Sets a few internal globals using the DateTimeImmutable class so that we can reference these spending/earning cycles throughout the app without running these calculations all the time.
A breakdown of what this does:
-
There are two cycles: an earning cycle and a spending cycle
-
The reset date refers to the earning cycle. That is when users start over with a zero'd out bank of confetti bits. So the earning cycle "ends" on the reset date.
-
The earning cycle "starts" one year prior to that, on the same date. Please don't set it to February 29th, I did not account for that when I built this forsaken system.
-
The spending cycle is offset by 1 month after the earning cycle. So the spending cycle "ends" 1 month after the earning cycle does. That means that the spending cycle "starts" one month after the earning cycle does as well.
-
There are situations where a user may want to look back at a previous cycle, so we account for those here as well. We only need the dates that those cycles started, because they ended when the current cycles started.
Tags
cb_core_set_spot_bonus_global()
Sets the amount for spot bonuses in our core class for easy access.
cb_core_set_spot_bonus_global() : mixed
Make sure to set this value in the DB via admin settings, or else we may never experience the bliss of automation.
Tags
cb_core_auto_reset()
Automatically increments the reset date by 1 year.
cb_core_auto_reset() : mixed
Tags
cb_core_current_date()
CB Core Current Date
cb_core_current_date([bool $offset = false ][, string $format = "Y-m-d H:i:s" ]) : string
Returns the current date and time in the given format. Defaults to MySQL format in the site's timezone.
Parameters
- $offset : bool = false
-
Whether to use the site's UTC offset setting. Default true.
- $format : string = "Y-m-d H:i:s"
-
The desired datetime format. Default MySQL - 'Y-m-d H:i:s'
Tags
Return values
string —The formatted datetime.
str_starts_with()
Str Starts With
str_starts_with([string $haystack = '' ][, string $needle = '' ]) : bool
PHP 8 Polyfill for str_starts_with
Parameters
- $haystack : string = ''
-
The string to search.
- $needle : string = ''
-
The substring to search for at the beginning.
Tags
Return values
bool —Whether the string starts with the given substring.
str_ends_with()
Str Ends With
str_ends_with(string $haystack, string $needle) : bool
PHP 8 Polyfill for str_ends_with
Parameters
- $haystack : string
-
The string to search.
- $needle : string
-
The substring to search for at the end.
Tags
Return values
bool —Whether the string ends with the given substring.
str_contains()
Str Contains
str_contains(string $haystack, string $needle) : bool
PHP 8 Polyfill for str_contains
Parameters
- $haystack : string
-
The string to search.
- $needle : string
-
The substring to search for.
Tags
Return values
bool —Whether the string contains the given substring.
cb_flush_rewrite_rules()
CB Flush Rewrite Rules
cb_flush_rewrite_rules() : mixed
Flushes the rewrite rules after we update a plugin or theme, so our pages stop disappearing.
Tags
cb_get_patch_data()
Gets PATCH data from an HTTP PATCH request.
cb_get_patch_data() : array<string|int, mixed>
Retrieves data from a PATCH request and returns it as an associative array.
Tags
Return values
array<string|int, mixed> —The PATCH request body as an associative array.
cb_get_delete_data()
Gets DELETE data from an HTTP DELETE request.
cb_get_delete_data() : array<string|int, mixed>
Retrieves data from a DELETE request and returns it as an associative array.
Tags
Return values
array<string|int, mixed> —The DELETE request body as an associative array.
cb_core_get_missing_users()
Gets a list of transactions for nonexistent users.
cb_core_get_missing_users() : array<string|int, mixed>
Get a list of users that are present in the confetti_bits_transactions table, but not in the wp_users table. Returns an array of transactions where the sender or recipient isn't on the platform anymore.
Tags
Return values
array<string|int, mixed> —An associative array of transaction data.
cb_core_get_user_display_name()
Gets the user display name.
cb_core_get_user_display_name([int $user_id = 0 ]) : string
Attempts to get a display_name for the given user_id. If that comes up empty, searches for the first_name. If that also comes up empty, searches for the nickname. If there's no display name to be found, it gives us a lovely bunch of abject nothingness.
Parameters
- $user_id : int = 0
-
The ID for the user whose name we want. Default current user_id.
Tags
Return values
string —The display_name on success, empty on failure.
cb_core_get_user_email()
Returns the email address for the given user.
cb_core_get_user_email([int $user_id = 0 ]) : string
Parameters
- $user_id : int = 0
-
The ID of the user. Default current user.
Tags
Return values
string —The user's email address, if one exists.
cb_core_is_multi_array()
Checks if the parameter is a multi-dimensional array.
cb_core_is_multi_array(array<string|int, mixed> $arr) : bool
Parameters
- $arr : array<string|int, mixed>
-
The array to check.
Tags
Return values
bool —Whether the array is multi-dimensional.
cb_core_send_sitewide_notice()
Sends out a sitewide notice.
cb_core_send_sitewide_notice() : mixed
Use this to send out non-critical updates that are intended to be informative or nice to know, such as an upcoming or recent update, new feature, etc.
Tags
cb_core_get_doomsday_clock()
Returns the number of days remaining until the reset date.
cb_core_get_doomsday_clock() : int
Tags
Return values
int —The number of days remaining before the reset.
cb_core_sanitize_string()
Washes away the sins of bad actors.
cb_core_sanitize_string([string $input = '' ]) : string
Use this to aggressively scrub input strings. I doubt that there are going to be any elite hackers playing injecting nonsense into this app, but this is good practice for other kinds of sanitization that we might want to do later.
Parameters
- $input : string = ''
-
An input string
Tags
Return values
string —A kinder, gentler string.
cb_core_smtp_init()
Injects our own config settings into PHPMailer.
cb_core_smtp_init(PHPMailer $phpmailer) : mixed
Parameters
- $phpmailer : PHPMailer
-
A PHPMailer object.
Tags
cb_core_admin_menu()
Adds a menu item for our settings.
cb_core_admin_menu() : mixed
Tags
cb_templates_get_admin_page()
Formats markup for our admin settings page.
cb_templates_get_admin_page() : string
Tags
Return values
string —The formatted page markup.
cb_core_admin_page()
Outputs markup for our admin settings page.
cb_core_admin_page() : mixed
Tags
cb_core_admin_settings_init()
cb_core_admin_settings_init() : mixed
cb_core_admin_settings_sanitize()
Will eventually be used to sanitize user input in the admin menu.
cb_core_admin_settings_sanitize(mixed $input) : string
Parameters
- $input : mixed
-
The input passed via post.
Tags
Return values
string —$input The "sanitized" input.
cb_core_admin_settings_section_callback()
Returns the content for our main settings section.
cb_core_admin_settings_section_callback() : string
Tags
Return values
string —Content.
cb_core_admin_reset_date_setting()
Outputs the setting field for the reset date.
cb_core_admin_reset_date_setting() : mixed
Tags
cb_core_admin_volunteer_setting()
Outputs the setting field for the volunteer amount per hour.
cb_core_admin_volunteer_setting() : mixed
Tags
cb_core_admin_spot_bonus_setting()
Outputs the setting field for the volunteer amount per hour.
cb_core_admin_spot_bonus_setting() : mixed
Tags
cb_core_convert_scripts_to_modules()
Replaces our default script tags with modules.
cb_core_convert_scripts_to_modules(mixed $tag, mixed $handle, mixed $src) : mixed
Parameters
- $tag : mixed
- $handle : mixed
- $src : mixed
cb_core_delete_user_data()
Deletes all Confetti Bits data associated with deleted user.
cb_core_delete_user_data(int $id, int $reassign, WP_User $user) : mixed
Parameters
- $id : int
-
The ID of the user that's being deleted.
- $reassign : int
-
An optional user ID to reassign items to.
- $user : WP_User
-
The instance of WP_User associated with the deleted user.
Tags
cb_core_do_spot_bonuses()
cb_core_do_spot_bonuses() : mixed
cb_core_listify()
cb_core_listify(mixed $string) : mixed
Parameters
- $string : mixed
cb_core_schedule_events()
cb_core_schedule_events() : mixed
cb_core_utc_to_local()
cb_core_utc_to_local([mixed $date_string = '' ]) : mixed
Parameters
- $date_string : mixed = ''
cb_core_ordinal_suffix()
Adds an ordinal suffix to a given integer.
cb_core_ordinal_suffix(int|string $int) : string
Parameters
- $int : int|string
-
An integer.
Tags
Return values
string —The same integer, but with a little spice.