Changeset 3214288
- Timestamp:
- 12/29/2024 02:44:49 AM (15 months ago)
- Location:
- lsw-organize-drafts/trunk
- Files:
-
- 2 edited
-
lsw_organize_drafts.php (modified) (12 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lsw-organize-drafts/trunk/lsw_organize_drafts.php
r1340949 r3214288 1 1 <?php 2 3 2 /** 4 * 5 * Plugin Name: Organize Drafts 6 * Plugin URI: http://www.linsoftware.com/organize-drafts/ 7 * Description: Organize Wordpress Drafts with "Draft Types." Think of draft types as folders for sorting your drafts. Use the default types or add your own custom draft types. 8 * Author: Linnea Wilhelm 9 * Author URI: http://www.linsoftware.com 10 * Version: 1.0.1 11 * License: GPL2 12 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 13 * Text Domain: lsw_organize_drafts 14 * Tags: organization, organize, workflow, work-flow, folders, drafts, editing 15 * Organize Wordpress Drafts with "Draft Types." Think of draft types as folders for sorting your 16 * drafts. Use the default types or add your own custom draft types. 17 * Improve your editing workflow and de-clutter your drafts. 18 * By default, works with posts and pages. See the FAQ for how to configure this to work with custom post types. 19 **/ 3 * Plugin Name: Organize Drafts 4 * Plugin URI: https://www.linsoftware.com/organize-drafts/ 5 * Description: Organize WordPress Drafts with "Draft Types." Think of draft types as folders for sorting your drafts. Use the default types or add your own custom draft types. 6 * Author: Linnea Huxford 7 * Author URI: https://www.linsoftware.com 8 * Version: 1.1.0 9 * License: GPL2 10 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 11 * Text Domain: lsw_organize_drafts 12 * Tags: organization, organize, workflow, work-flow, folders, drafts, editing 13 * Organize WordPress Drafts with "Draft Types." Think of draft types as folders for sorting your 14 * drafts. Use the default types or add your own custom draft types. 15 * Improve your editing workflow and de-clutter your drafts. 16 * By default, works with posts and pages. See the FAQ for how to configure this to work with custom post types. 17 **/ 20 18 21 19 … … 26 24 * @var string 27 25 */ 28 public $version = '1. 0.1';26 public $version = '1.1.0'; 29 27 30 28 /** … … 55 53 self::$_instance = new self(); 56 54 } 55 57 56 return self::$_instance; 58 57 } 59 58 60 59 public function __construct() { 61 LSW_Organize_Drafts::$post_types = array('post', 'page'); 62 LSW_Organize_Drafts::$draft_types = array ('Old Junk', 'Idea', 60 LSW_Organize_Drafts::$post_types = array( 'post', 'page' ); 61 LSW_Organize_Drafts::$draft_types = array( 62 'Idea', 63 63 'Outline', 64 'Needs Images', 'Completed'); 64 'Rough Draft', 65 'In Review', 66 'Needs Images', 67 'Ready to Publish', 68 ); 65 69 $this->hooks(); 66 67 70 } 68 71 … … 71 74 return; 72 75 } 73 add_action('init', array($this, 'setup_taxonomy')); 74 add_filter('manage_posts_columns' , array('LSW_Organize_Drafts', 'control_columns')); 75 add_filter('manage_pages_columns' , array('LSW_Organize_Drafts', 'control_columns')); 76 add_action('add_meta_boxes', array('LSW_Organize_Drafts','update_meta_boxes'), 20, 2 ); 77 add_action('save_post', array('LSW_Organize_Drafts', 'save_taxonomy_data'), 10, 2); 78 $post_types = apply_filters('lsw_default_post_types', LSW_Organize_Drafts::$post_types); 79 foreach($post_types as $type) { 80 add_filter( 'manage_edit-' . $type . '_sortable_columns', array('LSW_Organize_Drafts', 81 'make_column_sortable') ); 82 } 83 } 84 85 public static function make_column_sortable($sortable_columns) { 86 87 $sortable_columns[ 'taxonomy-lswdrafttype' ] = 'lswdrafttype'; 88 return $sortable_columns; 89 } 90 91 public static function save_taxonomy_data($post_id, $post) { 76 add_action( 'init', array( $this, 'setup_taxonomy' ) ); 77 add_filter( 'manage_posts_columns', array( 'LSW_Organize_Drafts', 'control_columns' ) ); 78 add_filter( 'manage_pages_columns', array( 'LSW_Organize_Drafts', 'control_columns' ) ); 79 add_action( 'admin_menu', array( 'LSW_Organize_Drafts', 'update_meta_boxes' ) ); 80 add_action( 'save_post', array( 'LSW_Organize_Drafts', 'save_taxonomy_data' ), 10, 2 ); 81 $post_types = apply_filters( 'lsw_default_post_types', LSW_Organize_Drafts::$post_types ); 82 foreach ( $post_types as $type ) { 83 add_filter( 'manage_edit-' . $type . '_sortable_columns', array( 84 'LSW_Organize_Drafts', 85 'make_column_sortable' 86 ) ); 87 } 88 } 89 90 public static function make_column_sortable( $sortable_columns ) { 91 92 $sortable_columns['taxonomy-lswdrafttype'] = 'lswdrafttype'; 93 94 return $sortable_columns; 95 } 96 97 public static function save_taxonomy_data( $post_id, $post ) { 92 98 93 99 // if this is autosave, do nothing 94 if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) 95 return; 100 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 101 return; 102 } 96 103 97 104 // verify this came from our screen and with proper authorization. 98 if ( ! isset($_POST['taxonomy_noncename']) || !wp_verify_nonce( $_POST['taxonomy_noncename'],99 'taxonomy_lswdrafttype' )) {105 if ( ! isset( $_POST['taxonomy_noncename'] ) || ! wp_verify_nonce( $_POST['taxonomy_noncename'], 106 'taxonomy_lswdrafttype' ) ) { 100 107 return; 101 108 } … … 103 110 // Check permissions 104 111 $edit_cap = 'edit_' . $post->post_type; 105 if ( ! current_user_can( $edit_cap, $post_id ) ) {106 return;112 if ( ! current_user_can( $edit_cap, $post_id ) ) { 113 return; 107 114 } 108 115 109 116 // OK, we're authenticated: we need update the draft type 110 if (isset($_POST['post_lswdrafttype'])) {111 $post_type = filter_var($_POST['post_lswdrafttype'], FILTER_SANITIZE_STRING);117 if ( isset( $_POST['post_lswdrafttype'] ) ) { 118 $post_type = sanitize_text_field( wp_unslash( $_POST['post_lswdrafttype'] ?? '' ) ); 112 119 wp_set_object_terms( $post_id, $post_type, 'lswdrafttype' ); 113 120 } … … 115 122 116 123 117 public static function update_meta_boxes($post_type, $post) { 118 119 $post_types = apply_filters('lsw_default_post_types', LSW_Organize_Drafts::$post_types); 124 public static function update_meta_boxes() { 125 $post_types = apply_filters( 'lsw_default_post_types', LSW_Organize_Drafts::$post_types ); 120 126 remove_meta_box( 'tagsdiv-lswdrafttype', $post_types, 'side' ); 121 if (isset($post->post_status) && ($post->post_status == 'draft' || $post->post_status == 'auto-draft')) { 122 add_meta_box('lswdrafttype_custom', __('Draft Type', 'lsw_organize_drafts'), array('LSW_Organize_Drafts','render_meta_box'), $post_types, 'side', 'core'); 123 } 124 } 125 126 public static function render_meta_box($post) { 127 127 add_meta_box( 'lswdrafttype_custom', __( 'Draft Type', 'lsw_organize_drafts' ), array( 128 'LSW_Organize_Drafts', 129 'render_meta_box' 130 ), $post_types, 'side', 'core' ); 131 } 132 133 public static function render_meta_box( $post ) { 134 135 if ( $post->post_status !== 'draft' ) { 136 printf( esc_html__( 'Not a draft' ) ); 137 138 return; 139 } 128 140 echo '<input type="hidden" name="taxonomy_noncename" id="taxonomy_noncename" value="' . 129 wp_create_nonce( 'taxonomy_lswdrafttype' ) . '" />';141 wp_create_nonce( 'taxonomy_lswdrafttype' ) . '" />'; 130 142 131 143 // Get all lswdrafttype taxonomy terms 132 $types = get_terms( 'lswdrafttype', 'hide_empty=0');144 $types = get_terms( 'lswdrafttype', 'hide_empty=0' ); 133 145 134 146 ?> … … 136 148 <!-- Display types as options --> 137 149 <?php 138 $names = get_the_terms( $post->ID, 'lswdrafttype');150 $names = get_the_terms( $post->ID, 'lswdrafttype' ); 139 151 ?> 140 152 <option class='lswdrafttype-option' value='' 141 <?php if (!count($names)) echo "selected";?>>None</option> 153 <?php if ( empty( $names ) ) { 154 echo "selected"; 155 } ?>>None 156 </option> 142 157 <?php 143 foreach ( $types as $type) {144 if ( !is_wp_error($types) && !empty($types) && !strcmp($type->slug, $names[0]->slug))158 foreach ( $types as $type ) { 159 if ( ! is_wp_error( $types ) && ! empty( $types ) && ! strcmp( $type->slug, $names[0]->slug ) ) { 145 160 echo "<option class='lswdrafttype-option' value='" . $type->slug . "' selected>" . $type->name . "</option>\n"; 146 else161 } else { 147 162 echo "<option class='lswdrafttype-option' value='" . $type->slug . "'>" . $type->name . "</option>\n"; 163 } 148 164 } 149 165 ?> … … 152 168 } 153 169 154 public static function control_columns( $columns) {155 if (isset($_GET['post_status']) && 'draft'==$_GET['post_status']) {170 public static function control_columns( $columns ) { 171 if ( isset( $_GET['post_status'] ) && 'draft' == $_GET['post_status'] ) { 156 172 return $columns; 157 173 } else { 158 unset($columns['taxonomy-lswdrafttype']); 174 unset( $columns['taxonomy-lswdrafttype'] ); 175 159 176 return $columns; 160 177 } … … 163 180 164 181 public function setup_taxonomy() { 165 $args = apply_filters('lsw_draft_types_args', $this->get_tax_args()); 166 $post_types = apply_filters('lsw_default_post_types', LSW_Organize_Drafts::$post_types); 167 if(!taxonomy_exists('lswdrafttype')) { 168 register_taxonomy( 'lswdrafttype', $post_types, $args ); 169 } 170 171 $test = get_terms( 'lswdrafttype', 'hide_empty=0'); 172 182 $args = apply_filters( 'lsw_draft_types_args', $this->get_tax_args() ); 183 $post_types = apply_filters( 'lsw_default_post_types', LSW_Organize_Drafts::$post_types ); 184 if ( ! taxonomy_exists( 'lswdrafttype' ) ) { 185 register_taxonomy( 'lswdrafttype', $post_types, $args ); 186 } 173 187 } 174 188 … … 176 190 $lsw_organize_drafts = LSW_Organize_Drafts::instance(); 177 191 $lsw_organize_drafts->setup_taxonomy(); 178 if (!LSW_Organize_Drafts::areDefaultTermsRegistered()) {192 if ( ! LSW_Organize_Drafts::areDefaultTermsRegistered() ) { 179 193 LSW_Organize_Drafts::registerDefaultTerms(); 180 194 } … … 182 196 183 197 public static function deactivate() { 184 198 delete_option( 'lsw_organize_drafts' ); 185 199 } 186 200 187 201 private static function areDefaultTermsRegistered() { 188 202 $options = LSW_Organize_Drafts::getPluginOptions(); 189 if (array_key_exists('default_terms_setup', $options)) {203 if ( array_key_exists( 'default_terms_setup', $options ) ) { 190 204 return $options['default_terms_setup'] == 1; 191 205 } else { … … 195 209 196 210 private static function getPluginOptions() { 197 return get_option( 'lsw_organize_drafts', array());198 } 199 200 private static function updateOption( $newValue, $key) {201 $options = LSW_Organize_Drafts::getPluginOptions();202 $options[ $key] = $newValue;203 update_option( 'lsw_organize_drafts', $options);211 return get_option( 'lsw_organize_drafts', array() ); 212 } 213 214 private static function updateOption( $newValue, $key ) { 215 $options = LSW_Organize_Drafts::getPluginOptions(); 216 $options[ $key ] = $newValue; 217 update_option( 'lsw_organize_drafts', $options ); 204 218 } 205 219 206 220 private static function registerDefaultTerms() { 207 foreach ( LSW_Organize_Drafts::$draft_types as $type ) {208 wp_insert_term( $type, 'lswdrafttype');209 } 210 LSW_Organize_Drafts::updateOption( 'default_terms_setup', 1);221 foreach ( LSW_Organize_Drafts::$draft_types as $type ) { 222 wp_insert_term( $type, 'lswdrafttype' ); 223 } 224 LSW_Organize_Drafts::updateOption( 'default_terms_setup', 1 ); 211 225 } 212 226 213 227 private function get_tax_args() { 214 $labels = array(215 'name' => __('Draft Types', 'lsw_organize_drafts'),216 'singular_name' => __('Draft Types', 'lsw_organize_drafts'),217 'menu_name' => __('Draft Types', 'lsw_organize_drafts'),218 'all_items' => __('All Draft Types', 'lsw_organize_drafts'),219 'add_new_item' => __('Add New Type', 'lsw_organize_drafts'),220 'choose_from_most_used' => __('Choose From the Most Used Draft Types', 'lsw_organize_drafts'),228 $labels = array( 229 'name' => __( 'Draft Types', 'lsw_organize_drafts' ), 230 'singular_name' => __( 'Draft Types', 'lsw_organize_drafts' ), 231 'menu_name' => __( 'Draft Types', 'lsw_organize_drafts' ), 232 'all_items' => __( 'All Draft Types', 'lsw_organize_drafts' ), 233 'add_new_item' => __( 'Add New Type', 'lsw_organize_drafts' ), 234 'choose_from_most_used' => __( 'Choose From the Most Used Draft Types', 'lsw_organize_drafts' ), 221 235 ); 222 236 223 return $args =array(224 'public' => false,225 'hierarchical' => false,237 return array( 238 'public' => false, 239 'hierarchical' => false, 226 240 'show_in_quick_edit' => false, 227 'labels' => $labels,228 'show_ui' => true,229 'show_in_menu' => true,230 'show_admin_column' => true,231 'query_var' => true,241 'labels' => $labels, 242 'show_ui' => true, 243 'show_in_menu' => true, 244 'show_admin_column' => true, 245 'query_var' => true, 232 246 ); 233 247 } -
lsw-organize-drafts/trunk/readme.txt
r1340949 r3214288 1 1 === Organize Drafts === 2 Author URI: http ://www.linsoftware.com3 Plugin URI: http ://www.linsoftware.com/organize-drafts/2 Author URI: https://www.linsoftware.com 3 Plugin URI: https://www.linsoftware.com/organize-drafts/ 4 4 Contributors: LinSoftware 5 Donate link: http://www.linsoftware.com/support-free-plugin-development/6 5 Tags: organization, organize, workflow, work-flow, folders, drafts, editing, draft folders, draft categories, categorize 7 6 Requires at least: 4.4.0 8 Tested up to: 4.4.19 Stable tag: 1. 0.17 Tested up to: 6.7.1 8 Stable tag: 1.1.0 10 9 License: GPLv2 or later 11 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html 12 11 13 Organize Word press Drafts with "Draft Types." Think of draft types as folders for sorting your drafts.12 Organize WordPress Drafts with "Draft Types." Think of draft types as folders for sorting your drafts. 14 13 15 14 == Description == 16 15 17 Organize Word press Drafts with "Draft Types." Think of draft types as folders for sorting your drafts. Use the default types or add your own custom draft types.16 Organize WordPress Drafts with "Draft Types." Think of draft types as folders for sorting your drafts. Use the default types or add your own custom draft types. 18 17 19 18 Features: 20 19 21 20 * Assign "Draft Types" to your drafts to improve your editing workflow and de-clutter your drafts. 22 * Create your own Draft Types. Default types are: Idea, Needs Images, Outline, Old Junk, and Completed.21 * Create your own Draft Types. Default types are: Idea, Outline, Rough Draft, In Review, Needs Images, Ready to Publish. 23 22 * Sort your draft posts by draft types. When viewing your drafts, you will see a draft types column that can be sorted alphabetically. 24 23 * By default, works with posts and pages. See the FAQ for how to configure this to work with custom post types. 25 24 26 Have an idea to improve this plugin? I'd like to hear about it. 25 Have an idea to improve this plugin? I'd like to hear about it. 27 26 28 27 == Installation == 29 28 30 1. Install the plugin in wp-content\plugins31 2. Activate the Plugin 29 1. Install the plugin in the plugins directory. 30 2. Activate the Plugin. 32 31 33 32 == Frequently Asked Questions == … … 48 47 == Screenshots == 49 48 50 1. Manage Draft Types through the Word press Admin sidebar.49 1. Manage Draft Types through the WordPress Admin sidebar. 51 50 52 51 2. View and Soft Drafts by Draft Types column. 53 52 54 3. Easily select the Draft Type from a dropdown menu. 53 3. Easily select the Draft Type from a dropdown menu. 55 54 56 55 57 56 == Changelog == 57 58 = 1.1.0: December 2024 = 59 60 * PHP 8.3 compatibility 61 * Change Default Draft Types. 58 62 59 63 = 1.0.1 =
Note: See TracChangeset
for help on using the changeset viewer.