Skip to:
Content

bbPress.org

Ticket #1409: anonymous-metabox.diff

File anonymous-metabox.diff, 7.9 KB (added by GautamGupta, 16 years ago)
  • bbp-admin/bbp-admin.php

     
    119119                // Check if there are any bbp_toggle_reply_* requests on admin_init, also have a message displayed
    120120                add_action( 'bbp_admin_init',              array( $this, 'toggle_reply'        ) );
    121121                add_action( 'admin_notices',               array( $this, 'toggle_reply_notice' ) );
     122
     123                // Anonymous metabox actions
     124                add_action( 'add_meta_boxes',              array( $this, 'anonymous_metabox'      ) );
     125                add_action( 'save_post',                   array( $this, 'anonymous_metabox_save' ) );
    122126        }
    123127
    124128        /**
     
    358362         * @uses bbp_normalize_forum() To make the forum normal (not category)
    359363         * @uses bbp_privatize_forum() To mark the forum as private
    360364         * @uses bbp_publicize_forum() To mark the forum as public
    361          * @uses do_action() Calls 'bbp_forum_attributes_metabox_save'
     365         * @uses do_action() Calls 'bbp_forum_attributes_metabox_save' with the
     366         *                    forum id
    362367         * @return int Forum id
    363368         */
    364369        function forum_attributes_metabox_save( $forum_id ) {
     
    397402                                bbp_publicize_forum( $forum_id );
    398403                }
    399404
    400                 do_action( 'bbp_forum_attributes_metabox_save' );
     405                do_action( 'bbp_forum_attributes_metabox_save', $forum_id );
    401406
    402407                return $forum_id;
    403408        }
     
    433438         * @param int $topic_id Topic id
    434439         * @uses current_user_can() To check if the current user is capable of
    435440         *                           editing the topic
    436          * @uses do_action() Calls 'bbp_topic_attributes_metabox_save'
     441         * @uses do_action() Calls 'bbp_topic_attributes_metabox_save' with the
     442         *                    topic id and parent id
    437443         * @return int Parent id
    438444         */
    439445        function topic_attributes_metabox_save( $topic_id ) {
     
    444450                        return $topic_id;
    445451
    446452                // OK, we're authenticated: we need to find and save the data
    447                 $parent_id = isset( $_topic['parent_id'] ) ? $_topic['parent_id'] : 0;
     453                $parent_id = isset( $topic['parent_id'] ) ? $topic['parent_id'] : 0;
    448454
    449                 do_action( 'bbp_topic_attributes_metabox_save' );
     455                do_action( 'bbp_topic_attributes_metabox_save', $topic_id, $parent_id );
    450456
    451457                return $parent_id;
    452458        }
     
    482488         * @param int $reply_id Reply id
    483489         * @uses current_user_can() To check if the current user is capable of
    484490         *                           editing the reply
    485          * @uses do_action() Calls 'bbp_reply_attributes_metabox_save'
     491         * @uses do_action() Calls 'bbp_reply_attributes_metabox_save' with the
     492         *                    reply id and parent id
    486493         * @return int Parent id
    487494         */
    488495        function reply_attributes_metabox_save( $reply_id ) {
     
    493500                        return $reply_id;
    494501
    495502                // OK, we're authenticated: we need to find and save the data
    496                 $parent_id = isset( $_reply['parent_id'] ) ? $_reply['parent_id'] : 0;
     503                $parent_id = isset( $reply['parent_id'] ) ? $reply['parent_id'] : 0;
    497504
    498                 do_action( 'bbp_reply_attributes_metabox_save' );
     505                do_action( 'bbp_reply_attributes_metabox_save', $reply_id, $parent_id );
    499506
    500507                return $parent_id;
    501508        }
    502509
    503510        /**
     511         * Add the anonymous user info metabox
     512         *
     513         * Allows editing of information about an anonymous user
     514         *
     515         * @since bbPress (r)
     516         *
     517         * @uses bbp_get_topic() To get the topic
     518         * @uses bbp_get_reply() To get the reply
     519         * @uses bbp_is_topic_anonymous() To check if the topic is by an
     520         *                                 anonymous user
     521         * @uses bbp_is_reply_anonymous() To check if the reply is by an
     522         *                                 anonymous user
     523         * @uses add_meta_box() To add the metabox
     524         * @uses do_action() Calls 'bbp_anonymous_metabox' with the topic/reply
     525         *                    id
     526         */
     527        function anonymous_metabox() {
     528                global $bbp;
     529
     530                $post_id = (int) $_GET['post'];
     531
     532                if ( $topic = bbp_get_topic( $post_id ) )
     533                        $topic_id = $topic->ID;
     534                elseif ( $reply = bbp_get_reply( $post_id ) )
     535                        $reply_id = $reply->ID;
     536                else
     537                        return;
     538
     539                if ( !empty( $topic_id ) && !bbp_is_topic_anonymous( $topic_id ) )
     540                        return;
     541
     542                if ( !empty( $reply_id ) && !bbp_is_reply_anonymous( $reply_id ) )
     543                        return;
     544
     545                add_meta_box(
     546                        'bbp_anonymous_metabox',
     547                        __( 'Anonymous User Information', 'bbpress' ),
     548                        'bbp_anonymous_metabox',
     549                        !empty( $topic_id ) ? $bbp->topic_id : $bbp->reply_id,
     550                        'side',
     551                        'high'
     552                );
     553
     554                do_action( 'bbp_anonymous_metabox', $post_id );
     555        }
     556
     557        /**
     558         * Save the anonymous user information for the topic/reply
     559         *
     560         * @since bbPress (r)
     561         *
     562         * @param int $post_id Topic or reply id
     563         * @uses bbp_get_topic() To get the topic
     564         * @uses bbp_get_reply() To get the reply
     565         * @uses current_user_can() To check if the current user can edit the
     566         *                           topic or reply
     567         * @uses bbp_is_topic_anonymous() To check if the topic is by an
     568         *                                 anonymous user
     569         * @uses bbp_is_reply_anonymous() To check if the reply is by an
     570         *                                 anonymous user
     571         * @uses bbp_filter_anonymous_post_data() To filter the anonymous user
     572         *                                         data
     573         * @uses update_post_meta() To update the anonymous user data
     574         * @uses do_action() Calls 'bbp_anonymous_metabox_save' with the topic/
     575         *                    reply id and anonymous data
     576         * @return int Topic or reply id
     577         */
     578        function anonymous_metabox_save( $post_id ) {
     579                if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
     580                        return $post_id;
     581
     582                if ( $topic = bbp_get_topic( $post_id ) )
     583                        $topic_id = $topic->ID;
     584                elseif ( $reply = bbp_get_reply( $post_id ) )
     585                        $reply_id = $reply->ID;
     586                else
     587                        return $post_id;
     588
     589                if ( !empty( $topic_id ) && ( !current_user_can( 'edit_topic', $topic_id ) || !bbp_is_topic_anonymous( $topic_id ) ) )
     590                        return $topic_id;
     591
     592                if ( !empty( $reply_id ) && ( !current_user_can( 'edit_reply', $reply_id ) || !bbp_is_reply_anonymous( $reply_id ) ) )
     593                        return $reply_id;
     594
     595                $anonymous_data = bbp_filter_anonymous_post_data();
     596
     597                update_post_meta( $post_id, '_bbp_anonymous_name',    $anonymous_data['bbp_anonymous_name']    );
     598                update_post_meta( $post_id, '_bbp_anonymous_email',   $anonymous_data['bbp_anonymous_email']   );
     599                update_post_meta( $post_id, '_bbp_anonymous_website', $anonymous_data['bbp_anonymous_website'] );
     600
     601                do_action( 'bbp_anonymous_metabox_save', $post_id, $anonymous_data );
     602
     603                return $post_id;
     604        }
     605
     606        /**
    504607         * Add some general styling to the admin area
    505608         *
    506609         * @since bbPress (r2464)
     
    19472050}
    19482051
    19492052/**
     2053 * Anonymous user information metabox
     2054 *
     2055 * @since bbPress (r)
     2056 *
     2057 * @uses get_post_meta() To get the anonymous user information
     2058 */
     2059function bbp_anonymous_metabox () {
     2060        global $post, $bbp;
     2061
     2062        ?>
     2063
     2064        <p>
     2065                <strong><?php _e( 'Name', 'bbpress' ); ?></strong>
     2066        </p>
     2067
     2068        <p>
     2069                <label class="screen-reader-text" for="bbp_anonymous_name"><?php _e( 'Name', 'bbpress' ); ?></label>
     2070                <input type="text" id="bbp_anonymous_name" name="bbp_anonymous_name" value="<?php echo get_post_meta( $post->ID, '_bbp_anonymous_name', true ); ?>" size="38" /></label>
     2071        </p>
     2072
     2073        <p>
     2074                <strong><?php _e( 'Email', 'bbpress' ); ?></strong>
     2075        </p>
     2076
     2077        <p>
     2078                <label class="screen-reader-text" for="bbp_anonymous_email"><?php _e( 'Email', 'bbpress' ); ?></label>
     2079                <input type="text" id="bbp_anonymous_email" name="bbp_anonymous_email" value="<?php echo get_post_meta( $post->ID, '_bbp_anonymous_email', true ); ?>" size="38" /></label>
     2080        </p>
     2081
     2082        <p>
     2083                <strong><?php _e( 'Website', 'bbpress' ); ?></strong>
     2084        </p>
     2085
     2086        <p>
     2087                <label class="screen-reader-text" for="bbp_anonymous_website"><?php _e( 'Website', 'bbpress' ); ?></label>
     2088                <input type="text" id="bbp_anonymous_website" name="bbp_anonymous_website" value="<?php echo get_post_meta( $post->ID, '_bbp_anonymous_website', true ); ?>" size="38" /></label>
     2089        </p>
     2090
     2091        <br />
     2092
     2093        <p><?php printf( __( '<strong>IP Address</strong>: %s', 'bbpress' ), get_post_meta( $post->ID, '_bbp_anonymous_ip', true ) ); ?></p>
     2094
     2095        <?php
     2096}
     2097
     2098/**
    19502099 * Setup bbPress Admin
    19512100 *
    19522101 * @since bbPress (r2596)