Version Description
- NEW: Added automatic creation of non-existing categories for subsite duplication
- Fixed issues with assigning taxonomy on new posts
- Resolved issues with featured image duplication between sites
- Tested with WordPress 6.0.2 + Multisite (PHP 8)
Download this release
Release Info
Developer | iclyde |
Plugin | Duplicate Post |
Version | 1.3.2 |
Comparing to | |
See all releases |
Code changes from version 1.3.1 to 1.3.2
- copy-delete-posts.php +2 -2
- post/handler.php +101 -5
- readme.txt +13 -17
copy-delete-posts.php
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
* Plugin Name: Copy & Delete Posts
|
5 |
* Plugin URI: https://copy-delete-posts.com
|
6 |
* Description: The best solution to easily make duplicates of your posts & pages, and delete them in one go.
|
7 |
-
* Version: 1.3.
|
8 |
* Author: Copy Delete Posts
|
9 |
* Author URI: https://copy-delete-posts.com/
|
10 |
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
@@ -30,7 +30,7 @@ analyst_init(array(
|
|
30 |
* @since 1.0.0
|
31 |
*/
|
32 |
// Plugin constants
|
33 |
-
define('CDP_VERSION', '1.3.
|
34 |
define('CDP_WP_VERSION', get_bloginfo('version'));
|
35 |
define('CDP_SCRIPT_DEBUG', false);
|
36 |
define('CDP_ROOT_DIR', __DIR__);
|
4 |
* Plugin Name: Copy & Delete Posts
|
5 |
* Plugin URI: https://copy-delete-posts.com
|
6 |
* Description: The best solution to easily make duplicates of your posts & pages, and delete them in one go.
|
7 |
+
* Version: 1.3.2
|
8 |
* Author: Copy Delete Posts
|
9 |
* Author URI: https://copy-delete-posts.com/
|
10 |
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
30 |
* @since 1.0.0
|
31 |
*/
|
32 |
// Plugin constants
|
33 |
+
define('CDP_VERSION', '1.3.2');
|
34 |
define('CDP_WP_VERSION', get_bloginfo('version'));
|
35 |
define('CDP_SCRIPT_DEBUG', false);
|
36 |
define('CDP_ROOT_DIR', __DIR__);
|
post/handler.php
CHANGED
@@ -319,13 +319,67 @@ function cdp_insert_new_post($areWePro = false) {
|
|
319 |
if ($setting != 'names')
|
320 |
$settings[$setting] = (($val == 'true') ? true : false);
|
321 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
322 |
/**
|
323 |
* This local function filters post data by user settings
|
324 |
* @param $post (array of wordpress post/page data)
|
325 |
* @param $settings (array of preselected settings of profile or by user)
|
326 |
* @return array with insert ready values for wordpress post || false on wrong $post
|
327 |
*/
|
328 |
-
function cdp_filter_post($post, $swap, $opt, $settings, $taxonomies = false, $areWePro = false) {
|
329 |
|
330 |
// If $post has wrong format return false
|
331 |
if (!(is_array($post) || is_object($post)))
|
@@ -368,6 +422,11 @@ function cdp_insert_new_post($areWePro = false) {
|
|
368 |
}
|
369 |
}
|
370 |
|
|
|
|
|
|
|
|
|
|
|
371 |
// Create array with required values and contant values
|
372 |
$new = array(
|
373 |
'post_title' => ($settings['title'] ? cdp_create_title($post['post_title'], $settings['names'], $post['ID'], $areWePro) : __('Untitled Copy', 'copy-delete-posts')),
|
@@ -396,8 +455,10 @@ function cdp_insert_new_post($areWePro = false) {
|
|
396 |
$new['post_password'] = $post['post_password'];
|
397 |
if ($settings['menu_order'])
|
398 |
$new['menu_order'] = $post['menu_order'];
|
399 |
-
if ($settings['category'])
|
400 |
-
|
|
|
|
|
401 |
if ($settings['post_tag'])
|
402 |
$new['tags_input'] = $post['tags_input'];
|
403 |
if ($taxonomies != false)
|
@@ -744,10 +805,14 @@ function cdp_insert_new_post($areWePro = false) {
|
|
744 |
* @param $id int/string of post
|
745 |
* @return array of inserted attachments
|
746 |
*/
|
747 |
-
function cdp_insert_attachments($id, $inserted_posts, $areWePro, $site) {
|
748 |
$inserts = array();
|
749 |
$media = get_attached_media('', $id);
|
750 |
|
|
|
|
|
|
|
|
|
751 |
// Handle multisite for premium
|
752 |
if ($areWePro && function_exists('cdpp_handle_multisite'))
|
753 |
cdpp_handle_multisite($site);
|
@@ -886,10 +951,11 @@ function cdp_insert_new_post($areWePro = false) {
|
|
886 |
|
887 |
// Run process and validate response
|
888 |
$childrens = cdp_check_childs($id); // if sizeof($this) == has childs
|
889 |
-
$post_data = cdp_filter_post($post, $swap, $pConv, $settings, $
|
890 |
$meta_data = cdp_filter_meta($meta, $settings, $id, $areWePro, $site, $post_data['post_title']); // can be false
|
891 |
$inserted_posts = cdp_insert_post($id, $post_data, $times, $areWePro, $isChild, $p_ids, $site); // $res['error'] must be == 0
|
892 |
$inserted_metas = cdp_insert_post_meta($inserted_posts['ids'], $meta_data, $areWePro, $inserted_posts['counter'], $site); // sizeof($res['error']) must be == 0
|
|
|
893 |
// Comments copy
|
894 |
if ($settings['comments'])
|
895 |
$inserted_comments = cdp_copy_comments($id, $inserted_posts['ids']);
|
@@ -900,6 +966,36 @@ function cdp_insert_new_post($areWePro = false) {
|
|
900 |
foreach ($inserted_posts['ids'] as $i => $tid)
|
901 |
$isReFormat = set_post_format($tid, get_post_format($id));
|
902 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
903 |
// Featured image copy
|
904 |
if ($settings['attachments'])
|
905 |
$inserted_attachments = cdp_insert_attachments($id, $inserted_posts, $areWePro, $site);
|
319 |
if ($setting != 'names')
|
320 |
$settings[$setting] = (($val == 'true') ? true : false);
|
321 |
|
322 |
+
/**
|
323 |
+
* cdp_duplicate_categories - Makes sure that categories exist on new subsite
|
324 |
+
*
|
325 |
+
* @param array $origin [ids of categories in source website]
|
326 |
+
* @param int $site ID of the destination subsite
|
327 |
+
* @return array [ids of categories in subsite]
|
328 |
+
*/
|
329 |
+
function cdp_duplicate_categories($origin, $site, $areWePro = false) {
|
330 |
+
|
331 |
+
if ($areWePro && $site != -1) {
|
332 |
+
|
333 |
+
$origin_ids = [];
|
334 |
+
$origin_names = [];
|
335 |
+
$newIds = [];
|
336 |
+
|
337 |
+
foreach ($origin as $i => $cat_id) {
|
338 |
+
$name = get_cat_name($cat_id);
|
339 |
+
if ($name && strlen($name) > 0) {
|
340 |
+
$origin_ids[] = $cat_id;
|
341 |
+
$origin_names[] = $name;
|
342 |
+
}
|
343 |
+
}
|
344 |
+
|
345 |
+
if (function_exists('cdpp_handle_multisite')) {
|
346 |
+
cdpp_handle_multisite($site);
|
347 |
+
}
|
348 |
+
|
349 |
+
foreach ($origin_names as $i => $cat_name) {
|
350 |
+
$cat_id = get_terms([
|
351 |
+
'fields' => 'ids',
|
352 |
+
'taxonomy' => 'category',
|
353 |
+
'name' => $cat_name
|
354 |
+
]);
|
355 |
+
|
356 |
+
if (sizeof($cat_id) > 0) {
|
357 |
+
$newIds[] = $cat_id[0];
|
358 |
+
} else {
|
359 |
+
$createdId = wp_create_category($cat_name);
|
360 |
+
if (is_numeric($createdId)) {
|
361 |
+
$newIds[] = $createdId;
|
362 |
+
}
|
363 |
+
}
|
364 |
+
}
|
365 |
+
|
366 |
+
if (function_exists('cdpp_handle_multisite_after')) {
|
367 |
+
cdpp_handle_multisite_after($site);
|
368 |
+
}
|
369 |
+
|
370 |
+
return $newIds;
|
371 |
+
|
372 |
+
} else return $origin;
|
373 |
+
|
374 |
+
}
|
375 |
+
|
376 |
/**
|
377 |
* This local function filters post data by user settings
|
378 |
* @param $post (array of wordpress post/page data)
|
379 |
* @param $settings (array of preselected settings of profile or by user)
|
380 |
* @return array with insert ready values for wordpress post || false on wrong $post
|
381 |
*/
|
382 |
+
function cdp_filter_post($post, $swap, $opt, $settings, $site, $taxonomies = false, $areWePro = false) {
|
383 |
|
384 |
// If $post has wrong format return false
|
385 |
if (!(is_array($post) || is_object($post)))
|
422 |
}
|
423 |
}
|
424 |
|
425 |
+
if (isset($ft['category']) && $settings['category']) {
|
426 |
+
$fixed_categories = cdp_duplicate_categories($ft['category'], $site, $areWePro);
|
427 |
+
$ft['category'] = $fixed_categories;
|
428 |
+
}
|
429 |
+
|
430 |
// Create array with required values and contant values
|
431 |
$new = array(
|
432 |
'post_title' => ($settings['title'] ? cdp_create_title($post['post_title'], $settings['names'], $post['ID'], $areWePro) : __('Untitled Copy', 'copy-delete-posts')),
|
455 |
$new['post_password'] = $post['post_password'];
|
456 |
if ($settings['menu_order'])
|
457 |
$new['menu_order'] = $post['menu_order'];
|
458 |
+
if ($settings['category']) {
|
459 |
+
$fixed_categories = cdp_duplicate_categories($post['post_category'], $site, $areWePro);
|
460 |
+
$new['post_category'] = $fixed_categories;
|
461 |
+
}
|
462 |
if ($settings['post_tag'])
|
463 |
$new['tags_input'] = $post['tags_input'];
|
464 |
if ($taxonomies != false)
|
805 |
* @param $id int/string of post
|
806 |
* @return array of inserted attachments
|
807 |
*/
|
808 |
+
function cdp_insert_attachments($id, $inserted_posts, $areWePro, $site, $featuredImageOnly = false) {
|
809 |
$inserts = array();
|
810 |
$media = get_attached_media('', $id);
|
811 |
|
812 |
+
if ($featuredImageOnly != false && is_array($featuredImageOnly)) {
|
813 |
+
$media = $featuredImageOnly;
|
814 |
+
}
|
815 |
+
|
816 |
// Handle multisite for premium
|
817 |
if ($areWePro && function_exists('cdpp_handle_multisite'))
|
818 |
cdpp_handle_multisite($site);
|
951 |
|
952 |
// Run process and validate response
|
953 |
$childrens = cdp_check_childs($id); // if sizeof($this) == has childs
|
954 |
+
$post_data = cdp_filter_post($post, $swap, $pConv, $settings, $site, $taxonomies, $areWePro); // can be false
|
955 |
$meta_data = cdp_filter_meta($meta, $settings, $id, $areWePro, $site, $post_data['post_title']); // can be false
|
956 |
$inserted_posts = cdp_insert_post($id, $post_data, $times, $areWePro, $isChild, $p_ids, $site); // $res['error'] must be == 0
|
957 |
$inserted_metas = cdp_insert_post_meta($inserted_posts['ids'], $meta_data, $areWePro, $inserted_posts['counter'], $site); // sizeof($res['error']) must be == 0
|
958 |
+
|
959 |
// Comments copy
|
960 |
if ($settings['comments'])
|
961 |
$inserted_comments = cdp_copy_comments($id, $inserted_posts['ids']);
|
966 |
foreach ($inserted_posts['ids'] as $i => $tid)
|
967 |
$isReFormat = set_post_format($tid, get_post_format($id));
|
968 |
|
969 |
+
if ($settings['f_image']) {
|
970 |
+
$thumbnail_id = get_post_thumbnail_id($id);
|
971 |
+
if (!is_bool($thumbnail_id) && $thumbnail_id > 0) {
|
972 |
+
$thumbnail_file = get_attached_file($thumbnail_id);
|
973 |
+
if (!is_bool($thumbnail_file) && is_string($thumbnail_file)) {
|
974 |
+
|
975 |
+
if (!$settings['attachments'] && $site != -1 && $areWePro) {
|
976 |
+
|
977 |
+
$thumbObj = [(object) ['ID' => $thumbnail_id]];
|
978 |
+
$thumbNewId = cdp_insert_attachments($id, $inserted_posts, $areWePro, $site, $thumbObj);
|
979 |
+
$thumbNewId = $thumbNewId[0]['id'];
|
980 |
+
|
981 |
+
if ($areWePro && function_exists('cdpp_handle_multisite')) {
|
982 |
+
cdpp_handle_multisite($site);
|
983 |
+
}
|
984 |
+
|
985 |
+
foreach ($inserted_posts['ids'] as $i_id) {
|
986 |
+
update_post_meta($i_id, '_thumbnail_id', $thumbNewId);
|
987 |
+
}
|
988 |
+
|
989 |
+
if ($areWePro && function_exists('cdpp_handle_multisite_after')) {
|
990 |
+
cdpp_handle_multisite_after($site);
|
991 |
+
}
|
992 |
+
|
993 |
+
}
|
994 |
+
|
995 |
+
}
|
996 |
+
}
|
997 |
+
}
|
998 |
+
|
999 |
// Featured image copy
|
1000 |
if ($settings['attachments'])
|
1001 |
$inserted_attachments = cdp_insert_attachments($id, $inserted_posts, $areWePro, $site);
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: CopyDeletePosts, copydelete
|
3 |
Tags: Duplicate post, Copy posts, Copy pages, Duplicate posts, Duplicate pages, Clone posts, Clone pages, Delete posts, Delete pages, Duplicator, copy post, copy page
|
4 |
Requires at least: 4.6
|
5 |
-
Tested up to: 6.0.
|
6 |
-
Stable tag: 1.3.
|
7 |
License: GPLv3
|
8 |
Requires PHP: 5.6
|
9 |
|
@@ -177,6 +177,12 @@ Vietnamese: [Sao chép bài đăng, sao chép trang, sao chép bài đăng tùy
|
|
177 |
|
178 |
== Changelog ==
|
179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
= 1.3.1 =
|
181 |
* Version fully tested with WordPress 6.0.1 + Multisite
|
182 |
* Removed unnecessary debug code
|
@@ -359,18 +365,8 @@ Vietnamese: [Sao chép bài đăng, sao chép trang, sao chép bài đăng tùy
|
|
359 |
* Initial release
|
360 |
|
361 |
== Upgrade Notice ==
|
362 |
-
= 1.3.
|
363 |
-
*
|
364 |
-
*
|
365 |
-
*
|
366 |
-
*
|
367 |
-
* Fixed issue while during duplication notice "Please select settings" appeared
|
368 |
-
* Fixed issue with multi-post duplication to different subsite
|
369 |
-
* Fixed post type restrictions, copy option won't appear in dropdown while copying is forbidden
|
370 |
-
* Fixed corner cases where copy action button was not displayed in subsites
|
371 |
-
* Fixed issues with backslashes and unicode characters - they should copied correctly now
|
372 |
-
* Default WordPress Posts and Pages are not longer treated as custom posts
|
373 |
-
* Resolved issues with scheduled clean-ups - sometimes this option settings were blank
|
374 |
-
* Resolved all deprecated warnings with PHP 8+
|
375 |
-
* NEW: Added automatic URL adjustment for multisites (premium)
|
376 |
-
* NEW: Added possibility to copy into multiple subsites at once - inside bulk modal (premium)
|
2 |
Contributors: CopyDeletePosts, copydelete
|
3 |
Tags: Duplicate post, Copy posts, Copy pages, Duplicate posts, Duplicate pages, Clone posts, Clone pages, Delete posts, Delete pages, Duplicator, copy post, copy page
|
4 |
Requires at least: 4.6
|
5 |
+
Tested up to: 6.0.2
|
6 |
+
Stable tag: 1.3.2
|
7 |
License: GPLv3
|
8 |
Requires PHP: 5.6
|
9 |
|
177 |
|
178 |
== Changelog ==
|
179 |
|
180 |
+
= 1.3.2 =
|
181 |
+
* NEW: Added automatic creation of non-existing categories for subsite duplication
|
182 |
+
* Fixed issues with assigning taxonomy on new posts
|
183 |
+
* Resolved issues with featured image duplication between sites
|
184 |
+
* Tested with WordPress 6.0.2 + Multisite (PHP 8)
|
185 |
+
|
186 |
= 1.3.1 =
|
187 |
* Version fully tested with WordPress 6.0.1 + Multisite
|
188 |
* Removed unnecessary debug code
|
365 |
* Initial release
|
366 |
|
367 |
== Upgrade Notice ==
|
368 |
+
= 1.3.2 =
|
369 |
+
* NEW: Added automatic creation of non-existing categories for subsite duplication
|
370 |
+
* Fixed issues with assigning taxonomy on new posts
|
371 |
+
* Resolved issues with featured image duplication between sites
|
372 |
+
* Tested with WordPress 6.0.2 + Multisite (PHP 8)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|