Version Description
Download this release
Release Info
| Developer | johnjamesjacoby |
| Plugin | |
| Version | 1.5 |
| Comparing to | |
| See all releases | |
Code changes from version 1.4 to 1.5
- post-type-switcher.php +364 -350
- readme.txt +6 -3
post-type-switcher.php
CHANGED
|
@@ -1,350 +1,364 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
/**
|
| 4 |
-
* Post Type Switcher
|
| 5 |
-
*
|
| 6 |
-
* Allow switching of a post type while editing a post (in post publish section)
|
| 7 |
-
*
|
| 8 |
-
* @package PostTypeSwitcher
|
| 9 |
-
* @subpackage Main
|
| 10 |
-
*/
|
| 11 |
-
|
| 12 |
-
/**
|
| 13 |
-
* Plugin Name: Post Type Switcher
|
| 14 |
-
* Plugin URI: http://wordpress.org/extend/post-type-switcher/
|
| 15 |
-
* Description: Allow switching of a post type while editing a post (in post publish section)
|
| 16 |
-
* Version: 1.
|
| 17 |
-
* Author: johnjamesjacoby
|
| 18 |
-
* Author URI: http://johnjamesjacoby.com
|
| 19 |
-
*/
|
| 20 |
-
|
| 21 |
-
// Exit if accessed directly
|
| 22 |
-
defined( 'ABSPATH' ) || exit;
|
| 23 |
-
|
| 24 |
-
/**
|
| 25 |
-
* The main post type switcher class
|
| 26 |
-
*
|
| 27 |
-
* @package PostTypeSwitcher
|
| 28 |
-
*/
|
| 29 |
-
final class Post_Type_Switcher {
|
| 30 |
-
|
| 31 |
-
/**
|
| 32 |
-
* Setup the actions needed to execute class methods where needed
|
| 33 |
-
*
|
| 34 |
-
* @since PostTypeSwitcher (1.1)
|
| 35 |
-
*/
|
| 36 |
-
public function __construct() {
|
| 37 |
-
|
| 38 |
-
if ( ! $this->is_allowed_page() )
|
| 39 |
-
return;
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
add_action( '
|
| 44 |
-
add_action( '
|
| 45 |
-
add_action( '
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
add_action( '
|
| 49 |
-
add_action( '
|
| 50 |
-
add_action(
|
| 51 |
-
add_action(
|
| 52 |
-
add_action( '
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
*
|
| 58 |
-
*
|
| 59 |
-
*
|
| 60 |
-
*
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
//
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
'
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
$
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
//
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
<
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
<a href="#" id="
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
*
|
| 122 |
-
*
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
*
|
| 131 |
-
*
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
*
|
| 148 |
-
*
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
*
|
| 215 |
-
*
|
| 216 |
-
*
|
| 217 |
-
*
|
| 218 |
-
*
|
| 219 |
-
*
|
| 220 |
-
*
|
| 221 |
-
*
|
| 222 |
-
*
|
| 223 |
-
*
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
jQuery( '
|
| 282 |
-
|
| 283 |
-
jQuery(
|
| 284 |
-
jQuery( '#post-type-
|
| 285 |
-
e.preventDefault();
|
| 286 |
-
});
|
| 287 |
-
|
| 288 |
-
jQuery( '#
|
| 289 |
-
jQuery( '#post-type-select' ).slideUp();
|
| 290 |
-
jQuery( '#edit-post-type-switcher' ).show();
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
}
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Post Type Switcher
|
| 5 |
+
*
|
| 6 |
+
* Allow switching of a post type while editing a post (in post publish section)
|
| 7 |
+
*
|
| 8 |
+
* @package PostTypeSwitcher
|
| 9 |
+
* @subpackage Main
|
| 10 |
+
*/
|
| 11 |
+
|
| 12 |
+
/**
|
| 13 |
+
* Plugin Name: Post Type Switcher
|
| 14 |
+
* Plugin URI: http://wordpress.org/extend/post-type-switcher/
|
| 15 |
+
* Description: Allow switching of a post type while editing a post (in post publish section)
|
| 16 |
+
* Version: 1.5
|
| 17 |
+
* Author: johnjamesjacoby
|
| 18 |
+
* Author URI: http://johnjamesjacoby.com
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
// Exit if accessed directly
|
| 22 |
+
defined( 'ABSPATH' ) || exit;
|
| 23 |
+
|
| 24 |
+
/**
|
| 25 |
+
* The main post type switcher class
|
| 26 |
+
*
|
| 27 |
+
* @package PostTypeSwitcher
|
| 28 |
+
*/
|
| 29 |
+
final class Post_Type_Switcher {
|
| 30 |
+
|
| 31 |
+
/**
|
| 32 |
+
* Setup the actions needed to execute class methods where needed
|
| 33 |
+
*
|
| 34 |
+
* @since PostTypeSwitcher (1.1)
|
| 35 |
+
*/
|
| 36 |
+
public function __construct() {
|
| 37 |
+
|
| 38 |
+
if ( ! $this->is_allowed_page() ) {
|
| 39 |
+
return;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
// @todo Remove this; since it's janky to need to do this.
|
| 43 |
+
add_action( 'manage_posts_columns', array( $this, 'add_column' ) );
|
| 44 |
+
add_action( 'manage_pages_columns', array( $this, 'add_column' ) );
|
| 45 |
+
add_action( 'manage_posts_custom_column', array( $this, 'manage_column' ), 10, 2 );
|
| 46 |
+
add_action( 'manage_pages_custom_column', array( $this, 'manage_column' ), 10, 2 );
|
| 47 |
+
|
| 48 |
+
add_action( 'post_submitbox_misc_actions', array( $this, 'metabox' ) );
|
| 49 |
+
add_action( 'quick_edit_custom_box', array( $this, 'quickedit' ), 10, 2 );
|
| 50 |
+
add_action( 'bulk_edit_custom_box', array( $this, 'quickedit' ), 10, 2 );
|
| 51 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'quickedit_script' ), 10, 1 );
|
| 52 |
+
add_action( 'save_post', array( $this, 'save_post' ), 999, 2 ); // Late priority for plugin friendliness
|
| 53 |
+
add_action( 'admin_head', array( $this, 'admin_head' ) );
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/**
|
| 57 |
+
* pts_metabox()
|
| 58 |
+
*
|
| 59 |
+
* Adds post_publish metabox to allow changing post_type
|
| 60 |
+
*
|
| 61 |
+
* @since PostTypeSwitcher (0.3)
|
| 62 |
+
*/
|
| 63 |
+
public function metabox() {
|
| 64 |
+
|
| 65 |
+
// Allow types to be filtered, just incase you really need to switch
|
| 66 |
+
// between crazy types of posts.
|
| 67 |
+
$args = (array) apply_filters( 'pts_post_type_filter', array(
|
| 68 |
+
'public' => true,
|
| 69 |
+
'show_ui' => true
|
| 70 |
+
) );
|
| 71 |
+
$post_types = get_post_types( $args, 'objects' );
|
| 72 |
+
$cpt_object = get_post_type_object( get_post_type() );
|
| 73 |
+
|
| 74 |
+
// Bail if object does not exist or produces an error
|
| 75 |
+
if ( empty( $cpt_object ) || is_wp_error( $cpt_object ) ) {
|
| 76 |
+
return;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
// Force-add current post type if it's not in the list
|
| 80 |
+
// https://wordpress.org/support/topic/dont-show-for-non-public-post-types?replies=4#post-5849287
|
| 81 |
+
if ( ! in_array( $cpt_object, $post_types ) ) {
|
| 82 |
+
$post_types[ get_post_type() ] = $cpt_object;
|
| 83 |
+
} ?>
|
| 84 |
+
|
| 85 |
+
<div class="misc-pub-section misc-pub-section-last post-type-switcher">
|
| 86 |
+
<label for="pts_post_type"><?php _e( 'Post Type:' ); ?></label>
|
| 87 |
+
<span id="post-type-display"><?php echo esc_html( $cpt_object->labels->singular_name ); ?></span>
|
| 88 |
+
|
| 89 |
+
<?php if ( current_user_can( $cpt_object->cap->publish_posts ) ) : ?>
|
| 90 |
+
|
| 91 |
+
<a href="#" id="edit-post-type-switcher" class="hide-if-no-js"><?php _e( 'Edit' ); ?></a>
|
| 92 |
+
|
| 93 |
+
<?php wp_nonce_field( 'post-type-selector', 'pts-nonce-select' ); ?>
|
| 94 |
+
|
| 95 |
+
<div id="post-type-select">
|
| 96 |
+
<select name="pts_post_type" id="pts_post_type">
|
| 97 |
+
|
| 98 |
+
<?php foreach ( $post_types as $post_type => $pt ) : ?>
|
| 99 |
+
|
| 100 |
+
<?php if ( ! current_user_can( $pt->cap->publish_posts ) ) :
|
| 101 |
+
continue;
|
| 102 |
+
endif; ?>
|
| 103 |
+
|
| 104 |
+
<option value="<?php echo esc_attr( $pt->name ); ?>" <?php selected( get_post_type(), $post_type ); ?>><?php echo esc_html( $pt->labels->singular_name ); ?></option>
|
| 105 |
+
|
| 106 |
+
<?php endforeach; ?>
|
| 107 |
+
|
| 108 |
+
</select>
|
| 109 |
+
<a href="#" id="save-post-type-switcher" class="hide-if-no-js button"><?php _e( 'OK' ); ?></a>
|
| 110 |
+
<a href="#" id="cancel-post-type-switcher" class="hide-if-no-js"><?php _e( 'Cancel' ); ?></a>
|
| 111 |
+
</div>
|
| 112 |
+
|
| 113 |
+
<?php endif; ?>
|
| 114 |
+
|
| 115 |
+
</div>
|
| 116 |
+
|
| 117 |
+
<?php
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
/**
|
| 121 |
+
* Adds the post type column
|
| 122 |
+
*
|
| 123 |
+
* @since PostTypeSwitcher (1.2)
|
| 124 |
+
*/
|
| 125 |
+
public function add_column( $columns ) {
|
| 126 |
+
return array_merge( $columns, array( 'post_type' => __( 'Type' ) ) );
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
/**
|
| 130 |
+
* Manages the post type column
|
| 131 |
+
*
|
| 132 |
+
* @since PostTypeSwitcher (1.1.1)
|
| 133 |
+
*/
|
| 134 |
+
public function manage_column( $column, $post_id ) {
|
| 135 |
+
switch( $column ) {
|
| 136 |
+
case 'post_type' :
|
| 137 |
+
$post_type = get_post_type_object( get_post_type( $post_id ) ); ?>
|
| 138 |
+
|
| 139 |
+
<span data-post-type="<?php echo esc_attr( $post_type->name ); ?>"><?php echo esc_html( $post_type->labels->singular_name ); ?></span>
|
| 140 |
+
|
| 141 |
+
<?php
|
| 142 |
+
break;
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
/**
|
| 147 |
+
* Adds quickedit button for bulk-editing post types
|
| 148 |
+
*
|
| 149 |
+
* @since PostTypeSwitcher (1.2)
|
| 150 |
+
*/
|
| 151 |
+
public function quickedit( $column_name, $post_type ) {
|
| 152 |
+
|
| 153 |
+
// Bail to prevent multiple dropdowns in each column
|
| 154 |
+
if ( $column_name !== 'post_type' ) {
|
| 155 |
+
return;
|
| 156 |
+
} ?>
|
| 157 |
+
|
| 158 |
+
<fieldset class="inline-edit-col-right">
|
| 159 |
+
<div class="inline-edit-col">
|
| 160 |
+
<label class="alignleft">
|
| 161 |
+
<span class="title"><?php _e( 'Post Type' ); ?></span>
|
| 162 |
+
<?php wp_nonce_field( 'post-type-selector', 'pts-nonce-select' ); ?>
|
| 163 |
+
<?php $this->select_box(); ?>
|
| 164 |
+
</label>
|
| 165 |
+
</div>
|
| 166 |
+
</fieldset>
|
| 167 |
+
|
| 168 |
+
<?php
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
/**
|
| 172 |
+
* Adds quickedit script for getting values into quickedit box
|
| 173 |
+
*
|
| 174 |
+
* @since PostTypeSwitcher (1.2)
|
| 175 |
+
*/
|
| 176 |
+
public function quickedit_script( $hook = '' ) {
|
| 177 |
+
if ( 'edit.php' !== $hook ) {
|
| 178 |
+
return;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
wp_enqueue_script( 'pts_quickedit', plugins_url( 'js/quickedit.js', __FILE__ ), array( 'jquery' ), '', true );
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
/**
|
| 185 |
+
* Output a post-type dropdown
|
| 186 |
+
*
|
| 187 |
+
* @since PostTypeSwitcher (1.2)
|
| 188 |
+
*/
|
| 189 |
+
public function select_box() {
|
| 190 |
+
$args = (array) apply_filters( 'pts_post_type_filter', array(
|
| 191 |
+
'public' => true,
|
| 192 |
+
'show_ui' => true
|
| 193 |
+
) );
|
| 194 |
+
$post_types = get_post_types( $args, 'objects' ); ?>
|
| 195 |
+
|
| 196 |
+
<select name="pts_post_type" id="pts_post_type">
|
| 197 |
+
|
| 198 |
+
<?php foreach ( $post_types as $post_type => $pt ) : ?>
|
| 199 |
+
|
| 200 |
+
<?php if ( ! current_user_can( $pt->cap->publish_posts ) ) :
|
| 201 |
+
continue;
|
| 202 |
+
endif; ?>
|
| 203 |
+
|
| 204 |
+
<option value="<?php echo esc_attr( $pt->name ); ?>" <?php selected( get_post_type(), $post_type ); ?>><?php echo esc_html( $pt->labels->singular_name ); ?></option>
|
| 205 |
+
|
| 206 |
+
<?php endforeach; ?>
|
| 207 |
+
|
| 208 |
+
</select>
|
| 209 |
+
|
| 210 |
+
<?php
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
/**
|
| 214 |
+
* Set the post type on save_post but only when editing
|
| 215 |
+
*
|
| 216 |
+
* We do a bunch of sanity checks here, to make sure we're only changing the
|
| 217 |
+
* post type when the user explicitly intends to.
|
| 218 |
+
*
|
| 219 |
+
* - Not during autosave
|
| 220 |
+
* - Check nonce
|
| 221 |
+
* - Check user capabilities
|
| 222 |
+
* - Check $_POST input name
|
| 223 |
+
* - Check if revision or current post-type
|
| 224 |
+
* - Check new post-type exists
|
| 225 |
+
* - Check that user can publish posts of new type
|
| 226 |
+
*
|
| 227 |
+
* @since PostTypeSwitcher (0.3)
|
| 228 |
+
* @param int $post_id
|
| 229 |
+
* @param object $post
|
| 230 |
+
* @return If any number of condtions are met
|
| 231 |
+
*/
|
| 232 |
+
public function save_post( $post_id, $post ) {
|
| 233 |
+
|
| 234 |
+
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
| 235 |
+
return;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
if ( ! isset( $_REQUEST['pts-nonce-select'] ) ) {
|
| 239 |
+
return;
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
if ( ! wp_verify_nonce( $_REQUEST['pts-nonce-select'], 'post-type-selector' ) ) {
|
| 243 |
+
return;
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
if ( ! current_user_can( 'edit_post', $post_id ) ) {
|
| 247 |
+
return;
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
if ( empty( $_REQUEST['pts_post_type'] ) ) {
|
| 251 |
+
return;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
if ( in_array( $post->post_type, array( $_REQUEST['pts_post_type'], 'revision' ) ) ) {
|
| 255 |
+
return;
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
$new_post_type_object = get_post_type_object( $_REQUEST['pts_post_type'] );
|
| 259 |
+
if ( empty( $new_post_type_object ) ) {
|
| 260 |
+
return;
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
if ( ! current_user_can( $new_post_type_object->cap->publish_posts ) ) {
|
| 264 |
+
return;
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
set_post_type( $post_id, $new_post_type_object->name );
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
/**
|
| 271 |
+
* Adds needed JS and CSS to admin header
|
| 272 |
+
*
|
| 273 |
+
* @since PostTypeSwitcher (0.3)
|
| 274 |
+
* @return If on post-new.php
|
| 275 |
+
*/
|
| 276 |
+
public function admin_head() {
|
| 277 |
+
?>
|
| 278 |
+
|
| 279 |
+
<script type="text/javascript">
|
| 280 |
+
jQuery( document ).ready( function( $ ) {
|
| 281 |
+
jQuery( '.misc-pub-section.curtime.misc-pub-section-last' ).removeClass( 'misc-pub-section-last' );
|
| 282 |
+
jQuery( '#edit-post-type-switcher' ).on( 'click', function(e) {
|
| 283 |
+
jQuery( this ).hide();
|
| 284 |
+
jQuery( '#post-type-select' ).slideDown();
|
| 285 |
+
e.preventDefault();
|
| 286 |
+
});
|
| 287 |
+
|
| 288 |
+
jQuery( '#save-post-type-switcher' ).on( 'click', function(e) {
|
| 289 |
+
jQuery( '#post-type-select' ).slideUp();
|
| 290 |
+
jQuery( '#edit-post-type-switcher' ).show();
|
| 291 |
+
jQuery( '#post-type-display' ).text( jQuery( '#pts_post_type :selected' ).text() );
|
| 292 |
+
e.preventDefault();
|
| 293 |
+
});
|
| 294 |
+
|
| 295 |
+
jQuery( '#cancel-post-type-switcher' ).on( 'click', function(e) {
|
| 296 |
+
jQuery( '#post-type-select' ).slideUp();
|
| 297 |
+
jQuery( '#edit-post-type-switcher' ).show();
|
| 298 |
+
e.preventDefault();
|
| 299 |
+
});
|
| 300 |
+
});
|
| 301 |
+
</script>
|
| 302 |
+
<style type="text/css">
|
| 303 |
+
#post-type-select {
|
| 304 |
+
line-height: 2.5em;
|
| 305 |
+
margin-top: 3px;
|
| 306 |
+
display: none;
|
| 307 |
+
}
|
| 308 |
+
#post-type-select select#pts_post_type {
|
| 309 |
+
margin-right: 2px;
|
| 310 |
+
}
|
| 311 |
+
#post-type-select a#save-post-type-switcher {
|
| 312 |
+
vertical-align: middle;
|
| 313 |
+
margin-right: 2px;
|
| 314 |
+
}
|
| 315 |
+
#post-type-display {
|
| 316 |
+
font-weight: bold;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
#post-body .post-type-switcher::before {
|
| 320 |
+
content: '\f109';
|
| 321 |
+
font: 400 20px/1 dashicons;
|
| 322 |
+
speak: none;
|
| 323 |
+
display: inline-block;
|
| 324 |
+
padding: 0 2px 0 0;
|
| 325 |
+
top: 0;
|
| 326 |
+
left: -1px;
|
| 327 |
+
position: relative;
|
| 328 |
+
vertical-align: top;
|
| 329 |
+
-webkit-font-smoothing: antialiased;
|
| 330 |
+
-moz-osx-font-smoothing: grayscale;
|
| 331 |
+
text-decoration: none !important;
|
| 332 |
+
color: #888;
|
| 333 |
+
}
|
| 334 |
+
</style>
|
| 335 |
+
|
| 336 |
+
<?php
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
/**
|
| 340 |
+
* Whether or not the current file requires the post type switcher
|
| 341 |
+
*
|
| 342 |
+
* @since PostTypeSwitcher (1.1)
|
| 343 |
+
* @return bool True if it should load, false if not
|
| 344 |
+
*/
|
| 345 |
+
private static function is_allowed_page() {
|
| 346 |
+
global $pagenow;
|
| 347 |
+
|
| 348 |
+
// Only for admin area
|
| 349 |
+
if ( ! is_admin() ) {
|
| 350 |
+
return false;
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
// Allowed admin pages
|
| 354 |
+
$pages = apply_filters( 'pts_allowed_pages', array(
|
| 355 |
+
'post.php',
|
| 356 |
+
'edit.php',
|
| 357 |
+
'admin-ajax.php'
|
| 358 |
+
) );
|
| 359 |
+
|
| 360 |
+
// Only show switcher when editing
|
| 361 |
+
return (bool) in_array( $pagenow, $pages );
|
| 362 |
+
}
|
| 363 |
+
}
|
| 364 |
+
new Post_Type_Switcher();
|
readme.txt
CHANGED
|
@@ -2,8 +2,8 @@
|
|
| 2 |
Contributors: johnjamesjacoby, beatpanda
|
| 3 |
Tags: post type
|
| 4 |
Requires at least: 3.0
|
| 5 |
-
Tested up to: 4.
|
| 6 |
-
Stable tag: 1.
|
| 7 |
|
| 8 |
A simple way to change a post's type in WordPress
|
| 9 |
|
|
@@ -22,8 +22,11 @@ Now with bulk editing, thanks to Matthew Gerring!
|
|
| 22 |
|
| 23 |
== Changelog ==
|
| 24 |
|
|
|
|
|
|
|
|
|
|
| 25 |
= Version 1.4 =
|
| 26 |
-
* Improve handling of non-public post
|
| 27 |
|
| 28 |
= Version 1.3 =
|
| 29 |
* Fix saving of autodrafts
|
| 2 |
Contributors: johnjamesjacoby, beatpanda
|
| 3 |
Tags: post type
|
| 4 |
Requires at least: 3.0
|
| 5 |
+
Tested up to: 4.2
|
| 6 |
+
Stable tag: 1.5
|
| 7 |
|
| 8 |
A simple way to change a post's type in WordPress
|
| 9 |
|
| 22 |
|
| 23 |
== Changelog ==
|
| 24 |
|
| 25 |
+
= Version 1.5 - norcross =
|
| 26 |
+
* Fix multiple quickedit dropdowns
|
| 27 |
+
|
| 28 |
= Version 1.4 =
|
| 29 |
+
* Improve handling of non-public post types
|
| 30 |
|
| 31 |
= Version 1.3 =
|
| 32 |
* Fix saving of autodrafts
|
