Skip to:
Content

bbPress.org


Ignore:
Timestamp:
05/19/2016 07:35:41 PM (9 years ago)
Author:
johnjamesjacoby
Message:

Statuses, Types, Visibilities: Pass the forum, topic, or reply ID into helper functions.

These ID's pass additional context into respective filters, useful for fine-grained control over UI elements.

This commit normalizes the way these functions work across all of bbPress where applicable, by ensuring all similar functions accept an ID and assume 0 by default. Note that there are currently 2 locations where no ID exists to pass context into, which is by design.

Fixes #2954.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/topics/functions.php

    r5969 r6026  
    284284    /** Topic Status **********************************************************/
    285285
     286    // Get available topic statuses
     287    $topic_statuses = bbp_get_topic_statuses();
     288
    286289    // Maybe put into moderation
    287290    if ( ! bbp_check_for_moderation( $anonymous_data, $topic_author, $topic_title, $topic_content ) ) {
     
    289292
    290293    // Check a whitelist of possible topic status ID's
    291     } elseif ( ! empty( $_POST['bbp_topic_status'] ) && in_array( $_POST['bbp_topic_status'], array_keys( bbp_get_topic_statuses() ) ) ) {
     294    } elseif ( ! empty( $_POST['bbp_topic_status'] ) && in_array( $_POST['bbp_topic_status'], array_keys( $topic_statuses ) ) ) {
    292295        $topic_status = sanitize_key( $_POST['bbp_topic_status'] );
    293296
     
    628631    /** Topic Status **********************************************************/
    629632
     633    // Get available topic statuses
     634    $topic_statuses = bbp_get_topic_statuses( $topic_id );
     635
    630636    // Maybe put into moderation
    631637    if ( ! bbp_check_for_moderation( $anonymous_data, $topic_author, $topic_title, $topic_content ) ) {
     
    637643
    638644    // Check a whitelist of possible topic status ID's
    639     } elseif ( ! empty( $_POST['bbp_topic_status'] ) && in_array( $_POST['bbp_topic_status'], array_keys( bbp_get_topic_statuses() ) ) ) {
     645    } elseif ( ! empty( $_POST['bbp_topic_status'] ) && in_array( $_POST['bbp_topic_status'], array_keys( $topic_statuses ) ) ) {
    640646        $topic_status = sanitize_key( $_POST['bbp_topic_status'] );
    641647
     
    20082014 * @since 2.4.0 bbPress (r5059)
    20092015 *
     2016 * @param int $topic_id   Optional. Topic id.
     2017 *
    20102018 * @return array
    20112019 */
    2012 function bbp_get_topic_statuses() {
     2020function bbp_get_topic_statuses( $topic_id = 0 ) {
    20132021    return apply_filters( 'bbp_get_topic_statuses', array(
    20142022        bbp_get_public_status_id()  => _x( 'Open',    'Open the topic',        'bbpress' ),
     
    20172025        bbp_get_trash_status_id()   => _x( 'Trash',   'Trash the topic',       'bbpress' ),
    20182026        bbp_get_pending_status_id() => _x( 'Pending', 'Mark topic as pending', 'bbpress' ),
    2019     ) );
     2027    ), $topic_id );
    20202028}
    20212029
     
    20252033 * @since 2.4.0 bbPress (r5059)
    20262034 *
     2035 * @param int $topic_id   Optional. Topic id.
     2036 *
    20272037 * @return array
    20282038 */
    2029 function bbp_get_topic_types() {
     2039function bbp_get_topic_types( $topic_id = 0 ) {
    20302040    return apply_filters( 'bbp_get_topic_types', array(
    20312041        'unstick' => _x( 'Normal',       'Unstick a topic',         'bbpress' ),
    20322042        'stick'   => _x( 'Sticky',       'Make topic sticky',       'bbpress' ),
    20332043        'super'   => _x( 'Super Sticky', 'Make topic super sticky', 'bbpress' )
    2034     ) );
     2044    ), $topic_id );
    20352045}
    20362046
Note: See TracChangeset for help on using the changeset viewer.