Skip to content

Commit ab4fcd2

Browse files
committed
Move ad hoc Options functions to wp-admin/includes/options.php:
* Move `options_discussion_add_js()` from `wp-admin/options-discussion.php` * Move `options_general_add_js()` from `wp-admin/options-general.php` * Move `options_permalink_add_js()` from `wp-admin/options-permalink.php` * Move `options_reading_add_js()` from `wp-admin/options-reading.php` * Move `options_reading_blog_charset()` from `wp-admin/options-reading.php` See #33813. git-svn-id: https://develop.svn.wordpress.org/trunk@34022 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 96a40d6 commit ab4fcd2

File tree

6 files changed

+144
-129
lines changed

6 files changed

+144
-129
lines changed

src/wp-admin/includes/admin.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
/** WordPress Misc Administration API */
4040
require_once(ABSPATH . 'wp-admin/includes/misc.php');
4141

42+
/** WordPress Options Administration API */
43+
require_once(ABSPATH . 'wp-admin/includes/options.php');
44+
4245
/** WordPress Plugin Administration API */
4346
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
4447

src/wp-admin/includes/options.php

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?php
2+
/**
3+
* WordPress Options Administration API.
4+
*
5+
* @package WordPress
6+
* @subpackage Administration
7+
* @since 4.4.0
8+
*/
9+
10+
/**
11+
* Output JavaScript to toggle display of additional settings if avatars are disabled.
12+
*
13+
* @since 4.2.0
14+
*/
15+
function options_discussion_add_js() {
16+
?>
17+
<script>
18+
(function($){
19+
var parent = $( '#show_avatars' ),
20+
children = $( '.avatar-settings' );
21+
parent.change(function(){
22+
children.toggleClass( 'hide-if-js', ! this.checked );
23+
});
24+
})(jQuery);
25+
</script>
26+
<?php
27+
}
28+
29+
/**
30+
* Display JavaScript on the page.
31+
*
32+
* @since 3.5.0
33+
*/
34+
function options_general_add_js() {
35+
?>
36+
<script type="text/javascript">
37+
jQuery(document).ready(function($){
38+
var $siteName = $( '#wp-admin-bar-site-name' ).children( 'a' ).first(),
39+
homeURL = ( <?php echo wp_json_encode( get_home_url() ); ?> || '' ).replace( /^(https?:\/\/)?(www\.)?/, '' );
40+
41+
$( '#blogname' ).on( 'input', function() {
42+
var title = $.trim( $( this ).val() ) || homeURL;
43+
44+
// Truncate to 40 characters.
45+
if ( 40 < title.length ) {
46+
title = title.substring( 0, 40 ) + '\u2026';
47+
}
48+
49+
$siteName.text( title );
50+
});
51+
52+
$("input[name='date_format']").click(function(){
53+
if ( "date_format_custom_radio" != $(this).attr("id") )
54+
$( "input[name='date_format_custom']" ).val( $( this ).val() ).siblings( '.example' ).text( $( this ).parent( 'label' ).text() );
55+
});
56+
$("input[name='date_format_custom']").focus(function(){
57+
$( '#date_format_custom_radio' ).prop( 'checked', true );
58+
});
59+
60+
$("input[name='time_format']").click(function(){
61+
if ( "time_format_custom_radio" != $(this).attr("id") )
62+
$( "input[name='time_format_custom']" ).val( $( this ).val() ).siblings( '.example' ).text( $( this ).parent( 'label' ).text() );
63+
});
64+
$("input[name='time_format_custom']").focus(function(){
65+
$( '#time_format_custom_radio' ).prop( 'checked', true );
66+
});
67+
$("input[name='date_format_custom'], input[name='time_format_custom']").change( function() {
68+
var format = $(this);
69+
format.siblings( '.spinner' ).addClass( 'is-active' );
70+
$.post(ajaxurl, {
71+
action: 'date_format_custom' == format.attr('name') ? 'date_format' : 'time_format',
72+
date : format.val()
73+
}, function(d) { format.siblings( '.spinner' ).removeClass( 'is-active' ); format.siblings('.example').text(d); } );
74+
});
75+
76+
var languageSelect = $( '#WPLANG' );
77+
$( 'form' ).submit( function() {
78+
// Don't show a spinner for English and installed languages,
79+
// as there is nothing to download.
80+
if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) {
81+
$( '#submit', this ).after( '<span class="spinner language-install-spinner" />' );
82+
}
83+
});
84+
});
85+
</script>
86+
<?php
87+
}
88+
89+
/**
90+
* Display JavaScript on the page.
91+
*
92+
* @since 3.5.0
93+
*/
94+
function options_permalink_add_js() {
95+
?>
96+
<script type="text/javascript">
97+
jQuery(document).ready(function() {
98+
jQuery('.permalink-structure input:radio').change(function() {
99+
if ( 'custom' == this.value )
100+
return;
101+
jQuery('#permalink_structure').val( this.value );
102+
});
103+
jQuery('#permalink_structure').focus(function() {
104+
jQuery("#custom_selection").attr('checked', 'checked');
105+
});
106+
});
107+
</script>
108+
<?php
109+
}
110+
111+
/**
112+
* Display JavaScript on the page.
113+
*
114+
* @since 3.5.0
115+
*/
116+
function options_reading_add_js() {
117+
?>
118+
<script type="text/javascript">
119+
jQuery(document).ready(function($){
120+
var section = $('#front-static-pages'),
121+
staticPage = section.find('input:radio[value="page"]'),
122+
selects = section.find('select'),
123+
check_disabled = function(){
124+
selects.prop( 'disabled', ! staticPage.prop('checked') );
125+
};
126+
check_disabled();
127+
section.find('input:radio').change(check_disabled);
128+
});
129+
</script>
130+
<?php
131+
}
132+
133+
/**
134+
* Render the blog charset setting.
135+
*
136+
* @since 3.5.0
137+
*/
138+
function options_reading_blog_charset() {
139+
echo '<input name="blog_charset" type="text" id="blog_charset" value="' . esc_attr( get_option( 'blog_charset' ) ) . '" class="regular-text" />';
140+
echo '<p class="description">' . __( 'The <a href="https://codex.wordpress.org/Glossary#Character_set">character encoding</a> of your site (UTF-8 is recommended)' ) . '</p>';
141+
}

