diff --git a/wp-admin/css/wp-admin.css b/wp-admin/css/wp-admin.css index c22c5915ef..7ca3745f67 100644 --- a/wp-admin/css/wp-admin.css +++ b/wp-admin/css/wp-admin.css @@ -747,7 +747,8 @@ input[readonly] { background-color: #eee; } -:-moz-placeholder { +:-moz-placeholder, +.wp-core-ui :-moz-placeholder { color: #a9a9a9; } @@ -3080,11 +3081,78 @@ input#link_url { margin: 2px 0 2px -2px; } -#post-status-select, #post-format { +#post-status-select { line-height: 2.5em; margin-top: 3px; } +/* Post formats form */ +#poststuff .post-format-select { + margin-top: 0; + padding-bottom: 0; +} + +.post-formats-fields { + margin-bottom: 20px; +} + +.wp-format-standard .post-formats-fields, +.wp-format-aside .post-formats-fields, +.wp-format-chat .post-formats-fields, +.wp-format-status .post-formats-fields { + display: none; +} + +.post-formats-fields .field { + display: none; + margin-bottom: 10px; +} + +.post-formats-fields input, +.post-formats-fields textarea { + padding: 5px; + font-size: 1.2em; +} + +.wp-format-chat .field.wp-format-chat, +.wp-format-gallery .field.wp-format-gallery, +.wp-format-link .field.wp-format-link, +.wp-format-image .field.wp-format-image, +.wp-format-quote .field.wp-format-quote, +.wp-format-video .field.wp-format-video, +.wp-format-audio .field.wp-format-audio { + display: block; +} + +#wp-format-image-holder { + overflow: hidden; + width: 300px; + height: 200px; + border: 1px solid #dfdfdf; + background: #f5f5f5; +} + +#wp-format-image-holder:hover { + background-color: #eee; +} + +#wp-format-image-select { + display: block; + height: 200px; + text-align: center; +} + +#wp-format-image-select img { + max-width: 100%; + max-height: 100%; +} + +.empty #wp-format-image-select { + padding-top: 120px; + height: 80px; + background: url(../images/media-button-2x.png) no-repeat center; +} + /* Post Screen */ #post-body #normal-sortables { min-height: 50px; diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index 1d56ad4492..52a1dc8cf0 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -112,9 +112,6 @@ if ( 'attachment' == $post_type ) { add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', null, 'side', 'core' ); } -if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post_type, 'post-formats' ) ) - add_meta_box( 'formatdiv', _x( 'Format', 'post format' ), 'post_format_meta_box', null, 'side', 'core' ); - // all taxonomies foreach ( get_object_taxonomies( $post ) as $tax_name ) { $taxonomy = get_taxonomy($tax_name); @@ -129,6 +126,17 @@ foreach ( get_object_taxonomies( $post ) as $tax_name ) { add_meta_box($tax_name . 'div', $label, 'post_categories_meta_box', null, 'side', 'core', array( 'taxonomy' => $tax_name )); } +// post format +if ( post_type_supports( $post_type, 'post-formats' ) ) { + wp_enqueue_script( 'post-formats' ); + $post_format = get_post_format(); + $format_class = ''; + if ( ! $post_format ) + $post_format = 'standard'; + + $format_class = " class='wp-format-{$post_format}'"; +} + if ( post_type_supports($post_type, 'page-attributes') ) add_meta_box('pageparentdiv', 'page' == $post_type ? __('Page Attributes') : __('Attributes'), 'page_attributes_meta_box', null, 'side', 'core'); @@ -321,8 +329,28 @@ wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
+'; + + foreach ( $all_post_formats as $slug => $label ) { + if ( $post_format == $slug ) + $class = 'nav-tab nav-tab-active'; + else + $class = 'nav-tab'; + + echo '' . $label . ''; + } + + echo ''; +} +?> +
-
+
> +
@@ -356,6 +384,65 @@ wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); do_action( 'edit_form_after_title' ); +// post format fields +if ( post_type_supports( $post_type, 'post-formats' ) ) { + $format_meta = get_post_format_meta( $post_ID ); + +if ( isset( $format_meta['image'] ) ) + $image = is_numeric( $format_meta['image'] ) ? wp_get_attachment_url( $format_meta['image'] ) : $format_meta['image']; +else + $image = false; +?> +
+ + + +
+ + +
+ +
+ + +
+ + + + + + + +
+ + +
+ +
+
diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index cc43c5522f..eb386ee652 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -193,10 +193,18 @@ function edit_post( $post_data = null ) { // Post Formats if ( isset( $post_data['post_format'] ) ) { - if ( current_theme_supports( 'post-formats', $post_data['post_format'] ) ) - set_post_format( $post_ID, $post_data['post_format'] ); - elseif ( '0' == $post_data['post_format'] ) - set_post_format( $post_ID, false ); + set_post_format( $post_ID, $post_data['post_format'] ); + } + + if ( isset( $post_data[ '_wp_format_url' ] ) ) { + update_post_meta( $post_ID, '_wp_format_url', addslashes( esc_url_raw( stripslashes( $post_data['_wp_format_url'] ) ) ) ); + } + + $format_keys = array( 'quote', 'quote_source', 'image', 'gallery', 'media' ); + + foreach ( $format_keys as $key ) { + if ( isset( $post_data[ '_wp_format_' . $key ] ) ) + update_post_meta( $post_ID, '_wp_format_' . $key, wp_filter_post_kses( $post_data[ '_wp_format_' . $key ] ) ); } // Meta Stuff diff --git a/wp-admin/js/post-formats.js b/wp-admin/js/post-formats.js new file mode 100644 index 0000000000..27f638aa07 --- /dev/null +++ b/wp-admin/js/post-formats.js @@ -0,0 +1,63 @@ +window.wp = window.wp || {}; + +(function($){ + var imageFrame; + + // Post formats selection + $('.post-format-select a').on( 'click', function(e){ + e.preventDefault(); + var $this = $(this), + format = $this.data('wpFormat'); + $('.post-format-select a.nav-tab-active').removeClass('nav-tab-active'); + $this.addClass('nav-tab-active').blur(); + $('#post_format').val(format); + $('#post-body-content').attr('class', 'wp-format-' + format ); + }); + + // Image selection + $('#wp-format-image-select').click( function( event ) { + var $el = $(this), + $holder = $('#wp-format-image-holder'), + $field = $('#wp_format_image'); + event.preventDefault(); + + // If the media frame already exists, reopen it. + if ( imageFrame ) { + imageFrame.open(); + return; + } + + // Create the media frame. + imageFrame = wp.media.frames.formatImage = wp.media({ + // Set the title of the modal. + title: $el.data('choose'), + + // Tell the modal to show only images. + library: { + type: 'image' + }, + + // Customize the submit button. + button: { + // Set the text of the button. + text: $el.data('update') + } + }); + + // When an image is selected, run a callback. + imageFrame.on( 'select', function() { + // Grab the selected attachment. + var attachment = imageFrame.state().get('selection').first(), + imageUrl = attachment.get('url'); + + // set the hidden input's value + $field.attr('value', attachment.id); + + // Show the image in the placeholder + $el.html(''); + $holder.removeClass('empty'); + }); + + imageFrame.open(); + }); +})(jQuery); diff --git a/wp-admin/js/post-formats.min.js b/wp-admin/js/post-formats.min.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/wp-includes/post.php b/wp-includes/post.php index 50570936c1..14fbe75223 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -1950,6 +1950,30 @@ function get_post_custom_values( $key = '', $post_id = 0 ) { return isset($custom[$key]) ? $custom[$key] : null; } +/** + * Retrieve post format metadata for a post + * + * @since 3.6.0 + * + * @param int $post_id + * @return null + */ +function get_post_format_meta( $post_id = 0 ) { + $values = array( + 'quote' => '', + 'quote_source' => '', + 'image' => '', + 'url' => '', + 'gallery' => '', + 'media' => '', + ); + + foreach ( $values as $key => $value ) + $values[$key] = get_post_meta( $post_id, '_wp_format_' . $key, true ); + + return $values; +} + /** * Check if post is sticky. * diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 139cd95038..cfb865e3c9 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -397,6 +397,8 @@ function wp_default_scripts( &$scripts ) { 'comma' => _x( ',', 'tag delimiter' ), ) ); + $scripts->add( 'post-formats', "/wp-admin/js/post-formats$suffix.js", array( 'media-models' ), false, 1 ); + $scripts->add( 'link', "/wp-admin/js/link$suffix.js", array( 'wp-lists', 'postbox' ), false, 1 ); $scripts->add( 'comment', "/wp-admin/js/comment$suffix.js", array( 'jquery', 'postbox' ) );