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-private-replies.php +65 -49 1.2.9 → 2.5.0 View file →
@@ -1,8 +1,8 @@
1 1 <?php
2 2 namespace features;
3 3
4 -class BBP_Private_Replies {
4 +class Forumax_Private_Replies {
5 5
6 6 /**
7 7 * The capability required to view private posts.
8 8 *
@@ -25,9 +25,9 @@
25 25 // Allow others to change the capability required to view private posts.
26 26 add_action( 'plugins_loaded', [ $this, 'filter_capability' ] );
27 27
28 28 // show the "Private Reply?" checkbox
29 - add_action( 'bbp_theme_before_reply_form_submit_wrapper', [ $this, 'checkbox' ] );
29 + add_action( 'frmx_reply_options', [ $this, 'checkbox' ] );
30 30
31 31 // save the private reply state
32 32 add_action( 'bbp_new_reply', [ $this, 'update_reply' ], 0, 6 );
33 33 add_action( 'bbp_edit_reply', [ $this, 'update_reply' ], 0, 6 );
@@ -78,23 +78,26 @@
78 78 */
79 79 public function checkbox() {
80 80
81 81 ?>
82 - <p>
83 -
84 - <input name="bbp_private_reply" id="bbp_private_reply" type="checkbox"<?php checked( '1', $this->is_private( bbp_get_reply_id() ) ); ?> value="1" tabindex="<?php bbp_tab_index(); ?>" />
85 -
86 - <?php if ( bbp_is_reply_edit() && ( get_the_author_meta( 'ID' ) != bbp_get_current_user_id() ) ) : ?>
87 -
88 - <label for="bbp_private_reply"><?php esc_html_e( "Set author's post as private.", 'ama-core' ); ?></label>
89 -
90 - <?php else : ?>
91 -
92 - <label for="bbp_private_reply"><?php esc_html_e( 'Set as private reply', 'ama-core' ); ?></label>
93 -
94 - <?php endif; ?>
95 -
96 - </p>
82 + <div class="frmx-option-row">
83 + <div class="frmx-option-icon frmx-option-icon--private">
84 + <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg>
85 + </div>
86 + <label for="bbp_private_reply" class="frmx-option-label">
87 + <?php if ( bbp_is_reply_edit() && ( get_the_author_meta( 'ID' ) != bbp_get_current_user_id() ) ) : ?>
88 + <span class="frmx-option-title"><?php esc_html_e( 'Private reply', 'forumax' ); ?></span>
89 + <span class="frmx-option-desc"><?php esc_html_e( "Set author's post as private", 'forumax' ); ?></span>
90 + <?php else : ?>
91 + <span class="frmx-option-title"><?php esc_html_e( 'Set as private reply', 'forumax' ); ?></span>
92 + <span class="frmx-option-desc"><?php esc_html_e( 'Only visible to moderators and topic author', 'forumax' ); ?></span>
93 + <?php endif; ?>
94 + </label>
95 + <label class="frmx-toggle" for="bbp_private_reply">
96 + <input name="bbp_private_reply" id="bbp_private_reply" type="checkbox"<?php checked( '1', $this->is_private( bbp_get_reply_id() ) ); ?> value="1" tabindex="<?php bbp_tab_index(); ?>" />
97 + <span class="frmx-toggle-slider"></span>
98 + </label>
99 + </div>
97 100 <?php
98 101
99 102 }
100 103
@@ -159,8 +162,45 @@
159 162 }
160 163
161 164
162 165 /**
166 + * Determines if the current user can view a private reply.
167 + *
168 + * @since 1.0
169 + *
170 + * @param int $reply_id The ID of the reply.
171 + * @return bool
172 + */
173 + public function can_view_private_reply( $reply_id = 0 ) {
174 +
175 + if ( empty( $reply_id ) ) {
176 + $reply_id = bbp_get_reply_id( $reply_id );
177 + }
178 +
179 + $current_user = is_user_logged_in() ? wp_get_current_user() : false;
180 + $topic_author = bbp_get_topic_author_id( bbp_get_reply_topic_id( $reply_id ) );
181 + $reply_author = bbp_get_reply_author_id( $reply_id );
182 +
183 + if ( ! empty( $current_user ) && $topic_author === $current_user->ID && user_can( $reply_author, $this->capability ) ) {
184 + // Let the thread author view replies if the reply author is from a moderator.
185 + return true;
186 + }
187 +
188 + if ( ! empty( $current_user ) && $reply_author === $current_user->ID ) {
189 + // Let the reply author view their own reply.
190 + return true;
191 + }
192 +
193 + if ( current_user_can( $this->capability ) ) {
194 + // Let moderators view all replies.
195 + return true;
196 + }
197 +
198 + return false;
199 + }
200 +
201 +
202 + /**
163 203 * Hides the reply content for users that do not have permission to view it
164 204 *
165 205 * @since 1.0
166 206 *
@@ -180,34 +220,11 @@
180 220 $reply_id = bbp_get_reply_id( $reply_id );
181 221 }
182 222
183 223 if ( $this->is_private( $reply_id ) ) {
184 -
185 - $can_view = false;
186 - $current_user = is_user_logged_in() ? wp_get_current_user() : false;
187 - $topic_author = bbp_get_topic_author_id();
188 - $reply_author = bbp_get_reply_author_id( $reply_id );
189 -
190 - if ( ! empty( $current_user ) && $topic_author === $current_user->ID && user_can( $reply_author, $this->capability ) ) {
191 - // Let the thread author view replies if the reply author is from a moderator
192 - $can_view = true;
224 + if ( ! $this->can_view_private_reply( $reply_id ) ) {
225 + $content = '<div class="alert alert-danger">' . esc_html__( 'This reply has been marked as private.', 'forumax' ) . '</div>';
193 226 }
194 -
195 - if ( ! empty( $current_user ) && $reply_author === $current_user->ID ) {
196 - // Let the reply author view their own reply
197 - $can_view = true;
198 - }
199 -
200 - if ( current_user_can( $this->capability ) ) {
201 - // Let moderators view all replies
202 - $can_view = true;
203 - }
204 -
205 - if ( ! $can_view ) {
206 - $content = '<div class="alert alert-danger">' . esc_html__( 'This reply has been marked as private.', 'ama-core' ) . '</div>';
207 - } else {
208 - $content = '<div class="alert alert-info">' . esc_html__( 'This is a private reply.', 'ama-core' ) . '</div>' . $content;
209 - }
210 227 }
211 228
212 229 return $content;
213 230 }
@@ -258,20 +275,19 @@
258 275 $reply_author = bbp_get_reply_author_id( $reply_id );
259 276 $reply_author_name = bbp_get_reply_author_display_name( $reply_id );
260 277
261 278 // Strip tags from text and setup mail data
262 - $topic_title = strip_tags( bbp_get_topic_title( $topic_id ) );
263 - $reply_content = strip_tags( bbp_get_reply_content( $reply_id ) );
279 + $topic_title = wp_strip_all_tags( bbp_get_topic_title( $topic_id ) );
280 + $reply_content = wp_strip_all_tags( bbp_get_reply_content( $reply_id ) );
264 281 $reply_url = bbp_get_reply_url( $reply_id );
265 282 $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
283 + $subject = apply_filters( 'bbp_subscription_mail_title', '[' . $blog_name . '] ' . $topic_title, $reply_id, $topic_id );
266 284
267 - $subject = apply_filters( 'bbp_subscription_mail_title', '[' . $blog_name . '] ' . $topic_title, $reply_id, $topic_id );
268 -
269 285 // Array to hold BCC's
270 - $headers = [];
286 + $headers = [];
271 287
272 288 // Setup the From header
273 - $headers[] = 'From: ' . get_bloginfo( 'name' ) . ' <' . $this->get_no_reply() . '>';
289 + $headers[] = 'From: ' . get_bloginfo( 'name' ) . ' <' . $this->get_no_reply() . '>';
274 290
275 291 // Get topic subscribers and bail if empty
276 292 $user_ids = bbp_get_topic_subscribers( $topic_id, true );
277 293 if ( empty( $user_ids ) ) {
@@ -332,6 +348,6 @@
332 348
333 349 } // end class
334 350
335 351 // instantiate our plugin's class.
336 -$GLOBALS['bbp_private_replies'] = new BBP_Private_Replies();
352 +$GLOBALS['bbp_private_replies'] = new Forumax_Private_Replies();
337 353 ?>