Skip to:
Content

bbPress.org

Changeset 2787


Ignore:
Timestamp:
01/09/2011 08:43:56 PM (16 years ago)
Author:
johnjamesjacoby
Message:

Introduce _get_ functions for forums, topics, and replies. Fixes #1415. Props GautamGupta via Google Code-in

Location:
branches/plugin
Files:
10 edited

Legend:

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

    r2786 r2787  
    211211
    212212                // Add the per page section
    213                 add_settings_section( 'bbp_slugs',          __( 'Slugs',         'bbpress' ), 'bbp_admin_setting_callback_slugs_section',   'bbpress'              );
     213                add_settings_section( 'bbp_slugs',          __( 'Forums',        'bbpress' ), 'bbp_admin_setting_callback_slugs_section',   'bbpress'              );
    214214
    215215                // Root slug setting
    216                 add_settings_field( '_bbp_root_slug',       __( 'Root Slug',     'bbpress' ), 'bbp_admin_setting_callback_root_slug',       'bbpress', 'bbp_slugs' );
     216                add_settings_field( '_bbp_root_slug',       __( 'Forum base',    'bbpress' ), 'bbp_admin_setting_callback_root_slug',       'bbpress', 'bbp_slugs' );
    217217                register_setting  ( 'bbpress',              '_bbp_root_slug',                 'sanitize_title'                                                     );
    218218
    219219                // Include root setting
    220                 add_settings_field( '_bbp_include_root',    __( 'Prefix Root?', 'bbpress' ), 'bbp_admin_setting_callback_include_root',    'bbpress', 'bbp_slugs' );
     220                add_settings_field( '_bbp_include_root',    __( 'Include base?', 'bbpress' ), 'bbp_admin_setting_callback_include_root',    'bbpress', 'bbp_slugs' );
    221221                register_setting  ( 'bbpress',              '_bbp_include_root',              'intval'                                                             );
    222222
    223223                // User slug setting
    224                 add_settings_field( '_bbp_user_slug',       __( 'User Slug',     'bbpress' ), 'bbp_admin_setting_callback_user_slug',       'bbpress', 'bbp_slugs' );
     224                add_settings_field( '_bbp_user_slug',       __( 'User base',     'bbpress' ), 'bbp_admin_setting_callback_user_slug',       'bbpress', 'bbp_slugs' );
    225225                register_setting  ( 'bbpress',              '_bbp_user_slug',                 'sanitize_title'                                                     );
    226226
    227227                // Forum slug setting
    228                 add_settings_field( '_bbp_forum_slug',      __( 'Forum Slug',    'bbpress' ), 'bbp_admin_setting_callback_forum_slug',      'bbpress', 'bbp_slugs' );
     228                add_settings_field( '_bbp_forum_slug',      __( 'Forum slug',    'bbpress' ), 'bbp_admin_setting_callback_forum_slug',      'bbpress', 'bbp_slugs' );
    229229                register_setting  ( 'bbpress',             '_bbp_forum_slug',                 'sanitize_title'                                                     );
    230230
    231231                // Topic slug setting
    232                 add_settings_field( '_bbp_topic_slug',      __( 'Topic Slug',    'bbpress' ), 'bbp_admin_setting_callback_topic_slug',      'bbpress', 'bbp_slugs' );
     232                add_settings_field( '_bbp_topic_slug',      __( 'Topic slug',    'bbpress' ), 'bbp_admin_setting_callback_topic_slug',      'bbpress', 'bbp_slugs' );
    233233                register_setting  ( 'bbpress',             '_bbp_topic_slug',                 'sanitize_title'                                                     );
    234234
    235235                // Reply slug setting
    236                 add_settings_field( '_bbp_reply_slug',      __( 'Reply Slug',    'bbpress' ), 'bbp_admin_setting_callback_reply_slug',      'bbpress', 'bbp_slugs' );
     236                add_settings_field( '_bbp_reply_slug',      __( 'Reply slug',    'bbpress' ), 'bbp_admin_setting_callback_reply_slug',      'bbpress', 'bbp_slugs' );
    237237                register_setting  ( 'bbpress',             '_bbp_reply_slug',                 'sanitize_title'                                                     );
    238238
    239239                // Topic tag slug setting
    240                 add_settings_field( '_bbp_topic_tag_slug', __( 'Topic Tag Slug', 'bbpress' ), 'bbp_admin_setting_callback_topic_tag_slug',  'bbpress', 'bbp_slugs' );
    241                 register_setting  ( 'bbpress',             '_bbp_topic_tag_slug',              'sanitize_title'                                                     );
     240                add_settings_field( '_bbp_topic_tag_slug', __( 'Topic tag slug', 'bbpress' ), 'bbp_admin_setting_callback_topic_tag_slug',  'bbpress', 'bbp_slugs' );
     241                register_setting  ( 'bbpress',             '_bbp_topic_tag_slug',             'sanitize_title'                                                     );
    242242
    243243                do_action( 'bbp_register_admin_settings' );
     
    345345         * @uses current_user_can() To check if the current user is capable of
    346346         *                           editing the forum
    347          * @uses get_post_field() To get the post type of the supplied id and
    348          *                         check if it's a forum
     347         * @uses bbp_get_forum() To get the forum
    349348         * @uses bbp_is_forum_closed() To check if the forum is closed
    350349         * @uses bbp_is_forum_category() To check if the forum is a category
     
    365364                        return $forum_id;
    366365
    367                 if ( $bbp->forum_id != get_post_field( 'post_type', $forum_id ) )
     366                if ( !$forum = bbp_get_forum( $forum_id ) )
    368367                        return $forum_id;
    369368
     
    850849         * @since bbPress (r2727)
    851850         *
    852          * @uses get_post() To get the topic
     851         * @uses bbp_get_topic() To get the topic
    853852         * @uses current_user_can() To check if the user is capable of editing
    854853         *                           the topic
     
    881880                        $post_data = array( 'ID' => $topic_id ); // Prelim array
    882881
    883                         if ( !$topic = get_post( $topic_id ) ) // Which topic?
     882                        if ( !$topic = bbp_get_topic( $topic_id ) ) // Which topic?
    884883                                wp_die( __( 'The topic was not found!', 'bbpress' ) );
    885884
     
    944943         * @since bbPress (r2727)
    945944         *
     945         * @uses bbp_get_topic() To get the topic
    946946         * @uses bbp_get_topic_title() To get the topic title of the topic
    947947         * @uses esc_html() To sanitize the topic title
     
    959959
    960960                        // Empty? No topic?
    961                         if ( empty( $notice ) || empty( $topic_id ) || !$topic = get_post( $topic_id ) )
     961                        if ( empty( $notice ) || empty( $topic_id ) || !$topic = bbp_get_topic( $topic_id ) )
    962962                                return;
    963963
     
    11991199                        if ( current_user_can( 'delete_topic', $topic->ID ) ) {
    12001200                                if ( $bbp->trash_status_id == $topic->post_status ) {
    1201                                         $post_type_object   = get_post_type_object( $topic->post_type );
     1201                                        $post_type_object   = get_post_type_object( $bbp->topic_id );
    12021202                                        $actions['untrash'] = "<a title='" . esc_attr( __( 'Restore this item from the Trash', 'bbpress' ) ) . "' href='" . wp_nonce_url( add_query_arg( array( '_wp_http_referer' => add_query_arg( array( 'post_type' => $bbp->topic_id ), admin_url( 'edit.php' ) ) ), admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $topic->ID ) ) ), 'untrash-' . $topic->post_type . '_' . $topic->ID ) . "'>" . __( 'Restore', 'bbpress' ) . "</a>";
    12031203                                } elseif ( EMPTY_TRASH_DAYS ) {
     
    12231223         * @since bbPress (r2740)
    12241224         *
    1225          * @uses get_post() To get the reply
     1225         * @uses bbp_get_reply() To get the reply
    12261226         * @uses current_user_can() To check if the user is capable of editing
    12271227         *                           the reply
     
    12471247                        $post_data = array( 'ID' => $reply_id ); // Prelim array
    12481248
    1249                         if ( !$reply = get_post( $reply_id ) ) // Which reply?
     1249                        if ( !$reply = bbp_get_reply( $reply_id ) ) // Which reply?
    12501250                                wp_die( __( 'The reply was not found!', 'bbpress' ) );
    12511251
     
    12911291         * @since bbPress (r2740)
    12921292         *
     1293         * @uses bbp_get_reply() To get the reply
    12931294         * @uses bbp_get_reply_title() To get the reply title of the reply
    12941295         * @uses esc_html() To sanitize the reply title
     
    13061307
    13071308                        // Empty? No reply?
    1308                         if ( empty( $notice ) || empty( $reply_id ) || !$reply = get_post( $reply_id ) )
     1309                        if ( empty( $notice ) || empty( $reply_id ) || !$reply = bbp_get_reply( $reply_id ) )
    13091310                                return;
    13101311
     
    15081509                        if ( current_user_can( 'delete_reply', $reply->ID ) ) {
    15091510                                if ( $bbp->trash_status_id == $reply->post_status ) {
    1510                                         $post_type_object = get_post_type_object( $reply->post_type );
     1511                                        $post_type_object = get_post_type_object( $bbp->reply_id );
    15111512                                        $actions['untrash'] = "<a title='" . esc_attr( __( 'Restore this item from the Trash', 'bbpress' ) ) . "' href='" . add_query_arg( array( '_wp_http_referer' => add_query_arg( array( 'post_type' => $bbp->reply_id ), admin_url( 'edit.php' ) ) ), wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $reply->ID ) ), 'untrash-' . $reply->post_type . '_' . $reply->ID ) ) . "'>" . __( 'Restore', 'bbpress' ) . "</a>";
    15121513                                } elseif ( EMPTY_TRASH_DAYS ) {
  • branches/plugin/bbp-admin/bbp-settings.php

    r2786 r2787  
    119119
    120120/**
    121  * Forums per page setting field
    122  *
    123  * @todo Implement
    124  *
    125  * @since bbPress (r2786)
    126  *
    127  * @uses form_option() To output the option value
    128  */
    129 function bbp_admin_setting_callback_forums_per_page() {
    130 ?>
    131 
    132                         <input name="_bbp_forums_per_page" type="text" id="_bbp_forums_per_page" value="<?php form_option( '_bbp_forums_per_page' ); ?>" class="small-text" />
    133                         <label for="_bbp_forums_per_page"><?php _e( 'per page', 'bbpress' ); ?></label>
    134 
    135 <?php
    136 }
    137 
    138 /**
    139121 * Topics per page setting field
    140122 *
     
    178160?>
    179161
    180                         <p><?php _e( 'Change the forum\'s slugs in this section.', 'bbpress' ); ?></p>
    181                         <p><?php printf( __( '<strong>Note</strong>: If you change any of these, all previous links would stop working. You must also go to the <a href="%s">permalinks</a> page and press the "Save Changes" button in order to make the changes take effect.', 'bbpress' ), get_admin_url( null, 'options-permalink.php' ) ); ?></p>
     162                        <p><?php printf( __( 'If you like, you may enter custom structures for your forum, topic, reply, and tag URLs here. If you change any of these, all previous links will stop working. If you leave these empty the defaults will be used.', 'bbpress' ), get_admin_url( null, 'options-permalink.php' ) ); ?></p>
    182163
    183164<?php
     
    303284function bbp_admin_settings() {
    304285?>
     286
    305287        <div class="wrap">
    306288
  • branches/plugin/bbp-includes/bbp-classes.php

    r2758 r2787  
    257257
    258258                if ( !empty( $current_forum ) ) {
    259                         $_current_page = get_post( $current_forum );
     259                        $_current_page = bbp_get_forum( $current_forum );
    260260
    261261                        if ( isset( $_current_page->ancestors ) && in_array( $forum->ID, (array) $_current_page->ancestors ) )
  • branches/plugin/bbp-includes/bbp-forum-template.php

    r2758 r2787  
    3434                'posts_per_page' => -1,
    3535                'orderby'        => 'menu_order',
    36                 'order'          => 'ASC'
     36                'order'          => 'ASC',
     37                'posts_per_page' => get_option( '_bbp_forums_per_page', 15 )
    3738        );
    3839
     
    134135                return apply_filters( 'bbp_get_forum_id', (int) $bbp_forum_id );
    135136        }
     137
     138/**
     139 * Gets a forum
     140 *
     141 * @since bbPress (r2787)
     142 *
     143 * @param int|object $forum forum id or forum object
     144 * @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT
     145 * @param string $filter Optional Sanitation filter. See {@link sanitize_post()}
     146 * @uses get_post() To get the forum
     147 * @return mixed Null if error or forum (in specified form) if success
     148 */
     149function bbp_get_forum( $forum, $output = OBJECT, $filter = 'raw' ) {
     150        global $bbp;
     151
     152        if ( empty( $forum ) || is_numeric( $forum ) )
     153                $forum = bbp_get_forum_id( $forum );
     154
     155        if ( !$forum = get_post( $forum, OBJECT, $filter ) )
     156                return $forum;
     157
     158        if ( $bbp->forum_id !== $forum->post_type )
     159                return null;
     160
     161        if ( $output == OBJECT ) {
     162                return $forum;
     163
     164        } elseif ( $output == ARRAY_A ) {
     165                $_forum = get_object_vars( $forum );
     166                return $_forum;
     167
     168        } elseif ( $output == ARRAY_N ) {
     169                $_forum = array_values( get_object_vars( $forum ) );
     170                return $_forum;
     171
     172        }
     173
     174        return apply_filters( 'bbp_get_forum', $forum );
     175}
    136176
    137177/**
     
    306346 * @param int $forum_id Optional. Forum id
    307347 * @uses bbp_get_forum_id() To get the forum id
    308  * @uses get_post() To get the forum
     348 * @uses bbp_get_forum() To get the forum
    309349 * @uses apply_filters() Calls 'bbp_get_forum_ancestors' with the ancestors
    310350 *                        and forum id
     
    314354        $forum_id = bbp_get_forum_id( $forum_id );
    315355
    316         if ( $forum = get_post( $forum_id ) ) {
     356        if ( $forum = bbp_get_forum( $forum_id ) ) {
    317357                $ancestors = array();
    318358                while ( 0 !== $forum->post_parent ) {
    319359                        $ancestors[] = $forum->post_parent;
    320                         $forum       = get_post( $forum->post_parent );
     360                        $forum       = bbp_get_forum( $forum->post_parent );
    321361                }
    322362        }
  • branches/plugin/bbp-includes/bbp-functions.php

    r2784 r2787  
    419419 *
    420420 * @uses bbPress:errors::add() To log various error messages
    421  * @uses get_post() To get the reply
     421 * @uses bbp_get_reply() To get the reply
    422422 * @uses check_admin_referer() To verify the nonce and check the referer
    423423 * @uses bbp_is_reply_anonymous() To check if the reply was by an anonymous user
     
    450450                if ( empty( $_POST['bbp_reply_id'] ) || !$reply_id = (int) $_POST['bbp_reply_id'] ) {
    451451                        $bbp->errors->add( 'bbp_edit_reply_id', __( '<strong>ERROR</strong>: Reply ID not found!', 'bbpress' ) );
    452                 } elseif ( !$reply = get_post( $reply_id ) ) {
     452                } elseif ( !$reply = bbp_get_reply( $reply_id ) ) {
    453453                        $bbp->errors->add( 'bbp_edit_reply_not_found', __( '<strong>ERROR</strong>: The reply you want to edit was not found!', 'bbpress' ) );
    454454                } else {
     
    792792 *
    793793 * @uses bbPress:errors::add() To log various error messages
    794  * @uses get_post() To get the topic
     794 * @uses bbp_get_topic() To get the topic
    795795 * @uses check_admin_referer() To verify the nonce and check the referer
    796796 * @uses bbp_is_topic_anonymous() To check if topic is by an anonymous user
     
    829829                if ( !$topic_id = (int) $_POST['bbp_topic_id'] ) {
    830830                        $bbp->errors->add( 'bbp_edit_topic_id', __( '<strong>ERROR</strong>: Topic ID not found!', 'bbpress' ) );
    831                 } elseif ( !$topic = get_post( $topic_id ) ) {
     831                } elseif ( !$topic = bbp_get_topic( $topic_id ) ) {
    832832                        $bbp->errors->add( 'bbp_edit_topic_not_found', __( '<strong>ERROR</strong>: The topic you want to edit was not found!', 'bbpress' ) );
    833833                } else {
     
    11991199 *
    12001200 * @uses bbPress:errors::add() To log various error messages
    1201  * @uses get_post() To get the topics
     1201 * @uses bbp_get_topic() To get the topics
    12021202 * @uses check_admin_referer() To verify the nonce and check the referer
    12031203 * @uses current_user_can() To check if the current user can edit the topics
     
    12341234                check_admin_referer( 'bbp-merge-topic_' . $source_topic_id );
    12351235
    1236                 if ( !$source_topic = get_post( $source_topic_id ) )
     1236                if ( !$source_topic = bbp_get_topic( $source_topic_id ) )
    12371237                        $bbp->errors->add( 'bbp_merge_topic_source_not_found', __( '<strong>ERROR</strong>: The topic you want to merge was not found!', 'bbpress' ) );
    12381238
     
    12431243                        $bbp->errors->add( 'bbp_merge_topic_destination_id', __( '<strong>ERROR</strong>: Destination topic ID not found!', 'bbpress' ) );
    12441244
    1245                 if ( !$destination_topic = get_post( $destination_topic_id ) )
     1245                if ( !$destination_topic = bbp_get_topic( $destination_topic_id ) )
    12461246                        $bbp->errors->add( 'bbp_merge_topic_destination_not_found', __( '<strong>ERROR</strong>: The topic you want to merge to was not found!', 'bbpress' ) );
    12471247
     
    13841384 *
    13851385 * @uses bbPress:errors::add() To log various error messages
    1386  * @uses get_post() To get the reply and topics
     1386 * @uses bbp_get_reply() To get the reply
     1387 * @uses bbp_get_topic() To get the topics
    13871388 * @uses check_admin_referer() To verify the nonce and check the referer
    13881389 * @uses current_user_can() To check if the current user can edit the topics
     
    14141415                        $bbp->errors->add( 'bbp_split_topic_reply_id', __( '<strong>ERROR</strong>: Reply ID to split the topic from not found!', 'bbpress' ) );
    14151416
    1416                 if ( !$from_reply = get_post( $from_reply_id ) )
     1417                if ( !$from_reply = bbp_get_reply( $from_reply_id ) )
    14171418                        $bbp->errors->add( 'bbp_split_topic_r_not_found', __( '<strong>ERROR</strong>: The reply you want to split from was not found!', 'bbpress' ) );
    14181419
    1419                 if ( !$source_topic = get_post( $from_reply->post_parent ) )
     1420                if ( !$source_topic = bbp_get_topic( $from_reply->post_parent ) )
    14201421                        $bbp->errors->add( 'bbp_split_topic_source_not_found', __( '<strong>ERROR</strong>: The topic you want to split was not found!', 'bbpress' ) );
    14211422
     
    14351436                                        $bbp->errors->add( 'bbp_split_topic_destination_id', __( '<strong>ERROR</strong>: Destination topic ID not found!', 'bbpress' ) );
    14361437
    1437                                 if ( !$destination_topic = get_post( $destination_topic_id ) )
     1438                                if ( !$destination_topic = bbp_get_topic( $destination_topic_id ) )
    14381439                                        $bbp->errors->add( 'bbp_split_topic_destination_not_found', __( '<strong>ERROR</strong>: The topic you want to split to was not found!', 'bbpress' ) );
    14391440
     
    14621463
    14631464                                        // Shouldn't happen
    1464                                         if ( false == $destination_topic_id || is_wp_error( $destination_topic_id ) || !$destination_topic = get_post( $destination_topic_id ) )
     1465                                        if ( false == $destination_topic_id || is_wp_error( $destination_topic_id ) || !$destination_topic = bbp_get_topic( $destination_topic_id ) )
    14651466                                                $bbp->errors->add( 'bbp_split_topic_destination_reply', __( '<strong>ERROR</strong>: There was a problem converting the reply into the topic, please try again!', 'bbpress' ) );
    14661467
     
    21362137 * @since bbPress (r2727)
    21372138 *
    2138  * @uses get_post() To get the topic
     2139 * @uses bbp_get_topic() To get the topic
    21392140 * @uses current_user_can() To check if the user is capable of editing or
    21402141 *                           deleting the topic
     
    21702171
    21712172                // Make sure topic exists
    2172                 if ( !$topic = get_post( $topic_id ) )
     2173                if ( !$topic = bbp_get_topic( $topic_id ) )
    21732174                        return;
    21742175
     
    22722273 * @since bbPress (r2740)
    22732274 *
    2274  * @uses get_post() To get the reply
     2275 * @uses bbp_get_reply() To get the reply
    22752276 * @uses current_user_can() To check if the user is capable of editing or
    22762277 *                           deleting the reply
     
    23012302
    23022303                // Make sure reply exists
    2303                 if ( !$reply = get_post( $reply_id ) )
     2304                if ( !$reply = bbp_get_reply( $reply_id ) )
    23042305                        return;
    23052306
     
    24582459 */
    24592460function bbp_is_favorites_active() {
    2460         return (bool) get_option( '_bbp_enable_favorites' );
     2461        return (bool) get_option( '_bbp_enable_favorites', true );
    24612462}
    24622463
     
    26102611 * @param int $reply_id ID of the newly made reply
    26112612 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active
    2612  * @uses get_post() To get the topic and reply
     2613 * @uses bbp_get_reply() To get the reply
     2614 * @uses bbp_get_topic() To get the reply's topic
    26132615 * @uses get_the_author_meta() To get the author's display name
    26142616 * @uses do_action() Calls 'bbp_pre_notify_subscribers' with the reply id and
     
    26322634                return false;
    26332635
    2634         if ( !$reply = get_post( $reply_id ) )
     2636        if ( !$reply = bbp_get_reply( $reply_id ) )
    26352637                return false;
    26362638
     
    26382640                return false;
    26392641
    2640         if ( !$topic = get_post( $reply->post_parent ) )
     2642        if ( !$topic = bbp_get_topic( $reply->post_parent ) )
    26412643                return false;
    26422644
  • branches/plugin/bbp-includes/bbp-options.php

    r2786 r2787  
    4141
    4242                // Topics per page
    43                 '_bbp_topics_per_page'      => '20',
     43                '_bbp_topics_per_page'      => '15',
    4444
    4545                // Replies per page
    46                 '_bbp_replies_per_page'     => '20',
     46                '_bbp_replies_per_page'     => '15',
    4747
    4848                /** SLUGS *************************************************************/
  • branches/plugin/bbp-includes/bbp-reply-template.php

    r2782 r2787  
    175175                return apply_filters( 'bbp_get_reply_id', (int) $bbp_reply_id );
    176176        }
     177
     178/**
     179 * Gets a reply
     180 *
     181 * @since bbPress (r2787)
     182 *
     183 * @param int|object $reply reply id or reply object
     184 * @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT
     185 * @param string $filter Optional Sanitation filter. See {@link sanitize_post()}
     186 * @uses get_post() To get the reply
     187 * @return mixed Null if error or reply (in specified form) if success
     188 */
     189function bbp_get_reply( $reply, $output = OBJECT, $filter = 'raw' ) {
     190        global $bbp;
     191
     192        if ( empty( $reply ) || is_numeric( $reply ) )
     193                $reply = bbp_get_reply_id( $reply );
     194
     195        if ( !$reply = get_post( $reply, OBJECT, $filter ) )
     196                return $reply;
     197
     198        if ( $bbp->reply_id !== $reply->post_type )
     199                return null;
     200
     201        if ( $output == OBJECT ) {
     202                return $reply;
     203
     204        } elseif ( $output == ARRAY_A ) {
     205                $_reply = get_object_vars( $reply );
     206                return $_reply;
     207
     208        } elseif ( $output == ARRAY_N ) {
     209                $_reply = array_values( get_object_vars( $reply ) );
     210                return $_reply;
     211
     212        }
     213
     214        return $reply;
     215}
    177216
    178217/**
     
    11001139         *  - edit_text: Edit text. Defaults to 'Edit'
    11011140         * @uses bbp_get_reply_id() To get the reply id
    1102          * @uses get_post() To get the reply
     1141         * @uses bbp_get_reply() To get the reply
    11031142         * @uses current_user_can() To check if the current user can edit the
    11041143         *                           reply
     
    11191158                extract( $r );
    11201159
    1121                 $reply = get_post( bbp_get_reply_id( (int) $id ) );
     1160                $reply = bbp_get_reply( bbp_get_reply_id( (int) $id ) );
    11221161
    11231162                if ( empty( $reply ) || !current_user_can( 'edit_reply', $reply->ID ) )
     
    11481187         * @param int $reply_id Optional. Reply id
    11491188         * @uses bbp_get_reply_id() To get the reply id
    1150          * @uses get_post() To get the reply
     1189         * @uses bbp_get_reply() To get the reply
    11511190         * @uses add_query_arg() To add custom args to the url
    11521191         * @uses home_url() To get the home url
     
    11581197                global $wp_rewrite, $bbp;
    11591198
    1160                 if ( !$reply = get_post( bbp_get_reply_id( $reply_id ) ) )
     1199                if ( !$reply = bbp_get_reply( bbp_get_reply_id( $reply_id ) ) )
    11611200                        return;
    11621201
     
    11971236         *  - delete_text: Delete text
    11981237         * @uses bbp_get_reply_id() To get the reply id
    1199          * @uses get_post() To get the reply
     1238         * @uses bbp_get_reply() To get the reply
    12001239         * @uses current_user_can() To check if the current user can delete the
    12011240         *                           reply
     
    12241263
    12251264                $actions = array();
    1226                 $reply   = get_post( bbp_get_reply_id( (int) $id ) );
     1265                $reply   = bbp_get_reply( bbp_get_reply_id( (int) $id ) );
    12271266
    12281267                if ( empty( $reply ) || !current_user_can( 'delete_reply', $reply->ID ) )
     
    12691308         *  - unspam_text: Unspam text
    12701309         * @uses bbp_get_reply_id() To get the reply id
    1271          * @uses get_post() To get the reply
     1310         * @uses bbp_get_reply() To get the reply
    12721311         * @uses current_user_can() To check if the current user can edit the
    12731312         *                           reply
     
    12931332                extract( $r );
    12941333
    1295                 $reply = get_post( bbp_get_reply_id( (int) $id ) );
     1334                $reply = bbp_get_reply( bbp_get_reply_id( (int) $id ) );
    12961335
    12971336                if ( empty( $reply ) || !current_user_can( 'moderate', $reply->ID ) )
     
    13341373         *  - split_title: Split title attribute
    13351374         * @uses bbp_get_reply_id() To get the reply id
    1336          * @uses get_post() To get the reply
     1375         * @uses bbp_get_reply() To get the reply
    13371376         * @uses current_user_can() To check if the current user can edit the
    13381377         *                           topic
     
    13581397                extract( $r );
    13591398
    1360                 $reply = get_post( bbp_get_reply_id( (int) $id ) );
     1399                $reply = bbp_get_reply( bbp_get_reply_id( (int) $id ) );
    13611400
    13621401                if ( empty( $reply ) || !current_user_can( 'moderate', $reply->post_parent ) )
  • branches/plugin/bbp-includes/bbp-topic-template.php

    r2786 r2787  
    275275                return apply_filters( 'bbp_get_topic_id', (int) $bbp_topic_id );
    276276        }
     277
     278/**
     279 * Gets a topic
     280 *
     281 * @since bbPress (r2787)
     282 *
     283 * @param int|object $topic Topic id or topic object
     284 * @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT
     285 * @param string $filter Optional Sanitation filter. See {@link sanitize_post()}
     286 * @uses get_post() To get the topic
     287 * @return mixed Null if error or topic (in specified form) if success
     288 */
     289function bbp_get_topic( $topic, $output = OBJECT, $filter = 'raw' ) {
     290        global $bbp;
     291
     292        if ( empty( $topic ) || is_numeric( $topic ) )
     293                $topic = bbp_get_topic_id( $topic );
     294
     295        if ( !$topic = get_post( $topic, OBJECT, $filter ) )
     296                return $topic;
     297
     298        if ( $bbp->topic_id !== $topic->post_type )
     299                return null;
     300
     301        if ( $output == OBJECT ) {
     302                return $topic;
     303
     304        } elseif ( $output == ARRAY_A ) {
     305                $_topic = get_object_vars( $topic );
     306                return $_topic;
     307
     308        } elseif ( $output == ARRAY_N ) {
     309                $_topic = array_values( get_object_vars( $topic ) );
     310                return $_topic;
     311
     312        }
     313
     314        return $topic;
     315}
    277316
    278317/**
     
    12821321         * @param int $topic_id Optional. Topic id
    12831322         * @uses bbp_get_topic_id() To get the topic id
    1284          * @uses get_post() To get the topic
     1323         * @uses bbp_get_topic() To get the topic
    12851324         * @uses bbp_get_topic_reply_count() To get the topic reply count
    12861325         * @uses bbp_get_topic_permalink() To get the topic permalink
     
    12971336                global $bbp;
    12981337
    1299                 $topic    = get_post( bbp_get_topic_id( (int) $topic_id ) );
     1338                $topic    = bbp_get_topic( bbp_get_topic_id( (int) $topic_id ) );
    13001339                $topic_id = $topic->ID;
    13011340                $replies  = bbp_get_topic_reply_count( $topic_id );
     
    16161655         *  - edit_text: Edit text
    16171656         * @uses bbp_get_topic_id() To get the topic id
    1618          * @uses get_post() To get the topic
     1657         * @uses bbp_get_topic() To get the topic
    16191658         * @uses current_user_can() To check if the current user can edit the
    16201659         *                           topic
     
    16351674                extract( $r );
    16361675
    1637                 $topic = get_post( bbp_get_topic_id( (int) $id ) );
     1676                $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
    16381677
    16391678                if ( empty( $topic ) || !current_user_can( 'edit_topic', $topic->ID ) )
     
    16641703         * @param int $topic_id Optional. Topic id
    16651704         * @uses bbp_get_topic_id() To get the topic id
    1666          * @uses get_post() To get the topic
     1705         * @uses bbp_get_topic() To get the topic
    16671706         * @uses add_query_arg() To add custom args to the url
    16681707         * @uses home_url() To get the home url
     
    16741713                global $wp_rewrite, $bbp;
    16751714
    1676                 if ( !$topic = get_post( bbp_get_topic_id( $topic_id ) ) )
     1715                if ( !$topic = bbp_get_topic( bbp_get_topic_id( $topic_id ) ) )
    16771716                        return;
    16781717
     
    17131752         *  - delete_text: Delete text
    17141753         * @uses bbp_get_topic_id() To get the topic id
    1715          * @uses get_post() To get the topic
     1754         * @uses bbp_get_topic() To get the topic
    17161755         * @uses current_user_can() To check if the current user can delete the
    17171756         *                           topic
     
    17401779
    17411780                $actions = array();
    1742                 $topic   = get_post( bbp_get_topic_id( (int) $id ) );
     1781                $topic   = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
    17431782
    17441783                if ( empty( $topic ) || !current_user_can( 'delete_topic', $topic->ID ) )
     
    17851824         *  - open_text: Open text
    17861825         * @uses bbp_get_topic_id() To get the topic id
    1787          * @uses get_post() To get the topic
     1826         * @uses bbp_get_topic() To get the topic
    17881827         * @uses current_user_can() To check if the current user can edit the
    17891828         *                           topic
     
    18091848                extract( $r );
    18101849
    1811                 $topic = get_post( bbp_get_topic_id( (int) $id ) );
     1850                $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
    18121851
    18131852                if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) )
     
    18471886         *  - super_text: Stick to front text
    18481887         * @uses bbp_get_topic_id() To get the topic id
    1849          * @uses get_post() To get the topic
     1888         * @uses bbp_get_topic() To get the topic
    18501889         * @uses current_user_can() To check if the current user can edit the
    18511890         *                           topic
     
    18711910                extract( $r );
    18721911
    1873                 $topic = get_post( bbp_get_topic_id( (int) $id ) );
     1912                $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
    18741913
    18751914                if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) )
     
    19181957         *  - link_after: After the link
    19191958         *  - merge_text: Merge text
     1959         * @uses bbp_get_topic_id() To get the topic id
     1960         * @uses bbp_get_topic() To get the topic
    19201961         * @uses bbp_get_topic_edit_url() To get the topic edit url
    19211962         * @uses add_query_arg() To add custom args to the url
     
    19361977                extract( $r );
    19371978
    1938                 $topic = get_post( bbp_get_topic_id( (int) $id ) );
     1979                $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
    19391980
    19401981                if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) )
     
    19702011         *  - unspam_text: Unspam text
    19712012         * @uses bbp_get_topic_id() To get the topic id
    1972          * @uses get_post() To get the topic
     2013         * @uses bbp_get_topic() To get the topic
    19732014         * @uses current_user_can() To check if the current user can edit the
    19742015         *                           topic
     
    19942035                extract( $r );
    19952036
    1996                 $topic = get_post( bbp_get_topic_id( (int) $id ) );
     2037                $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
    19972038
    19982039                if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) )
  • branches/plugin/bbp-includes/bbp-users.php

    r2780 r2787  
    195195 * @uses bbp_get_user_id() To get the user id
    196196 * @uses bbp_get_user_favorites_topic_ids() To get the user favorites
    197  * @uses get_post() To get the topic
     197 * @uses bbp_get_topic() To get the topic
    198198 * @uses bbp_get_topic_id() To get the topic id
    199199 * @uses apply_filters() Calls 'bbp_is_user_favorite' with the bool, user id,
     
    210210
    211211        if ( !empty( $topic_id ) ) {
    212                 $post = get_post( $topic_id );
    213                 $topic_id = $post->ID;
     212                $topic    = bbp_get_topic( $topic_id );
     213                $topic_id = !empty( $topic ) ? $topic->ID : 0;
    214214        } elseif ( !$topic_id = bbp_get_topic_id() ) {
    215215                if ( empty( $post ) )
     
    246246        $favorites = (array) bbp_get_user_favorites_topic_ids( $user_id );
    247247
    248         if ( !$topic = get_post( $topic_id ) )
     248        if ( !$topic = bbp_get_topic( $topic_id ) )
    249249                return false;
    250250
     
    388388 * @uses bbp_get_user_id() To get the user id
    389389 * @uses bbp_get_user_subscribed_topic_ids() To get the user's subscriptions
    390  * @uses get_post() To get the topic
     390 * @uses bbp_get_topic() To get the topic
    391391 * @uses bbp_get_topic_id() To get the topic id
    392392 * @uses apply_filters() Calls 'bbp_is_user_subscribed' with the bool, user id,
     
    403403
    404404        if ( !empty( $topic_id ) ) {
    405                 $post     = get_post( $topic_id );
    406                 $topic_id = $post->ID;
     405                $topic     = bbp_get_topic( $topic_id );
     406                $topic_id = !empty( $topic ) ? $topic->ID : 0;
    407407        } elseif ( !$topic_id = bbp_get_topic_id() ) {
    408408                if ( empty( $post ) )
     
    429429 * @param int $topic_id Optional. Topic id
    430430 * @uses bbp_get_user_subscribed_topic_ids() To get the user's subscriptions
    431  * @uses get_post() To get the topic
     431 * @uses bbp_get_topic() To get the topic
    432432 * @uses update_user_meta() To update the user's subscriptions
    433433 * @uses do_action() Calls 'bbp_add_user_subscription' with the user & topic id
     
    440440        $subscriptions = (array) bbp_get_user_subscribed_topic_ids( $user_id );
    441441
    442         if ( !$topic = get_post( $topic_id ) )
     442        if ( !$topic = bbp_get_topic( $topic_id ) )
    443443                return false;
    444444
  • branches/plugin/bbp-themes/bbp-twentyten/functions.php

    r2758 r2787  
    3232 * @uses bbp_get_current_user_id() To get the current user id
    3333 * @uses current_user_can() To check if the current user can edit the user
    34  * @uses get_post() To get the topic
     34 * @uses bbp_get_topic() To get the topic
    3535 * @uses check_ajax_referer() To verify the nonce & check the referer
    3636 * @uses bbp_is_user_favorite() To check if the topic is user's favorite
     
    4545                die( '-1' );
    4646
    47         if ( !$topic = get_post( $id ) )
     47        if ( !$topic = bbp_get_topic( $id ) )
    4848                die( '0' );
    4949
     
    6969 * @uses bbp_get_current_user_id() To get the current user id
    7070 * @uses current_user_can() To check if the current user can edit the user
    71  * @uses get_post() To get the topic
     71 * @uses bbp_get_topic() To get the topic
    7272 * @uses check_ajax_referer() To verify the nonce & check the referer
    7373 * @uses bbp_is_user_subscribed() To check if the topic is in user's
     
    8787                die( '-1' );
    8888
    89         if ( !$topic = get_post( $id ) )
     89        if ( !$topic = bbp_get_topic( $id ) )
    9090                die( '0' );
    9191
Note: See TracChangeset for help on using the changeset viewer.