Post Type Switcher - Version 0.1

Version Description

Download this release

Release Info

Developer johnjamesjacoby
Plugin Icon 128x128 Post Type Switcher
Version 0.1
Comparing to
See all releases

Version 0.1

Files changed (2) hide show
  1. post-type-switcher.php +111 -0
  2. readme.txt +38 -0
post-type-switcher.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Post Type Switcher
4
+ Plugin URI: http://wordpress.org
5
+ Description: Allow switching of post_type in post publish area
6
+ Author: John James Jacoby
7
+ Version: 0.1
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
+ $post_types = get_post_types();
22
+ $cur_post_type = $post->post_type;
23
+ $cur_post_type_object = get_post_type_object( $cur_post_type );
24
+ $can_publish = current_user_can( $cur_post_type_object->cap->publish_posts );
25
+ ?>
26
+
27
+ <div class="misc-pub-section misc-pub-section-last post-type-switcher">
28
+ <label for="pts_post_type"><?php _e( 'Post Type:' ); ?></label>
29
+ <span id="post-type-display"><?php echo $cur_post_type_object->label; ?></span>
30
+ <?php if ( $can_publish ) : ?>
31
+ <a href="#pts_post_type" class="edit-post-type hide-if-no-js"><?php _e( 'Edit' ); ?></a>
32
+ <div id="post-type-select" class="hide-if-js">
33
+ <select name="pts_post_type" id="pts_post_type">
34
+ <?php
35
+ foreach ( $post_types as $post_type ) {
36
+ $pt = get_post_type_object( $post_type );
37
+ if ( current_user_can( $pt->cap->publish_posts ) ) :
38
+ ?>
39
+ <option value="<?php echo $pt->name; ?>"<?php if ( $cur_post_type == $post_type ) : ?>selected="selected"<?php endif; ?>><?php echo $pt->label; ?></option>
40
+ <?php
41
+ endif;
42
+ }
43
+ ?>
44
+ </select>
45
+ <input type="hidden" name="hidden_post_type" id="hidden_post_type" value="<?php echo $cur_post_type; ?>" />
46
+ <a href="#pts_post_type" class="save-post-type hide-if-no-js button"><?php _e( 'OK' ); ?></a>
47
+ <a href="#pts_post_type" class="cancel-post-type hide-if-no-js"><?php _e( 'Cancel' ); ?></a>
48
+ </div>
49
+ </div>
50
+ <?php
51
+ endif;
52
+ }
53
+ add_action( 'post_submitbox_misc_actions', 'pts_metabox' );
54
+
55
+ /**
56
+ * pts_head()
57
+ *
58
+ * Adds needed JS and CSS to admin header
59
+ */
60
+ function pts_head() {
61
+ ?>
62
+ <script type='text/javascript'>
63
+ jQuery(document).ready(function(){
64
+ jQuery('#post-type-select').siblings('a.edit-post-type').click(function() {
65
+ if (jQuery('#post-type-select').is(":hidden")) {
66
+ jQuery('#post-type-select').slideDown("normal");
67
+ jQuery(this).hide();
68
+ }
69
+ return false;
70
+ });
71
+
72
+ jQuery('.save-post-type', '#post-type-select').click(function() {
73
+ jQuery('#post-type-select').slideUp("normal");
74
+ jQuery('#post-type-select').siblings('a.edit-post-type').show();
75
+ pts_updateText();
76
+ return false;
77
+ });
78
+
79
+ jQuery('.cancel-post-type', '#post-type-select').click(function() {
80
+ jQuery('#post-type-select').slideUp("normal");
81
+ jQuery('#pts_post_type').val(jQuery('#hidden_post_type').val());
82
+ jQuery('#post-type-select').siblings('a.edit-post-type').show();
83
+ pts_updateText();
84
+ return false;
85
+ });
86
+
87
+ function pts_updateText() {
88
+ jQuery('#post-type-display').html( jQuery('#pts_post_type :selected').text() );
89
+ jQuery('#hidden_post_type').val(jQuery('#pts_post_type').val());
90
+ jQuery('#post_type').val(jQuery('#pts_post_type').val());
91
+ return true;
92
+ }
93
+ });
94
+ </script>
95
+ <style type="text/css">
96
+ #post-type-select {
97
+ line-height: 2.5em;
98
+ margin-top: 3px;
99
+ }
100
+ #post-type-display {
101
+ font-weight: bold;
102
+ }
103
+ div.post-type-switcher {
104
+ border-top: 1px solid #eee;
105
+ }
106
+ </style>
107
+ <?php
108
+ }
109
+ add_action( 'admin_head', 'pts_head' );
110
+
111
+ ?>
readme.txt ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.1
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.1 =
24
+ * Release
25
+
26
+ == Installation ==
27
+
28
+ * Install the plugin into the plugins/post-type-swticher directory, and activate!
29
+ * From the post edit screen, above the "Publish" button is the "Post Type" interface.
30
+ * Change post types as needed.
31
+
32
+ == Frequently Asked Questions ==
33
+
34
+ = Why would I need this? =
35
+ I needed it to move WordPress posts into a custom post type of my own, so this plugin was borned!
36
+
37
+ = Does this ruin my taxonomy associations? =
38
+ It shouldn't. The only thing this plugin does for version 0.1 is change the 'post_type' property of the post.