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
This commit is contained in:
Mark Jaquith 2013-04-25 07:28:33 +00:00
parent 3f231a1758
commit 082e067a2d
8 changed files with 185 additions and 127 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'
'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'show-post-format-ui',
);
// Register core Ajax calls.

View File

@ -3938,6 +3938,10 @@ body .ui-tooltip {
padding-bottom: 0;
}
.no-ui {
display: none;
}
.post-formats-fields {
display: none;
margin-bottom: 15px;

View File

@ -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
<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="post-format-options">
<?php echo $post_format_options; ?>
<div class="wp-post-format-ui<?php if ( ! $show_post_format_ui ) echo ' no-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'); ?>>

View File

@ -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'] : '';

View File

@ -1,140 +1,147 @@
<?php
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="post-format-change"><span class="icon <?php echo esc_attr( $post_format ); ?>"></span> <span class="post-format-description"><?php echo $all_post_formats[$post_format]['description']; ?></span> <a href="#"><?php _e('Change format'); ?></a></div>
<div class="post-formats-fields">
<div class="wp-post-format-ui<?php if ( ! $show_post_format_ui ) echo ' no-ui' ?>">
<div class="post-format-change"><span class="icon <?php echo esc_attr( $post_format ); ?>"></span> <span class="post-format-description"><?php echo $all_post_formats[$post_format]['description']; ?></span> <a href="#"><?php _e('Change format'); ?></a></div>
<div class="post-formats-fields">
<input type="hidden" name="post_format" id="post_format" value="<?php echo esc_attr( $post_format ); ?>" />
<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-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 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 ?>
<label for="wp_format_image"><?php
if ( current_user_can( 'unfiltered_html' ) )
_e( 'Image HTML or URL' );
else
_e( 'Image URL' );
?></label>
<textarea id="wp_format_image" type="text" name="_format_image" class="widefat"><?php esc_html_e( $format_meta['image'] ); ?></textarea>
<div data-format="image" class="wp-format-media-holder hide-if-no-js">
<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>
<?php endif ?>
<label for="wp_format_image"><?php
if ( current_user_can( 'unfiltered_html' ) )
_e( 'Image HTML or URL' );
else
_e( 'Image URL' );
?></label>
<textarea id="wp_format_image" type="text" name="_format_image" class="widefat"><?php esc_html_e( $format_meta['image'] ); ?></textarea>
<div data-format="image" class="wp-format-media-holder hide-if-no-js">
<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 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" />
</div>
</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" />
</div>
<div class="field wp-format-quote">
<label for="wp_format_quote_source_url"><?php _e( 'Link URL' ); ?></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" />
</div>
<div class="field wp-format-quote">
<label for="wp_format_quote_source_url"><?php _e( 'Link URL' ); ?></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" />
</div>
<div class="field wp-format-image">
<label for="wp_format_image_url"><?php _e( 'Link URL' ); ?></label>
<input type="text" id="wp_format_image_url" name="_format_url" value="<?php echo esc_url( $format_meta['url'] ); ?>" class="widefat" />
</div>
<div class="field wp-format-image">
<label for="wp_format_image_url"><?php _e( 'Link URL' ); ?></label>
<input type="text" id="wp_format_image_url" name="_format_url" value="<?php echo esc_url( $format_meta['url'] ); ?>" class="widefat" />
</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 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 esc_html_e( $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>
<?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 esc_html_e( $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 class="field wp-format-audio">
<?php if ( ! empty( $format_meta['audio_embed'] ) ):
$value = $format_meta['audio_embed'];
?>
</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 esc_html_e( $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 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 esc_html_e( $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>
</div>

View File

@ -962,6 +962,18 @@ 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, $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 '<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

@ -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();

View File

@ -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 );
}