Skip to:
Content

bbPress.org


Ignore:
Timestamp:
12/29/2016 04:25:54 AM (5 years ago)
Author:
johnjamesjacoby
Message:

Metaboxes: Add metaboxes for viewing favorites & subscriptions of topics & replies.

  • New functions for outputting avatars of users who have favved or subbed
  • Use the $post parameter that's passed in, rather than using get_the_ID() again
  • Use require_once as a language construct vs. include_once() as a function
  • Pass $post object through to metabox subsequent filters vs just the ID

See #2959.

File:
1 edited

Legend:

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

    r6115 r6197  
    294294 * @uses do_action() Calls 'bbp_forum_metabox'
    295295 */
    296 function bbp_forum_metabox() {
     296function bbp_forum_metabox( $post ) {
    297297
    298298    // Post ID
    299     $post_id     = get_the_ID();
    300299    $post_parent = bbp_get_global_post_field( 'post_parent', 'raw'  );
    301300    $menu_order  = bbp_get_global_post_field( 'menu_order',  'edit' );
     
    308307        <strong class="label"><?php esc_html_e( 'Type:', 'bbpress' ); ?></strong>
    309308        <label class="screen-reader-text" for="bbp_forum_type_select"><?php esc_html_e( 'Type:', 'bbpress' ) ?></label>
    310         <?php bbp_form_forum_type_dropdown( array( 'forum_id' => $post_id ) ); ?>
     309        <?php bbp_form_forum_type_dropdown( array( 'forum_id' => $post->ID ) ); ?>
    311310    </p>
    312311
     
    320319        <strong class="label"><?php esc_html_e( 'Status:', 'bbpress' ); ?></strong>
    321320        <label class="screen-reader-text" for="bbp_forum_status_select"><?php esc_html_e( 'Status:', 'bbpress' ) ?></label>
    322         <?php bbp_form_forum_status_dropdown( array( 'forum_id' => $post_id ) ); ?>
     321        <?php bbp_form_forum_status_dropdown( array( 'forum_id' => $post->ID ) ); ?>
    323322    </p>
    324323
     
    332331        <strong class="label"><?php esc_html_e( 'Visibility:', 'bbpress' ); ?></strong>
    333332        <label class="screen-reader-text" for="bbp_forum_visibility_select"><?php esc_html_e( 'Visibility:', 'bbpress' ) ?></label>
    334         <?php bbp_form_forum_visibility_dropdown( array( 'forum_id' => $post_id ) ); ?>
     333        <?php bbp_form_forum_visibility_dropdown( array( 'forum_id' => $post->ID ) ); ?>
    335334    </p>
    336335
     
    353352            'order'              => 'ASC',
    354353            'walker'             => '',
    355             'exclude'            => $post_id,
     354            'exclude'            => $post->ID,
    356355
    357356            // Output-related
     
    374373    <?php
    375374    wp_nonce_field( 'bbp_forum_metabox_save', 'bbp_forum_metabox' );
    376     do_action( 'bbp_forum_metabox', $post_id );
     375    do_action( 'bbp_forum_metabox', $post );
    377376}
    378377
     
    389388 * @uses do_action() Calls 'bbp_topic_metabox'
    390389 */
    391 function bbp_topic_metabox() {
    392 
    393     // Post ID
    394     $post_id = get_the_ID();
    395     $status  = get_post_status( $post_id );
     390function bbp_topic_metabox( $post ) {
    396391
    397392    /** Type ******************************************************************/
     
    402397        <strong class="label"><?php esc_html_e( 'Type:', 'bbpress' ); ?></strong>
    403398        <label class="screen-reader-text" for="bbp_stick_topic"><?php esc_html_e( 'Topic Type', 'bbpress' ); ?></label>
    404         <?php bbp_form_topic_type_dropdown( array( 'topic_id' => $post_id ) ); ?>
     399        <?php bbp_form_topic_type_dropdown( array( 'topic_id' => $post->ID ) ); ?>
    405400    </p>
    406401
     
    413408    <p>
    414409        <strong class="label"><?php esc_html_e( 'Status:', 'bbpress' ); ?></strong>
    415         <input type="hidden" name="hidden_post_status" id="hidden_post_status" value="<?php echo esc_attr( ( 'auto-draft' === $status ) ? 'draft' : $status ); ?>" />
     410        <input type="hidden" name="hidden_post_status" id="hidden_post_status" value="<?php echo esc_attr( ( 'auto-draft' === $post->post_status ) ? 'draft' : $post->post_status ); ?>" />
    416411        <label class="screen-reader-text" for="bbp_open_close_topic"><?php esc_html_e( 'Select whether to open or close the topic.', 'bbpress' ); ?></label>
    417         <?php bbp_form_topic_status_dropdown( array( 'select_id' => 'post_status', 'topic_id' => $post_id ) ); ?>
     412        <?php bbp_form_topic_status_dropdown( array( 'select_id' => 'post_status', 'topic_id' => $post->ID ) ); ?>
    418413    </p>
    419414
     
    431426        <?php bbp_dropdown( array(
    432427            'post_type'          => bbp_get_forum_post_type(),
    433             'selected'           => bbp_get_topic_forum_id( $post_id ),
     428            'selected'           => bbp_get_topic_forum_id( $post->ID ),
    434429            'numberposts'        => -1,
    435430            'orderby'            => 'title',
     
    451446    <?php
    452447    wp_nonce_field( 'bbp_topic_metabox_save', 'bbp_topic_metabox' );
    453     do_action( 'bbp_topic_metabox', $post_id );
     448    do_action( 'bbp_topic_metabox', $post );
    454449}
    455450
     
    466461 * @uses do_action() Calls 'bbp_reply_metabox'
    467462 */
    468 function bbp_reply_metabox() {
    469 
    470     // Post ID
    471     $post_id = get_the_ID();
    472     $status  = get_post_status( $post_id );
     463function bbp_reply_metabox( $post ) {
    473464
    474465    // Get some meta
    475     $reply_topic_id = bbp_get_reply_topic_id( $post_id );
    476     $reply_forum_id = bbp_get_reply_forum_id( $post_id );
     466    $reply_topic_id = bbp_get_reply_topic_id( $post->ID );
     467    $reply_forum_id = bbp_get_reply_forum_id( $post->ID );
    477468    $topic_forum_id = bbp_get_topic_forum_id( $reply_topic_id );
    478469
     
    483474    <p>
    484475        <strong class="label"><?php esc_html_e( 'Status:', 'bbpress' ); ?></strong>
    485         <input type="hidden" name="hidden_post_status" id="hidden_post_status" value="<?php echo esc_attr( ( 'auto-draft' === $status ) ? 'draft' : $status ); ?>" />
     476        <input type="hidden" name="hidden_post_status" id="hidden_post_status" value="<?php echo esc_attr( ( 'auto-draft' === $post->post_status ) ? 'draft' : $post->post_status ); ?>" />
    486477        <label class="screen-reader-text" for="post_status"><?php esc_html_e( 'Select what status to give the reply.', 'bbpress' ); ?></label>
    487         <?php bbp_form_reply_status_dropdown( array( 'select_id' => 'post_status', 'reply_id' => $post_id ) ); ?>
     478        <?php bbp_form_reply_status_dropdown( array( 'select_id' => 'post_status', 'reply_id' => $post->ID ) ); ?>
    488479    </p>
    489480
     
    495486
    496487    // Only allow individual manipulation of reply forum if there is a mismatch
    497     if ( ( $reply_forum_id !== $topic_forum_id ) && ( current_user_can( 'edit_others_replies' ) || current_user_can( 'moderate', $post_id ) ) ) : ?>
     488    if ( ( $reply_forum_id !== $topic_forum_id ) && ( current_user_can( 'edit_others_replies' ) || current_user_can( 'moderate', $post->ID ) ) ) : ?>
    498489
    499490        <p>
     
    540531            <strong class="label"><?php esc_html_e( 'Reply To:', 'bbpress' ); ?></strong>
    541532            <label class="screen-reader-text" for="bbp_reply_to"><?php esc_html_e( 'Reply To', 'bbpress' ); ?></label>
    542             <?php bbp_reply_to_dropdown( $post_id ); ?>
     533            <?php bbp_reply_to_dropdown( $post->ID ); ?>
    543534        </p>
    544535
     
    553544    <?php
    554545    wp_nonce_field( 'bbp_reply_metabox_save', 'bbp_reply_metabox' );
    555     do_action( 'bbp_reply_metabox', $post_id );
     546    do_action( 'bbp_reply_metabox', $post );
    556547}
    557548
     
    574565    // Pull in the list table class
    575566    if ( ! class_exists( 'BBP_Topic_Replies_List_Table' ) ) {
    576         include_once bbpress()->admin->admin_dir . '/list-tables/topic-replies.php';
     567        require_once bbpress()->admin->admin_dir . '/list-tables/topic-replies.php';
    577568    }
    578569
     
    602593 * @since 2.0.0 bbPress (r2828)
    603594 *
     595 * @param WP_Post $post The current post object
    604596 * @uses bbp_is_reply_anonymous() To check if reply is anonymous
    605597 * @uses bbp_is_topic_anonymous() To check if topic is anonymous
    606  * @uses get_the_ID() To get the global post ID
    607598 * @uses get_post_meta() To get the author user information
    608599 */
    609 function bbp_author_metabox() {
    610 
    611     // Post ID
    612     $post_id = get_the_ID();
     600function bbp_author_metabox( $post ) {
    613601
    614602    // Show extra bits if topic/reply is anonymous
    615     if ( bbp_is_reply_anonymous( $post_id ) || bbp_is_topic_anonymous( $post_id ) ) : ?>
     603    if ( bbp_is_reply_anonymous( $post->ID ) || bbp_is_topic_anonymous( $post->ID ) ) : ?>
    616604
    617605        <p>
    618606            <strong class="label"><?php esc_html_e( 'Name:', 'bbpress' ); ?></strong>
    619607            <label class="screen-reader-text" for="bbp_anonymous_name"><?php esc_html_e( 'Name', 'bbpress' ); ?></label>
    620             <input type="text" id="bbp_anonymous_name" name="bbp_anonymous_name" value="<?php echo esc_attr( get_post_meta( $post_id, '_bbp_anonymous_name', true ) ); ?>" />
     608            <input type="text" id="bbp_anonymous_name" name="bbp_anonymous_name" value="<?php echo esc_attr( get_post_meta( $post->ID, '_bbp_anonymous_name', true ) ); ?>" />
    621609        </p>
    622610
     
    624612            <strong class="label"><?php esc_html_e( 'Email:', 'bbpress' ); ?></strong>
    625613            <label class="screen-reader-text" for="bbp_anonymous_email"><?php esc_html_e( 'Email', 'bbpress' ); ?></label>
    626             <input type="text" id="bbp_anonymous_email" name="bbp_anonymous_email" value="<?php echo esc_attr( get_post_meta( $post_id, '_bbp_anonymous_email', true ) ); ?>" />
     614            <input type="text" id="bbp_anonymous_email" name="bbp_anonymous_email" value="<?php echo esc_attr( get_post_meta( $post->ID, '_bbp_anonymous_email', true ) ); ?>" />
    627615        </p>
    628616
     
    630618            <strong class="label"><?php esc_html_e( 'Website:', 'bbpress' ); ?></strong>
    631619            <label class="screen-reader-text" for="bbp_anonymous_website"><?php esc_html_e( 'Website', 'bbpress' ); ?></label>
    632             <input type="text" id="bbp_anonymous_website" name="bbp_anonymous_website" value="<?php echo esc_attr( get_post_meta( $post_id, '_bbp_anonymous_website', true ) ); ?>" />
     620            <input type="text" id="bbp_anonymous_website" name="bbp_anonymous_website" value="<?php echo esc_attr( get_post_meta( $post->ID, '_bbp_anonymous_website', true ) ); ?>" />
    633621        </p>
    634622
     
    646634        <strong class="label"><?php esc_html_e( 'IP:', 'bbpress' ); ?></strong>
    647635        <label class="screen-reader-text" for="bbp_author_ip_address"><?php esc_html_e( 'IP Address', 'bbpress' ); ?></label>
    648         <input type="text" id="bbp_author_ip_address" name="bbp_author_ip_address" value="<?php echo esc_attr( get_post_meta( $post_id, '_bbp_author_ip', true ) ); ?>" disabled="disabled" />
    649     </p>
    650 
    651     <?php
    652 
    653     do_action( 'bbp_author_metabox', $post_id );
     636        <input type="text" id="bbp_author_ip_address" name="bbp_author_ip_address" value="<?php echo esc_attr( get_post_meta( $post->ID, '_bbp_author_ip', true ) ); ?>" disabled="disabled" />
     637    </p>
     638
     639    <?php
     640
     641    do_action( 'bbp_author_metabox', $post );
    654642}
    655643
     
    662650 * @uses get_post_meta() To get the author user information
    663651 */
    664 function bbp_moderator_assignment_metabox() {
    665 
    666     // Post ID
    667     $object_id      = get_the_ID();
    668     $user_ids       = bbp_get_moderator_ids( $object_id );
     652function bbp_moderator_assignment_metabox( $post ) {
     653
     654    // Get nicenames
     655    $user_ids       = bbp_get_moderator_ids( $post->ID );
    669656    $user_nicenames = bbp_get_user_nicenames_from_ids( $user_ids );
    670657    $moderators     = ! empty( $user_nicenames )
     
    679666    <?php
    680667
    681     do_action( 'bbp_moderator_assignment_metabox', $object_id );
    682 }
     668    do_action( 'bbp_moderator_assignment_metabox', $post );
     669}
     670
     671/**
     672 * See who marked a topic as a favorite
     673 *
     674 * @since 2.6.0 bbPress (r6179)
     675 */
     676function bbp_topic_favorites_metabox( $post ) {
     677
     678    // Get user IDs
     679    $user_ids = bbp_get_topic_favoriters( $post->ID );
     680
     681    // Output
     682    ?><p><?php
     683
     684        // Users were found
     685        if ( ! empty( $user_ids ) ) :
     686
     687            foreach ( $user_ids as $user_id ) :
     688                echo get_avatar( $user_id, 32 );
     689            endforeach;
     690
     691        // No users
     692        else :
     693            esc_html_e( 'No users have favorited this topic.', 'bbpress' );
     694        endif;
     695
     696    ?></p><?php
     697
     698    do_action( 'bbp_favorites_metabox', $post );
     699}
     700
     701/**
     702 * See who subscribed to a topic
     703 *
     704 * @since 2.6.0 bbPress (r6179)
     705 */
     706function bbp_topic_subscriptions_metabox( $post ) {
     707
     708    // Get user IDs
     709    $user_ids = bbp_get_topic_subscribers( $post->ID );
     710
     711    // Output
     712    ?><p><?php
     713
     714        // Users were found
     715        if ( ! empty( $user_ids ) ) :
     716
     717            foreach ( $user_ids as $user_id ) :
     718                echo get_avatar( $user_id, 32 );
     719            endforeach;
     720
     721        // No users
     722        else :
     723            esc_html_e( 'No users have subscribed to this topic.', 'bbpress' );
     724        endif;
     725
     726    ?></p><?php
     727
     728    do_action( 'bbp_subscriptions_metabox', $post );
     729}
     730
     731/**
     732 * See who subscribed to a forum
     733 *
     734 * @since 2.6.0 bbPress (r6179)
     735 */
     736function bbp_forum_subscriptions_metabox( $post ) {
     737
     738    // Get user IDs
     739    $user_ids = bbp_get_forum_subscribers( $post->ID );
     740
     741    // Output
     742    ?><p><?php
     743
     744        // Users were found
     745        if ( ! empty( $user_ids ) ) :
     746
     747            foreach ( $user_ids as $user_id ) :
     748                echo get_avatar( $user_id, 32 );
     749            endforeach;
     750
     751        // No users
     752        else :
     753            esc_html_e( 'No users have subscribed to this forum.', 'bbpress' );
     754        endif;
     755
     756    ?></p><?php
     757
     758    do_action( 'bbp_forum_subscriptions_metabox', $post );
     759}
Note: See TracChangeset for help on using the changeset viewer.