From 082e067a2d2153ef7c48fff475d8de622cf7b35d Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Thu, 25 Apr 2013 07:28:33 +0000 Subject: [PATCH] Screen option for Post Format UI. props nacin. see #23930. git-svn-id: http://core.svn.wordpress.org/trunk@24092 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin-ajax.php | 2 +- wp-admin/css/wp-admin.css | 4 + wp-admin/edit-form-advanced.php | 15 +- wp-admin/includes/ajax-actions.php | 19 +++ wp-admin/includes/post-formats.php | 245 +++++++++++++++-------------- wp-admin/includes/screen.php | 12 ++ wp-admin/js/post-formats.js | 10 ++ wp-includes/user.php | 5 - 8 files changed, 185 insertions(+), 127 deletions(-) diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 89d7cd3acf..c652ae7cca 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -56,7 +56,7 @@ $core_actions_post = array( 'save-widget', 'set-post-thumbnail', 'date_format', 'time_format', 'wp-fullscreen-save-post', 'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment', 'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor', - 'send-attachment-to-editor', 'save-attachment-order', 'heartbeat' + 'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'show-post-format-ui', ); // Register core Ajax calls. diff --git a/wp-admin/css/wp-admin.css b/wp-admin/css/wp-admin.css index 55107ae9af..1b07b3e5ba 100644 --- a/wp-admin/css/wp-admin.css +++ b/wp-admin/css/wp-admin.css @@ -3938,6 +3938,10 @@ body .ui-tooltip { padding-bottom: 0; } +.no-ui { + display: none; +} + .post-formats-fields { display: none; margin-bottom: 15px; diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index 30fce330b2..d92e8c4b62 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -146,6 +146,15 @@ if ( post_type_supports( $post_type, 'post-formats' ) && apply_filters( 'enable_ $post_format_set_class = ''; } + $user_wants = get_user_option( 'post_formats_' . $post_type ); + if ( false !== $user_wants ) { + // User wants what user gets. + $show_post_format_ui = (bool) $user_wants; + } else { + // UI is shown when the theme supports formats, or if the site has formats assigned to posts. + $show_post_format_ui = current_theme_supports( 'post-formats' ) || get_terms( 'post_format', array( 'number' => 1 ) ); + } + $format_class = " class='wp-format-{$post_format}'"; @@ -383,8 +392,10 @@ if ( isset( $post_new_file ) && current_user_can( $post_type_object->cap->create

