Version Description
Download this release
Release Info
Developer | arjunthakur |
Plugin | Duplicate Page and Post |
Version | 1.0.1 |
Comparing to | |
See all releases |
Version 1.0.1
- duplicate-wp-page-post.php +173 -0
- readme.txt +0 -0
duplicate-wp-page-post.php
ADDED
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Duplicate Page and Post
|
4 |
+
Plugin URI: http://www.hisysinfotech.com/
|
5 |
+
Description: This plugin quickly creates a clone of page or post
|
6 |
+
Author: Arjun Thakur
|
7 |
+
Author URI: http://www.hisysinfotech.com/
|
8 |
+
Version: 1.0.1
|
9 |
+
License: GPLv2 or later
|
10 |
+
Text Domain: dpp_wpp_page
|
11 |
+
*/
|
12 |
+
if ( ! defined( 'ABSPATH' ) ) exit;
|
13 |
+
if (!defined("dpp_wpp_page_directory-dn")) define("dpp_wpp_page_directory-dn", plugin_basename(dirname(__FILE__)));
|
14 |
+
if(!class_exists('dcc_dpp_wpp_page')):
|
15 |
+
class dpp_wpp_page
|
16 |
+
{
|
17 |
+
|
18 |
+
/*AutoLoad Hooks*/
|
19 |
+
public function __construct()
|
20 |
+
{
|
21 |
+
register_activation_hook(__FILE__, array(&$this, 'dpp_wpp_page_install'));
|
22 |
+
add_action( 'admin_action_dt_dpp_post_as_draft', array(&$this,'dt_dpp_post_as_draft') );
|
23 |
+
add_filter( 'post_row_actions', array(&$this,'dt_dpp_post_link'), 10, 2);
|
24 |
+
add_filter( 'page_row_actions', array(&$this,'dt_dpp_post_link'), 10, 2);
|
25 |
+
add_action( 'post_submitbox_misc_actions', array(&$this,'dpp_wpp_page_custom_button'));
|
26 |
+
add_action( 'wp_before_admin_bar_render', array(&$this, 'dpp_wpp_page_admin_bar_link'));
|
27 |
+
}
|
28 |
+
|
29 |
+
/*Activation Hook*/
|
30 |
+
public function dpp_wpp_page_install()
|
31 |
+
{
|
32 |
+
$defaultsettings = array('dpp_post_status' => 'draft',
|
33 |
+
'dpp_post_redirect' => 'to_list',
|
34 |
+
'dpp_post_suffix' => '' );
|
35 |
+
$opt = get_option('dpp_wpp_page_options');
|
36 |
+
if(!$opt['dpp_post_status'])
|
37 |
+
{
|
38 |
+
update_option('dpp_wpp_page_options', $defaultsettings);
|
39 |
+
}
|
40 |
+
}
|
41 |
+
|
42 |
+
/*Important function*/
|
43 |
+
public function dt_dpp_post_as_draft()
|
44 |
+
{
|
45 |
+
global $wpdb;
|
46 |
+
|
47 |
+
/*sanitize_GET POST REQUEST*/
|
48 |
+
$post_copy = sanitize_text_field( $_POST["post"] );
|
49 |
+
$get_copy = sanitize_text_field( $_GET['post'] );
|
50 |
+
$request_copy = sanitize_text_field( $_REQUEST['action'] );
|
51 |
+
|
52 |
+
$opt = get_option('dpp_wpp_page_options');
|
53 |
+
$suffix = !empty($opt['dpp_post_suffix']) ? ' -- '.$opt['dpp_post_suffix'] : '';
|
54 |
+
$post_status = !empty($opt['dpp_post_status']) ? $opt['dpp_post_status'] : 'draft';
|
55 |
+
$redirectit = !empty($opt['dpp_post_redirect']) ? $opt['dpp_post_redirect'] : 'to_list';
|
56 |
+
|
57 |
+
if (! ( isset( $get_copy ) || isset( $post_copy ) || ( isset($request_copy) && 'dt_dpp_post_as_draft' == $request_copy ) ) ) {
|
58 |
+
wp_die('No post!');
|
59 |
+
}
|
60 |
+
$returnpage = '';
|
61 |
+
|
62 |
+
/* Get post id */
|
63 |
+
$post_id = (isset($get_copy) ? $get_copy : $post_copy );
|
64 |
+
|
65 |
+
$post = get_post( $post_id );
|
66 |
+
|
67 |
+
$current_user = wp_get_current_user();
|
68 |
+
$new_post_author = $current_user->ID;
|
69 |
+
|
70 |
+
/*Create the post Copy */
|
71 |
+
if (isset( $post ) && $post != null) {
|
72 |
+
/* Post data array */
|
73 |
+
$args = array('comment_status' => $post->comment_status,
|
74 |
+
'ping_status' => $post->ping_status,
|
75 |
+
'post_author' => $new_post_author,
|
76 |
+
'post_content' => $post->post_content,
|
77 |
+
'post_excerpt' => $post->post_excerpt,
|
78 |
+
'post_name' => $post->post_name,
|
79 |
+
'post_parent' => $post->post_parent,
|
80 |
+
'post_password' => $post->post_password,
|
81 |
+
'post_status' => $post_status,
|
82 |
+
'post_title' => $post->post_title.$suffix,
|
83 |
+
'post_type' => $post->post_type,
|
84 |
+
'to_ping' => $post->to_ping,
|
85 |
+
'menu_order' => $post->menu_order
|
86 |
+
|
87 |
+
);
|
88 |
+
$new_post_id = wp_insert_post( $args );
|
89 |
+
|
90 |
+
$taxonomies = get_object_taxonomies($post->post_type);
|
91 |
+
if(!empty($taxonomies) && is_array($taxonomies)):
|
92 |
+
foreach ($taxonomies as $taxonomy) {
|
93 |
+
$post_terms = wp_get_object_terms($post_id, $taxonomy, array('fields' => 'slugs'));
|
94 |
+
wp_set_object_terms($new_post_id, $post_terms, $taxonomy, false);}
|
95 |
+
endif;
|
96 |
+
|
97 |
+
$post_meta_infos = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id");
|
98 |
+
if (count($post_meta_infos)!=0) {
|
99 |
+
$sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
|
100 |
+
foreach ($post_meta_infos as $meta_info) {
|
101 |
+
$meta_key = $meta_info->meta_key;
|
102 |
+
$meta_value = addslashes($meta_info->meta_value);
|
103 |
+
$sql_query_sel[]= "SELECT $new_post_id, '$meta_key', '$meta_value'";
|
104 |
+
}
|
105 |
+
$sql_query.= implode(" UNION ALL ", $sql_query_sel);
|
106 |
+
$wpdb->query($sql_query);
|
107 |
+
}
|
108 |
+
|
109 |
+
/*choice redirect */
|
110 |
+
if($post->post_type != 'post'):$returnpage = '?post_type='.$post->post_type; endif;
|
111 |
+
if(!empty($redirectit) && $redirectit == 'to_list'):wp_redirect( admin_url( 'edit.php'.$returnpage ) );
|
112 |
+
elseif(!empty($redirectit) && $redirectit == 'to_page'):wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_post_id ) );
|
113 |
+
else:
|
114 |
+
wp_redirect( admin_url( 'edit.php'.$returnpage ) );
|
115 |
+
endif;
|
116 |
+
exit;
|
117 |
+
} else {
|
118 |
+
wp_die('Error! Post creation failed: ' . $post_id);
|
119 |
+
}
|
120 |
+
}
|
121 |
+
|
122 |
+
/*Add link to action*/
|
123 |
+
public function dt_dpp_post_link( $actions, $post ) {
|
124 |
+
$opt = get_option('dpp_wpp_page_options');
|
125 |
+
$post_status = !empty($opt['dpp_post_status']) ? $opt['dpp_post_status'] : 'draft';
|
126 |
+
if (current_user_can('edit_posts')) {
|
127 |
+
$actions['dpp'] = '<a href="admin.php?action=dt_dpp_post_as_draft&post=' . $post->ID . '" title="Clone this as '.$post_status.'" rel="permalink">Click here to Clone</a>';
|
128 |
+
}
|
129 |
+
return $actions;
|
130 |
+
}
|
131 |
+
|
132 |
+
/*Add link to edit Post*/
|
133 |
+
public function dpp_wpp_page_custom_button(){
|
134 |
+
$opt = get_option('dpp_wpp_page_options');
|
135 |
+
$post_status = !empty($opt['dpp_post_status']) ? $opt['dpp_post_status'] : 'draft';
|
136 |
+
global $post;
|
137 |
+
$html = '<div id="major-publishing-actions">';
|
138 |
+
$html .= '<div id="export-action">';
|
139 |
+
$html .= '<a href="admin.php?action=dt_dpp_post_as_draft&post=' . $post->ID . '" title="dpp this as '.$post_status.'" rel="permalink">Click here to Clone</a>';
|
140 |
+
$html .= '</div>';
|
141 |
+
$html .= '</div>';
|
142 |
+
echo $html;
|
143 |
+
}
|
144 |
+
|
145 |
+
/*Click here to clone Admin Bar*/
|
146 |
+
public function dpp_wpp_page_admin_bar_link()
|
147 |
+
{
|
148 |
+
global $wp_admin_bar;
|
149 |
+
global $post;
|
150 |
+
$opt = get_option('dpp_wpp_page_options');
|
151 |
+
$post_status = !empty($opt['dpp_post_status']) ? $opt['dpp_post_status'] : 'draft';
|
152 |
+
$current_object = get_queried_object();
|
153 |
+
if ( empty($current_object) )
|
154 |
+
return;
|
155 |
+
if ( ! empty( $current_object->post_type ) && ( $post_type_object = get_post_type_object( $current_object->post_type ) )&& ( $post_type_object->show_ui || $current_object->post_type == 'attachment') )
|
156 |
+
{
|
157 |
+
$wp_admin_bar->add_menu( array('parent' => 'edit',
|
158 |
+
'id' => 'dpp_this',
|
159 |
+
'title' => __("dpp this as ".$post_status."", 'dpp_wpp_page'),
|
160 |
+
'href' => admin_url().'admin.php?action=dt_dpp_post_as_draft&post=' . $post->ID
|
161 |
+
) );
|
162 |
+
}
|
163 |
+
}
|
164 |
+
|
165 |
+
/*WP Url Redirect*/
|
166 |
+
static function dp_redirect($url)
|
167 |
+
{
|
168 |
+
echo '<script>window.location.href="'.$url.'"</script>';
|
169 |
+
}
|
170 |
+
}
|
171 |
+
new dpp_wpp_page;
|
172 |
+
endif;
|
173 |
+
?>
|
readme.txt
ADDED
File without changes
|