diff --git a/CHANGELOG.md b/CHANGELOG.md index afbf666..50eb301 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). + +## 3.0.0 +* Improved Quick-Edit and Bulk-Edit support +* Remove `attachment` type support for now, as there is no way to switch back +* Fix bug causing some post-types to switch unexpectedly + ## 2.0.1 * Ensure quick-edit works with new procedure * Quick-edit "Type" column works again! diff --git a/assets/js/quickedit.js b/assets/js/quickedit.js index 75dac67..6cc94ec 100644 --- a/assets/js/quickedit.js +++ b/assets/js/quickedit.js @@ -4,9 +4,21 @@ function pts_quick_edit() { var $ = jQuery; var _edit = inlineEditPost.edit; + $( '#bulk-edit' ) + .find( '.inline-edit-col-right .inline-edit-col' ) + .append( + $('#bulk-edit #pts_bulk_edit' ) + ); + + $( '.inline-edit-row' ).not( '#bulk-edit' ) + .find( '.inline-edit-col-right .inline-edit-col' ) + .append( + $( '.inline-edit-row #pts_quick_edit' ) + ); + inlineEditPost.edit = function( id ) { - var args = [].slice.call(arguments ); + var args = [].slice.call( arguments ); _edit.apply( this, args ); @@ -16,17 +28,17 @@ function pts_quick_edit() { var - // editRow is the quick-edit row, containing the inputs that need to be updated - editRow = $( '#edit-' + id ), + // edit_row is the quick-edit row, containing the inputs that need to be updated + edit_row = $( '#edit-' + id ), - // postRow is the row shown when a book isn't being edited, which also holds the existing values. - postRow = $( '#post-' + id ), + // post_row is the row shown when a book isn't being edited, which also holds the existing values. + post_row = $( '#post-' + id ), // get the existing values - post_type = $( '.post_type', postRow ).data( 'post-type' ); - + post_type = $( 'td.post_type span', post_row ).data( 'post-type' ); + // set the values in the quick-editor - $( 'select[name="pts_post_type"] option[value="' + post_type + '"]', editRow ).attr( 'selected', 'selected' ); + $( 'select[name="pts_post_type"] option[value="' + post_type + '"]', edit_row ).attr( 'selected', 'selected' ); }; } diff --git a/post-type-switcher.php b/post-type-switcher.php index 7193a9e..d9a263f 100644 --- a/post-type-switcher.php +++ b/post-type-switcher.php @@ -16,7 +16,7 @@ * License: GPLv2 or later * License URI: https://www.gnu.org/licenses/gpl-2.0.html * Description: Allow switching of a post type while editing a post (in post publish section) - * Version: 2.0.1 + * Version: 3.0.0 * Text Domain: post-type-switcher * Domain Path: /assets/lang/ */ @@ -31,6 +31,15 @@ */ final class Post_Type_Switcher { + /** + * Asset version, for cache busting + * + * @since 3.0.1 + * + * @var int + */ + private $asset_version = 201609170001; + /** * Hook in the basic early actions * @@ -71,11 +80,11 @@ public function admin_init() { add_action( 'manage_pages_custom_column', array( $this, 'manage_column' ), 10, 2 ); // Add UI to "Publish" metabox - add_action( 'admin_head', array( $this, 'admin_head' ) ); - add_action( 'post_submitbox_misc_actions', array( $this, 'metabox' ) ); - add_action( 'quick_edit_custom_box', array( $this, 'quickedit' ), 10, 2 ); - add_action( 'bulk_edit_custom_box', array( $this, 'quickedit' ), 10, 2 ); - add_action( 'admin_enqueue_scripts', array( $this, 'quickedit_script' ), 10, 1 ); + add_action( 'admin_head', array( $this, 'admin_head' ) ); + add_action( 'post_submitbox_misc_actions', array( $this, 'metabox' ) ); + add_action( 'quick_edit_custom_box', array( $this, 'quick_edit' ) ); + add_action( 'bulk_edit_custom_box', array( $this, 'quick_edit_bulk' ) ); + add_action( 'admin_enqueue_scripts', array( $this, 'quick_edit_script' ) ); // Override add_filter( 'wp_insert_attachment_data', array( $this, 'override_type' ), 10, 2 ); @@ -108,9 +117,14 @@ public function metabox() { // https://wordpress.org/support/topic/dont-show-for-non-public-post-types?replies=4#post-5849287 if ( ! in_array( $cpt_object, $post_types, true ) ) { $post_types[ $post_type ] = $cpt_object; - } ?> + } -
+ // Unset attachment types, since support seems to be broken + if ( isset( $post_types['attachment'] ) ) { + unset( $post_types['attachment'] ); + } + + ?>
labels->singular_name ); ?> @@ -175,25 +189,47 @@ public function manage_column( $column, $post_id ) { * * @since 1.2.0 */ - public function quickedit( $column_name, $post_type ) { + public function quick_edit( $column_name = '' ) { + + // Bail to prevent multiple dropdowns in each column + if ( 'post_type' !== $column_name ) { + return; + } ?> + +
+ +
+ + -
-
- -
-
+ ?> asset_version, true ); } /** @@ -217,24 +255,52 @@ public function quickedit_script( $hook = '' ) { * * @since 1.2 */ - public function select_box() { - $post_types = get_post_types( $this->get_post_type_args(), 'objects' ); + public function select_box( $bulk = false ) { + + // Get post type specific data + $args = $this->get_post_type_args(); + $post_types = get_post_types( $args, 'objects' ); $post_type = get_post_type(); + $selected = ''; + + // Unset attachment types, since support seems to be broken + if ( isset( $post_types['attachment'] ) ) { + unset( $post_types['attachment'] ); + } + // Start an output buffer + ob_start(); + + // Output ?>