-
- +
+
+ +
> diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index 8d59917578..a0ecf2bacb 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -1135,6 +1135,25 @@ function wp_ajax_closed_postboxes() { wp_die( 1 ); } +function wp_ajax_show_post_format_ui() { + error_log( serialize( $_REQUEST ) ); + + if ( empty( $_POST['post_type'] ) ) + wp_die( 0 ); + + check_ajax_referer( 'show-post-format-ui_' . $_POST['post_type'], 'nonce' ); + + if ( ! $post_type_object = get_post_type_object( $_POST['post_type'] ) ) + wp_die( 0 ); + + if ( ! current_user_can( $post_type_object->cap->edit_posts ) ) + wp_die( -1 ); + + update_user_option( get_current_user_id(), 'post_formats_' . $post_type_object->name, empty( $_POST['show'] ) ? 0 : 1 ); + + wp_die( 1 ); +} + function wp_ajax_hidden_columns() { check_ajax_referer( 'screen-options-nonce', 'screenoptionnonce' ); $hidden = isset( $_POST['hidden'] ) ? $_POST['hidden'] : ''; diff --git a/wp-admin/includes/post-formats.php b/wp-admin/includes/post-formats.php index ac4c749fc3..9571e55056 100644 --- a/wp-admin/includes/post-formats.php +++ b/wp-admin/includes/post-formats.php @@ -1,140 +1,147 @@ -
-
+
+
+
- + -
- - -
+
+ + +
-
- -
- ', esc_url( $image ), get_the_title( $value ) ); - } elseif ( preg_match( '/' . get_shortcode_regex() . '/s', $value ) ) { - echo do_shortcode( $value ); - } elseif ( ! preg_match( '#<[^>]+>#', $value ) ) { - printf( '', esc_url( $value ) ); - } else { - echo $value; - } +
+ +
+ ', esc_url( $image ), get_the_title( $value ) ); + } elseif ( preg_match( '/' . get_shortcode_regex() . '/s', $value ) ) { + echo do_shortcode( $value ); + } elseif ( ! preg_match( '#<[^>]+>#', $value ) ) { + printf( '', esc_url( $value ) ); + } else { + echo $value; + } + ?> +
+ + + +
+ + + +
- - - -
- - - + + -
- +
+ + +
-
- - -
+
+ + +
-
- - -
- -
- -
- ]+>#', $value ) ) { - if ( strstr( $value, home_url() ) ) - echo do_shortcode( sprintf( '[video src="%s"]', $value ) ); - else - echo $wp_embed->autoembed( $value ); - } else { - echo $value; - } +
+ +
+ ]+>#', $value ) ) { + if ( strstr( $value, home_url() ) ) + echo do_shortcode( sprintf( '[video src="%s"]', $value ) ); + else + echo $wp_embed->autoembed( $value ); + } else { + echo $value; + } + ?> +
+ + + +
+ + + +
- - - -
- - - -
-
-
- -
- ]+>#', $value ) ) { - if ( strstr( $value, home_url() ) ) - echo do_shortcode( sprintf( '[audio src="%s"]', $value ) ); - else - echo $wp_embed->autoembed( $value ); - } else { - echo $value; - } +
+ -
- - - -
- - - +
+ ]+>#', $value ) ) { + if ( strstr( $value, home_url() ) ) + echo do_shortcode( sprintf( '[audio src="%s"]', $value ) ); + else + echo $wp_embed->autoembed( $value ); + } else { + echo $value; + } + ?> +
+ + + +
+ + + +
-
+
\ No newline at end of file diff --git a/wp-admin/includes/screen.php b/wp-admin/includes/screen.php index 4fd4519031..0f6c4dd2ba 100644 --- a/wp-admin/includes/screen.php +++ b/wp-admin/includes/screen.php @@ -962,6 +962,18 @@ final class WP_Screen { echo '\n"; + } elseif ( 'post' == $this->base && post_type_supports( $this->post_type, 'post-formats' ) && apply_filters( 'enable_post_format_ui', true, $GLOBALS['post'] ) ) { + $user_wants = get_user_option( 'post_formats_' . $this->post_type ); + if ( false !== $user_wants ) { + // User wants what user gets. + $show_post_format_ui = (bool) $user_wants; + } else { + // UI is shown when the theme supports formats, or if the site has formats assigned to posts. + $show_post_format_ui = current_theme_supports( 'post-formats' ) || get_terms( 'post_format', array( 'number' => 1 ) ); + } + echo '\n"; } ?>
diff --git a/wp-admin/js/post-formats.js b/wp-admin/js/post-formats.js index 4d31ffb03a..9344df09b9 100644 --- a/wp-admin/js/post-formats.js +++ b/wp-admin/js/post-formats.js @@ -109,6 +109,16 @@ window.wp = window.wp || {}; resizeContent( initialFormat, true ); } + $('#show_post_format_ui').on('change', function() { + $('.wp-post-format-ui').toggleClass('no-ui', ! this.checked ); + $.post( ajaxurl, { + action: 'show-post-format-ui', + post_type: $('#post_type').val(), + show: this.checked ? 1 : 0, + nonce: $('#show_post_format_ui_nonce').val() + }); + }); + $('.post-format-change a').click(function() { $('.post-formats-fields, .post-format-change').slideUp(); $('.post-format-options').slideDown(); diff --git a/wp-includes/user.php b/wp-includes/user.php index dc06dfa8e8..8e475e1b09 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -276,11 +276,6 @@ function update_user_option( $user_id, $option_name, $newvalue, $global = false if ( !$global ) $option_name = $wpdb->prefix . $option_name; - // For backward compatibility. See differences between update_user_meta() and deprecated update_usermeta(). - // http://core.trac.wordpress.org/ticket/13088 - if ( is_null( $newvalue ) || is_scalar( $newvalue ) && empty( $newvalue ) ) - return delete_user_meta( $user_id, $option_name ); - return update_user_meta( $user_id, $option_name, $newvalue ); }