PluginProbe
Post Duplicator / 2.26
Post Duplicator v2.26
3.0.16 trunk 1.1 2.0 2.2 2.20 2.21 2.22 2.23 2.24 2.25 2.26 2.27 2.28 2.29 2.3 2.30 2.31 2.32 2.33 2.34 2.35 2.36 2.37 2.38 All 52 releases
post-duplicator / includes / settings.php

settings.php in Post Duplicator 2.26, at includes/settings.php

272 lines 8.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 add_action( 'admin_menu', 'mtphr_post_duplicator_settings_page' );
4 /**
5 * Add a menu page to display options
6 *
7 * @since 2.0
8 */
9 function mtphr_post_duplicator_settings_page() {
10
11 add_management_page(
12 esc_html__('Post Duplicator', 'post-duplicator'), // The value used to populate the browser's title bar when the menu page is active
13 esc_html__('Post Duplicator', 'post-duplicator'), // The label of this submenu item displayed in the menu
14 'administrator', // What roles are able to access this submenu item
15 'mtphr_post_duplicator_settings_menu', // The ID used to represent this submenu item
16 'mtphr_post_duplicator_settings_display' // The callback function used to render the options for this submenu item
17 );
18 }
19
20
21
22
23 add_action( 'admin_init', 'mtphr_post_duplicator_initialize_settings' );
24 /**
25 * Initializes the options page.
26 *
27 * @since 2.16
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',
34 'options' => array(
35 'all_users' => esc_html__('Allow Duplication of All Users', 'post-duplicator'),
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(
43 'title' => esc_html__( 'Post Author', 'post-duplicator' ),
44 'type' => 'radio',
45 'options' => array(
46 'current_user' => esc_html__('Current User', 'post-duplicator'),
47 'original_user' => esc_html__('Original Post Author', 'post-duplicator'),
48 ),
49 'display' => 'inline',
50 'default' => 'current_user'
51 );
52
53 $settings['status'] = array(
54 'title' => esc_html__( 'Post Status', 'post-duplicator' ),
55 'type' => 'select',
56 'options' => array(
57 'same' => esc_html__('Same as original', 'post-duplicator'),
58 'draft' => esc_html__('Draft', 'post-duplicator'),
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(
73 'title' => esc_html__( 'Post Date', 'post-duplicator' ),
74 'type' => 'radio',
75 'options' => array(
76 'duplicate' => esc_html__('Duplicate Timestamp', 'post-duplicator'),
77 'current' => esc_html__('Current Time', 'post-duplicator')
78 ),
79 'display' => 'inline',
80 'default' => 'current'
81 );
82
83 $settings['title'] = array(
84 'title' => esc_html__( 'Duplicate Title', 'post-duplicator' ),
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(
92 'title' => esc_html__( 'Duplicate Slug', 'post-duplicator' ),
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',
133 'options' => array(
134 'newer' => esc_html__('newer', 'post-duplicator'),
135 'older' => esc_html__('older', 'post-duplicator')
136 ),
137 'default' => 'newer'
138 )
139 )
140 );
141
142 if( false == get_option('mtphr_post_duplicator_settings') ) {
143 add_option( 'mtphr_post_duplicator_settings' );
144 }
145
146 /* Register the style options */
147 add_settings_section(
148 'mtphr_post_duplicator_settings_section', // ID used to identify this section and with which to register options
149 '', // Title to be displayed on the administration page
150 'mtphr_post_duplicator_settings_callback', // Callback used to render the description of the section
151 'mtphr_post_duplicator_settings' // Page on which to add this section of options
152 );
153
154 $settings = apply_filters( 'mtphr_post_duplicator_settings', $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);
162 }
163 }
164
165 // Register the fields with WordPress
166 register_setting( 'mtphr_post_duplicator_settings', 'mtphr_post_duplicator_settings', 'mtphr_post_duplicator_settings_sanitize' );
167 }
168
169
170 /**
171 * Sanitize the settings
172 *
173 * @since 2.0
174 */
175 function mtphr_post_duplicator_settings_sanitize( $fields ) {
176 $sanitized_fields = array(
177 'post_duplication' => isset( $fields['post_duplication'] ) ? esc_attr( $fields['post_duplication'] ) : 'all_users',
178 'post_author' => isset( $fields['post_author'] ) ? esc_attr( $fields['post_author'] ) : 'current_user',
179 'status' => isset( $fields['status'] ) ? esc_attr( $fields['status'] ) : 'draft',
180 'type' => isset( $fields['type'] ) ? esc_attr( $fields['type'] ) : 'same',
181 'timestamp' => isset( $fields['timestamp'] ) ? esc_attr( $fields['timestamp'] ) : 'current',
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'] ) ? esc_attr( $fields['time_offset'] ) : false,
185 'time_offset_days' => isset( $fields['time_offset_days'] ) ? intval( $fields['time_offset_days'] ) : 0,
186 'time_offset_hours' => isset( $fields['time_offset_hours'] ) ? intval( $fields['time_offset_hours'] ) : 0,
187 'time_offset_minutes' => isset( $fields['time_offset_minutes'] ) ? intval( $fields['time_offset_minutes'] ) : 0,
188 'time_offset_seconds' => isset( $fields['time_offset_seconds'] ) ? intval( $fields['time_offset_seconds'] ) : 0,
189 'time_offset_direction' => isset( $fields['time_offset_direction'] ) ? esc_attr( $fields['time_offset_direction'] ) : 'newer',
190 );
191 return $sanitized_fields;
192 }
193
194
195
196
197 /**
198 * Renders a simple page to display for the theme menu defined above.
199 *
200 * @since 2.0
201 */
202 function mtphr_post_duplicator_settings_display() {
203 ?>
204 <div class="wrap">
205
206 <h2><?php _e( 'Post Duplicator Settings', 'post-duplicator' ); ?></h2>
207 <?php settings_errors(); ?>
208
209 <form method="post" action="options.php">
210 <?php
211 settings_fields( 'mtphr_post_duplicator_settings' );
212 do_settings_sections( 'mtphr_post_duplicator_settings' );
213 submit_button();
214 ?>
215 </form>
216
217 </div><!-- /.wrap -->
218 <?php
219 }
220
221
222
223
224 /**
225 * The callback function for the settings sections.
226 *
227 * @since 2.0
228 */
229 function mtphr_post_duplicator_settings_callback() {
230 echo '<h4>' . esc_html__( 'Customize the settings for duplicated posts.', 'post-duplicator' ) . '</h4>';
231 }
232
233
234
235
236 /**
237 * The custom field callback.
238 *
239 * @since 1.0
240 */
241 function mtphr_post_duplicator_field_display( $args ) {
242
243 // First, we read the options collection
244 if( isset($args['option']) ) {
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_'.$args['type']) ) {
259 call_user_func( 'mtphr_post_duplicator_metaboxer_'.$args['type'], $args, $value );
260 }
261
262 echo '<div>';
263 }
264
265 // Add a descriptions
266 if( isset( $args['description'] ) ) {
267 echo '<span class="description"><small>' . wp_kses_post( $args['description'] ) . '</small></span>';
268 }
269 }
270
271
272