Changeset 22127 for trunk/wp-admin/options-reading.php
- Timestamp:
- 10/06/2012 03:19:29 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/options-reading.php
r21872 r22127 15 15 $title = __( 'Reading Settings' ); 16 16 $parent_file = 'options-general.php'; 17 18 wp_enqueue_script( 'sample-permalink' ); 17 19 18 20 /** … … 23 25 function options_reading_add_js() { 24 26 ?> 25 <script type="text/javascript"> 26 //<![CDATA[ 27 jQuery(document).ready(function($){ 28 var section = $('#front-static-pages'), 29 staticPage = section.find('input:radio[value="page"]'), 30 selects = section.find('select'), 31 check_disabled = function(){ 32 selects.prop( 'disabled', ! staticPage.prop('checked') ); 33 }; 34 check_disabled(); 35 section.find('input:radio').change(check_disabled); 27 <script> 28 jQuery(document).ready( function($) { 29 var section = $('#front-static-pages'); 30 $('#show_on_front').change( function() { 31 var checked = $(this).prop('checked'); 32 section.toggleClass('page-on-front', checked); 33 if ( checked ) 34 $('#page_for_posts').prop('checked', true).change(); 36 35 }); 37 //]]> 36 $('#page_for_posts').change( function() { 37 section.toggleClass('page-for-posts', $(this).prop('checked')); 38 }); 39 $('#page_on_front').change( function() { 40 section.toggleClass('new-front-page', 'new' === $(this).val()); 41 }); 42 }); 38 43 </script> 39 44 <?php 40 45 } 41 add_action( 'admin_head', 'options_reading_add_js');46 add_action( 'admin_head', 'options_reading_add_js' ); 42 47 43 48 /** … … 83 88 <?php 84 89 settings_fields( 'reading' ); 85 90 wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); 91 ?> 92 <table class="form-table"> 93 <?php 86 94 if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) 87 95 add_settings_field( 'blog_charset', __( 'Encoding for pages and feeds' ), 'options_reading_blog_charset', 'reading', 'default', array( 'label_for' => 'blog_charset' ) ); 88 ?> 89 90 <?php if ( ! get_pages() ) : ?> 91 <input name="show_on_front" type="hidden" value="posts" /> 92 <table class="form-table"> 93 <?php 94 if ( 'posts' != get_option( 'show_on_front' ) ) : 96 97 $classes = ''; 98 if ( 'page' == get_option( 'show_on_front' ) ) { 99 if ( ! get_pages() || ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) ) { 95 100 update_option( 'show_on_front', 'posts' ); 96 endif; 97 98 else : 99 if ( 'page' == get_option( 'show_on_front' ) && ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) ) 100 update_option( 'show_on_front', 'posts' ); 101 ?> 102 <table class="form-table"> 103 <tr valign="top"> 104 <th scope="row"><?php _e( 'Front page displays' ); ?></th> 105 <td id="front-static-pages"><fieldset><legend class="screen-reader-text"><span><?php _e( 'Front page displays' ); ?></span></legend> 106 <p><label> 107 <input name="show_on_front" type="radio" value="posts" class="tog" <?php checked( 'posts', get_option( 'show_on_front' ) ); ?> /> 108 <?php _e( 'Your latest posts' ); ?> 109 </label> 101 } else { 102 $classes = 'page-on-front'; 103 if ( get_option( 'page_for_posts' ) ) 104 $classes .= ' page-for-posts'; 105 } 106 } 107 108 $all_pages = get_pages(); 109 $new_front_page_only = ! get_option( 'page_on_front' ) && ( ! $all_pages || ( 1 == count( $all_pages ) && __( 'sample-page' ) == $all_pages[0]->post_name ) ); 110 111 if ( current_user_can( 'create_posts', 'page' ) && ! ( get_option( 'page_for_posts' ) && $page_for_posts = get_post( get_option( 'page_for_posts' ) ) ) ) { 112 $title = _x( 'Blog', 'default page for posts title' ); 113 // @todo What if the found page is post_type = attachment or post_status != publish? 114 // We could go ahead and create a new one, but we would not be able to take over 115 // the slug from another page. (We could for an attachment.) 116 // We must also check that the user can edit this page and publish a page. 117 // Otherwise, we must assume they cannot create pages (throughout), and thus 118 // should fall back to the dropdown. 119 if ( ! $page_for_posts = get_page_by_path( sanitize_title( $title ) ) ) { 120 $page_for_posts = get_default_post_to_edit( 'page', true ); 121 $page_for_posts->post_title = $title; 122 $page_for_posts->post_name = sanitize_title( $title ); 123 } 124 } 125 126 if ( ! $new_front_page_only || current_user_can( 'create_posts', 'page' ) ) : ?> 127 <tr valign="top"> 128 <th scope="row"><?php _e( 'Enable a static front page' ); ?></th> 129 <td id="front-static-pages" class="<?php echo $classes; ?>"> 130 <fieldset><legend class="screen-reader-text"><span><?php _e( 'Enable a static front page' ); ?></span></legend> 131 <p><label for="show_on_front"> 132 <input id="show_on_front" name="show_on_front" type="checkbox" value="page" <?php checked( 'page', get_option( 'show_on_front' ) ); ?> /> 133 <?php printf( __( 'Show a <a href="%s">page</a> instead of your latest posts' ), 'edit.php?post_type=page' ); ?> 134 </label></p> 135 <p class="if-page-on-front sub-option"> 136 <?php if ( $new_front_page_only ) : // If no pages, or only sample page, only allow a new page to be added ?> 137 <label for="page_on_front_title"><?php _e( 'Add new page titled:' ); ?> 138 <?php else : ?> 139 <label for="page_on_front"> 140 <select name="page_on_front" id="page_on_front"> 141 <option value="0"><?php _e( '— Select —' ); ?></option> 142 <?php if ( current_user_can( 'create_posts', 'page' ) ) : ?> 143 <option value="new" id="new-page"><?php _e( '— Add new page —' ); ?></option> 144 <?php endif; ?> 145 <?php echo walk_page_dropdown_tree( $all_pages, 0, array( 'selected' => get_option( 'page_on_front' ) ) ); ?> 146 </select> 147 </label> 148 <?php if ( current_user_can( 'create_posts', 'page' ) ) : ?> 149 <label for="page_on_front_title" class="if-new-front-page"><?php _e( 'titled:' ); ?> 150 <?php endif; ?> 151 <?php endif; ?> 152 <?php if ( current_user_can( 'create_posts', 'page' ) ) : ?> 153 <input name="page_on_front_title" type="text" id="page_on_front_title" value="<?php echo esc_attr_x( 'Home', 'default page on front title' ); ?>" /> 154 </label> 155 <?php endif; ?> 110 156 </p> 111 <p><label> 112 <input name="show_on_front" type="radio" value="page" class="tog" <?php checked( 'page', get_option( 'show_on_front' ) ); ?> /> 113 <?php printf( __( 'A <a href="%s">static page</a> (select below)' ), 'edit.php?post_type=page' ); ?> 114 </label> 157 <p class="if-page-on-front"><label for="page_for_posts"> 158 <input id="page_for_posts" name="page_for_posts" type="checkbox" value="<?php echo $page_for_posts->ID; ?>" <?php checked( (bool) get_option( 'page_for_posts' ) ); ?> /> 159 <?php _e( 'Show latest posts on a separate page' ); ?> 160 </label></p> 161 <?php if ( current_user_can( 'create_posts', 'page' ) ) : ?> 162 <p class="if-page-for-posts sub-option"><label for="page_for_posts_title"><?php _e( 'Page title:' ); ?> 163 <input name="page_for_posts_title" type="text" id="page_for_posts_title" value="<?php echo esc_attr( htmlspecialchars( $page_for_posts->post_title ) ); ?>" /> 164 </label></p> 165 <p class="if-page-for-posts sub-option" id="edit-slug-box"> 166 <?php echo get_sample_permalink_html( $page_for_posts->ID, $page_for_posts->post_title, $page_for_posts->post_name ); ?> 115 167 </p> 116 <ul> 117 <li><label for="page_on_front"><?php printf( __( 'Front page: %s' ), wp_dropdown_pages( array( 'name' => 'page_on_front', 'echo' => 0, 'show_option_none' => __( '— Select —' ), 'option_none_value' => '0', 'selected' => get_option( 'page_on_front' ) ) ) ); ?></label></li> 118 <li><label for="page_for_posts"><?php printf( __( 'Posts page: %s' ), wp_dropdown_pages( array( 'name' => 'page_for_posts', 'echo' => 0, 'show_option_none' => __( '— Select —' ), 'option_none_value' => '0', 'selected' => get_option( 'page_for_posts' ) ) ) ); ?></label></li> 119 </ul> 120 <?php if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == get_option( 'page_on_front' ) ) : ?> 121 <div id="front-page-warning" class="error inline"><p><?php _e( '<strong>Warning:</strong> these pages should not be the same!' ); ?></p></div> 122 <?php endif; ?> 123 </fieldset></td> 124 </tr> 125 <?php endif; ?> 168 <input name="post_name" type="hidden" id="post_name" value="<?php echo esc_attr( apply_filters( 'editable_slug', $page_for_posts->post_name ) ); ?>" /> 169 <?php if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == get_option( 'page_on_front' ) ) : ?> 170 <div class="error inline"><p><strong><?php _e( 'ERROR:' ); ?></strong> <?php _e( 'These pages should not be the same!' ); ?></p></div> 171 <?php endif; ?> 172 </fieldset> 173 <?php else : // cannot create pages, so fall back to a selector of existing pages ?> 174 <p class="if-page-for-posts sub-option"><label for="page_for_posts"> 175 <?php wp_dropdown_pages( array( 176 'name' => 'page_for_posts', 'show_option_none' => __( '— Select —' ), 177 'option_none_value' => '0', 'selected' => get_option( 'page_for_posts' ) 178 ) ); ?> 179 <?php endif; // create pages ?> 180 </td> 181 </tr> 182 <?php endif; // if no pages to choose from and can't create pages ?> 183 126 184 <tr valign="top"> 127 185 <th scope="row"><label for="posts_per_page"><?php _e( 'Blog pages show at most' ); ?></label></th>
Note: See TracChangeset
for help on using the changeset viewer.