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
This commit is contained in:
Scott Taylor 2015-09-10 21:44:29 +00:00
parent 96a40d6102
commit ab4fcd20d0
6 changed files with 144 additions and 129 deletions

View File

@ -39,6 +39,9 @@ require_once(ABSPATH . 'wp-admin/includes/import.php');
/** WordPress Misc Administration API */ /** WordPress Misc Administration API */
require_once(ABSPATH . 'wp-admin/includes/misc.php'); require_once(ABSPATH . 'wp-admin/includes/misc.php');
/** WordPress Options Administration API */
require_once(ABSPATH . 'wp-admin/includes/options.php');
/** WordPress Plugin Administration API */ /** WordPress Plugin Administration API */
require_once(ABSPATH . 'wp-admin/includes/plugin.php'); require_once(ABSPATH . 'wp-admin/includes/plugin.php');

View File

@ -0,0 +1,141 @@
<?php
/**
* WordPress Options Administration API.
*
* @package WordPress
* @subpackage Administration
* @since 4.4.0
*/
/**
* Output JavaScript to toggle display of additional settings if avatars are disabled.
*
* @since 4.2.0
*/
function options_discussion_add_js() {
?>
<script>
(function($){
var parent = $( '#show_avatars' ),
children = $( '.avatar-settings' );
parent.change(function(){
children.toggleClass( 'hide-if-js', ! this.checked );
});
})(jQuery);
</script>
<?php
}
/**
* Display JavaScript on the page.
*
* @since 3.5.0
*/
function options_general_add_js() {
?>
<script type="text/javascript">
jQuery(document).ready(function($){
var $siteName = $( '#wp-admin-bar-site-name' ).children( 'a' ).first(),
homeURL = ( <?php echo wp_json_encode( get_home_url() ); ?> || '' ).replace( /^(https?:\/\/)?(www\.)?/, '' );
$( '#blogname' ).on( 'input', function() {
var title = $.trim( $( this ).val() ) || homeURL;
// Truncate to 40 characters.
if ( 40 < title.length ) {
title = title.substring( 0, 40 ) + '\u2026';
}
$siteName.text( title );
});
$("input[name='date_format']").click(function(){
if ( "date_format_custom_radio" != $(this).attr("id") )
$( "input[name='date_format_custom']" ).val( $( this ).val() ).siblings( '.example' ).text( $( this ).parent( 'label' ).text() );
});
$("input[name='date_format_custom']").focus(function(){
$( '#date_format_custom_radio' ).prop( 'checked', true );
});
$("input[name='time_format']").click(function(){
if ( "time_format_custom_radio" != $(this).attr("id") )
$( "input[name='time_format_custom']" ).val( $( this ).val() ).siblings( '.example' ).text( $( this ).parent( 'label' ).text() );
});
$("input[name='time_format_custom']").focus(function(){
$( '#time_format_custom_radio' ).prop( 'checked', true );
});
$("input[name='date_format_custom'], input[name='time_format_custom']").change( function() {
var format = $(this);
format.siblings( '.spinner' ).addClass( 'is-active' );
$.post(ajaxurl, {
action: 'date_format_custom' == format.attr('name') ? 'date_format' : 'time_format',
date : format.val()
}, function(d) { format.siblings( '.spinner' ).removeClass( 'is-active' ); format.siblings('.example').text(d); } );
});
var languageSelect = $( '#WPLANG' );
$( 'form' ).submit( function() {
// Don't show a spinner for English and installed languages,
// as there is nothing to download.
if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) {
$( '#submit', this ).after( '<span class="spinner language-install-spinner" />' );
}
});
});
</script>
<?php
}
/**
* Display JavaScript on the page.
*
* @since 3.5.0
*/
function options_permalink_add_js() {
?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('.permalink-structure input:radio').change(function() {
if ( 'custom' == this.value )
return;
jQuery('#permalink_structure').val( this.value );
});
jQuery('#permalink_structure').focus(function() {
jQuery("#custom_selection").attr('checked', 'checked');
});
});
</script>
<?php
}
/**
* Display JavaScript on the page.
*
* @since 3.5.0
*/
function options_reading_add_js() {
?>
<script type="text/javascript">
jQuery(document).ready(function($){
var section = $('#front-static-pages'),
staticPage = section.find('input:radio[value="page"]'),
selects = section.find('select'),
check_disabled = function(){
selects.prop( 'disabled', ! staticPage.prop('checked') );
};
check_disabled();
section.find('input:radio').change(check_disabled);
});
</script>
<?php
}
/**
* Render the blog charset setting.
*
* @since 3.5.0
*/
function options_reading_blog_charset() {
echo '<input name="blog_charset" type="text" id="blog_charset" value="' . esc_attr( get_option( 'blog_charset' ) ) . '" class="regular-text" />';
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>';
}

View File

