Skip to:
Content

bbPress.org

Changeset 5060


Ignore:
Timestamp:
08/02/2013 07:20:49 AM (12 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.

Location:
trunk
Files:
11 edited

Legend:

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

    r5016 r5060  
    575575                                }
    576576                            } );
    577                         <?php if ( bbp_get_reply_post_type() === get_current_screen()->post_type ) : ?>
     577                        <?php if ( bbp_get_topic_post_type() === get_current_screen()->post_type ) : ?>
     578                            jQuery( '#misc-publishing-actions' ).find( '.misc-pub-section' ).first().remove();
     579                            jQuery( '#save-action' ).remove();
     580                        <?php elseif ( bbp_get_reply_post_type() === get_current_screen()->post_type ) : ?>
    578581                            var bbp_topic_id = jQuery( '#bbp_topic_id' );
    579582                            bbp_topic_id.suggest( ajaxurl + '?action=bbp_suggest_topic', {
  • trunk/includes/admin/metaboxes.php

    r5015 r5060  
    261261        <strong class="label"><?php esc_html_e( 'Type:', 'bbpress' ); ?></strong>
    262262        <label class="screen-reader-text" for="bbp_forum_type_select"><?php esc_html_e( 'Type:', 'bbpress' ) ?></label>
    263         <?php bbp_form_forum_type_dropdown( $post_id ); ?>
     263        <?php bbp_form_forum_type_dropdown( array( 'forum_id' => $post_id ) ); ?>
    264264    </p>
    265265
     
    273273        <strong class="label"><?php esc_html_e( 'Status:', 'bbpress' ); ?></strong>
    274274        <label class="screen-reader-text" for="bbp_forum_status_select"><?php esc_html_e( 'Status:', 'bbpress' ) ?></label>
    275         <?php bbp_form_forum_status_dropdown( $post_id ); ?>
     275        <?php bbp_form_forum_status_dropdown( array( 'forum_id' => $post_id ) ); ?>
    276276    </p>
    277277
     
    285285        <strong class="label"><?php esc_html_e( 'Visibility:', 'bbpress' ); ?></strong>
    286286        <label class="screen-reader-text" for="bbp_forum_visibility_select"><?php esc_html_e( 'Visibility:', 'bbpress' ) ?></label>
    287         <?php bbp_form_forum_visibility_dropdown( $post_id ); ?>
     287        <?php bbp_form_forum_visibility_dropdown( array( 'forum_id' => $post_id ) ); ?>
    288288    </p>
    289289
     
    345345
    346346    // Post ID
    347     $post_id = get_the_ID(); ?>
     347    $post_id = get_the_ID();
     348
     349    /** Type ******************************************************************/
     350
     351    ?>
    348352
    349353    <p>
    350354        <strong class="label"><?php esc_html_e( 'Type:', 'bbpress' ); ?></strong>
    351355        <label class="screen-reader-text" for="bbp_stick_topic"><?php esc_html_e( 'Topic Type', 'bbpress' ); ?></label>
    352         <?php bbp_topic_type_select( array( 'topic_id' => $post_id ) ); ?>
    353     </p>
     356        <?php bbp_form_topic_type_dropdown( array( 'topic_id' => $post_id ) ); ?>
     357    </p>
     358
     359    <?php
     360
     361    /** Status ****************************************************************/
     362
     363    ?>
     364
     365    <p>
     366        <strong class="label"><?php esc_html_e( 'Status:', 'bbpress' ); ?></strong>
     367        <label class="screen-reader-text" for="bbp_open_close_topic"><?php esc_html_e( 'Select whether to open or close the topic.', 'bbpress' ); ?></label>
     368        <?php bbp_form_topic_status_dropdown( array( 'select_id' => 'post_status', 'topic_id' => $post_id ) ); ?>
     369    </p>
     370
     371    <?php
     372
     373    /** Parent *****************************************************************/
     374
     375    ?>
    354376
    355377    <p>
  • trunk/includes/admin/settings.php

    r5059 r5060  
    636636    ob_start(); ?>
    637637
    638     <select id="_bbp_thread_replies_depth" name="_bbp_thread_replies_depth" <?php bbp_maybe_admin_setting_disabled( '_bbp_thread_replies_depth' ); ?>>
     638    <select id="_bbp_thread_replies_depth" name="_bbp_thread_replies_depth">
    639639    <?php for ( $i = 2; $i <= $max_depth; $i++ ) : ?>
    640640
  • trunk/includes/core/capabilities.php

    r5057 r5060  
    505505 */
    506506function bbp_remove_roles() {
    507 
    508     // Remove the bbPress roles
    509     foreach ( array_keys( bbp_get_dynamic_roles() ) as $bbp_role ) {
    510         remove_role( $bbp_role );
    511     }
    512 
    513     // Some early adopters may have a deprecated visitor role. It was later
    514     // replaced by the Spectator role.
    515     remove_role( 'bbp_visitor' );
    516 }
     507    _doing_it_wrong( 'bbp_remove_roles', __( 'Editable forum roles no longer exist.', 'bbpress' ), '2.2' );
     508}
  • trunk/includes/extend/buddypress/groups.php

    r5056 r5060  
    749749
    750750                    // Strip the super stickies from topic query
    751                     add_filter( 'bbp_get_super_stickies',                 array( $this, 'no_super_stickies'  ), 10, 1 );
     751                    add_filter( 'bbp_get_super_stickies', array( $this, 'no_super_stickies'  ), 10, 1 );
    752752
    753753                    // Unset the super sticky option on topic form
    754                     add_filter( 'bbp_after_topic_type_select_parse_args', array( $this, 'unset_super_sticky' ), 10, 1 );
     754                    add_filter( 'bbp_get_topic_types',    array( $this, 'unset_super_sticky' ), 10, 1 );
    755755
    756756                    // Query forums and show them if they exist
     
    808808
    809809                        // Unset the super sticky link on edit topic template
    810                         add_filter( 'bbp_after_topic_type_select_parse_args', array( $this, 'unset_super_sticky' ), 10, 1 );
     810                        add_filter( 'bbp_get_topic_types', array( $this, 'unset_super_sticky' ), 10, 1 );
    811811
    812812                        // Set the edit switches
     
    922922     */
    923923    public function unset_super_sticky( $args = array() ) {
    924         $args['super_text'] = '';
     924        if ( isset( $args['super'] ) ) {
     925            unset( $args['super'] );
     926        }
    925927        return $args;
    926928    }
  • trunk/includes/forums/functions.php

    r5021 r5060  
    801801    if ( bbp_get_public_status_id() !== $current_visibility ) {
    802802
    803         // Update forum post_status
    804         global $wpdb;
    805         $wpdb->update( $wpdb->posts, array( 'post_status' => bbp_get_public_status_id() ), array( 'ID' => $forum_id ) );
    806         wp_transition_post_status( bbp_get_public_status_id(), $current_visibility, get_post( $forum_id ) );
     803        // Update forums visibility setting
     804        wp_insert_post( array(
     805            'ID'          => $forum_id,
     806            'post_status' => bbp_get_public_status_id()
     807        ) );
    807808    }
    808809
     
    851852
    852853        // Update forums visibility setting
    853         global $wpdb;
    854         $wpdb->update( $wpdb->posts, array( 'post_status' => bbp_get_private_status_id() ), array( 'ID' => $forum_id ) );
    855         wp_transition_post_status( bbp_get_private_status_id(), $current_visibility, get_post( $forum_id ) );
     854        wp_insert_post( array(
     855            'ID'          => $forum_id,
     856            'post_status' => bbp_get_private_status_id()
     857        ) );
    856858    }
    857859
     
    900902
    901903        // Update forums visibility setting
    902         global $wpdb;
    903         $wpdb->update( $wpdb->posts, array( 'post_status' => bbp_get_hidden_status_id() ), array( 'ID' => $forum_id ) );
    904         wp_transition_post_status( bbp_get_hidden_status_id(), $current_visibility, get_post( $forum_id ) );
     904        wp_insert_post( array(
     905            'ID'          => $forum_id,
     906            'post_status' => bbp_get_hidden_status_id()
     907        ) );
    905908    }
    906909
     
    15431546}
    15441547
     1548/** Helpers *******************************************************************/
     1549
     1550/**
     1551 * Return an associative array of available topic statuses
     1552 *
     1553 * @since bbPress (r5059)
     1554 *
     1555 * @return array
     1556 */
     1557function bbp_get_forum_statuses() {
     1558    return apply_filters( 'bbp_get_forum_statuses', array(
     1559        'open'   => _x( 'Open',    'Open the forum',  'bbpress' ),
     1560        'closed' => _x( 'Closed',  'Close the forum', 'bbpress' )
     1561    ) );
     1562}
     1563
     1564/**
     1565 * Return an associative array of forum types
     1566 *
     1567 * @since bbPress (r5059)
     1568 *
     1569 * @return array
     1570 */
     1571function bbp_get_forum_types() {
     1572    return apply_filters( 'bbp_get_forum_types', array(
     1573        'forum'    => _x( 'Forum',    'Forum accepts new topics', 'bbpress' ),
     1574        'category' => _x( 'Category', 'Forum is a category',      'bbpress' )
     1575    ) );
     1576}
     1577
     1578/**
     1579 * Return an associative array of forum visibility
     1580 *
     1581 * @since bbPress (r5059)
     1582 *
     1583 * @return array
     1584 */
     1585function bbp_get_forum_visibilities() {
     1586    return apply_filters( 'bbp_get_forum_visibilities', array(
     1587        bbp_get_public_status_id()  => _x( 'Public',  'Make forum public',  'bbpress' ),
     1588        bbp_get_private_status_id() => _x( 'Private', 'Make forum private', 'bbpress' ),
     1589        bbp_get_hidden_status_id()  => _x( 'Hidden',  'Make forum hidden',  'bbpress' )
     1590    ) );
     1591}
     1592
    15451593/** Queries *******************************************************************/
    15461594
  • 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
  • trunk/includes/topics/functions.php

    r5055 r5060  
    276276        $topic_status = bbp_get_pending_status_id();
    277277
    278     // Default to published
     278    // Check a whitelist of possible topic status ID's
     279    } elseif ( in_array( $_POST['bbp_topic_status'], array( bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_pending_status_id(), bbp_get_trash_status_id(), bbp_get_orphan_status_id() ) ) ) {
     280        $topic_status = $_POST['bbp_topic_status'];
     281
     282    // Default to published if nothing else
    279283    } else {
    280284        $topic_status = bbp_get_public_status_id();
     
    608612        }
    609613
     614    // Check a whitelist of possible topic status ID's
     615    } elseif ( in_array( $_POST['bbp_topic_status'], array( bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_pending_status_id(), bbp_get_trash_status_id(), bbp_get_orphan_status_id() ) ) ) {
     616        $topic_status = $_POST['bbp_topic_status'];
     617
    610618    // Use existing post_status
    611619    } else {
     
    19441952}
    19451953
     1954/** Helpers *******************************************************************/
     1955
     1956/**
     1957 * Return an associative array of available topic statuses
     1958 *
     1959 * @since bbPress (r5059)
     1960 *
     1961 * @return array
     1962 */
     1963function bbp_get_topic_statuses() {
     1964    return apply_filters( 'bbp_get_topic_statuses', array(
     1965        bbp_get_public_status_id()  => _x( 'Open',    'Open the topic',        'bbpress' ),
     1966        bbp_get_closed_status_id()  => _x( 'Closed',  'Close the topic',       'bbpress' ),
     1967        bbp_get_spam_status_id()    => _x( 'Spam',    'Spam the topic',        'bbpress' ),
     1968        bbp_get_trash_status_id()   => _x( 'Trash',   'Trash the topic',       'bbpress' ),
     1969        bbp_get_pending_status_id() => _x( 'Pending', 'Mark topic as pending', 'bbpress' ),
     1970    ) );
     1971}
     1972
     1973/**
     1974 * Return an associative array of topic sticky types
     1975 *
     1976 * @since bbPress (r5059)
     1977 *
     1978 * @return array
     1979 */
     1980function bbp_get_topic_types() {
     1981    return apply_filters( 'bbp_get_topic_types', array(
     1982        'unstick' => _x( 'Normal',       'Unstick a topic',         'bbpress' ),
     1983        'stick'   => _x( 'Sticky',       'Make topic sticky',       'bbpress' ),
     1984        'super'   => _x( 'Super Sticky', 'Make topic super sticky', 'bbpress' )
     1985    ) );
     1986}
     1987
    19461988/** Stickies ******************************************************************/
    19471989
  • trunk/includes/topics/template.php

    r5045 r5060  
    29132913 * Displays topic type select box (normal/sticky/super sticky)
    29142914 *
    2915  * @since bbPress (r2784)
     2915 * @since bbPress (r5059)
     2916 * @deprecated since bbPress (r5059)
    29162917 *
    29172918 * @param $args This function supports these arguments:
    2918  *  - stick_text: Sticky text
    2919  *  - super_text: Super Sticky text
    2920  *  - unstick_text: Unstick (normal) text
    29212919 *  - select_id: Select id. Defaults to bbp_stick_topic
    29222920 *  - tab: Tabindex
    29232921 *  - topic_id: Topic id
    2924  * @uses bbp_get_topic_id() To get the topic id
    2925  * @uses bbp_is_single_topic() To check if we're viewing a single topic
    2926  * @uses bbp_is_topic_edit() To check if it is the topic edit page
    2927  * @uses bbp_is_topic_super_sticky() To check if the topic is a super sticky
    2928  * @uses bbp_is_topic_sticky() To check if the topic is a sticky
     2922 *  - selected: Override the selected option
    29292923 */
    29302924function bbp_topic_type_select( $args = '' ) {
    2931 
    2932     // Parse arguments against default values
    2933     $r = bbp_parse_args( $args, array(
    2934         'unstick_text' => __( 'Normal',       'bbpress' ),
    2935         'stick_text'   => __( 'Sticky',       'bbpress' ),
    2936         'super_text'   => __( 'Super Sticky', 'bbpress' ),
    2937         'select_id'    => 'bbp_stick_topic',
    2938         'tab'          => bbp_get_tab_index(),
    2939         'topic_id'     => 0
    2940     ), 'topic_type_select' );
    2941 
    2942     // Edit topic
    2943     if ( bbp_is_single_topic() || bbp_is_topic_edit() ) {
    2944 
    2945         // Get current topic id
    2946         $topic_id = bbp_get_topic_id( $r['topic_id'] );
    2947 
    2948         // Post value is passed
    2949         if ( bbp_is_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {
    2950             $sticky_current = $_POST[ $r['select_id'] ];
    2951 
    2952         // Topic is super sticky
    2953         } elseif ( bbp_is_topic_super_sticky( $topic_id ) ) {
    2954             $sticky_current = 'super';
    2955 
    2956         // Topic is sticky or normal
    2957         } else {
    2958             $sticky_current = bbp_is_topic_sticky( $topic_id, false ) ? 'stick' : 'unstick';
    2959         }
    2960 
    2961     // New topic
    2962     } else {
    2963 
    2964         // Post value is passed
    2965         if ( bbp_is_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {
    2966             $sticky_current = $_POST[ $r['select_id'] ];
    2967 
    2968         // Default to unstick
    2969         } else {
    2970             $sticky_current = 'unstick';
    2971         }
    2972     }
    2973 
    2974     // Used variables
    2975     $tab             = !empty( $r['tab'] ) ? ' tabindex="' . $r['tab'] . '"' : '';
    2976     $select_id       = esc_attr( $r['select_id'] );
    2977     $sticky_statuses = array_filter( array(
    2978         'unstick' => $r['unstick_text'],
    2979         'stick'   => $r['stick_text'],
    2980         'super'   => $r['super_text'],
    2981     ) ); ?>
    2982 
    2983     <select name="<?php echo $select_id; ?>" id="<?php echo $select_id; ?>"<?php echo $tab; ?>>
    2984 
    2985         <?php foreach ( $sticky_statuses as $sticky_status => $label ) : ?>
    2986 
    2987             <option value="<?php echo esc_attr( $sticky_status ); ?>"<?php selected( $sticky_current, $sticky_status ); ?>><?php echo esc_html( $label ); ?></option>
    2988 
    2989         <?php endforeach; ?>
    2990 
    2991     </select>
    2992 
    2993     <?php
    2994 }
     2925    echo bbp_get_form_topic_type_dropdown( $args );
     2926}
     2927
     2928/**
     2929 * Displays topic type select box (normal/sticky/super sticky)
     2930 *
     2931 * @since bbPress (r5059)
     2932 *
     2933 * @param $args This function supports these arguments:
     2934 *  - select_id: Select id. Defaults to bbp_stick_topic
     2935 *  - tab: Tabindex
     2936 *  - topic_id: Topic id
     2937 *  - selected: Override the selected option
     2938 */
     2939function bbp_form_topic_type_dropdown( $args = '' ) {
     2940    echo bbp_get_form_topic_type_dropdown( $args );
     2941}
     2942    /**
     2943     * Returns topic type select box (normal/sticky/super sticky)
     2944     *
     2945     * @since bbPress (r5059)
     2946     *
     2947     * @param $args This function supports these arguments:
     2948     *  - select_id: Select id. Defaults to bbp_stick_topic
     2949     *  - tab: Tabindex
     2950     *  - topic_id: Topic id
     2951     *  - selected: Override the selected option
     2952     * @uses bbp_get_topic_id() To get the topic id
     2953     * @uses bbp_is_single_topic() To check if we're viewing a single topic
     2954     * @uses bbp_is_topic_edit() To check if it is the topic edit page
     2955     * @uses bbp_is_topic_super_sticky() To check if the topic is a super sticky
     2956     * @uses bbp_is_topic_sticky() To check if the topic is a sticky
     2957     */
     2958    function bbp_get_form_topic_type_dropdown( $args = '' ) {
     2959
     2960        // Parse arguments against default values
     2961        $r = bbp_parse_args( $args, array(
     2962            'select_id'    => 'bbp_stick_topic',
     2963            'tab'          => bbp_get_tab_index(),
     2964            'topic_id'     => 0,
     2965            'selected'     => false
     2966        ), 'topic_type_select' );
     2967
     2968        // No specific selected value passed
     2969        if ( empty( $r['selected'] ) ) {
     2970
     2971            // Post value is passed
     2972            if ( bbp_is_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {
     2973                $r['selected'] = $_POST[ $r['select_id'] ];
     2974
     2975            // No Post value passed
     2976            } else {
     2977
     2978                // Edit topic
     2979                if ( bbp_is_single_topic() || bbp_is_topic_edit() ) {
     2980
     2981                    // Get current topic id
     2982                    $topic_id = bbp_get_topic_id( $r['topic_id'] );
     2983
     2984                    // Topic is super sticky
     2985                    if ( bbp_is_topic_super_sticky( $topic_id ) ) {
     2986                        $r['selected'] = 'super';
     2987
     2988                    // Topic is sticky or normal
     2989                    } else {
     2990                        $r['selected'] = bbp_is_topic_sticky( $topic_id, false ) ? 'stick' : 'unstick';
     2991                    }
     2992                }
     2993            }
     2994        }
     2995
     2996        // Used variables
     2997        $tab = !empty( $r['tab'] ) ? ' tabindex="' . (int) $r['tab'] . '"' : '';
     2998
     2999        // Start an output buffer, we'll finish it after the select loop
     3000        ob_start(); ?>
     3001
     3002        <select name="<?php echo esc_attr( $r['select_id'] ); ?>" id="<?php echo esc_attr( $r['select_id'] ); ?>_select"<?php echo $tab; ?>>
     3003
     3004            <?php foreach ( bbp_get_topic_types() as $key => $label ) : ?>
     3005
     3006                <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
     3007
     3008            <?php endforeach; ?>
     3009
     3010        </select>
     3011
     3012        <?php
     3013
     3014        // Return the results
     3015        return apply_filters( 'bbp_get_form_topic_type_dropdown', ob_get_clean(), $r );
     3016    }
     3017
     3018/**
     3019 * Output value topic status dropdown
     3020 *
     3021 * @since bbPress (r5059)
     3022 *
     3023 * @param int $topic_id The topic id to use
     3024 */
     3025function bbp_form_topic_status_dropdown( $args = '' ) {
     3026    echo bbp_get_form_topic_status_dropdown( $args );
     3027}
     3028    /**
     3029     * Returns topic status downdown
     3030     *
     3031     * This dropdown is only intended to be seen by users with the 'moderate'
     3032     * capability. Because of this, no additional capablitiy checks are performed
     3033     * within this function to check available topic statuses.
     3034     *
     3035     * @since bbPress (r5059)
     3036     *
     3037     * @param $args This function supports these arguments:
     3038     *  - select_id: Select id. Defaults to bbp_open_close_topic
     3039     *  - tab: Tabindex
     3040     *  - topic_id: Topic id
     3041     *  - selected: Override the selected option
     3042     */
     3043    function bbp_get_form_topic_status_dropdown( $args = '' ) {
     3044
     3045        // Parse arguments against default values
     3046        $r = bbp_parse_args( $args, array(
     3047            'select_id' => 'bbp_topic_status',
     3048            'tab'       => bbp_get_tab_index(),
     3049            'topic_id'  => 0,
     3050            'selected'  => false
     3051        ), 'topic_open_close_select' );
     3052
     3053        // No specific selected value passed
     3054        if ( empty( $r['selected'] ) ) {
     3055
     3056            // Post value is passed
     3057            if ( bbp_is_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {
     3058                $r['selected'] = $_POST[ $r['select_id'] ];
     3059
     3060            // No Post value was passed
     3061            } else {
     3062
     3063                // Edit topic
     3064                if ( bbp_is_topic_edit() ) {
     3065                    $r['topic_id'] = bbp_get_topic_id( $r['topic_id'] );
     3066                    $r['selected'] = bbp_get_topic_status( $r['topic_id'] );
     3067
     3068                // New topic
     3069                } else {
     3070                    $r['selected'] = bbp_get_public_status_id();
     3071                }
     3072            }
     3073        }
     3074
     3075        // Used variables
     3076        $tab = ! empty( $r['tab'] ) ? ' tabindex="' . (int) $r['tab'] . '"' : '';
     3077
     3078        // Start an output buffer, we'll finish it after the select loop
     3079        ob_start(); ?>
     3080
     3081        <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ); ?>_select"<?php echo $tab; ?>>
     3082
     3083            <?php foreach ( bbp_get_topic_statuses( $r['topic_id'] ) as $key => $label ) : ?>
     3084
     3085                <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
     3086
     3087            <?php endforeach; ?>
     3088
     3089        </select>
     3090
     3091        <?php
     3092
     3093        // Return the results
     3094        return apply_filters( 'bbp_get_form_topic_status_dropdown', ob_get_clean(), $r );
     3095    }
    29953096
    29963097/** Single Topic **************************************************************/
  • trunk/templates/default/bbpress/form-reply.php

    r4994 r5060  
    110110
    111111                        <fieldset class="bbp-form">
    112                             <legend><?php _e( 'Revision', 'bbpress' ); ?></legend>
    113                             <div>
     112                            <legend>
    114113                                <input name="bbp_log_reply_edit" id="bbp_log_reply_edit" type="checkbox" value="1" <?php bbp_form_reply_log_edit(); ?> tabindex="<?php bbp_tab_index(); ?>" />
    115114                                <label for="bbp_log_reply_edit"><?php _e( 'Keep a log of this edit:', 'bbpress' ); ?></label><br />
    116                             </div>
     115                            </legend>
    117116
    118117                            <div>
  • trunk/templates/default/bbpress/form-topic.php

    r4994 r5060  
    128128                            <label for="bbp_stick_topic"><?php _e( 'Topic Type:', 'bbpress' ); ?></label><br />
    129129
    130                             <?php bbp_topic_type_select(); ?>
     130                            <?php bbp_form_topic_type_dropdown(); ?>
    131131
    132132                        </p>
     
    134134                        <?php do_action( 'bbp_theme_after_topic_form_type' ); ?>
    135135
     136                        <?php do_action( 'bbp_theme_before_topic_form_status' ); ?>
     137
     138                        <p>
     139
     140                            <label for="bbp_topic_status"><?php _e( 'Topic Status:', 'bbpress' ); ?></label><br />
     141
     142                            <?php bbp_form_topic_status_dropdown(); ?>
     143
     144                        </p>
     145
     146                        <?php do_action( 'bbp_theme_after_topic_form_status' ); ?>
     147
    136148                    <?php endif; ?>
    137149
     
    163175
    164176                        <fieldset class="bbp-form">
    165                             <legend><?php _e( 'Revision', 'bbpress' ); ?></legend>
    166                             <div>
     177                            <legend>
    167178                                <input name="bbp_log_topic_edit" id="bbp_log_topic_edit" type="checkbox" value="1" <?php bbp_form_topic_log_edit(); ?> tabindex="<?php bbp_tab_index(); ?>" />
    168179                                <label for="bbp_log_topic_edit"><?php _e( 'Keep a log of this edit:', 'bbpress' ); ?></label><br />
    169                             </div>
     180                            </legend>
    170181
    171182                            <div>
Note: See TracChangeset for help on using the changeset viewer.