src/wp-admin/options-discussion.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,6 @@
1414
$title = __('Discussion Settings');
1515
$parent_file = 'options-general.php';
1616

17-
/**
18-
* Output JavaScript to toggle display of additional settings if avatars are disabled.
19-
*
20-
* @since 4.2.0
21-
*/
22-
function options_discussion_add_js() {
23-
?>
24-
<script>
25-
(function($){
26-
var parent = $( '#show_avatars' ),
27-
children = $( '.avatar-settings' );
28-
parent.change(function(){
29-
children.toggleClass( 'hide-if-js', ! this.checked );
30-
});
31-
})(jQuery);
32-
</script>
33-
<?php
34-
}
3517
add_action( 'admin_print_footer_scripts', 'options_discussion_add_js' );
3618

3719
get_current_screen()->add_help_tab( array(

src/wp-admin/options-general.php

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -20,65 +20,6 @@
2020
/* translators: date and time format for exact current time, mainly about timezones, see http://php.net/date */
2121
$timezone_format = _x('Y-m-d H:i:s', 'timezone date format');
2222

23-
/**
24-
* Display JavaScript on the page.
25-
*
26-
* @since 3.5.0
27-
*/
28-
function options_general_add_js() {
29-
?>
30-
<script type="text/javascript">
31-
jQuery(document).ready(function($){
32-
var $siteName = $( '#wp-admin-bar-site-name' ).children( 'a' ).first(),
33-
homeURL = ( <?php echo wp_json_encode( get_home_url() ); ?> || '' ).replace( /^(https?:\/\/)?(www\.)?/, '' );
34-
35-
$( '#blogname' ).on( 'input', function() {
36-
var title = $.trim( $( this ).val() ) || homeURL;
37-
38-
// Truncate to 40 characters.
39-
if ( 40 < title.length ) {
40-
title = title.substring( 0, 40 ) + '\u2026';
41-
}
42-
43-
$siteName.text( title );
44-
});
45-
46-
$("input[name='date_format']").click(function(){
47-
if ( "date_format_custom_radio" != $(this).attr("id") )
48-
$( "input[name='date_format_custom']" ).val( $( this ).val() ).siblings( '.example' ).text( $( this ).parent( 'label' ).text() );
49-
});
50-
$("input[name='date_format_custom']").focus(function(){
51-
$( '#date_format_custom_radio' ).prop( 'checked', true );
52-
});
53-
54-
$("input[name='time_format']").click(function(){
55-
if ( "time_format_custom_radio" != $(this).attr("id") )
56-
$( "input[name='time_format_custom']" ).val( $( this ).val() ).siblings( '.example' ).text( $( this ).parent( 'label' ).text() );
57-
});
58-
$("input[name='time_format_custom']").focus(function(){
59-
$( '#time_format_custom_radio' ).prop( 'checked', true );
60-
});
61-
$("input[name='date_format_custom'], input[name='time_format_custom']").change( function() {
62-
var format = $(this);
63-
format.siblings( '.spinner' ).addClass( 'is-active' );
64-
$.post(ajaxurl, {
65-
action: 'date_format_custom' == format.attr('name') ? 'date_format' : 'time_format',
66-
date : format.val()
67-
}, function(d) { format.siblings( '.spinner' ).removeClass( 'is-active' ); format.siblings('.example').text(d); } );
68-
});
69-
70-
var languageSelect = $( '#WPLANG' );
71-
$( 'form' ).submit( function() {
72-
// Don't show a spinner for English and installed languages,
73-
// as there is nothing to download.
74-
if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) {
75-
$( '#submit', this ).after( '<span class="spinner language-install-spinner" />' );
76-
}
77-
});
78-
});
79-
</script>
80-
<?php
81-
}
8223
add_action('admin_head', 'options_general_add_js');
8324

8425
$options_help = '<p>' . __('The fields on this screen determine some of the basics of your site setup.') . '</p>' .

src/wp-admin/options-permalink.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,6 @@
4646
'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
4747
);
4848

