| 1 | Index: wp-includes/script-loader.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-includes/script-loader.php (revision 22121) |
|---|
| 4 | +++ wp-includes/script-loader.php (working copy) |
|---|
| 5 | @@ -369,10 +369,14 @@ |
|---|
| 6 | |
|---|
| 7 | $scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array('jquery-ui-sortable'), false, 1 ); |
|---|
| 8 | |
|---|
| 9 | - $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox'), false, 1 ); |
|---|
| 10 | - did_action( 'init' ) && $scripts->localize( 'post', 'postL10n', array( |
|---|
| 11 | + $scripts->add( 'sample-permalink', "/wp-admin/js/sample-permalink.js", array(), false, 1 ); |
|---|
| 12 | + did_action( 'init' ) && $scripts->localize( 'sample-permalink', 'samplePermalinkL10n', array( |
|---|
| 13 | 'ok' => __('OK'), |
|---|
| 14 | 'cancel' => __('Cancel'), |
|---|
| 15 | + ) ); |
|---|
| 16 | + |
|---|
| 17 | + $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox', 'sample-permalink' ), false, 1 ); |
|---|
| 18 | + did_action( 'init' ) && $scripts->localize( 'post', 'postL10n', array( |
|---|
| 19 | 'publishOn' => __('Publish on:'), |
|---|
| 20 | 'publishOnFuture' => __('Schedule for:'), |
|---|
| 21 | 'publishOnPast' => __('Published on:'), |
|---|
| 22 | Index: wp-admin/includes/post.php |
|---|
| 23 | =================================================================== |
|---|
| 24 | --- wp-admin/includes/post.php (revision 22121) |
|---|
| 25 | +++ wp-admin/includes/post.php (working copy) |
|---|
| 26 | @@ -1062,6 +1062,7 @@ |
|---|
| 27 | global $wpdb; |
|---|
| 28 | $post = get_post($id); |
|---|
| 29 | |
|---|
| 30 | + $context = isset( $_POST['context'] ) ? $_POST['context'] : get_current_screen()->id; |
|---|
| 31 | list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug); |
|---|
| 32 | |
|---|
| 33 | if ( 'publish' == get_post_status( $post ) ) { |
|---|
| 34 | @@ -1073,6 +1074,8 @@ |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) { |
|---|
| 38 | + if ( 'options-reading' == $context ) |
|---|
| 39 | + return ''; |
|---|
| 40 | $return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink" tabindex="-1">' . $permalink . "</span>\n"; |
|---|
| 41 | if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) ) |
|---|
| 42 | $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small" target="_blank">' . __('Change Permalinks') . "</a></span>\n"; |
|---|
| 43 | @@ -1101,12 +1104,12 @@ |
|---|
| 44 | $post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>'; |
|---|
| 45 | $display_link = str_replace(array('%pagename%','%postname%'), $post_name_html, $permalink); |
|---|
| 46 | $view_link = str_replace(array('%pagename%','%postname%'), $post_name, $permalink); |
|---|
| 47 | - $return = '<strong>' . __('Permalink:') . "</strong>\n"; |
|---|
| 48 | + $return = ( 'options-reading' == $context ) ? __( 'Located at' ) . "\n" : '<strong>' . __( 'Permalink:' ) . "</strong>\n"; |
|---|
| 49 | $return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n"; |
|---|
| 50 | $return .= '‎'; // Fix bi-directional text display defect in RTL languages. |
|---|
| 51 | $return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button button-small hide-if-no-js" onclick="editPermalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n"; |
|---|
| 52 | $return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n"; |
|---|
| 53 | - if ( isset($view_post) ) |
|---|
| 54 | + if ( isset( $view_post ) && 'options-reading' != $context ) |
|---|
| 55 | $return .= "<span id='view-post-btn'><a href='$view_link' class='button button-small'>$view_post</a></span>\n"; |
|---|
| 56 | |
|---|
| 57 | $return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug); |
|---|
| 58 | @@ -1322,3 +1325,87 @@ |
|---|
| 59 | |
|---|
| 60 | return $url; |
|---|
| 61 | } |
|---|
| 62 | + |
|---|
| 63 | +/** |
|---|
| 64 | + * Creates new pages to be set as a front page or a page for posts in Reading Settings. |
|---|
| 65 | + * |
|---|
| 66 | + * @todo Make sure we are doing adequate sanitization on success, and cleanup/reset on failure. |
|---|
| 67 | + * |
|---|
| 68 | + * @since 3.5.0 |
|---|
| 69 | + * @access private |
|---|
| 70 | + */ |
|---|
| 71 | +function _create_pages_for_reading_settings() { |
|---|
| 72 | + // If we're saving the Reading Settings screen, intercept. |
|---|
| 73 | + if ( ! isset( $_POST['show_on_front'] ) ) |
|---|
| 74 | + return; |
|---|
| 75 | + |
|---|
| 76 | + // If a new front page was meant to be created, go forth and create it. |
|---|
| 77 | + if ( isset( $_POST['page_on_front'] ) && 'new' == $_POST['page_on_front'] ) { |
|---|
| 78 | + if ( ! current_user_can( 'create_posts', 'page' ) ) { |
|---|
| 79 | + $_POST['page_on_front'] = 0; |
|---|
| 80 | + $_POST['show_on_front'] = 'posts'; |
|---|
| 81 | + add_settings_error( 'page_on_front', __( 'You are not allowed to create pages on this site.' ) ); |
|---|
| 82 | + } |
|---|
| 83 | + |
|---|
| 84 | + $existing_page = get_page_by_title( stripslashes( $_POST['page_on_front_title'] ) ); |
|---|
| 85 | + |
|---|
| 86 | + // If page already exists and it's public, there's no need to create a new page |
|---|
| 87 | + if ( $existing_page && 'publish' == $existing_page->post_status ) { |
|---|
| 88 | + $page_id = $existing_page->ID; |
|---|
| 89 | + } else { |
|---|
| 90 | + $page_id = wp_insert_post( array( |
|---|
| 91 | + 'post_title' => $_POST['page_on_front_title'], |
|---|
| 92 | + 'post_type' => 'page', |
|---|
| 93 | + 'post_status' => 'publish', |
|---|
| 94 | + 'comment_status' => 'closed', |
|---|
| 95 | + 'ping_status' => 'closed', |
|---|
| 96 | + // @todo Create some sort of a 'context' in postmeta so we know we created a page through these means. |
|---|
| 97 | + // Consider then showing that context in the list table as a good-first-step. |
|---|
| 98 | + ), true ); |
|---|
| 99 | + } |
|---|
| 100 | + |
|---|
| 101 | + // Make sure page_on_front is properly saved by options.php. |
|---|
| 102 | + if ( is_wp_error( $page_id ) ) |
|---|
| 103 | + $_POST['page_on_front'] = 0; |
|---|
| 104 | + else |
|---|
| 105 | + $_POST['page_on_front'] = $page_id; |
|---|
| 106 | + } |
|---|
| 107 | + |
|---|
| 108 | + // If a page for posts was meant to be specified, update/create it. |
|---|
| 109 | + if ( ! isset( $_POST['page_for_posts'] ) ) |
|---|
| 110 | + return; |
|---|
| 111 | + |
|---|
| 112 | + $page_for_posts = (int) $_POST['page_for_posts']; |
|---|
| 113 | + if ( ! $page_for_posts || ! $page = get_post( $page_for_posts, ARRAY_A ) ) { |
|---|
| 114 | + $_POST['page_for_posts'] = 0; |
|---|
| 115 | + return; |
|---|
| 116 | + } |
|---|
| 117 | + |
|---|
| 118 | + // @todo The UI (see @todo's in options-reading) should cover the next 3 conditionals, |
|---|
| 119 | + // which means we shouldn't need to bother with setting a settings error here. |
|---|
| 120 | + // However, we may wish to restore settings before bailing, beyond setting |
|---|
| 121 | + // page_for_posts to 0 (which we then expect to get cleaned up by options.php). |
|---|
| 122 | + if ( 'page' != $page['post_type'] || ! current_user_can( 'edit_post', $page_for_posts ) ) { |
|---|
| 123 | + $_POST['page_for_posts'] = 0; |
|---|
| 124 | + return; |
|---|
| 125 | + } |
|---|
| 126 | + |
|---|
| 127 | + if ( 'publish' != $page['post_status'] && ! current_user_can( 'publish_post', $page_for_posts ) ) { |
|---|
| 128 | + $_POST['page_for_posts'] = 0; |
|---|
| 129 | + return; |
|---|
| 130 | + } |
|---|
| 131 | + |
|---|
| 132 | + $args = add_magic_quotes( $page ); |
|---|
| 133 | + $args['post_title'] = $_POST['page_for_posts_title']; |
|---|
| 134 | + $args['post_name'] = $_POST['post_name']; |
|---|
| 135 | + $args['post_status'] = 'publish'; |
|---|
| 136 | + if ( 'auto-draft' == $page->post_status ) { |
|---|
| 137 | + $args['comment_status'] = 'closed'; |
|---|
| 138 | + $args['ping_status'] = 'closed'; |
|---|
| 139 | + } |
|---|
| 140 | + |
|---|
| 141 | + $page_id = wp_insert_post( $args, true ); |
|---|
| 142 | + if ( is_wp_error( $page_id ) ) |
|---|
| 143 | + $_POST['page_for_posts'] = 0; |
|---|
| 144 | +} |
|---|
| 145 | +add_filter( 'admin_init', '_create_pages_for_reading_settings' ); |
|---|
| 146 | Index: wp-admin/js/sample-permalink.js |
|---|
| 147 | =================================================================== |
|---|
| 148 | --- wp-admin/js/sample-permalink.js (revision 0) |
|---|
| 149 | +++ wp-admin/js/sample-permalink.js (revision 0) |
|---|
| 150 | @@ -0,0 +1,75 @@ |
|---|
| 151 | +var editPermalink, makeSlugeditClickable; |
|---|
| 152 | + |
|---|
| 153 | +(function($){ |
|---|
| 154 | + if ( ! $('#edit-slug-box').length ) |
|---|
| 155 | + return; |
|---|
| 156 | + editPermalink = function(post_id) { |
|---|
| 157 | + var i, c = 0, |
|---|
| 158 | + e = $('#editable-post-name'), |
|---|
| 159 | + revert_e = e.html(), |
|---|
| 160 | + real_slug = $('#post_name'), |
|---|
| 161 | + revert_slug = real_slug.val(), |
|---|
| 162 | + b = $('#edit-slug-buttons'), |
|---|
| 163 | + revert_b = b.html(), |
|---|
| 164 | + full = $('#editable-post-name-full').html(); |
|---|
| 165 | + |
|---|
| 166 | + $('#view-post-btn').hide(); |
|---|
| 167 | + b.html('<a href="#" class="save button button-small">'+samplePermalinkL10n.ok+'</a> <a class="cancel" href="#">'+samplePermalinkL10n.cancel+'</a>'); |
|---|
| 168 | + b.children('.save').click(function() { |
|---|
| 169 | + var new_slug = e.children('input').val(); |
|---|
| 170 | + if ( new_slug == $('#editable-post-name-full').text() ) { |
|---|
| 171 | + return $('.cancel', '#edit-slug-buttons').click(); |
|---|
| 172 | + } |
|---|
| 173 | + $.post(ajaxurl, { |
|---|
| 174 | + action: 'sample-permalink', |
|---|
| 175 | + post_id: post_id, |
|---|
| 176 | + new_slug: new_slug, |
|---|
| 177 | + new_title: $('#title').val(), |
|---|
| 178 | + context: pagenow, |
|---|
| 179 | + samplepermalinknonce: $('#samplepermalinknonce').val() |
|---|
| 180 | + }, function(data) { |
|---|
| 181 | + $('#edit-slug-box').html(data); |
|---|
| 182 | + b.html(revert_b); |
|---|
| 183 | + real_slug.val(new_slug); |
|---|
| 184 | + makeSlugeditClickable(); |
|---|
| 185 | + $('#view-post-btn').show(); |
|---|
| 186 | + }); |
|---|
| 187 | + return false; |
|---|
| 188 | + }); |
|---|
| 189 | + |
|---|
| 190 | + $('.cancel', '#edit-slug-buttons').click(function() { |
|---|
| 191 | + $('#view-post-btn').show(); |
|---|
| 192 | + e.html(revert_e); |
|---|
| 193 | + b.html(revert_b); |
|---|
| 194 | + real_slug.val(revert_slug); |
|---|
| 195 | + return false; |
|---|
| 196 | + }); |
|---|
| 197 | + |
|---|
| 198 | + for ( i = 0; i < full.length; ++i ) { |
|---|
| 199 | + if ( '%' == full.charAt(i) ) |
|---|
| 200 | + c++; |
|---|
| 201 | + } |
|---|
| 202 | + |
|---|
| 203 | + slug_value = ( c > full.length / 4 ) ? '' : full; |
|---|
| 204 | + e.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children('input').keypress(function(e){ |
|---|
| 205 | + var key = e.keyCode || 0; |
|---|
| 206 | + // on enter, just save the new slug, don't save the post |
|---|
| 207 | + if ( 13 == key ) { |
|---|
| 208 | + b.children('.save').click(); |
|---|
| 209 | + return false; |
|---|
| 210 | + } |
|---|
| 211 | + if ( 27 == key ) { |
|---|
| 212 | + b.children('.cancel').click(); |
|---|
| 213 | + return false; |
|---|
| 214 | + } |
|---|
| 215 | + real_slug.val(this.value); |
|---|
| 216 | + }).focus(); |
|---|
| 217 | + } |
|---|
| 218 | + |
|---|
| 219 | + makeSlugeditClickable = function() { |
|---|
| 220 | + $('#editable-post-name').click(function() { |
|---|
| 221 | + $('#edit-slug-buttons').children('.edit-slug').click(); |
|---|
| 222 | + }); |
|---|
| 223 | + } |
|---|
| 224 | + makeSlugeditClickable(); |
|---|
| 225 | +})(jQuery); |
|---|
| 226 | \ No newline at end of file |
|---|
| 227 | Index: wp-admin/js/post.js |
|---|
| 228 | =================================================================== |
|---|
| 229 | --- wp-admin/js/post.js (revision 22121) |
|---|
| 230 | +++ wp-admin/js/post.js (working copy) |
|---|
| 231 | @@ -559,71 +559,6 @@ |
|---|
| 232 | }); |
|---|
| 233 | } // end submitdiv |
|---|
| 234 | |
|---|
| 235 | - // permalink |
|---|
| 236 | - if ( $('#edit-slug-box').length ) { |
|---|
| 237 | - editPermalink = function(post_id) { |
|---|
| 238 | - var i, c = 0, e = $('#editable-post-name'), revert_e = e.html(), real_slug = $('#post_name'), revert_slug = real_slug.val(), b = $('#edit-slug-buttons'), revert_b = b.html(), full = $('#editable-post-name-full').html(); |
|---|
| 239 | - |
|---|
| 240 | - $('#view-post-btn').hide(); |
|---|
| 241 | - b.html('<a href="#" class="save button button-small">'+postL10n.ok+'</a> <a class="cancel" href="#">'+postL10n.cancel+'</a>'); |
|---|
| 242 | - b.children('.save').click(function() { |
|---|
| 243 | - var new_slug = e.children('input').val(); |
|---|
| 244 | - if ( new_slug == $('#editable-post-name-full').text() ) { |
|---|
| 245 | - return $('.cancel', '#edit-slug-buttons').click(); |
|---|
| 246 | - } |
|---|
| 247 | - $.post(ajaxurl, { |
|---|
| 248 | - action: 'sample-permalink', |
|---|
| 249 | - post_id: post_id, |
|---|
| 250 | - new_slug: new_slug, |
|---|
| 251 | - new_title: $('#title').val(), |
|---|
| 252 | - samplepermalinknonce: $('#samplepermalinknonce').val() |
|---|
| 253 | - }, function(data) { |
|---|
| 254 | - $('#edit-slug-box').html(data); |
|---|
| 255 | - b.html(revert_b); |
|---|
| 256 | - real_slug.val(new_slug); |
|---|
| 257 | - makeSlugeditClickable(); |
|---|
| 258 | - $('#view-post-btn').show(); |
|---|
| 259 | - }); |
|---|
| 260 | - return false; |
|---|
| 261 | - }); |
|---|
| 262 | - |
|---|
| 263 | - $('.cancel', '#edit-slug-buttons').click(function() { |
|---|
| 264 | - $('#view-post-btn').show(); |
|---|
| 265 | - e.html(revert_e); |
|---|
| 266 | - b.html(revert_b); |
|---|
| 267 | - real_slug.val(revert_slug); |
|---|
| 268 | - return false; |
|---|
| 269 | - }); |
|---|
| 270 | - |
|---|
| 271 | - for ( i = 0; i < full.length; ++i ) { |
|---|
| 272 | - if ( '%' == full.charAt(i) ) |
|---|
| 273 | - c++; |
|---|
| 274 | - } |
|---|
| 275 | - |
|---|
| 276 | - slug_value = ( c > full.length / 4 ) ? '' : full; |
|---|
| 277 | - e.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children('input').keypress(function(e){ |
|---|
| 278 | - var key = e.keyCode || 0; |
|---|
| 279 | - // on enter, just save the new slug, don't save the post |
|---|
| 280 | - if ( 13 == key ) { |
|---|
| 281 | - b.children('.save').click(); |
|---|
| 282 | - return false; |
|---|
| 283 | - } |
|---|
| 284 | - if ( 27 == key ) { |
|---|
| 285 | - b.children('.cancel').click(); |
|---|
| 286 | - return false; |
|---|
| 287 | - } |
|---|
| 288 | - real_slug.val(this.value); |
|---|
| 289 | - }).focus(); |
|---|
| 290 | - } |
|---|
| 291 | - |
|---|
| 292 | - makeSlugeditClickable = function() { |
|---|
| 293 | - $('#editable-post-name').click(function() { |
|---|
| 294 | - $('#edit-slug-buttons').children('.edit-slug').click(); |
|---|
| 295 | - }); |
|---|
| 296 | - } |
|---|
| 297 | - makeSlugeditClickable(); |
|---|
| 298 | - } |
|---|
| 299 | - |
|---|
| 300 | // word count |
|---|
| 301 | if ( typeof(wpWordCount) != 'undefined' ) { |
|---|
| 302 | $(document).triggerHandler('wpcountwords', [ co.val() ]); |
|---|
| 303 | Index: wp-admin/css/wp-admin-rtl.css |
|---|
| 304 | =================================================================== |
|---|
| 305 | --- wp-admin/css/wp-admin-rtl.css (revision 22121) |
|---|
| 306 | +++ wp-admin/css/wp-admin-rtl.css (working copy) |
|---|
| 307 | @@ -915,8 +915,7 @@ |
|---|
| 308 | border-bottom-right-radius: 3px; |
|---|
| 309 | } |
|---|
| 310 | |
|---|
| 311 | -#front-page-warning, |
|---|
| 312 | -#front-static-pages ul, |
|---|
| 313 | +#front-static-pages .sub-option, |
|---|
| 314 | ul.export-filters, |
|---|
| 315 | .inline-editor ul.cat-checklist ul, |
|---|
| 316 | .categorydiv ul.categorychecklist ul, |
|---|
| 317 | Index: wp-admin/css/wp-admin.css |
|---|
| 318 | =================================================================== |
|---|
| 319 | --- wp-admin/css/wp-admin.css (revision 22121) |
|---|
| 320 | +++ wp-admin/css/wp-admin.css (working copy) |
|---|
| 321 | @@ -2929,6 +2929,10 @@ |
|---|
| 322 | font-size: 11px; |
|---|
| 323 | } |
|---|
| 324 | |
|---|
| 325 | +#front-static-pages #edit-slug-box { |
|---|
| 326 | + padding: 0; |
|---|
| 327 | +} |
|---|
| 328 | + |
|---|
| 329 | #editable-post-name-full { |
|---|
| 330 | display: none; |
|---|
| 331 | } |
|---|
| 332 | @@ -3414,8 +3418,7 @@ |
|---|
| 333 | margin: 0; |
|---|
| 334 | } |
|---|
| 335 | |
|---|
| 336 | -#front-page-warning, |
|---|
| 337 | -#front-static-pages ul, |
|---|
| 338 | +#front-static-pages .sub-option, |
|---|
| 339 | ul.export-filters, |
|---|
| 340 | .inline-editor ul.cat-checklist ul, |
|---|
| 341 | .categorydiv ul.categorychecklist ul, |
|---|
| 342 | @@ -4988,6 +4991,19 @@ |
|---|
| 343 | margin: -3px 3px; |
|---|
| 344 | } |
|---|
| 345 | |
|---|
| 346 | +.js.options-reading-php .if-page-on-front, |
|---|
| 347 | +.js.options-reading-php .if-page-for-posts, |
|---|
| 348 | +.options-reading-php .if-new-front-page { |
|---|
| 349 | + display: none; |
|---|
| 350 | +} |
|---|
| 351 | +.options-reading-php .page-on-front .if-page-on-front, |
|---|
| 352 | +.options-reading-php .page-for-posts .if-page-for-posts { |
|---|
| 353 | + display: block; |
|---|
| 354 | +} |
|---|
| 355 | +.options-reading-php .new-front-page .if-new-front-page { |
|---|
| 356 | + display: inline; |
|---|
| 357 | +} |
|---|
| 358 | + |
|---|
| 359 | /*------------------------------------------------------------------------------ |
|---|
| 360 | 21.0 - Admin Footer |
|---|
| 361 | ------------------------------------------------------------------------------*/ |
|---|
| 362 | Index: wp-admin/options-reading.php |
|---|
| 363 | =================================================================== |
|---|
| 364 | --- wp-admin/options-reading.php (revision 22121) |
|---|
| 365 | +++ wp-admin/options-reading.php (working copy) |
|---|
| 366 | @@ -15,6 +15,8 @@ |
|---|
| 367 | $title = __( 'Reading Settings' ); |
|---|
| 368 | $parent_file = 'options-general.php'; |
|---|
| 369 | |
|---|
| 370 | +wp_enqueue_script( 'sample-permalink' ); |
|---|
| 371 | + |
|---|
| 372 | /** |
|---|
| 373 | * Display JavaScript on the page. |
|---|
| 374 | * |
|---|
| 375 | @@ -22,23 +24,26 @@ |
|---|
| 376 | */ |
|---|
| 377 | function options_reading_add_js() { |
|---|
| 378 | ?> |
|---|
| 379 | -<script type="text/javascript"> |
|---|
| 380 | -//<![CDATA[ |
|---|
| 381 | - jQuery(document).ready(function($){ |
|---|
| 382 | - var section = $('#front-static-pages'), |
|---|
| 383 | - staticPage = section.find('input:radio[value="page"]'), |
|---|
| 384 | - selects = section.find('select'), |
|---|
| 385 | - check_disabled = function(){ |
|---|
| 386 | - selects.prop( 'disabled', ! staticPage.prop('checked') ); |
|---|
| 387 | - }; |
|---|
| 388 | - check_disabled(); |
|---|
| 389 | - section.find('input:radio').change(check_disabled); |
|---|
| 390 | +<script> |
|---|
| 391 | +jQuery(document).ready( function($) { |
|---|
| 392 | + var section = $('#front-static-pages'); |
|---|
| 393 | + $('#show_on_front').change( function() { |
|---|
| 394 | + var checked = $(this).prop('checked'); |
|---|
| 395 | + section.toggleClass('page-on-front', checked); |
|---|
| 396 | + if ( checked ) |
|---|
| 397 | + $('#page_for_posts').prop('checked', true).change(); |
|---|
| 398 | }); |
|---|
| 399 | -//]]> |
|---|
| 400 | + $('#page_for_posts').change( function() { |
|---|
| 401 | + section.toggleClass('page-for-posts', $(this).prop('checked')); |
|---|
| 402 | + }); |
|---|
| 403 | + $('#page_on_front').change( function() { |
|---|
| 404 | + section.toggleClass('new-front-page', 'new' === $(this).val()); |
|---|
| 405 | + }); |
|---|
| 406 | +}); |
|---|
| 407 | </script> |
|---|
| 408 | <?php |
|---|
| 409 | } |
|---|
| 410 | -add_action('admin_head', 'options_reading_add_js'); |
|---|
| 411 | +add_action( 'admin_head', 'options_reading_add_js' ); |
|---|
| 412 | |
|---|
| 413 | /** |
|---|
| 414 | * Render the blog charset setting. |
|---|
| 415 | @@ -82,47 +87,100 @@ |
|---|
| 416 | <form method="post" action="options.php"> |
|---|
| 417 | <?php |
|---|
| 418 | settings_fields( 'reading' ); |
|---|
| 419 | - |
|---|
| 420 | +wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); |
|---|
| 421 | +?> |
|---|
| 422 | +<table class="form-table"> |
|---|
| 423 | +<?php |
|---|
| 424 | if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) |
|---|
| 425 | add_settings_field( 'blog_charset', __( 'Encoding for pages and feeds' ), 'options_reading_blog_charset', 'reading', 'default', array( 'label_for' => 'blog_charset' ) ); |
|---|
| 426 | -?> |
|---|
| 427 | |
|---|
| 428 | -<?php if ( ! get_pages() ) : ?> |
|---|
| 429 | -<input name="show_on_front" type="hidden" value="posts" /> |
|---|
| 430 | -<table class="form-table"> |
|---|
| 431 | -<?php |
|---|
| 432 | - if ( 'posts' != get_option( 'show_on_front' ) ) : |
|---|
| 433 | +$classes = ''; |
|---|
| 434 | +if ( 'page' == get_option( 'show_on_front' ) ) { |
|---|
| 435 | + if ( ! get_pages() || ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) ) { |
|---|
| 436 | update_option( 'show_on_front', 'posts' ); |
|---|
| 437 | - endif; |
|---|
| 438 | + } else { |
|---|
| 439 | + $classes = 'page-on-front'; |
|---|
| 440 | + if ( get_option( 'page_for_posts' ) ) |
|---|
| 441 | + $classes .= ' page-for-posts'; |
|---|
| 442 | + } |
|---|
| 443 | +} |
|---|
| 444 | |
|---|
| 445 | -else : |
|---|
| 446 | - if ( 'page' == get_option( 'show_on_front' ) && ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) ) |
|---|
| 447 | - update_option( 'show_on_front', 'posts' ); |
|---|
| 448 | -?> |
|---|
| 449 | -<table class="form-table"> |
|---|
| 450 | +$all_pages = get_pages(); |
|---|
| 451 | +$new_front_page_only = ! get_option( 'page_on_front' ) && ( ! $all_pages || ( 1 == count( $all_pages ) && __( 'sample-page' ) == $all_pages[0]->post_name ) ); |
|---|
| 452 | + |
|---|
| 453 | +if ( current_user_can( 'create_posts', 'page' ) && ! ( get_option( 'page_for_posts' ) && $page_for_posts = get_post( get_option( 'page_for_posts' ) ) ) ) { |
|---|
| 454 | + $title = _x( 'Blog', 'default page for posts title' ); |
|---|
| 455 | + // @todo What if the found page is post_type = attachment or post_status != publish? |
|---|
| 456 | + // We could go ahead and create a new one, but we would not be able to take over |
|---|
| 457 | + // the slug from another page. (We could for an attachment.) |
|---|
| 458 | + // We must also check that the user can edit this page and publish a page. |
|---|
| 459 | + // Otherwise, we must assume they cannot create pages (throughout), and thus |
|---|
| 460 | + // should fall back to the dropdown. |
|---|
| 461 | + if ( ! $page_for_posts = get_page_by_path( sanitize_title( $title ) ) ) { |
|---|
| 462 | + $page_for_posts = get_default_post_to_edit( 'page', true ); |
|---|
| 463 | + $page_for_posts->post_title = $title; |
|---|
| 464 | + $page_for_posts->post_name = sanitize_title( $title ); |
|---|
| 465 | + } |
|---|
| 466 | +} |
|---|
| 467 | + |
|---|
| 468 | +if ( ! $new_front_page_only || current_user_can( 'create_posts', 'page' ) ) : ?> |
|---|
| 469 | <tr valign="top"> |
|---|
| 470 | -<th scope="row"><?php _e( 'Front page displays' ); ?></th> |
|---|
| 471 | -<td id="front-static-pages"><fieldset><legend class="screen-reader-text"><span><?php _e( 'Front page displays' ); ?></span></legend> |
|---|
| 472 | - <p><label> |
|---|
| 473 | - <input name="show_on_front" type="radio" value="posts" class="tog" <?php checked( 'posts', get_option( 'show_on_front' ) ); ?> /> |
|---|
| 474 | - <?php _e( 'Your latest posts' ); ?> |
|---|
| 475 | - </label> |
|---|
| 476 | +<th scope="row"><?php _e( 'Enable a static front page' ); ?></th> |
|---|
| 477 | +<td id="front-static-pages" class="<?php echo $classes; ?>"> |
|---|
| 478 | + <fieldset><legend class="screen-reader-text"><span><?php _e( 'Enable a static front page' ); ?></span></legend> |
|---|
| 479 | + <p><label for="show_on_front"> |
|---|
| 480 | + <input id="show_on_front" name="show_on_front" type="checkbox" value="page" <?php checked( 'page', get_option( 'show_on_front' ) ); ?> /> |
|---|
| 481 | + <?php printf( __( 'Show a <a href="%s">page</a> instead of your latest posts' ), 'edit.php?post_type=page' ); ?> |
|---|
| 482 | + </label></p> |
|---|
| 483 | + <p class="if-page-on-front sub-option"> |
|---|
| 484 | + <?php if ( $new_front_page_only ) : // If no pages, or only sample page, only allow a new page to be added ?> |
|---|
| 485 | + <label for="page_on_front_title"><?php _e( 'Add new page titled:' ); ?> |
|---|
| 486 | + <?php else : ?> |
|---|
| 487 | + <label for="page_on_front"> |
|---|
| 488 | + <select name="page_on_front" id="page_on_front"> |
|---|
| 489 | + <option value="0"><?php _e( '— Select —' ); ?></option> |
|---|
| 490 | + <?php if ( current_user_can( 'create_posts', 'page' ) ) : ?> |
|---|
| 491 | + <option value="new" id="new-page"><?php _e( '— Add new page —' ); ?></option> |
|---|
| 492 | + <?php endif; ?> |
|---|
| 493 | + <?php echo walk_page_dropdown_tree( $all_pages, 0, array( 'selected' => get_option( 'page_on_front' ) ) ); ?> |
|---|
| 494 | + </select> |
|---|
| 495 | + </label> |
|---|
| 496 | + <?php if ( current_user_can( 'create_posts', 'page' ) ) : ?> |
|---|
| 497 | + <label for="page_on_front_title" class="if-new-front-page"><?php _e( 'titled:' ); ?> |
|---|
| 498 | + <?php endif; ?> |
|---|
| 499 | + <?php endif; ?> |
|---|
| 500 | + <?php if ( current_user_can( 'create_posts', 'page' ) ) : ?> |
|---|
| 501 | + <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' ); ?>" /> |
|---|
| 502 | + </label> |
|---|
| 503 | + <?php endif; ?> |
|---|
| 504 | </p> |
|---|
| 505 | - <p><label> |
|---|
| 506 | - <input name="show_on_front" type="radio" value="page" class="tog" <?php checked( 'page', get_option( 'show_on_front' ) ); ?> /> |
|---|
| 507 | - <?php printf( __( 'A <a href="%s">static page</a> (select below)' ), 'edit.php?post_type=page' ); ?> |
|---|
| 508 | - </label> |
|---|
| 509 | + <p class="if-page-on-front"><label for="page_for_posts"> |
|---|
| 510 | + <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' ) ); ?> /> |
|---|
| 511 | + <?php _e( 'Show latest posts on a separate page' ); ?> |
|---|
| 512 | + </label></p> |
|---|
| 513 | + <?php if ( current_user_can( 'create_posts', 'page' ) ) : ?> |
|---|
| 514 | + <p class="if-page-for-posts sub-option"><label for="page_for_posts_title"><?php _e( 'Page title:' ); ?> |
|---|
| 515 | + <input name="page_for_posts_title" type="text" id="page_for_posts_title" value="<?php echo esc_attr( htmlspecialchars( $page_for_posts->post_title ) ); ?>" /> |
|---|
| 516 | + </label></p> |
|---|
| 517 | + <p class="if-page-for-posts sub-option" id="edit-slug-box"> |
|---|
| 518 | + <?php echo get_sample_permalink_html( $page_for_posts->ID, $page_for_posts->post_title, $page_for_posts->post_name ); ?> |
|---|
| 519 | + <input name="post_name" type="hidden" id="post_name" value="<?php echo esc_attr( apply_filters( 'editable_slug', $page_for_posts->post_name ) ); ?>" /> |
|---|
| 520 | </p> |
|---|
| 521 | -<ul> |
|---|
| 522 | - <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> |
|---|
| 523 | - <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> |
|---|
| 524 | -</ul> |
|---|
| 525 | -<?php if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == get_option( 'page_on_front' ) ) : ?> |
|---|
| 526 | -<div id="front-page-warning" class="error inline"><p><?php _e( '<strong>Warning:</strong> these pages should not be the same!' ); ?></p></div> |
|---|
| 527 | -<?php endif; ?> |
|---|
| 528 | -</fieldset></td> |
|---|
| 529 | + <?php if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == get_option( 'page_on_front' ) ) : ?> |
|---|
| 530 | + <div class="error inline"><p><strong><?php _e( 'ERROR:' ); ?></strong> <?php _e( 'These pages should not be the same!' ); ?></p></div> |
|---|
| 531 | + <?php endif; ?> |
|---|
| 532 | + </fieldset> |
|---|
| 533 | + <?php else : // cannot create pages, so fall back to a selector of existing pages ?> |
|---|
| 534 | + <p class="if-page-for-posts sub-option"><label for="page_for_posts"> |
|---|
| 535 | + <?php wp_dropdown_pages( array( |
|---|
| 536 | + 'name' => 'page_for_posts', 'show_option_none' => __( '— Select —' ), |
|---|
| 537 | + 'option_none_value' => '0', 'selected' => get_option( 'page_for_posts' ) |
|---|
| 538 | + ) ); ?> |
|---|
| 539 | + <?php endif; // create pages ?> |
|---|
| 540 | +</td> |
|---|
| 541 | </tr> |
|---|
| 542 | -<?php endif; ?> |
|---|
| 543 | +<?php endif; // if no pages to choose from and can't create pages ?> |
|---|
| 544 | + |
|---|
| 545 | <tr valign="top"> |
|---|
| 546 | <th scope="row"><label for="posts_per_page"><?php _e( 'Blog pages show at most' ); ?></label></th> |
|---|
| 547 | <td> |
|---|