Post Duplicator - Version 2.0

Version Description

  • Added a settings page to set 'post status' and 'date' of duplicated posts.
Download this release

Release Info

Developer metaphorcreations
Plugin Icon 128x128 Post Duplicator
Version 2.0
Comparing to
See all releases

Code changes from version 1.1 to 2.0

Files changed (3) hide show
  1. m4c-postduplicator.php +21 -68
  2. readme.txt +11 -3
  3. screenshot-1.png +0 -0
m4c-postduplicator.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Post Duplicator
4
  Description: Creates functionality to duplicate any and all post types, including taxonomies & custom fields
5
- Version: 1.1
6
  Author: Metaphor Creations
7
  Author URI: http://www.metaphorcreations.com
8
  License: GPL2
@@ -28,89 +28,42 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28
 
29
 
30
 
31
- add_action( 'admin_enqueue_scripts', 'm4c_duplicate_post_scripts' );
32
- /**
33
- * Add the necessary jquery.
34
- *
35
- * @since 1.0.0
36
- */
37
- function m4c_duplicate_post_scripts( $hook_suffix ) {
38
- if( $hook_suffix == 'edit.php' ) {
39
- wp_enqueue_script( 'm4c-duplicate-post', plugins_url().'/post-duplicator/m4c-postduplicator.js', array('jquery'), '1.0' );
40
- }
41
  }
 
 
42
 
43
 
44
 
45
 
46
- add_filter( 'post_row_actions', 'm4c_action_row', 10, 2 );
47
- add_filter( 'page_row_actions', 'm4c_action_row', 10, 2 );
48
  /**
49
- * Add a duplicate post link.
50
  *
51
- * @since 1.0.0
52
  */
53
- function m4c_action_row( $actions, $post ){
54
 
55
- // Get the post type object
56
- $post_type = get_post_type_object( $post->post_type );
 
 
 
57
 
58
- // Create a nonce & add an action
59
- $nonce = wp_create_nonce( 'm4c_ajax_file_nonce' );
60
- $actions['duplicate_post'] = '<a class="m4c-duplicate-post" rel="'.$nonce.'" href="'.$post->ID.'">Duplicate '.$post_type->labels->singular_name.'</a>';
61
-
62
- return $actions;
63
  }
64
 
65
 
66
 
67
 
68
- add_action( 'wp_ajax_m4c_duplicate_post', 'm4c_duplicate_post' );
69
- /**
70
- * Thehe jQuery ajax call to create a new post.
71
- * Duplicates all the data including custom meta.
72
- *
73
- * @since 1.0.0
74
- */
75
- function m4c_duplicate_post() {
76
-
77
- // Get access to the database
78
- global $wpdb;
79
-
80
- // Check the nonce
81
- check_ajax_referer( 'm4c_ajax_file_nonce', 'security' );
82
-
83
- // Get variables
84
- $original_id = $_POST['original_id'];
85
-
86
- // Get the post as an array
87
- $duplicate = get_post( $original_id, 'ARRAY_A' );
88
-
89
- // Modify some of the elements
90
- $duplicate['post_title'] = $duplicate['post_title'].' Copy';
91
-
92
- // Remove some of the keys
93
- unset( $duplicate['ID'] );
94
- unset( $duplicate['guid'] );
95
- unset( $duplicate['comment_count'] );
96
 
97
- // Insert the post into the database
98
- $duplicate_id = wp_insert_post( $duplicate );
99
-
100
- // Duplicate all the taxonomies/terms
101
- $taxonomies = get_object_taxonomies( $duplicate['post_type'] );
102
- foreach( $taxonomies as $taxonomy ) {
103
- $terms = wp_get_post_terms( $original_id, $taxonomy, array('fields' => 'names') );
104
- wp_set_object_terms( $duplicate_id, $terms, $taxonomy );
105
- }
106
 
107
- // Duplicate all the custom fields
108
- $custom_fields = get_post_custom( $original_id );
109
- foreach ( $custom_fields as $key => $value ) {
110
- add_post_meta( $duplicate_id, $key, maybe_unserialize($value[0]) );
111
- }
112
 
113
- echo 'Duplicate Post Created!';
114
 
115
- die(); // this is required to return a proper result
116
- }
2
  /*
3
  Plugin Name: Post Duplicator
4
  Description: Creates functionality to duplicate any and all post types, including taxonomies & custom fields
5
+ Version: 2.0
6
  Author: Metaphor Creations
7
  Author URI: http://www.metaphorcreations.com
8
  License: GPL2
28
 
29
 
30
 
31
+ /**Define Widget Constants */
32
+ if ( WP_DEBUG ) {
33
+ define ( 'MTPHR_POST_DUPLICATOR_VERSION', '2.0-'.time() );
34
+ } else {
35
+ define ( 'MTPHR_POST_DUPLICATOR_VERSION', '2.0' );
 
 
 
 
 
36
  }
