Plugin Directory

Changeset 3214288


Ignore:
Timestamp:
12/29/2024 02:44:49 AM (15 months ago)
Author:
LinSoftware
Message:

Adds support for PHP 8.3 and WP 6.7

Location:
lsw-organize-drafts/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lsw-organize-drafts/trunk/lsw_organize_drafts.php

    r1340949 r3214288  
    11<?php
    2 
    32/**
    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 **/
    2018
    2119
     
    2624     * @var string
    2725     */
    28     public $version = '1.0.1';
     26    public $version = '1.1.0';
    2927
    3028    /**
     
    5553            self::$_instance = new self();
    5654        }
     55
    5756        return self::$_instance;
    5857    }
    5958
    6059    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',
    6363            'Outline',
    64             'Needs Images', 'Completed');
     64            'Rough Draft',
     65            'In Review',
     66            'Needs Images',
     67            'Ready to Publish',
     68        );
    6569        $this->hooks();
    66 
    6770    }
    6871
     
    7174            return;
    7275        }
    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 ) {
    9298
    9399        // 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        }
    96103
    97104        // 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' ) ) {
    100107            return;
    101108        }
     
    103110        // Check permissions
    104111        $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;
    107114        }
    108115
    109116        // 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'] ?? '' ) );
    112119            wp_set_object_terms( $post_id, $post_type, 'lswdrafttype' );
    113120        }
     
    115122
    116123
    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 );
    120126        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        }
    128140        echo '<input type="hidden" name="taxonomy_noncename" id="taxonomy_noncename" value="' .
    129             wp_create_nonce( 'taxonomy_lswdrafttype' ) . '" />';
     141            wp_create_nonce( 'taxonomy_lswdrafttype' ) . '" />';
    130142
    131143        // Get all lswdrafttype taxonomy terms
    132         $types = get_terms('lswdrafttype', 'hide_empty=0');
     144        $types = get_terms( 'lswdrafttype', 'hide_empty=0' );
    133145
    134146        ?>
     
    136148            <!-- Display types as options -->
    137149            <?php
    138             $names = get_the_terms($post->ID, 'lswdrafttype');
     150            $names = get_the_terms( $post->ID, 'lswdrafttype' );
    139151            ?>
    140152            <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>
    142157            <?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 ) ) {
    145160                    echo "<option class='lswdrafttype-option' value='" . $type->slug . "' selected>" . $type->name . "</option>\n";
    146                 else
     161                } else {
    147162                    echo "<option class='lswdrafttype-option' value='" . $type->slug . "'>" . $type->name . "</option>\n";
     163                }
    148164            }
    149165            ?>
     
    152168    }
    153169
    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'] ) {
    156172            return $columns;
    157173        } else {
    158             unset($columns['taxonomy-lswdrafttype']);
     174            unset( $columns['taxonomy-lswdrafttype'] );
     175
    159176            return $columns;
    160177        }
     
    163180
    164181    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        }
    173187    }
    174188
     
    176190        $lsw_organize_drafts = LSW_Organize_Drafts::instance();
    177191        $lsw_organize_drafts->setup_taxonomy();
    178         if(!LSW_Organize_Drafts::areDefaultTermsRegistered()) {
     192        if ( ! LSW_Organize_Drafts::areDefaultTermsRegistered() ) {
    179193            LSW_Organize_Drafts::registerDefaultTerms();
    180194        }
     
    182196
    183197    public static function deactivate() {
    184 
     198        delete_option( 'lsw_organize_drafts' );
    185199    }
    186200
    187201    private static function areDefaultTermsRegistered() {
    188202        $options = LSW_Organize_Drafts::getPluginOptions();
    189         if(array_key_exists('default_terms_setup', $options)) {
     203        if ( array_key_exists( 'default_terms_setup', $options ) ) {
    190204            return $options['default_terms_setup'] == 1;
    191205        } else {
     
    195209
    196210    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 );
    204218    }
    205219
    206220    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 );
    211225    }
    212226
    213227    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' ),
    221235        );
    222236
    223         return $args = array(
    224             'public'            => false,
    225             'hierarchical'      => false,
     237        return array(
     238            'public'             => false,
     239            'hierarchical'       => false,
    226240            '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,
    232246        );
    233247    }
  • lsw-organize-drafts/trunk/readme.txt

    r1340949 r3214288  
    11=== Organize Drafts ===
    2 Author URI: http://www.linsoftware.com
    3 Plugin URI: http://www.linsoftware.com/organize-drafts/
     2Author URI: https://www.linsoftware.com
     3Plugin URI: https://www.linsoftware.com/organize-drafts/
    44Contributors: LinSoftware
    5 Donate link: http://www.linsoftware.com/support-free-plugin-development/
    65Tags: organization, organize, workflow, work-flow, folders, drafts, editing, draft folders, draft categories, categorize
    76Requires at least: 4.4.0
    8 Tested up to: 4.4.1
    9 Stable tag: 1.0.1
     7Tested up to: 6.7.1
     8Stable tag: 1.1.0
    109License: GPLv2 or later
    1110License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1211
    13 Organize Wordpress Drafts with "Draft Types."  Think of draft types as folders for sorting your drafts.
     12Organize WordPress Drafts with "Draft Types."  Think of draft types as folders for sorting your drafts.
    1413
    1514== Description ==
    1615
    17 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.
     16Organize 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.
    1817
    1918Features:
    2019
    2120* 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.
    2322* Sort your draft posts by draft types.  When viewing your drafts, you will see a draft types column that can be sorted alphabetically.
    2423* By default, works with posts and pages. See the FAQ for how to configure this to work with custom post types.
    2524
    26 Have an idea to improve this plugin?  I'd like to hear about it. 
     25Have an idea to improve this plugin?  I'd like to hear about it.
    2726
    2827== Installation ==
    2928
    30 1. Install the plugin in wp-content\plugins
    31 2. Activate the Plugin
     291. Install the plugin in the plugins directory.
     302. Activate the Plugin.
    3231
    3332== Frequently Asked Questions ==
     
    4847== Screenshots ==
    4948
    50 1. Manage Draft Types through the Wordpress Admin sidebar.
     491. Manage Draft Types through the WordPress Admin sidebar.
    5150
    52512. View and Soft Drafts by Draft Types column.
    5352
    54 3. Easily select the Draft Type from a dropdown menu. 
     533. Easily select the Draft Type from a dropdown menu.
    5554
    5655
    5756== Changelog ==
     57
     58= 1.1.0: December 2024 =
     59
     60* PHP 8.3 compatibility
     61* Change Default Draft Types.
    5862
    5963= 1.0.1 =
Note: See TracChangeset for help on using the changeset viewer.