#3420 closed defect (bug) (fixed)
PHP Notice when editing non-published topic
Reported by: | dd32 | Owned by: | johnjamesjacoby |
---|---|---|---|
Milestone: | 2.6.7 | Priority: | normal |
Severity: | normal | Version: | |
Component: | General | Keywords: | |
Cc: |
Description
It looks like the $topic_status
variable ends up undefined when bbp_check_for_moderation()
and bbp_is_topic_public()
both return false.
It appears to be when editing a topic that is still pending review I guess.
The below patch is what was most obvious to me at first, but I guess the first if branch could also just get an additional else
branch.
E_NOTICE: Undefined variable: topic_status in wp-content/plugins/bbpress/includes/topics/functions.php:622 Source: POST https://de.wordpress.org/support/?post_type=topic&p=101119
-
includes/topics/functions.php
function bbp_edit_topic_handler( $action 547 547 // No topic content 548 548 if ( empty( $topic_content ) ) { 549 549 bbp_add_error( 'bbp_edit_topic_content', __( '<strong>Error</strong>: Your topic cannot be empty.', 'bbpress' ) ); 550 550 } 551 551 552 552 /** Topic Bad Words *******************************************************/ 553 553 554 554 if ( ! bbp_check_for_moderation( $anonymous_data, $topic_author, $topic_title, $topic_content, true ) ) { 555 555 bbp_add_error( 'bbp_topic_moderation', __( '<strong>Error</strong>: Your topic cannot be edited at this time.', 'bbpress' ) ); 556 556 } 557 557 558 558 /** Topic Status **********************************************************/ 559 559 560 560 // Get available topic statuses 561 561 $topic_statuses = bbp_get_topic_statuses( $topic_id ); 562 $topic_status = $topic->post_status; 562 563 563 564 // Maybe put into moderation 564 565 if ( ! bbp_check_for_moderation( $anonymous_data, $topic_author, $topic_title, $topic_content ) ) { 565 566 566 567 // Set post status to pending if public or closed 567 568 if ( bbp_is_topic_public( $topic->ID ) ) { 568 569 $topic_status = bbp_get_pending_status_id(); 569 570 } 570 571 571 572 // Check possible topic status ID's 572 573 } elseif ( ! empty( $_POST['bbp_topic_status'] ) && in_array( $_POST['bbp_topic_status'], array_keys( $topic_statuses ), true ) ) { 573 574 $topic_status = sanitize_key( $_POST['bbp_topic_status'] ); 574 575 // Use existing post_status576 } else {577 $topic_status = $topic->post_status;578 575 } 579 576 580 577 /** Topic Tags ************************************************************/ 581 578 582 579 // Either replace terms 583 580 if ( bbp_allow_topic_tags() && current_user_can( 'assign_topic_tags', $topic_id ) && ! empty( $_POST['bbp_topic_tags'] ) ) { 584 581 585 582 // Escape tag input 586 583 $terms = sanitize_text_field( $_POST['bbp_topic_tags'] ); 587 584 588 585 // Explode by comma 589 586 if ( strstr( $terms, ',' ) ) { 590 587 $terms = explode( ',', $terms ); 591 588 }
Attachments (1)
Change History (5)
Note: See
TracTickets for help on using
tickets.
Or combining
bbp_is_topic_public()
into the firstif ( bbp_check_for_moderation() )
conditional could also maybe be cleaner.includes/topics/functions.php
// Set post status to pending if public or closedif ( bbp_is_topic_public( $topic->ID ) ) {$topic_status = bbp_get_pending_status_id();}