Skip to:
Content

bbPress.org

Changeset 2860 for trunk/bb-edit.php


Ignore:
Timestamp:
02/10/2011 08:33:59 AM (15 years ago)
Author:
johnjamesjacoby
Message:

Add ability for capable users to edit anonymous topic/post user data. Fixes #1463.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bb-edit.php

    r2147 r2860  
    66$post_id = (int) $_POST['post_id'];
    77
    8 $bb_post  = bb_get_post( $post_id );
     8$bb_post = bb_get_post( $post_id );
    99
    1010if ( !$bb_post ) {
     
    2121    add_filter('bb_is_first_where', 'bb_no_where');
    2222
    23 if ( bb_is_first( $bb_post->post_id ) && bb_current_user_can( 'edit_topic', $bb_post->topic_id ) ) {
    24     bb_insert_topic( array(
    25         'topic_title' => stripslashes( $_POST['topic'] ),
    26         'topic_id' => $bb_post->topic_id
    27     ) );
     23// Check possible anonymous user data
     24$post_author = $post_email = $post_url = '';
     25
     26if ( !bb_get_user( get_post_author_id( $post_id ) ) ) {
     27    if ( !$post_author = sanitize_user( trim( $_POST['author'] ) ) )
     28        bb_die( __( 'Every post needs an author name!' ) );
     29    elseif ( !$post_email = sanitize_email( trim( $_POST['email'] ) ) )
     30        bb_die( __( 'Every post needs a valid email address!' ) );
     31
     32    if ( !empty( $_POST['url'] ) )
     33        $post_url = esc_url( trim( $_POST['url'] ) );
    2834}
    2935
    30 bb_insert_post( array(
    31     'post_text' => stripslashes( $_POST['post_content'] ),
    32     'post_id' => $post_id,
    33     'topic_id' => $bb_post->topic_id
    34 ) );
     36// Loop through possible anonymous post data
     37foreach( array('post_author', 'post_email', 'post_url') as $field ) {
     38    if ( ! empty( $$field ) ) {
     39        $post_data[$field] = $$field;
     40    }
     41}
     42
     43// Setup topic data
     44if ( bb_is_first( $bb_post->post_id ) && bb_current_user_can( 'edit_topic', $bb_post->topic_id ) ) {
     45
     46    $post_data['topic_title'] = stripslashes( $_POST['topic'] );
     47    $post_data['topic_id']    = $bb_post->topic_id;
     48
     49    bb_insert_topic( $post_data );
     50}
     51
     52// Setup post data
     53$post_data['post_text'] = stripslashes( $_POST['post_content'] );
     54$post_data['post_id']   = $post_id;
     55
     56bb_insert_post( $post_data );
    3557
    3658if ( $post_id ) {
Note: See TracChangeset for help on using the changeset viewer.