Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/themify-.../classes
File: class-builder-duplicate-page.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Builder Duplicate API
[2] Fix | Delete
*
[3] Fix | Delete
* This class provide api to duplicate post or page including the builder data.
[4] Fix | Delete
*
[5] Fix | Delete
*
[6] Fix | Delete
* @package Themify_Builder
[7] Fix | Delete
* @subpackage Themify_Builder/classes
[8] Fix | Delete
*/
[9] Fix | Delete
[10] Fix | Delete
defined( 'ABSPATH' ) || exit;
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Duplicate builder class.
[14] Fix | Delete
*
[15] Fix | Delete
* Main class to handle duplicate post/page with it's builder data.
[16] Fix | Delete
*
[17] Fix | Delete
*
[18] Fix | Delete
* @package Themify_Builder
[19] Fix | Delete
* @subpackage Themify_Builder/classes
[20] Fix | Delete
* @author Themify
[21] Fix | Delete
*/
[22] Fix | Delete
class Themify_Builder_Duplicate_Page {
[23] Fix | Delete
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Class Constructor.
[27] Fix | Delete
*
[28] Fix | Delete
* @access public
[29] Fix | Delete
*/
[30] Fix | Delete
public static function init() {
[31] Fix | Delete
// Actions
[32] Fix | Delete
add_action( 'themify_builder_duplicate', array( __CLASS__, 'duplicate_data' ), 10, 2 );
[33] Fix | Delete
add_action( 'wp_ajax_tb_duplicate_page', array( __CLASS__, 'duplicate_page_ajaxify' ), 10 );
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* Duplicate page
[38] Fix | Delete
*/
[39] Fix | Delete
public static function duplicate_page_ajaxify() {
[40] Fix | Delete
check_ajax_referer('tf_nonce', 'nonce');
[41] Fix | Delete
if ( ! empty( $_POST['bid'] ) && current_user_can( 'edit_posts' ) ) {
[42] Fix | Delete
$post_id = (int) $_POST['bid'];
[43] Fix | Delete
$post = get_post($post_id);
[44] Fix | Delete
if( is_object($post) ) {
[45] Fix | Delete
$new_post_id=self::duplicate($post);
[46] Fix | Delete
if($new_post_id>0 && !is_string($new_post_id)){
[47] Fix | Delete
unset($post);
[48] Fix | Delete
$new_url = !empty($_POST['tb_is_admin']) && intval($_POST['tb_is_admin'])===1?get_edit_post_link( $new_post_id,'json' ):get_permalink( $new_post_id );
[49] Fix | Delete
wp_send_json_success($new_url);
[50] Fix | Delete
}
[51] Fix | Delete
else{
[52] Fix | Delete
if($new_post_id===0){
[53] Fix | Delete
$new_post_id=__('There is an error on duplicating page','themify');
[54] Fix | Delete
}
[55] Fix | Delete
wp_send_json_error($new_post_id);
[56] Fix | Delete
}
[57] Fix | Delete
}
[58] Fix | Delete
}
[59] Fix | Delete
wp_die();
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
[63] Fix | Delete
/**
[64] Fix | Delete
* Perform duplicating post/page.
[65] Fix | Delete
*
[66] Fix | Delete
* @access public
[67] Fix | Delete
* @param object $post
[68] Fix | Delete
* @param string $status
[69] Fix | Delete
* @param string $parent_id
[70] Fix | Delete
* @return int
[71] Fix | Delete
*/
[72] Fix | Delete
public static function duplicate( $post, $status = '', $parent_id = '' ) {
[73] Fix | Delete
// We don't want to clone revisions
[74] Fix | Delete
if ( $post->post_type === 'revision' ){
[75] Fix | Delete
return;
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
$prefix = $suffix = '';
[79] Fix | Delete
[80] Fix | Delete
if ( $post->post_type !== 'attachment' ) {
[81] Fix | Delete
$suffix = ' Copy';
[82] Fix | Delete
}
[83] Fix | Delete
$new_post_author = wp_get_current_user();
[84] Fix | Delete
[85] Fix | Delete
$new_post = array(
[86] Fix | Delete
'menu_order' => $post->menu_order,
[87] Fix | Delete
'comment_status' => $post->comment_status,
[88] Fix | Delete
'ping_status' => $post->ping_status,
[89] Fix | Delete
'post_author' => $new_post_author->ID,
[90] Fix | Delete
'post_content' => $post->post_content,
[91] Fix | Delete
'post_excerpt' => $post->post_excerpt,
[92] Fix | Delete
'post_mime_type' => $post->post_mime_type,
[93] Fix | Delete
'post_parent' => $new_post_parent = empty($parent_id)? $post->post_parent : $parent_id,
[94] Fix | Delete
'post_password' => $post->post_password,
[95] Fix | Delete
'post_status' => $new_post_status = (empty($status))? $post->post_status: $status,
[96] Fix | Delete
'post_title' => $prefix.$post->post_title.$suffix,
[97] Fix | Delete
'post_type' => $post->post_type
[98] Fix | Delete
);
[99] Fix | Delete
[100] Fix | Delete
$new_post_id = wp_insert_post( $new_post );
[101] Fix | Delete
if($new_post_id>0 && !is_wp_error($new_post_id)){
[102] Fix | Delete
// apply hook to duplicate action
[103] Fix | Delete
do_action( 'themify_builder_duplicate', $new_post_id, $post );
[104] Fix | Delete
[105] Fix | Delete
delete_post_meta( $new_post_id, '_themify_builder_dp_original' );
[106] Fix | Delete
add_post_meta( $new_post_id, '_themify_builder_dp_original', $post->ID );
[107] Fix | Delete
[108] Fix | Delete
// If the copy is published or scheduled, we have to set a proper slug.
[109] Fix | Delete
if ( $new_post_status === 'publish' || $new_post_status === 'future' ) {
[110] Fix | Delete
$post_name = wp_unique_post_slug( $post->post_name, $new_post_id, $new_post_status, $post->post_type, $new_post_parent );
[111] Fix | Delete
$new_post = array();
[112] Fix | Delete
$new_post['ID'] = $new_post_id;
[113] Fix | Delete
$new_post['post_name'] = $post_name;
[114] Fix | Delete
[115] Fix | Delete
// Update the post into the database
[116] Fix | Delete
$new_post_id=wp_update_post( $new_post );
[117] Fix | Delete
if(is_wp_error($new_post_id)){
[118] Fix | Delete
$new_post_id=$new_post_id->get_error_message();
[119] Fix | Delete
}
[120] Fix | Delete
}
[121] Fix | Delete
}
[122] Fix | Delete
elseif(is_wp_error($new_post_id)){
[123] Fix | Delete
$new_post_id=$new_post_id->get_error_message();
[124] Fix | Delete
}
[125] Fix | Delete
return $new_post_id;
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
/**
[129] Fix | Delete
* Duplicate custom fields / post meta.
[130] Fix | Delete
*
[131] Fix | Delete
* @access public
[132] Fix | Delete
* @param int $new_id
[133] Fix | Delete
* @param object $post
[134] Fix | Delete
*/
[135] Fix | Delete
private static function duplicate_postmeta( $new_id, $post ) {
[136] Fix | Delete
$meta_keys = get_post_custom_keys( $post->ID );
[137] Fix | Delete
if ( empty( $meta_keys ) ){
[138] Fix | Delete
return;
[139] Fix | Delete
}
[140] Fix | Delete
foreach ( $meta_keys as $meta_key ) {
[141] Fix | Delete
if( $meta_key === '_themify_builder_settings_json' ) {
[142] Fix | Delete
$builder_data =ThemifyBuilder_Data_Manager::get_data( $post->ID ); // get builder data from original post
[143] Fix | Delete
Themify_Builder_Model::removeElementIds($builder_data);
[144] Fix | Delete
ThemifyBuilder_Data_Manager::save_data( $builder_data, $new_id ); // save the data for the new post
[145] Fix | Delete
}
[146] Fix | Delete
elseif (!self::exclude_postmeta( $meta_key ) ) {
[147] Fix | Delete
$meta_values = get_post_custom_values( $meta_key, $post->ID );
[148] Fix | Delete
foreach ( $meta_values as $meta_value ) {
[149] Fix | Delete
$meta_value = maybe_unserialize( $meta_value );
[150] Fix | Delete
update_post_meta( $new_id, $meta_key, $meta_value );
[151] Fix | Delete
}
[152] Fix | Delete
}
[153] Fix | Delete
}
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
/**
[157] Fix | Delete
* Check if a custom field must NOT be copied to duplicated post
[158] Fix | Delete
*
[159] Fix | Delete
* @return bool
[160] Fix | Delete
*/
[161] Fix | Delete
private static function exclude_postmeta(string $meta_key ) {
[162] Fix | Delete
/*oEmbed cache data or WP post edit*/
[163] Fix | Delete
return substr( $meta_key, 0, 7 ) === '_oembed' || in_array( $meta_key, array( '_edit_last', '_edit_lock' ),true) ;
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
/**
[167] Fix | Delete
* Duplicate categories and custom taxonomies
[168] Fix | Delete
*
[169] Fix | Delete
* @access public
[170] Fix | Delete
* @param int $new_id
[171] Fix | Delete
* @param object $post
[172] Fix | Delete
*/
[173] Fix | Delete
private static function duplicate_taxonomies( $new_id, $post ) {
[174] Fix | Delete
global $wpdb;
[175] Fix | Delete
if ( isset( $wpdb->terms ) ) {
[176] Fix | Delete
// Clear default category (added by wp_insert_post)
[177] Fix | Delete
wp_set_object_terms( $new_id, NULL, 'category' );
[178] Fix | Delete
[179] Fix | Delete
$taxonomies = get_object_taxonomies( $post->post_type );
[180] Fix | Delete
foreach ( $taxonomies as $taxonomy ) {
[181] Fix | Delete
$post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'orderby' => 'term_order' ) );
[182] Fix | Delete
$terms = array();
[183] Fix | Delete
$terms_count = count( $post_terms );
[184] Fix | Delete
for ( $i=0; $i < $terms_count; ++$i ) {
[185] Fix | Delete
$terms[] = $post_terms[ $i ]->slug;
[186] Fix | Delete
}
[187] Fix | Delete
wp_set_object_terms( $new_id, $terms, $taxonomy );
[188] Fix | Delete
}
[189] Fix | Delete
}
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
/**
[193] Fix | Delete
* Duplicate attachment data entries
[194] Fix | Delete
*
[195] Fix | Delete
* @access public
[196] Fix | Delete
* Actual files does not copied
[197] Fix | Delete
* @param int $new_id
[198] Fix | Delete
* @param object $post
[199] Fix | Delete
*/
[200] Fix | Delete
private static function duplicate_attachment( $new_id, $post ) {
[201] Fix | Delete
// get children
[202] Fix | Delete
$children = get_posts(
[203] Fix | Delete
array( 'post_type' =>get_post_types(),
[204] Fix | Delete
'numberposts' => -1,
[205] Fix | Delete
'post_status' => 'any',
[206] Fix | Delete
'post_parent' => $post->ID,
[207] Fix | Delete
'ignore_sticky_posts'=>true,
[208] Fix | Delete
'no_found_rows'=>true,
[209] Fix | Delete
'cache_results'=>false) );
[210] Fix | Delete
// clone old attachments
[211] Fix | Delete
foreach ( $children as $child ) {
[212] Fix | Delete
if ( $child->post_type !== 'attachment' && $child->post_type!==$post->post_type){
[213] Fix | Delete
self::duplicate( $child, '', $new_id );
[214] Fix | Delete
}
[215] Fix | Delete
}
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
public static function duplicate_data($new_id, $post ){
[219] Fix | Delete
self::duplicate_postmeta($new_id, $post);
[220] Fix | Delete
self::duplicate_taxonomies($new_id, $post);
[221] Fix | Delete
self::duplicate_attachment($new_id, $post);
[222] Fix | Delete
}
[223] Fix | Delete
}
[224] Fix | Delete
[225] Fix | Delete
Themify_Builder_Duplicate_Page::init();
[226] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function