Make WordPress Core


Ignore:
Timestamp:
03/29/2013 03:35:41 AM (13 years ago)
Author:
markjaquith
Message:

Post Format UI.

  • Icons
  • Selection
  • Prompt text
  • Special fields
  • Styling
  • Sparkles

This is going to need testing, polish, and love.

see #19570. props melchoyce, helen, wonderboymusic, lessbloat, rachelbaker, aaroncampbell, DrewAPicture, ryelle.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-form-advanced.php

    r23766 r23843  
    131131if ( post_type_supports( $post_type, 'post-formats' ) ) {
    132132    wp_enqueue_script( 'post-formats' );
     133    wp_enqueue_script( 'wp-mediaelement' );
     134    wp_enqueue_style( 'wp-mediaelement' );
    133135    $post_format = get_post_format();
    134136
     
    138140    $format_class = " class='wp-format-{$post_format}'";
    139141}
     142
     143if ( post_type_supports( $post_type, 'post-formats' ) ) {
     144    $all_post_formats = array(
     145        'standard' => array (
     146            'description' => __( 'Add a title and use the editor to compose your post.' )
     147        ),
     148        'image' => array (
     149            'description' => __( 'Select or upload an image to use for your post.' )
     150        ),
     151        'gallery' => array (
     152            'description' => __( 'Use the Add Media button to select or upload images for your gallery.' )
     153        ),
     154        'link' => array (
     155            'description' => __( 'Add a link URL below.' )
     156        ),
     157        'video' => array (
     158            'description' => __( 'Paste a video embed into the box, upload a video file, or choose one from your Media Library.' )
     159        ),
     160        'audio' => array (
     161            'description' => __( 'Paste an audio embed into the box, upload an audio file, or choose one from your Media Library.' )
     162        ),
     163        'chat' => array (
     164            'description' => __( 'Copy a chat or Q&A transcript into the editor.' )
     165        ),
     166        'status' => array (
     167            'description' => __( 'Use the editor to compose a status update. What’s new?' )
     168        ),
     169        'quote' => array (
     170            'description' => __( 'Copy a quotation into the box. Also add the source and URL if you have them.' )
     171        ),
     172        'aside' => array (
     173            'description' => __( 'An aside is a quick thought or side topic. Use the editor to compose one.' )
     174        )
     175    );
     176    $post_format_options = '';
     177
     178    foreach ( $all_post_formats as $slug => $attr ) {
     179        $class = '';
     180        if ( $post_format == $slug ) {
     181            $class = 'class="active"';
     182            $active_post_type_slug = $slug;
     183            $active_post_type_label = ucfirst( $slug );
     184            $active_post_format_description = $attr['description'];
     185        }
     186
     187        $post_format_options .= '<a ' . $class . ' href="?format=' . $slug . '" data-description="' . $attr['description'] . '" data-wp-format="' . $slug . '" title="' . ucfirst( sprintf( __( '%s Post' ), $slug ) ) . '"><div class="' . $slug . '"></div></a>';
     188    }
     189}
     190
     191$current_post_format = array( 'currentPostFormat' => esc_html( $active_post_type_slug ) );
     192wp_localize_script( 'post', 'postFormats', $current_post_format );
    140193
    141194if ( post_type_supports($post_type, 'page-attributes') )
     
    338391
    339392<div id="poststuff">
    340 
    341 <?php
    342 if ( post_type_supports( $post_type, 'post-formats' ) ) {
    343     $all_post_formats = get_post_format_strings();
    344 
    345     echo '<h2 class="nav-tab-wrapper post-format-select">';
    346 
    347     foreach ( $all_post_formats as $slug => $label ) {
    348         if ( $post_format == $slug )
    349             $class = 'nav-tab nav-tab-active';
    350         else
    351             $class = 'nav-tab';
    352 
    353         echo '<a class="' . $class . '" href="?format=' . $slug . '" data-wp-format="' . $slug . '">' . $label . '</a>';
    354     }
    355 
    356     echo '</h2>';
    357 }
    358 ?>
    359 
    360393<div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
    361394<div id="post-body-content"<?php echo $format_class; ?>>
     395
     396<?php if ( ! empty( $post_format_options ) ) : ?>
     397<div class="post-format-options">
     398    <span class="post-format-tip">Standard Post</span>
     399    <?php echo $post_format_options; ?>
     400</div>
     401<?php endif; ?>
    362402
    363403<?php if ( post_type_supports($post_type, 'title') ) { ?>
     
    374414    $sample_permalink_html .= '<input id="shortlink" type="hidden" value="' . esc_attr($shortlink) . '" /><a href="#" class="button button-small" onclick="prompt(&#39;URL:&#39;, jQuery(\'#shortlink\').val()); return false;">' . __('Get Shortlink') . '</a>';
    375415
    376 if ( $post_type_object->public && ! ( 'pending' == get_post_status( $post ) && !current_user_can( $post_type_object->cap->publish_posts ) ) ) { ?>
    377     <div id="edit-slug-box" class="hide-if-no-js">
     416if ( $post_type_object->public && ! ( 'pending' == get_post_status( $post ) && !current_user_can( $post_type_object->cap->publish_posts ) ) ) {
     417    $has_sample_permalink = $sample_permalink_html && 'auto-draft' != $post->post_status;
     418?>
     419    <div id="edit-slug-box" class="hide-if-no-js<?php if ( ! $has_sample_permalink ) echo ' hidden' ?>">
    378420    <?php
    379         if ( $sample_permalink_html && 'auto-draft' != $post->post_status )
     421        if ( $has_sample_permalink )
    380422            echo $sample_permalink_html;
    381423    ?>
     
    399441
    400442// post format fields
    401 if ( post_type_supports( $post_type, 'post-formats' ) ) {
    402     $format_meta = get_post_format_meta( $post_ID );
    403 ?>
    404 <div class="post-formats-fields edit-form-section">
    405 
    406 <input type="hidden" name="post_format" id="post_format" value="<?php echo esc_attr( $post_format ); ?>" />
    407 
    408 <div class="field wp-format-quote">
    409     <label for="_wp_format_quote" class="screen-reader-text"><?php _e( 'Quote' ); ?>:</label>
    410     <textarea name="_wp_format_quote" placeholder="<?php esc_attr_e( 'Quote' ); ?>" class="widefat"><?php echo esc_textarea( $format_meta['quote'] ); ?></textarea>
    411 </div>
    412 
    413 <div class="field wp-format-quote">
    414     <label for="_wp_format_quote_source" class="screen-reader-text"><?php _e( 'Quote source' ); ?>:</label>
    415     <input type="text" name="_wp_format_quote_source" value="<?php echo esc_attr( $format_meta['quote_source'] ); ?>" placeholder="<?php esc_attr_e( 'Quote source' ); ?>" class="widefat" />
    416 </div>
    417 
    418 <div class="field wp-format-link wp-format-quote">
    419     <label for="_wp_format_url" class="screen-reader-text"><?php _e( 'Link URL' ); ?>:</label>
    420     <input type="text" name="_wp_format_url" value="<?php echo esc_url( $format_meta['url'] ); ?>" placeholder="<?php esc_attr_e( 'Link URL' ); ?>" class="widefat" />
    421 </div>
    422 
    423 <div class="field wp-format-audio wp-format-video">
    424     <label for="_wp_format_media" class="screen-reader-text"><?php _e( 'Embed code or URL' ); ?>:</label>
    425     <textarea name="_wp_format_media" placeholder="<?php esc_attr_e( 'Embed code or URL' ); ?>" class="widefat"><?php echo esc_textarea( $format_meta['media'] ); ?></textarea>
    426 </div>
    427 
    428 </div>
    429 <?php
    430 }
     443if ( post_type_supports( $post_type, 'post-formats' ) )
     444    require_once( './includes/post-formats.php' );
    431445
    432446if ( post_type_supports($post_type, 'editor') ) {
Note: See TracChangeset for help on using the changeset viewer.