Version Description
Download this release
Release Info
Developer | mndpsingh287 |
Plugin | Duplicate Page |
Version | 1.1 |
Comparing to | |
See all releases |
Version 1.1
duplicate-page/duplicatepage.php
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Duplicate Page
|
4 |
+
Plugin URI: http://mysenseinc.com/
|
5 |
+
Description: It will duplicate Posts and Pages only.
|
6 |
+
Author: mndpsingh287
|
7 |
+
Version: 1.1
|
8 |
+
Author URI: https://profiles.wordpress.org/mndpsingh287/
|
9 |
+
License: GPLv2
|
10 |
+
Text Domain: trackpage
|
11 |
+
*/
|
12 |
+
function dt_duplicate_post_as_draft(){
|
13 |
+
global $wpdb;
|
14 |
+
if (! ( isset( $_GET['post']) || isset( $_POST['post']) || ( isset($_REQUEST['action']) && 'dt_duplicate_post_as_draft' == $_REQUEST['action'] ) ) ) {
|
15 |
+
wp_die('No post to duplicate has been supplied!');
|
16 |
+
}
|
17 |
+
/*
|
18 |
+
* get the original post id
|
19 |
+
*/
|
20 |
+
$post_id = (isset($_GET['post']) ? $_GET['post'] : $_POST['post']);
|
21 |
+
/*
|
22 |
+
* and all the original post data then
|
23 |
+
*/
|
24 |
+
$post = get_post( $post_id );
|
25 |
+
/*
|
26 |
+
* if you don't want current user to be the new post author,
|
27 |
+
* then change next couple of lines to this: $new_post_author = $post->post_author;
|
28 |
+
*/
|
29 |
+
$current_user = wp_get_current_user();
|
30 |
+
$new_post_author = $current_user->ID;
|
31 |
+
/*
|
32 |
+
* if post data exists, create the post duplicate
|
33 |
+
*/
|
34 |
+
if (isset( $post ) && $post != null) {
|
35 |
+
/*
|
36 |
+
* new post data array
|
37 |
+
*/
|
38 |
+
$args = array(
|
39 |
+
'comment_status' => $post->comment_status,
|
40 |
+
'ping_status' => $post->ping_status,
|
41 |
+
'post_author' => $new_post_author,
|
42 |
+
'post_content' => $post->post_content,
|
43 |
+
'post_excerpt' => $post->post_excerpt,
|
44 |
+
'post_name' => $post->post_name,
|
45 |
+
'post_parent' => $post->post_parent,
|
46 |
+
'post_password' => $post->post_password,
|
47 |
+
'post_status' => 'draft',
|
48 |
+
'post_title' => $post->post_title,
|
49 |
+
'post_type' => $post->post_type,
|
50 |
+
'to_ping' => $post->to_ping,
|
51 |
+
'menu_order' => $post->menu_order
|
52 |
+
);
|
53 |
+
/*
|
54 |
+
* insert the post by wp_insert_post() function
|
55 |
+
*/
|
56 |
+
$new_post_id = wp_insert_post( $args );
|
57 |
+
/*
|
58 |
+
* get all current post terms ad set them to the new post draft
|
59 |
+
*/
|
60 |
+
$taxonomies = get_object_taxonomies($post->post_type);
|
61 |
+
if(!empty($taxonomies) && is_array($taxonomies)):
|
62 |
+
foreach ($taxonomies as $taxonomy) {
|
63 |
+
$post_terms = wp_get_object_terms($post_id, $taxonomy, array('fields' => 'slugs'));
|
64 |
+
wp_set_object_terms($new_post_id, $post_terms, $taxonomy, false);
|
65 |
+
}
|
66 |
+
endif;
|
67 |
+
/*
|
68 |
+
* duplicate all post meta
|
69 |
+
*/
|
70 |
+
$post_meta_infos = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id");
|
71 |
+
if (count($post_meta_infos)!=0) {
|
72 |
+
$sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
|
73 |
+
foreach ($post_meta_infos as $meta_info) {
|
74 |
+
$meta_key = $meta_info->meta_key;
|
75 |
+
$meta_value = addslashes($meta_info->meta_value);
|
76 |
+
$sql_query_sel[]= "SELECT $new_post_id, '$meta_key', '$meta_value'";
|
77 |
+
}
|
78 |
+
$sql_query.= implode(" UNION ALL ", $sql_query_sel);
|
79 |
+
$wpdb->query($sql_query);
|
80 |
+
}
|
81 |
+
/*
|
82 |
+
* finally, redirect to the edit post screen for the new draft
|
83 |
+
*/
|
84 |
+
wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_post_id ) );
|
85 |
+
exit;
|
86 |
+
} else {
|
87 |
+
wp_die('Error! Post creation failed, could not find original post: ' . $post_id);
|
88 |
+
}
|
89 |
+
}
|
90 |
+
add_action( 'admin_action_dt_duplicate_post_as_draft', 'dt_duplicate_post_as_draft' );
|
91 |
+
/*
|
92 |
+
* Add the duplicate link to action list for post_row_actions
|
93 |
+
*/
|
94 |
+
function dt_duplicate_post_link( $actions, $post ) {
|
95 |
+
if (current_user_can('edit_posts')) {
|
96 |
+
$actions['duplicate'] = '<a href="admin.php?action=dt_duplicate_post_as_draft&post=' . $post->ID . '" title="Duplicate This as Draft" rel="permalink">Duplicate This</a>';
|
97 |
+
}
|
98 |
+
return $actions;
|
99 |
+
}
|
100 |
+
add_filter( 'post_row_actions', 'dt_duplicate_post_link', 10, 2); /* for posts */
|
101 |
+
add_filter( 'page_row_actions', 'dt_duplicate_post_link', 10, 2); /* for pages */
|
102 |
+
?>
|
duplicate-page/readme.txt
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Duplicate Page ===
|
2 |
+
Contributors: mndpsingh287
|
3 |
+
Tags: Page Duplicate, Post duplicate, duplicate custom posts, duplicate page, duplicate post, duplicate ,custom posts, post, page, duplicate this, duplicate
|
4 |
+
Requires at least: 3.4
|
5 |
+
Tested up to: 4.5
|
6 |
+
Stable tag: 1.1
|
7 |
+
License: GPLv2 or later
|
8 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
+
|
10 |
+
It will duplicate Posts, Pages and Custom Posts.
|
11 |
+
|
12 |
+
== Description ==
|
13 |
+
|
14 |
+
It will duplicate Posts, Pages and Custom Posts. You can duplicate you pages, posts and custom post by just one click and it will save as draft.
|
15 |
+
|
16 |
+
|
17 |
+
== Installation ==
|
18 |
+
|
19 |
+
1. Upload the `duplicatepage` folder to the directory `/wp-content/plugins/`.
|
20 |
+
2. Activate the plugin using the 'Plugins' menu in WordPress. =
|
21 |
+
|
22 |
+
== Frequently asked questions ==
|
23 |
+
|
24 |
+
## How to use
|
25 |
+
|
26 |
+
1. First create New Post/Page Or Use old.
|
27 |
+
2. After click on duplicate this link, then duplicate post/ page will be created and saved as draft.
|
28 |
+
|
29 |
+
== Screenshots ==
|
30 |
+
|
31 |
+
1. Duplicate this icon
|
32 |
+
2. Duplicate Post/page
|
33 |
+
|
34 |
+
== Changelog ==
|
35 |
+
|
36 |
+
= 1.1 (04th May,2016) =
|
37 |
+
|
38 |
+
* fix some Bug in 1.0
|
39 |
+
|
40 |
+
|
41 |
+
== Other Notes ==
|
42 |
+
|
43 |
+
= Minimum requirements for Gallery Bank. =
|
44 |
+
* Wordpress 3.3+
|
45 |
+
* PHP 5.x
|
46 |
+
* MySQL 5.x
|
47 |
+
|
48 |
+
If any problem occurs, please contact us at [mandeep.singh@mysenseinc.com](mailto:mandeep.singh@mysenseinc.com).
|
49 |
+
|
50 |
+
|
51 |
+
|
52 |
+
|
53 |
+
|
54 |
+
|
duplicate-page/screenshot/screenshot-1.png
ADDED
Binary file
|
duplicate-page/screenshot/screenshot-2.png
ADDED
Binary file
|