Version Description
Download this release
Release Info
Developer | johnjamesjacoby |
Plugin | Post Type Switcher |
Version | 0.3 |
Comparing to | |
See all releases |
Code changes from version 0.2 to 0.3
- post-type-switcher.php +159 -123
- readme.txt +45 -41
post-type-switcher.php
CHANGED
@@ -1,123 +1,159 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Plugin Name: Post Type Switcher
|
4 |
-
Plugin URI: http://wordpress.org
|
5 |
-
Description: Allow switching of
|
6 |
-
Author: John James Jacoby
|
7 |
-
Version: 0.
|
8 |
-
Author URI: http://johnjamesjacoby.com
|
9 |
-
*/
|
10 |
-
|
11 |
-
/**
|
12 |
-
* pts_metabox()
|
13 |
-
*
|
14 |
-
* Adds post_publish metabox to allow changing post_type
|
15 |
-
*
|
16 |
-
* @global object $post Current post
|
17 |
-
*/
|
18 |
-
function pts_metabox() {
|
19 |
-
global $post;
|
20 |
-
|
21 |
-
//
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
//
|
26 |
-
$
|
27 |
-
|
28 |
-
//
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
$
|
34 |
-
|
35 |
-
//
|
36 |
-
$
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
<
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
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 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Post Type Switcher
|
4 |
+
Plugin URI: http://wordpress.org/extend/post-type-switcher/
|
5 |
+
Description: Allow switching of a post type in post publish area.
|
6 |
+
Author: John James Jacoby
|
7 |
+
Version: 0.3
|
8 |
+
Author URI: http://johnjamesjacoby.com
|
9 |
+
*/
|
10 |
+
|
11 |
+
/**
|
12 |
+
* pts_metabox()
|
13 |
+
*
|
14 |
+
* Adds post_publish metabox to allow changing post_type
|
15 |
+
*
|
16 |
+
* @global object $post Current post
|
17 |
+
*/
|
18 |
+
function pts_metabox() {
|
19 |
+
global $post, $pagenow;
|
20 |
+
|
21 |
+
// Only show switcher when editing
|
22 |
+
if ( $pagenow == 'post-new.php' )
|
23 |
+
return;
|
24 |
+
|
25 |
+
// Disallows things like attachments, revisions, etc...
|
26 |
+
$safe_filter = array( 'public' => true, 'show_ui' => true );
|
27 |
+
|
28 |
+
// Allow to be filtered, just incase you really need to switch between
|
29 |
+
// those crazy types of posts
|
30 |
+
$args = apply_filters( 'pts_metabox', $safe_filter );
|
31 |
+
|
32 |
+
// Get the post types based on the above arguments
|
33 |
+
$post_types = get_post_types( (array) $args, 'objects' );
|
34 |
+
|
35 |
+
// Populate necessary post_type values
|
36 |
+
$cur_post_type = $post->post_type;
|
37 |
+
$cur_post_type_object = get_post_type_object( $cur_post_type );
|
38 |
+
|
39 |
+
// Make sure the currently logged in user has the power
|
40 |
+
$can_publish = current_user_can( $cur_post_type_object->cap->publish_posts );
|
41 |
+
?>
|
42 |
+
|
43 |
+
<div class="misc-pub-section misc-pub-section-last post-type-switcher">
|
44 |
+
<label for="pts_post_type"><?php _e( 'Post Type:' ); ?></label>
|
45 |
+
<span id="post-type-display"><?php echo $cur_post_type_object->labels->singular_name; ?></span>
|
46 |
+
|
47 |
+
<?php if ( !empty( $can_publish ) ) : ?>
|
48 |
+
|
49 |
+
<a href="#" id="edit-post-type-switcher" class="hide-if-no-js"><?php _e( 'Edit' ); ?></a>
|
50 |
+
|
51 |
+
<?php wp_nonce_field( 'post-type-selector', 'pts-nonce-select' ); ?>
|
52 |
+
|
53 |
+
<div id="post-type-select">
|
54 |
+
<select name="pts_post_type" id="pts_post_type">
|
55 |
+
|
56 |
+
<?php
|
57 |
+
foreach ( $post_types as $post_type => $pt ) {
|
58 |
+
if ( ! current_user_can( $pt->cap->publish_posts ) )
|
59 |
+
continue;
|
60 |
+
|
61 |
+
echo '<option value="' . esc_attr( $pt->name ) . '"' . selected( $cur_post_type, $post_type, false ) . '>' . $pt->labels->singular_name . "</option>\n";
|
62 |
+
}
|
63 |
+
?>
|
64 |
+
|
65 |
+
</select>
|
66 |
+
<a href="#" id="save-post-type-switcher" class="hide-if-no-js button"><?php _e( 'OK' ); ?></a>
|
67 |
+
<a href="#" id="cancel-post-type-switcher" class="hide-if-no-js"><?php _e( 'Cancel' ); ?></a>
|
68 |
+
</div>
|
69 |
+
</div>
|
70 |
+
|
71 |
+
<?php
|
72 |
+
endif;
|
73 |
+
}
|
74 |
+
add_action( 'post_submitbox_misc_actions', 'pts_metabox' );
|
75 |
+
|
76 |
+
function pts_save_post( $post_id, $post ) {
|
77 |
+
global $pagenow;
|
78 |
+
|
79 |
+
// Only show switcher when editing
|
80 |
+
if ( $pagenow == 'post-new.php' )
|
81 |
+
return;
|
82 |
+
|
83 |
+
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
|
84 |
+
return;
|
85 |
+
|
86 |
+
if ( ! isset( $_POST['pts-nonce-select'] ) )
|
87 |
+
return;
|
88 |
+
|
89 |
+
if ( ! wp_verify_nonce( $_POST['pts-nonce-select'], 'post-type-selector' ) )
|
90 |
+
return;
|
91 |
+
|
92 |
+
if ( ! current_user_can( 'edit_post', $post_id ) )
|
93 |
+
return;
|
94 |
+
|
95 |
+
if ( $_POST['pts_post_type'] == $post->post_type )
|
96 |
+
return;
|
97 |
+
|
98 |
+
if ( ! $new_post_type_object = get_post_type_object( $_POST['pts_post_type'] ) )
|
99 |
+
return;
|
100 |
+
|
101 |
+
if ( ! current_user_can( $new_post_type_object->cap->publish_posts ) )
|
102 |
+
return;
|
103 |
+
|
104 |
+
set_post_type( $post_id, $new_post_type_object->name );
|
105 |
+
}
|
106 |
+
add_action( 'save_post', 'pts_save_post', 10, 2 );
|
107 |
+
|
108 |
+
/**
|
109 |
+
* pts_head()
|
110 |
+
*
|
111 |
+
* Adds needed JS and CSS to admin header
|
112 |
+
*/
|
113 |
+
function pts_head() {
|
114 |
+
global $pagenow;
|
115 |
+
|
116 |
+
// Only show switcher when editing
|
117 |
+
if ( $pagenow == 'post-new.php' )
|
118 |
+
return; ?>
|
119 |
+
|
120 |
+
<script type='text/javascript'>
|
121 |
+
jQuery(document).ready(function($){
|
122 |
+
$('#edit-post-type-switcher').click( function() {
|
123 |
+
$(this).hide();
|
124 |
+
$('#post-type-select').slideDown();
|
125 |
+
e.preventDefault();
|
126 |
+
});
|
127 |
+
|
128 |
+
$('#save-post-type-switcher').click( function() {
|
129 |
+
$('#post-type-select').slideUp();
|
130 |
+
$('#edit-post-type-switcher').show();
|
131 |
+
$('#post-type-display').text( $('#pts_post_type :selected').text() );
|
132 |
+
e.preventDefault();
|
133 |
+
});
|
134 |
+
|
135 |
+
$('#cancel-post-type-switcher').click( function() {
|
136 |
+
$('#post-type-select').slideUp();
|
137 |
+
$('#edit-post-type-switcher').show();
|
138 |
+
e.preventDefault();
|
139 |
+
});
|
140 |
+
});
|
141 |
+
</script>
|
142 |
+
<style type="text/css">
|
143 |
+
#post-type-select {
|
144 |
+
line-height: 2.5em;
|
145 |
+
margin-top: 3px;
|
146 |
+
display: none;
|
147 |
+
}
|
148 |
+
#post-type-display {
|
149 |
+
font-weight: bold;
|
150 |
+
}
|
151 |
+
div.post-type-switcher {
|
152 |
+
border-top: 1px solid #eee;
|
153 |
+
}
|
154 |
+
</style>
|
155 |
+
<?php
|
156 |
+
}
|
157 |
+
add_action( 'admin_head', 'pts_head' );
|
158 |
+
|
159 |
+
?>
|
readme.txt
CHANGED
@@ -1,41 +1,45 @@
|
|
1 |
-
=== Post Type Switcher ===
|
2 |
-
Contributors: johnjamesjacoby
|
3 |
-
Tags: post type
|
4 |
-
Requires at least: 3.0
|
5 |
-
Tested up to: 3.0
|
6 |
-
Stable tag: 0.2
|
7 |
-
|
8 |
-
A simple way to change a post type in WordPress.
|
9 |
-
|
10 |
-
== Description ==
|
11 |
-
|
12 |
-
A simple way to change a post type in WordPress.
|
13 |
-
|
14 |
-
Any combination is possible, even custom post types.
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
== Changelog ==
|
22 |
-
|
23 |
-
= Version 0.
|
24 |
-
*
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
*
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
1 |
+
=== Post Type Switcher ===
|
2 |
+
Contributors: johnjamesjacoby
|
3 |
+
Tags: post type
|
4 |
+
Requires at least: 3.0
|
5 |
+
Tested up to: 3.0
|
6 |
+
Stable tag: 0.2
|
7 |
+
|
8 |
+
A simple way to change a post type in WordPress.
|
9 |
+
|
10 |
+
== Description ==
|
11 |
+
|
12 |
+
A simple way to change a post type in WordPress.
|
13 |
+
|
14 |
+
Any combination is possible, even custom post types.
|
15 |
+
|
16 |
+
Page to Post
|
17 |
+
Post to Page
|
18 |
+
Page to Attachment
|
19 |
+
Post to Custom
|
20 |
+
|
21 |
+
== Changelog ==
|
22 |
+
|
23 |
+
= Version 0.3 =
|
24 |
+
* Use the API to change the post type, fixing a conflict with persistent object caches
|
25 |
+
* No longer requires JavaScript
|
26 |
+
|
27 |
+
= Version 0.2 =
|
28 |
+
* Disallow post types that are not public and do not have a visible UI
|
29 |
+
|
30 |
+
= Version 0.1 =
|
31 |
+
* Release
|
32 |
+
|
33 |
+
== Installation ==
|
34 |
+
|
35 |
+
* Install the plugin into the plugins/post-type-swticher directory, and activate!
|
36 |
+
* From the post edit screen, above the "Publish" button is the "Post Type" interface.
|
37 |
+
* Change post types as needed.
|
38 |
+
|
39 |
+
== Frequently Asked Questions ==
|
40 |
+
|
41 |
+
= Why would I need this? =
|
42 |
+
I needed it to move WordPress posts into a custom post type of my own, so this plugin was borned!
|
43 |
+
|
44 |
+
= Does this ruin my taxonomy associations? =
|
45 |
+
It shouldn't. The only thing this plugin does for version 0.1 is change the 'post_type' property of the post.
|