| 1 | Index: wp-includes/default-filters.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-includes/default-filters.php (revision 22380) |
|---|
| 4 | +++ wp-includes/default-filters.php (working copy) |
|---|
| 5 | @@ -258,6 +258,7 @@ |
|---|
| 6 | add_action( 'importer_scheduled_cleanup', 'wp_delete_attachment' ); |
|---|
| 7 | add_action( 'upgrader_scheduled_cleanup', 'wp_delete_attachment' ); |
|---|
| 8 | add_action( 'welcome_panel', 'wp_welcome_panel' ); |
|---|
| 9 | +add_action( 'page_for_posts_message', 'display_page_for_posts_message' ); |
|---|
| 10 | |
|---|
| 11 | // Navigation menu actions |
|---|
| 12 | add_action( 'delete_post', '_wp_delete_post_menu_item' ); |
|---|
| 13 | Index: wp-admin/includes/post.php |
|---|
| 14 | =================================================================== |
|---|
| 15 | --- wp-admin/includes/post.php (revision 22380) |
|---|
| 16 | +++ wp-admin/includes/post.php (working copy) |
|---|
| 17 | @@ -1330,6 +1330,27 @@ |
|---|
| 18 | } |
|---|
| 19 | |
|---|
| 20 | /** |
|---|
| 21 | + * Checks if page on front is set, else shows latests posts |
|---|
| 22 | + * |
|---|
| 23 | + * @since 3.5.0 |
|---|
| 24 | + * @access private |
|---|
| 25 | + */ |
|---|
| 26 | + |
|---|
| 27 | +function _show_on_front_cant_create_pages () { |
|---|
| 28 | + |
|---|
| 29 | + // If an existing page is set, keep things as is, rather than reverting to showing posts. |
|---|
| 30 | + if ( get_option( 'page_on_front' ) ) { |
|---|
| 31 | + $show_on_front_value = 'page'; |
|---|
| 32 | + } else { |
|---|
| 33 | + $show_on_front_value = 'posts'; |
|---|
| 34 | + update_option( 'page_on_front', 0 ); |
|---|
| 35 | + update_option( 'page_for_posts', 0 ); |
|---|
| 36 | + } |
|---|
| 37 | + add_settings_error( 'page_on_front', 'create_pages', __( 'You are not allowed to create pages on this site.' ) ); |
|---|
| 38 | + return $show_on_front_value; |
|---|
| 39 | +} |
|---|
| 40 | + |
|---|
| 41 | +/** |
|---|
| 42 | * Creates new pages to be set as a front page or a page for posts in Reading Settings. |
|---|
| 43 | * |
|---|
| 44 | * @todo Make sure we are doing adequate sanitization on success, and cleanup/reset on failure. |
|---|
| 45 | @@ -1338,108 +1359,99 @@ |
|---|
| 46 | * @access private |
|---|
| 47 | */ |
|---|
| 48 | function _show_on_front_reading_settings( $show_on_front_value ) { |
|---|
| 49 | + |
|---|
| 50 | // If we're not saving the Reading Settings screen, don't intercept. |
|---|
| 51 | if ( ! $_POST || ! strpos( wp_get_referer(), 'options-reading.php' ) ) |
|---|
| 52 | return $show_on_front_value; |
|---|
| 53 | - |
|---|
| 54 | + |
|---|
| 55 | + // If 'latest posts' is set, stop here |
|---|
| 56 | if ( 'posts' == $show_on_front_value ) { |
|---|
| 57 | update_option( 'page_on_front', 0 ); |
|---|
| 58 | update_option( 'page_for_posts', 0 ); |
|---|
| 59 | + |
|---|
| 60 | return $show_on_front_value; |
|---|
| 61 | } |
|---|
| 62 | + |
|---|
| 63 | + // They didn't select a page at all. Sad face. |
|---|
| 64 | + if ( ! $_POST['page_on_front_title'] ) { |
|---|
| 65 | + $show_on_front_value = 'posts'; |
|---|
| 66 | + update_option( 'page_on_front', 0 ); |
|---|
| 67 | + update_option( 'page_for_posts', 0 ); |
|---|
| 68 | + add_settings_error( 'page_on_front', 'no_page_selected', __( 'You must select a page to set a static front page.' ) ); |
|---|
| 69 | + return $show_on_front_value; |
|---|
| 70 | + } |
|---|
| 71 | + |
|---|
| 72 | + // PAGE_ON_FRONT |
|---|
| 73 | + $existing_page_on_front = get_page_by_title( stripslashes( $_POST['page_on_front_title'] ) ); |
|---|
| 74 | |
|---|
| 75 | - // If a new front page was meant to be created, go forth and create it. |
|---|
| 76 | - if ( 'new' == $_POST['page_on_front'] ) { |
|---|
| 77 | - |
|---|
| 78 | + if ( $existing_page_on_front && $existing_page_on_front->ID && 'publish' == $existing_page_on_front->post_status && 'page' == $existing_page_on_front->post_type ) { |
|---|
| 79 | + |
|---|
| 80 | + // If a page exists with this same title, use it |
|---|
| 81 | + update_option( 'page_on_front', (int) $existing_page_on_front->ID ); |
|---|
| 82 | + } else { |
|---|
| 83 | + |
|---|
| 84 | // If the user can't create pages, revert. |
|---|
| 85 | if ( ! current_user_can( 'create_posts', 'page' ) ) { |
|---|
| 86 | - // If an existing page is set, keep things as is, rather than reverting to showing posts. |
|---|
| 87 | - if ( get_option( 'page_on_front' ) ) { |
|---|
| 88 | - $show_on_front_value = 'page'; |
|---|
| 89 | - } else { |
|---|
| 90 | - $show_on_front_value = 'posts'; |
|---|
| 91 | - update_option( 'page_on_front', 0 ); |
|---|
| 92 | - update_option( 'page_for_posts', 0 ); |
|---|
| 93 | - } |
|---|
| 94 | - add_settings_error( 'page_on_front', 'create_pages', __( 'You are not allowed to create pages on this site.' ) ); |
|---|
| 95 | - return $show_on_front_value; |
|---|
| 96 | + return _show_on_front_cant_create_pages(); |
|---|
| 97 | } |
|---|
| 98 | - |
|---|
| 99 | - $existing_page = get_page_by_title( stripslashes( $_POST['page_on_front_title'] ) ); |
|---|
| 100 | - |
|---|
| 101 | - // If page already exists and it's public, there's no need to create a new page. |
|---|
| 102 | - if ( $existing_page && 'publish' == $existing_page->post_status ) { |
|---|
| 103 | - $page_id = $existing_page->ID; |
|---|
| 104 | - } else { |
|---|
| 105 | - $page_id = wp_insert_post( array( |
|---|
| 106 | - 'post_title' => $_POST['page_on_front_title'], |
|---|
| 107 | - 'post_type' => 'page', |
|---|
| 108 | - 'post_status' => 'publish', |
|---|
| 109 | - 'comment_status' => 'closed', |
|---|
| 110 | - 'ping_status' => 'closed', |
|---|
| 111 | - // @todo Create some sort of a 'context' in postmeta so we know we created a page through these means. |
|---|
| 112 | - // Consider then showing that context in the list table as a good-first-step. |
|---|
| 113 | - ) ); |
|---|
| 114 | - } |
|---|
| 115 | - |
|---|
| 116 | + |
|---|
| 117 | + // Create new page |
|---|
| 118 | + $page_id = wp_insert_post( array( |
|---|
| 119 | + 'post_title' => wp_strip_all_tags( $_POST['page_on_front_title'] ), |
|---|
| 120 | + 'post_type' => 'page', |
|---|
| 121 | + 'post_status' => 'publish', |
|---|
| 122 | + 'comment_status' => 'closed', |
|---|
| 123 | + 'ping_status' => 'closed' |
|---|
| 124 | + // @todo Create some sort of a 'context' in postmeta so we know we created a page through these means. |
|---|
| 125 | + // Consider then showing that context in the list table as a good-first-step. |
|---|
| 126 | + ) ); |
|---|
| 127 | + |
|---|
| 128 | if ( $page_id ) { |
|---|
| 129 | update_option( 'page_on_front', $page_id ); |
|---|
| 130 | - // If we can't save it, revert. |
|---|
| 131 | - } elseif ( get_option( 'page_on_front' ) ) { |
|---|
| 132 | - // If an existing page is set, keep things as is, rather than reverting to showing posts. |
|---|
| 133 | - $show_on_front_value = 'page'; |
|---|
| 134 | } else { |
|---|
| 135 | - $show_on_front_value = 'posts'; |
|---|
| 136 | - update_option( 'page_on_front', 0 ); |
|---|
| 137 | - update_option( 'page_for_posts', 0 ); |
|---|
| 138 | - return $show_on_front_value; |
|---|
| 139 | + |
|---|
| 140 | + // If we can't save it, revert. |
|---|
| 141 | + return _show_on_front_cant_create_pages(); |
|---|
| 142 | } |
|---|
| 143 | - } elseif ( $_POST['page_on_front'] ) { |
|---|
| 144 | - update_option( 'page_on_front', $_POST['page_on_front'] ); |
|---|
| 145 | - } else { |
|---|
| 146 | - // They didn't select a page at all. Sad face. |
|---|
| 147 | - $show_on_front_value = 'posts'; |
|---|
| 148 | - update_option( 'page_on_front', 0 ); |
|---|
| 149 | - update_option( 'page_for_posts', 0 ); |
|---|
| 150 | - add_settings_error( 'page_on_front', 'no_page_selected', __( 'You must select a page to set a static front page.' ) ); |
|---|
| 151 | - return $show_on_front_value; |
|---|
| 152 | } |
|---|
| 153 | - |
|---|
| 154 | - // If a page for posts was meant to be specified, update/create it. |
|---|
| 155 | - if ( ! isset( $_POST['page_for_posts'] ) ) { |
|---|
| 156 | - update_option( 'page_for_posts', 0 ); |
|---|
| 157 | + |
|---|
| 158 | + // PAGE_FOR_POSTS |
|---|
| 159 | + if ( ! isset( $_POST['page_for_posts_name'] ) ) { |
|---|
| 160 | return $show_on_front_value; |
|---|
| 161 | } |
|---|
| 162 | - |
|---|
| 163 | - $page_for_posts = (int) $_POST['page_for_posts']; |
|---|
| 164 | - |
|---|
| 165 | - if ( ! $page_for_posts || ! $page = get_post( $page_for_posts, ARRAY_A ) ) { |
|---|
| 166 | - update_option( 'page_for_posts', 0 ); |
|---|
| 167 | - return $show_on_front_value; |
|---|
| 168 | + |
|---|
| 169 | + $existing_page_for_posts = get_page_by_path( stripslashes( $_POST['page_for_posts_name'] ) ); |
|---|
| 170 | + |
|---|
| 171 | + if ( $existing_page_for_posts && $existing_page_for_posts->ID && 'publish' == $existing_page_for_posts->post_status && 'page' == $existing_page_for_posts->post_type ) { |
|---|
| 172 | + |
|---|
| 173 | + // If a page exists with this same name, use it |
|---|
| 174 | + update_option( 'page_for_posts', (int) $existing_page_for_posts->ID ); |
|---|
| 175 | + } else { |
|---|
| 176 | + |
|---|
| 177 | + // If the user can't create pages, revert. |
|---|
| 178 | + if ( ! current_user_can( 'create_posts', 'page' ) ) { |
|---|
| 179 | + return _show_on_front_cant_create_pages(); |
|---|
| 180 | + } |
|---|
| 181 | + |
|---|
| 182 | + // Create new page |
|---|
| 183 | + $page_id = wp_insert_post( array( |
|---|
| 184 | + 'post_title' => 'Latest posts', |
|---|
| 185 | + 'post_name' => wp_strip_all_tags( $_POST['page_for_posts_name'] ), |
|---|
| 186 | + 'post_type' => 'page', |
|---|
| 187 | + 'post_status' => 'publish', |
|---|
| 188 | + 'comment_status' => 'closed', |
|---|
| 189 | + 'ping_status' => 'closed' |
|---|
| 190 | + ) ); |
|---|
| 191 | + |
|---|
| 192 | + if ( $page_id ) { |
|---|
| 193 | + update_option( 'page_for_posts', $page_id ); |
|---|
| 194 | + } else { |
|---|
| 195 | + |
|---|
| 196 | + // If we can't save it, revert. |
|---|
| 197 | + return _show_on_front_cant_create_pages(); |
|---|
| 198 | + } |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | - if ( 'page' != $page['post_type'] || ! current_user_can( 'edit_post', $page_for_posts ) ) { |
|---|
| 202 | - update_option( 'page_for_posts', 0 ); |
|---|
| 203 | - return $show_on_front_value; |
|---|
| 204 | - } |
|---|
| 205 | - |
|---|
| 206 | - if ( 'publish' != $page['post_status'] && ! current_user_can( 'publish_post', $page_for_posts ) ) { |
|---|
| 207 | - update_option( 'page_for_posts', 0 ); |
|---|
| 208 | - return $show_on_front_value; |
|---|
| 209 | - } |
|---|
| 210 | - |
|---|
| 211 | - $args = add_magic_quotes( $page ); |
|---|
| 212 | - $args['post_title'] = $_POST['page_for_posts_title']; |
|---|
| 213 | - $args['post_name'] = $_POST['post_name']; |
|---|
| 214 | - $args['post_status'] = 'publish'; |
|---|
| 215 | - if ( 'auto-draft' == $page['post_status'] ) { |
|---|
| 216 | - $args['comment_status'] = 'closed'; |
|---|
| 217 | - $args['ping_status'] = 'closed'; |
|---|
| 218 | - } |
|---|
| 219 | - |
|---|
| 220 | - $page_id = wp_insert_post( $args ); |
|---|
| 221 | - update_option( 'page_for_posts', $page_id ); |
|---|
| 222 | - |
|---|
| 223 | return $show_on_front_value; |
|---|
| 224 | } |
|---|
| 225 | -add_filter( 'sanitize_option_show_on_front', '_show_on_front_reading_settings' ); |
|---|
| 226 | +add_filter( 'sanitize_option_show_on_front', '_show_on_front_reading_settings' ); |
|---|
| 227 | \ No newline at end of file |
|---|
| 228 | Index: wp-admin/edit-form-advanced.php |
|---|
| 229 | =================================================================== |
|---|
| 230 | --- wp-admin/edit-form-advanced.php (revision 22380) |
|---|
| 231 | +++ wp-admin/edit-form-advanced.php (working copy) |
|---|
| 232 | @@ -306,8 +306,20 @@ |
|---|
| 233 | wp_nonce_field( 'autosave', 'autosavenonce', false ); |
|---|
| 234 | wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); |
|---|
| 235 | wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); |
|---|
| 236 | -?> |
|---|
| 237 | |
|---|
| 238 | +do_action( 'page_for_posts_message' ); |
|---|
| 239 | + |
|---|
| 240 | +function display_page_for_posts_message () { |
|---|
| 241 | + global $post; |
|---|
| 242 | + |
|---|
| 243 | + if ( $post->ID == get_option( 'page_for_posts' ) ) { ?> |
|---|
| 244 | + <div class="updated message"> |
|---|
| 245 | + <p><?php echo sprintf( __( 'This page is set to display your <a href="%s">latest posts</a>. As a result, the main content for this page (as seen in the editor below) will not be displayed. Visit your <a href="%s">reading settings</a> to change the \'front page displays\' option.' ), 'options-reading.php', 'options-reading.php' ); ?></p> |
|---|
| 246 | + </div> |
|---|
| 247 | +<?php |
|---|
| 248 | + } |
|---|
| 249 | +} ?> |
|---|
| 250 | + |
|---|
| 251 | <div id="poststuff"> |
|---|
| 252 | |
|---|
| 253 | <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>"> |
|---|
| 254 | Index: wp-admin/css/ie.css |
|---|
| 255 | =================================================================== |
|---|
| 256 | --- wp-admin/css/ie.css (revision 22380) |
|---|
| 257 | +++ wp-admin/css/ie.css (working copy) |
|---|
| 258 | @@ -601,4 +601,4 @@ |
|---|
| 259 | |
|---|
| 260 | * html #adminmenu div.wp-menu-image { |
|---|
| 261 | height: 29px; |
|---|
| 262 | -} |
|---|
| 263 | +} |
|---|
| 264 | \ No newline at end of file |
|---|
| 265 | Index: wp-admin/css/wp-admin.css |
|---|
| 266 | =================================================================== |
|---|
| 267 | --- wp-admin/css/wp-admin.css (revision 22380) |
|---|
| 268 | +++ wp-admin/css/wp-admin.css (working copy) |
|---|
| 269 | @@ -4431,12 +4431,6 @@ |
|---|
| 270 | margin-top: 12px; |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | -.form-table input.tog { |
|---|
| 274 | - margin-top: 2px; |
|---|
| 275 | - margin-right: 2px; |
|---|
| 276 | - float: left; |
|---|
| 277 | -} |
|---|
| 278 | - |
|---|
| 279 | .form-table td p { |
|---|
| 280 | margin-top: 4px; |
|---|
| 281 | } |
|---|
| 282 | @@ -5134,18 +5128,45 @@ |
|---|
| 283 | margin: -3px 3px; |
|---|
| 284 | } |
|---|
| 285 | |
|---|
| 286 | -.js.options-reading-php .if-page-on-front, |
|---|
| 287 | -.js.options-reading-php .if-page-for-posts, |
|---|
| 288 | -.options-reading-php .if-new-front-page { |
|---|
| 289 | +#front-static-pages .pfp-wrapper { |
|---|
| 290 | + display: inline-block; |
|---|
| 291 | + position: relative; |
|---|
| 292 | +} |
|---|
| 293 | + |
|---|
| 294 | +#front-static-pages .pfp-wrapper .description { |
|---|
| 295 | + white-space: nowrap; |
|---|
| 296 | +} |
|---|
| 297 | + |
|---|
| 298 | +#front-static-pages .pfp-slash { |
|---|
| 299 | + left: 6px; |
|---|
| 300 | + position: absolute; |
|---|
| 301 | + top: 1px; |
|---|
| 302 | +} |
|---|
| 303 | + |
|---|
| 304 | +#page_for_posts_name { |
|---|
| 305 | + margin: 0; |
|---|
| 306 | + padding-left: 8px; |
|---|
| 307 | + width: 170px; |
|---|
| 308 | +} |
|---|
| 309 | + |
|---|
| 310 | +#page_on_front_title { |
|---|
| 311 | + margin: 0; |
|---|
| 312 | + width: 170px; |
|---|
| 313 | +} |
|---|
| 314 | + |
|---|
| 315 | +#front-static-pages .page-options { |
|---|
| 316 | display: none; |
|---|
| 317 | + margin-top: 8px; |
|---|
| 318 | } |
|---|
| 319 | -.options-reading-php .page-on-front .if-page-on-front, |
|---|
| 320 | -.options-reading-php .page-for-posts .if-page-for-posts { |
|---|
| 321 | + |
|---|
| 322 | +.page-options .sample-url { |
|---|
| 323 | + color: #888; |
|---|
| 324 | + font-size: 11px; |
|---|
| 325 | +} |
|---|
| 326 | + |
|---|
| 327 | +.static-front-page #front-static-pages .page-options { |
|---|
| 328 | display: block; |
|---|
| 329 | } |
|---|
| 330 | -.options-reading-php .new-front-page .if-new-front-page { |
|---|
| 331 | - display: inline; |
|---|
| 332 | -} |
|---|
| 333 | |
|---|
| 334 | /*------------------------------------------------------------------------------ |
|---|
| 335 | 21.0 - Admin Footer |
|---|
| 336 | Index: wp-admin/options-reading.php |
|---|
| 337 | =================================================================== |
|---|
| 338 | --- wp-admin/options-reading.php (revision 22380) |
|---|
| 339 | +++ wp-admin/options-reading.php (working copy) |
|---|
| 340 | @@ -16,6 +16,8 @@ |
|---|
| 341 | $parent_file = 'options-general.php'; |
|---|
| 342 | |
|---|
| 343 | wp_enqueue_script( 'sample-permalink' ); |
|---|
| 344 | +wp_enqueue_script( 'jquery-ui-core' ); |
|---|
| 345 | +wp_enqueue_script( 'jquery-ui-autocomplete' ); |
|---|
| 346 | |
|---|
| 347 | /** |
|---|
| 348 | * Display JavaScript on the page. |
|---|
| 349 | @@ -23,25 +25,107 @@ |
|---|
| 350 | * @since 3.5.0 |
|---|
| 351 | */ |
|---|
| 352 | function options_reading_add_js() { |
|---|
| 353 | + |
|---|
| 354 | +$all_pages = get_pages(); |
|---|
| 355 | + |
|---|
| 356 | +// Populate autocomplete options |
|---|
| 357 | +$page_titles_json = $page_names_json = array(); |
|---|
| 358 | + |
|---|
| 359 | +foreach ( $all_pages as $page ) { |
|---|
| 360 | + array_push( $page_titles_json, array( |
|---|
| 361 | + 'id' => $page->ID, |
|---|
| 362 | + 'label' => $page->post_title, |
|---|
| 363 | + 'post_name' => $page->post_name |
|---|
| 364 | + ) ); |
|---|
| 365 | + |
|---|
| 366 | + array_push( $page_names_json, array( |
|---|
| 367 | + 'id' => $page->ID, |
|---|
| 368 | + 'label' => $page->post_name, |
|---|
| 369 | + 'post_title' => $page->post_title |
|---|
| 370 | + ) ); |
|---|
| 371 | +} |
|---|
| 372 | ?> |
|---|
| 373 | <script> |
|---|
| 374 | -jQuery(document).ready( function($) { |
|---|
| 375 | - var section = $('#front-static-pages'); |
|---|
| 376 | - $('#show_on_front').change( function() { |
|---|
| 377 | - var checked = $(this).prop('checked'); |
|---|
| 378 | - section.toggleClass('page-on-front', checked); |
|---|
| 379 | - if ( checked ) |
|---|
| 380 | - $('#page_for_posts').prop('checked', true).change(); |
|---|
| 381 | - else |
|---|
| 382 | - section.removeClass('page-for-posts'); |
|---|
| 383 | - }); |
|---|
| 384 | - $('#page_for_posts').change( function() { |
|---|
| 385 | - section.toggleClass('page-for-posts', $(this).prop('checked')); |
|---|
| 386 | - }); |
|---|
| 387 | - $('#page_on_front').change( function() { |
|---|
| 388 | - section.toggleClass('new-front-page', 'new' === $(this).val()); |
|---|
| 389 | - }); |
|---|
| 390 | -}); |
|---|
| 391 | + jQuery( function( $ ) { |
|---|
| 392 | + var pageTitles = <?php echo json_encode( $page_titles_json ); ?>, |
|---|
| 393 | + pageNames = <?php echo json_encode( $page_names_json ); ?>; |
|---|
| 394 | + |
|---|
| 395 | + $( document ).ready( function () { |
|---|
| 396 | + $( '.tog' ).change( function () { |
|---|
| 397 | + if ( 'page' === $( this ).val() ) { |
|---|
| 398 | + $( '.form-table' ).addClass( 'static-front-page' ); |
|---|
| 399 | + } else { |
|---|
| 400 | + $( '.form-table' ).removeClass( 'static-front-page' ); |
|---|
| 401 | + } |
|---|
| 402 | + }); |
|---|
| 403 | + $( '#page_on_front_title' ).keyup( function () { |
|---|
| 404 | + |
|---|
| 405 | + // Hide edit link |
|---|
| 406 | + $( this ).parent().find( '.description' ).hide(); |
|---|
| 407 | + }); |
|---|
| 408 | + $( '#page_for_posts_name' ).keyup( function () { |
|---|
| 409 | + thisVal = $( this ).val(); |
|---|
| 410 | + |
|---|
| 411 | + // Update example URL |
|---|
| 412 | + $( '.page_for_posts_url' ).html( thisVal ); |
|---|
| 413 | + |
|---|
| 414 | + // Hide edit link |
|---|
| 415 | + $( this ).parent().find( '.description' ).hide(); |
|---|
| 416 | + }); |
|---|
| 417 | + }); |
|---|
| 418 | + |
|---|
| 419 | + addAutocomplete( 'page_on_front_title', pageTitles, 'page_on_front' ); |
|---|
| 420 | + addAutocomplete( 'page_for_posts_name', pageNames, 'page_for_posts' ); |
|---|
| 421 | + |
|---|
| 422 | + function addAutocomplete ( textbox, source, hidden ) { |
|---|
| 423 | + $( '#' + textbox ).autocomplete( { |
|---|
| 424 | + source: source, |
|---|
| 425 | + minLength: 1, |
|---|
| 426 | + delay: 0, |
|---|
| 427 | + autoFocus: true, |
|---|
| 428 | + response: function( event, ui ) { |
|---|
| 429 | + |
|---|
| 430 | + // If this value doesn't exist in dropdown, show 'add new page' option at top |
|---|
| 431 | + if ( ! isNewPage( source, $( this ).val() ) ) { |
|---|
| 432 | + ui.content.unshift( { |
|---|
| 433 | + 'id': 0, |
|---|
| 434 | + 'label': '-- Add new page --', |
|---|
| 435 | + 'post_name': null |
|---|
| 436 | + } ); |
|---|
| 437 | + } |
|---|
| 438 | + }, |
|---|
| 439 | + select: function( event, ui ) { |
|---|
| 440 | + var thisVal = $( this ).val(); |
|---|
| 441 | + |
|---|
| 442 | + // Update example URL on click |
|---|
| 443 | + if ( 'page_for_posts_name' === textbox ) |
|---|
| 444 | + $( '.page_for_posts_url' ).html( ui.item.label ); |
|---|
| 445 | + |
|---|
| 446 | + if ( 0 === ui.item.id ){ |
|---|
| 447 | + setTimeout( function () { |
|---|
| 448 | + $( '#' + textbox ).val( thisVal ).focus(); |
|---|
| 449 | + }, 30); |
|---|
| 450 | + } |
|---|
| 451 | + |
|---|
| 452 | + if ( ui.item.id ) { |
|---|
| 453 | + var thisId = ui.item.id; |
|---|
| 454 | + } else { |
|---|
| 455 | + var thisId = 'new'; |
|---|
| 456 | + } |
|---|
| 457 | + $( '#' + hidden ).val( thisId ); |
|---|
| 458 | + } |
|---|
| 459 | + } ); |
|---|
| 460 | + } |
|---|
| 461 | + function isNewPage ( source, label ) { |
|---|
| 462 | + |
|---|
| 463 | + for ( i=0; i<source.length; i++ ) { |
|---|
| 464 | + if ( label === source[i].label ) |
|---|
| 465 | + return true; |
|---|
| 466 | + } |
|---|
| 467 | + |
|---|
| 468 | + return false; |
|---|
| 469 | + } |
|---|
| 470 | + } ); |
|---|
| 471 | </script> |
|---|
| 472 | <?php |
|---|
| 473 | } |
|---|
| 474 | @@ -90,99 +174,97 @@ |
|---|
| 475 | <?php |
|---|
| 476 | settings_fields( 'reading' ); |
|---|
| 477 | wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); |
|---|
| 478 | -?> |
|---|
| 479 | -<table class="form-table"> |
|---|
| 480 | -<?php |
|---|
| 481 | -if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) |
|---|
| 482 | - add_settings_field( 'blog_charset', __( 'Encoding for pages and feeds' ), 'options_reading_blog_charset', 'reading', 'default', array( 'label_for' => 'blog_charset' ) ); |
|---|
| 483 | |
|---|
| 484 | $classes = ''; |
|---|
| 485 | if ( 'page' == get_option( 'show_on_front' ) ) { |
|---|
| 486 | - if ( ! get_pages() || ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) ) { |
|---|
| 487 | + $classes = 'static-front-page'; |
|---|
| 488 | + /*if ( ! get_pages() || ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) ) { |
|---|
| 489 | update_option( 'show_on_front', 'posts' ); |
|---|
| 490 | } else { |
|---|
| 491 | - $classes = 'page-on-front'; |
|---|
| 492 | - if ( get_option( 'page_for_posts' ) ) |
|---|
| 493 | - $classes .= ' page-for-posts'; |
|---|
| 494 | - } |
|---|
| 495 | + $classes = 'static-front-page'; |
|---|
| 496 | + }*/ |
|---|
| 497 | } |
|---|
| 498 | +?> |
|---|
| 499 | +<table class="form-table <?php echo $classes; ?>"> |
|---|
| 500 | +<?php |
|---|
| 501 | +if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) |
|---|
| 502 | + add_settings_field( 'blog_charset', __( 'Encoding for pages and feeds' ), 'options_reading_blog_charset', 'reading', 'default', array( 'label_for' => 'blog_charset' ) ); |
|---|
| 503 | |
|---|
| 504 | -$all_pages = get_pages(); |
|---|
| 505 | -$new_front_page_only = ! get_option( 'page_on_front' ) && ( ! $all_pages || ( 1 == count( $all_pages ) && __( 'sample-page' ) == $all_pages[0]->post_name ) ); |
|---|
| 506 | +$page_on_front = get_post( get_option( 'page_on_front' ) ); |
|---|
| 507 | +$page_for_posts = get_post( get_option( 'page_for_posts' ) ); |
|---|
| 508 | |
|---|
| 509 | -if ( current_user_can( 'create_posts', 'page' ) && ! ( get_option( 'page_for_posts' ) && $page_for_posts = get_post( get_option( 'page_for_posts' ) ) ) ) { |
|---|
| 510 | - $title = _x( 'Blog', 'default page for posts title' ); |
|---|
| 511 | - // @todo What if the found page is post_type = attachment or post_status != publish? |
|---|
| 512 | - // We could go ahead and create a new one, but we would not be able to take over |
|---|
| 513 | - // the slug from another page. (We could for an attachment.) |
|---|
| 514 | - // We must also check that the user can edit this page and publish a page. |
|---|
| 515 | - // Otherwise, we must assume they cannot create pages (throughout), and thus |
|---|
| 516 | - // should fall back to the dropdown. |
|---|
| 517 | - $page_for_posts = get_page_by_path( sanitize_title( $title ) ); |
|---|
| 518 | - if ( ! $page_for_posts || $page_for_posts->ID == get_option( 'page_on_front' ) ) { |
|---|
| 519 | - $page_for_posts = get_default_post_to_edit( 'page', true ); |
|---|
| 520 | - $page_for_posts->post_title = $title; |
|---|
| 521 | - $page_for_posts->post_name = sanitize_title( $title ); |
|---|
| 522 | - } |
|---|
| 523 | +// Setup empty vars |
|---|
| 524 | +$page_on_front_helper_text = $page_for_posts_helper_text = ''; |
|---|
| 525 | + |
|---|
| 526 | +if ( ! isset( $page_on_front ) ) { |
|---|
| 527 | + // Default for page_on_front |
|---|
| 528 | + $page_on_front->post_title = 'Home'; |
|---|
| 529 | +} else { |
|---|
| 530 | + // Show link to edit page if it exists |
|---|
| 531 | + $page_on_front_helper_text = sprintf( __( '<span class="description"> (<a href="%s">Edit</a>)</span>' ), 'post.php?post=' . $page_on_front->ID . '&action=edit' ); |
|---|
| 532 | } |
|---|
| 533 | |
|---|
| 534 | -if ( ! $new_front_page_only || current_user_can( 'create_posts', 'page' ) ) : ?> |
|---|
| 535 | -<tr valign="top"> |
|---|
| 536 | -<th scope="row"><?php _e( 'Enable a static front page' ); ?></th> |
|---|
| 537 | -<td id="front-static-pages" class="<?php echo $classes; ?>"> |
|---|
| 538 | - <fieldset><legend class="screen-reader-text"><span><?php _e( 'Enable a static front page' ); ?></span></legend> |
|---|
| 539 | - <p><label for="show_on_front"> |
|---|
| 540 | - <input id="show_on_front" name="show_on_front" type="checkbox" value="page" <?php checked( 'page', get_option( 'show_on_front' ) ); ?> /> |
|---|
| 541 | - <?php printf( __( 'Show a <a href="%s">page</a> instead of your latest posts' ), 'edit.php?post_type=page' ); ?> |
|---|
| 542 | - </label></p> |
|---|
| 543 | - <p class="if-page-on-front sub-option"> |
|---|
| 544 | - <?php if ( $new_front_page_only ) : // If no pages, or only sample page, only allow a new page to be added ?> |
|---|
| 545 | - <label for="page_on_front_title"><?php _e( 'Add new page titled:' ); ?> |
|---|
| 546 | - <?php else : ?> |
|---|
| 547 | - <label for="page_on_front"> |
|---|
| 548 | - <select name="page_on_front" id="page_on_front"> |
|---|
| 549 | - <option value="0"><?php _e( '— Select —' ); ?></option> |
|---|
| 550 | - <?php if ( current_user_can( 'create_posts', 'page' ) ) : ?> |
|---|
| 551 | - <option value="new" id="new-page"><?php _e( '— Add new page —' ); ?></option> |
|---|
| 552 | - <?php endif; ?> |
|---|
| 553 | - <?php echo walk_page_dropdown_tree( $all_pages, 0, array( 'selected' => get_option( 'page_on_front' ) ) ); ?> |
|---|
| 554 | - </select> |
|---|
| 555 | - </label> |
|---|
| 556 | - <?php if ( current_user_can( 'create_posts', 'page' ) ) : ?> |
|---|
| 557 | - <label for="page_on_front_title" class="if-new-front-page"><?php _e( 'titled:' ); ?> |
|---|
| 558 | - <?php endif; ?> |
|---|
| 559 | - <?php endif; ?> |
|---|
| 560 | - <?php if ( current_user_can( 'create_posts', 'page' ) ) : ?> |
|---|
| 561 | - <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' ); ?>" /> |
|---|
| 562 | - </label> |
|---|
| 563 | - <?php endif; ?> |
|---|
| 564 | - </p> |
|---|
| 565 | - <p class="if-page-on-front"><label for="page_for_posts"> |
|---|
| 566 | - <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' ) ); ?> /> |
|---|
| 567 | - <?php _e( 'Show latest posts on a separate page' ); ?> |
|---|
| 568 | - </label></p> |
|---|
| 569 | - <?php if ( current_user_can( 'create_posts', 'page' ) ) : ?> |
|---|
| 570 | - <p class="if-page-for-posts sub-option"><label for="page_for_posts_title"><?php _e( 'Page title:' ); ?> |
|---|
| 571 | - <input name="page_for_posts_title" type="text" id="page_for_posts_title" value="<?php echo esc_attr( htmlspecialchars( $page_for_posts->post_title ) ); ?>" /> |
|---|
| 572 | - </label></p> |
|---|
| 573 | - <p class="if-page-for-posts sub-option" id="edit-slug-box"> |
|---|
| 574 | - <?php echo get_sample_permalink_html( $page_for_posts->ID, $page_for_posts->post_title, $page_for_posts->post_name ); ?> |
|---|
| 575 | - </p> |
|---|
| 576 | - <input name="post_name" type="hidden" id="post_name" value="<?php echo esc_attr( apply_filters( 'editable_slug', $page_for_posts->post_name ) ); ?>" /> |
|---|
| 577 | - <?php if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == get_option( 'page_on_front' ) ) : ?> |
|---|
| 578 | - <div class="error inline"><p><strong><?php _e( 'ERROR:' ); ?></strong> <?php _e( 'These pages should not be the same!' ); ?></p></div> |
|---|
| 579 | - <?php endif; ?> |
|---|
| 580 | - </fieldset> |
|---|
| 581 | - <?php else : // cannot create pages, so fall back to a selector of existing pages ?> |
|---|
| 582 | - <p class="if-page-for-posts sub-option"><label for="page_for_posts"> |
|---|
| 583 | - <?php wp_dropdown_pages( array( |
|---|
| 584 | - 'name' => 'page_for_posts', 'show_option_none' => __( '— Select —' ), |
|---|
| 585 | - 'option_none_value' => '0', 'selected' => get_option( 'page_for_posts' ) |
|---|
| 586 | - ) ); ?> |
|---|
| 587 | - <?php endif; // create pages ?> |
|---|
| 588 | -</td> |
|---|
| 589 | +if ( ! isset( $page_for_posts ) ) { |
|---|
| 590 | + // Default for page_for_posts |
|---|
| 591 | + $page_for_posts->post_name = 'blog'; |
|---|
| 592 | +} else { |
|---|
| 593 | + // Show link to edit page if it exists |
|---|
| 594 | + $page_for_posts_helper_text = sprintf( __( '<span class="description"> (<a href="%s">Edit</a>)</span>' ), 'post.php?post=' . $page_for_posts->ID . '&action=edit' ); |
|---|
| 595 | +} |
|---|
| 596 | +?> |
|---|
| 597 | + |
|---|
| 598 | +<tr> |
|---|
| 599 | + <th scope="row"><?php _e( 'Front page displays' ); ?></th> |
|---|
| 600 | + <td id="front-static-pages" class="<?php echo $classes; ?>"> |
|---|
| 601 | + <fieldset> |
|---|
| 602 | + <legend class="screen-reader-text"> |
|---|
| 603 | + <span><?php _e( 'Front page displays' ); ?></span> |
|---|
| 604 | + </legend> |
|---|
| 605 | + <label> |
|---|
| 606 | + <input name="show_on_front" type="radio" value="posts" class="tog" <?php checked( 'posts', get_option( 'show_on_front' ) ); ?> /> |
|---|
| 607 | + <span class="radio-label"><?php _e( 'Your latest posts' ); ?></span> |
|---|
| 608 | + </label> |
|---|
| 609 | + <br /> |
|---|
| 610 | + <label> |
|---|
| 611 | + <input name="show_on_front" type="radio" value="page" class="tog" <?php checked( 'page', get_option( 'show_on_front' ) ); ?> /> |
|---|
| 612 | + <span class="radio-label"><?php _e( 'A static page' ); ?></span> |
|---|
| 613 | + </label> |
|---|
| 614 | + <div class="page-options"> |
|---|
| 615 | + <label> |
|---|
| 616 | + <?php _e( 'Enter a title for your static front page.' ); ?><br /> |
|---|
| 617 | + <?php if ( current_user_can( 'create_posts', 'page' ) ) : ?> |
|---|
| 618 | + <input name="page_on_front_title" type="text" id="page_on_front_title" value="<?php echo esc_attr_x( $page_on_front->post_title, 'default page on front title' ); ?>" /> |
|---|
| 619 | + <?php echo $page_on_front_helper_text; ?> |
|---|
| 620 | + <?php else : // cannot create pages, so fall back to a selector of existing pages ?> |
|---|
| 621 | + <?php wp_dropdown_pages( array( |
|---|
| 622 | + 'name' => 'page_on_front', 'show_option_none' => __( '— Select —' ), |
|---|
| 623 | + 'option_none_value' => '0', 'selected' => get_option( 'page_on_front' ) |
|---|
| 624 | + ) ); ?> |
|---|
| 625 | + <?php endif; // cannot create pages ?> |
|---|
| 626 | + </label> |
|---|
| 627 | + </div> |
|---|
| 628 | + <div class="page-options"> |
|---|
| 629 | + <label> |
|---|
| 630 | + <?php _e( 'Choose a URL for your latests posts.' ); ?><br /> |
|---|
| 631 | + <div class="pfp-wrapper"> |
|---|
| 632 | + <?php if ( current_user_can( 'create_posts', 'page' ) ) : ?> |
|---|
| 633 | + <div class="pfp-slash">/</div> |
|---|
| 634 | + <input name="page_for_posts_name" type="text" id="page_for_posts_name" value="<?php echo esc_attr_x( $page_for_posts->post_name, 'default page for posts name' ); ?>" /> |
|---|
| 635 | + <?php echo $page_for_posts_helper_text; ?> |
|---|
| 636 | + <br /> |
|---|
| 637 | + <span class="sample-url"><?php echo get_site_url(); ?>/<strong class="page_for_posts_url"><?php echo $page_for_posts->post_name; ?></strong></span> |
|---|
| 638 | + <?php else : // cannot create pages, so fall back to a selector of existing pages ?> |
|---|
| 639 | + <?php wp_dropdown_pages( array( |
|---|
| 640 | + 'name' => 'page_for_posts', 'show_option_none' => __( '— Select —' ), |
|---|
| 641 | + 'option_none_value' => '0', 'selected' => get_option( 'page_for_posts' ) |
|---|
| 642 | + ) ); ?> |
|---|
| 643 | + <?php endif; // cannot create pages ?> |
|---|
| 644 | + </div> |
|---|
| 645 | + </label> |
|---|
| 646 | + </div> |
|---|
| 647 | + </fieldset> |
|---|
| 648 | + </td> |
|---|
| 649 | </tr> |
|---|
| 650 | -<?php endif; // if no pages to choose from and can't create pages ?> |
|---|
| 651 | |
|---|
| 652 | <tr valign="top"> |
|---|
| 653 | <th scope="row"><label for="posts_per_page"><?php _e( 'Blog pages show at most' ); ?></label></th> |
|---|