49-
/**
50-
* Display JavaScript on the page.
51-
*
52-
* @since 3.5.0
53-
*/
54-
function options_permalink_add_js() {
55-
?>
56-
<script type="text/javascript">
57-
jQuery(document).ready(function() {
58-
jQuery('.permalink-structure input:radio').change(function() {
59-
if ( 'custom' == this.value )
60-
return;
61-
jQuery('#permalink_structure').val( this.value );
62-
});
63-
jQuery('#permalink_structure').focus(function() {
64-
jQuery("#custom_selection").attr('checked', 'checked');
65-
});
66-
});
67-
</script>
68-
<?php
69-
}
7049
add_filter('admin_head', 'options_permalink_add_js');
7150

7251
$home_path = get_home_path();

src/wp-admin/options-reading.php

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,8 @@
1515
$title = __( 'Reading Settings' );
1616
$parent_file = 'options-general.php';
1717

18-
/**
19-
* Display JavaScript on the page.
20-
*
21-
* @since 3.5.0
22-
*/
23-
function options_reading_add_js() {
24-
?>
25-
<script type="text/javascript">
26-
jQuery(document).ready(function($){
27-
var section = $('#front-static-pages'),
28-
staticPage = section.find('input:radio[value="page"]'),
29-
selects = section.find('select'),
30-
check_disabled = function(){
31-
selects.prop( 'disabled', ! staticPage.prop('checked') );
32-
};
33-
check_disabled();
34-
section.find('input:radio').change(check_disabled);
35-
});
36-
</script>
37-
<?php
38-
}
3918
add_action('admin_head', 'options_reading_add_js');
4019

41-
/**
42-
* Render the blog charset setting.
43-
*
44-
* @since 3.5.0
45-
*/
46-
function options_reading_blog_charset() {
47-
echo '<input name="blog_charset" type="text" id="blog_charset" value="' . esc_attr( get_option( 'blog_charset' ) ) . '" class="regular-text" />';
48-
echo '<p class="description">' . __( 'The <a href="https://codex.wordpress.org/Glossary#Character_set">character encoding</a> of your site (UTF-8 is recommended)' ) . '</p>';
49-
}
50-
5120
get_current_screen()->add_help_tab( array(
5221
'id' => 'overview',
5322
'title' => __('Overview'),

0 commit comments

Comments
 (0)