options.php 4.0 KB

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