• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / duplicate-post / 21545921988

31 Jan 2026 02:28PM UTC coverage: 49.883% (-0.04%) from 49.922%
21545921988

Pull #449

github

web-flow
Merge d42dda939 into 70cd21894
Pull Request #449: Replace `dp_` prefix with `duplicate_post_`

0 of 18 new or added lines in 2 files covered. (0.0%)

1 existing line in 1 file now uncovered.

1278 of 2562 relevant lines covered (49.88%)

3.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/compat/wpml-functions.php
1
<?php
2
/**
3
 * WPML compatibility functions
4
 *
5
 * @global array $duplicated_posts Array to store the posts being duplicated.
6
 *
7
 * @package Yoast\WP\Duplicate_Post
8
 * @since   3.2
9
 */
10

11
add_action( 'admin_init', 'duplicate_post_wpml_init' );
×
12

13
/**
14
 * Add handlers for WPML compatibility.
15
 *
16
 * @return void
17
 */
18
function duplicate_post_wpml_init() {
19
        if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
×
NEW
20
                add_action( 'duplicate_post_duplicate_page', 'duplicate_post_wpml_copy_translations', 10, 3 );
×
NEW
21
                add_action( 'duplicate_post_duplicate_post', 'duplicate_post_wpml_copy_translations', 10, 3 );
×
UNCOV
22
                add_action( 'shutdown', 'duplicate_wpml_string_packages', 11 );
×
23
        }
24
}
25

26
global $duplicated_posts;
×
27

28
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals -- Reason: Renaming a global variable is a BC break.
29
$duplicated_posts = [];
×
30

31
/**
32
 * Copy post translations.
33
 *
34
 * @global SitePress $sitepress        Instance of the Main WPML class.
35
 * @global array     $duplicated_posts Array of duplicated posts.
36
 *
37
 * @param int     $post_id ID of the copy.
38
 * @param WP_Post $post    Original post object.
39
 * @param string  $status  Status of the new post.
40
 *
41
 * @return void
42
 */
43
function duplicate_post_wpml_copy_translations( $post_id, $post, $status = '' ) {
44
        global $sitepress;
×
45
        global $duplicated_posts;
×
46

NEW
47
        remove_action( 'duplicate_post_duplicate_page', 'duplicate_post_wpml_copy_translations', 10 );
×
NEW
48
        remove_action( 'duplicate_post_duplicate_post', 'duplicate_post_wpml_copy_translations', 10 );
×
49

50
        $current_language = $sitepress->get_current_language();
×
51
        $trid             = $sitepress->get_element_trid( $post->ID );
×
52
        if ( ! empty( $trid ) ) {
×
53
                $translations = $sitepress->get_element_translations( $trid );
×
54
                $new_trid     = $sitepress->get_element_trid( $post_id );
×
55
                foreach ( $translations as $code => $details ) {
×
56
                        if ( $code !== $current_language ) {
×
57
                                if ( $details->element_id ) {
×
58
                                        $translation = get_post( $details->element_id );
×
59
                                        if ( ! $translation ) {
×
60
                                                continue;
×
61
                                        }
62
                                        $new_post_id = duplicate_post_create_duplicate( $translation, $status );
×
63
                                        if ( ! is_wp_error( $new_post_id ) ) {
×
64
                                                $sitepress->set_element_language_details(
×
65
                                                        $new_post_id,
×
66
                                                        'post_' . $translation->post_type,
×
67
                                                        $new_trid,
×
68
                                                        $code,
×
69
                                                        $current_language
×
70
                                                );
×
71
                                        }
72
                                }
73
                        }
74
                }
75

76
                // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals -- Reason: see above.
77
                $duplicated_posts[ $post->ID ] = $post_id;
×
78
        }
79
}
80

81
/**
82
 * Duplicate string packages.
83
 *
84
 * @global array() $duplicated_posts Array of duplicated posts.
85
 *
86
 * @return void
87
 */
88
function duplicate_wpml_string_packages() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals -- Reason: renaming the function would be a BC-break.
89
        global $duplicated_posts;
×
90

91
        foreach ( $duplicated_posts as $original_post_id => $duplicate_post_id ) {
×
92
                // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals -- Reason: using WPML native filter.
93
                $original_string_packages = apply_filters( 'wpml_st_get_post_string_packages', false, $original_post_id );
×
94

95
                // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals -- Reason: using WPML native filter.
96
                $new_string_packages = apply_filters( 'wpml_st_get_post_string_packages', false, $duplicate_post_id );
×
97

98
                if ( is_array( $original_string_packages ) ) {
×
99
                        foreach ( $original_string_packages as $original_string_package ) {
×
100
                                $translated_original_strings = $original_string_package->get_translated_strings( [] );
×
101

102
                                foreach ( $new_string_packages as $new_string_package ) {
×
103
                                        $cache = new WPML_WP_Cache( 'WPML_Package' );
×
104
                                        $cache->flush_group_cache();
×
105
                                        $new_strings = $new_string_package->get_package_strings();
×
106
                                        foreach ( $new_strings as $new_string ) {
×
107

108
                                                if ( isset( $translated_original_strings[ $new_string->name ] ) ) {
×
109
                                                        foreach ( $translated_original_strings[ $new_string->name ] as $language => $translated_string ) {
×
110

111
                                                                do_action(
×
112
                                                                        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals -- Reason: using WPML native filter.
113
                                                                        'wpml_add_string_translation',
×
114
                                                                        $new_string->id,
×
115
                                                                        $language,
×
116
                                                                        $translated_string['value'],
×
117
                                                                        $translated_string['status']
×
118
                                                                );
×
119
                                                        }
120
                                                }
121
                                        }
122
                                }
123
                        }
124
                }
125
        }
126
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc