PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.5.1
Forumax – AI Powered Advanced Community Forum Plugin v2.5.1
2.5.1 2.5.0 2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 All 31 releases
← All changes | includes/features/bbp_solved_topic.php +23 -4 2.4.1 → 2.5.1 View file →
@@ -53,18 +53,23 @@
53 53 *
54 54 * @since 2.2.0
55 55 */
56 56 public function handle_solve_action() {
57 + if ( ! isset( $_GET['solve_topic'] ) && ! isset( $_GET['unsolve_topic'] ) ) {
58 + return;
59 + }
60 +
57 61 $topic_id = bbp_get_topic_id();
62 + $nonce = isset( $_GET['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ) : '';
58 63
59 64 if ( isset( $_GET['solve_topic'] ) ) {
60 65 // Verify nonce
61 - if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'forumax_solve_topic_' . $topic_id ) ) {
66 + if ( ! wp_verify_nonce( $nonce, 'forumax_solve_topic_' . $topic_id ) ) {
62 67 wp_die( esc_html__( 'Security check failed.', 'forumax' ) );
63 68 }
64 69 $this->solve_topic( $topic_id );
65 70 } elseif ( isset( $_GET['unsolve_topic'] ) ) {
66 - if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'forumax_unsolve_topic_' . $topic_id ) ) {
71 + if ( ! wp_verify_nonce( $nonce, 'forumax_unsolve_topic_' . $topic_id ) ) {
67 72 wp_die( esc_html__( 'Security check failed.', 'forumax' ) );
68 73 }
69 74 $this->unsolve_topic( $topic_id );
70 75 }
@@ -206,9 +211,11 @@
206 211 if ( ! $get_topic_meta ) {
207 212 update_post_meta( $topic_id, '_bbp_topic_has_best_answer', '1' );
208 213 }
209 214 update_post_meta( $reply_id, '_bbp_reply_is_best_answer', '1' );
210 - } else {
215 + } elseif ( get_post_meta( $reply_id, '_bbp_reply_is_best_answer', true ) ) {
216 + // Only clear the topic flag when this reply was the best answer;
217 + // saving any other reply must not wipe it.
211 218 delete_post_meta( $reply_id, '_bbp_reply_is_best_answer' );
212 219 delete_post_meta( $topic_id, '_bbp_topic_has_best_answer' );
213 220 }
214 221
@@ -437,7 +444,19 @@
437 444
438 445 // Instantiate the class.
439 446 $GLOBALS['forumax_solve_topic'] = new forumax_solve_topic();
440 447
448 +/**
449 + * Shared solved-topic instance.
450 + *
451 + * Constructing a new instance re-registers every hook, so repeated calls
452 + * (once per topic in a loop) duplicated badges and filters.
453 + *
454 + * @return forumax_solve_topic
455 + */
441 456 function forumax_solve_topic(): forumax_solve_topic {
442 - return new forumax_solve_topic();
457 + if ( ! ( $GLOBALS['forumax_solve_topic'] ?? null ) instanceof forumax_solve_topic ) {
458 + $GLOBALS['forumax_solve_topic'] = new forumax_solve_topic();
459 + }
460 +
461 + return $GLOBALS['forumax_solve_topic'];
443 462 }