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