Skip to:
Content

bbPress.org

Changeset 5856


Ignore:
Timestamp:
07/16/2015 03:26:57 AM (6 years ago)
Author:
johnjamesjacoby
Message:

Forums: Introduce bbp_update_forum_visibility action in bbp_save_forum_extras()

This changeset provides custom visibilites with an execution point to perform their own actions.

Fixes #2740.

File:
1 edited

Legend:

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

    r5855 r5856  
    670670    }
    671671
    672     /** Forum Status ******************************************************/
     672    /** Forum Status **********************************************************/
    673673
    674674    if ( ! empty( $_POST['bbp_forum_status'] ) && in_array( $_POST['bbp_forum_status'], array( 'open', 'closed' ) ) ) {
     
    682682    }
    683683
    684     /** Forum Type ********************************************************/
     684    /** Forum Type ************************************************************/
    685685
    686686    if ( ! empty( $_POST['bbp_forum_type'] ) && in_array( $_POST['bbp_forum_type'], array( 'forum', 'category' ) ) ) {
     
    694694    }
    695695
    696     /** Forum Visibility **************************************************/
    697 
    698     if ( ! empty( $_POST['bbp_forum_visibility'] ) && in_array( $_POST['bbp_forum_visibility'], array( bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id() ) ) ) {
     696    /** Forum Visibility ******************************************************/
     697
     698    if ( ! empty( $_POST['bbp_forum_visibility'] ) && in_array( $_POST['bbp_forum_visibility'], array_keys( bbp_get_forum_visibilities() ) ) ) {
    699699
    700700        // Get forums current visibility
    701         $visibility = bbp_get_forum_visibility( $forum_id );
     701        $old_visibility = bbp_get_forum_visibility( $forum_id );
     702
     703        // Sanitize the new visibility
     704        $new_visibility = sanitize_key( $_POST['bbp_forum_visibility'] );
    702705
    703706        // What is the new forum visibility setting?
    704         switch ( $_POST['bbp_forum_visibility'] ) {
     707        switch ( $new_visibility ) {
    705708
    706709            // Hidden
    707710            case bbp_get_hidden_status_id()  :
    708                 bbp_hide_forum( $forum_id, $visibility );
     711                bbp_hide_forum( $forum_id, $old_visibility );
    709712                break;
    710713
    711714            // Private
    712715            case bbp_get_private_status_id() :
    713                 bbp_privatize_forum( $forum_id, $visibility );
     716                bbp_privatize_forum( $forum_id, $old_visibility );
    714717                break;
    715718
    716719            // Publish (default)
    717720            case bbp_get_public_status_id()  :
    718             default        :
    719                 bbp_publicize_forum( $forum_id, $visibility );
     721            default :
     722                bbp_publicize_forum( $forum_id, $old_visibility );
    720723                break;
    721724        }
    722     }
    723 }
    724 
    725 /** Forum Actions *************************************************************/
     725
     726        /**
     727         * Allow custom forum visibility save actions
     728         *
     729         * @since bbPress (r5855)
     730         *
     731         * @param int    $forum_id       The forum ID
     732         * @param string $old_visibility The current forum visibility
     733         * @param string $new_visibility The new forum visibility
     734         */
     735        do_action( 'bbp_update_forum_visibility', $forum_id, $old_visibility, $new_visibility );
     736    }
     737}
     738
     739/** Forum Open/Close **********************************************************/
    726740
    727741/**
     
    774788}
    775789
     790/** Forum Type ****************************************************************/
     791
    776792/**
    777793 * Make the forum a category
     
    817833    return $forum_id;
    818834}
     835
     836/** Forum Visibility **********************************************************/
    819837
    820838/**
Note: See TracChangeset for help on using the changeset viewer.