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

Yoast / duplicate-post / 21727572250

05 Feb 2026 08:36PM UTC coverage: 58.14% (+0.02%) from 58.118%
21727572250

Pull #453

github

web-flow
Merge 52b84513e into dbdc515e8
Pull Request #453: Update to YoastCS 3.3.0

66 of 118 new or added lines in 29 files covered. (55.93%)

4 existing lines in 2 files now uncovered.

1532 of 2635 relevant lines covered (58.14%)

7.44 hits per line

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

0.0
/common-functions.php
1
<?php
2
/**
3
 * Common functions.
4
 *
5
 * @package Yoast\WP\Duplicate_Post
6
 * @since   2.0
7
 */
8

9
use Yoast\WP\Duplicate_Post\Permissions_Helper;
10
use Yoast\WP\Duplicate_Post\UI\Link_Builder;
11
use Yoast\WP\Duplicate_Post\Utils;
12

13
/**
14
 * Tests if post type is enabled to be copied.
15
 *
16
 * @param string $post_type The post type to check.
17
 * @return bool
18
 */
19
function duplicate_post_is_post_type_enabled( $post_type ) {
20
        $duplicate_post_types_enabled = get_option( 'duplicate_post_types_enabled', [ 'post', 'page' ] );
×
21
        if ( ! is_array( $duplicate_post_types_enabled ) ) {
×
22
                $duplicate_post_types_enabled = [ $duplicate_post_types_enabled ];
×
23
        }
24

25
        /** This filter is documented in src/permissions-helper.php */
26
        $duplicate_post_types_enabled = apply_filters( 'duplicate_post_enabled_post_types', $duplicate_post_types_enabled );
×
27
        return in_array( $post_type, $duplicate_post_types_enabled, true );
×
28
}
29

30
/**
31
 * Template tag to retrieve/display duplicate post link for post.
32
 *
33
 * @param int    $id      Optional. Post ID.
34
 * @param string $context Optional, default to display. How to write the '&', defaults to '&amp;'.
35
 * @param bool   $draft   Optional, default to true.
36
 * @return string
37
 */
38
function duplicate_post_get_clone_post_link( $id = 0, $context = 'display', $draft = true ) {
39
        $post = get_post( $id );
×
40
        if ( ! $post ) {
×
41
                return '';
×
42
        }
43

44
        $link_builder       = new Link_Builder();
×
45
        $permissions_helper = new Permissions_Helper();
×
46

47
        if ( ! $permissions_helper->should_links_be_displayed( $post ) ) {
×
48
                return '';
×
49
        }
50

51
        if ( $draft ) {
×
52
                return $link_builder->build_new_draft_link( $post, $context );
×
53
        }
54
        else {
55
                return $link_builder->build_clone_link( $post, $context );
×
56
        }
57
}
58

59
/**
60
 * Displays duplicate post link for post.
61
 *
62
 * @param string|null $link   Optional. Anchor text.
63
 * @param string      $before Optional. Display before edit link.
64
 * @param string      $after  Optional. Display after edit link.
65
 * @param int         $id     Optional. Post ID.
66
 *
67
 * @return void
68
 */
69
function duplicate_post_clone_post_link( $link = null, $before = '', $after = '', $id = 0 ) {
70
        $post = get_post( $id );
×
71
        if ( ! $post ) {
×
72
                return;
×
73
        }
74

75
        $url = duplicate_post_get_clone_post_link( $post->ID );
×
76
        if ( ! $url ) {
×
77
                return;
×
78
        }
79

NEW
80
        $link ??= __( 'Copy to a new draft', 'duplicate-post' );
×
NEW
81
        $link   = '<a class="post-clone-link" href="' . esc_url( $url ) . '">' . esc_html( $link ) . '</a>';
×
82

83
        /**
84
         * Filter on the clone link HTML.
85
         *
86
         * @param string $link The full HTML tag of the link.
87
         * @param int    $ID   The ID of the post.
88
         *
89
         * @return string
90
         */
91
        echo $before . apply_filters( 'duplicate_post_clone_post_link', $link, $post->ID ) . $after; // phpcs:ignore WordPress.Security.EscapeOutput
×
92
}
93

94
/**
95
 * Gets the original post.
96
 *
97
 * @param int|null $post   Optional. Post ID or Post object.
98
 * @param string   $output Optional, default is Object. Either OBJECT, ARRAY_A, or ARRAY_N.
99
 * @return mixed Post data.
100
 */
101
function duplicate_post_get_original( $post = null, $output = OBJECT ) {
102
        return Utils::get_original( $post, $output );
×
103
}
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