PluginProbe
WP Discourse / trunk
WP Discourse vtrunk
2.6.4 2.6.3 1.2.1 1.2.2 1.2.5 1.2.6 1.2.7 1.2.8 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.85 1.4.0 1.4.15 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 All 150 releases
wp-discourse / admin / comment-settings.php

comment-settings.php in WP Discourse trunk, at admin/comment-settings.php

509 lines 14.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Commenting Settings.
4 *
5 * @package WPDiscourse
6 */
7
8 namespace WPDiscourse\Admin;
9
10 use WPDiscourse\Shared\PluginUtilities;
11
12 /**
13 * Class CommentSettings
14 */
15 class CommentSettings {
16 use PluginUtilities;
17
18 /**
19 * An instance of the FormHelper class.
20 *
21 * @access protected
22 * @var \WPDiscourse\Admin\FormHelper
23 */
24 protected $form_helper;
25
26 /**
27 * Gives access to the plugin options.
28 *
29 * @access protected
30 * @var array|void
31 */
32 protected $options;
33
34 /**
35 * CommentSettings constructor.
36 *
37 * @param \WPDiscourse\Admin\FormHelper $form_helper An instance of the FormHelper class.
38 */
39 public function __construct( $form_helper ) {
40 $this->form_helper = $form_helper;
41
42 add_action( 'admin_init', array( $this, 'register_comment_settings' ) );
43 }
44
45 /**
46 * Add settings section, settings fields, and register the setting.
47 */
48 public function register_comment_settings() {
49 $this->options = $this->get_options();
50 $use_network_comment_settings = is_multisite() && ! empty( $this->options['multisite-configuration-enabled'] );
51
52 add_settings_section(
53 'discourse_commenting_settings_section',
54 __( 'Comment Settings', 'wp-discourse' ),
55 array(
56 $this,
57 'commenting_settings_tab_details',
58 ),
59 'discourse_comment'
60 );
61
62 add_settings_field(
63 'discourse_enable_discourse_comments',
64 __( 'Enable Discourse Comments', 'wp-discourse' ),
65 array(
66 $this,
67 'enable_discourse_comments_checkbox',
68 ),
69 'discourse_comment',
70 'discourse_commenting_settings_section'
71 );
72
73 add_settings_field(
74 'discourse_ajax_load',
75 __( 'Load Comments With Ajax', 'wp-discourse' ),
76 array(
77 $this,
78 'ajax_load_checkbox',
79 ),
80 'discourse_comment',
81 'discourse_commenting_settings_section'
82 );
83
84 add_settings_field(
85 'discourse_load_comment_css',
86 __( 'Load Comment CSS', 'wp-discourse' ),
87 array(
88 $this,
89 'load_comment_css_checkbox',
90 ),
91 'discourse_comment',
92 'discourse_commenting_settings_section'
93 );
94
95 add_settings_field(
96 'discourse_new_tab',
97 __( 'Open Links in New Tab', 'wp-discourse' ),
98 array(
99 $this,
100 'discourse_new_tab_checkbox',
101 ),
102 'discourse_comment',
103 'discourse_commenting_settings_section'
104 );
105
106 add_settings_field(
107 'discourse_hide_wordpress_comments',
108 __( 'Remove WordPress Comments Template', 'wp-discourse' ),
109 array(
110 $this,
111 'discourse_hide_wordpress_comments_checkbox',
112 ),
113 'discourse_comment',
114 'discourse_commenting_settings_section'
115 );
116
117 add_settings_field(
118 'discourse_show_existing_comments',
119 __( 'Show Existing WP Comments', 'wp-discourse' ),
120 array(
121 $this,
122 'show_existing_comments_checkbox',
123 ),
124 'discourse_comment',
125 'discourse_commenting_settings_section'
126 );
127
128 add_settings_field(
129 'discourse_existing_comments_heading',
130 __( 'Existing Comments Heading', 'wp-discourse' ),
131 array(
132 $this,
133 'existing_comments_heading_input',
134 ),
135 'discourse_comment',
136 'discourse_commenting_settings_section'
137 );
138
139 add_settings_field(
140 'discourse_max_comments',
141 __( 'Max Visible Comments', 'wp-discourse' ),
142 array(
143 $this,
144 'max_comments_input',
145 ),
146 'discourse_comment',
147 'discourse_commenting_settings_section'
148 );
149
150 add_settings_field(
151 'discourse_min_replies',
152 __( 'Min Number of Replies', 'wp-discourse' ),
153 array(
154 $this,
155 'min_replies_input',
156 ),
157 'discourse_comment',
158 'discourse_commenting_settings_section'
159 );
160
161 add_settings_field(
162 'discourse_min_score',
163 __( 'Min Score of Posts', 'wp-discourse' ),
164 array(
165 $this,
166 'min_score_input',
167 ),
168 'discourse_comment',
169 'discourse_commenting_settings_section'
170 );
171
172 add_settings_field(
173 'discourse_min_trust_level',
174 __( 'Min Trust Level', 'wp-discourse' ),
175 array(
176 $this,
177 'min_trust_level_input',
178 ),
179 'discourse_comment',
180 'discourse_commenting_settings_section'
181 );
182
183 add_settings_field(
184 'discourse_bypass_trust_level_score',
185 __( 'Bypass Trust Level Score', 'wp-discourse' ),
186 array(
187 $this,
188 'bypass_trust_level_input',
189 ),
190 'discourse_comment',
191 'discourse_commenting_settings_section'
192 );
193
194 add_settings_field(
195 'discourse_only_show_moderator_liked',
196 __( 'Only Import Moderator-Liked', 'wp-discourse' ),
197 array(
198 $this,
199 'only_show_moderator_liked_checkbox',
200 ),
201 'discourse_comment',
202 'discourse_commenting_settings_section'
203 );
204
205 add_settings_field(
206 'discourse_custom_datetime_format',
207 __( 'Custom Datetime Format', 'wp-discourse' ),
208 array(
209 $this,
210 'custom_datetime_format',
211 ),
212 'discourse_comment',
213 'discourse_commenting_settings_section'
214 );
215
216 add_settings_field(
217 'discourse_cache_html',
218 __( 'Cache Comment HTML', 'wp-discourse' ),
219 array(
220 $this,
221 'cache_html_checkbox',
222 ),
223 'discourse_comment',
224 'discourse_commenting_settings_section'
225 );
226
227 add_settings_field(
228 'discourse_clear_cached_comment_html',
229 __( 'Clear Cached Comment HTML', 'wp-discourse' ),
230 array(
231 $this,
232 'clear_cached_comment_html_checkbox',
233 ),
234 'discourse_comment',
235 'discourse_commenting_settings_section'
236 );
237
238 if ( ! $use_network_comment_settings ) {
239 add_settings_field(
240 'discourse_verbose_comment_logs',
241 __( 'Verbose Comment Logs', 'wp-discourse' ),
242 array(
243 $this,
244 'verbose_comment_logs',
245 ),
246 'discourse_comment',
247 'discourse_commenting_settings_section'
248 );
249 }
250
251 register_setting(
252 'discourse_comment',
253 'discourse_comment',
254 array(
255 $this->form_helper,
256 'validate_options',
257 )
258 );
259 }
260
261 /**
262 * Outputs markup for the enable-discourse-comments settings.
263 */
264 public function enable_discourse_comments_checkbox() {
265 $comment_type = $this->options['comment-type'];
266 $hide_radio = empty( $this->options['enable-discourse-comments'] );
267 $this->form_helper->checkbox_input( 'enable-discourse-comments', 'discourse_comment', __( 'Display Discourse comments or a link to the comments on WordPress.', 'wp-discourse' ) );
268
269 ?>
270 <div class="discourse-comment-type
271 <?php
272 if ( $hide_radio ) {
273 esc_attr_e( ' hidden' ); }
274 ?>
275 ">
276 <label for="display-comments">
277 <input type="radio" name="discourse_comment[comment-type]" value="display-comments" <?php checked( 'display-comments', $comment_type ); ?>>
278 <?php esc_html_e( 'Display comments for all topics', 'wp-discourse' ); ?>
279 </label><br>
280 <label for="display-public-comments-only">
281 <input type="radio" name="discourse_comment[comment-type]" value="display-public-comments-only" <?php checked( 'display-public-comments-only', $comment_type ); ?>>
282 <?php esc_html_e( 'Display comments for public topics. Display a link for private topics.', 'wp-discourse' ); ?>
283 </label><br>
284 <label for="display-comments-link">
285 <input type="radio" name="discourse_comment[comment-type]" value="display-comments-link" <?php checked( 'display-comments-link', $comment_type ); ?>>
286 <?php esc_html_e( 'Display a link to the comments', 'wp-discourse' ); ?>
287 </label>
288 </div>
289 <?php
290 }
291
292 /**
293 * Outputs markup for the cache-html checkbox.
294 */
295 public function cache_html_checkbox() {
296 $this->form_helper->checkbox_input(
297 'cache-html',
298 'discourse_comment',
299 __(
300 'Cache the Discourse comment HTML that is generated by the plugin.',
301 'wp-discourse'
302 )
303 );
304 }
305
306 /**
307 * Outputs markup for the clear-cached-comment-html checkbox.
308 */
309 public function clear_cached_comment_html_checkbox() {
310 $this->form_helper->checkbox_input(
311 'clear-cached-comment-html',
312 'discourse_comment',
313 __(
314 'Selecting this option will clear all cached comment HTML.',
315 'wp-discourse'
316 ),
317 __( 'Only enabled for a single request.', 'wp-discourse' )
318 );
319 }
320
321 /**
322 * Outputs markup for the discourse_verbose_comment_logs checkbox.
323 */
324 public function verbose_comment_logs() {
325 $this->form_helper->checkbox_input(
326 'verbose-comment-logs',
327 'discourse_comment',
328 __(
329 'Enable verbose logs for comments.',
330 'wp-discourse'
331 ),
332 __( 'Will log successful operations as well as errors.', 'wp-discourse' ) . ' View logs in the <a href="?page=wp_discourse_options&tab=log_viewer">' . __( 'Log Viewer', 'wp-discourse' ) . '</a>.'
333 );
334 }
335
336 /**
337 * Outputs markup for the discourse-new-tab checkbox.
338 */
339 public function ajax_load_checkbox() {
340 $this->form_helper->checkbox_input(
341 'ajax-load',
342 'discourse_comment',
343 __( 'Load comments with Ajax.', 'wp-discourse' ),
344 __(
345 'This is useful if page caching is preventing Discourse comments from updating on WordPress. When this setting is enabled, old WordPress comments
346 cannot be displayed beneath the Discourse comments.',
347 'wp-discourse'
348 )
349 );
350 }
351
352 /**
353 * Outputs markup for the load-comment-css checkbox.
354 */
355 public function load_comment_css_checkbox() {
356 $this->form_helper->checkbox_input(
357 'load-comment-css',
358 'discourse_comment',
359 __( 'Loads a CSS file for styling comments', 'wp-discourse' ),
360 __( 'This is currently adding styles to Discourse oneboxes and quotes.', 'wp-discourse' )
361 );
362 }
363
364 /**
365 * Outputs markup for the discourse-new-tab checkbox.
366 */
367 public function discourse_new_tab_checkbox() {
368 $this->form_helper->checkbox_input(
369 'discourse-new-tab',
370 'discourse_comment',
371 __( 'Open links to Discourse in a new tab.', 'wp-discourse' )
372 );
373 }
374
375 /**
376 * Outputs markup for the discourse-hide-wordpress comments checkbox.
377 */
378 public function discourse_hide_wordpress_comments_checkbox() {
379 $this->form_helper->checkbox_input(
380 'hide-wordpress-comments',
381 'discourse_comment',
382 __( 'Do not load the WordPress comments template for posts that are not Published to Discourse.', 'wp-discourse' ),
383 __(
384 'The WP Discourse plugin requires comments to be enabled in order to display Discourse comments.
385 Enable this setting to keep the WordPress comment area from appearing beneath posts that have not been published to Discourse.',
386 'wp-discourse'
387 )
388 );
389 }
390
391 /**
392 * Outputs markup for the show-existing-comments checkbox.
393 */
394 public function show_existing_comments_checkbox() {
395 $this->form_helper->checkbox_input( 'show-existing-comments', 'discourse_comment', __( 'Display existing WordPress comments beneath Discourse comments.', 'wp-discourse' ) );
396 }
397
398 /**
399 * Outputs markup for the existing-comments-heading input.
400 */
401 public function existing_comments_heading_input() {
402 $this->form_helper->input( 'existing-comments-heading', 'discourse_comment', __( 'Heading for existing WordPress comments (for example, "Historical Comment Archive".)', 'wp-discourse' ) );
403 }
404
405 /**
406 * Outputs markup for the max-comments input.
407 */
408 public function max_comments_input() {
409 $this->form_helper->input(
410 'max-comments',
411 'discourse_comment',
412 __(
413 "Maximum number of comments to display. To display a link to the Discourse
414 topic, without displaying comments on WordPress, set 'max visible comments' to 0.",
415 'wp-discourse'
416 ),
417 'number',
418 0
419 );
420 }
421
422 /**
423 * Outputs markup for the min-replies input.
424 */
425 public function min_replies_input() {
426 $this->form_helper->input( 'min-replies', 'discourse_comment', __( 'Minimum replies required prior to pulling comments across.', 'wp-discourse' ), 'number', 0 );
427 }
428
429 /**
430 * Outputs markup for the min-score input.
431 */
432 public function min_score_input() {
433 $this->form_helper->input( 'min-score', 'discourse_comment', __( 'Minimum score required prior to pulling comments across (score = 15 points per like, 5 per reply, 5 per incoming link, 0.2 per read.)', 'wp-discourse' ), 'number', 0 );
434 }
435
436 /**
437 * Outputs markup for the min-trust-level input.
438 */
439 public function min_trust_level_input() {
440 $this->form_helper->input(
441 'min-trust-level',
442 'discourse_comment',
443 __(
444 'Minimum Discourse user trust level required
445 for comments that are pulled to WordPress. (Trust levels range between 0 and 5.)',
446 'wp-discourse'
447 ),
448 'number',
449 0,
450 5
451 );
452 }
453
454 /**
455 * Outputs markup for the bypass-trust-level input.
456 */
457 public function bypass_trust_level_input() {
458 $this->form_helper->input( 'bypass-trust-level-score', 'discourse_comment', __( 'Bypass trust level check on posts with this score.', 'wp-discourse' ), 'number', 0 );
459 }
460
461 /**
462 * Outputs markup for the custom-datetime input.
463 */
464 public function custom_datetime_format() {
465 $this->form_helper->input(
466 'custom-datetime-format',
467 'discourse_comment',
468 __( 'The datetime format used for displaying the comment date/time. (default: "', 'wp-discourse' ) .
469 get_option( 'date_format' ) . '").' .
470 __( ' See ', 'wp-discourse' ) . '<a href="https://codex.wordpress.org/Formatting_Date_and_Time" target="_blank" rel="noreferrer noopener">' .
471 __( 'this page', 'wp-discourse' ) . '</a>' . __( ' for more information.', 'wp-discourse' )
472 );
473 }
474
475 /**
476 * Outputs markup for the only-show-moderator-liked checkbox.
477 */
478 public function only_show_moderator_liked_checkbox() {
479 $this->form_helper->checkbox_input( 'only-show-moderator-liked', 'discourse_comment', __( "Only import comments 'liked' by a Discourse moderator.", 'wp-discourse' ) );
480 }
481
482 /**
483 * Details for the 'commenting_options' tab.
484 */
485 public function commenting_settings_tab_details() {
486 $setup_howto_url = 'https://meta.discourse.org/t/wp-discourse-plugin-installation-and-setup/50752';
487 $discourse_meta_url = 'https://meta.discourse.org/';
488 $template_customization_url = 'https://meta.discourse.org/t/wp-discourse-template-customization/50754';
489 ?>
490 <p class="wpdc-options-documentation">
491 <em><?php esc_html_e( 'This section is for configuring how Discourse comments are displayed on your WordPress site.', 'wp-discourse' ); ?></em>
492 </p>
493 <p class="wpdc-options-documentation">
494 <em>
495 <?php esc_html_e( 'For detailed instructions, see the ', 'wp-discourse' ); ?>
496 <a href="<?php echo esc_url( $setup_howto_url ); ?>"
497 target="_blank" rel="noreferrer noopener"><?php esc_html_e( 'WP Discourse plugin installation and setup', 'wp-discourse' ); ?></a>
498 <?php esc_html_e( 'and', 'wp-discourse' ); ?>
499 <a href="<?php echo esc_url( $template_customization_url ); ?>"
500 target="_blank" rel="noreferrer noopener"><?php esc_html_e( 'WP Discourse template customization', 'wp-discourse' ); ?></a>
501 <?php esc_html_e( 'topics on the ', 'wp-discourse' ); ?>
502 <a href="<?php echo esc_url( $discourse_meta_url ); ?>" target="_blank" rel="noreferrer noopener">Discourse Meta</a>
503 <?php esc_html_e( 'forum.', 'wp-discourse' ); ?>
504 </em>
505 </p>
506 <?php
507 }
508 }
509