PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.5.0
Forumax – AI Powered Advanced Community Forum Plugin v2.5.0
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 +62 -26 1.2.2 → 2.5.0 View file →
@@ -1,8 +1,8 @@
1 1 <?php
2 2 namespace features;
3 3
4 -class bbp_solved_topic {
4 +class forumax_solve_topic {
5 5
6 6 /**
7 7 * The capability required to view private posts.
8 8 *
@@ -41,13 +41,37 @@
41 41
42 42 add_filter( 'bbp_theme_before_topic_title', [ $this, 'solved_badge' ], 999, 2 );
43 43 add_filter( 'bbp_topic_admin_links', [ $this, 'add_topic_admin_link' ], 10, 2 );
44 44
45 + add_action( 'template_redirect', [ $this, 'handle_solve_action' ] );
46 +
45 47 // add a class name indicating the read status
46 48 add_filter( 'post_class', [ $this, 'reply_post_class' ] );
47 49 }
48 50
49 51 /**
52 + * Handle the solve/unsolve action via GET request
53 + *
54 + * @since 2.2.0
55 + */
56 + public function handle_solve_action() {
57 + $topic_id = bbp_get_topic_id();
58 +
59 + if ( isset( $_GET['solve_topic'] ) ) {
60 + // Verify nonce
61 + if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'forumax_solve_topic_' . $topic_id ) ) {
62 + wp_die( esc_html__( 'Security check failed.', 'forumax' ) );
63 + }
64 + $this->solve_topic( $topic_id );
65 + } elseif ( isset( $_GET['unsolve_topic'] ) ) {
66 + if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'forumax_unsolve_topic_' . $topic_id ) ) {
67 + wp_die( esc_html__( 'Security check failed.', 'forumax' ) );
68 + }
69 + $this->unsolve_topic( $topic_id );
70 + }
71 + }
72 +
73 + /**
50 74 * Admin links
51 75 */
52 76 public function add_topic_admin_link( $links, $topic_id ) {
53 77
@@ -52,20 +76,18 @@
52 76 public function add_topic_admin_link( $links, $topic_id ) {
53 77
54 78 $topic_author = bbp_get_topic_author_id( bbp_get_topic_id() );
55 79 if ( ( current_user_can( $this->capability ) ) || ( $topic_author == get_current_user_id() ) ) {
56 - if ( isset( $_GET['unsolve_topic'] ) ) {
57 - $this->unsolve_topic( bbp_get_topic_id() );
58 - $links['solved'] = '<a href="' . bbp_get_topic_permalink() . '?solve_topic">' . esc_html__( 'Mark as solved', 'ama-core' ) . '</a>';
59 - } elseif ( isset( $_GET['solve_topic'] ) ) {
60 - $this->solve_topic( bbp_get_topic_id() );
61 - $links['unsolved'] = '<a href="' . bbp_get_topic_permalink() . '?unsolve_topic">' . esc_html__( 'Mark as unsolved', 'ama-core' ) . '</a>';
80 + if ( $this->is_solved( bbp_get_topic_id() ) ) {
81 + $links['unsolved'] = '<a href="' . wp_nonce_url(
82 + add_query_arg( 'unsolve_topic', '1', bbp_get_topic_permalink() ),
83 + 'forumax_unsolve_topic_' . bbp_get_topic_id()
84 + ) . '">' . esc_html__( 'Mark as unsolved', 'forumax' ) . '</a>';
62 85 } else {
63 - if ( $this->is_solved( bbp_get_topic_id() ) ) {
64 - $links['unsolved'] = '<a href="' . bbp_get_topic_permalink() . '?unsolve_topic">' . esc_html__( 'Mark as unsolved', 'ama-core' ) . '</a>';
65 - } else {
66 - $links['solved'] = '<a href="' . bbp_get_topic_permalink() . '?solve_topic">' . esc_html__( 'Mark as solved', 'ama-core' ) . '</a>';
67 - }
86 + $links['solved'] = '<a href="' . wp_nonce_url(
87 + add_query_arg( 'solve_topic', '1', bbp_get_topic_permalink() ),
88 + 'forumax_solve_topic_' . bbp_get_topic_id()
89 + ) . '">' . esc_html__( 'Mark as solved', 'forumax' ) . '</a>';
68 90 }
69 91 }
70 92 return $links;
71 93 }
@@ -73,12 +95,13 @@
73 95 public function solve_topic( $topic_id = 0 ) {
74 96 $topic_author = bbp_get_topic_author_id( $topic_id );
75 97 if ( ( current_user_can( $this->capability ) ) || ( $topic_author == get_current_user_id() ) ) {
76 98 update_post_meta( $topic_id, '_bbp_topic_is_solved', '1' );
77 - $redirect = remove_query_arg( [ 'solve_topic' ] );
99 + $redirect = remove_query_arg( [ 'solve_topic', '_wpnonce' ] );
78 100 wp_safe_redirect( $redirect );
101 + exit;
79 102 } else {
80 - wp_die( esc_html__( 'You do not have the permission to do that!', 'ama-core' ) );
103 + wp_die( esc_html__( 'You do not have the permission to do that!', 'forumax' ) );
81 104 }
82 105
83 106 }
84 107
@@ -85,12 +108,13 @@
85 108 public function unsolve_topic( $topic_id = 0 ) {
86 109 $topic_author = bbp_get_topic_author_id( $topic_id );
87 110 if ( ( current_user_can( $this->capability ) ) || ( $topic_author == get_current_user_id() ) ) {
88 111 delete_post_meta( $topic_id, '_bbp_topic_is_solved' );
89 - $redirect = remove_query_arg( [ 'unsolve_topic' ] );
112 + $redirect = remove_query_arg( [ 'unsolve_topic', '_wpnonce' ] );
90 113 wp_safe_redirect( $redirect );
114 + exit;
91 115 } else {
92 - wp_die( esc_html__( 'You do not have the permission to do that!', 'ama-core' ) );
116 + wp_die( esc_html__( 'You do not have the permission to do that!', 'forumax' ) );
93 117 }
94 118 }
95 119
96 120 /**
@@ -101,9 +125,9 @@
101 125 *
102 126 * @return void
103 127 */
104 128 public function filter_capability() {
105 - $this->capability = apply_filters( 'bbp_solved_topic_capability', $this->capability );
129 + $this->capability = apply_filters( 'forumax_solve_topic_capability', $this->capability );
106 130 }
107 131
108 132 /**
109 133 * Solved topic badge
@@ -133,9 +157,9 @@
133 157 if ( ( ! $has_best_answer ) || ( $is_best_answer ) ) {
134 158 ?>
135 159 <p>
136 160 <input name="bbp_best_answer" id="bbp_best_answer" type="checkbox"<?php checked( '1', $is_best_answer ); ?> value="1" tabindex="<?php bbp_tab_index(); ?>" />
137 - <label for="bbp_best_answer"><?php esc_html_e( 'Set this reply as Best Answer.', 'ama-core' ); ?></label>
161 + <label for="bbp_best_answer"><?php esc_html_e( 'Set this reply as Best Answer.', 'forumax' ); ?></label>
138 162 </p>
139 163 <?php
140 164 }
141 165 }
@@ -152,10 +176,10 @@
152 176 $topic_author = bbp_get_topic_author_id( bbp_get_topic_id() );
153 177 if ( bbp_is_topic_edit() && ( ( current_user_can( $this->capability ) ) || ( $topic_author == get_current_user_id() ) ) ) {
154 178 ?>
155 179 <p>
156 - <input name="bbp_solved_topic" id="bbp_solved_topic" type="checkbox"<?php checked( '1', $this->is_solved( bbp_get_topic_id() ) ); ?> value="1" tabindex="<?php bbp_tab_index(); ?>" />
157 - <label for="bbp_solved_topic"><?php esc_html_e( 'Set this post as solved.', 'ama-core' ); ?></label>
180 + <input name="forumax_solve_topic" id="forumax_solve_topic" type="checkbox"<?php checked( '1', $this->is_solved( bbp_get_topic_id() ) ); ?> value="1" tabindex="<?php bbp_tab_index(); ?>" />
181 + <label for="forumax_solve_topic"><?php esc_html_e( 'Set this post as solved.', 'forumax' ); ?></label>
158 182 </p>
159 183 <?php
160 184 }
161 185
@@ -201,9 +225,9 @@
201 225 * @return void
202 226 */
203 227 public function update_topic( $topic_id = 0, $is_edit = false ) {
204 228
205 - if ( isset( $_POST['bbp_solved_topic'] ) ) {
229 + if ( isset( $_POST['forumax_solve_topic'] ) ) {
206 230 update_post_meta( $topic_id, '_bbp_topic_is_solved', '1' );
207 231 } else {
208 232 delete_post_meta( $topic_id, '_bbp_topic_is_solved' );
209 233 }
@@ -288,9 +312,15 @@
288 312 *
289 313 * @return bool
290 314 */
291 315 public function has_best_answer( $topic_id = 0 ) {
316 +
317 + // if bbpress is not active, return the classes
292 318
319 + if ( ! function_exists( 'bbp_get_topic_id' ) ) {
320 + return false;
321 + }
322 +
293 323 $retval = false;
294 324
295 325 // Checking a specific reply id.
296 326 if ( ! empty( $topic_id ) ) {
@@ -332,9 +362,9 @@
332 362
333 363 $topic_id = bbp_get_topic_id();
334 364
335 365 if ( $this->is_best_answer( $reply_id ) ) {
336 - $content = '<div class="solved-topic-bar" id="best-answer"><span class="badge"><i class="icon_check"></i> ' . esc_html__( 'Best Answer', 'ama-core' ) . '</span></div>' . $content;
366 + $content = '<div class="solved-topic-bar" id="best-answer"><span class="badge"><i class="icon_check"></i> ' . esc_html__( 'Best Answer', 'forumax' ) . '</span></div>' . $content;
337 367 }
338 368
339 369 return $content;
340 370 }
@@ -365,9 +395,9 @@
365 395 $close = '</div>';
366 396 }
367 397
368 398 if ( $this->is_solved( $topic_id ) ) {
369 - $resolved = '<span class="accepted-ans-mark"><i class="icon_check_alt"></i> ' . esc_html__( 'Resolved', 'ama-core' ) . '</span>';
399 + $resolved = '<span class="accepted-ans-mark badge"><i class="icon_check_alt"></i> ' . esc_html__( 'Resolved', 'forumax' ) . '</span>';
370 400 }
371 401
372 402 $content = $content . $open . $resolved . $has_best_answer . $close;
373 403
@@ -383,8 +413,14 @@
383 413 *
384 414 * @return bool
385 415 */
386 416 public function reply_post_class( $classes ) {
417 +
418 + // if bbpress is not active, return the classes
419 + if ( ! function_exists( 'bbp_get_reply_id' ) ) {
420 + return $classes;
421 + }
422 +
387 423 $reply_id = bbp_get_reply_id();
388 424
389 425 // Only apply the class to replies.
390 426 if ( bbp_get_reply_post_type() != get_post_type( $reply_id ) ) {
@@ -399,9 +435,9 @@
399 435 }
400 436 }
401 437
402 438 // Instantiate the class.
403 -$GLOBALS['bbp_solved_topic'] = new bbp_solved_topic();
439 +$GLOBALS['forumax_solve_topic'] = new forumax_solve_topic();
404 440
405 -function bbp_solved_topic(): bbp_solved_topic {
406 - return new bbp_solved_topic();
441 +function forumax_solve_topic(): forumax_solve_topic {
442 + return new forumax_solve_topic();
407 443 }