Version Description
- Sanitization and validation updates
- Settings page optimization
Download this release
Release Info
Developer | metaphorcreations |
Plugin | Post Duplicator |
Version | 2.27 |
Comparing to | |
See all releases |
Code changes from version 2.26 to 2.27
- includes/ajax.php +19 -19
- includes/edit.php +2 -2
- includes/helpers.php +2 -2
- includes/notices.php +3 -3
- includes/settings.php +36 -41
- m4c-postduplicator.php +3 -4
- metaboxer/metaboxer.php +26 -38
- readme.txt +6 -2
includes/ajax.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
|
3 |
/* --------------------------------------------------------- */
|
4 |
-
/* !Duplicate the post - 2.
|
5 |
/* --------------------------------------------------------- */
|
6 |
|
7 |
function mtphr_duplicate_post( $original_id, $args=array(), $do_action=true ) {
|
@@ -16,18 +16,18 @@ function mtphr_duplicate_post( $original_id, $args=array(), $do_action=true ) {
|
|
16 |
$settings = wp_parse_args( $args, $global_settings );
|
17 |
|
18 |
// Modify some of the elements
|
19 |
-
$appended = isset( $settings['title'] ) ? $settings['title'] : esc_html__( 'Copy', 'post-duplicator' );
|
20 |
-
$duplicate['post_title'] = $duplicate['post_title'] . ' ' . $appended;
|
21 |
$duplicate['post_name'] = sanitize_title( $duplicate['post_name'] . '-' . $settings['slug'] );
|
22 |
|
23 |
// Set the status
|
24 |
if( $settings['status'] != 'same' ) {
|
25 |
-
$duplicate['post_status'] = $settings['status'];
|
26 |
}
|
27 |
|
28 |
// Set the type
|
29 |
if( $settings['type'] != 'same' ) {
|
30 |
-
$duplicate['post_type'] = $settings['type'];
|
31 |
}
|
32 |
|
33 |
// Set the post date
|
@@ -57,7 +57,7 @@ function mtphr_duplicate_post( $original_id, $args=array(), $do_action=true ) {
|
|
57 |
unset( $duplicate['guid'] );
|
58 |
unset( $duplicate['comment_count'] );
|
59 |
|
60 |
-
$duplicate['post_content'] = str_replace( array( '\r\n', '\r', '\n' ), '<br />', $duplicate['post_content'] ); //Handles guttenburg escaping in returns for blocks
|
61 |
|
62 |
// Insert the post into the database
|
63 |
$duplicate_id = wp_insert_post( $duplicate );
|
@@ -68,16 +68,16 @@ function mtphr_duplicate_post( $original_id, $args=array(), $do_action=true ) {
|
|
68 |
$terms = wp_get_post_terms( $original_id, $taxonomy, array('fields' => 'names') );
|
69 |
wp_set_object_terms( $duplicate_id, $terms, $taxonomy );
|
70 |
}
|
71 |
-
|
72 |
-
|
73 |
$custom_fields = get_post_custom( $original_id );
|
74 |
-
|
75 |
-
|
76 |
foreach( $value as $i=>$v ) {
|
77 |
$data = array(
|
78 |
-
'post_id' => $duplicate_id,
|
79 |
-
'meta_key' => $key,
|
80 |
-
'meta_value' => $v,
|
81 |
);
|
82 |
$formats = array(
|
83 |
'%d',
|
@@ -87,12 +87,12 @@ function mtphr_duplicate_post( $original_id, $args=array(), $do_action=true ) {
|
|
87 |
$result = $wpdb->insert( $wpdb->prefix.'postmeta', $data, $formats );
|
88 |
}
|
89 |
}
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
|
97 |
return $duplicate_id;
|
98 |
}
|
1 |
<?php
|
2 |
|
3 |
/* --------------------------------------------------------- */
|
4 |
+
/* !Duplicate the post - 2.27 */
|
5 |
/* --------------------------------------------------------- */
|
6 |
|
7 |
function mtphr_duplicate_post( $original_id, $args=array(), $do_action=true ) {
|
16 |
$settings = wp_parse_args( $args, $global_settings );
|
17 |
|
18 |
// Modify some of the elements
|
19 |
+
$appended = isset( $settings['title'] ) ? sanitize_text_field( $settings['title'] ) : esc_html__( 'Copy', 'post-duplicator' );
|
20 |
+
$duplicate['post_title'] = wp_kses_post( $duplicate['post_title'] ) . ' ' . $appended;
|
21 |
$duplicate['post_name'] = sanitize_title( $duplicate['post_name'] . '-' . $settings['slug'] );
|
22 |
|
23 |
// Set the status
|
24 |
if( $settings['status'] != 'same' ) {
|
25 |
+
$duplicate['post_status'] = sanitize_text_field( $settings['status'] );
|
26 |
}
|
27 |
|
28 |
// Set the type
|
29 |
if( $settings['type'] != 'same' ) {
|
30 |
+
$duplicate['post_type'] = sanitize_text_field( $settings['type'] );
|
31 |
}
|
32 |
|
33 |
// Set the post date
|
57 |
unset( $duplicate['guid'] );
|
58 |
unset( $duplicate['comment_count'] );
|
59 |
|
60 |
+
$duplicate['post_content'] = str_replace( array( '\r\n', '\r', '\n' ), '<br />', wp_kses_post( $duplicate['post_content'] ) ); //Handles guttenburg escaping in returns for blocks
|
61 |
|
62 |
// Insert the post into the database
|
63 |
$duplicate_id = wp_insert_post( $duplicate );
|
68 |
$terms = wp_get_post_terms( $original_id, $taxonomy, array('fields' => 'names') );
|
69 |
wp_set_object_terms( $duplicate_id, $terms, $taxonomy );
|
70 |
}
|
71 |
+
|
72 |
+
// Duplicate all the custom fields
|
73 |
$custom_fields = get_post_custom( $original_id );
|
74 |
+
foreach ( $custom_fields as $key => $value ) {
|
75 |
+
if( is_array($value) && count($value) > 0 ) {
|
76 |
foreach( $value as $i=>$v ) {
|
77 |
$data = array(
|
78 |
+
'post_id' => intval( $duplicate_id ),
|
79 |
+
'meta_key' => sanitize_text_field( $key ),
|
80 |
+
'meta_value' => wp_kses_post( $v ),
|
81 |
);
|
82 |
$formats = array(
|
83 |
'%d',
|
87 |
$result = $wpdb->insert( $wpdb->prefix.'postmeta', $data, $formats );
|
88 |
}
|
89 |
}
|
90 |
+
}
|
91 |
+
|
92 |
+
// Add an action for others to do custom stuff
|
93 |
+
if( $do_action ) {
|
94 |
+
do_action( 'mtphr_post_duplicator_created', $original_id, $duplicate_id, $settings );
|
95 |
+
}
|
96 |
|
97 |
return $duplicate_id;
|
98 |
}
|
includes/edit.php
CHANGED
@@ -3,12 +3,12 @@
|
|
3 |
/**
|
4 |
* Add a duplicate post link.
|
5 |
*
|
6 |
-
* @since 2.
|
7 |
*/
|
8 |
function mtphr_post_duplicator_action_row_link( $post ) {
|
9 |
|
10 |
// Do not show on trash page
|
11 |
-
$post_status = isset( $_GET['post_status'] ) ? $_GET['post_status'] : false;
|
12 |
if ( 'trash' == $post_status ) {
|
13 |
return false;
|
14 |
}
|
3 |
/**
|
4 |
* Add a duplicate post link.
|
5 |
*
|
6 |
+
* @since 2.27
|
7 |
*/
|
8 |
function mtphr_post_duplicator_action_row_link( $post ) {
|
9 |
|
10 |
// Do not show on trash page
|
11 |
+
$post_status = isset( $_GET['post_status'] ) ? sanitize_text_field( $_GET['post_status'] ) : false;
|
12 |
if ( 'trash' == $post_status ) {
|
13 |
return false;
|
14 |
}
|
includes/helpers.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
|
3 |
/* --------------------------------------------------------- */
|
4 |
-
/* !Return an array of post types - 2.
|
5 |
/* --------------------------------------------------------- */
|
6 |
|
7 |
if( !function_exists('mtphr_post_duplicator_post_types') ) {
|
@@ -18,7 +18,7 @@ function mtphr_post_duplicator_post_types() {
|
|
18 |
|
19 |
if( is_array($pts) && count($pts) > 0 ) {
|
20 |
foreach( $pts as $i=>$pt ) {
|
21 |
-
$post_types[$i] = $pt->labels->singular_name;
|
22 |
}
|
23 |
}
|
24 |
|
1 |
<?php
|
2 |
|
3 |
/* --------------------------------------------------------- */
|
4 |
+
/* !Return an array of post types - 2.27 */
|
5 |
/* --------------------------------------------------------- */
|
6 |
|
7 |
if( !function_exists('mtphr_post_duplicator_post_types') ) {
|
18 |
|
19 |
if( is_array($pts) && count($pts) > 0 ) {
|
20 |
foreach( $pts as $i=>$pt ) {
|
21 |
+
$post_types[$i] = sanitize_text_field( $pt->labels->singular_name );
|
22 |
}
|
23 |
}
|
24 |
|
includes/notices.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
|
3 |
/* --------------------------------------------------------- */
|
4 |
-
/* !Create an admin notice that a post has been duplicated - 2.
|
5 |
/* --------------------------------------------------------- */
|
6 |
|
7 |
function mtphr_post_duplicator_notice() {
|
@@ -16,8 +16,8 @@ function mtphr_post_duplicator_notice() {
|
|
16 |
$post_type = get_post_type_object( $duplicated_post->post_type );
|
17 |
|
18 |
// Set the button label
|
19 |
-
$pt = $post_type->labels->singular_name;
|
20 |
-
$link = '<a href="'.get_edit_post_link( $duplicated_id ).'">'.esc_html__( 'here', 'post-duplicator' ).'</a>';
|
21 |
$label = sprintf( __( 'Successfully Duplicated! You can edit your new %1$s %2$s.', 'post-duplicator' ), $pt, $link );
|
22 |
|
23 |
?>
|
1 |
<?php
|
2 |
|
3 |
/* --------------------------------------------------------- */
|
4 |
+
/* !Create an admin notice that a post has been duplicated - 2.27 */
|
5 |
/* --------------------------------------------------------- */
|
6 |
|
7 |
function mtphr_post_duplicator_notice() {
|
16 |
$post_type = get_post_type_object( $duplicated_post->post_type );
|
17 |
|
18 |
// Set the button label
|
19 |
+
$pt = sanitize_text_field( $post_type->labels->singular_name );
|
20 |
+
$link = wp_kses_post( '<a href="'.get_edit_post_link( $duplicated_id ).'">'.esc_html__( 'here', 'post-duplicator' ).'</a>' );
|
21 |
$label = sprintf( __( 'Successfully Duplicated! You can edit your new %1$s %2$s.', 'post-duplicator' ), $pt, $link );
|
22 |
|
23 |
?>
|
includes/settings.php
CHANGED
@@ -24,10 +24,12 @@ add_action( 'admin_init', 'mtphr_post_duplicator_initialize_settings' );
|
|
24 |
/**
|
25 |
* Initializes the options page.
|
26 |
*
|
27 |
-
* @since 2.
|
28 |
*/
|
29 |
function mtphr_post_duplicator_initialize_settings() {
|
30 |
|
|
|
|
|
31 |
$settings['post_duplication'] = array(
|
32 |
'title' => esc_html__( 'Post Duplication', 'post-duplicator' ),
|
33 |
'type' => 'radio',
|
@@ -36,7 +38,7 @@ function mtphr_post_duplicator_initialize_settings() {
|
|
36 |
'current_user' => esc_html__('Limit to Current User', 'post-duplicator')
|
37 |
),
|
38 |
'display' => 'inline',
|
39 |
-
'default' => 'all_users'
|
40 |
);
|
41 |
|
42 |
$settings['post_author'] = array(
|
@@ -47,7 +49,7 @@ function mtphr_post_duplicator_initialize_settings() {
|
|
47 |
'original_user' => esc_html__('Original Post Author', 'post-duplicator'),
|
48 |
),
|
49 |
'display' => 'inline',
|
50 |
-
'default' => 'current_user'
|
51 |
);
|
52 |
|
53 |
$settings['status'] = array(
|
@@ -59,14 +61,14 @@ function mtphr_post_duplicator_initialize_settings() {
|
|
59 |
'publish' => esc_html__('Published', 'post-duplicator'),
|
60 |
'pending' => esc_html__('Pending', 'post-duplicator')
|
61 |
),
|
62 |
-
'default' => 'draft'
|
63 |
);
|
64 |
|
65 |
$settings['type'] = array(
|
66 |
'title' => esc_html__( 'Post Type', 'post-duplicator' ),
|
67 |
'type' => 'select',
|
68 |
'options' => mtphr_post_duplicator_post_types(),
|
69 |
-
'default' => 'same'
|
70 |
);
|
71 |
|
72 |
$settings['timestamp'] = array(
|
@@ -77,7 +79,7 @@ function mtphr_post_duplicator_initialize_settings() {
|
|
77 |
'current' => esc_html__('Current Time', 'post-duplicator')
|
78 |
),
|
79 |
'display' => 'inline',
|
80 |
-
'default' => 'current'
|
81 |
);
|
82 |
|
83 |
$settings['title'] = array(
|
@@ -85,7 +87,7 @@ function mtphr_post_duplicator_initialize_settings() {
|
|
85 |
'description' => esc_html__('String that should be appended to the duplicate post\'s title', 'post-duplicator'),
|
86 |
'type' => 'text',
|
87 |
'display' => 'inline',
|
88 |
-
'default' => esc_html__('Copy', 'post-duplicator')
|
89 |
);
|
90 |
|
91 |
$settings['slug'] = array(
|
@@ -93,40 +95,41 @@ function mtphr_post_duplicator_initialize_settings() {
|
|
93 |
'description' => esc_html__('String that should be appended to the duplicate post\'s slug', 'post-duplicator'),
|
94 |
'type' => 'text',
|
95 |
'display' => 'inline',
|
96 |
-
'default' => 'copy'
|
97 |
);
|
98 |
|
99 |
$settings['time_offset'] = array(
|
100 |
'title' => esc_html__( 'Offset Date', 'post-duplicator' ),
|
101 |
'type' => 'checkbox',
|
|
|
102 |
'append' => array(
|
103 |
'time_offset_days' => array(
|
104 |
'type' => 'text',
|
105 |
'size' => 2,
|
106 |
'after' => esc_html__(' days', 'post-duplicator'),
|
107 |
'text_align' => 'right',
|
108 |
-
'default' => 0
|
109 |
),
|
110 |
'time_offset_hours' => array(
|
111 |
'type' => 'text',
|
112 |
'size' => 2,
|
113 |
'after' => esc_html__(' hours', 'post-duplicator'),
|
114 |
'text_align' => 'right',
|
115 |
-
'default' => 0
|
116 |
),
|
117 |
'time_offset_minutes' => array(
|
118 |
'type' => 'text',
|
119 |
'size' => 2,
|
120 |
'after' => esc_html__(' minutes', 'post-duplicator'),
|
121 |
'text_align' => 'right',
|
122 |
-
'default' => 0
|
123 |
),
|
124 |
'time_offset_seconds' => array(
|
125 |
'type' => 'text',
|
126 |
'size' => 2,
|
127 |
'after' => esc_html__(' seconds', 'post-duplicator'),
|
128 |
'text_align' => 'right',
|
129 |
-
'default' => 0
|
130 |
),
|
131 |
'time_offset_direction' => array(
|
132 |
'type' => 'select',
|
@@ -134,7 +137,7 @@ function mtphr_post_duplicator_initialize_settings() {
|
|
134 |
'newer' => esc_html__('newer', 'post-duplicator'),
|
135 |
'older' => esc_html__('older', 'post-duplicator')
|
136 |
),
|
137 |
-
'default' => 'newer'
|
138 |
)
|
139 |
)
|
140 |
);
|
@@ -155,7 +158,6 @@ function mtphr_post_duplicator_initialize_settings() {
|
|
155 |
|
156 |
if( is_array($settings) ) {
|
157 |
foreach( $settings as $id => $setting ) {
|
158 |
-
$setting['option'] = 'mtphr_post_duplicator_settings';
|
159 |
$setting['option_id'] = $id;
|
160 |
$setting['id'] = 'mtphr_post_duplicator_settings['.$id.']';
|
161 |
add_settings_field( $setting['id'], $setting['title'], 'mtphr_post_duplicator_field_display', 'mtphr_post_duplicator_settings', 'mtphr_post_duplicator_settings_section', $setting);
|
@@ -170,23 +172,23 @@ function mtphr_post_duplicator_initialize_settings() {
|
|
170 |
/**
|
171 |
* Sanitize the settings
|
172 |
*
|
173 |
-
* @since 2.
|
174 |
*/
|
175 |
function mtphr_post_duplicator_settings_sanitize( $fields ) {
|
176 |
$sanitized_fields = array(
|
177 |
-
'post_duplication' => isset( $fields['post_duplication'] ) ?
|
178 |
-
'post_author' => isset( $fields['post_author'] ) ?
|
179 |
-
'status' => isset( $fields['status'] ) ?
|
180 |
-
'type' => isset( $fields['type'] ) ?
|
181 |
-
'timestamp' => isset( $fields['timestamp'] ) ?
|
182 |
-
'title' => isset( $fields['title'] ) ? sanitize_text_field( $fields['title'] )
|
183 |
-
'slug' => isset( $fields['slug'] ) ? sanitize_title_with_dashes( $fields['slug'] )
|
184 |
-
'time_offset' => isset( $fields['time_offset'] ) ?
|
185 |
-
'time_offset_days' => isset( $fields['time_offset_days'] ) ? intval( $fields['time_offset_days'] )
|
186 |
-
'time_offset_hours' => isset( $fields['time_offset_hours'] ) ? intval( $fields['time_offset_hours'] )
|
187 |
-
'time_offset_minutes' => isset( $fields['time_offset_minutes'] ) ? intval( $fields['time_offset_minutes'] )
|
188 |
-
'time_offset_seconds' => isset( $fields['time_offset_seconds'] ) ? intval( $fields['time_offset_seconds'] )
|
189 |
-
'time_offset_direction' => isset( $fields['time_offset_direction'] ) ?
|
190 |
);
|
191 |
return $sanitized_fields;
|
192 |
}
|
@@ -236,27 +238,20 @@ function mtphr_post_duplicator_settings_callback() {
|
|
236 |
/**
|
237 |
* The custom field callback.
|
238 |
*
|
239 |
-
* @since
|
240 |
*/
|
241 |
function mtphr_post_duplicator_field_display( $args ) {
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
$options = get_option( $args['option'] );
|
246 |
-
$value = isset( $options[$args['option_id']] ) ? $options[$args['option_id']] : '';
|
247 |
-
} else {
|
248 |
-
$value = get_option( $args['id'] );
|
249 |
-
}
|
250 |
-
if( $value == '' && isset($args['default']) ) {
|
251 |
-
$value = $args['default'];
|
252 |
}
|
253 |
if( isset($args['type']) ) {
|
254 |
|
255 |
echo '<div class="mtphr-post-duplicator-metaboxer-field mtphr-post-duplicator-metaboxer-' . esc_attr( $args['type'] ) . '">';
|
256 |
|
257 |
// Call the function to display the field
|
258 |
-
if ( function_exists('mtphr_post_duplicator_metaboxer_'
|
259 |
-
call_user_func( 'mtphr_post_duplicator_metaboxer_'
|
260 |
}
|
261 |
|
262 |
echo '<div>';
|
24 |
/**
|
25 |
* Initializes the options page.
|
26 |
*
|
27 |
+
* @since 2.17
|
28 |
*/
|
29 |
function mtphr_post_duplicator_initialize_settings() {
|
30 |
|
31 |
+
$options = get_option( 'mtphr_post_duplicator_settings', array() );
|
32 |
+
|
33 |
$settings['post_duplication'] = array(
|
34 |
'title' => esc_html__( 'Post Duplication', 'post-duplicator' ),
|
35 |
'type' => 'radio',
|
38 |
'current_user' => esc_html__('Limit to Current User', 'post-duplicator')
|
39 |
),
|
40 |
'display' => 'inline',
|
41 |
+
'default' => isset( $options['post_duplication'] ) ? sanitize_text_field( $options['post_duplication'] ) : 'all_users'
|
42 |
);
|
43 |
|
44 |
$settings['post_author'] = array(
|
49 |
'original_user' => esc_html__('Original Post Author', 'post-duplicator'),
|
50 |
),
|
51 |
'display' => 'inline',
|
52 |
+
'default' => isset( $options['post_author'] ) ? sanitize_text_field( $options['post_author'] ) : 'current_user'
|
53 |
);
|
54 |
|
55 |
$settings['status'] = array(
|
61 |
'publish' => esc_html__('Published', 'post-duplicator'),
|
62 |
'pending' => esc_html__('Pending', 'post-duplicator')
|
63 |
),
|
64 |
+
'default' => isset( $options['status'] ) ? sanitize_text_field( $options['status'] ) : 'draft'
|
65 |
);
|
66 |
|
67 |
$settings['type'] = array(
|
68 |
'title' => esc_html__( 'Post Type', 'post-duplicator' ),
|
69 |
'type' => 'select',
|
70 |
'options' => mtphr_post_duplicator_post_types(),
|
71 |
+
'default' => isset( $options['type'] ) ? sanitize_text_field( $options['type'] ) : 'same'
|
72 |
);
|
73 |
|
74 |
$settings['timestamp'] = array(
|
79 |
'current' => esc_html__('Current Time', 'post-duplicator')
|
80 |
),
|
81 |
'display' => 'inline',
|
82 |
+
'default' => isset( $options['timestamp'] ) ? sanitize_text_field( $options['timestamp'] ) : 'current'
|
83 |
);
|
84 |
|
85 |
$settings['title'] = array(
|
87 |
'description' => esc_html__('String that should be appended to the duplicate post\'s title', 'post-duplicator'),
|
88 |
'type' => 'text',
|
89 |
'display' => 'inline',
|
90 |
+
'default' => isset( $options['title'] ) ? sanitize_text_field( $options['title'] ) : esc_html__('Copy', 'post-duplicator')
|
91 |
);
|
92 |
|
93 |
$settings['slug'] = array(
|
95 |
'description' => esc_html__('String that should be appended to the duplicate post\'s slug', 'post-duplicator'),
|
96 |
'type' => 'text',
|
97 |
'display' => 'inline',
|
98 |
+
'default' => isset( $options['slug'] ) ? sanitize_text_field( $options['slug'] ) : 'copy'
|
99 |
);
|
100 |
|
101 |
$settings['time_offset'] = array(
|
102 |
'title' => esc_html__( 'Offset Date', 'post-duplicator' ),
|
103 |
'type' => 'checkbox',
|
104 |
+
'default' => isset( $options['time_offset'] ) ? sanitize_text_field( $options['time_offset'] ) : 0,
|
105 |
'append' => array(
|
106 |
'time_offset_days' => array(
|
107 |
'type' => 'text',
|
108 |
'size' => 2,
|
109 |
'after' => esc_html__(' days', 'post-duplicator'),
|
110 |
'text_align' => 'right',
|
111 |
+
'default' => isset( $options['time_offset_days'] ) ? sanitize_text_field( $options['time_offset_days'] ) : 0
|
112 |
),
|
113 |
'time_offset_hours' => array(
|
114 |
'type' => 'text',
|
115 |
'size' => 2,
|
116 |
'after' => esc_html__(' hours', 'post-duplicator'),
|
117 |
'text_align' => 'right',
|
118 |
+
'default' => isset( $options['time_offset_hours'] ) ? sanitize_text_field( $options['time_offset_hours'] ) : 0
|
119 |
),
|
120 |
'time_offset_minutes' => array(
|
121 |
'type' => 'text',
|
122 |
'size' => 2,
|
123 |
'after' => esc_html__(' minutes', 'post-duplicator'),
|
124 |
'text_align' => 'right',
|
125 |
+
'default' => isset( $options['time_offset_minutes'] ) ? sanitize_text_field( $options['time_offset_minutes'] ) : 0
|
126 |
),
|
127 |
'time_offset_seconds' => array(
|
128 |
'type' => 'text',
|
129 |
'size' => 2,
|
130 |
'after' => esc_html__(' seconds', 'post-duplicator'),
|
131 |
'text_align' => 'right',
|
132 |
+
'default' => isset( $options['time_offset_seconds'] ) ? sanitize_text_field( $options['time_offset_seconds'] ) : 0
|
133 |
),
|
134 |
'time_offset_direction' => array(
|
135 |
'type' => 'select',
|
137 |
'newer' => esc_html__('newer', 'post-duplicator'),
|
138 |
'older' => esc_html__('older', 'post-duplicator')
|
139 |
),
|
140 |
+
'default' => isset( $options['time_offset_direction'] ) ? sanitize_text_field( $options['time_offset_direction'] ) : 'newer'
|
141 |
)
|
142 |
)
|
143 |
);
|
158 |
|
159 |
if( is_array($settings) ) {
|
160 |
foreach( $settings as $id => $setting ) {
|
|
|
161 |
$setting['option_id'] = $id;
|
162 |
$setting['id'] = 'mtphr_post_duplicator_settings['.$id.']';
|
163 |
add_settings_field( $setting['id'], $setting['title'], 'mtphr_post_duplicator_field_display', 'mtphr_post_duplicator_settings', 'mtphr_post_duplicator_settings_section', $setting);
|
172 |
/**
|
173 |
* Sanitize the settings
|
174 |
*
|
175 |
+
* @since 2.27
|
176 |
*/
|
177 |
function mtphr_post_duplicator_settings_sanitize( $fields ) {
|
178 |
$sanitized_fields = array(
|
179 |
+
'post_duplication' => isset( $fields['post_duplication'] ) ? sanitize_text_field( $fields['post_duplication'] ) : 'all_users',
|
180 |
+
'post_author' => isset( $fields['post_author'] ) ? sanitize_text_field( $fields['post_author'] ) : 'current_user',
|
181 |
+
'status' => isset( $fields['status'] ) ? sanitize_text_field( $fields['status'] ) : 'draft',
|
182 |
+
'type' => isset( $fields['type'] ) ? sanitize_text_field( $fields['type'] ) : 'same',
|
183 |
+
'timestamp' => isset( $fields['timestamp'] ) ? sanitize_text_field( $fields['timestamp'] ) : 'current',
|
184 |
+
'title' => isset( $fields['title'] ) ? sanitize_text_field( $fields['title'] ) : '',
|
185 |
+
'slug' => isset( $fields['slug'] ) ? sanitize_title_with_dashes( $fields['slug'] ) : '',
|
186 |
+
'time_offset' => isset( $fields['time_offset'] ) ? sanitize_text_field( $fields['time_offset'] ) : false,
|
187 |
+
'time_offset_days' => isset( $fields['time_offset_days'] ) ? intval( $fields['time_offset_days'] ) : 0,
|
188 |
+
'time_offset_hours' => isset( $fields['time_offset_hours'] ) ? intval( $fields['time_offset_hours'] ) : 0,
|
189 |
+
'time_offset_minutes' => isset( $fields['time_offset_minutes'] ) ? intval( $fields['time_offset_minutes'] ) : 0,
|
190 |
+
'time_offset_seconds' => isset( $fields['time_offset_seconds'] ) ? intval( $fields['time_offset_seconds'] ) : 0,
|
191 |
+
'time_offset_direction' => isset( $fields['time_offset_direction'] ) ? sanitize_text_field( $fields['time_offset_direction'] ) : 'newer',
|
192 |
);
|
193 |
return $sanitized_fields;
|
194 |
}
|
238 |
/**
|
239 |
* The custom field callback.
|
240 |
*
|
241 |
+
* @since 2.27
|
242 |
*/
|
243 |
function mtphr_post_duplicator_field_display( $args ) {
|
244 |
+
$value = '';
|
245 |
+
if( isset( $args['default'] ) ) {
|
246 |
+
$value = sanitize_text_field( $args['default'] );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
}
|
248 |
if( isset($args['type']) ) {
|
249 |
|
250 |
echo '<div class="mtphr-post-duplicator-metaboxer-field mtphr-post-duplicator-metaboxer-' . esc_attr( $args['type'] ) . '">';
|
251 |
|
252 |
// Call the function to display the field
|
253 |
+
if ( function_exists('mtphr_post_duplicator_metaboxer_'. esc_attr( $args['type'] ) ) ) {
|
254 |
+
call_user_func( 'mtphr_post_duplicator_metaboxer_'. esc_attr( $args['type'] ), $args, $value );
|
255 |
}
|
256 |
|
257 |
echo '<div>';
|
m4c-postduplicator.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
/*
|
3 |
Plugin Name: Post Duplicator
|
4 |
Description: Creates functionality to duplicate any and all post types, including taxonomies & custom fields
|
5 |
-
Version: 2.
|
6 |
Author: Metaphor Creations
|
7 |
Author URI: http://www.metaphorcreations.com
|
8 |
Text Domain: post-duplicator
|
@@ -30,7 +30,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
30 |
|
31 |
// Plugin version.
|
32 |
if ( ! defined( 'MTPHR_POST_DUPLICATOR_VERSION' ) ) {
|
33 |
-
define( 'MTPHR_POST_DUPLICATOR_VERSION', '2.
|
34 |
}
|
35 |
|
36 |
// Plugin Folder Path.
|
@@ -65,14 +65,13 @@ function mtphr_post_duplicator_localization() {
|
|
65 |
/**
|
66 |
* Include files.
|
67 |
*
|
68 |
-
* @since 2.
|
69 |
*/
|
70 |
if ( is_admin() ) {
|
71 |
|
72 |
// Load Metaboxer
|
73 |
require_once( MTPHR_POST_DUPLICATOR_DIR.'includes/helpers.php' );
|
74 |
require_once( MTPHR_POST_DUPLICATOR_DIR.'metaboxer/metaboxer.php' );
|
75 |
-
//require_once( MTPHR_POST_DUPLICATOR_DIR.'metaboxer/metaboxer-class.php' );
|
76 |
require_once( MTPHR_POST_DUPLICATOR_DIR.'includes/scripts.php' );
|
77 |
require_once( MTPHR_POST_DUPLICATOR_DIR.'includes/ajax.php' );
|
78 |
require_once( MTPHR_POST_DUPLICATOR_DIR.'includes/edit.php' );
|
2 |
/*
|
3 |
Plugin Name: Post Duplicator
|
4 |
Description: Creates functionality to duplicate any and all post types, including taxonomies & custom fields
|
5 |
+
Version: 2.27
|
6 |
Author: Metaphor Creations
|
7 |
Author URI: http://www.metaphorcreations.com
|
8 |
Text Domain: post-duplicator
|
30 |
|
31 |
// Plugin version.
|
32 |
if ( ! defined( 'MTPHR_POST_DUPLICATOR_VERSION' ) ) {
|
33 |
+
define( 'MTPHR_POST_DUPLICATOR_VERSION', '2.27' );
|
34 |
}
|
35 |
|
36 |
// Plugin Folder Path.
|
65 |
/**
|
66 |
* Include files.
|
67 |
*
|
68 |
+
* @since 2.27
|
69 |
*/
|
70 |
if ( is_admin() ) {
|
71 |
|
72 |
// Load Metaboxer
|
73 |
require_once( MTPHR_POST_DUPLICATOR_DIR.'includes/helpers.php' );
|
74 |
require_once( MTPHR_POST_DUPLICATOR_DIR.'metaboxer/metaboxer.php' );
|
|
|
75 |
require_once( MTPHR_POST_DUPLICATOR_DIR.'includes/scripts.php' );
|
76 |
require_once( MTPHR_POST_DUPLICATOR_DIR.'includes/ajax.php' );
|
77 |
require_once( MTPHR_POST_DUPLICATOR_DIR.'includes/edit.php' );
|
metaboxer/metaboxer.php
CHANGED
@@ -18,20 +18,20 @@ function mtphr_post_duplicator_metaboxer_container( $field, $context ) {
|
|
18 |
|
19 |
global $post;
|
20 |
|
21 |
-
$default = isset( $field['default'] ) ? $field['default'] : '';
|
22 |
-
$value = ( get_post_meta( $post->ID, $field['id'], true ) != '' ) ? get_post_meta( $post->ID, $field['id'], true ) : $default;
|
23 |
-
$display = isset( $field['display'] ) ? $field['display'] : '';
|
24 |
?>
|
25 |
<tr class="mtphr-post-duplicator-metaboxer-field mtphr-post-duplicator-metaboxer-field-<?php esc_attr_e( $field['type'] ); ?> mtphr-post-duplicator-metaboxer<?php esc_attr_e( $field['id'] ); ?><?php if( isset($field['class']) ) { esc_attr_e( ' ' . $field['class'] ); } ?> clearfix">
|
26 |
|
27 |
<?php
|
28 |
-
$content_class = 'mtphr-post-duplicator-metaboxer-field-content mtphr-post-duplicator-metaboxer-field-content-full mtphr-post-duplicator-metaboxer-'
|
29 |
$content_span = ' colspan="2"';
|
30 |
$label = false;
|
31 |
|
32 |
if ( isset($field['name']) || isset($field['description']) ) {
|
33 |
|
34 |
-
$content_class = 'mtphr-post-duplicator-metaboxer-field-content mtphr-post-duplicator-metaboxer-'
|
35 |
$content_span = '';
|
36 |
$label = true;
|
37 |
?>
|
@@ -54,8 +54,8 @@ function mtphr_post_duplicator_metaboxer_container( $field, $context ) {
|
|
54 |
<td<?php esc_html_e( $content_span ); ?> class="<?php esc_attr_e( $content_class ); ?>" id="<?php esc_attr_e( $post->ID ); ?>">
|
55 |
<?php
|
56 |
// Call the function to display the field
|
57 |
-
if ( function_exists('mtphr_post_duplicator_metaboxer_'
|
58 |
-
call_user_func( 'mtphr_post_duplicator_metaboxer_'
|
59 |
}
|
60 |
?>
|
61 |
</td>
|
@@ -80,39 +80,27 @@ function mtphr_post_duplicator_metaboxer_append_field( $field ) {
|
|
80 |
if( isset($field['append']) ) {
|
81 |
|
82 |
$fields = $field['append'];
|
83 |
-
$settings = ( isset($field['option'] ) ) ? $field['option'] : false;
|
84 |
|
85 |
if( is_array($fields) ) {
|
86 |
|
87 |
foreach( $fields as $id => $field ) {
|
88 |
-
|
89 |
-
// Get the value
|
90 |
-
if( $settings) {
|
91 |
-
$options = get_option( $settings );
|
92 |
-
$value = isset( $options[$id] ) ? $options[$id] : get_option( $id );
|
93 |
-
} else {
|
94 |
-
global $post;
|
95 |
-
$value = get_post_meta( $post->ID, $id, true );
|
96 |
-
}
|
97 |
-
|
98 |
-
// Set the default if no value
|
99 |
-
if( $value == '' && isset($field['default']) ) {
|
100 |
-
$value = $field['default'];
|
101 |
-
}
|
102 |
|
103 |
if( isset($field['type']) ) {
|
104 |
-
|
105 |
-
if
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
$field['id'] = $id;
|
110 |
}
|
|
|
|
|
|
|
111 |
|
112 |
// Call the function to display the field
|
113 |
-
|
|
|
114 |
echo '<div class="mtphr-post-duplicator-metaboxer-appended mtphr-post-duplicator-metaboxer' . esc_attr( $field['id'] ) . '">';
|
115 |
-
call_user_func(
|
116 |
echo '</div>';
|
117 |
}
|
118 |
}
|
@@ -141,11 +129,11 @@ function mtphr_post_duplicator_metaboxer_select( $field, $value='' ) {
|
|
141 |
|
142 |
foreach ( $field['options'] as $key => $option ) {
|
143 |
if( is_numeric($key) && !$key_val ) {
|
144 |
-
$name = ( is_array( $option ) ) ? $option['name'] : $option;
|
145 |
-
$val = ( is_array( $option ) ) ? $option['value'] : $option;
|
146 |
} else {
|
147 |
-
$name = $option;
|
148 |
-
$val = $key;
|
149 |
}
|
150 |
echo '<option value="'.esc_attr( $val ).'" '.selected( $val, $value, false ).'>'.stripslashes( wp_kses_post( $name ) ).'</option>';
|
151 |
}
|
@@ -233,10 +221,10 @@ function mtphr_post_duplicator_metaboxer_checkbox( $field, $value='' ) {
|
|
233 |
/**
|
234 |
* Renders an text field.
|
235 |
*
|
236 |
-
* @since 2.
|
237 |
*/
|
238 |
function mtphr_post_duplicator_metaboxer_text( $field, $value='' ) {
|
239 |
-
$size = ( isset($field['size']) ) ? $field['size'] : 40;
|
240 |
$before = ( isset($field['before']) ) ? '<span>'.$field['before'].' </span>' : '';
|
241 |
$after = ( isset($field['after']) ) ? '<span> '.$field['after'].'</span>' : '';
|
242 |
$text_align = ( isset($field['text_align']) ) ? ' style="text-align:'.$field['text_align'].'"' : '' ;
|
@@ -254,8 +242,8 @@ function mtphr_post_duplicator_metaboxer_text( $field, $value='' ) {
|
|
254 |
* @since 2.25
|
255 |
*/
|
256 |
function mtphr_post_duplicator_metaboxer_textarea( $field, $value='' ) {
|
257 |
-
$rows = ( isset($field['rows']) ) ? $field['rows'] : 5;
|
258 |
-
$cols = ( isset($field['cols']) ) ? $field['cols'] : 40;
|
259 |
echo '<textarea name="'.esc_attr( $field['id'] ).'" id="'.esc_attr( $field['id'] ).'" rows="'.esc_attr( $rows ).'" cols="'.esc_attr( $cols ).'">'.wp_kses_post( $value ).'</textarea>';
|
260 |
|
261 |
// Add appended fields
|
18 |
|
19 |
global $post;
|
20 |
|
21 |
+
$default = isset( $field['default'] ) ? sanitize_text_field( $field['default'] ) : '';
|
22 |
+
$value = ( get_post_meta( $post->ID, $field['id'], true ) != '' ) ? sanitize_text_field( get_post_meta( $post->ID, $field['id'], true ) ) : $default;
|
23 |
+
$display = isset( $field['display'] ) ? sanitize_text_field( $field['display'] ) : '';
|
24 |
?>
|
25 |
<tr class="mtphr-post-duplicator-metaboxer-field mtphr-post-duplicator-metaboxer-field-<?php esc_attr_e( $field['type'] ); ?> mtphr-post-duplicator-metaboxer<?php esc_attr_e( $field['id'] ); ?><?php if( isset($field['class']) ) { esc_attr_e( ' ' . $field['class'] ); } ?> clearfix">
|
26 |
|
27 |
<?php
|
28 |
+
$content_class = 'mtphr-post-duplicator-metaboxer-field-content mtphr-post-duplicator-metaboxer-field-content-full mtphr-post-duplicator-metaboxer-'.esc_attr( $field['type'] ).' clearfix';
|
29 |
$content_span = ' colspan="2"';
|
30 |
$label = false;
|
31 |
|
32 |
if ( isset($field['name']) || isset($field['description']) ) {
|
33 |
|
34 |
+
$content_class = 'mtphr-post-duplicator-metaboxer-field-content mtphr-post-duplicator-metaboxer-'.esc_attr( $field['type'] ).' clearfix';
|
35 |
$content_span = '';
|
36 |
$label = true;
|
37 |
?>
|
54 |
<td<?php esc_html_e( $content_span ); ?> class="<?php esc_attr_e( $content_class ); ?>" id="<?php esc_attr_e( $post->ID ); ?>">
|
55 |
<?php
|
56 |
// Call the function to display the field
|
57 |
+
if ( function_exists('mtphr_post_duplicator_metaboxer_'.esc_attr( $field['type'] )) ) {
|
58 |
+
call_user_func( 'mtphr_post_duplicator_metaboxer_'.esc_attr( $field['type'] ), $field, $value );
|
59 |
}
|
60 |
?>
|
61 |
</td>
|
80 |
if( isset($field['append']) ) {
|
81 |
|
82 |
$fields = $field['append'];
|
|
|
83 |
|
84 |
if( is_array($fields) ) {
|
85 |
|
86 |
foreach( $fields as $id => $field ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
if( isset($field['type']) ) {
|
89 |
+
|
90 |
+
// Set the default if no value
|
91 |
+
$value = '';
|
92 |
+
if( isset($field['default']) ) {
|
93 |
+
$value = sanitize_text_field( $field['default'] );
|
|
|
94 |
}
|
95 |
+
|
96 |
+
$field['option_id'] = $id;
|
97 |
+
$field['id'] = 'mtphr_post_duplicator_settings['.sanitize_text_field( $id ).']';
|
98 |
|
99 |
// Call the function to display the field
|
100 |
+
$function_name = 'mtphr_post_duplicator_metaboxer_' . esc_attr( $field['type'] );
|
101 |
+
if ( function_exists( $function_name ) ) {
|
102 |
echo '<div class="mtphr-post-duplicator-metaboxer-appended mtphr-post-duplicator-metaboxer' . esc_attr( $field['id'] ) . '">';
|
103 |
+
call_user_func( $function_name, $field, $value );
|
104 |
echo '</div>';
|
105 |
}
|
106 |
}
|
129 |
|
130 |
foreach ( $field['options'] as $key => $option ) {
|
131 |
if( is_numeric($key) && !$key_val ) {
|
132 |
+
$name = ( is_array( $option ) ) ? sanitize_text_field( $option['name'] ) : sanitize_text_field( $option );
|
133 |
+
$val = ( is_array( $option ) ) ? sanitize_text_field( $option['value'] ) : sanitize_text_field( $option );
|
134 |
} else {
|
135 |
+
$name = sanitize_text_field( $option );
|
136 |
+
$val = sanitize_text_field( $key );
|
137 |
}
|
138 |
echo '<option value="'.esc_attr( $val ).'" '.selected( $val, $value, false ).'>'.stripslashes( wp_kses_post( $name ) ).'</option>';
|
139 |
}
|
221 |
/**
|
222 |
* Renders an text field.
|
223 |
*
|
224 |
+
* @since 2.27
|
225 |
*/
|
226 |
function mtphr_post_duplicator_metaboxer_text( $field, $value='' ) {
|
227 |
+
$size = ( isset( $field['size'] ) ) ? intval( $field['size'] ) : 40;
|
228 |
$before = ( isset($field['before']) ) ? '<span>'.$field['before'].' </span>' : '';
|
229 |
$after = ( isset($field['after']) ) ? '<span> '.$field['after'].'</span>' : '';
|
230 |
$text_align = ( isset($field['text_align']) ) ? ' style="text-align:'.$field['text_align'].'"' : '' ;
|
242 |
* @since 2.25
|
243 |
*/
|
244 |
function mtphr_post_duplicator_metaboxer_textarea( $field, $value='' ) {
|
245 |
+
$rows = ( isset($field['rows']) ) ? intval( $field['rows'] ) : 5;
|
246 |
+
$cols = ( isset($field['cols']) ) ? intval( $field['cols'] ) : 40;
|
247 |
echo '<textarea name="'.esc_attr( $field['id'] ).'" id="'.esc_attr( $field['id'] ).'" rows="'.esc_attr( $rows ).'" cols="'.esc_attr( $cols ).'">'.wp_kses_post( $value ).'</textarea>';
|
248 |
|
249 |
// Add appended fields
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: metaphorcreations
|
|
3 |
Tags: posts, post, duplicate, duplication
|
4 |
Requires at least: 4.0
|
5 |
Tested up to: 5.9
|
6 |
-
Stable tag: 2.
|
7 |
License: GPL2
|
8 |
|
9 |
Creates functionality to duplicate any and all post types, including taxonomies & custom fields.
|
@@ -41,6 +41,10 @@ Check out the 'Installation' tab.
|
|
41 |
|
42 |
== Changelog ==
|
43 |
|
|
|
|
|
|
|
|
|
44 |
= 2.26 =
|
45 |
* Removed duplicate functionality from post trash pages
|
46 |
* Database sanitization updates
|
@@ -146,4 +150,4 @@ Must upgrade in order for the plugin to work. The file paths where initially wro
|
|
146 |
|
147 |
== Upgrade Notice ==
|
148 |
|
149 |
-
Sanitization updates
|
3 |
Tags: posts, post, duplicate, duplication
|
4 |
Requires at least: 4.0
|
5 |
Tested up to: 5.9
|
6 |
+
Stable tag: 2.27
|
7 |
License: GPL2
|
8 |
|
9 |
Creates functionality to duplicate any and all post types, including taxonomies & custom fields.
|
41 |
|
42 |
== Changelog ==
|
43 |
|
44 |
+
= 2.27 =
|
45 |
+
* Sanitization and validation updates
|
46 |
+
* Settings page optimization
|
47 |
+
|
48 |
= 2.26 =
|
49 |
* Removed duplicate functionality from post trash pages
|
50 |
* Database sanitization updates
|
150 |
|
151 |
== Upgrade Notice ==
|
152 |
|
153 |
+
Sanitization updates settings optimization
|