Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,13 @@ public function user_can_resolve( $retval, $user_id, $topic_id ) {
if ( ! $user ) {
return $retval;
}

// The compat object is loaded from the request, not from $topic_id.
$terms = get_the_terms( $topic_id, $this->taxonomy() );
if ( empty( $terms ) || is_wp_error( $terms ) || ! in_array( (string) $this->slug(), wp_list_pluck( $terms, 'slug' ), true ) ) {
return $retval;
}

if (
( ! empty( $this->authors ) && in_array( $user->user_nicename, $this->authors, true ) )
||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ public function dropdown( $retval, $r ) {
* @return bool True if enabled, otherwise false
*/
public function is_enabled_on_forum( $retval, $forum_id = 0 ) {
// Check the passed forum id.
// An explicit forum id wins over whatever the request happens to be rendering.
if ( ! empty( $forum_id ) ) {
$retval = ( $forum_id != Plugin::REVIEWS_FORUM_ID );
return ( Plugin::REVIEWS_FORUM_ID !== (int) $forum_id );
}

// Check the current forum.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,6 @@ public function get_topic_resolution_form() {
* @param string $action The requested action to compare this function to
*/
public function topic_resolution_handler( $action = '' ) {
if ( ! $this->is_enabled_on_forum() ) {
return false;
}

// Bail if the action isn't meant for this function.
if ( $action != 'wporg_bbp_topic_resolution' ) {
return;
Expand All @@ -284,6 +280,11 @@ public function topic_resolution_handler( $action = '' ) {
$user_id = get_current_user_id();
$resolution = $_POST[ self::META_KEY ];

// Resolution must be enabled on the topic's forum, not on the one being viewed.
if ( $topic && ! $this->is_enabled_on_forum( bbp_get_topic_forum_id( $topic->ID ) ) ) {
return false;
}

// Check for empty topic id.
if ( empty( $topic_id ) || ! $topic ) {
bbp_add_error( 'wporg_bbp_topic_resolution_topic_id', __( '<strong>Error:</strong> No topic was found!', 'wporg-forums' ) );
Expand Down Expand Up @@ -509,11 +510,9 @@ public function sanitize_topic_resolution( $resolution ) {
* @return bool True if allowed, false if not
*/
public function user_can_resolve( $user_id, $topic_id ) {
$post = false;
$topic_id = bbp_get_topic_id();
if ( $topic_id ) {
$post = get_post( $topic_id );
}
// Authorize against the requested topic, only falling back to the displayed one.
$topic_id = bbp_get_topic_id( $topic_id );
$post = $topic_id ? bbp_get_topic( $topic_id ) : false;

if ( $user_id && $post && ( user_can( $user_id, 'moderate', $topic_id ) || $user_id == $post->post_author ) ) {
$retval = true;
Expand Down