Skip to:
Content

bbPress.org

Changeset 3575


Ignore:
Timestamp:
11/02/2011 09:22:04 PM (10 years ago)
Author:
johnjamesjacoby
Message:

Add functions and settings for BuddyPress group forums and Akismet extensions. Add checks to these settings to only show them when relevant. Do not load new Forums component if BuddyPress forums are already active. See #1669.

Location:
branches/plugin
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-admin/bbp-admin.php

    r3469 r3575  
    302302        register_setting  ( 'bbpress',              '_bbp_view_slug',                 'sanitize_title'                                                                );
    303303
     304        /** BuddyPress ********************************************************/
     305
     306        if ( is_plugin_active( 'buddypress/bp-loader.php' ) && defined( 'BP_VERSION' ) && !bp_is_active( 'forums' ) ) {
     307
     308            // Add the per page section
     309            add_settings_section( 'bbp_buddypress',          __( 'BuddyPress', 'bbpress' ),          'bbp_admin_setting_callback_buddypress_section',   'bbpress'                   );
     310
     311            // Topics per page setting
     312            add_settings_field( '_bbp_enable_group_forums',  __( 'Enable Group Forums', 'bbpress' ), 'bbp_admin_setting_callback_group_forums',         'bbpress', 'bbp_buddypress' );
     313            register_setting  ( 'bbpress',                  '_bbp_enable_group_forums',                  'intval'                                                                       );
     314
     315            // Topics per page setting
     316            add_settings_field( '_bbp_group_forums_root_id', __( 'Root Group Forum', 'bbpress' ),    'bbp_admin_setting_callback_group_forums_root_id', 'bbpress', 'bbp_buddypress' );
     317            register_setting  ( 'bbpress',                  '_bbp_group_forums_root_id',             'intval'                                                                       );
     318        }
     319
     320        /** Akismet ***********************************************************/
     321
     322        if ( is_plugin_active( 'akismet/akismet.php' ) && defined( 'AKISMET_VERSION' ) ) {
     323
     324            // Add the per page section
     325            add_settings_section( 'bbp_akismet',       __( 'Akismet', 'bbpress' ),      'bbp_admin_setting_callback_akismet_section', 'bbpress'                );
     326
     327            // Replies per page setting
     328            add_settings_field( '_bbp_enable_akismet', __( 'Use Akismet',  'bbpress' ), 'bbp_admin_setting_callback_akismet',         'bbpress', 'bbp_akismet' );
     329            register_setting  ( 'bbpress',            '_bbp_enable_akismet',            'intval'                                                               );
     330        }
     331
    304332        do_action( 'bbp_register_admin_settings' );
    305333    }
  • branches/plugin/bbp-admin/bbp-settings.php

    r3495 r3575  
    1111if ( !defined( 'ABSPATH' ) ) exit;
    1212
    13 /** Start Main Section ********************************************************/
     13/** Main Section **************************************************************/
    1414
    1515/**
     
    2121?>
    2222
    23     <p><?php _e( 'Main settings for the bbPress plugin', 'bbpress' ); ?></p>
     23    <p><?php _e( 'Main forum settings for enabling features and setting time limits', 'bbpress' ); ?></p>
    2424
    2525<?php
     
    6969
    7070    <input id="_bbp_enable_favorites" name="_bbp_enable_favorites" type="checkbox" id="_bbp_enable_favorites" value="1" <?php checked( bbp_is_favorites_active( true ) ); ?> />
    71     <label for="_bbp_enable_favorites"><?php _e( 'Allow users to mark topics as favorites?', 'bbpress' ); ?></label>
     71    <label for="_bbp_enable_favorites"><?php _e( 'Allow users to mark topics as favorites', 'bbpress' ); ?></label>
    7272
    7373<?php
     
    138138}
    139139
    140 /** Start Per Page Section ****************************************************/
     140/** Per Page Section **********************************************************/
    141141
    142142/**
     
    148148?>
    149149
    150     <p><?php _e( 'Per page settings for the bbPress plugin', 'bbpress' ); ?></p>
     150    <p><?php _e( 'How many topics and replies to show per page', 'bbpress' ); ?></p>
    151151
    152152<?php
     
    185185}
    186186
    187 /** Start Per RSS Page Section ************************************************/
     187/** Per RSS Page Section ******************************************************/
    188188
    189189/**
     
    195195?>
    196196
    197     <p><?php _e( 'Per RSS page settings for the bbPress plugin', 'bbpress' ); ?></p>
     197    <p><?php _e( 'How many topics and replies to show per RSS page', 'bbpress' ); ?></p>
    198198
    199199<?php
     
    232232}
    233233
    234 /** Start Slug Section ********************************************************/
     234/** Slug Section **************************************************************/
    235235
    236236/**
     
    245245        flush_rewrite_rules(); ?>
    246246
    247     <p><?php printf( __( 'Include custom root slugs to prefix your forums and topics with. These can be partnered with WordPress pages to allow more flexibility.', 'bbpress' ), get_admin_url( null, 'options-permalink.php' ) ); ?></p>
     247    <p><?php printf( __( 'Custom root slugs to prefix your forums and topics with. These can be partnered with WordPress pages to allow more flexibility.', 'bbpress' ), get_admin_url( null, 'options-permalink.php' ) ); ?></p>
    248248
    249249<?php
     
    294294?>
    295295
    296     <p><?php printf( __( 'You can enter custom slugs for your single forums, topics, replies, and tags URLs here. If you change these, existing permalinks will also change.', 'bbpress' ), get_admin_url( null, 'options-permalink.php' ) ); ?></p>
     296    <p><?php printf( __( 'Custom slugs for single forums, topics, replies, tags, users, and views here. If you change these, existing permalinks will also change.', 'bbpress' ), get_admin_url( null, 'options-permalink.php' ) ); ?></p>
    297297
    298298<?php
     
    418418    // Slug Check
    419419    bbp_form_slug_conflict_check( '_bbp_view_slug', 'view' );
     420}
     421
     422/** BuddyPress ****************************************************************/
     423
     424/**
     425 * Extension settings section description for the settings page
     426 *
     427 * @since bbPress (r3575)
     428 */
     429function bbp_admin_setting_callback_buddypress_section() {
     430?>
     431
     432    <p><?php _e( 'Forum settings for BuddyPress', 'bbpress' ); ?></p>
     433
     434<?php
     435}
     436
     437/**
     438 * Allow BuddyPress group forums setting field
     439 *
     440 * @since bbPress (r3575)
     441 *
     442 * @uses checked() To display the checked attribute
     443 */
     444function bbp_admin_setting_callback_group_forums() {
     445?>
     446
     447    <input id="_bbp_enable_group_forums" name="_bbp_enable_group_forums" type="checkbox" id="_bbp_enable_group_forums" value="1" <?php checked( bbp_is_akismet_active( true ) ); ?> />
     448    <label for="_bbp_enable_group_forums"><?php _e( 'Allow BuddyPress Groups to have their own forums', 'bbpress' ); ?></label>
     449
     450<?php
     451}
     452
     453/**
     454 * Replies per page setting field
     455 *
     456 * @since bbPress (r3575)
     457 *
     458 * @uses bbp_form_option() To output the option value
     459 */
     460function bbp_admin_setting_callback_group_forums_root_id() {
     461?>
     462
     463    <?php
     464        bbp_dropdown( array(
     465            'selected'           => bbp_get_group_forums_root_id(),
     466            'show_none'          => __( '(Forum Root)', 'bbpress' ),
     467            'select_id'          => '_bbp_group_forums_root_id',
     468            'disable_categories' => false
     469        ) );
     470    ?>
     471
     472    <label for="_bbp_group_forums_root_id"><?php _e( 'is the parent for all group forums', 'bbpress' ); ?></label>
     473
     474<?php
     475}
     476
     477/** Akismet *******************************************************************/
     478
     479/**
     480 * Extension settings section description for the settings page
     481 *
     482 * @since bbPress (r3575)
     483 */
     484function bbp_admin_setting_callback_akismet_section() {
     485?>
     486
     487    <p><?php _e( 'Forum settings for Akismet', 'bbpress' ); ?></p>
     488
     489<?php
     490}
     491
     492
     493/**
     494 * Allow Akismet setting field
     495 *
     496 * @since bbPress (r3575)
     497 *
     498 * @uses checked() To display the checked attribute
     499 */
     500function bbp_admin_setting_callback_akismet() {
     501?>
     502
     503    <input id="_bbp_enable_akismet" name="_bbp_enable_akismet" type="checkbox" id="_bbp_enable_akismet" value="1" <?php checked( bbp_is_akismet_active( true ) ); ?> />
     504    <label for="_bbp_enable_akismet"><?php _e( 'Allow Akismet to actively prevent topic and reply spam', 'bbpress' ); ?></label>
     505
     506<?php
    420507}
    421508
     
    555642
    556643    // Only set the slugs once ver page load
    557     static $the_core_slugs;
     644    static $the_core_slugs = array();
    558645
    559646    // Get the form value
  • branches/plugin/bbp-includes/bbp-core-options.php

    r3452 r3575  
    129129        // Hidden forums
    130130        '_bbp_hidden_forums'        => '',
     131
     132        /** BuddyPress ********************************************************/
     133
     134        // Enable BuddyPress Group Extension
     135        '_bbp_enable_group_forums'  => true,
     136
     137        // Group Forums parent forum id
     138        '_bbp_group_forums_root_id' => '0',
     139
     140        /** Akismet ***********************************************************/
     141
     142        // Users from all sites can post
     143        '_bbp_enable_akismet'       => true,
    131144    );
    132145
     
    182195 * Add filters to each bbPress option and allow them to be overloaded from
    183196 * inside the $bbp->options array.
    184  * 
     197 *
    185198 * @since bbPress (r3451)
    186199 *
     
    190203 */
    191204function bbp_setup_option_filters() {
    192    
     205
    193206    // Get the default options and values
    194207    $options = bbp_get_default_options();
     
    209222 *
    210223 * @global bbPress $bbp
    211  * @param bool $value
     224 * @param bool $value Optional. Default value false
    212225 * @return mixed false if not overloaded, mixed if set
    213226 */
     
    236249 * @since bbPress (r2658)
    237250 *
    238  * @param $default bool Optional.Default value
     251 * @param $default bool Optional.Default value true
    239252 *
    240253 * @uses get_option() To get the favorites option
     
    242255 */
    243256function bbp_is_favorites_active( $default = true ) {
    244     return apply_filters( 'bbp_is_favorites_active', (bool) get_option( '_bbp_enable_favorites', $default ) );
     257    return (bool) apply_filters( 'bbp_is_favorites_active', (bool) get_option( '_bbp_enable_favorites', $default ) );
    245258}
    246259
     
    250263 * @since bbPress (r2658)
    251264 *
    252  * @param $default bool Optional.Default value
     265 * @param $default bool Optional.Default value true
    253266 *
    254267 * @uses get_option() To get the subscriptions option
     
    256269 */
    257270function bbp_is_subscriptions_active( $default = true ) {
    258     return apply_filters( 'bbp_is_subscriptions_active', (bool) get_option( '_bbp_enable_subscriptions', $default ) );
     271    return (bool) apply_filters( 'bbp_is_subscriptions_active', (bool) get_option( '_bbp_enable_subscriptions', $default ) );
    259272}
    260273
     
    264277 * @since bbPress (r3412)
    265278 *
    266  * @param $default bool Optional. Default value
     279 * @param $default bool Optional. Default value true
    267280 *
    268281 * @uses get_option() To get the allow revisions
     
    270283 */
    271284function bbp_allow_revisions( $default = true ) {
    272     return apply_filters( 'bbp_allow_revisions', (bool) get_option( '_bbp_allow_revisions', $default ) );
     285    return (bool) apply_filters( 'bbp_allow_revisions', (bool) get_option( '_bbp_allow_revisions', $default ) );
    273286}
    274287
     
    292305 * @since bbPress (r3378)
    293306 *
    294  * @param $default bool Optional. Default value
     307 * @param $default bool Optional. Default value false
    295308 *
    296309 * @uses get_option() To get the global access option
     
    298311 */
    299312function bbp_allow_global_access( $default = false ) {
    300     return apply_filters( 'bbp_allow_global_access', (bool) get_option( '_bbp_allow_global_access', $default ) );
     313    return (bool) apply_filters( 'bbp_allow_global_access', (bool) get_option( '_bbp_allow_global_access', $default ) );
    301314}
    302315
     
    306319 * @since bbPress (r3246)
    307320 *
    308  * @param $default bool Optional. Default value
     321 * @param $default bool Optional. Default value 80
    309322 */
    310323function bbp_title_max_length( $default = '80' ) {
     
    316329     * @since bbPress (r3246)
    317330     *
    318      * @param $default bool Optional. Default value
     331     * @param $default bool Optional. Default value 80
    319332     *
    320333     * @uses get_option() To get the maximum title length
     
    322335     */
    323336    function bbp_get_title_max_length( $default = '80' ) {
    324         return apply_filters( 'bbp_get_title_max_length', (int) get_option( '_bbp_title_max_length', $default ) );
     337        return (int) apply_filters( 'bbp_get_title_max_length', (int) get_option( '_bbp_title_max_length', $default ) );
    325338    }
    326339
     340/**
     341 * Output the grop forums root parent forum id
     342 *
     343 * @since bbPress (r3575)
     344 *
     345 * @param $default bool Optional. Default value
     346 */
     347function bbp_group_forums_root_id( $default = '0' ) {
     348    echo bbp_get_group_forums_root_id( $default );
     349}
     350    /**
     351     * Return the grop forums root parent forum id
     352     *
     353     * @since bbPress (r3575)
     354     *
     355     * @param $default bool Optional. Default value 0
     356     *
     357     * @uses get_option() To get the maximum title length
     358     * @return int Is anonymous posting allowed?
     359     */
     360    function bbp_get_group_forums_root_id( $default = '0' ) {
     361        return (int) apply_filters( 'bbp_get_group_forums_root_id', (int) get_option( '_bbp_group_forums_root_id', $default ) );
     362    }
     363
     364/**
     365 * Checks if BuddyPress Group Forums are enabled
     366 *
     367 * @since bbPress (r3575)
     368 *
     369 * @param $default bool Optional. Default value true
     370 *
     371 * @uses get_option() To get the group forums option
     372 * @return bool Is group forums enabled or not
     373 */
     374function bbp_is_group_forums_active( $default = true ) {
     375    return (bool) apply_filters( 'bbp_is_group_forums_active', (bool) get_option( '_bbp_enable_group_forums', $default ) );
     376}
     377
     378/**
     379 * Checks if Akismet is enabled
     380 *
     381 * @since bbPress (r3575)
     382 *
     383 * @param $default bool Optional. Default value true
     384 *
     385 * @uses get_option() To get the Akismet option
     386 * @return bool Is Akismet enabled or not
     387 */
     388function bbp_is_akismet_active( $default = true ) {
     389    return (bool) apply_filters( 'bbp_is_akismet_active', (bool) get_option( '_bbp_enable_akismet', $default ) );
     390}
     391
    327392?>
  • branches/plugin/bbp-includes/bbp-extend-akismet.php

    r3505 r3575  
    690690    if ( 'bbPress' !== get_class( $bbp ) ) return;
    691691
     692    // Bail if Akismet is turned off
     693    if ( !bbp_is_akismet_active() ) return;
     694
    692695    // Instantiate Akismet for bbPress
    693696    $bbp->extend->akismet = new BBP_Akismet();
  • branches/plugin/bbp-includes/bbp-extend-buddypress.php

    r3565 r3575  
    428428    public function user_profile_url( $user_id ) {
    429429
     430        // Define local variable(s)
     431        $profile_url = '';
     432
    430433        // Special handling for forum component
    431434        if ( bp_is_current_component( 'forums' ) ) {
     
    716719            return;
    717720
     721        // Define local variable(s)
     722        $sub_nav     = array();
     723        $user_domain = '';
     724
    718725        // Add 'Forums' to the main navigation
    719726        $main_nav = array(
     
    727734
    728735        // Determine user to use
    729         if ( isset( $bp->displayed_user->domain ) ) {
     736        if ( isset( $bp->displayed_user->domain ) )
    730737            $user_domain = $bp->displayed_user->domain;
    731             $user_login  = $bp->displayed_user->userdata->user_login;
    732         } elseif ( isset( $bp->loggedin_user->domain ) ) {
     738        elseif ( isset( $bp->loggedin_user->domain ) )
    733739            $user_domain = $bp->loggedin_user->domain;
    734             $user_login  = $bp->loggedin_user->userdata->user_login;
    735         } else {
     740        else
    736741            return;
    737         }
    738742
    739743        // User link
     
    807811            // Setup the logged in user variables
    808812            $user_domain = $bp->loggedin_user->domain;
    809             $user_login  = $bp->loggedin_user->userdata->user_login;
    810813            $forums_link = trailingslashit( $user_domain . $this->slug );
    811814
     
    10511054    if ( 'bbPress' !== get_class( $bbp ) ) return;
    10521055
    1053     // Instantiate BuddyPress forums component
     1056    // Bail if BuddyPress Forums are already active
     1057    if ( bp_is_active( 'forums' ) ) return;
     1058
     1059    // Create the new BuddyPress Forums component
    10541060    $bp->forums = new BBP_Forums_Component();
    10551061
    1056     // Setup the group extension
    1057     if ( bp_is_active( 'groups' ) )
     1062    // Register the group extension only if groups are active
     1063    if ( bbp_is_group_forums_active() && bp_is_active( 'groups' ) ) {
    10581064        bp_register_group_extension( 'BBP_Forums_Group_Extension' );
     1065    }
    10591066}
    10601067
Note: See TracChangeset for help on using the changeset viewer.