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-private-replies.php +65 -42 1.4.1 → 2.5.1 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,22 +78,26 @@
78 78 */
79 79 public function checkbox() {
80 80
81 81 ?>
82 - <p>
83 - <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(); ?>" />
84 -
85 - <?php if ( bbp_is_reply_edit() && ( get_the_author_meta( 'ID' ) != bbp_get_current_user_id() ) ) : ?>
86 -
87 - <label for="bbp_private_reply"><?php esc_html_e( "Set author's post as private.", 'bbp-core' ); ?></label>
88 -
89 - <?php else : ?>
90 -
91 - <label for="bbp_private_reply"><?php esc_html_e( 'Set as private reply', 'bbp-core' ); ?></label>
92 -
93 - <?php endif; ?>
94 -
95 - </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>
96 100 <?php
97 101
98 102 }
99 103
@@ -158,8 +162,45 @@
158 162 }
159 163
160 164
161 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 + /**
162 203 * Hides the reply content for users that do not have permission to view it
163 204 *
164 205 * @since 1.0
165 206 *
@@ -178,35 +219,17 @@
178 219 if ( empty( $reply_id ) ) {
179 220 $reply_id = bbp_get_reply_id( $reply_id );
180 221 }
181 222
223 + // the_content/the_excerpt run for every post; only replies can be private.
224 + if ( empty( $reply_id ) ) {
225 + return $content;
226 + }
227 +
182 228 if ( $this->is_private( $reply_id ) ) {
183 -
184 - $can_view = false;
185 - $current_user = is_user_logged_in() ? wp_get_current_user() : false;
186 - $topic_author = bbp_get_topic_author_id();
187 - $reply_author = bbp_get_reply_author_id( $reply_id );
188 -
189 - if ( ! empty( $current_user ) && $topic_author === $current_user->ID && user_can( $reply_author, $this->capability ) ) {
190 - // Let the thread author view replies if the reply author is from a moderator
191 - $can_view = true;
229 + if ( ! $this->can_view_private_reply( $reply_id ) ) {
230 + $content = '<div class="alert alert-danger">' . esc_html__( 'This reply has been marked as private.', 'forumax' ) . '</div>';
192 231 }
193 -
194 - if ( ! empty( $current_user ) && $reply_author === $current_user->ID ) {
195 - // Let the reply author view their own reply
196 - $can_view = true;
197 - }
198 -
199 - if ( current_user_can( $this->capability ) ) {
200 - // Let moderators view all replies
201 - $can_view = true;
202 - }
203 -
204 - if ( ! $can_view ) {
205 - $content = '<div class="alert alert-danger">' . esc_html__( 'This reply has been marked as private.', 'bbp-core' ) . '</div>';
206 - } else {
207 - $content = '<div class="alert alert-warning">' . esc_html__( 'This is a private reply.', 'bbp-core' ) . '</div>' . $content;
208 - }
209 232 }
210 233
211 234 return $content;
212 235 }
@@ -330,6 +353,6 @@
330 353
331 354 } // end class
332 355
333 356 // instantiate our plugin's class.
334 -$GLOBALS['bbp_private_replies'] = new BBP_Private_Replies();
357 +$GLOBALS['bbp_private_replies'] = new Forumax_Private_Replies();
335 358 ?>