Skip to:
Content

bbPress.org

Changeset 6026


Ignore:
Timestamp:
05/19/2016 07:35:41 PM (8 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.

Location:
trunk/src/includes
Files:
4 edited

Legend:

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

    r5954 r6026  
    17911791 * @since 2.4.0 bbPress (r5059)
    17921792 *
     1793 * @param int $forum_id   Optional. Forum id.
     1794 *
    17931795 * @return array
    17941796 */
    1795 function bbp_get_forum_statuses() {
     1797function bbp_get_forum_statuses( $forum_id = 0 ) {
    17961798    return apply_filters( 'bbp_get_forum_statuses', array(
    17971799        'open'   => _x( 'Open',    'Open the forum',  'bbpress' ),
    17981800        'closed' => _x( 'Closed',  'Close the forum', 'bbpress' )
    1799     ) );
     1801    ), $forum_id );
    18001802}
    18011803
     
    18051807 * @since 2.4.0 bbPress (r5059)
    18061808 *
     1809 * @param int $forum_id   Optional. Forum id.
     1810 *
    18071811 * @return array
    18081812 */
    1809 function bbp_get_forum_types() {
     1813function bbp_get_forum_types( $forum_id = 0 ) {
    18101814    return apply_filters( 'bbp_get_forum_types', array(
    18111815        'forum'    => _x( 'Forum',    'Forum accepts new topics', 'bbpress' ),
    18121816        'category' => _x( 'Category', 'Forum is a category',      'bbpress' )
    1813     ) );
     1817    ), $forum_id );
    18141818}
    18151819
     
    18191823 * @since 2.4.0 bbPress (r5059)
    18201824 *
     1825 * @param int $forum_id   Optional. Forum id.
     1826 *
    18211827 * @return array
    18221828 */
    1823 function bbp_get_forum_visibilities() {
     1829function bbp_get_forum_visibilities( $forum_id = 0) {
    18241830    return apply_filters( 'bbp_get_forum_visibilities', array(
    18251831        bbp_get_public_status_id()  => _x( 'Public',  'Make forum public',  'bbpress' ),
    18261832        bbp_get_private_status_id() => _x( 'Private', 'Make forum private', 'bbpress' ),
    18271833        bbp_get_hidden_status_id()  => _x( 'Hidden',  'Make forum hidden',  'bbpress' )
    1828     ) );
     1834    ), $forum_id );
    18291835}
    18301836
  • trunk/src/includes/forums/template.php

    r6024 r6026  
    26832683        <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select"<?php echo $tab; ?>>
    26842684
    2685             <?php foreach ( bbp_get_forum_types() as $key => $label ) : ?>
     2685            <?php foreach ( bbp_get_forum_types( $r['forum_id'] ) as $key => $label ) : ?>
    26862686
    26872687                <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
     
    27752775        <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select"<?php echo $tab; ?>>
    27762776
    2777             <?php foreach ( bbp_get_forum_statuses() as $key => $label ) : ?>
     2777            <?php foreach ( bbp_get_forum_statuses( $r['forum_id'] ) as $key => $label ) : ?>
    27782778
    27792779                <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
     
    28672867        <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select"<?php echo $tab; ?>>
    28682868
    2869             <?php foreach ( bbp_get_forum_visibilities() as $key => $label ) : ?>
     2869            <?php foreach ( bbp_get_forum_visibilities( $r['forum_id'] ) as $key => $label ) : ?>
    28702870
    28712871                <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
  • trunk/src/includes/replies/functions.php

    r5969 r6026  
    16961696 * @since 2.6.0 bbPress (r5399)
    16971697 *
     1698 * @param int $reply_id   Optional. Reply id.
     1699 *
    16981700 * @return array
    16991701 */
    1700 function bbp_get_reply_statuses() {
     1702function bbp_get_reply_statuses( $reply_id = 0 ) {
    17011703    return apply_filters( 'bbp_get_reply_statuses', array(
    17021704        bbp_get_public_status_id()  => _x( 'Publish', 'Publish the reply',     'bbpress' ),
     
    17041706        bbp_get_trash_status_id()   => _x( 'Trash',   'Trash the reply',       'bbpress' ),
    17051707        bbp_get_pending_status_id() => _x( 'Pending', 'Mark reply as pending', 'bbpress' ),
    1706     ) );
     1708    ), $reply_id );
    17071709}
    17081710
  • 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.