comment_post_ID ) && current_user_can( Capabilities::MODERATE ) && current_user_can( 'edit_comment', (int) $comment->comment_ID ); if ( ! $allowed || ! $official ) { return $allowed; } return $comment->user_id && user_can( (int) $comment->user_id, Capabilities::MODERATE ); } /** * Marks or unmarks a comment as an official response. * * @param int $comment_id Comment ID. * @param bool $official Whether the comment is an official response. * @return bool False when the comment does not exist or the current user may not change it. */ public static function mark( int $comment_id, bool $official ): bool { $comment = get_comment( $comment_id ); if ( ! $comment instanceof WP_Comment || ! self::can_mark( $comment, $official ) ) { return false; } if ( $official ) { update_comment_meta( $comment_id, self::META, 1 ); } else { delete_comment_meta( $comment_id, self::META ); } return true; } /** * Returns a request's newest approved official response. * * @param int $request_id Request ID. */ public static function latest( int $request_id ): ?WP_Comment { $comments = get_comments( [ 'post_id' => $request_id, 'status' => 'approve', 'meta_key' => self::META, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- One request's comments. 'number' => 1, 'orderby' => 'comment_date_gmt', 'order' => 'DESC', ] ); return $comments[0] ?? null; } }