Last active
October 15, 2018 15:08
-
-
Save wpmudev-sls/7b90b1508b25ea829bb4b6beaa18ca44 to your computer and use it in GitHub Desktop.
[Cloner] - Fix for Themeco Pro theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'wpmudev_copier-copied-posts', function( $source_blog_id, $posts_mapping, $user_id, $template, $type ){ | |
global $wpdb; | |
$meta_keys = array( '_cornerstone_data', '_cs_template_data' ); | |
$meta_keys_q = ""; | |
$meta_keys_q = $type_str = implode( | |
" || ", | |
array_map( | |
function( $s ) { | |
return "m.meta_key = '" . $s . "'"; | |
}, $meta_keys | |
) | |
); | |
if ( is_array( $type ) ) { | |
$type_str = implode( | |
",", | |
array_map( | |
function( $s ) { | |
return '"' . $s . '"'; | |
}, $type | |
) | |
); | |
$type_query = "p.post_type IN ({$type_str})"; | |
} | |
else{ | |
$type_query = "p.post_type='{$type}'"; | |
} | |
$query = "SELECT ID FROM {$wpdb->posts} as p | |
LEFT JOIN {$wpdb->postmeta} as m | |
ON p.ID=m.post_id | |
WHERE {$type_query} AND m.meta_key = '_cornerstone_data'"; | |
$posts = $wpdb->get_results( $query ); | |
if ( empty( $posts ) ) { | |
return; | |
} | |
foreach ( $posts as $post ) { | |
$parent_id = array_search ( $post->ID, $posts_mapping ); | |
$meta_keys = array( '_cornerstone_data', '_cs_template_data' ); | |
if ( $parent_id ) { | |
foreach ( $meta_keys as $meta_key ) { | |
switch_to_blog( $source_blog_id ); | |
$source_meta = get_post_meta( $parent_id , $meta_key, true ); | |
restore_current_blog(); | |
if ( ! empty( $source_meta ) ) { | |
update_post_meta( $post->ID, $meta_key, addslashes( $source_meta ) ); | |
} | |
} | |
/*switch_to_blog( $source_blog_id ); | |
$source_meta = get_post_meta( $parent_id , '_cornerstone_data', true ); | |
restore_current_blog(); | |
if ( ! empty( $source_meta ) ) { | |
update_post_meta( $post->ID, '_cornerstone_data', addslashes( $source_meta ) ); | |
}*/ | |
} | |
} | |
}, 20, 5 ); | |
add_filter( 'wpmudev_copier_get_source_posts_args', function( $args ){ | |
$args['post_status'][] = 'tco-data'; | |
return $args; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment