rendered paste body<?php/*Plugin Name: QuickPress CategoryPlugin URI: http://www.t31os.co.cc/Description: Adds category selection to the QuickPress widget shown in the WordPress dashboardAuthor: t31osVersion: 1.0Author URI: http://www.t31os.co.cc/*/class quickpress_category { public function quickpress_category() { add_action( 'wp_dashboard_setup' , array( $this , 'dashboard_updater' ) ); add_action( 'admin_init', array( $this , 'register_option' ) ); } public function register_option() { // Register the setting - with basic validation, only need be 0/1 or true/false , keep it simple register_setting( 'enable-dropdown', 'quickpress_category' , array( $this , 'option_validation') ); // 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"> <input type="checkbox" name="quickpress_category" <?php echo $checked; ?>value="1" /> 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; case ( isset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press'] ) ) : $wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']['callback'] = array( &$this , 'quickpress_widget' ); return; case ( isset( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_quick_press'] ) ): $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( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['action'] ) && 0 === strpos( $_POST['action'], 'post-quickpress' ) && (int) $_POST['post_ID'] ) { $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 ); $drafts_query = new WP_Query( array( '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>' ); $_REQUEST = array(); // hack for get_default_post_to_edit() } $post = get_default_post_to_edit(); // Args for dropdown $args = array( '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 $categories = str_replace( "id='post_category[]'" , "id='post_category'" , $categories ); ?> <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 deactivationregister_deactivation_hook( __FILE__, 'remove_options' );function remove_options() { delete_option( 'quickpress_category' );}?>