@ -14,24 +14,6 @@ if ( ! current_user_can( 'manage_options' ) )
$title = __('Discussion Settings'); $title = __('Discussion Settings');
$parent_file = 'options-general.php'; $parent_file = 'options-general.php';
/**
* Output JavaScript to toggle display of additional settings if avatars are disabled.
*
* @since 4.2.0
*/
function options_discussion_add_js() {
?>
<script>
(function($){
var parent = $( '#show_avatars' ),
children = $( '.avatar-settings' );
parent.change(function(){
children.toggleClass( 'hide-if-js', ! this.checked );
});
})(jQuery);
</script>
<?php
}
add_action( 'admin_print_footer_scripts', 'options_discussion_add_js' ); add_action( 'admin_print_footer_scripts', 'options_discussion_add_js' );
get_current_screen()->add_help_tab( array( get_current_screen()->add_help_tab( array(

View File

@ -20,65 +20,6 @@ $parent_file = 'options-general.php';
/* translators: date and time format for exact current time, mainly about timezones, see http://php.net/date */ /* translators: date and time format for exact current time, mainly about timezones, see http://php.net/date */
$timezone_format = _x('Y-m-d H:i:s', 'timezone date format'); $timezone_format = _x('Y-m-d H:i:s', 'timezone date format');
/**
* Display JavaScript on the page.
*
* @since 3.5.0
*/
function options_general_add_js() {
?>
<script type="text/javascript">
jQuery(document).ready(function($){
var $siteName = $( '#wp-admin-bar-site-name' ).children( 'a' ).first(),
homeURL = ( <?php echo wp_json_encode( get_home_url() ); ?> || '' ).replace( /^(https?:\/\/)?(www\.)?/, '' );
$( '#blogname' ).on( 'input', function() {
var title = $.trim( $( this ).val() ) || homeURL;
// Truncate to 40 characters.
if ( 40 < title.length ) {
title = title.substring( 0, 40 ) + '\u2026';
}
$siteName.text( title );
});
$("input[name='date_format']").click(function(){
if ( "date_format_custom_radio" != $(this).attr("id") )
$( "input[name='date_format_custom']" ).val( $( this ).val() ).siblings( '.example' ).text( $( this ).parent( 'label' ).text() );
});
$("input[name='date_format_custom']").focus(function(){
$( '#date_format_custom_radio' ).prop( 'checked', true );
});
$("input[name='time_format']").click(function(){
if ( "time_format_custom_radio" != $(this).attr("id") )
$( "input[name='time_format_custom']" ).val( $( this ).val() ).siblings( '.example' ).text( $( this ).parent( 'label' ).text() );
});
$("input[name='time_format_custom']").focus(function(){
$( '#time_format_custom_radio' ).prop( 'checked', true );
});
$("input[name='date_format_custom'], input[name='time_format_custom']").change( function() {
var format = $(this);
format.siblings( '.spinner' ).addClass( 'is-active' );
$.post(ajaxurl, {
action: 'date_format_custom' == format.attr('name') ? 'date_format' : 'time_format',
date : format.val()
}, function(d) { format.siblings( '.spinner' ).removeClass( 'is-active' ); format.siblings('.example').text(d); } );
});
var languageSelect = $( '#WPLANG' );
$( 'form' ).submit( function() {
// Don't show a spinner for English and installed languages,
// as there is nothing to download.
if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) {
$( '#submit', this ).after( '<span class="spinner language-install-spinner" />' );
}
});
});
</script>
<?php
}
add_action('admin_head', 'options_general_add_js'); add_action('admin_head', 'options_general_add_js');
$options_help = '<p>' . __('The fields on this screen determine some of the basics of your site setup.') . '</p>' . $options_help = '<p>' . __('The fields on this screen determine some of the basics of your site setup.') . '</p>' .

View File

@ -46,27 +46,6 @@ get_current_screen()->set_help_sidebar(
'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
); );
/**
* Display JavaScript on the page.
*
* @since 3.5.0
*/
function options_permalink_add_js() {
?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('.permalink-structure input:radio').change(function() {
if ( 'custom' == this.value )
return;
jQuery('#permalink_structure').val( this.value );
});
jQuery('#permalink_structure').focus(function() {
jQuery("#custom_selection").attr('checked', 'checked');
});
});
</script>
<?php
}
add_filter('admin_head', 'options_permalink_add_js'); add_filter('admin_head', 'options_permalink_add_js');
$home_path = get_home_path(); $home_path = get_home_path();

View File

@ -15,39 +15,8 @@ if ( ! current_user_can( 'manage_options' ) )
$title = __( 'Reading Settings' ); $title = __( 'Reading Settings' );
$parent_file = 'options-general.php'; $parent_file = 'options-general.php';
/**
* Display JavaScript on the page.
*
* @since 3.5.0
*/
function options_reading_add_js() {
?>
<script type="text/javascript">
jQuery(document).ready(function($){
var section = $('#front-static-pages'),
staticPage = section.find('input:radio[value="page"]'),
selects = section.find('select'),
check_disabled = function(){
selects.prop( 'disabled', ! staticPage.prop('checked') );
};
check_disabled();
section.find('input:radio').change(check_disabled);
});
</script>
<?php
}
add_action('admin_head', 'options_reading_add_js'); add_action('admin_head', 'options_reading_add_js');
/**
* Render the blog charset setting.
*
* @since 3.5.0
*/
function options_reading_blog_charset() {
echo '<input name="blog_charset" type="text" id="blog_charset" value="' . esc_attr( get_option( 'blog_charset' ) ) . '" class="regular-text" />';
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>';
}
get_current_screen()->add_help_tab( array( get_current_screen()->add_help_tab( array(
'id' => 'overview', 'id' => 'overview',
'title' => __('Overview'), 'title' => __('Overview'),