Plugin Directory


Ignore:
Timestamp:
10/09/2013 05:49:27 PM (12 years ago)
Author:
lessbloat
Message:

Made a few tweaks to Quick Drafts widget:

  • Show just the 3 latest drafts
  • Only show "view all" link if there are more than 3 drafts
  • Adjusted padding/margins so that horizontal dividing line stretches all the way across the box
  • on click for the form changed effect from show() to slideDown()
  • Changed no drafts notice from "There are no drafts at the moment" to "You have yet to add any drafts."
  • Removed tags field
  • Removed media upload button
  • Hooked up new form post callback function
  • Adjusted margin between draft title and draft description to adjust for drafts with just a title
  • Added 1 sec yellow background highlight on submit to show recently added draft in list below form
File:
1 edited

Legend:

Unmodified
Added
Removed
  • dashboard/trunk/quickdraft.php

    r784283 r785449  
    99}
    1010
     11add_action( 'admin_post_new-quickdraft-post', 'dashboard_plugin_quickdraft_admin_post' );
     12function dashboard_plugin_quickdraft_admin_post() {
     13    $post = get_post( $_REQUEST['post_ID'] );
     14    check_admin_referer( 'add-' . $post->post_type );
     15    edit_post();
     16    return wp_dashboard_quick_draft();
     17}
     18
    1119// The QuickDraft widget display and creation of drafts
    1220function wp_dashboard_quick_draft() {
    1321    global $post_ID;
    14 
    15     if ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['action'] ) && 0 === strpos( $_POST['action'], 'post-quickpress' ) && (int) $_POST['post_ID'] ) {
    16         $view = get_permalink( $_POST['post_ID'] );
    17         $edit = esc_url( get_edit_post_link( $_POST['post_ID'] ) );
    18         if ( 'post-quickpress-publish' == $_POST['action'] ) {
    19             if ( current_user_can('publish_posts') )
    20                 printf( '<div class="updated"><p>' . __( 'Post published. <a href="%s">View post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( $view ), $edit );
    21             else
    22                 printf( '<div class="updated"><p>' . __( 'Post submitted. <a href="%s">Preview post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( add_query_arg( 'preview', 1, $view ) ), $edit );
    23         } else {
    24             printf( '<div class="updated"><p>' . __( 'Draft saved. <a href="%s">Preview post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( add_query_arg( 'preview', 1, $view ) ), $edit );
    25         }
    26         printf('<p class="easy-blogging">' . __('You can also try %s, easy blogging from anywhere on the Web.') . '</p>', '<a href="' . esc_url( admin_url( 'tools.php' ) ) . '">' . __('Press This') . '</a>' );
    27         $_REQUEST = array(); // hack for get_default_post_to_edit()
    28     }
    2922
    3023    /* Check if a new auto-draft (= no new post_ID) is needed or if the old can be used */
     
    4740
    4841    $post_ID = (int) $post->ID;
    49 
    50     $media_settings = array(
    51         'id' => $post->ID,
    52         'nonce' => wp_create_nonce( 'update-post_' . $post->ID ),
    53     );
    54 
    55     if ( current_theme_supports( 'post-thumbnails', $post->post_type ) && post_type_supports( $post->post_type, 'thumbnail' ) ) {
    56         $featured_image_id = get_post_meta( $post->ID, '_thumbnail_id', true );
    57         $media_settings['featuredImageId'] = $featured_image_id ? $featured_image_id : -1;
    58     }
    5942?>
    6043
    61     <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press" class="initial-form">
     44    <form name="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post" id="quick-press" class="initial-form">
    6245        <div class="input-text-wrap" id="title-wrap">
    63             <label class="screen-reader-text prompt" for="title" id="title-prompt-text"><?php _e( 'Enter title here' ); ?></label>
    64             <input type="text" name="post_title" id="title" autocomplete="off" value="<?php echo esc_attr( $post->post_title ); ?>" />
     46            <label class="screen-reader-text prompt" for="title" id="title-prompt-text"><?php _e( "What's on your mind?" ); ?></label>
     47            <input type="text" name="post_title" id="title" autocomplete="off" />
    6548        </div>
    6649
    67         <?php if ( current_user_can( 'upload_files' ) ) : ?>
    68         <div id="wp-content-wrap" class="wp-editor-wrap hide-if-no-js wp-media-buttons">
    69             <?php do_action( 'media_buttons', 'content' ); ?>
    70         </div>
    71         <?php endif; ?>
    72 
    73         <div class="textarea-wrap">
    74             <label class="screen-reader-text prompt" for="content" id="content-prompt-text"><?php _e( "What's on your mind?" ); ?></label>
    75             <textarea name="content" id="content" class="mceEditor" rows="3" cols="15"><?php echo esc_textarea( $post->post_content ); ?></textarea>
    76         </div>
    77 
    78         <script type="text/javascript">
    79         edCanvas = document.getElementById('content');
    80         edInsertContent = null;
    81         <?php if ( $_POST ) : ?>
    82         wp.media.editor.remove('content');
    83         wp.media.view.settings.post = <?php echo json_encode( $media_settings ); // big juicy hack. ?>;
    84         wp.media.editor.add('content');
    85         <?php endif; ?>
    86         </script>
    87 
    88         <div class="input-text-wrap" id="tags-input-wrap">
    89             <label class="screen-reader-text prompt" for="tags-input" id="tags-input-prompt-text"><?php _e( 'Tags (separate with commas)' ); ?></label>
    90             <input type="text" name="tags_input" id="tags-input" value="<?php echo get_tags_to_edit( $post->ID ); ?>" />
     50        <div class="textarea-wrap" id="description-wrap">
     51            <label class="screen-reader-text prompt" for="content" id="content-prompt-text"><?php _e( 'Enter a description' ); ?></label>
     52            <textarea name="content" id="content" class="mceEditor" rows="3" cols="15"></textarea>
    9153        </div>
    9254
    9355        <p class="submit">
    94             <input type="hidden" name="action" id="quickpost-action" value="post-quickpress-save" />
     56            <input type="hidden" name="action" id="quickpost-action" value="new-quickdraft-post" />
    9557            <input type="hidden" name="post_ID" value="<?php echo $post_ID; ?>" />
    9658            <input type="hidden" name="post_type" value="post" />
     
    11274            'post_status'    => 'draft',
    11375            'author'         => $GLOBALS['current_user']->ID,
    114             'posts_per_page' => 5,
     76            'posts_per_page' => 4,
    11577            'orderby'        => 'modified',
    11678            'order'          => 'DESC'
     
    12183    if ( $drafts && is_array( $drafts ) ) {
    12284        $list = array();
     85        $draft_count = 0;
    12386        foreach ( $drafts as $draft ) {
     87            if ( 3 == $draft_count )
     88                break;
     89           
     90            $draft_count++;
     91           
    12492            $url = get_edit_post_link( $draft->ID );
    12593            $title = _draft_or_post_title( $draft->ID );
     
    13199?>
    132100    <div class="drafts">
     101        <?php if ( 3 < count($drafts) ) { ?>
    133102        <p class="view-all"><a href="edit.php?post_status=draft" ><?php _e('View all'); ?></a></p>
     103        <?php } ?>
    134104        <p class="title"><?php _e('Drafts'); ?></p>
    135105        <ul id="draft-list">
     
    138108    </div>
    139109<?php } else { ?>
    140     <div class="drafts"><p><?php _e('There are no drafts at the moment'); ?></p></div>
     110    <div class="drafts"><p><?php _e("You have yet to add any drafts."); ?></p></div>
    141111<?php }
    142112}
Note: See TracChangeset for help on using the changeset viewer.