Advertising
- WordPress - QuickPress Category
- Sunday, January 3rd, 2010 at 12:13:02pm MST
- <?php
- /*
- Plugin Name: QuickPress Category
- Plugin URI: http://www.t31os.co.cc/
- Description: Adds category selection to the QuickPress widget shown in the WordPress dashboard
- Author: t31os
- Version: 1.0
- Author URI: http://www.t31os.co.cc/
- */
- class quickpress_category {
- public function quickpress_category() {
- }
- public function register_option() {
- // Register the setting - with basic validation, only need be 0/1 or true/false , keep it simple
- // Register the setting field
- add_settings_field( 'quickpress_category', 'Quickpress category', array( $this , 'add_category_option' ), 'writing', 'default' );
- }
- public function option_validation( $input ) {
- if( !$input )
- return 0;
- if( $input == 1 )
- return 1;
- else
- return 0;
- }
- // Output the checkbox for toggling the category dropdown
- public function add_category_option() {
- $checked =
- ( get_option('quickpress_category') && get_option('quickpress_category') == 1 ) ? 'checked="checked" ' : '';
- ?>
- <div class="input-text-wrap">
- <label class="selectit">
- Enable quickpress category selection.
- </label>
- </div>
- <?php
- settings_fields('enable-dropdown');
- return;
- }
- public function dashboard_updater() {
- // Global the variable so it's available inside the function (that's how you access variables outside a functions scope)
- global $wp_meta_boxes;
- // Determine where the widget is and update the callback name if the option is enabled
- switch( true ) {
- case ( !get_option( 'quickpress_category' ) || get_option( 'quickpress_category' ) == false ) :
- return;
- $wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']['callback'] = array( &$this , 'quickpress_widget' );
- return;
- $wp_meta_boxes['dashboard']['normal']['core']['dashboard_quick_press']['callback'] = array( &$this , 'quickpress_widget' );
- return;
- }
- return;
- }
- // Most of this is just code from the original widget
- public function quickpress_widget() {
- // Call $current_user, so there's no reliance on $GLOBAL, per original widget
- global $current_user;
- $drafts = false;
- if(
- $view = get_permalink( $_POST['post_ID'] );
- $edit = esc_url( get_edit_post_link( $_POST['post_ID'] ) );
- if ( 'post-quickpress-publish' == $_POST['action'] ) {
- if ( current_user_can('publish_posts') )
- printf( '<div class="message"><p>' . __( 'Post Published. <a href="%s">View post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( $view ), $edit );
- else
- printf( '<div class="message"><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 );
- }
- else {
- printf( '<div class="message"><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 );
- 'post_type' => 'post',
- 'post_status' => 'draft',
- 'author' => $current_user->data->ID,
- 'posts_per_page' => 1,
- 'orderby' => 'modified',
- 'order' => 'DESC'
- ) );
- if ( $drafts_query->posts )
- $drafts =& $drafts_query->posts;
- }
- printf('<p class="textright">' . __('You can also try %s, easy blogging from anywhere on the Web.') . '</p>', '<a href="tools.php">' . __('Press This') . '</a>' );
- }
- $post = get_default_post_to_edit();
- // Args for dropdown
- 'order' => 'ASC',
- 'hierarchical' => 1,
- 'echo' => 0,
- 'name' => 'post_category[]',
- 'hide_empty' => 0
- );
- // Create dropdown
- $categories = wp_dropdown_categories( array_merge( $args , array( 'selected' => get_option('default_category') ) ) );
- // Replace the ID
- ?>
- <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press">
- <h4 id="quick-post-title"><label for="title">Title</label></h4>
- <div class="input-text-wrap">
- <input type="text" name="post_title" id="title" tabindex="1" autocomplete="off" value="<?php echo esc_attr( $post->post_title ); ?>" />
- </div>
- <h4 id="quick-post-category"><label for="title">Category</label></h4>
- <div><?php echo $categories;?></div>
- <div class="clear"><br /></div>
- <?php
- if ( current_user_can( 'upload_files' ) ) { ?>
- <div id="media-buttons" class="hide-if-no-js"><?php do_action( 'media_buttons' );?></div>
- <?php
- }
- ?>
- <h4 id="content-label"><label for="content">Content</label></h4>
- <div class="textarea-wrap">
- <textarea name="content" id="content" class="mceEditor" rows="3" cols="15" tabindex="2"><?php echo $post->post_content; ?></textarea>
- </div>
- <script type="text/javascript">edCanvas = document.getElementById('content');edInsertContent = null;</script>
- <h4><label for="tags-input">Tags</label></h4>
- <div class="input-text-wrap">
- <input type="text" name="tags_input" id="tags-input" tabindex="3" value="<?php echo get_tags_to_edit( $post->ID ); ?>" />
- </div>
- <p class="submit">
- <input type="hidden" name="action" id="quickpost-action" value="post-quickpress-save" />
- <input type="hidden" name="quickpress_post_ID" value="<?php echo (int) $post->ID; ?>" />
- <?php wp_nonce_field('add-post'); ?>
- <input type="submit" name="save" id="save-post" class="button" tabindex="4" value="<?php esc_attr_e('Save Draft'); ?>" />
- <input type="reset" value="<?php esc_attr_e( 'Reset' ); ?>" class="button" />
- <?php
- if ( current_user_can('publish_posts') ) {
- echo '<input type="submit" name="publish" id="publish" accesskey="p" tabindex="5" class="button-primary" value="' . esc_attr('Publish') . '" />';
- }
- else {
- echo '<input type="submit" name="publish" id="publish" accesskey="p" tabindex="5" class="button-primary" value="' . esc_attr('Submit for Review') .'" />';
- }
- ?>
- <br class="clear" />
- </p>
- </form>
- <?php
- if ( $drafts )
- wp_dashboard_recent_drafts( $drafts );
- return;
- }
- }
- $quickpress_category = new quickpress_category();
- // Removes the option from the options table on deactivation
- register_deactivation_hook( __FILE__, 'remove_options' );
- function remove_options() {
- delete_option( 'quickpress_category' );
- }
- ?>
Paste Details
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.