Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Advertising

WordPress - QuickPress Category
Sunday, January 3rd, 2010 at 12:13:02pm MST 

  1. <?php
  2. /*
  3. Plugin Name: QuickPress Category
  4. Plugin URI: http://www.t31os.co.cc/
  5. Description: Adds category selection to the QuickPress widget shown in the WordPress dashboard
  6. Author: t31os
  7. Version: 1.0
  8. Author URI: http://www.t31os.co.cc/
  9. */
  10.  
  11. class quickpress_category {
  12.        
  13.         public function quickpress_category() {
  14.                 add_action( 'wp_dashboard_setup' , array( $this , 'dashboard_updater' ) );
  15.                 add_action( 'admin_init', array( $this , 'register_option' ) );
  16.         }
  17.        
  18.         public function register_option() {
  19.                 // Register the setting - with basic validation, only need be 0/1 or true/false , keep it simple
  20.                 register_setting( 'enable-dropdown', 'quickpress_category' , array( $this , 'option_validation') );
  21.                 // Register the setting field
  22.                 add_settings_field( 'quickpress_category', 'Quickpress category', array( $this , 'add_category_option' ), 'writing', 'default' );
  23.         }
  24.         public function option_validation( $input ) {
  25.                 if( !$input )
  26.                         return 0;
  27.                 if( $input == 1 )
  28.                         return 1;
  29.                 else
  30.                         return 0;
  31.         }
  32.         // Output the checkbox for toggling the category dropdown
  33.         public function add_category_option() {
  34.                 $checked =
  35.                         ( get_option('quickpress_category') && get_option('quickpress_category') == 1 ) ? 'checked="checked" ' : '';
  36.                 ?>
  37.                         <div class="input-text-wrap">
  38.                                 <label class="selectit">
  39.                                         <input type="checkbox" name="quickpress_category" <?php echo $checked; ?>value="1" />
  40.                                         Enable quickpress category selection.
  41.                                 </label>
  42.                         </div>
  43.                 <?php
  44.                 settings_fields('enable-dropdown');
  45.                 return;
  46.         }
  47.        
  48.         public function dashboard_updater() {
  49.                 // Global the variable so it's available inside the function (that's how you access variables outside a functions scope)
  50.                 global $wp_meta_boxes;
  51.                
  52.                 // Determine where the widget is and update the callback name if the option is enabled
  53.                 switch( true ) {
  54.                        
  55.                         case ( !get_option( 'quickpress_category' ) || get_option( 'quickpress_category' ) == false ) :
  56.                                 return;
  57.                        
  58.                         case ( isset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press'] ) ) :
  59.                                 $wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']['callback'] = array( &$this , 'quickpress_widget' );
  60.                                 return;
  61.                        
  62.                         case ( isset( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_quick_press'] ) ):
  63.                                 $wp_meta_boxes['dashboard']['normal']['core']['dashboard_quick_press']['callback'] = array( &$this , 'quickpress_widget' );
  64.                                 return;
  65.                 }
  66.                 return;
  67.         }
  68.         // Most of this is just code from the original widget
  69.         public function quickpress_widget() {
  70.                 // Call $current_user, so there's no reliance on $GLOBAL, per original widget
  71.                 global $current_user;
  72.                
  73.                 $drafts = false;
  74.                 if(
  75.                         'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['action'] ) &&
  76.                         0 === strpos( $_POST['action'], 'post-quickpress' ) && (int) $_POST['post_ID'] ) {
  77.                        
  78.                         $view = get_permalink( $_POST['post_ID'] );
  79.                         $edit = esc_url( get_edit_post_link( $_POST['post_ID'] ) );
  80.                        
  81.                         if ( 'post-quickpress-publish' == $_POST['action'] ) {
  82.                                 if ( current_user_can('publish_posts') )
  83.                                         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 );
  84.                                 else
  85.                                         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 );
  86.                         }
  87.                         else {
  88.                                 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 );
  89.                                        
  90.                                 $drafts_query = new WP_Query( array(
  91.                                         'post_type' => 'post',
  92.                                         'post_status' => 'draft',
  93.                                         'author' => $current_user->data->ID,
  94.                                         'posts_per_page' => 1,
  95.                                         'orderby' => 'modified',
  96.                                         'order' => 'DESC'
  97.                                 ) );
  98.  
  99.                                 if ( $drafts_query->posts )
  100.                                         $drafts =& $drafts_query->posts;
  101.                         }
  102.                         printf('<p class="textright">' . __('You can also try %s, easy blogging from anywhere on the Web.') . '</p>', '<a href="tools.php">' . __('Press This') . '</a>' );
  103.                         $_REQUEST = array(); // hack for get_default_post_to_edit()
  104.                 }
  105.                 $post = get_default_post_to_edit();
  106.                
  107.                 // Args for dropdown
  108.                 $args = array(
  109.                         'order' => 'ASC',
  110.                         'hierarchical' => 1,
  111.                         'echo' => 0,
  112.                         'name' => 'post_category[]',
  113.                         'hide_empty' => 0
  114.                 );
  115.                 // Create dropdown
  116.                 $categories = wp_dropdown_categories( array_merge( $args , array( 'selected' => get_option('default_category') ) ) );
  117.                 // Replace the ID
  118.                 $categories = str_replace( "id='post_category[]'" , "id='post_category'" , $categories );
  119.                
  120.                 ?>
  121.                
  122.                 <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press">
  123.                         <h4 id="quick-post-title"><label for="title">Title</label></h4>
  124.                         <div class="input-text-wrap">
  125.                                 <input type="text" name="post_title" id="title" tabindex="1" autocomplete="off" value="<?php echo esc_attr( $post->post_title ); ?>" />
  126.                         </div>
  127.                         <h4 id="quick-post-category"><label for="title">Category</label></h4>
  128.                         <div><?php echo $categories;?></div>
  129.                         <div class="clear"><br /></div>
  130.                 <?php
  131.  
  132.                 if ( current_user_can( 'upload_files' ) ) { ?>
  133.                         <div id="media-buttons" class="hide-if-no-js"><?php do_action( 'media_buttons' );?></div>
  134.                 <?php
  135.                 }
  136.                 ?>
  137.                         <h4 id="content-label"><label for="content">Content</label></h4>
  138.                         <div class="textarea-wrap">
  139.                                 <textarea name="content" id="content" class="mceEditor" rows="3" cols="15" tabindex="2"><?php echo  $post->post_content; ?></textarea>
  140.                         </div>
  141.                         <script type="text/javascript">edCanvas = document.getElementById('content');edInsertContent = null;</script>
  142.                         <h4><label for="tags-input">Tags</label></h4>
  143.                         <div class="input-text-wrap">
  144.                                 <input type="text" name="tags_input" id="tags-input" tabindex="3" value="<?php echo get_tags_to_edit( $post->ID ); ?>" />
  145.                         </div>
  146.                         <p class="submit">
  147.                                 <input type="hidden" name="action" id="quickpost-action" value="post-quickpress-save" />
  148.                                 <input type="hidden" name="quickpress_post_ID" value="<?php echo  (int) $post->ID; ?>" />
  149.                                 <?php wp_nonce_field('add-post'); ?>
  150.                                 <input type="submit" name="save" id="save-post" class="button" tabindex="4" value="<?php  esc_attr_e('Save Draft'); ?>" />
  151.                                 <input type="reset" value="<?php esc_attr_e( 'Reset' ); ?>" class="button" />
  152.                 <?php
  153.                 if ( current_user_can('publish_posts') ) {
  154.                         echo '<input type="submit" name="publish" id="publish" accesskey="p" tabindex="5" class="button-primary" value="' . esc_attr('Publish') . '" />';
  155.                 }
  156.                 else {
  157.                         echo '<input type="submit" name="publish" id="publish" accesskey="p" tabindex="5" class="button-primary" value="' . esc_attr('Submit for Review') .'" />';
  158.                 }
  159.                 ?>
  160.                         <br class="clear" />
  161.                         </p>
  162.                 </form>
  163.                 <?php
  164.                 if ( $drafts )
  165.                         wp_dashboard_recent_drafts( $drafts );
  166.                 return;
  167.         }
  168. }
  169. $quickpress_category = new quickpress_category();
  170.  
  171. // Removes the option from the options table on deactivation
  172. register_deactivation_hook( __FILE__, 'remove_options' );
  173. function remove_options() {
  174.         delete_option( 'quickpress_category' );
  175. }
  176. ?>

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.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



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.

worth-right