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:
parent
3f231a1758
commit
082e067a2d
|
@ -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.
|
||||
|
|
|
@ -3938,6 +3938,10 @@ body .ui-tooltip {
|
|||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
.no-ui {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.post-formats-fields {
|
||||
display: none;
|
||||
margin-bottom: 15px;
|
||||
|
|
|
@ -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">
|
||||
<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'); ?>>
|
||||
|
|
|
@ -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'] : '';
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
<?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 ); ?>" />
|
||||
|
||||
|
@ -137,4 +143,5 @@ $format_meta = get_post_format_meta( $post_ID );
|
|||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -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" />
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue