Skip to:
Content

bbPress.org

Changeset 4971


Ignore:
Timestamp:
05/28/2013 11:12:36 PM (13 years ago)
Author:
johnjamesjacoby
Message:

Allow the search feature to be toggled on and off. Introduces new setting and supporting function to get and override the option easily in third party plugins. Fixes #2342.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/admin/settings.php

    r4969 r4971  
    8585                /** User Section ******************************************************/
    8686
    87                 'bbp_settings_user' => array(
     87                'bbp_settings_users' => array(
    8888
    8989                        // Edit lock setting
     
    158158                                'title'             => __( 'Topic tags', 'bbpress' ),
    159159                                'callback'          => 'bbp_admin_setting_callback_topic_tags',
     160                                'sanitize_callback' => 'intval',
     161                                'args'              => array()
     162                        ),
     163
     164                        // Allow topic tags
     165                        '_bbp_allow_search' => array(
     166                                'title'             => __( 'Search', 'bbpress' ),
     167                                'callback'          => 'bbp_admin_setting_callback_search',
    160168                                'sanitize_callback' => 'intval',
    161169                                'args'              => array()
     
    178186                        ),
    179187
    180                         // Allow threadde replies
    181                         '_bbp_allow_threaded_replies' => array(
    182                                 'sanitize_callback' => 'intval',
    183                                 'args'              => array()
    184                         ),
    185 
    186188                        // Set reply threading level
    187189                        '_bbp_thread_replies_depth' => array(
    188190                                'title'             => __( 'Reply Threading', 'bbpress' ),
    189191                                'callback'          => 'bbp_admin_setting_callback_thread_replies_depth',
     192                                'sanitize_callback' => 'intval',
     193                                'args'              => array()
     194                        ),
     195
     196                        // Allow threadde replies
     197                        '_bbp_allow_threaded_replies' => array(
    190198                                'sanitize_callback' => 'intval',
    191199                                'args'              => array()
     
    588596        <input id="_bbp_allow_topic_tags" name="_bbp_allow_topic_tags" type="checkbox" id="_bbp_allow_topic_tags" value="1" <?php checked( bbp_allow_topic_tags( true ) ); bbp_maybe_admin_setting_disabled( '_bbp_allow_topic_tags' ); ?> />
    589597        <label for="_bbp_allow_topic_tags"><?php esc_html_e( 'Allow topics to have tags', 'bbpress' ); ?></label>
     598
     599<?php
     600}
     601
     602/**
     603 * Allow forum wide search
     604 *
     605 * @since bbPress (r4970)
     606 *
     607 * @uses checked() To display the checked attribute
     608 */
     609function bbp_admin_setting_callback_search() {
     610?>
     611
     612        <input id="_bbp_allow_search" name="_bbp_allow_search" type="checkbox" id="_bbp_allow_search" value="1" <?php checked( bbp_allow_search( true ) ); bbp_maybe_admin_setting_disabled( '_bbp_allow_search' ); ?> />
     613        <label for="_bbp_allow_search"><?php esc_html_e( 'Allow forum wide search', 'bbpress' ); ?></label>
    590614
    591615<?php
  • trunk/includes/common/shortcodes.php

    r4917 r4971  
    621621        public function display_search_form() {
    622622
     623                // Bail if search is disabled
     624                if ( ! bbp_allow_search() ) {
     625                        return;
     626                }
     627
    623628                // Start output buffer
    624629                $this->start( 'bbp_search_form' );
     
    645650
    646651                // Sanity check required info
    647                 if ( !empty( $content ) )
     652                if ( !empty( $content ) ) {
    648653                        return $content;
     654                }
     655
     656                // Bail if search is disabled
     657                if ( ! bbp_allow_search() ) {
     658                        return;
     659                }
    649660
    650661                // Trim search attribute if it's set
  • trunk/includes/common/template-tags.php

    r4953 r4971  
    795795        global $wp_query;
    796796
     797        // Bail if search is disabled
     798        if ( ! bbp_allow_search() )
     799                return false;
     800
    797801        // Assume false
    798802        $retval = false;
     
    824828function bbp_is_search_results() {
    825829        global $wp_query;
     830
     831        // Bail if search is disabled
     832        if ( ! bbp_allow_search() )
     833                return false;
    826834
    827835        // Assume false
  • trunk/includes/common/widgets.php

    r4948 r4971  
    408408         */
    409409        public function widget( $args, $instance ) {
     410
     411                // Bail if search is disabled
     412                if ( ! bbp_allow_search() )
     413                        return;
    410414
    411415                // Get widget settings
  • trunk/includes/core/options.php

    r4963 r4971  
    3737                '_bbp_allow_global_access'    => 1,                          // Users from all sites can post
    3838                '_bbp_allow_revisions'        => 1,                          // Allow revisions
    39                 '_bbp_allow_topic_tags'       => 1,                          // Topic Tags
     39                '_bbp_allow_topic_tags'       => 1,                          // Allow topic tagging
    4040                '_bbp_allow_threaded_replies' => 0,                          // Allow threaded replies
     41                '_bbp_allow_search'           => 1,                          // Allow forum-wide search
    4142                '_bbp_thread_replies_depth'   => 2,                          // Thread replies depth
    4243                '_bbp_use_wp_editor'          => 1,                          // Use the WordPress editor if available
     
    228229function bbp_allow_topic_tags( $default = 1 ) {
    229230        return (bool) apply_filters( 'bbp_allow_topic_tags', (bool) get_option( '_bbp_allow_topic_tags', $default ) );
     231}
     232
     233/**
     234 * Is forum-wide searching allowed
     235 *
     236 * @since bbPress (r4970)
     237 * @param $default bool Optional. Default value true
     238 * @uses get_option() To get the forum-wide search setting
     239 * @return bool Is forum-wide searching allowed?
     240 */
     241function bbp_allow_search( $default = 1 ) {
     242        return (bool) apply_filters( 'bbp_allow_search', (bool) get_option( '_bbp_allow_search', $default ) );
    230243}
    231244
  • trunk/templates/default/bbpress/content-archive-forum.php

    r4733 r4971  
    1212<div id="bbpress-forums">
    1313
    14         <div class="bbp-search-form">
     14        <?php if ( bbp_allow_search() ) : ?>
    1515
    16                 <?php bbp_get_template_part( 'form', 'search' ); ?>
     16                <div class="bbp-search-form">
    1717
    18         </div>
     18                        <?php bbp_get_template_part( 'form', 'search' ); ?>
     19
     20                </div>
     21
     22        <?php endif; ?>
    1923
    2024        <?php bbp_breadcrumb(); ?>
  • trunk/templates/default/bbpress/content-archive-topic.php

    r4733 r4971  
    1111
    1212<div id="bbpress-forums">
     13
     14        <?php if ( bbp_allow_search() ) : ?>
     15
     16                <div class="bbp-search-form">
     17
     18                        <?php bbp_get_template_part( 'form', 'search' ); ?>
     19
     20                </div>
     21
     22        <?php endif; ?>
    1323
    1424        <?php bbp_breadcrumb(); ?>
Note: See TracChangeset for help on using the changeset viewer.