| | 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 | /** |
| | 2053 | * Anonymous user information metabox |
| | 2054 | * |
| | 2055 | * @since bbPress (r) |
| | 2056 | * |
| | 2057 | * @uses get_post_meta() To get the anonymous user information |
| | 2058 | */ |
| | 2059 | function 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 | /** |