Skip to:
Content

bbPress.org


Ignore:
Timestamp:
08/02/2013 07:20:49 AM (13 years ago)
Author:
johnjamesjacoby
Message:

Normalize forum, topic, and reply dropdown form fields and associated functions. Includes several new functions with _get_ equivalents to replace incorrectly named _select() functions.

First pass at adding custom topic status handling. Props jkudish. See #2187.

Also replaces $wpdb->update() calls with wp_update_post() in associated functions. Fixes #2351.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/forums/template.php

    r5058 r5060  
    6565                'posts_per_page'      => get_option( '_bbp_forums_per_page', 50 ),
    6666                'ignore_sticky_posts' => true,
    67                 'orderby'             => 'menu_order title',
     67                'orderby'             => 'menu_order',
    6868                'order'               => 'ASC'
    6969        ), 'has_forums' );
     
    21102110        }
    21112111
    2112 /** Form Dropdows *************************************************************/
     2112/** Form Dropdowns ************************************************************/
    21132113
    21142114/**
     
    21202120 * @uses bbp_get_form_forum_type() To get the topic's forum id
    21212121 */
    2122 function bbp_form_forum_type_dropdown( $forum_id = 0 ) {
    2123         echo bbp_get_form_forum_type_dropdown( $forum_id );
     2122function bbp_form_forum_type_dropdown( $args = '' ) {
     2123        echo bbp_get_form_forum_type_dropdown( $args );
    21242124}
    21252125        /**
     
    21342134         * @return string HTML select list for selecting forum type
    21352135         */
    2136         function bbp_get_form_forum_type_dropdown( $forum_id = 0 ) {
    2137                 $forum_id   = bbp_get_forum_id( $forum_id );
    2138                 $forum_attr = apply_filters( 'bbp_forum_types', array(
    2139                         'forum'    => __( 'Forum',    'bbpress' ),
    2140                         'category' => __( 'Category', 'bbpress' )
    2141                 ) );
    2142                 $type_output = '<select name="bbp_forum_type" id="bbp_forum_type_select">' . "\n";
    2143 
    2144                 foreach ( $forum_attr as $value => $label )
    2145                         $type_output .= "\t" . '<option value="' . esc_attr( $value ) . '"' . selected( bbp_get_forum_type( $forum_id ), $value, false ) . '>' . esc_html( $label ) . '</option>' . "\n";
    2146 
    2147                 $type_output .= '</select>';
    2148 
    2149                 return apply_filters( 'bbp_get_form_forum_type_dropdown', $type_output, $forum_id, $forum_attr );
     2136        function bbp_get_form_forum_type_dropdown( $args = '' ) {
     2137
     2138                // Backpat for handling passing of a forum ID as integer
     2139                if ( is_int( $args ) ) {
     2140                        $forum_id = (int) $args;
     2141                        $args     = array();
     2142                } else {
     2143                        $forum_id = 0;
     2144                }
     2145
     2146                // Parse arguments against default values
     2147                $r = bbp_parse_args( $args, array(
     2148                        'select_id'    => 'bbp_forum_type',
     2149                        'tab'          => bbp_get_tab_index(),
     2150                        'forum_id'     => $forum_id,
     2151                        'selected'     => false
     2152                ), 'forum_type_select' );
     2153
     2154                // No specific selected value passed
     2155                if ( empty( $r['selected'] ) ) {
     2156
     2157                        // Post value is passed
     2158                        if ( bbp_is_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {
     2159                                $r['selected'] = $_POST[ $r['select_id'] ];
     2160
     2161                        // No Post value was passed
     2162                        } else {
     2163
     2164                                // Edit topic
     2165                                if ( bbp_is_forum_edit() ) {
     2166                                        $r['forum_id'] = bbp_get_forum_id( $r['forum_id'] );
     2167                                        $r['selected'] = bbp_get_forum_type( $r['forum_id'] );
     2168
     2169                                // New topic
     2170                                } else {
     2171                                        $r['selected'] = bbp_get_public_status_id();
     2172                                }
     2173                        }
     2174                }
     2175
     2176                // Used variables
     2177                $tab = ! empty( $r['tab'] ) ? ' tabindex="' . (int) $r['tab'] . '"' : '';
     2178
     2179                // Start an output buffer, we'll finish it after the select loop
     2180                ob_start(); ?>
     2181
     2182                <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select"<?php echo $tab; ?>>
     2183
     2184                        <?php foreach ( bbp_get_forum_types() as $key => $label ) : ?>
     2185
     2186                                <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
     2187
     2188                        <?php endforeach; ?>
     2189
     2190                </select>
     2191
     2192                <?php
     2193
     2194                // Return the results
     2195                return apply_filters( 'bbp_get_form_forum_type_dropdown', ob_get_clean(), $r );
    21502196        }
    21512197
     
    21582204 * @uses bbp_get_form_forum_status() To get the topic's forum id
    21592205 */
    2160 function bbp_form_forum_status_dropdown( $forum_id = 0 ) {
    2161         echo bbp_get_form_forum_status_dropdown( $forum_id );
     2206function bbp_form_forum_status_dropdown( $args = '' ) {
     2207        echo bbp_get_form_forum_status_dropdown( $args );
    21622208}
    21632209        /**
     
    21722218         * @return string HTML select list for selecting forum status
    21732219         */
    2174         function bbp_get_form_forum_status_dropdown( $forum_id = 0 ) {
    2175                 $forum_id   = bbp_get_forum_id( $forum_id );
    2176                 $forum_attr = apply_filters( 'bbp_forum_statuses', array(
    2177                         'open'   => _x( 'Open',   'Forum Status', 'bbpress' ),
    2178                         'closed' => _x( 'Closed', 'Forum Status', 'bbpress' )
    2179                 ) );
    2180                 $status_output = '<select name="bbp_forum_status" id="bbp_forum_status_select">' . "\n";
    2181 
    2182                 foreach ( $forum_attr as $value => $label )
    2183                         $status_output .= "\t" . '<option value="' . esc_attr( $value ) . '"' . selected( bbp_get_forum_status( $forum_id ), $value, false ) . '>' . esc_html( $label ) . '</option>' . "\n";
    2184 
    2185                 $status_output .= '</select>';
    2186 
    2187                 return apply_filters( 'bbp_get_form_forum_status_dropdown', $status_output, $forum_id, $forum_attr );
     2220        function bbp_get_form_forum_status_dropdown( $args = '' ) {
     2221
     2222                // Backpat for handling passing of a forum ID
     2223                if ( is_int( $args ) ) {
     2224                        $forum_id = (int) $args;
     2225                        $args     = array();
     2226                } else {
     2227                        $forum_id = 0;
     2228                }
     2229
     2230                // Parse arguments against default values
     2231                $r = bbp_parse_args( $args, array(
     2232                        'select_id'    => 'bbp_forum_status',
     2233                        'tab'          => bbp_get_tab_index(),
     2234                        'forum_id'     => $forum_id,
     2235                        'selected'     => false
     2236                ), 'forum_status_select' );
     2237
     2238                // No specific selected value passed
     2239                if ( empty( $r['selected'] ) ) {
     2240
     2241                        // Post value is passed
     2242                        if ( bbp_is_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {
     2243                                $r['selected'] = $_POST[ $r['select_id'] ];
     2244
     2245                        // No Post value was passed
     2246                        } else {
     2247
     2248                                // Edit topic
     2249                                if ( bbp_is_forum_edit() ) {
     2250                                        $r['forum_id'] = bbp_get_forum_id( $r['forum_id'] );
     2251                                        $r['selected'] = bbp_get_forum_status( $r['forum_id'] );
     2252
     2253                                // New topic
     2254                                } else {
     2255                                        $r['selected'] = bbp_get_public_status_id();
     2256                                }
     2257                        }
     2258                }
     2259
     2260                // Used variables
     2261                $tab = ! empty( $r['tab'] ) ? ' tabindex="' . (int) $r['tab'] . '"' : '';
     2262
     2263                // Start an output buffer, we'll finish it after the select loop
     2264                ob_start(); ?>
     2265
     2266                <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select"<?php echo $tab; ?>>
     2267
     2268                        <?php foreach ( bbp_get_forum_statuses() as $key => $label ) : ?>
     2269
     2270                                <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
     2271
     2272                        <?php endforeach; ?>
     2273
     2274                </select>
     2275
     2276                <?php
     2277
     2278                // Return the results
     2279                return apply_filters( 'bbp_get_form_forum_status_dropdown', ob_get_clean(), $r );
    21882280        }
    21892281
     
    21962288 * @uses bbp_get_form_forum_visibility() To get the topic's forum id
    21972289 */
    2198 function bbp_form_forum_visibility_dropdown( $forum_id = 0 ) {
    2199         echo bbp_get_form_forum_visibility_dropdown( $forum_id );
     2290function bbp_form_forum_visibility_dropdown( $args = '' ) {
     2291        echo bbp_get_form_forum_visibility_dropdown( $args );
    22002292}
    22012293        /**
     
    22102302         * @return string HTML select list for selecting forum visibility
    22112303         */
    2212         function bbp_get_form_forum_visibility_dropdown( $forum_id = 0 ) {
    2213                 $forum_id   = bbp_get_forum_id( $forum_id );
    2214                 $forum_attr = apply_filters( 'bbp_forum_visibilities', array(
    2215                         bbp_get_public_status_id()  => __( 'Public',  'bbpress' ),
    2216                         bbp_get_private_status_id() => __( 'Private', 'bbpress' ),
    2217                         bbp_get_hidden_status_id()  => __( 'Hidden',  'bbpress' )
    2218                 ) );
    2219                 $visibility_output = '<select name="bbp_forum_visibility" id="bbp_forum_visibility_select">' . "\n";
    2220 
    2221                 foreach ( $forum_attr as $value => $label )
    2222                         $visibility_output .= "\t" . '<option value="' . esc_attr( $value ) . '"' . selected( bbp_get_forum_visibility( $forum_id ), $value, false ) . '>' . esc_html( $label ) . '</option>' . "\n";
    2223 
    2224                 $visibility_output .= '</select>';
    2225 
    2226                 return apply_filters( 'bbp_get_form_forum_visibility_dropdown', $visibility_output, $forum_id, $forum_attr );
     2304        function bbp_get_form_forum_visibility_dropdown( $args = '' ) {
     2305
     2306                // Backpat for handling passing of a forum ID
     2307                if ( is_int( $args ) ) {
     2308                        $forum_id = (int) $args;
     2309                        $args     = array();
     2310                } else {
     2311                        $forum_id = 0;
     2312                }
     2313
     2314                // Parse arguments against default values
     2315                $r = bbp_parse_args( $args, array(
     2316                        'select_id'    => 'bbp_forum_visibility',
     2317                        'tab'          => bbp_get_tab_index(),
     2318                        'forum_id'     => $forum_id,
     2319                        'selected'     => false
     2320                ), 'forum_type_select' );
     2321
     2322                // No specific selected value passed
     2323                if ( empty( $r['selected'] ) ) {
     2324
     2325                        // Post value is passed
     2326                        if ( bbp_is_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {
     2327                                $r['selected'] = $_POST[ $r['select_id'] ];
     2328
     2329                        // No Post value was passed
     2330                        } else {
     2331
     2332                                // Edit topic
     2333                                if ( bbp_is_forum_edit() ) {
     2334                                        $r['forum_id'] = bbp_get_forum_id( $r['forum_id'] );
     2335                                        $r['selected'] = bbp_get_forum_visibility( $r['forum_id'] );
     2336
     2337                                // New topic
     2338                                } else {
     2339                                        $r['selected'] = bbp_get_public_status_id();
     2340                                }
     2341                        }
     2342                }
     2343
     2344                // Used variables
     2345                $tab = ! empty( $r['tab'] ) ? ' tabindex="' . (int) $r['tab'] . '"' : '';
     2346
     2347                // Start an output buffer, we'll finish it after the select loop
     2348                ob_start(); ?>
     2349
     2350                <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select"<?php echo $tab; ?>>
     2351
     2352                        <?php foreach ( bbp_get_forum_visibilities() as $key => $label ) : ?>
     2353
     2354                                <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
     2355
     2356                        <?php endforeach; ?>
     2357
     2358                </select>
     2359
     2360                <?php
     2361
     2362                // Return the results
     2363                return apply_filters( 'bbp_get_form_forum_type_dropdown', ob_get_clean(), $r );
    22272364        }
    22282365
Note: See TracChangeset for help on using the changeset viewer.