Make WordPress Core

Changeset 24092


Ignore:
Timestamp:
04/25/2013 07:28:33 AM (12 years ago)
Author:
markjaquith
Message:

Screen option for Post Format UI.

props nacin. see #23930.

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r23692 r24092  
    5757    'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment',
    5858    'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor',
    59     'send-attachment-to-editor', 'save-attachment-order', 'heartbeat'
     59    'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'show-post-format-ui',
    6060);
    6161
  • trunk/wp-admin/css/wp-admin.css

    r24085 r24092  
    39393939}
    39403940
     3941.no-ui {
     3942    display: none;
     3943}
     3944
    39413945.post-formats-fields {
    39423946    display: none;
  • trunk/wp-admin/edit-form-advanced.php

    r24084 r24092  
    147147    }
    148148
     149    $user_wants = get_user_option( 'post_formats_' . $post_type );
     150    if ( false !== $user_wants ) {
     151        // User wants what user gets.
     152        $show_post_format_ui = (bool) $user_wants;
     153    } else {
     154        // UI is shown when the theme supports formats, or if the site has formats assigned to posts.
     155        $show_post_format_ui = current_theme_supports( 'post-formats' ) || get_terms( 'post_format', array( 'number' => 1 ) );
     156    }
     157
    149158    $format_class = " class='wp-format-{$post_format}'";
    150159
     
    384393</div>
    385394<?php if ( ! empty( $post_format_options ) ) : ?>
    386 <div class="post-format-options">
    387     <?php echo $post_format_options; ?>
     395<div class="wp-post-format-ui<?php if ( ! $show_post_format_ui ) echo ' no-ui' ?>">
     396    <div class="post-format-options">
     397        <?php echo $post_format_options; ?>
     398    </div>
    388399</div>
    389400<?php endif; ?>
  • trunk/wp-admin/includes/ajax-actions.php

    r24019 r24092  
    11361136}
    11371137
     1138function wp_ajax_show_post_format_ui() {
     1139    error_log( serialize( $_REQUEST ) );
     1140
     1141    if ( empty( $_POST['post_type'] ) )
     1142        wp_die( 0 );
     1143
     1144    check_ajax_referer( 'show-post-format-ui_' . $_POST['post_type'], 'nonce' );
     1145
     1146    if ( ! $post_type_object = get_post_type_object( $_POST['post_type'] ) )
     1147        wp_die( 0 );
     1148
     1149    if ( ! current_user_can( $post_type_object->cap->edit_posts ) )
     1150        wp_die( -1 );
     1151
     1152    update_user_option( get_current_user_id(), 'post_formats_' . $post_type_object->name, empty( $_POST['show'] ) ? 0 : 1 );
     1153
     1154    wp_die( 1 );
     1155}
     1156
    11381157function wp_ajax_hidden_columns() {
    11391158    check_ajax_referer( 'screen-options-nonce', 'screenoptionnonce' );
  • trunk/wp-admin/includes/post-formats.php

    r24034 r24092  
    11<?php
     2
     3defined( 'ABSPATH' ) or die;
     4
    25global $wp_embed;
    36
    47$format_meta = get_post_format_meta( $post_ID );
    58
     9wp_nonce_field( 'show-post-format-ui_' . $post_type, 'show_post_format_ui_nonce', false );
     10
    611?>
    7 <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>
    8 <div class="post-formats-fields">
     12<div class="wp-post-format-ui<?php if ( ! $show_post_format_ui ) echo ' no-ui' ?>">
     13    <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>
     14    <div class="post-formats-fields">
    915
    10     <input type="hidden" name="post_format" id="post_format" value="<?php echo esc_attr( $post_format ); ?>" />
     16        <input type="hidden" name="post_format" id="post_format" value="<?php echo esc_attr( $post_format ); ?>" />
    1117
    12     <div class="field wp-format-quote">
    13         <label for="wp_format_quote_source"><?php _e( 'Quote source' ); ?></label>
    14         <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" />
    15     </div>
     18        <div class="field wp-format-quote">
     19            <label for="wp_format_quote_source"><?php _e( 'Quote source' ); ?></label>
     20            <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" />
     21        </div>
    1622
    17     <div class="field wp-format-image">
    18         <?php if ( ! empty( $format_meta['image'] ) ) :
    19             $value = $format_meta['image'];
    20         ?>
    21         <div id="image-preview" class="wp-format-media-preview">
    22             <?php
    23                 if ( is_numeric( $value ) ) {
    24                     $image = wp_get_attachment_url( $value );
    25                     printf( '<img src="%s" alt="%s" />', esc_url( $image ), get_the_title( $value ) );
    26                 } elseif ( preg_match( '/' . get_shortcode_regex() . '/s', $value ) ) {
    27                     echo do_shortcode( $value );
    28                 } elseif ( ! preg_match( '#<[^>]+>#', $value ) ) {
    29                     printf( '<img src="%s" alt="" />', esc_url( $value ) );
    30                 } else {
    31                     echo $value;
    32                 }
     23        <div class="field wp-format-image">
     24            <?php if ( ! empty( $format_meta['image'] ) ) :
     25                $value = $format_meta['image'];
    3326            ?>
     27            <div id="image-preview" class="wp-format-media-preview">
     28                <?php
     29                    if ( is_numeric( $value ) ) {
     30                        $image = wp_get_attachment_url( $value );
     31                        printf( '<img src="%s" alt="%s" />', esc_url( $image ), get_the_title( $value ) );
     32                    } elseif ( preg_match( '/' . get_shortcode_regex() . '/s', $value ) ) {
     33                        echo do_shortcode( $value );
     34                    } elseif ( ! preg_match( '#<[^>]+>#', $value ) ) {
     35                        printf( '<img src="%s" alt="" />', esc_url( $value ) );
     36                    } else {
     37                        echo $value;
     38                    }
     39                ?>
     40            </div>
     41            <?php endif ?>
     42            <label for="wp_format_image"><?php
     43                if ( current_user_can( 'unfiltered_html' ) )
     44                    _e( 'Image HTML or URL' );
     45                else
     46                    _e( 'Image URL' );
     47            ?></label>
     48            <textarea id="wp_format_image" type="text" name="_format_image" class="widefat"><?php esc_html_e( $format_meta['image'] ); ?></textarea>
     49            <div data-format="image" class="wp-format-media-holder hide-if-no-js">
     50                <a href="#" class="wp-format-media-select"
     51                    data-choose="<?php esc_attr_e( 'Choose an Image' ); ?>"
     52                    data-update="<?php esc_attr_e( 'Select Image' ); ?>">
     53                    <?php _e( 'Select / Upload Image' ); ?>
     54                </a>
     55            </div>
    3456        </div>
    35         <?php endif ?>
    36         <label for="wp_format_image"><?php
    37             if ( current_user_can( 'unfiltered_html' ) )
    38                 _e( 'Image HTML or URL' );
    39             else
    40                 _e( 'Image URL' );
    41         ?></label>
    42         <textarea id="wp_format_image" type="text" name="_format_image" class="widefat"><?php esc_html_e( $format_meta['image'] ); ?></textarea>
    43         <div data-format="image" class="wp-format-media-holder hide-if-no-js">
    44             <a href="#" class="wp-format-media-select"
    45                 data-choose="<?php esc_attr_e( 'Choose an Image' ); ?>"
    46                 data-update="<?php esc_attr_e( 'Select Image' ); ?>">
    47                 <?php _e( 'Select / Upload Image' ); ?>
    48             </a>
     57
     58        <div class="field wp-format-link">
     59            <label for="wp_format_link_url"><?php _e( 'Link URL' ); ?></label>
     60            <input type="text" id="wp_format_link_url" name="_format_link_url" value="<?php echo esc_url( $format_meta['link_url'] ); ?>" class="widefat" />
    4961        </div>
    50     </div>
    5162
    52     <div class="field wp-format-link">
    53         <label for="wp_format_link_url"><?php _e( 'Link URL' ); ?></label>
    54         <input type="text" id="wp_format_link_url" name="_format_link_url" value="<?php echo esc_url( $format_meta['link_url'] ); ?>" class="widefat" />
    55     </div>
     63        <div class="field wp-format-quote">
     64            <label for="wp_format_quote_source_url"><?php _e( 'Link URL' ); ?></label>
     65            <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" />
     66        </div>
    5667
    57     <div class="field wp-format-quote">
    58         <label for="wp_format_quote_source_url"><?php _e( 'Link URL' ); ?></label>
    59         <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" />
    60     </div>
     68        <div class="field wp-format-image">
     69            <label for="wp_format_image_url"><?php _e( 'Link URL' ); ?></label>
     70            <input type="text" id="wp_format_image_url" name="_format_url" value="<?php echo esc_url( $format_meta['url'] ); ?>" class="widefat" />
     71        </div>
    6172
    62     <div class="field wp-format-image">
    63         <label for="wp_format_image_url"><?php _e( 'Link URL' ); ?></label>
    64         <input type="text" id="wp_format_image_url" name="_format_url" value="<?php echo esc_url( $format_meta['url'] ); ?>" class="widefat" />
    65     </div>
     73        <div class="field wp-format-video">
     74            <?php if ( ! empty( $format_meta['video_embed'] ) ):
     75                $value = $format_meta['video_embed'];
     76            ?>
     77            <div id="video-preview" class="wp-format-media-preview">
     78                <?php
     79                    if ( is_numeric( $value ) ) {
     80                        $video = wp_get_attachment_url( $value );
     81                        echo do_shortcode( sprintf( '[video src="%s"]', $video ) );
     82                    } elseif ( preg_match( '/' . get_shortcode_regex() . '/s', $value ) ) {
     83                        echo do_shortcode( $value );
     84                    } elseif ( ! preg_match( '#<[^>]+>#', $value ) ) {
     85                        if ( strstr( $value, home_url() ) )
     86                            echo do_shortcode( sprintf( '[video src="%s"]', $value ) );
     87                        else
     88                            echo $wp_embed->autoembed( $value );
     89                    } else {
     90                        echo $value;
     91                    }
     92                ?>
     93            </div>
     94            <?php endif; ?>
     95            <label for="wp_format_video"><?php
     96                if ( current_user_can( 'unfiltered_html' ) )
     97                    _e( 'Video embed code or URL' );
     98                else
     99                    _e( 'Video URL' );
     100            ?></label>
     101            <textarea id="wp_format_video" type="text" name="_format_video_embed" class="widefat"><?php esc_html_e( $format_meta['video_embed'] ); ?></textarea>
     102            <div data-format="video" class="wp-format-media-holder hide-if-no-js">
     103                <a href="#" class="wp-format-media-select"
     104                    data-choose="<?php esc_attr_e( 'Choose a Video' ); ?>"
     105                    data-update="<?php esc_attr_e( 'Select Video' ); ?>">
     106                    <?php _e( 'Select Video From Media Library' ) ?>
     107                </a>
     108            </div>
     109        </div>
    66110
    67     <div class="field wp-format-video">
    68         <?php if ( ! empty( $format_meta['video_embed'] ) ):
    69             $value = $format_meta['video_embed'];
    70         ?>
    71         <div id="video-preview" class="wp-format-media-preview">
    72             <?php
    73                 if ( is_numeric( $value ) ) {
    74                     $video = wp_get_attachment_url( $value );
    75                     echo do_shortcode( sprintf( '[video src="%s"]', $video ) );
    76                 } elseif ( preg_match( '/' . get_shortcode_regex() . '/s', $value ) ) {
    77                     echo do_shortcode( $value );
    78                 } elseif ( ! preg_match( '#<[^>]+>#', $value ) ) {
    79                     if ( strstr( $value, home_url() ) )
    80                         echo do_shortcode( sprintf( '[video src="%s"]', $value ) );
    81                     else
    82                         echo $wp_embed->autoembed( $value );
    83                 } else {
    84                     echo $value;
    85                 }
     111        <div class="field wp-format-audio">
     112            <?php if ( ! empty( $format_meta['audio_embed'] ) ):
     113                $value = $format_meta['audio_embed'];
    86114            ?>
    87         </div>
    88         <?php endif; ?>
    89         <label for="wp_format_video"><?php
    90             if ( current_user_can( 'unfiltered_html' ) )
    91                 _e( 'Video embed code or URL' );
    92             else
    93                 _e( 'Video URL' );
    94         ?></label>
    95         <textarea id="wp_format_video" type="text" name="_format_video_embed" class="widefat"><?php esc_html_e( $format_meta['video_embed'] ); ?></textarea>
    96         <div data-format="video" class="wp-format-media-holder hide-if-no-js">
    97             <a href="#" class="wp-format-media-select"
    98                 data-choose="<?php esc_attr_e( 'Choose a Video' ); ?>"
    99                 data-update="<?php esc_attr_e( 'Select Video' ); ?>">
    100                 <?php _e( 'Select Video From Media Library' ) ?>
    101             </a>
    102         </div>
    103     </div>
    104 
    105     <div class="field wp-format-audio">
    106         <?php if ( ! empty( $format_meta['audio_embed'] ) ):
    107             $value = $format_meta['audio_embed'];
    108         ?>
    109         <div id="audio-preview" class="wp-format-media-preview">
    110             <?php
    111                 if ( is_numeric( $value ) ) {
    112                     $audio = wp_get_attachment_url( $value );
    113                     echo do_shortcode( sprintf( '[audio src="%s"]', $audio ) );
    114                 } elseif ( preg_match( '/' . get_shortcode_regex() . '/s', $value ) ) {
    115                     echo do_shortcode( $value );
    116                 } elseif ( ! preg_match( '#<[^>]+>#', $value ) ) {
    117                     if ( strstr( $value, home_url() ) )
    118                         echo do_shortcode( sprintf( '[audio src="%s"]', $value ) );
    119                     else
    120                         echo $wp_embed->autoembed( $value );
    121                 } else {
    122                     echo $value;
    123                 }
    124             ?>
    125         </div>
    126         <?php endif; ?>
    127         <label for="wp_format_audio"><?php
    128             if ( current_user_can( 'unfiltered_html' ) )
    129                 _e( 'Audio embed code or URL' );
    130             else
    131                 _e( 'Audio URL' );
    132         ?></label>
    133         <textarea id="wp_format_audio" name="_format_audio_embed" class="widefat"><?php esc_html_e( $format_meta['audio_embed'] ); ?></textarea>
    134         <div data-format="audio" class="wp-format-media-holder hide-if-no-js">
    135             <a href="#" class="wp-format-media-select" data-choose="<?php esc_attr_e( 'Choose Audio' ); ?>" data-update="<?php esc_attr_e( 'Select Audio' ); ?>">
    136                 <?php _e( 'Select Audio From Media Library' ) ?>
    137             </a>
     115            <div id="audio-preview" class="wp-format-media-preview">
     116                <?php
     117                    if ( is_numeric( $value ) ) {
     118                        $audio = wp_get_attachment_url( $value );
     119                        echo do_shortcode( sprintf( '[audio src="%s"]', $audio ) );
     120                    } elseif ( preg_match( '/' . get_shortcode_regex() . '/s', $value ) ) {
     121                        echo do_shortcode( $value );
     122                    } elseif ( ! preg_match( '#<[^>]+>#', $value ) ) {
     123                        if ( strstr( $value, home_url() ) )
     124                            echo do_shortcode( sprintf( '[audio src="%s"]', $value ) );
     125                        else
     126                            echo $wp_embed->autoembed( $value );
     127                    } else {
     128                        echo $value;
     129                    }
     130                ?>
     131            </div>
     132            <?php endif; ?>
     133            <label for="wp_format_audio"><?php
     134                if ( current_user_can( 'unfiltered_html' ) )
     135                    _e( 'Audio embed code or URL' );
     136                else
     137                    _e( 'Audio URL' );
     138            ?></label>
     139            <textarea id="wp_format_audio" name="_format_audio_embed" class="widefat"><?php esc_html_e( $format_meta['audio_embed'] ); ?></textarea>
     140            <div data-format="audio" class="wp-format-media-holder hide-if-no-js">
     141                <a href="#" class="wp-format-media-select" data-choose="<?php esc_attr_e( 'Choose Audio' ); ?>" data-update="<?php esc_attr_e( 'Select Audio' ); ?>">
     142                    <?php _e( 'Select Audio From Media Library' ) ?>
     143                </a>
     144            </div>
    138145        </div>
    139146    </div>
  • trunk/wp-admin/includes/screen.php

    r24081 r24092  
    963963                        echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />';
    964964                        echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n";
     965                    } elseif ( 'post' == $this->base && post_type_supports( $this->post_type, 'post-formats' ) && apply_filters( 'enable_post_format_ui', true, $GLOBALS['post'] ) ) {
     966                        $user_wants = get_user_option( 'post_formats_' . $this->post_type );
     967                        if ( false !== $user_wants ) {
     968                            // User wants what user gets.
     969                            $show_post_format_ui = (bool) $user_wants;
     970                        } else {
     971                            // UI is shown when the theme supports formats, or if the site has formats assigned to posts.
     972                            $show_post_format_ui = current_theme_supports( 'post-formats' ) || get_terms( 'post_format', array( 'number' => 1 ) );
     973                        }
     974                        echo '<label for="show_post_format_ui">';
     975                        echo '<input type="checkbox" id="show_post_format_ui"' . checked( $show_post_format_ui, true, false ) . ' />';
     976                        echo __( 'Post Formats' ) . "</label>\n";
    965977                    }
    966978                ?>
  • trunk/wp-admin/js/post-formats.js

    r24088 r24092  
    109109            resizeContent( initialFormat, true );
    110110        }
     111
     112        $('#show_post_format_ui').on('change', function() {
     113            $('.wp-post-format-ui').toggleClass('no-ui', ! this.checked );
     114            $.post( ajaxurl, {
     115                action: 'show-post-format-ui',
     116                post_type: $('#post_type').val(),
     117                show: this.checked ? 1 : 0,
     118                nonce: $('#show_post_format_ui_nonce').val()
     119            });
     120        });
    111121
    112122        $('.post-format-change a').click(function() {
  • trunk/wp-includes/user.php

    r24056 r24092  
    276276    if ( !$global )
    277277        $option_name = $wpdb->prefix . $option_name;
    278 
    279     // For backward compatibility. See differences between update_user_meta() and deprecated update_usermeta().
    280     // http://core.trac.wordpress.org/ticket/13088
    281     if ( is_null( $newvalue ) || is_scalar( $newvalue ) && empty( $newvalue ) )
    282         return delete_user_meta( $user_id, $option_name );
    283278
    284279    return update_user_meta( $user_id, $option_name, $newvalue );
Note: See TracChangeset for help on using the changeset viewer.