-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Leandro Bosaipo
committed
Aug 19, 2019
1 parent
bfc7b15
commit 54a3a25
Showing
10 changed files
with
2,140 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
add_action( 'admin_init', 'duplicate_post_jetpack_init' ); | ||
|
||
|
||
function duplicate_post_jetpack_init() { | ||
add_filter('duplicate_post_blacklist_filter', 'duplicate_post_jetpack_add_to_blacklist', 10, 1 ); | ||
|
||
if (class_exists('WPCom_Markdown')){ | ||
add_action('duplicate_post_pre_copy', 'duplicate_post_jetpack_disable_markdown', 10); | ||
add_action('duplicate_post_post_copy', 'duplicate_post_jetpack_enable_markdown', 10); | ||
} | ||
} | ||
|
||
function duplicate_post_jetpack_add_to_blacklist($meta_blacklist) { | ||
$meta_blacklist[] = '_wpas*'; //Jetpack Publicize | ||
$meta_blacklist[] = '_publicize*'; //Jetpack Publicize | ||
|
||
$meta_blacklist[] = '_jetpack*'; //Jetpack Subscriptions etc. | ||
|
||
return $meta_blacklist; | ||
} | ||
|
||
// Markdown | ||
function duplicate_post_jetpack_disable_markdown(){ | ||
WPCom_Markdown::get_instance()->unload_markdown_for_posts(); | ||
} | ||
|
||
function duplicate_post_jetpack_enable_markdown(){ | ||
WPCom_Markdown::get_instance()->load_markdown_for_posts(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
add_action( 'admin_init', 'duplicate_post_wpml_init' ); | ||
|
||
function duplicate_post_wpml_init() { | ||
if ( defined( 'ICL_SITEPRESS_VERSION' ) ) { | ||
add_action('dp_duplicate_page', 'duplicate_post_wpml_copy_translations', 10, 3); | ||
add_action('dp_duplicate_post', 'duplicate_post_wpml_copy_translations', 10, 3); | ||
add_action('shutdown', 'duplicate_wpml_string_packages', 11 ); | ||
} | ||
} | ||
|
||
global $duplicated_posts; | ||
$duplicated_posts = array(); | ||
|
||
function duplicate_post_wpml_copy_translations($post_id, $post, $status = '') { | ||
global $sitepress; | ||
global $duplicated_posts; | ||
|
||
remove_action('dp_duplicate_page', 'duplicate_post_wpml_copy_translations', 10); | ||
remove_action('dp_duplicate_post', 'duplicate_post_wpml_copy_translations', 10); | ||
|
||
$current_language = $sitepress->get_current_language(); | ||
$trid = $sitepress->get_element_trid($post->ID); | ||
if (!empty($trid)) { | ||
$translations = $sitepress->get_element_translations($trid); | ||
$new_trid = $sitepress->get_element_trid($post_id); | ||
foreach ($translations as $code => $details) { | ||
if ($code != $current_language) { | ||
if ( $details->element_id ) { | ||
$translation = get_post( $details->element_id ); | ||
if (!$translation) continue; | ||
$new_post_id = duplicate_post_create_duplicate( $translation, $status ); | ||
$sitepress->set_element_language_details( $new_post_id, 'post_' . $translation->post_type, $new_trid, $code, $current_language ); | ||
} | ||
} | ||
} | ||
$duplicated_posts[ $post->ID ] = $post_id; | ||
} | ||
} | ||
|
||
function duplicate_wpml_string_packages() { | ||
global $duplicated_posts; | ||
|
||
foreach ( $duplicated_posts as $original_post_id => $duplicate_post_id ) { | ||
|
||
$original_string_packages = apply_filters( 'wpml_st_get_post_string_packages', false, $original_post_id ); | ||
$new_string_packages = apply_filters( 'wpml_st_get_post_string_packages', false, $duplicate_post_id ); | ||
if ( is_array( $original_string_packages ) ) { | ||
foreach ( $original_string_packages as $original_string_package ) { | ||
$translated_original_strings = $original_string_package->get_translated_strings( array() ); | ||
|
||
foreach ( $new_string_packages as $new_string_package ) { | ||
$cache = new WPML_WP_Cache( 'WPML_Package' ); | ||
$cache->flush_group_cache(); | ||
$new_strings = $new_string_package->get_package_strings(); | ||
foreach ( $new_strings as $new_string ) { | ||
|
||
if ( isset( $translated_original_strings[ $new_string->name ] ) ) { | ||
foreach ( $translated_original_strings[ $new_string->name ] as $language => $translated_string ) { | ||
|
||
do_action( | ||
'wpml_add_string_translation', | ||
$new_string->id, | ||
$language, | ||
$translated_string['value'], | ||
$translated_string['status'] | ||
); | ||
|
||
} | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
?> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.