# Quick Draft for Pages and Custom Post Types

> Adds a dashboard widget like Quick Draft that lets you start a draft of any post type, such as a page, product or event, with a title and a few notes.

- Type: PHP
- Runs: Admin only
- Category: [Dashboard](https://wpide.com/library/category/dashboard/)
- Tags: dashboard-widget, drafts, post-types
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/dash-quick-draft-any-type/

## Code

```php
add_action( 'wp_dashboard_setup', function () {
    if ( ! current_user_can( 'edit_posts' ) ) {
        return;
    }

    wp_add_dashboard_widget( 'wpide_quick_draft_any', 'Quick draft (any type)', function () {
        $types = array_filter( get_post_types( array( 'show_ui' => true, 'public' => true ), 'objects' ), function ( $type ) {
            return 'attachment' !== $type->name && current_user_can( $type->cap->edit_posts );
        } );

        if ( ! empty( $_GET['wpide_qd'] ) ) {
            $id = absint( $_GET['wpide_qd'] );
            printf( '<div class="notice notice-success inline"><p>Draft saved. <a href="%s">Continue editing</a></p></div>', esc_url( get_edit_post_link( $id ) ) );
        }
        ?>
        <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
            <input type="hidden" name="action" value="wpide_quick_draft">
            <?php wp_nonce_field( 'wpide_quick_draft', 'wpide_qd_nonce' ); ?>
            <p><label for="wpide-qd-type">Type</label><br>
                <select id="wpide-qd-type" name="wpide_qd_type">
                    <?php foreach ( $types as $type ) : ?>
                        <option value="<?php echo esc_attr( $type->name ); ?>"><?php echo esc_html( $type->labels->singular_name ); ?></option>
                    <?php endforeach; ?>
                </select></p>
            <p><label for="wpide-qd-title">Title</label><br><input id="wpide-qd-title" name="wpide_qd_title" type="text" class="widefat" required></p>
            <p><label for="wpide-qd-content">Notes</label><br><textarea id="wpide-qd-content" name="wpide_qd_content" rows="3" class="widefat"></textarea></p>
            <p><button class="button button-primary">Save draft</button></p>
        </form>
        <?php
    } );
} );

add_action( 'admin_post_wpide_quick_draft', function () {
    check_admin_referer( 'wpide_quick_draft', 'wpide_qd_nonce' );

    $type   = isset( $_POST['wpide_qd_type'] ) ? sanitize_key( $_POST['wpide_qd_type'] ) : 'post';
    $object = get_post_type_object( $type );
    if ( ! $object || ! current_user_can( $object->cap->edit_posts ) ) {
        wp_die( 'Not allowed.', 403 );
    }

    $id = wp_insert_post( array(
        'post_type'    => $type,
        'post_status'  => 'draft',
        'post_title'   => isset( $_POST['wpide_qd_title'] ) ? sanitize_text_field( wp_unslash( $_POST['wpide_qd_title'] ) ) : '',
        'post_content' => isset( $_POST['wpide_qd_content'] ) ? wp_kses_post( wp_unslash( $_POST['wpide_qd_content'] ) ) : '',
        'post_author'  => get_current_user_id(),
    ) );

    wp_safe_redirect( add_query_arg( 'wpide_qd', (int) $id, admin_url( 'index.php' ) ) );
    exit;
} );
```

## Notes

After saving you get a link to continue editing the new draft.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Quick Draft for Pages and Custom Post Types" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
