Version Description
- Updated filenames and paths so the plugin works.
=
Download this release
Release Info
Developer | metaphorcreations |
Plugin | Post Duplicator |
Version | 1.1 |
Comparing to | |
See all releases |
Version 1.1
- m4c-postduplicator.js +29 -0
- m4c-postduplicator.php +116 -0
- readme.txt +48 -0
m4c-postduplicator.js
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
jQuery( document ).ready( function() {
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Duplicate post listener.
|
5 |
+
*
|
6 |
+
* Creates an ajax request that creates a new post,
|
7 |
+
* duplicating all the data and custom meta.
|
8 |
+
*
|
9 |
+
* @since 1.0.0
|
10 |
+
*/
|
11 |
+
jQuery( '.m4c-duplicate-post' ).click( function( e ) {
|
12 |
+
|
13 |
+
e.preventDefault();
|
14 |
+
|
15 |
+
// Create the data to pass
|
16 |
+
var data = {
|
17 |
+
action: 'm4c_duplicate_post',
|
18 |
+
original_id: jQuery(this).attr('href'),
|
19 |
+
security: jQuery(this).attr('rel')
|
20 |
+
};
|
21 |
+
|
22 |
+
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
|
23 |
+
jQuery.post( ajaxurl, data, function( response ) {
|
24 |
+
|
25 |
+
// Reload the page
|
26 |
+
location.reload();
|
27 |
+
});
|
28 |
+
});
|
29 |
+
});
|
m4c-postduplicator.php
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
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
|
9 |
+
*/
|
10 |
+
|
11 |
+
/*
|
12 |
+
Copyright 2012 Metaphor Creations (email : joe@metaphorcreations.com)
|
13 |
+
|
14 |
+
This program is free software; you can redistribute it and/or modify
|
15 |
+
it under the terms of the GNU General Public License, version 2, as
|
16 |
+
published by the Free Software Foundation.
|
17 |
+
|
18 |
+
This program is distributed in the hope that it will be useful,
|
19 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
GNU General Public License for more details.
|
22 |
+
|
23 |
+
You should have received a copy of the GNU General Public License
|
24 |
+
along with this program; if not, write to the Free Software
|
25 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
26 |
+
*/
|
27 |
+
|
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 |
+
}
|
readme.txt
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Post Duplicator ===
|
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 |
+
|
9 |
+
Creates functionality to duplicate any and all post types, including taxonomies & custom fields.
|
10 |
+
|
11 |
+
== Description ==
|
12 |
+
|
13 |
+
This plugin was created to make an exact duplicate of a selected post. Custom post types are supported, along with custom taxonomies and custom fields.
|
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 |
+
|
21 |
+
== Installation ==
|
22 |
+
|
23 |
+
1. Upload `m4c-postduplicator` directory to the `/wp-content/plugins/` directory
|
24 |
+
2. Activate the plugin through the 'Plugins' menu in WordPress
|
25 |
+
|
26 |
+
== Frequently Asked Questions ==
|
27 |
+
|
28 |
+
= Are there any settings I need to configure? =
|
29 |
+
|
30 |
+
No.
|
31 |
+
|
32 |
+
= How do I install the plugin? =
|
33 |
+
|
34 |
+
Check out the 'Installation' tab.
|
35 |
+
|
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.
|