C:\xampp\htdocs\landing\wp-content\updraft\plugins-old\duplicate-post\src\class-utils.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php
/**
 * Utility methods for Duplicate Post.
 *
 * @package Duplicate_Post
 * @since 4.0
 */

namespace Yoast\WP\Duplicate_Post;

/**
 * Represents the Utils class.
 */
class Utils {

    
/**
     * Flattens a version number for use in a filename.
     *
     * @param string $version The original version number.
     *
     * @return string The flattened version number.
     */
    
public static function flatten_version$version ) {
        
$parts = \explode'.'$version );

        if ( \
count$parts ) === && \preg_match'/^\d+$/'$parts[1] ) === ) {
            
$parts[] = '0';
        }

        return \
implode''$parts );
    }

    
/**
     * Adds slashes only to strings.
     *
     * @param mixed $value Value to slash only if string.
     *
     * @return string|mixed
     */
    
public static function addslashes_to_strings_only$value ) {
        return \
is_string$value ) ? \addslashes$value ) : $value;
    }

    
/**
     * Replaces faulty core wp_slash().
     *
     * Until WP 5.5 wp_slash() recursively added slashes not just to strings in array/objects, leading to errors.
     *
     * @param mixed $value What to add slashes to.
     *
     * @return mixed
     */
    
public static function recursively_slash_strings$value ) {
        return \
map_deep$value, [ self::class, 'addslashes_to_strings_only' ] );
    }

    
/**
     * Gets the original post.
     *
     * @param int|\WP_Post|null $post   Optional. Post ID or Post object.
     * @param string            $output Optional, default is Object. Either OBJECT, ARRAY_A, or ARRAY_N.
     *
     * @return \WP_Post|null Post data if successful, null otherwise.
     */
    
public static function get_original$post null$output = \OBJECT ) {
        
$post = \get_post$post );
        if ( ! 
$post ) {
            return 
null;
        }

        
$original_id self::get_original_post_id$post->ID );

        if ( empty( 
$original_id ) ) {
            return 
null;
        }

        return \
get_post$original_id$output );
    }

    
/**
     * Determines if the post has ancestors marked for copy.
     *
     * If we are copying children, and the post has already an ancestor marked for copy, we have to filter it out.
     *
     * @param \WP_Post $post     The post object.
     * @param array    $post_ids The array of marked post IDs.
     *
     * @return bool Whether the post has ancestors marked for copy.
     */
    
public static function has_ancestors_marked$post$post_ids ) {
        
$ancestors_in_array 0;
        
$parent             = \wp_get_post_parent_id$post->ID );
        while ( 
$parent ) {
            if ( \
in_array$parent$post_idstrue ) ) {
                
$ancestors_in_array++;
            }
            
$parent = \wp_get_post_parent_id$parent );
        }
        return ( 
$ancestors_in_array !== );
    }

    
/**
     * Returns a link to edit, preview or view a post, in accordance to user capabilities.
     *
     * @param \WP_Post $post Post ID or Post object.
     *
     * @return string|null The link to edit, preview or view a post.
     */
    
public static function get_edit_or_view_link$post ) {
        
$post = \get_post$post );
        if ( ! 
$post ) {
            return 
null;
        }

        
$can_edit_post    = \current_user_can'edit_post'$post->ID );
        
$title            = \_draft_or_post_title$post );
        
$post_type_object = \get_post_type_object$post->post_type );

        if ( 
$can_edit_post && $post->post_status !== 'trash' ) {
            return \
sprintf(
                
'<a href="%s" aria-label="%s">%s</a>',
                \
get_edit_post_link$post->ID ),
                
/* translators: %s: post title */
                
\esc_attr( \sprintf( \__'Edit &#8220;%s&#8221;''default' ), $title ) ),
                
$title
            
);
        } elseif ( \
is_post_type_viewable$post_type_object ) ) {
            if ( \
in_array$post->post_status, [ 'pending''draft''future' ], true ) ) {
                if ( 
$can_edit_post ) {
                    
$preview_link = \get_preview_post_link$post );
                    return \
sprintf(
                        
'<a href="%s" rel="bookmark" aria-label="%s">%s</a>',
                        \
esc_url$preview_link ),
                        
/* translators: %s: post title */
                        
\esc_attr( \sprintf( \__'Preview &#8220;%s&#8221;''default' ), $title ) ),
                        
$title
                    
);
                }
            } elseif ( 
$post->post_status !== 'trash' ) {
                return \
sprintf(
                    
'<a href="%s" rel="bookmark" aria-label="%s">%s</a>',
                    \
get_permalink$post->ID ),
                    
/* translators: %s: post title */
                    
\esc_attr( \sprintf( \__'View &#8220;%s&#8221;''default' ), $title ) ),
                    
$title
                
);
            }
        }
        return 
$title;
    }

    
/**
     * Gets the ID of the original post intended to be rewritten with the copy for Rewrite & Republish.
     *
     * @param int $post_id The copy post ID.
     *
     * @return int The original post id of a copy for Rewrite & Republish.
     */
    
public static function get_original_post_id$post_id ) {
        return (int) \
get_post_meta$post_id'_dp_original'true );
    }

    
/**
     * Gets the registered WordPress roles.
     *
     * @return array The roles.
     * @codeCoverageIgnore As this is a simple wrapper method for a built-in WordPress method, we don't have to test it.
     */
    
public static function get_roles() {
        global 
$wp_roles;

        return 
$wp_roles->get_names();
    }

    
/**
     * Gets the default meta field names to be filtered out.
     *
     * @return array The names of the meta fields to filter out by default.
     */
    
public static function get_default_filtered_meta_names() {
        return [
            
'_edit_lock',
            
'_edit_last',
            
'_dp_original',
            
'_dp_is_rewrite_republish_copy',
            
'_dp_has_rewrite_republish_copy',
            
'_dp_has_been_republished',
            
'_dp_creation_date_gmt',
        ];
    }

    
/**
     * Gets a Duplicate Post option from the database.
     *
     * @param string $option The option to get.
     * @param string $key    The key to retrieve, if the option is an array.
     *
     * @return mixed The option.
     */
    
public static function get_option$option$key '' ) {
        
$option = \get_option$option );

        if ( ! \
is_array$option ) || empty( $key ) ) {
            return 
$option;
        }

        if ( ! \
array_key_exists$key$option ) ) {
            return 
'';
        }

        return 
$option$key ];
    }

    
/**
     * Determines if a plugin is active.
     *
     * We can't use is_plugin_active because this must work on the frontend too.
     *
     * @param string $plugin Path to the plugin file relative to the plugins directory.
     *
     * @return bool Whether a plugin is currently active.
     */
    
public static function is_plugin_active$plugin ) {
        if ( \
in_array$plugin, (array) \get_option'active_plugins', [] ), true ) ) {
            return 
true;
        }

        if ( ! \
is_multisite() ) {
            return 
false;
        }

        
$plugins = \get_site_option'active_sitewide_plugins' );
        return isset( 
$plugins$plugin ] );
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586