First pass at removing Post Format UI.

see #24452. fixes #24455.

git-svn-id: http://core.svn.wordpress.org/trunk@24388 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Mark Jaquith 2013-05-30 21:33:46 +00:00
parent c5530f9fc6
commit 89fd06e44b
11 changed files with 9 additions and 715 deletions

View File

@ -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', 'show-post-format-ui',
'send-attachment-to-editor', 'save-attachment-order', 'heartbeat',
);
// Register core Ajax calls.

View File

@ -95,39 +95,6 @@ if ( isset( $post ) && is_a( $post, 'WP_Post' ) && post_type_supports( get_post_
$post_format = 'standard';
$admin_body_class .= ' wp-format-' . $post_format;
$show_post_format_ui = false;
if ( apply_filters( 'enable_post_format_ui', true, $post ) ) {
// If the user has explicitly set a screen option, use it, otherwise the UI is shown
// when the theme supports formats, or if the site has formats assigned to posts.
$post_format_user_option = get_user_option( 'post_formats_' . $post->post_type );
if ( false !== $post_format_user_option )
$show_post_format_ui = (bool) $post_format_user_option;
else
$show_post_format_ui = current_theme_supports( 'post-formats' ) || (bool) get_terms( 'post_format', array( 'number' => 1 ) );
if ( ! $show_post_format_ui ) {
$meta = get_post_format_meta( $post->ID );
$format_meta_keys = array(
'link' => array( 'linkurl' ),
'image' => array( 'url', 'image' ),
'quote' => array( 'quote_source_name', 'quote_source_url' ),
'video' => array( 'video_embed' ),
'audio' => array( 'audio_embed' ),
);
// If there's any structured post format data, enforce the UI display.
$format_meta_keys = isset( $format_meta_keys[ get_post_format() ] ) ? $format_meta_keys[ get_post_format() ] : array();
foreach ( $format_meta_keys as $key )
if ( ! empty( $meta[ $key ] ) )
$show_post_format_ui = true;
}
}
if ( $show_post_format_ui )
$admin_body_class .= ' wp-post-format-show-ui';
}
if ( wp_is_mobile() )

View File

@ -112,6 +112,9 @@ 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);
@ -126,73 +129,6 @@ 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
$format_class = '';
$post_format = '';
$post_format_options = '';
if ( post_type_supports( $post_type, 'post-formats' ) && apply_filters( 'enable_post_format_ui', true, $post ) ) {
wp_enqueue_script( 'post-formats' );
wp_enqueue_script( 'wp-mediaelement' );
wp_enqueue_style( 'wp-mediaelement' );
$post_format = get_post_format();
if ( ! empty( $_REQUEST['format'] ) && in_array( $_REQUEST['format'], get_post_format_slugs() ) )
$post_format = $_REQUEST['format'];
if ( ! $post_format )
$post_format = 'standard';
$format_class = " class='wp-format-{$post_format}'";
$all_post_formats = array(
'standard' => array (
'description' => __( 'Use the editor below to compose your post.' )
),
'image' => array (
'description' => __( 'Select or upload an image for your post.' )
),
'gallery' => array (
'description' => __( 'Use the Add Media button to select or upload images for your gallery.' )
),
'link' => array (
'description' => __( 'Add a link title and destination URL. Use the editor to compose optional text to accompany the link.' )
),
'video' => array (
'description' => __( 'Select or upload a video, or paste a video embed code into the box.' )
),
'audio' => array (
'description' => __( 'Select or upload an audio file, or paste an audio embed code into the box.' )
),
'chat' => array (
'description' => __( 'Copy a chat or Q&A transcript into the editor.' )
),
'status' => array (
'description' => __( 'Use the editor to compose a status update. What’s new?' )
),
'quote' => array (
'description' => __( 'Add a source name and link if you have them. Use the editor to compose the quote.' )
),
'aside' => array (
'description' => __( 'Use the editor to share a quick thought or side topic.' )
)
);
foreach ( $all_post_formats as $slug => $attr ) {
$class = '';
if ( $post_format == $slug ) {
$class = 'class="active"';
$active_post_type_slug = $slug;
}
$url = add_query_arg( 'format', $slug );
$post_format_options .= '<a ' . $class . ' href="' . esc_url( $url ) . '" data-description="' . $attr['description'] . '" data-wp-format="' . $slug . '" title="' . ucfirst( $slug ) . '"><div class="' . $slug . '"></div><span class="post-format-title">' . ucfirst( $slug ) . '</span></a>';
}
$current_post_format = array( 'currentPostFormat' => esc_html( $active_post_type_slug ) );
wp_localize_script( 'post-formats', 'postFormats', $current_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');
@ -379,13 +315,7 @@ if ( isset( $post_new_file ) && current_user_can( $post_type_object->cap->create
<div id="lost-connection-notice" class="error hidden">
<p><?php _e("You have lost your connection with the server, and saving has been disabled. This message will vanish once you've reconnected."); ?></p>
</div>
<?php if ( ! empty( $post_format_options ) ) : ?>
<div class="wp-post-format-ui">
<div class="post-format-options">
<?php echo $post_format_options; ?>
</div>
</div>
<?php endif; ?>
<form name="post" action="post.php" method="post" id="post"<?php do_action('post_edit_form_tag'); ?>>
<?php wp_nonce_field($nonce_action); ?>
<input type="hidden" id="user-id" name="user_ID" value="<?php echo (int) $user_ID ?>" />
@ -411,12 +341,8 @@ wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
<div id="poststuff">
<div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
<div id="post-body-content"<?php echo $format_class; ?>>
<?php if ( ! empty( $all_post_formats ) ) : ?>
<div class="wp-post-format-ui">
<div class="post-format-change"><span class="icon <?php echo esc_attr( 'wp-format-' . $post_format ); ?>"></span> <span class="post-format-description"><?php echo $all_post_formats[$post_format]['description']; ?></span></div>
</div>
<?php endif; ?>
<div id="post-body-content">
<?php if ( post_type_supports($post_type, 'title') ) { ?>
<div id="titlediv">
<div id="titlewrap">
@ -456,10 +382,6 @@ if ( has_action( 'edit_form_after_title' ) ) {
echo '</div>';
}
// post format fields
if ( post_type_supports( $post_type, 'post-formats' ) && apply_filters( 'enable_post_format_ui', true, $post ) )
require_once( './includes/post-formats.php' );
if ( post_type_supports($post_type, 'editor') ) {
?>
<div id="postdivrich" class="postarea edit-form-section">
@ -467,7 +389,7 @@ if ( post_type_supports($post_type, 'editor') ) {
<?php wp_editor( $post->post_content, 'content', array(
'dfw' => true,
'tabfocus_elements' => 'insert-media-button,save-post',
'editor_height' => in_array( $post_format, array( 'status', 'aside' ) ) ? 120 : 360
'editor_height' => 360,
) ); ?>
<table id="post-status-info" cellspacing="0"><tbody><tr>
<td id="wp-word-count"><?php printf( __( 'Word count: %s' ), '<span class="word-count">0</span>' ); ?></td>

View File

@ -1126,23 +1126,6 @@ function wp_ajax_closed_postboxes() {
wp_die( 1 );
}
function wp_ajax_show_post_format_ui() {
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'] : '';

View File

@ -1,163 +0,0 @@
<?php
/**
* Structured data fields for the Post Formats UI
*
* @package WordPress
* @subpackage Administration
*/
defined( 'ABSPATH' ) or die;
global $wp_embed;
$format_meta = get_post_format_meta( $post_ID );
wp_nonce_field( 'show-post-format-ui_' . $post_type, 'show_post_format_ui_nonce', false );
?>
<div class="wp-post-format-ui">
<div class="post-formats-fields">
<input type="hidden" name="post_format" id="post_format" value="<?php echo esc_attr( $post_format ); ?>" />
<div class="field wp-format-quote">
<label for="wp_format_quote_source"><?php _e( 'Quote source' ); ?></label>
<input type="text" id="wp_format_quote_source" name="_format_quote_source_name" value="<?php echo esc_attr( $format_meta['quote_source_name'] ); ?>" class="widefat" />
</div>
<div class="field wp-format-image">
<?php if ( ! empty( $format_meta['image'] ) ) :
$value = $format_meta['image'];
?>
<div id="image-preview" class="wp-format-media-preview">
<?php
if ( is_numeric( $value ) ) {
$image = wp_get_attachment_url( $value );
printf( '<img src="%s" alt="%s" />', esc_url( $image ), get_the_title( $value ) );
} elseif ( preg_match( '/' . get_shortcode_regex() . '/s', $value ) ) {
echo do_shortcode( $value );
} elseif ( ! preg_match( '#<[^>]+>#', $value ) ) {
printf( '<img src="%s" alt="" />', esc_url( $value ) );
} else {
echo $value;
}
?>
</div>
<?php endif ?>
<div data-format="image" class="wp-format-media-holder hide-if-no-js">
<div><h3><?php _e( 'Drop image file to upload' ); ?></h3></div>
<a href="#" class="wp-format-media-select"
data-choose="<?php esc_attr_e( 'Choose an Image' ); ?>"
data-update="<?php esc_attr_e( 'Select Image' ); ?>">
<?php _e( 'Select / Upload Image' ); ?>
</a>
</div>
<div class="wp-format-image-textarea hide-if-js">
<label for="wp_format_image"><?php
if ( current_user_can( 'unfiltered_html' ) )
_e( 'Image URL or HTML' );
else
_e( 'Image URL' );
?></label>
<textarea id="wp_format_image" type="text" name="_format_image" class="widefat"><?php echo esc_textarea( $format_meta['image'] ); ?></textarea>
</div>
<p class="use-url-or-html hide-if-no-js">
<span><?php
if ( current_user_can( 'unfiltered_html' ) )
_e( '(or <a href="#">use an image URL or HTML</a>)' );
else
_e( '(or <a href="#">use an image URL</a>)' );
?></span>
<span style="display: none"><?php _e( '(or <a href="#">select/upload an image</a>)' ); ?></span></p>
</div>
<div class="field wp-format-link">
<label for="wp_format_link_url"><?php _e( 'Link URL' ); ?></label>
<input type="text" id="wp_format_link_url" name="_format_link_url" value="<?php echo esc_url( $format_meta['link_url'] ); ?>" class="widefat code" />
</div>
<div class="field wp-format-quote">
<label for="wp_format_quote_source_url"><?php _e( 'Quote source link' ); ?></label>
<input type="text" id="wp_format_quote_source_url" name="_format_quote_source_url" value="<?php echo esc_url( $format_meta['quote_source_url'] ); ?>" class="widefat code" />
</div>
<div class="field wp-format-image">
<label for="wp_format_image_url"><?php _e( 'Image click-through link' ); ?></label>
<input type="text" id="wp_format_image_url" name="_format_url" value="<?php echo esc_url( $format_meta['url'] ); ?>" class="widefat code" />
</div>
<div class="field wp-format-video">
<?php if ( ! empty( $format_meta['video_embed'] ) ):
$value = $format_meta['video_embed'];
?>
<div id="video-preview" class="wp-format-media-preview">
<?php
if ( is_numeric( $value ) ) {
$video = wp_get_attachment_url( $value );
echo do_shortcode( sprintf( '[video src="%s"]', $video ) );
} elseif ( preg_match( '/' . get_shortcode_regex() . '/s', $value ) ) {
echo do_shortcode( $value );
} elseif ( ! preg_match( '#<[^>]+>#', $value ) ) {
if ( strstr( $value, home_url() ) )
echo do_shortcode( sprintf( '[video src="%s"]', $value ) );
else
echo $wp_embed->autoembed( $value );
} else {
echo $value;
}
?>
</div>
<?php endif; ?>
<label for="wp_format_video"><?php
if ( current_user_can( 'unfiltered_html' ) )
_e( 'Video embed code or URL' );
else
_e( 'Video URL' );
?></label>
<textarea id="wp_format_video" type="text" name="_format_video_embed" class="widefat"><?php echo esc_textarea( $format_meta['video_embed'] ); ?></textarea>
<div data-format="video" class="wp-format-media-holder hide-if-no-js">
<a href="#" class="wp-format-media-select"
data-choose="<?php esc_attr_e( 'Choose a Video' ); ?>"
data-update="<?php esc_attr_e( 'Select Video' ); ?>">
<?php _e( 'Select Video From Media Library' ) ?>
</a>
</div>
</div>
<div class="field wp-format-audio">
<?php if ( ! empty( $format_meta['audio_embed'] ) ):
$value = $format_meta['audio_embed'];
?>
<div id="audio-preview" class="wp-format-media-preview">
<?php
if ( is_numeric( $value ) ) {
$audio = wp_get_attachment_url( $value );
echo do_shortcode( sprintf( '[audio src="%s"]', $audio ) );
} elseif ( preg_match( '/' . get_shortcode_regex() . '/s', $value ) ) {
echo do_shortcode( $value );
} elseif ( ! preg_match( '#<[^>]+>#', $value ) ) {
if ( strstr( $value, home_url() ) )
echo do_shortcode( sprintf( '[audio src="%s"]', $value ) );
else
echo $wp_embed->autoembed( $value );
} else {
echo $value;
}
?>
</div>
<?php endif; ?>
<label for="wp_format_audio"><?php
if ( current_user_can( 'unfiltered_html' ) )
_e( 'Audio embed code or URL' );
else
_e( 'Audio URL' );
?></label>
<textarea id="wp_format_audio" name="_format_audio_embed" class="widefat"><?php echo esc_textarea( $format_meta['audio_embed'] ); ?></textarea>
<div data-format="audio" class="wp-format-media-holder hide-if-no-js">
<a href="#" class="wp-format-media-select" data-choose="<?php esc_attr_e( 'Choose Audio' ); ?>" data-update="<?php esc_attr_e( 'Select Audio' ); ?>">
<?php _e( 'Select Audio From Media Library' ) ?>
</a>
</div>
</div>
</div>
</div>

View File

@ -1290,26 +1290,6 @@ function wp_create_post_autosave( $post_id ) {
$new_autosave['ID'] = $old_autosave->ID;
$new_autosave['post_author'] = $post_author;
// Auto-save revisioned meta fields.
foreach ( _wp_post_revision_meta_keys() as $meta_key ) {
if ( isset( $_POST[ $meta_key ] ) && get_post_meta( $new_autosave['ID'], $meta_key, true ) != $_POST[ $meta_key ] ) {
// Use the underlying delete_metadata and add_metadata vs delete_post_meta
// and add_post_meta to make sure we're working with the actual revision meta.
delete_metadata( 'post', $new_autosave['ID'], $meta_key );
if ( ! empty( $_POST[ $meta_key ] ) )
add_metadata( 'post', $new_autosave['ID'], $meta_key, $_POST[ $meta_key ] );
}
}
// Save the post format if different
if ( isset( $_POST['post_format'] ) && get_post_meta( $new_autosave['ID'], '_revision_post_format', true ) != $_POST['post_format'] ) {
delete_metadata( 'post', $new_autosave['ID'], '_revision_post_format' );
if ( ! empty( $_POST['post_format'] ) )
add_metadata( 'post', $new_autosave['ID'], '_revision_post_format', $_POST['post_format'] );
}
return wp_update_post( $new_autosave );
}

View File

@ -963,36 +963,6 @@ final class WP_Screen {
echo '<label for="wp_welcome_panel-hide">';
echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />';
echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n";
} elseif ( 'post' == $this->base && post_type_supports( $this->post_type, 'post-formats' ) && apply_filters( 'enable_post_format_ui', true, $post ) ) {
// If the user has explicitly set a screen option, use it, otherwise the UI is shown
// when the theme supports formats, or if the site has formats assigned to posts.
$post_format_user_option = get_user_option( 'post_formats_' . $post->post_type );
if ( false !== $post_format_user_option )
$show_post_format_ui = (bool) $post_format_user_option;
else
$show_post_format_ui = current_theme_supports( 'post-formats' ) || (bool) get_terms( 'post_format', array( 'number' => 1 ) );
if ( ! $show_post_format_ui && 'auto-draft' != $post->post_status ) {
$meta = get_post_format_meta( $post->ID );
$format_meta_keys = array(
'link' => array( 'linkurl' ),
'image' => array( 'url', 'image' ),
'quote' => array( 'quote_source_name', 'quote_source_url' ),
'video' => array( 'video_embed' ),
'audio' => array( 'audio_embed' ),
);
// If there's any structured post format data, enforce the UI display.
$format_meta_keys = isset( $format_meta_keys[ get_post_format() ] ) ? $format_meta_keys[ get_post_format() ] : array();
foreach ( $format_meta_keys as $key )
if ( ! empty( $meta[ $key ] ) )
$show_post_format_ui = true;
}
echo '<label for="show_post_format_ui">';
echo '<input type="checkbox" id="show_post_format_ui"' . checked( $show_post_format_ui, true, false ) . ' />';
echo __( 'Post Formats' ) . "</label>\n";
}
?>
<br class="clear" />

View File

@ -1,361 +0,0 @@
/*globals window, $, jQuery, document, _, postFormats, tinymce, ajaxurl, wp, getUserSetting */
window.wp = window.wp || {};
(function ($) {
"use strict";
var mediaFrame, insertMediaButton, container, icon, formatField,
body,
lastMimeType,
classRegex = /\s?\bwp-format-[^ ]+/g,
shortHeight = 120,
lastHeight = 360,
initialFormat = 'standard',
shortClass = 'short-format',
noTitleFormats = ['status'],
noMediaFormats = ['status', 'aside', 'image', 'audio', 'video'],
shortContentFormats = ['status', 'aside'],
noUIFormats = ['standard', 'chat', 'status', 'aside', 'gallery'];
function imageFormatUploadProgress( uploader, file ) {
var $bar = $( '#' + uploader.settings.drop_element + ' .media-progress-bar div' );
$bar.width( file.percent + '%' );
}
function imageFormatUploadStart( uploader ) {
$( '#' + uploader.settings.drop_element + ' .wp-format-media-select' ).append('<div class="media-progress-bar"><div></div></div>');
}
function imageFormatUploadError() {
$( '.media-progress-bar', $('.wp-format-media-holder[data-format=image]') ).remove();
}
function imageFormatUploadSuccess( attachment ) {
var $holder, $field, html = wp.media.string.image({
size : 'full',
align : false,
link : 'none'
}, attachment.attributes );
$holder = $('.wp-format-media-holder[data-format=image]');
$( '.media-progress-bar', $holder ).remove();
if ( 'image' !== attachment.attributes.type )
return;
$field = $( '#wp_format_' + $holder.data( 'format' ) );
// set the hidden input's value
$field.val( html );
$( '#image-preview' ).remove();
$holder.parent().prepend( ['<div id="image-preview" class="wp-format-media-preview">',
'<img src="', attachment.get('url'), '"',
attachment.get('width') ? ' width="' + attachment.get('width') + '"' : '',
attachment.get('height') ? ' height="' + attachment.get('height') + '"' : '',
' />',
'</div>'].join( '' ) );
}
function imageFormatUploadFilesAdded( uploader, files ) {
$.each( files, function( i, file ) {
if ( i > 0 )
uploader.removeFile(file);
});
}
var uploader = {
container: null,
browser: null,
dropzone: $('.wp-format-media-holder[data-format=image]'),
success: imageFormatUploadSuccess,
error: imageFormatUploadError,
plupload: {
runtimes: 'html5',
filters: [ {title: 'Image', extensions: 'jpg,jpeg,gif,png'} ]
},
params: {}
};
uploader = new wp.Uploader( uploader );
if ( uploader.supports.dragdrop ) {
uploader.uploader.bind( 'BeforeUpload', imageFormatUploadStart );
uploader.uploader.bind( 'UploadProgress', imageFormatUploadProgress );
uploader.uploader.bind( 'FilesAdded', imageFormatUploadFilesAdded );
} else {
uploader.uploader.destroy();
uploader = null;
}
function switchFormatClass( format ) {
formatField.val( format );
$.each( [ container, icon, body ], function(i, thing) {
thing.prop( 'className', thing.prop( 'className' ).replace( classRegex, '' ) )
.addClass( 'wp-format-' + format );
});
}
function resizeContent( format, noAnimate ) {
var height, content = $( '#content, #content_ifr' );
height = content.outerHeight();
if ( shortHeight < height ) {
lastHeight = height;
}
if ( -1 < $.inArray( format, shortContentFormats ) ) {
if ( ! content.hasClass( shortClass ) ) {
content.addClass( shortClass );
_(content).each(function (elem) {
$(elem)[noAnimate ? 'css' : 'animate']( { height : shortHeight } );
});
}
} else {
content.removeClass( shortClass ).animate( { height : lastHeight } );
}
}
function switchFormat(elem) {
var editor, body, formatTo, formatFrom,
format = elem.data( 'wp-format' ),
titlePrompt = $( '#title-prompt-text' ),
description = $( '.post-format-description' ),
postTitle = $( '#title'),
fields = $( '.post-formats-fields' ),
tinyIcon = $( '.post-format-change span.icon' );
if ( format === postFormats.currentPostFormat ) {
return;
}
elem.addClass( 'active' ).siblings().removeClass( 'active' );
// Animate the media button going away or coming back
formatTo = -1 < $.inArray( format, noMediaFormats );
formatFrom = -1 < $.inArray( postFormats.currentPostFormat, noMediaFormats );
if ( formatFrom ? !formatTo : formatTo ) { // XOR
insertMediaButton.fadeToggle( 200 ).css( 'display', 'inline-block' );
}
// Animate the title going away or coming back
formatTo = -1 < $.inArray( format, noTitleFormats );
formatFrom = -1 < $.inArray( postFormats.currentPostFormat, noTitleFormats );
if ( formatFrom ? !formatTo : formatTo ) { // XOR
$( '#titlewrap' ).fadeToggle( 200 );
}
// Animate the fields moving going away or coming in
formatTo = -1 < $.inArray( format, noUIFormats );
formatFrom = -1 < $.inArray( postFormats.currentPostFormat, noUIFormats );
if ( formatTo && formatFrom ) { // To/from have no UI. No slide.
switchFormatClass( format );
fields.hide();
} else if ( formatFrom ) { // Only destination has UI. Slide down.
fields.hide();
switchFormatClass( format );
fields.slideDown( 400 );
} else if ( formatTo ) { // Only source has UI. Slide up.
fields.slideUp( 200, function(){
switchFormatClass( format );
});
} else { // Both have UI. Slide both ways.
fields.slideUp( 200, function(){
switchFormatClass( format );
fields.slideDown( 400 );
});
}
resizeContent( format );
postTitle.focus();
if ( '' === postTitle.val() ) {
titlePrompt.removeClass( 'screen-reader-text' );
postTitle.keydown( function (e) {
titlePrompt.addClass( 'screen-reader-text' );
$( e.currentTarget ).unbind( e );
} );
}
// Update description line
description.html( elem.data( 'description' ) );
tinyIcon
.show()
.prop( 'className', tinyIcon.prop( 'className' ).replace( classRegex, '' ) )
.addClass( 'wp-format-' + format );
if ( description.not( ':visible' ) ) {
description.slideDown( 'fast' );
}
if ( typeof tinymce !== 'undefined' ) {
editor = tinymce.get( 'content' );
if ( editor ) {
body = editor.getBody();
body.className = body.className.replace( /\bpost-format-[^ ]+/, '' );
editor.dom.addClass( body, 'post-format-' + format );
}
}
// If gallery, force it to open to gallery state
insertMediaButton.toggleClass( 'gallery', 'gallery' === format );
postFormats.currentPostFormat = format;
}
$(function () {
body = $( 'body' );
container = $( '#post-body-content' );
icon = $( '.icon32' );
formatField = $( '#post_format' );
insertMediaButton = $( '#insert-media-button' ).toggleClass( 'gallery', 'gallery' === postFormats.currentPostFormat );
initialFormat = $( '.post-format-options .active' ).data( 'wp-format' );
if ( -1 < $.inArray( initialFormat, shortContentFormats ) ) {
resizeContent( initialFormat, true );
}
$( '#show_post_format_ui' ).on( 'change', function () {
body.toggleClass( 'wp-post-format-show-ui', this.checked );
// Reset the display properties of possibly hidden items.
insertMediaButton.css( 'display', '' );
$( '#titlewrap' ).css( 'display', '' );
$.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 formats selection
$( '.post-format-options' ).on( 'click', 'a', function (e) {
e.preventDefault();
switchFormat( $( e.currentTarget ) );
} );
// Toggle select/upload and URL/HTML for images
$( '.use-url-or-html' ).on( 'click', 'a', function(e) {
e.preventDefault();
$( '.wp-format-media-holder, .wp-format-image-textarea' ).toggle();
$(this).closest( 'p' ).find( 'span' ).toggle();
});
// Media selection
$( '.wp-format-media-select' ).click( function (e) {
e.preventDefault();
var $el = $(e.currentTarget), mediaPreview, mime = 'image', $holder, $field;
$holder = $el.closest( '.wp-format-media-holder' );
$field = $( '#wp_format_' + $holder.data( 'format' ) );
mime = $holder.data( 'format' );
// If the media frame already exists, reopen it.
if ( mediaFrame && lastMimeType === mime ) {
mediaFrame.open();
return;
}
lastMimeType = mime;
mediaFrame = wp.media.frames.formatMedia = wp.media( {
button: {
text: $el.data( 'update' )
},
states: [
new wp.media.controller.Library({
library: wp.media.query( { type: mime } ),
title: $el.data( 'choose' ),
displaySettings: 'image' === mime
})
]
} );
mediaPreview = function (attachment) {
var w, h, dimensions = '', url = attachment.url, mime = attachment.mime, format = attachment.type;
if ( 'video' === format ) {
if ( attachment.width ) {
w = attachment.width;
if ( w > 600 ) {
w = 600;
}
dimensions += ' width="' + w + '"';
}
if ( attachment.height ) {
h = attachment.height;
if ( attachment.width && w < attachment.width ) {
h = Math.round( ( h * w ) / attachment.width );
}
dimensions += ' height="' + h + '"';
}
}
$( '#' + format + '-preview' ).remove();
$holder.parent().prepend( '<div id="' + format + '-preview" class="wp-format-media-preview">' +
'<' + format + dimensions + ' class="wp-' + format + '-shortcode" controls="controls" preload="none">' +
'<source type="' + mime + '" src="' + url + '" />' +
'</' + format + '></div>' );
$( '.wp-' + format + '-shortcode' ).mediaelementplayer();
};
// When an image is selected, run a callback.
mediaFrame.on( 'select', function () {
// Grab the selected attachment.
var w = 0, h = 0, html, attachment = mediaFrame.state().get( 'selection' ).first().toJSON();
if ( 0 === attachment.mime.indexOf( 'audio' ) ) {
$field.val( attachment.url );
// show one preview at a time
mediaPreview( attachment );
} else if ( 0 === attachment.mime.indexOf( 'video' ) ) {
attachment.src = attachment.url;
$field.val( wp.shortcode.string( {
tag: 'video',
attrs: _.pick( attachment, 'src', 'width', 'height' )
} ) );
// show one preview at a time
mediaPreview( attachment );
} else {
html = wp.media.string.image({
size: 'full',
align : false,
link : 'none'
}, attachment);
// set the hidden input's value
$field.val( html );
$( '#image-preview' ).remove();
if ( attachment.width ) {
w = attachment.width > 600 ? 600 : attachment.width;
}
if ( attachment.height ) {
h = attachment.height;
}
if ( w < attachment.width ) {
h = Math.round( ( h * w ) / attachment.width );
}
$holder.parent().prepend( ['<div id="image-preview" class="wp-format-media-preview">',
'<img src="', attachment.url, '"',
w ? ' width="' + w + '"' : '',
h ? ' height="' + h + '"' : '',
' />',
'</div>'].join( '' ) );
}
});
mediaFrame.open();
});
});
}( jQuery ) );

File diff suppressed because one or more lines are too long

View File

@ -2676,8 +2676,7 @@ function wp_insert_post($postarr, $wp_error = false) {
}
$maybe_empty = ! $post_content && ! $post_title && ! $post_excerpt && post_type_supports( $post_type, 'editor' )
&& post_type_supports( $post_type, 'title' ) && post_type_supports( $post_type, 'excerpt' )
&& ! in_array( get_post_format( $post_ID ), array( 'audio', 'video', 'quote', 'image' ) );
&& post_type_supports( $post_type, 'title' ) && post_type_supports( $post_type, 'excerpt' );
if ( apply_filters( 'wp_insert_post_empty_content', $maybe_empty, $postarr ) ) {
if ( $wp_error )

View File

@ -415,8 +415,6 @@ function wp_default_scripts( &$scripts ) {
'comma' => _x( ',', 'tag delimiter' ),
) );
$scripts->add( 'post-formats', "/wp-admin/js/post-formats$suffix.js", array( 'media-models', 'wp-plupload' ), 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' ) );