diff --git a/wp-admin/css/wp-admin-rtl.css b/wp-admin/css/wp-admin-rtl.css index 6a0087d74e..1bc8a8939d 100644 --- a/wp-admin/css/wp-admin-rtl.css +++ b/wp-admin/css/wp-admin-rtl.css @@ -915,8 +915,7 @@ table.diff td, table.diff th { border-bottom-right-radius: 3px; } -#front-page-warning, -#front-static-pages ul, +#front-static-pages .sub-option, ul.export-filters, .inline-editor ul.cat-checklist ul, .categorydiv ul.categorychecklist ul, diff --git a/wp-admin/css/wp-admin.css b/wp-admin/css/wp-admin.css index 875c281db9..e80a21d5e1 100644 --- a/wp-admin/css/wp-admin.css +++ b/wp-admin/css/wp-admin.css @@ -2929,6 +2929,10 @@ input#link_url { font-size: 11px; } +#front-static-pages #edit-slug-box { + padding: 0; +} + #editable-post-name-full { display: none; } @@ -3414,8 +3418,7 @@ div.tabs-panel-inactive { margin: 0; } -#front-page-warning, -#front-static-pages ul, +#front-static-pages .sub-option, ul.export-filters, .inline-editor ul.cat-checklist ul, .categorydiv ul.categorychecklist ul, @@ -4988,6 +4991,19 @@ h2 .nav-tab { margin: -3px 3px; } +.js.options-reading-php .if-page-on-front, +.js.options-reading-php .if-page-for-posts, +.options-reading-php .if-new-front-page { + display: none; +} +.options-reading-php .page-on-front .if-page-on-front, +.options-reading-php .page-for-posts .if-page-for-posts { + display: block; +} +.options-reading-php .new-front-page .if-new-front-page { + display: inline; +} + /*------------------------------------------------------------------------------ 21.0 - Admin Footer ------------------------------------------------------------------------------*/ diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 44bc7c231c..aa671a72f7 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -1062,6 +1062,7 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { global $wpdb; $post = get_post($id); + $context = isset( $_POST['context'] ) ? $_POST['context'] : get_current_screen()->id; list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug); if ( 'publish' == get_post_status( $post ) ) { @@ -1073,6 +1074,8 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { } if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) { + if ( 'options-reading' == $context ) + return ''; $return = '' . __('Permalink:') . "\n" . '' . $permalink . "\n"; if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) ) $return .= '' . __('Change Permalinks') . "\n"; @@ -1101,12 +1104,12 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { $post_name_html = '' . $post_name_abridged . ''; $display_link = str_replace(array('%pagename%','%postname%'), $post_name_html, $permalink); $view_link = str_replace(array('%pagename%','%postname%'), $post_name, $permalink); - $return = '' . __('Permalink:') . "\n"; + $return = ( 'options-reading' == $context ) ? __( 'Located at' ) . "\n" : '' . __( 'Permalink:' ) . "\n"; $return .= '' . $display_link . "\n"; $return .= '‎'; // Fix bi-directional text display defect in RTL languages. $return .= '' . __('Edit') . "\n"; $return .= '' . $post_name . "\n"; - if ( isset($view_post) ) + if ( isset( $view_post ) && 'options-reading' != $context ) $return .= "$view_post\n"; $return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug); @@ -1322,3 +1325,87 @@ function post_preview() { return $url; } + +/** + * Creates new pages to be set as a front page or a page for posts in Reading Settings. + * + * @todo Make sure we are doing adequate sanitization on success, and cleanup/reset on failure. + * + * @since 3.5.0 + * @access private + */ +function _create_pages_for_reading_settings() { + // If we're saving the Reading Settings screen, intercept. + if ( ! isset( $_POST['show_on_front'] ) ) + return; + + // If a new front page was meant to be created, go forth and create it. + if ( isset( $_POST['page_on_front'] ) && 'new' == $_POST['page_on_front'] ) { + if ( ! current_user_can( 'create_posts', 'page' ) ) { + $_POST['page_on_front'] = 0; + $_POST['show_on_front'] = 'posts'; + add_settings_error( 'page_on_front', __( 'You are not allowed to create pages on this site.' ) ); + } + + $existing_page = get_page_by_title( stripslashes( $_POST['page_on_front_title'] ) ); + + // If page already exists and it's public, there's no need to create a new page + if ( $existing_page && 'publish' == $existing_page->post_status ) { + $page_id = $existing_page->ID; + } else { + $page_id = wp_insert_post( array( + 'post_title' => $_POST['page_on_front_title'], + 'post_type' => 'page', + 'post_status' => 'publish', + 'comment_status' => 'closed', + 'ping_status' => 'closed', + // @todo Create some sort of a 'context' in postmeta so we know we created a page through these means. + // Consider then showing that context in the list table as a good-first-step. + ), true ); + } + + // Make sure page_on_front is properly saved by options.php. + if ( is_wp_error( $page_id ) ) + $_POST['page_on_front'] = 0; + else + $_POST['page_on_front'] = $page_id; + } + + // If a page for posts was meant to be specified, update/create it. + if ( ! isset( $_POST['page_for_posts'] ) ) + return; + + $page_for_posts = (int) $_POST['page_for_posts']; + if ( ! $page_for_posts || ! $page = get_post( $page_for_posts, ARRAY_A ) ) { + $_POST['page_for_posts'] = 0; + return; + } + + // @todo The UI (see @todo's in options-reading) should cover the next 3 conditionals, + // which means we shouldn't need to bother with setting a settings error here. + // However, we may wish to restore settings before bailing, beyond setting + // page_for_posts to 0 (which we then expect to get cleaned up by options.php). + if ( 'page' != $page['post_type'] || ! current_user_can( 'edit_post', $page_for_posts ) ) { + $_POST['page_for_posts'] = 0; + return; + } + + if ( 'publish' != $page['post_status'] && ! current_user_can( 'publish_post', $page_for_posts ) ) { + $_POST['page_for_posts'] = 0; + return; + } + + $args = add_magic_quotes( $page ); + $args['post_title'] = $_POST['page_for_posts_title']; + $args['post_name'] = $_POST['post_name']; + $args['post_status'] = 'publish'; + if ( 'auto-draft' == $page['post_status'] ) { + $args['comment_status'] = 'closed'; + $args['ping_status'] = 'closed'; + } + + $page_id = wp_insert_post( $args, true ); + if ( is_wp_error( $page_id ) ) + $_POST['page_for_posts'] = 0; +} +add_filter( 'admin_init', '_create_pages_for_reading_settings' ); diff --git a/wp-admin/js/post.js b/wp-admin/js/post.js index 274c5903a7..2de4d05995 100644 --- a/wp-admin/js/post.js +++ b/wp-admin/js/post.js @@ -559,71 +559,6 @@ jQuery(document).ready( function($) { }); } // end submitdiv - // permalink - if ( $('#edit-slug-box').length ) { - editPermalink = function(post_id) { - 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(); - - $('#view-post-btn').hide(); - b.html(''+postL10n.ok+' '+postL10n.cancel+''); - b.children('.save').click(function() { - var new_slug = e.children('input').val(); - if ( new_slug == $('#editable-post-name-full').text() ) { - return $('.cancel', '#edit-slug-buttons').click(); - } - $.post(ajaxurl, { - action: 'sample-permalink', - post_id: post_id, - new_slug: new_slug, - new_title: $('#title').val(), - samplepermalinknonce: $('#samplepermalinknonce').val() - }, function(data) { - $('#edit-slug-box').html(data); - b.html(revert_b); - real_slug.val(new_slug); - makeSlugeditClickable(); - $('#view-post-btn').show(); - }); - return false; - }); - - $('.cancel', '#edit-slug-buttons').click(function() { - $('#view-post-btn').show(); - e.html(revert_e); - b.html(revert_b); - real_slug.val(revert_slug); - return false; - }); - - for ( i = 0; i < full.length; ++i ) { - if ( '%' == full.charAt(i) ) - c++; - } - - slug_value = ( c > full.length / 4 ) ? '' : full; - e.html('').children('input').keypress(function(e){ - var key = e.keyCode || 0; - // on enter, just save the new slug, don't save the post - if ( 13 == key ) { - b.children('.save').click(); - return false; - } - if ( 27 == key ) { - b.children('.cancel').click(); - return false; - } - real_slug.val(this.value); - }).focus(); - } - - makeSlugeditClickable = function() { - $('#editable-post-name').click(function() { - $('#edit-slug-buttons').children('.edit-slug').click(); - }); - } - makeSlugeditClickable(); - } - // word count if ( typeof(wpWordCount) != 'undefined' ) { $(document).triggerHandler('wpcountwords', [ co.val() ]); diff --git a/wp-admin/js/sample-permalink.js b/wp-admin/js/sample-permalink.js new file mode 100644 index 0000000000..9651dd0b54 --- /dev/null +++ b/wp-admin/js/sample-permalink.js @@ -0,0 +1,75 @@ +var editPermalink, makeSlugeditClickable; + +(function($){ + if ( ! $('#edit-slug-box').length ) + return; + editPermalink = function(post_id) { + 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(); + + $('#view-post-btn').hide(); + b.html(''+samplePermalinkL10n.ok+' '+samplePermalinkL10n.cancel+''); + b.children('.save').click(function() { + var new_slug = e.children('input').val(); + if ( new_slug == $('#editable-post-name-full').text() ) { + return $('.cancel', '#edit-slug-buttons').click(); + } + $.post(ajaxurl, { + action: 'sample-permalink', + post_id: post_id, + new_slug: new_slug, + new_title: $('#title').val(), + context: pagenow, + samplepermalinknonce: $('#samplepermalinknonce').val() + }, function(data) { + $('#edit-slug-box').html(data); + b.html(revert_b); + real_slug.val(new_slug); + makeSlugeditClickable(); + $('#view-post-btn').show(); + }); + return false; + }); + + $('.cancel', '#edit-slug-buttons').click(function() { + $('#view-post-btn').show(); + e.html(revert_e); + b.html(revert_b); + real_slug.val(revert_slug); + return false; + }); + + for ( i = 0; i < full.length; ++i ) { + if ( '%' == full.charAt(i) ) + c++; + } + + slug_value = ( c > full.length / 4 ) ? '' : full; + e.html('').children('input').keypress(function(e){ + var key = e.keyCode || 0; + // on enter, just save the new slug, don't save the post + if ( 13 == key ) { + b.children('.save').click(); + return false; + } + if ( 27 == key ) { + b.children('.cancel').click(); + return false; + } + real_slug.val(this.value); + }).focus(); + } + + makeSlugeditClickable = function() { + $('#editable-post-name').click(function() { + $('#edit-slug-buttons').children('.edit-slug').click(); + }); + } + makeSlugeditClickable(); +})(jQuery); \ No newline at end of file diff --git a/wp-admin/options-reading.php b/wp-admin/options-reading.php index d15502d75a..cb4532bf9f 100644 --- a/wp-admin/options-reading.php +++ b/wp-admin/options-reading.php @@ -15,6 +15,8 @@ if ( ! current_user_can( 'manage_options' ) ) $title = __( 'Reading Settings' ); $parent_file = 'options-general.php'; +wp_enqueue_script( 'sample-permalink' ); + /** * Display JavaScript on the page. * @@ -22,23 +24,26 @@ $parent_file = 'options-general.php'; */ function options_reading_add_js() { ?> - 'blog_charset' ) ); +wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); ?> - - - 'blog_charset' ) ); -else : - if ( 'page' == get_option( 'show_on_front' ) && ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) ) +$classes = ''; +if ( 'page' == get_option( 'show_on_front' ) ) { + if ( ! get_pages() || ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) ) { update_option( 'show_on_front', 'posts' ); -?> -
+ } else { + $classes = 'page-on-front'; + if ( get_option( 'page_for_posts' ) ) + $classes .= ' page-for-posts'; + } +} + +$all_pages = get_pages(); +$new_front_page_only = ! get_option( 'page_on_front' ) && ( ! $all_pages || ( 1 == count( $all_pages ) && __( 'sample-page' ) == $all_pages[0]->post_name ) ); + +if ( current_user_can( 'create_posts', 'page' ) && ! ( get_option( 'page_for_posts' ) && $page_for_posts = get_post( get_option( 'page_for_posts' ) ) ) ) { + $title = _x( 'Blog', 'default page for posts title' ); + // @todo What if the found page is post_type = attachment or post_status != publish? + // We could go ahead and create a new one, but we would not be able to take over + // the slug from another page. (We could for an attachment.) + // We must also check that the user can edit this page and publish a page. + // Otherwise, we must assume they cannot create pages (throughout), and thus + // should fall back to the dropdown. + if ( ! $page_for_posts = get_page_by_path( sanitize_title( $title ) ) ) { + $page_for_posts = get_default_post_to_edit( 'page', true ); + $page_for_posts->post_title = $title; + $page_for_posts->post_name = sanitize_title( $title ); + } +} + +if ( ! $new_front_page_only || current_user_can( 'create_posts', 'page' ) ) : ?> - - + + + +

+ + + +

- + +
-

+

+
+

+

+ +

-

+

+ +

+

+ ID, $page_for_posts->post_title, $page_for_posts->post_name ); ?>

-
    -
  • -
  • -
- -

Warning: these pages should not be the same!' ); ?>

- -
diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 4384cd112d..eb19a2cdb3 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -369,10 +369,14 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array('jquery-ui-sortable'), false, 1 ); - $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox'), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'post', 'postL10n', array( + $scripts->add( 'sample-permalink', "/wp-admin/js/sample-permalink.js", array(), false, 1 ); + did_action( 'init' ) && $scripts->localize( 'sample-permalink', 'samplePermalinkL10n', array( 'ok' => __('OK'), 'cancel' => __('Cancel'), + ) ); + + $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox', 'sample-permalink' ), false, 1 ); + did_action( 'init' ) && $scripts->localize( 'post', 'postL10n', array( 'publishOn' => __('Publish on:'), 'publishOnFuture' => __('Schedule for:'), 'publishOnPast' => __('Published on:'),