Skip to content

Commit 53fe220

Browse files
authored
Merge pull request #41 from wpaccessibility/af/add-discussion-page
Add discussion page
2 parents 246dff9 + 0705fe6 commit 53fe220

File tree

3 files changed

+235
-0
lines changed

3 files changed

+235
-0
lines changed

settings-api-enhanced.php

+15
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ function sae_replace_options_permalink() {
8989
exit;
9090
}
9191

92+
/**
93+
* Replaces the Settings > Discussion screen with the plugin variant.
94+
*/
95+
function sae_replace_options_discussion() {
96+
global $title, $parent_file, $submenu_file;
97+
98+
// Ensure submenu item is highlighted correctly.
99+
$submenu_file = 'options-discussion.php';
100+
101+
require_once SAE_ABSPATH . 'wp-admin/options-discussion.php';
102+
103+
exit;
104+
}
105+
92106
/**
93107
* Loads the plugin files.
94108
*/
@@ -110,6 +124,7 @@ function sae_load() {
110124
add_action( 'load-options-reading.php', 'sae_replace_options_reading' );
111125
add_action( 'load-options-media.php', 'sae_replace_options_media' );
112126
add_action( 'load-options-permalink.php', 'sae_replace_options_permalink' );
127+
add_action( 'load-options-discussion.php', 'sae_replace_options_discussion' );
113128
}
114129

