PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 4.0.3
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v4.0.3
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
profile-builder / add-ons-free / labels-edit / labels-edit.php

labels-edit.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 4.0.3, at add-ons-free/labels-edit/labels-edit.php

494 lines 18.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly
3 if ( ! defined( 'ABSPATH' ) ) exit;
4
5 /*
6 Description: Enables editing of labels from Profile Builder.
7 */
8
9
10 /* function that enqueues the necessary scripts */
11 function wppb_le_scripts_and_styles( $hook ) {
12 if( $hook == 'profile-builder_page_pb-labels-edit' ) {
13 wp_enqueue_script( 'pble_init', plugin_dir_url( __FILE__ ) . 'assets/js/init.js', array( 'jquery' ) );
14 wp_enqueue_script( 'pble_chosen', plugin_dir_url( __FILE__ ) . 'assets/chosen/chosen.jquery.min.js', array( 'jquery' ) );
15 wp_enqueue_style( 'pble_chosen_css', plugin_dir_url( __FILE__ ) . 'assets/chosen/chosen.css' );
16 wp_enqueue_style( 'pble_css', plugin_dir_url( __FILE__ ) . 'assets/css/style.css' );
17 }
18 }
19 add_action( 'admin_enqueue_scripts', 'wppb_le_scripts_and_styles' );
20
21 /* load required files */
22 require_once 'potx.php';
23 require_once 'inc/class-pble-import.php';
24 require_once 'inc/class-pble-export.php';
25 //require_once 'assets/lib/wck-api/wordpress-creation-kit.php';
26
27 /* scan labels on plugin activate if not already scanned */
28 function wppb_le_scan_on_plugin_activate() {
29 $pble_check = get_option( 'pble_backup', 'not_set' );
30
31 if( empty( $pble_check ) || $pble_check === 'not_set' ) {
32 // use of output buffer to fix "headers already sent" notice on plugin activation
33 ob_start();
34 wppb_le_scan_labels( wp_create_nonce( 'wppb_rescan_labels' ) );
35 $output = ob_get_clean();
36 }
37 }
38 register_activation_hook( __FILE__, 'wppb_le_scan_on_plugin_activate' );
39
40 /* scan pble labels */
41 function wppb_le_scan_labels( $nonce ) {
42
43 if( !wp_verify_nonce( $nonce, 'wppb_rescan_labels' ) )
44 return;
45
46 // create directory iterator
47 $ite = new RecursiveDirectoryIterator( WPPB_PLUGIN_DIR );
48
49 // array with files to get strings from
50 $pb_files_to_get = apply_filters( 'pb_files_to_get',
51 array(
52 'functions.php',
53 'login.php',
54 'recover.php',
55 'register.php',
56 'logout.php',
57 'class-formbuilder.php',
58 'edit-profile.php',
59 'admin-approval.php',
60 'email-confirmation.php',
61 'resend-activation.php',
62 'userlisting.php',
63 'email.php',
64 'username.php',
65 'password-repeat.php',
66 'form-designs.php',
67 'dashboard.php',
68 'profile-builder.catalog.php',
69 )
70 );
71
72 global $wppb_strings;
73 $wppb_strings = array();
74
75 // loop through directory and get _e() and __() function calls
76 foreach( new RecursiveIteratorIterator( $ite ) as $filename => $current_file ) {
77 // http://php.net/manual/en/class.splfileinfo.php
78 if( isset( $current_file ) ) {
79 $current_file_pathinfo = pathinfo( $current_file );
80 if( isset( $current_file_pathinfo['extension'] ) ) {
81 if( ! empty( $current_file_pathinfo['extension'] ) && $current_file_pathinfo['extension'] == "php" ) {
82 if( in_array( basename( $current_file ), $pb_files_to_get ) ) {
83 if( file_exists( $current_file ) ) {
84 _wppb_le_potx_process_file( realpath( $current_file ), 0, '_wppb_le_output_str2' );
85 }
86 }
87 }
88 }
89 }
90 }
91
92 update_option( 'pble_backup', $wppb_strings );
93
94 }
95
96 // populate array with Profile Builder labels
97 function _wppb_le_output_str2( $str ) {
98 global $wppb_strings;
99 if( is_array( $wppb_strings ) && ! in_array( $str, $wppb_strings ) ) {
100 $wppb_strings[] = $str;
101 }
102 }
103
104 /* scan pble labels on Rescan button click */
105 function wppb_le_rescan() {
106
107 if( isset( $_POST['rescan'] ) && isset( $_POST['wppb_nonce'] ) && wp_verify_nonce( sanitize_text_field( $_POST['wppb_nonce'] ), 'wppb_rescan_labels' ) ) {
108 wppb_le_scan_labels( sanitize_text_field( $_POST['wppb_nonce'] ) );
109 }
110
111 }
112 add_action( 'init', 'wppb_le_rescan' );
113
114 /* rescan success message */
115 function wppb_le_rescan_success_message() {
116 if( isset( $_POST['rescan'] ) && isset( $_POST['wppb_nonce'] ) && wp_verify_nonce( sanitize_text_field( $_POST['wppb_nonce'] ), 'wppb_rescan_labels' ) ) {
117 global $wppb_strings;
118 $wppb_strings_count = count( $wppb_strings );
119
120 $rescan_message = '<div id="message" class="updated"><p>' . $wppb_strings_count . __(' labels scanned.', 'profile-builder') . '</p></div>';
121 echo wp_kses_post( $rescan_message );
122 }
123 }
124 add_action( 'admin_notices', 'wppb_le_rescan_success_message' );
125
126 /*
127 * change text strings
128 *
129 * @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
130 */
131 function wppb_le_text_strings( $translated_text, $text, $domain ) {
132 if( $domain != 'profile-builder' )
133 return $translated_text;
134
135 $edited_labels = get_option( 'pble' );
136
137 if( empty( $edited_labels ) || $edited_labels === 'not_set' ) {
138 return $translated_text;
139 }
140
141 if( is_array( $edited_labels ) && ! empty( $edited_labels ) ) {
142 foreach( $edited_labels as $inner_array ) {
143 if( !empty( $text ) ) {
144 if( strip_tags( $text ) === $inner_array['pble-label'] || strip_tags( $text ) === htmlentities($inner_array['pble-label']) ) {
145 $translated_text = wp_kses_post( $inner_array['pble-newlabel'] );
146 }
147 }
148 }
149 }
150
151 return $translated_text;
152 }
153 add_filter( 'gettext', 'wppb_le_text_strings', 8, 3 );
154
155 function wppb_le_text_strings_with_context( $translated_text, $text, $context, $domain ) {
156 if( $domain != 'profile-builder' )
157 return $translated_text;
158
159 $edited_labels = get_option( 'pble' );
160
161 if( empty( $edited_labels ) || $edited_labels === 'not_set' ) {
162 return $translated_text;
163 }
164
165 if( is_array( $edited_labels ) && ! empty( $edited_labels ) ) {
166 foreach( $edited_labels as $inner_array ) {
167 if( strip_tags( $text ) === $inner_array['pble-label'] || strip_tags( $text ) === htmlentities($inner_array['pble-label']) ) {
168 $translated_text = wp_kses_post( $inner_array['pble-newlabel'] );
169 }
170 }
171 }
172
173 return $translated_text;
174 }
175 add_filter( 'gettext_with_context', 'wppb_le_text_strings_with_context', 8, 4 );
176
177 function wppb_le_ngettext_strings( $translated_text, $single, $plural, $number, $domain ){
178 if( $domain != 'profile-builder' )
179 return $translated_text;
180
181 $edited_labels = get_option( 'pble' );
182
183 if( empty( $edited_labels ) || $edited_labels === 'not_set' ) {
184 return $translated_text;
185 }
186
187 if( is_array( $edited_labels ) && ! empty( $edited_labels ) ) {
188 foreach( $edited_labels as $inner_array ) {
189 if( strip_tags( $single ) === $inner_array['pble-label'] ) {
190 $translated_text = wp_kses_post( $inner_array['pble-newlabel'] );
191 }
192 if( strip_tags( $plural ) === $inner_array['pble-label'] ) {
193 $translated_text = wp_kses_post( $inner_array['pble-newlabel'] );
194 }
195 }
196 }
197
198 return $translated_text;
199 }
200 add_filter( 'ngettext', 'wppb_le_text_strings', 8, 5 );
201
202 function wppb_le_ngettext_strings_with_context( $translated_text, $single, $plural, $number, $context, $domain ){
203 if( $domain != 'profile-builder' )
204 return $translated_text;
205
206 $edited_labels = get_option( 'pble' );
207
208 if( empty( $edited_labels ) || $edited_labels === 'not_set' ) {
209 return $translated_text;
210 }
211
212 if( is_array( $edited_labels ) && ! empty( $edited_labels ) ) {
213 foreach( $edited_labels as $inner_array ) {
214 if( strip_tags( $single ) === $inner_array['pble-label'] ) {
215 $translated_text = wp_kses_post( $inner_array['pble-newlabel'] );
216 }
217 if( strip_tags( $plural ) === $inner_array['pble-label'] ) {
218 $translated_text = wp_kses_post( $inner_array['pble-newlabel'] );
219 }
220 }
221 }
222
223 return $translated_text;
224 }
225 add_filter( 'ngettext_with_context', 'wppb_le_ngettext_strings_with_context', 8, 6 );
226
227
228 function wppb_le_remove_gettext_filter( $screen ) {
229 if( is_object( $screen ) && $screen->id == 'profile-builder_page_pb-labels-edit' ) {
230 remove_filter( 'gettext', 'wppb_le_text_strings', 8 );
231 }
232 }
233 add_action( 'current_screen', 'wppb_le_remove_gettext_filter' );
234
235 function wppb_le_remove_gettext_filter_from_ajax(){
236 remove_filter( 'gettext', 'wppb_le_text_strings', 8 );
237 }
238 add_action('wp_ajax_wck_add_formpble', 'wppb_le_remove_gettext_filter_from_ajax');
239 add_action('wp_ajax_wck_refresh_listpble', 'wppb_le_remove_gettext_filter_from_ajax');
240 add_action('wp_ajax_wck_refresh_entrypble', 'wppb_le_remove_gettext_filter_from_ajax');
241
242
243 /* PB Labels Edit subpage content function */
244 function wppb_le_page() {
245 // create Labels Edit page
246 $args = array(
247 'menu_title' => __( 'Labels Edit', 'profile-builder' ),
248 'page_title' => __( 'Labels Edit', 'profile-builder' ),
249 'menu_slug' => 'pb-labels-edit',
250 'page_type' => 'submenu_page',
251 'capability' => 'manage_options',
252 'priority' => 5,
253 'parent_slug' => 'profile-builder'
254 );
255 if( class_exists( 'WCK_Page_Creator_PB' ) ) {
256 new WCK_Page_Creator_PB( $args );
257 }
258
259 // array with Profile Builder strings to edit
260 $wppb_strings = get_option( 'pble_backup', array() );
261 $pble_labels = $wppb_strings;
262
263
264 // array with fields for Edit Labels metabox
265 $pble_fields = array(
266 array( 'type' => 'select', 'slug' => 'pble-label', 'title' => __( 'Label to Edit', 'profile-builder' ), 'default-option' => true, 'values' => $pble_labels, 'options' => $pble_labels, 'description' => __( 'Here you will see the default label so you can copy it.', 'profile-builder' ) ),
267 array( 'type' => 'textarea', 'slug' => 'pble-newlabel', 'title' => __( 'New Label', 'profile-builder' ) ),
268 );
269
270 // create Edit Labels metabox
271 $pble_args = array(
272 'metabox_id' => 'pble-id',
273 'metabox_title' => __( 'Edit Labels', 'profile-builder' ),
274 'post_type' => 'pb-labels-edit',
275 'meta_name' => 'pble',
276 'meta_array' => $pble_fields,
277 'context' => 'option'
278 );
279 if( class_exists( 'Wordpress_Creation_Kit_PB' ) ) {
280 new Wordpress_Creation_Kit_PB( $pble_args );
281 }
282 }
283 add_action( 'init', 'wppb_le_page', 11 );
284
285 // add Rescan side meta-box
286 function wppb_le_side_metabox() {
287 add_meta_box(
288 'pble-id-side',
289 __( 'Rescan Lables', 'profile-builder' ),
290 'wppb_le_rescan_button',
291 'profile-builder_page_pb-labels-edit',
292 'normal'
293 );
294 }
295
296 add_action( 'add_meta_boxes', 'wppb_le_side_metabox' );
297 add_action( 'wck_add_meta_boxes', 'wppb_le_side_metabox' );
298
299 // Rescan side meta-box content
300 function wppb_le_rescan_button() {
301 ?>
302 <div class="wrap cozmoslabs-form-field-wrapper">
303
304 <form action="" method="post">
305 <input type="hidden" name="wppb_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wppb_rescan_labels' ) ); ?>" />
306 <input type="submit" class="button-primary" name="rescan" value="Rescan" />
307 </form>
308
309 <?php echo '<p class="cozmoslabs-description cozmoslabs-description-align-right">'. esc_html__( 'Rescan all Profile Builder labels.', 'profile-builder' ) .'</p>'; ?>
310 </div>
311 <?php
312 }
313
314 // add Informations side meta-box
315 function wppb_le_info_side_metabox() {
316 add_meta_box(
317 'pble-id-side-info',
318 __( 'Informations', 'profile-builder' ),
319 'wppb_le_info',
320 'profile-builder_page_pb-labels-edit',
321 'normal'
322 );
323 }
324 add_action( 'add_meta_boxes', 'wppb_le_info_side_metabox' );
325 add_action( 'wck_add_meta_boxes', 'wppb_le_info_side_metabox' );
326
327 // Informations side meta-box content
328 function wppb_le_info() {
329 ?>
330 <div class="cozmoslabs-form-field-wrapper">
331 <label class="cozmoslabs-form-field-label"><?php esc_html_e( 'Variables', 'profile-builder' ) ?></label>
332 <p class="cozmoslabs-description" style="display: flex; gap: 10px;"><span>%1$s</span> <span>%2$s</span> <span>%s</span> <span>etc.</span></p>
333 </div>
334
335 <p class="cozmoslabs-description cozmoslabs-description-space-left"><strong><?php echo esc_html__( 'Place them like in the default string!', 'profile-builder' ) ?></strong></p>
336
337 <div class="cozmoslabs-form-field-wrapper">
338 <label class="cozmoslabs-form-field-label"><?php esc_html_e( 'Example', 'profile-builder' ) ?></label>
339 <div>
340 <p class="cozmoslabs-description"><strong><?php esc_html_e( 'Old Label: ', 'profile-builder' ) ?></strong> <span>in %1$d sec, click %2$s.%3$s</span></p>
341 <p class="cozmoslabs-description"><strong><?php esc_html_e( 'New Label: ', 'profile-builder' ) ?></strong> <span>click %2$s.%3$s in %1$d sec</span></p>
342 </div>
343 </div>
344
345 <p class="cozmoslabs-description cozmoslabs-description-space-left"><a href="http://www.cozmoslabs.com/?p=40126" target="_blank"><?php echo esc_html__( 'Read more detailed informations', 'profile-builder' ) ?></a></p>
346 <?php
347 }
348
349 // add Import and Export side meta-box
350 function wppb_le_impexp_metabox() {
351 add_meta_box(
352 'pble-id-side-impexp',
353 __( 'Import and Export Labels', 'profile-builder' ),
354 'wppb_le_impexp_content',
355 'profile-builder_page_pb-labels-edit',
356 'normal'
357 );
358 }
359 add_action( 'add_meta_boxes', 'wppb_le_impexp_metabox' );
360 add_action( 'wck_add_meta_boxes', 'wppb_le_impexp_metabox' );
361
362 // Import and Export side meta-box content
363 function wppb_le_impexp_content() {
364 // call import function
365 wppb_le_import();
366 ?>
367 <h4 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Import Labels from a .json file.', 'profile-builder' ); ?></h4>
368
369 <form name="pble-upload" method="post" action="" enctype= "multipart/form-data">
370 <input type="hidden" name="wppb_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wppb_import_labels' ) ); ?>" />
371
372 <div class="wrap cozmoslabs-form-field-wrapper">
373 <label class="cozmoslabs-form-field-label"><?php esc_html_e( 'JSON File', 'profile-builder' ); ?></label>
374 <input type="file" name="pble-upload" value="pble-upload" id="pble-upload" />
375 </div>
376
377 <div class="wrap cozmoslabs-form-field-wrapper">
378 <input class="button-primary" type="submit" name="pble-import" value=<?php esc_html_e( 'Import', 'profile-builder' ); ?> id="pble-import" onclick="return confirm( '<?php esc_html_e( 'This will overwrite all your old edited labels!\nAre you sure you want to continue?', 'profile-builder' ); ?>' )" />
379 <p class="cozmoslabs-description cozmoslabs-description-align-right"><?php esc_html_e( 'Easily import the labels from another site.', 'profile-builder' ); ?></p>
380 </div>
381 </form>
382
383 <hr style="margin: 35px 0;">
384
385 <h4 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Export Labels as a .json file.', 'profile-builder' ); ?></h4>
386 <form action="" method="post">
387 <input type="hidden" name="wppb_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wppb_export_labels' ) ); ?>" />
388
389 <div class="wrap cozmoslabs-form-field-wrapper">
390 <input class="button-primary" type="submit" name="pble-export" value=<?php esc_html_e( 'Export', 'profile-builder' ); ?> id="pble-export" />
391 <p class="cozmoslabs-description cozmoslabs-description-align-right"><?php esc_html_e( 'Easily import the labels into another site.', 'profile-builder' ); ?></p>
392 </div>
393 </form>
394 <?php
395 }
396
397 /* function that check for already edited labels */
398 function wppb_le_check_for_errors( $message, $fields, $required_fields, $meta_name, $posted_values, $post_id ) {
399 if ( $meta_name == 'pble' ) {
400 /* todo: broken check for added fields so you can't edit same label twice - fix it for future version
401 $pble_posted_labels = get_option( $meta_name, 'not_set' );
402 $posted_labels = array();
403
404
405 if( ! empty( $pble_posted_labels ) ) {
406 foreach( $pble_posted_labels as $label ) {
407 $posted_labels[] = $label['pble-label'];
408 }
409
410 if( ( in_array( $posted_values['pble-label'], $posted_labels ) ) ) {
411 $message = __( "This label is already edited!", 'profile-builder' );
412 }
413 }
414 */
415
416 if( $posted_values['pble-label'] == '' ) {
417 $message = __( "You must select a label to edit!", 'profile-builder' );
418 }
419 }
420 return $message;
421 }
422 add_filter( 'wck_extra_message', 'wppb_le_check_for_errors', 10, 6 );
423
424 /* function that change table header */
425 function wppb_le_header( $list_header ){
426 $delete_all_nonce = wp_create_nonce( 'pble-delete-all-entries' );
427
428 return '<thead><tr><th class="wck-number">#</th><th class="wck-content">'. __( 'Labels', 'profile-builder' ) .'</th><th class="wck-edit">'. __( 'Edit', 'profile-builder' ) .'</th><th class="wck-delete"><a id="wppb-delete-all-fields" class="wppb-delete-all-fields" onclick="wppb_le_delete_all_fields(event, this.id, \'' . esc_js($delete_all_nonce) . '\')" title="' . __('Delete all', 'profile-builder') . '" href="#">'. __( 'Delete all', 'profile-builder' ) .'</a></th></tr></thead>';
429 }
430 add_action( 'wck_metabox_content_header_pble', 'wppb_le_header' );
431
432 /* function that delete all edited labels */
433 add_action("wp_ajax_pble_delete_all_fields", 'wppb_le_delete_all_fields_callback' );
434 function wppb_le_delete_all_fields_callback(){
435 check_ajax_referer( "pble-delete-all-entries" );
436
437 if( !current_user_can( 'manage_options' ) )
438 die();
439
440 if( ! empty( $_POST['meta'] ) )
441 $meta_name = sanitize_text_field( $_POST['meta'] );
442 else
443 $meta_name = '';
444
445 if( $meta_name == 'pble' ) {
446 delete_option( 'pble' );
447 }
448 exit;
449 }
450
451 /* function that calls chosen after refresh */
452 function wppb_le_chosen_pble( $id ) {
453 echo "<script type=\"text/javascript\">wppb_le_chosen(); wppb_le_description( jQuery( '.update_container_pble .mb-select' ) ); </script>";
454 }
455 add_action( "wck_ajax_add_form_pble", "wppb_le_chosen_pble" );
456 add_action( "wck_after_adding_form_pble", "wppb_le_chosen_pble" );
457
458 /* import class arguments and call */
459 function wppb_le_import() {
460 if( isset( $_POST['pble-import'] ) && isset( $_POST['wppb_nonce'] ) && wp_verify_nonce( sanitize_text_field( $_POST['wppb_nonce'] ), 'wppb_import_labels' ) && current_user_can( 'manage_options' ) ) {
461 if( isset( $_FILES['pble-upload'] ) ) {
462 $pble_args = array(
463 'pble'
464 );
465
466 $pble_json_upload = new WPPB_LE_Import( $pble_args );
467 $pble_json_upload->upload_json_file();
468 /* show error/success messages */
469 $pble_messages = $pble_json_upload->get_messages();
470 foreach ( $pble_messages as $pble_message ) {
471 echo '<div id="message" class='. esc_attr( $pble_message['type'] ) .'><p>'. $pble_message['message'] .'</p></div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
472 }
473 }
474 }
475 }
476
477 /* export class arguments and call */
478 add_action( 'admin_init', 'wppb_le_export' );
479 function wppb_le_export() {
480 if( isset( $_POST['pble-export'] ) && isset( $_POST['wppb_nonce'] ) && wp_verify_nonce( sanitize_text_field( $_POST['wppb_nonce'] ), 'wppb_export_labels' ) && current_user_can( 'manage_options' ) ) {
481 $check_export = get_option( 'pble', 'not_set' );
482 if( empty( $check_export ) || $check_export === 'not_set' ) {
483 echo '<div id="message" class="error"><p>' . esc_html__('No labels edited, nothing to export!', 'profile-builder') . '</p></div>';
484 } else {
485 $pble_args = array(
486 'pble'
487 );
488
489 $pble_prefix = 'PBLE_';
490 $pble_json_export = new WPPB_LE_Export( $pble_args );
491 $pble_json_export->download_to_json_format( $pble_prefix );
492 }
493 }
494 }