37
+ define ( 'MTPHR_POST_DUPLICATOR_DIR', plugin_dir_path(__FILE__) );
38
+ define ( 'MTPHR_POST_DUPLICATOR_URL', plugins_url().'/post-duplicator' );
39
 
40
 
41
 
42
 
 
 
43
  /**
44
+ * Include files.
45
  *
46
+ * @since 2.0
47
  */
48
+ if ( is_admin() ) {
49
 
50
+ // Load Metaboxer
51
+ if( !function_exists('metaboxer_container') ) {
52
+ require_once( MTPHR_POST_DUPLICATOR_DIR.'metaboxer/metaboxer.php' );
53
+ require_once( MTPHR_POST_DUPLICATOR_DIR.'metaboxer/metaboxer-class.php' );
54
+ }
55
 
56
+ require_once( MTPHR_POST_DUPLICATOR_DIR.'includes/scripts.php' );
57
+ require_once( MTPHR_POST_DUPLICATOR_DIR.'includes/ajax.php' );
58
+ require_once( MTPHR_POST_DUPLICATOR_DIR.'includes/edit.php' );
59
+ require_once( MTPHR_POST_DUPLICATOR_DIR.'includes/functions.php' );
60
+ require_once( MTPHR_POST_DUPLICATOR_DIR.'includes/settings.php' );
61
  }
62
 
63
 
64
 
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
 
 
 
 
 
 
 
 
 
67
 
 
 
 
 
 
68
 
 
69
 
 
 
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: metaphorcreations
3
  Tags: posts, post, duplicate, duplication
4
  Requires at least: 3.0
5
- Tested up to: 3.3.2
6
  Stable tag: /trunk/
7
  License: GPL2
8
 
@@ -14,7 +14,7 @@ This plugin was created to make an exact duplicate of a selected post. Custom po
14
 
15
  *Note: Comments are not passed to the new post.
16
 
17
- There are no settings to mess with as this plugin is simply meant to quickly and easily duplicate a post. Just hover over a post in the edit screen and select 'Duplicate {post_type}' to create a duplicate post.
18
 
19
  I created this plugin mainly for myself when I'm develping WordPress sites. I always need dummy content to fill out the look of a website and wanted a very quick and easy way to create multiple posts.
20
 
@@ -27,7 +27,8 @@ I created this plugin mainly for myself when I'm develping WordPress sites. I al
27
 
28
  = Are there any settings I need to configure? =
29
 
30
- No.
 
31
 
32
  = How do I install the plugin? =
33
 
@@ -36,13 +37,20 @@ Check out the 'Installation' tab.
36
  == Screenshots ==
37
 
38
  1. Sample view of the duplicate post link
 
39
 
40
  == Changelog ==
41
 
 
 
 
42
  = 1.1 =
43
  * Updated filenames and paths so the plugin works.
44
 
45
  == Upgrade Notice ==
46
 
 
 
 
47
  = 1.1 =
48
  Must upgrade in order for the plugin to work. The file paths where initially wrong as the plugin upload created a different directory name.
2
  Contributors: metaphorcreations
3
  Tags: posts, post, duplicate, duplication
4
  Requires at least: 3.0
5
+ Tested up to: 3.4.
6
  Stable tag: /trunk/
7
  License: GPL2
8
 
14
 
15
  *Note: Comments are not passed to the new post.
16
 
17
+ This plugin is simply meant to quickly and easily duplicate a post. Just hover over a post in the edit screen and select 'Duplicate {post_type}' to create a duplicate post.
18
 
19
  I created this plugin mainly for myself when I'm develping WordPress sites. I always need dummy content to fill out the look of a website and wanted a very quick and easy way to create multiple posts.
20
 
27
 
28
  = Are there any settings I need to configure? =
29
 
30
+ No, but there are a couple settings you can adjust if you choose to do so.
31
+ View the settings by going to 'Tools > Post Duplicator'.
32
 
33
  = How do I install the plugin? =
34
 
37
  == Screenshots ==
38
 
39
  1. Sample view of the duplicate post link
40
+ 2. View of the settings page
41
 
42
  == Changelog ==
43
 
44
+ = 2.0 =
45
+ * Added a settings page to set 'post status' and 'date' of duplicated posts.
46
+
47
  = 1.1 =
48
  * Updated filenames and paths so the plugin works.
49
 
50
  == Upgrade Notice ==
51
 
52
+ = 2.0 =
53
+ Upgrade Post Duplicator to add 'post status' and 'date' options to your duplicated posts.
54
+
55
  = 1.1 =
56
  Must upgrade in order for the plugin to work. The file paths where initially wrong as the plugin upload created a different directory name.
screenshot-1.png ADDED
Binary file