115130
sae_load();
+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
<?php
2+
/**
3+
* WordPress Options implementation for Discussion Settings.
4+
*
5+
* @package WordPress
6+
* @subpackage Administration
7+
* @since 4.8.0
8+
*/
9+
10+
/**
11+
* Adds default settings fields for the Discussion Settings page.
12+
*
13+
* @since 4.8.0
14+
*/
15+
function add_settings_fields_options_discussion() {
16+
sae_add_settings_section( 'article', __( 'Default article settings' ), 'settings_section_article_before', 'discussion' );
17+
18+
sae_add_settings_field( 'default_pingback_flag', '', 'checkbox', 'discussion', 'article', array(
19+
'skip_title' => true,
20+
'label' => __( 'Attempt to notify any blogs linked to from the article' ),
21+
) );
22+
23+
sae_add_settings_field( 'default_ping_status', '', 'checkbox', 'discussion', 'article', array(
24+
'skip_title' => true,
25+
'label' => __( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new articles' ),
26+
) );
27+
28+
sae_add_settings_field( 'default_comment_status', '', 'checkbox', 'discussion', 'article', array(
29+
'skip_title' => true,
30+
'label' => __( 'Allow people to post comments on new articles' ),
31+
) );
32+
33+
sae_add_settings_section( 'comment', __( 'Other comment settings' ), null, 'discussion' );
34+
35+
sae_add_settings_field( 'require_name_email', '', 'checkbox', 'discussion', 'comment', array(
36+
'skip_title' => true,
37+
'label' => __( 'Comment author must fill out name and email' ),
38+
) );
39+
40+
if ( ! get_option( 'users_can_register' ) && is_multisite() ) {
41+
sae_add_settings_field( 'comment_registration', '', 'checkbox', 'discussion', 'comment', array(
42+
'skip_title' => true,
43+
'label' => __( 'Users must be registered and logged in to comment' ),
44+
'description' => __( 'Signup has been disabled. Only members of this site can comment.' ),
45+
) );
46+
} else {
47+
sae_add_settings_field( 'comment_registration', '', 'checkbox', 'discussion', 'comment', array(
48+
'skip_title' => true,
49+
'label' => __( 'Users must be registered and logged in to comment' ),
50+
) );
51+
}
52+
53+
sae_add_settings_field( 'close_comments_for_old_posts', '', 'checkbox', 'discussion', 'comment', array(
54+
'skip_title' => true,
55+
'label' => __( 'Automatically close comments on old articles: enter the number of days in the field below' ),
56+
) );
57+
58+
sae_add_settings_field( 'close_comments_days_old', __( 'Number of days after which comments will be automatically closed' ), 'number', 'discussion', 'comment', array(
59+
'input_class' => 'small-text',
60+
'min' => '0',
61+
'step' => '1',
62+
) );
63+
64+
sae_add_settings_field( 'thread_comments', '', 'checkbox', 'discussion', 'comment', array(
65+
'skip_title' => true,
66+
'label' => __( 'Enable threaded (nested) comments: set the number of levels in the field below' ),
67+
) );
68+
69+
/**
70+
* Filters the maximum depth of threaded/nested comments.
71+
*
72+
* @since 2.7.0.
73+
*
74+
* @param int $max_depth The maximum depth of threaded comments. Default 10.
75+
*/
76+
$maxdeep = (int) apply_filters( 'thread_comments_depth_max', 10 );
77+
78+
for ( $depth_index = 2; $depth_index <= $maxdeep; $depth_index++ ) {
79+
$thread_comments_depth_choices[ $depth_index ] = $depth_index;
80+
}
81+
82+
sae_add_settings_field( 'thread_comments_depth', __( 'Nested comments levels deep' ), 'select', 'discussion', 'comment', array(
83+
'choices' => $thread_comments_depth_choices,
84+
) );
85+
86+
sae_add_settings_field( 'page_comments', '', 'checkbox', 'discussion', 'comment', array(
87+
'skip_title' => true,
88+
'label' => __( 'Break comments into pages' ),
89+
) );
90+
91+
sae_add_settings_field( 'comments_per_page', __( 'Number of top level comments per page' ), 'number', 'discussion', 'comment', array(
92+
'input_class' => 'small-text',
93+
'min' => '0',
94+
'step' => '1',
95+
) );
96+
97+
sae_add_settings_field( 'default_comments_page', __( 'Comments page displayed by default' ), 'select', 'discussion', 'comment', array(
98+
'choices' => array(
99+
'newest' => __( 'last page' ),
100+
'oldest' => __( 'first page' ),
101+
)
102+
) );
103+
104+
sae_add_settings_field( 'comment_order', __( 'Comments to display at the top of each page' ), 'select', 'discussion', 'comment', array(
105+
'choices' => array(
106+
'asc' => __( 'older comments' ),
107+
'desc' => __( 'newer comments' ),
108+
)
109+
) );
110+
111+
sae_add_settings_section( 'notifications', __( 'Notifications' ), null, 'discussion' );
112+
113+
sae_add_settings_field( 'comments_notify', '', 'checkbox', 'discussion', 'notifications', array(
114+
'skip_title' => true,
115+
'label' => __( 'Email me when anyone posts a comment' ),
116+
) );
117+
118+
sae_add_settings_field( 'moderation_notify', '', 'checkbox', 'discussion', 'notifications', array(
119+
'skip_title' => true,
120+
'label' => __( 'Email me when a comment is held for moderation' ),
121+
) );
122+
123+
sae_add_settings_section( 'moderation', __( 'Comment moderation' ), null, 'discussion' );
124+
125+
sae_add_settings_field( 'comment_moderation', '', 'checkbox', 'discussion', 'moderation', array(
126+
'skip_title' => true,
127+
'label' => __( 'Before a comment appears, it must be manually approved' ),
128+
) );
129+
130+
sae_add_settings_field( 'comment_whitelist', '', 'checkbox', 'discussion', 'moderation', array(
131+
'skip_title' => true,
132+
'label' => __( 'Before a comment appears, the comment author must have a previously approved comment' ),
133+
) );
134+
135+
sae_add_settings_field( 'comment_max_links', __( 'Number of links in a comment after which it will be held in the moderation queue' ), 'number', 'discussion', 'moderation', array(
136+
'input_class' => 'small-text',
137+
'min' => '0',
138+
'step' => '1',
139+
'description' => __( 'A common characteristic of comment spam is a large number of links.' ),
140+
) );
141+
142+
sae_add_settings_field( 'moderation_keys', __( 'Moderation words' ), 'textarea', 'discussion', 'moderation', array(
143+
'rows' => '10',
144+
'cols' => '50',
145+
'input_class' => 'large-text code',
146+
'description' => sprintf(
147+
__( 'When a comment contains any of these words in its content, name, URL, email, or IP, it will be held in the %1$smoderation queue%2$s. One word or IP per line. It will match inside words, so &#8220;press&#8221; will match &#8220;WordPress&#8221;.' ),
148+
'<a href="edit-comments.php?comment_status=moderated">',
149+
'</a>'
150+
),
151+
) );
152+
153+
sae_add_settings_field( 'blacklist_keys', __( 'Comment blacklist' ), 'textarea', 'discussion', 'moderation', array(
154+
'rows' => '10',
155+
'cols' => '50',
156+
'input_class' => 'large-text code',
157+
'description' => __( 'When a comment contains any of these words in its content, name, URL, email, or IP, it will be put in the trash. One word or IP per line. It will match inside words, so &#8220;press&#8221; will match &#8220;WordPress&#8221;.' )
158+
) );
159+
}
160+
161+
/**
162+
* Settings section callback for the 'thumbnail_size' section.
163+
*
164+
* @since 4.8.0
165+
*/
166+
function settings_section_article_before() {
167+
echo '<p>' . __( 'These settings may be overridden for individual articles.' ) . '</p>';
168+
}

wp-admin/options-discussion.php

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Discussion settings administration panel.
4+
*
5+
* @package WordPress
6+
* @subpackage Administration
7+
*/
8+
9+
/** WordPress Administration Bootstrap */
10+
//require_once( dirname( __FILE__ ) . '/admin.php' );
11+
12+
13+
/** WordPress Options implementation for Discussion Settings */
14+
require_once( SAE_ABSPATH . 'wp-admin/includes/options-discussion.php' );
15+
16+
add_settings_fields_options_discussion();
17+
18+
if ( ! current_user_can( 'manage_options' ) ) {
19+
wp_die( __( 'Sorry, you are not allowed to manage options for this site.' ) );
20+
}
21+
22+
$title = __( 'Discussion Settings' );
23+
$parent_file = 'options-general.php';
24+
25+
get_current_screen()->add_help_tab( array(
26+
'id' => 'overview',
27+
'title' => __('Overview'),
28+
'content' => '<p>' . __( 'This screen provides many options for controlling the management and display of comments and links to your posts/pages. So many, in fact, they won&#8217;t all fit here! :) Use the documentation links to get information on what each discussion setting does.' ) . '</p>' .
29+
'<p>' . __( 'You must click the Save Changes button at the bottom of the screen for new settings to take effect.' ) . '</p>',
30+
));
31+
32+
get_current_screen()->set_help_sidebar(
33+
'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
34+
'<p>' . __( '<a href="https://codex.wordpress.org/Settings_Discussion_Screen">Documentation on Discussion Settings</a>' ) . '</p>' .
35+
'<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>'
36+
);
37+
38+
include( ABSPATH . 'wp-admin/admin-header.php' );
39+
?>
40+
41+
<div class="wrap">
42+
<h1><?php echo esc_html( $title ); ?></h1>
43+
44+
<form method="post" action="options.php">
45+
<?php settings_fields( 'discussion' ); ?>
46+
47+
<?php sae_do_settings_sections( 'discussion' ); ?>
48+
49+
<?php submit_button(); ?>
50+
</form>
51+
</div>
52+
<?php include( ABSPATH . 'wp-admin/admin-footer.php' ); ?>

0 commit comments

Comments
 (0)