Skip to content

Commit 78a56b2

Browse files
author
Luke Carbis
committed
Give Settings connector a labels property, only track WP CLI if it has a known setting
1 parent e566e7b commit 78a56b2

File tree

1 file changed

+114
-107
lines changed

1 file changed

+114
-107
lines changed

connectors/class-connector-settings.php

Lines changed: 114 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ class Connector_Settings extends Connector {
3030
'update_option_tag_base',
3131
);
3232

33+
/**
34+
* Labels used for WordPress Settings
35+
*
36+
* @var array
37+
*/
38+
public $labels = array();
39+
3340
/**
3441
* Option names used in options-permalink.php
3542
*
@@ -82,6 +89,109 @@ class Connector_Settings extends Connector {
8289
public function register() {
8390
parent::register();
8491

92+
$this->labels = array(
93+
// General
94+
'blogname' => esc_html__( 'Site Title', 'stream' ),
95+
'blogdescription' => esc_html__( 'Tagline', 'stream' ),
96+
'admin_email' => esc_html__( 'E-mail Address', 'stream' ),
97+
'new_admin_email' => esc_html__( 'E-mail Address', 'stream' ),
98+
'siteurl' => esc_html__( 'WordPress Address (URL)', 'stream' ),
99+
'home' => esc_html__( 'Site Address (URL)', 'stream' ),
100+
'users_can_register' => esc_html__( 'Membership', 'stream' ),
101+
'default_role' => esc_html__( 'New User Default Role', 'stream' ),
102+
'timezone_string' => esc_html__( 'Timezone', 'stream' ),
103+
'date_format' => esc_html__( 'Date Format', 'stream' ),
104+
'time_format' => esc_html__( 'Time Format', 'stream' ),
105+
'start_of_week' => esc_html__( 'Week Starts On', 'stream' ),
106+
// Writing
107+
'use_smilies' => esc_html__( 'Formatting', 'stream' ),
108+
'use_balanceTags' => esc_html__( 'Formatting', 'stream' ),
109+
'default_category' => esc_html__( 'Default Post Category', 'stream' ),
110+
'default_post_format' => esc_html__( 'Default Post Format', 'stream' ),
111+
'mailserver_url' => esc_html__( 'Mail Server', 'stream' ),
112+
'mailserver_login' => esc_html__( 'Login Name', 'stream' ),
113+
'mailserver_pass' => esc_html__( 'Password', 'stream' ),
114+
'default_email_category' => esc_html__( 'Default Mail Category', 'stream' ),
115+
'ping_sites' => esc_html__( 'Update Services', 'stream' ),
116+
// Reading
117+
'show_on_front' => esc_html__( 'Front page displays', 'stream' ),
118+
'page_on_front' => esc_html__( 'Front page displays', 'stream' ),
119+
'page_for_posts' => esc_html__( 'Front page displays', 'stream' ),
120+
'posts_per_page' => esc_html__( 'Blog pages show at most', 'stream' ),
121+
'posts_per_rss' => esc_html__( 'Syndication feeds show the most recent', 'stream' ),
122+
'rss_use_excerpt' => esc_html__( 'For each article in a feed, show', 'stream' ),
123+
'blog_public' => esc_html__( 'Search Engine Visibility', 'stream' ),
124+
// Discussion
125+
'default_pingback_flag' => esc_html__( 'Default article settings', 'stream' ),
126+
'default_ping_status' => esc_html__( 'Default article settings', 'stream' ),
127+
'default_comment_status' => esc_html__( 'Default article settings', 'stream' ),
128+
'require_name_email' => esc_html__( 'Other comment settings', 'stream' ),
129+
'comment_registration' => esc_html__( 'Other comment settings', 'stream' ),
130+
'close_comments_for_old_posts' => esc_html__( 'Other comment settings', 'stream' ),
131+
'close_comments_days_old' => esc_html__( 'Other comment settings', 'stream' ),
132+
'thread_comments' => esc_html__( 'Other comment settings', 'stream' ),
133+
'thread_comments_depth' => esc_html__( 'Other comment settings', 'stream' ),
134+
'page_comments' => esc_html__( 'Other comment settings', 'stream' ),
135+
'comments_per_page' => esc_html__( 'Other comment settings', 'stream' ),
136+
'default_comments_page' => esc_html__( 'Other comment settings', 'stream' ),
137+
'comment_order' => esc_html__( 'Other comment settings', 'stream' ),
138+
'comments_notify' => esc_html__( 'E-mail me whenever', 'stream' ),
139+
'moderation_notify' => esc_html__( 'E-mail me whenever', 'stream' ),
140+
'comment_moderation' => esc_html__( 'Before a comment appears', 'stream' ),
141+
'comment_whitelist' => esc_html__( 'Before a comment appears', 'stream' ),
142+
'comment_max_links' => esc_html__( 'Comment Moderation', 'stream' ),
143+
'moderation_keys' => esc_html__( 'Comment Moderation', 'stream' ),
144+
'blacklist_keys' => esc_html__( 'Comment Blacklist', 'stream' ),
145+
'show_avatars' => esc_html__( 'Show Avatars', 'stream' ),
146+
'avatar_rating' => esc_html__( 'Maximum Rating', 'stream' ),
147+
'avatar_default' => esc_html__( 'Default Avatar', 'stream' ),
148+
// Media
149+
'thumbnail_size_w' => esc_html__( 'Thumbnail size', 'stream' ),
150+
'thumbnail_size_h' => esc_html__( 'Thumbnail size', 'stream' ),
151+
'thumbnail_crop' => esc_html__( 'Thumbnail size', 'stream' ),
152+
'medium_size_w' => esc_html__( 'Medium size', 'stream' ),
153+
'medium_size_h' => esc_html__( 'Medium size', 'stream' ),
154+
'large_size_w' => esc_html__( 'Large size', 'stream' ),
155+
'large_size_h' => esc_html__( 'Large size', 'stream' ),
156+
'uploads_use_yearmonth_folders' => esc_html__( 'Uploading Files', 'stream' ),
157+
// Permalinks
158+
'permalink_structure' => esc_html__( 'Permalink Settings', 'stream' ),
159+
'category_base' => esc_html__( 'Category base', 'stream' ),
160+
'tag_base' => esc_html__( 'Tag base', 'stream' ),
161+
// Network
162+
'registrationnotification' => esc_html__( 'Registration notification', 'stream' ),
163+
'registration' => esc_html__( 'Allow new registrations', 'stream' ),
164+
'add_new_users' => esc_html__( 'Add New Users', 'stream' ),
165+
'menu_items' => esc_html__( 'Enable administration menus', 'stream' ),
166+
'upload_space_check_disabled' => esc_html__( 'Site upload space check', 'stream' ),
167+
'blog_upload_space' => esc_html__( 'Site upload space', 'stream' ),
168+
'upload_filetypes' => esc_html__( 'Upload file types', 'stream' ),
169+
'site_name' => esc_html__( 'Network Title', 'stream' ),
170+
'first_post' => esc_html__( 'First Post', 'stream' ),
171+
'first_page' => esc_html__( 'First Page', 'stream' ),
172+
'first_comment' => esc_html__( 'First Comment', 'stream' ),
173+
'first_comment_url' => esc_html__( 'First Comment URL', 'stream' ),
174+
'first_comment_author' => esc_html__( 'First Comment Author', 'stream' ),
175+
'welcome_email' => esc_html__( 'Welcome Email', 'stream' ),
176+
'welcome_user_email' => esc_html__( 'Welcome User Email', 'stream' ),
177+
'fileupload_maxk' => esc_html__( 'Max upload file size', 'stream' ),
178+
'global_terms_enabled' => esc_html__( 'Terms Enabled', 'stream' ),
179+
'illegal_names' => esc_html__( 'Banned Names', 'stream' ),
180+
'limited_email_domains' => esc_html__( 'Limited Email Registrations', 'stream' ),
181+
'banned_email_domains' => esc_html__( 'Banned Email Domains', 'stream' ),
182+
'WPLANG' => esc_html__( 'Network Language', 'stream' ),
183+
'blog_count' => esc_html__( 'Blog Count', 'stream' ),
184+
'user_count' => esc_html__( 'User Count', 'stream' ),
185+
// Other
186+
'wp_stream_db' => esc_html__( 'Stream Database Version', 'stream' ),
187+
);
188+
189+
// These option labels are special and need to change based on multisite context
190+
if ( is_network_admin() ) {
191+
$this->labels['admin_email'] = esc_html__( 'Network Admin Email', 'stream' );
192+
$this->labels['new_admin_email'] = esc_html__( 'Network Admin Email', 'stream' );
193+
}
194+
85195
add_action( 'admin_head', array( $this, 'highlight_field' ) );
86196
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_jquery_color' ) );
87197
add_action( sprintf( 'update_option_theme_mods_%s', get_option( 'stylesheet' ) ), array( $this, 'log_theme_modification' ), 10, 2 );
@@ -238,111 +348,8 @@ public function is_key_option_group( $key, $old_value, $value ) {
238348
* @return array Field label translations
239349
*/
240350
public function get_field_label( $field_key ) {
241-
$labels = array(
242-
// General
243-
'blogname' => esc_html__( 'Site Title', 'stream' ),
244-
'blogdescription' => esc_html__( 'Tagline', 'stream' ),
245-
'admin_email' => esc_html__( 'E-mail Address', 'stream' ),
246-
'new_admin_email' => esc_html__( 'E-mail Address', 'stream' ),
247-
'siteurl' => esc_html__( 'WordPress Address (URL)', 'stream' ),
248-
'home' => esc_html__( 'Site Address (URL)', 'stream' ),
249-
'users_can_register' => esc_html__( 'Membership', 'stream' ),
250-
'default_role' => esc_html__( 'New User Default Role', 'stream' ),
251-
'timezone_string' => esc_html__( 'Timezone', 'stream' ),
252-
'date_format' => esc_html__( 'Date Format', 'stream' ),
253-
'time_format' => esc_html__( 'Time Format', 'stream' ),
254-
'start_of_week' => esc_html__( 'Week Starts On', 'stream' ),
255-
// Writing
256-
'use_smilies' => esc_html__( 'Formatting', 'stream' ),
257-
'use_balanceTags' => esc_html__( 'Formatting', 'stream' ),
258-
'default_category' => esc_html__( 'Default Post Category', 'stream' ),
259-
'default_post_format' => esc_html__( 'Default Post Format', 'stream' ),
260-
'mailserver_url' => esc_html__( 'Mail Server', 'stream' ),
261-
'mailserver_login' => esc_html__( 'Login Name', 'stream' ),
262-
'mailserver_pass' => esc_html__( 'Password', 'stream' ),
263-
'default_email_category' => esc_html__( 'Default Mail Category', 'stream' ),
264-
'ping_sites' => esc_html__( 'Update Services', 'stream' ),
265-
// Reading
266-
'show_on_front' => esc_html__( 'Front page displays', 'stream' ),
267-
'page_on_front' => esc_html__( 'Front page displays', 'stream' ),
268-
'page_for_posts' => esc_html__( 'Front page displays', 'stream' ),
269-
'posts_per_page' => esc_html__( 'Blog pages show at most', 'stream' ),
270-
'posts_per_rss' => esc_html__( 'Syndication feeds show the most recent', 'stream' ),
271-
'rss_use_excerpt' => esc_html__( 'For each article in a feed, show', 'stream' ),
272-
'blog_public' => esc_html__( 'Search Engine Visibility', 'stream' ),
273-
// Discussion
274-
'default_pingback_flag' => esc_html__( 'Default article settings', 'stream' ),
275-
'default_ping_status' => esc_html__( 'Default article settings', 'stream' ),
276-
'default_comment_status' => esc_html__( 'Default article settings', 'stream' ),
277-
'require_name_email' => esc_html__( 'Other comment settings', 'stream' ),
278-
'comment_registration' => esc_html__( 'Other comment settings', 'stream' ),
279-
'close_comments_for_old_posts' => esc_html__( 'Other comment settings', 'stream' ),
280-
'close_comments_days_old' => esc_html__( 'Other comment settings', 'stream' ),
281-
'thread_comments' => esc_html__( 'Other comment settings', 'stream' ),
282-
'thread_comments_depth' => esc_html__( 'Other comment settings', 'stream' ),
283-
'page_comments' => esc_html__( 'Other comment settings', 'stream' ),
284-
'comments_per_page' => esc_html__( 'Other comment settings', 'stream' ),
285-
'default_comments_page' => esc_html__( 'Other comment settings', 'stream' ),
286-
'comment_order' => esc_html__( 'Other comment settings', 'stream' ),
287-
'comments_notify' => esc_html__( 'E-mail me whenever', 'stream' ),
288-
'moderation_notify' => esc_html__( 'E-mail me whenever', 'stream' ),
289-
'comment_moderation' => esc_html__( 'Before a comment appears', 'stream' ),
290-
'comment_whitelist' => esc_html__( 'Before a comment appears', 'stream' ),
291-
'comment_max_links' => esc_html__( 'Comment Moderation', 'stream' ),
292-
'moderation_keys' => esc_html__( 'Comment Moderation', 'stream' ),
293-
'blacklist_keys' => esc_html__( 'Comment Blacklist', 'stream' ),
294-
'show_avatars' => esc_html__( 'Show Avatars', 'stream' ),
295-
'avatar_rating' => esc_html__( 'Maximum Rating', 'stream' ),
296-
'avatar_default' => esc_html__( 'Default Avatar', 'stream' ),
297-
// Media
298-
'thumbnail_size_w' => esc_html__( 'Thumbnail size', 'stream' ),
299-
'thumbnail_size_h' => esc_html__( 'Thumbnail size', 'stream' ),
300-
'thumbnail_crop' => esc_html__( 'Thumbnail size', 'stream' ),
301-
'medium_size_w' => esc_html__( 'Medium size', 'stream' ),
302-
'medium_size_h' => esc_html__( 'Medium size', 'stream' ),
303-
'large_size_w' => esc_html__( 'Large size', 'stream' ),
304-
'large_size_h' => esc_html__( 'Large size', 'stream' ),
305-
'uploads_use_yearmonth_folders' => esc_html__( 'Uploading Files', 'stream' ),
306-
// Permalinks
307-
'permalink_structure' => esc_html__( 'Permalink Settings', 'stream' ),
308-
'category_base' => esc_html__( 'Category base', 'stream' ),
309-
'tag_base' => esc_html__( 'Tag base', 'stream' ),
310-
// Network
311-
'registrationnotification' => esc_html__( 'Registration notification', 'stream' ),
312-
'registration' => esc_html__( 'Allow new registrations', 'stream' ),
313-
'add_new_users' => esc_html__( 'Add New Users', 'stream' ),
314-
'menu_items' => esc_html__( 'Enable administration menus', 'stream' ),
315-
'upload_space_check_disabled' => esc_html__( 'Site upload space check', 'stream' ),
316-
'blog_upload_space' => esc_html__( 'Site upload space', 'stream' ),
317-
'upload_filetypes' => esc_html__( 'Upload file types', 'stream' ),
318-
'site_name' => esc_html__( 'Network Title', 'stream' ),
319-
'first_post' => esc_html__( 'First Post', 'stream' ),
320-
'first_page' => esc_html__( 'First Page', 'stream' ),
321-
'first_comment' => esc_html__( 'First Comment', 'stream' ),
322-
'first_comment_url' => esc_html__( 'First Comment URL', 'stream' ),
323-
'first_comment_author' => esc_html__( 'First Comment Author', 'stream' ),
324-
'welcome_email' => esc_html__( 'Welcome Email', 'stream' ),
325-
'welcome_user_email' => esc_html__( 'Welcome User Email', 'stream' ),
326-
'fileupload_maxk' => esc_html__( 'Max upload file size', 'stream' ),
327-
'global_terms_enabled' => esc_html__( 'Terms Enabled', 'stream' ),
328-
'illegal_names' => esc_html__( 'Banned Names', 'stream' ),
329-
'limited_email_domains' => esc_html__( 'Limited Email Registrations', 'stream' ),
330-
'banned_email_domains' => esc_html__( 'Banned Email Domains', 'stream' ),
331-
'WPLANG' => esc_html__( 'Network Language', 'stream' ),
332-
'blog_count' => esc_html__( 'Blog Count', 'stream' ),
333-
'user_count' => esc_html__( 'User Count', 'stream' ),
334-
// Other
335-
'wp_stream_db' => esc_html__( 'Stream Database Version', 'stream' ),
336-
);
337-
338-
// These option labels are special and need to change based on multisite context
339-
if ( is_network_admin() ) {
340-
$labels['admin_email'] = esc_html__( 'Network Admin Email', 'stream' );
341-
$labels['new_admin_email'] = esc_html__( 'Network Admin Email', 'stream' );
342-
}
343-
344-
if ( isset( $labels[ $field_key ] ) ) {
345-
return $labels[ $field_key ];
351+
if ( isset( $this->labels[ $field_key ] ) ) {
352+
return $this->labels[ $field_key ];
346353
}
347354

348355
return $field_key;
@@ -534,7 +541,7 @@ function( $rule ) use ( $submenu, $record ) {
534541
}
535542

536543
/**
537-
* Trigger this connector from WP CLI
544+
* Trigger this connector from WP CLI, only for known Settings
538545
*
539546
* @action update_option
540547
*
@@ -543,7 +550,7 @@ function( $rule ) use ( $submenu, $record ) {
543550
* @param mixed $value
544551
*/
545552
public function callback_update_option( $option, $value, $old_value ) {
546-
if ( defined( '\WP_CLI' ) && \WP_CLI ) {
553+
if ( defined( '\WP_CLI' ) && \WP_CLI && array_key_exists( $option, $this->labels ) ) {
547554
$this->callback_updated_option( $option, $value, $old_value );
548555
}
549556
}

0 commit comments

Comments
 (0)