[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/src/includes/common/ -> functions.php (summary)

bbPress Common Functions Common functions are ones that are used by more than one component, like forums, topics, replies, users, topic tags, etc...

File Size: 2683 lines (80 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 48 functions

  bbp_get_post_types()
  bbp_get_redirect_to()
  bbp_add_view_all()
  bbp_remove_view_all()
  bbp_get_view_all()
  bbp_get_paged()
  bbp_get_unique_array_values()
  bbp_fix_post_author()
  bbp_fix_untrash_post_status()
  bbp_past_edit_lock()
  bbp_get_trash_days()
  bbp_get_statistics()
  bbp_filter_anonymous_post_data()
  bbp_sanitize_anonymous_post_author()
  bbp_update_anonymous_post_author()
  bbp_check_for_duplicate()
  bbp_check_for_flood()
  bbp_check_for_moderation()
  bbp_check_for_blacklist()
  bbp_get_do_not_reply_address()
  bbp_notify_topic_subscribers()
  bbp_notify_forum_subscribers()
  bbp_notify_subscribers()
  bbp_get_email_addresses_from_user_ids()
  bbp_chunk_emails()
  bbp_get_email_header()
  bbp_logout_url()
  bbp_parse_args()
  bbp_query_post_parent__in()
  bbp_get_public_child_last_id()
  bbp_get_child_counts()
  bbp_filter_child_counts_list()
  bbp_get_public_child_count()
  bbp_get_non_public_child_count()
  bbp_get_public_child_ids()
  bbp_get_all_child_ids()
  bbp_update_post_family_caches()
  bbp_update_post_author_caches()
  bbp_get_global_post_field()
  bbp_verify_nonce_request()
  bbp_request_feed_trap()
  bbp_get_page_by_path()
  bbp_set_404()
  bbp_set_200()
  bbp_pre_handle_404()
  bbp_posts_pre_query()
  bbp_get_url_scheme()
  bbp_is_title_too_long()

Functions
Functions that are not part of a class:

bbp_get_post_types( $args = array()   X-Ref
Return array of bbPress registered post types

return: array
since: 2.6.0 bbPress (r6813)
param: array $args Array of arguments to pass into `get_post_types()`

bbp_get_redirect_to()   X-Ref
Return the unescaped redirect_to request value

return: string The URL to redirect to, if set

bbp_add_view_all( $original_link = '', $force = false )   X-Ref
Append 'view=all' to query string if it's already there from referer

return: string The link with 'view=all' appended if necessary
since: 2.0.0 bbPress (r3325)
param: string $original_link Original Link to be modified
param: bool $force Override bbp_get_view_all() check

bbp_remove_view_all( $original_link = '' )   X-Ref
Remove 'view=all' from query string

return: string The link with 'view=all' appended if necessary
since: 2.0.0 bbPress (r3325)
param: string $original_link Original Link to be modified

bbp_get_view_all( $cap = 'moderate' )   X-Ref
If current user can and is viewing all topics/replies

return: bool Whether current user can and is viewing all
since: 2.0.0 bbPress (r3325)
param: string $cap Capability used to ensure user can view all

bbp_get_paged()   X-Ref
Assist pagination by returning correct page number

return: int Current page number
since: 2.0.0 bbPress (r2628)

bbp_get_unique_array_values( $array = array()   X-Ref
Return the unique non-empty values of an array.

return: array
since: 2.6.0 bbPress (r6481)
param: array $array Array to get values of

bbp_fix_post_author( $data = array()   X-Ref
Fix post author id on post save

When a logged in user changes the status of an anonymous reply or topic, or
edits it, the post_author field is set to the logged in user's id. This
function fixes that.

return: array Data
since: 2.0.0 bbPress (r2734)
param: array $data Post data
param: array $postarr Original post array (includes post id)

bbp_fix_untrash_post_status( $new_status = 'draft', $post_id = 0, $previous_status = 'pending' )   X-Ref
Use the previous status when restoring a topic or reply.

Fixes an issue since WordPress 5.6.0. See
{@link https://bbpress.trac.wordpress.org/ticket/3433}.

since: 2.6.10 bbPress (r7233)
param: string $new_status      New status to use when untrashing. Default: 'draft'
param: int    $post_id         Post ID
param: string $previous_status Previous post status from '_wp_trash_meta_status' meta key. Default: 'pending'

bbp_past_edit_lock( $datetime = '', $utc = true )   X-Ref
Check a date against the length of time something can be edited.

It is recommended to leave $utc set to true and to work with UTC/GMT dates.
Turning this off will use the WordPress offset which is likely undesirable.

return: bool True by default, if date is past, or editing is disabled.
since: 2.0.0 bbPress (r3133)
since: 2.6.0 bbPress (r6868) Inverted some logic and added unit tests
param: string  $datetime Gets run through strtotime()
param: boolean $utc      Default true. Is the timestamp in UTC?

bbp_get_trash_days( $context = 'forum' )   X-Ref
Get number of days something should remain trashed for before it is cleaned
up by WordPress Cron. If set to 0, items will skip trash and be deleted
immediately.

return: int Number of days items remain in trash
since: 2.6.0 bbPress (r6424)
param: string $context Provide context for additional filtering

bbp_get_statistics( $args = array()   X-Ref
Get the forum statistics

return: array Array of statistics
since: 2.0.0 bbPress (r2769)
since: 2.6.0 bbPress (r6055)  Added:
since: 2.6.10 bbPress (r7235) Renamed:
param: array $args Optional. The function supports these arguments (all

bbp_filter_anonymous_post_data( $args = array()   X-Ref
Filter anonymous post data

We use REMOTE_ADDR here directly. If you are behind a proxy, you should
ensure that it is properly set, such as in wp-config.php, for your
environment. See {@link https://core.trac.wordpress.org/ticket/9235}

Note that bbp_pre_anonymous_filters() is responsible for sanitizing each
of the filtered core anonymous values here.

If there are any errors, those are directly added to {@link bbPress:errors}

return: bool|array False on errors, values in an array on success
since: 2.0.0 bbPress (r2734)
param: array $args Optional. If no args are there, then $_POST values are

bbp_sanitize_anonymous_post_author( $anonymous_data = array()   X-Ref
Sanitize an array of anonymous post author data

return: array
since: 2.6.0 bbPress (r6400)
param: array $anonymous_data

bbp_update_anonymous_post_author( $post_id = 0, $anonymous_data = array()   X-Ref
Update the relevant meta-data for an anonymous post author

since: 2.6.0 bbPress (r6400)
param: int    $post_id
param: array  $anonymous_data
param: string $post_type

bbp_check_for_duplicate( $post_data = array()   X-Ref
Check for duplicate topics/replies

Check to make sure that a user is not making a duplicate post

return: bool True if it is not a duplicate, false if it is
since: 2.0.0 bbPress (r2763)
param: array $post_data Contains information about the comment

bbp_check_for_flood( $anonymous_data = array()   X-Ref
Check for flooding

Check to make sure that a user is not making too many posts in a short amount
of time.

return: bool True if there is no flooding, false if there is
since: 2.0.0 bbPress (r2734)
param: array $anonymous_data Optional - if it's an anonymous post. Do not
param: int $author_id Optional. Supply if it's a post by a logged in user.

bbp_check_for_moderation( $anonymous_data = array()   X-Ref
Checks topics and replies against the discussion moderation of blocked keys

return: bool True if test is passed, false if fail
since: 2.1.0 bbPress (r3581)
param: array $anonymous_data Optional - if it's an anonymous post. Do not
param: int $author_id Topic or reply author ID
param: string $title The title of the content
param: string $content The content being posted
param: mixed  $strict  False for moderation_keys. True for blacklist_keys.

bbp_check_for_blacklist( $anonymous_data = array()   X-Ref
Deprecated. Use bbp_check_for_moderation() with strict flag set.

since: 2.0.0 bbPress (r3446)
since: 2.6.0 bbPress (r6854)

bbp_get_do_not_reply_address()   X-Ref
Get the "Do Not Reply" email address to use when sending subscription emails.

We make some educated guesses here based on the home URL. Filters are
available to customize this address further. In the future, we may consider
using `admin_email` instead, though this is not normally publicized.

We use `$_SERVER['SERVER_NAME']` here to mimic similar functionality in
WordPress core. Previously, we used `get_home_url()` to use already validated
user input, but it was causing issues in some installations.

return: string
since: 2.6.0 bbPress (r5409)

bbp_notify_topic_subscribers( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = array()   X-Ref
Sends notification emails for new replies to subscribed topics

Gets new post ID and check if there are subscribed users to that topic, and
if there are, send notifications

Note: in bbPress 2.6, we've moved away from 1 email per subscriber to 1 email
with everyone BCC'd. This may have negative repercussions for email services
that limit the number of addresses in a BCC field (often to around 500.) In
those cases, we recommend unhooking this function and creating your own
custom email script.

return: bool True on success, false on failure
since: 2.6.0 bbPress (r5413)
param: int $reply_id ID of the newly made reply
param: int $topic_id ID of the topic of the reply
param: int $forum_id ID of the forum of the reply
param: array $anonymous_data Optional - if it's an anonymous post. Do not
param: int $reply_author ID of the topic author ID

bbp_notify_forum_subscribers( $topic_id = 0, $forum_id = 0, $anonymous_data = array()   X-Ref
Sends notification emails for new topics to subscribed forums

Gets new post ID and check if there are subscribed users to that forum, and
if there are, send notifications

Note: in bbPress 2.6, we've moved away from 1 email per subscriber to 1 email
with everyone BCC'd. This may have negative repercussions for email services
that limit the number of addresses in a BCC field (often to around 500.) In
those cases, we recommend unhooking this function and creating your own
custom email script.

return: bool True on success, false on failure
since: 2.5.0 bbPress (r5156)
param: int $topic_id ID of the newly made reply
param: int $forum_id ID of the forum for the topic
param: array $anonymous_data Optional - if it's an anonymous post. Do not
param: int $topic_author ID of the topic author ID

bbp_notify_subscribers( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = array()   X-Ref
Sends notification emails for new replies to subscribed topics

This function is deprecated. Please use: bbp_notify_topic_subscribers()

return: bool True on success, false on failure
since: 2.0.0 bbPress (r2668)
param: int $reply_id ID of the newly made reply
param: int $topic_id ID of the topic of the reply
param: int $forum_id ID of the forum of the reply
param: array $anonymous_data Optional - if it's an anonymous post. Do not
param: int $reply_author ID of the topic author ID

bbp_get_email_addresses_from_user_ids( $user_ids = array()   X-Ref
Return an array of user email addresses from an array of user IDs

return: array
since: 2.6.0 bbPress (r6722)
param: array $user_ids

bbp_chunk_emails( $args = array()   X-Ref
Automatically splits bbPress emails with many Bcc recipients into chunks.

This middleware is useful because topics and forums with many subscribers
run into problems with Bcc limits, and many hosting companies & third-party
services limit the size of a Bcc audience to prevent spamming.

The default "chunk" size is 40 users per iteration, and can be filtered if
desired. A future version of bbPress will introduce a setting to more easily
tune this.

return: array
since: 2.6.0 bbPress (r6918)
param: array $args Original arguments passed to wp_mail().

bbp_get_email_header()   X-Ref
Return the string used for the bbPress specific X-header.

return: string
since: 2.6.0 bbPress (r6919)

bbp_logout_url( $url = '', $redirect_to = '' )   X-Ref
Return a clean and reliable logout URL

This function is used to filter `logout_url`. If no $redirect_to value is
passed, it will default to the request uri, then the forum root.

See: `wp_logout_url()`

return: string The url
since: 2.1.0 bbPress (2815)
param: string $url URL used to log out
param: string $redirect_to Where to redirect to?

bbp_parse_args( $args, $defaults = array()   X-Ref
Merge user defined arguments into defaults array.

This function is used throughout bbPress to allow for either a string or array
to be merged into another array. It is identical to wp_parse_args() except
it allows for arguments to be passively or aggressively filtered using the
optional $filter_key parameter.

return: array Merged user defined values with defaults.
since: 2.1.0 bbPress (r3839)
param: string|array $args Value to merge with $defaults
param: array $defaults Array that serves as the defaults.
param: string $filter_key String to key the filters from

bbp_query_post_parent__in( $where, $object = '' )   X-Ref
Adds ability to include or exclude specific post_parent ID's

return: string
since: 2.0.0 bbPress (r2996)
param: string $where
param: WP_Query $object

bbp_get_public_child_last_id( $parent_id = 0, $post_type = 'post' )   X-Ref
Query the DB and get the last public post_id that has parent_id as post_parent

return: int The last active post_id
since: 2.0.0 bbPress (r2868)
since: 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects
param: int    $parent_id Parent id.
param: string $post_type Post type. Defaults to 'post'.

bbp_get_child_counts( $parent_id = 0 )   X-Ref
Query the database for child counts, grouped by type & status

since: 2.6.0 bbPress (r6826)
param: int $parent_id

bbp_filter_child_counts_list( $parent_id = 0, $types = array( 'post' )   X-Ref
Filter a list of child counts, from `bbp_get_child_counts()`

return: array A list of objects or object fields.
since: 2.6.0 bbPress (r6826)
param: int    $parent_id  ID of post to get child counts from
param: array  $types      Optional. An array of post types to filter by
param: array  $statuses   Optional. An array of post statuses to filter by

bbp_get_public_child_count( $parent_id = 0, $post_type = 'post' )   X-Ref
Query the DB and get a count of public children

return: int The number of children
since: 2.0.0 bbPress (r2868)
since: 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects
param: int    $parent_id Parent id.
param: string $post_type Post type. Defaults to 'post'.

bbp_get_non_public_child_count( $parent_id = 0, $post_type = 'post' )   X-Ref
Query the DB and get a count of public children

return: int The number of children
since: 2.0.0 bbPress (r2868)
since: 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects
param: int    $parent_id Parent id.
param: string $post_type Post type. Defaults to 'post'.

bbp_get_public_child_ids( $parent_id = 0, $post_type = 'post' )   X-Ref
Query the DB and get the child id's of public children

return: array The array of children
since: 2.0.0 bbPress (r2868)
since: 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects
param: int    $parent_id Parent id.
param: string $post_type Post type. Defaults to 'post'.

bbp_get_all_child_ids( $parent_id = 0, $post_type = 'post' )   X-Ref
Query the DB and get the child id's of all children

return: array The array of children
since: 2.0.0 bbPress (r3325)
param: int $parent_id  Parent id
param: string $post_type Post type. Defaults to 'post'

bbp_update_post_family_caches( $objects = array()   X-Ref
Prime familial post caches.

This function uses _prime_post_caches() to prepare the object cache for
imminent requests to post objects that aren't naturally cached by the primary
WP_Query calls themselves. Post author caches are also primed.

This is triggered when a `update_post_family_cache` argument is set to true.

Also see: bbp_update_post_author_caches()

return: bool True if some IDs were cached
since: 2.6.0 bbPress (r6699)
param: array $objects Array of objects, fresh from a query

bbp_update_post_author_caches( $objects = array()   X-Ref
Prime post author caches.

This function uses cache_users() to prepare the object cache for
imminent requests to user objects that aren't naturally cached by the primary
WP_Query calls themselves.

This is triggered when a `update_post_author_cache` argument is set to true.

return: bool True if some IDs were cached
since: 2.6.0 bbPress (r6699)
param: array $objects Array of objects, fresh from a query

bbp_get_global_post_field( $field = 'ID', $context = 'edit' )   X-Ref
Get the unfiltered value of a global $post's key

Used most frequently when editing a forum/topic/reply

return: string Field value
since: 2.1.0 bbPress (r3694)
param: string $field Name of the key
param: string $context How to sanitize - raw|edit|db|display|attribute|js

bbp_verify_nonce_request( $action = '', $query_arg = '_wpnonce' )   X-Ref
Makes sure the user requested an action from another page on this site.

To avoid security exploits within the theme.

since: 2.1.0 bbPress (r4022)
param: string $action Action nonce
param: string $query_arg where to look for nonce in $_REQUEST

bbp_request_feed_trap( $query_vars = array()   X-Ref
This function is hooked into the WordPress 'request' action and is
responsible for sniffing out the query vars and serving up RSS2 feeds if
the stars align and the user has requested a feed of any bbPress type.

return: array
since: 2.0.0 bbPress (r3171)
param: array $query_vars

bbp_get_page_by_path( $path = '' )   X-Ref
Used to guess if page exists at requested path

return: mixed False if no page, Page object if true
since: 2.0.0 bbPress (r3304)
param: string $path

bbp_set_404( $query = null )   X-Ref
Sets the 404 status.

Used primarily with topics/replies inside hidden forums.

return: bool Always returns true
since: 2.0.0 bbPress (r3051)
since: 2.6.0 bbPress (r6583) Use status_header() & nocache_headers()
param: WP_Query $query  The query being checked

bbp_set_200()   X-Ref
Sets the 200 status header.

since: 2.6.0 bbPress (r6583)

bbp_pre_handle_404( $override = false, $wp_query = false )   X-Ref
Maybe handle the default 404 handling for some bbPress conditions

Some conditions (like private/hidden forums and edits) have their own checks
on `bbp_template_redirect` and are not currently 404s.

return: bool False to leave alone, true to override
since: 2.6.0 bbPress (r6555)
param: bool $override Whether to override the default handler
param: WP_Query $wp_query The posts query being referenced

bbp_posts_pre_query( $posts = null, $wp_query = false )   X-Ref
Maybe pre-assign the posts that are returned from a WP_Query.

This effectively short-circuits the default query for posts, which is
currently only used to avoid calling the main query when it's not necessary.

return: mixed Null if no override. Array if overridden.
since: 2.6.0 bbPress (r6580)
param: mixed $posts Default null. Array of posts (possibly empty)
param: WP_Query $wp_query

bbp_get_url_scheme()   X-Ref
Get scheme for a URL based on is_ssl() results.

return: string https:// if is_ssl(), otherwise http://
since: 2.6.0 bbPress (r6759)

bbp_is_title_too_long( $title = '' )   X-Ref
Is a title longer that the maximum title length?

Uses mb_strlen() in `8bit` mode to treat strings as raw. This matches the
behavior present in Comments, PHPMailer, RandomCompat, and others.

return: bool
since: 2.6.0 bbPress (r6783)
param: string $title



Generated: Sat Apr 27 01:00:49 2024 Cross-referenced by PHPXref 0.7.1