[ 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

since: 2.6.0 bbPress (r6813)
return: array
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

since: 2.0.0 bbPress (r3325)
return: string The link with 'view=all' appended if necessary
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

since: 2.0.0 bbPress (r3325)
return: string The link with 'view=all' appended if necessary
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

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

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

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

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

since: 2.6.0 bbPress (r6481)
return: array
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.

since: 2.0.0 bbPress (r2734)
return: array Data
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.

since: 2.0.0 bbPress (r3133)
since: 2.6.0 bbPress (r6868) Inverted some logic and added unit tests
return: bool True by default, if date is past, or editing is disabled.
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.

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

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

since: 2.0.0 bbPress (r2769)
since: 2.6.0 bbPress (r6055)  Added:
since: 2.6.10 bbPress (r7235) Renamed:
return: array Array of statistics
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}

since: 2.0.0 bbPress (r2734)
return: bool|array False on errors, values in an array on success
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

since: 2.6.0 bbPress (r6400)
return: array
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

since: 2.0.0 bbPress (r2763)
return: bool True if it is not a duplicate, false if it is
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.

since: 2.0.0 bbPress (r2734)
return: bool True if there is no flooding, false if there is
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

since: 2.1.0 bbPress (r3581)
return: bool True if test is passed, false if fail
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.

since: 2.6.0 bbPress (r5409)
return: string

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.

since: 2.6.0 bbPress (r5413)
return: bool True on success, false on failure
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.

since: 2.5.0 bbPress (r5156)
return: bool True on success, false on failure
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()

since: 2.0.0 bbPress (r2668)
return: bool True on success, false on failure
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

since: 2.6.0 bbPress (r6722)
return: array
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.

since: 2.6.0 bbPress (r6918)
return: array
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.

since: 2.6.0 bbPress (r6919)
return: string

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()`

since: 2.1.0 bbPress (2815)
return: string The url
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.

since: 2.1.0 bbPress (r3839)
return: array Merged user defined values with defaults.
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

since: 2.0.0 bbPress (r2996)
return: string
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

since: 2.0.0 bbPress (r2868)
since: 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects
return: int The last active post_id
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()`

since: 2.6.0 bbPress (r6826)
return: array A list of objects or object fields.
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

since: 2.0.0 bbPress (r2868)
since: 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects
return: int The number of children
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

since: 2.0.0 bbPress (r2868)
since: 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects
return: int The number of children
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

since: 2.0.0 bbPress (r2868)
since: 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects
return: array The array of children
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

since: 2.0.0 bbPress (r3325)
return: array The array of children
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()

since: 2.6.0 bbPress (r6699)
return: bool True if some IDs were cached
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.

since: 2.6.0 bbPress (r6699)
return: bool True if some IDs were cached
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

since: 2.1.0 bbPress (r3694)
return: string Field value
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.

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

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

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

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

Used primarily with topics/replies inside hidden forums.

since: 2.0.0 bbPress (r3051)
since: 2.6.0 bbPress (r6583) Use status_header() & nocache_headers()
return: bool Always returns true
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.

since: 2.6.0 bbPress (r6555)
return: bool False to leave alone, true to override
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.

since: 2.6.0 bbPress (r6580)
return: mixed Null if no override. Array if overridden.
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.

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

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.

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



Generated: Sat Dec 21 01:00:52 2024 Cross-referenced by PHPXref 0.7.1