$current_file ) {
// http://php.net/manual/en/class.splfileinfo.php
if( isset( $current_file ) ) {
$current_file_pathinfo = pathinfo( $current_file );
if( isset( $current_file_pathinfo['extension'] ) ) {
if( ! empty( $current_file_pathinfo['extension'] ) && $current_file_pathinfo['extension'] == "php" ) {
if( in_array( basename( $current_file ), $pb_files_to_get ) ) {
if( file_exists( $current_file ) ) {
_wppb_le_potx_process_file( realpath( $current_file ), 0, '_wppb_le_output_str2' );
}
}
}
}
}
}
update_option( 'pble_backup', $wppb_strings );
}
// populate array with Profile Builder labels
function _wppb_le_output_str2( $str ) {
global $wppb_strings;
if( is_array( $wppb_strings ) && ! in_array( $str, $wppb_strings ) ) {
$wppb_strings[] = $str;
}
}
/* scan pble labels on Rescan button click */
function wppb_le_rescan() {
if( isset( $_POST['rescan'] ) && isset( $_POST['wppb_nonce'] ) && wp_verify_nonce( sanitize_text_field( $_POST['wppb_nonce'] ), 'wppb_rescan_labels' ) ) {
wppb_le_scan_labels( sanitize_text_field( $_POST['wppb_nonce'] ) );
}
}
add_action( 'init', 'wppb_le_rescan' );
/* rescan success message */
function wppb_le_rescan_success_message() {
if( isset( $_POST['rescan'] ) && isset( $_POST['wppb_nonce'] ) && wp_verify_nonce( sanitize_text_field( $_POST['wppb_nonce'] ), 'wppb_rescan_labels' ) ) {
global $wppb_strings;
$wppb_strings_count = count( $wppb_strings );
$rescan_message = '
' . $wppb_strings_count . __(' labels scanned.', 'profile-builder') . '
';
echo wp_kses_post( $rescan_message );
}
}
add_action( 'admin_notices', 'wppb_le_rescan_success_message' );
/*
* change text strings
*
* @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
*/
function wppb_le_text_strings( $translated_text, $text, $domain ) {
if( is_admin() && ( !isset( $_POST ) || !isset( $_POST['wppb_msf_ajax_nonce'] ) ) )
return $translated_text;
$edited_labels = get_option( 'pble' );
if( empty( $edited_labels ) || $edited_labels === 'not_set' ) {
return $translated_text;
}
if( is_array( $edited_labels ) && ! empty( $edited_labels ) ) {
foreach( $edited_labels as $inner_array ) {
if( $text === $inner_array['pble-label'] || $text === htmlentities($inner_array['pble-label']) ) {
$translated_text = wp_kses_post( $inner_array['pble-newlabel'] );
}
}
}
return $translated_text;
}
add_filter( 'gettext', 'wppb_le_text_strings', 8, 3 );
function wppb_le_ngettext_strings( $translated_text, $single, $plural, $number, $domain ){
if( is_admin() )
return $translated_text;
if( $domain != 'profile-builder' )
return $translated_text;
$edited_labels = get_option( 'pble' );
if( empty( $edited_labels ) || $edited_labels === 'not_set' ) {
return $translated_text;
}
if( is_array( $edited_labels ) && ! empty( $edited_labels ) ) {
foreach( $edited_labels as $inner_array ) {
if( $single === $inner_array['pble-label'] ) {
$translated_text = wp_kses_post( $inner_array['pble-newlabel'] );
}
if( $plural === $inner_array['pble-label'] ) {
$translated_text = wp_kses_post( $inner_array['pble-newlabel'] );
}
}
}
return $translated_text;
}
add_filter( 'ngettext', 'wppb_le_text_strings', 8, 5 );
function wppb_le_remove_gettext_filter( $screen ) {
if( is_object( $screen ) && $screen->id == 'profile-builder_page_pb-labels-edit' ) {
remove_filter( 'gettext', 'wppb_le_text_strings', 8 );
}
}
add_action( 'current_screen', 'wppb_le_remove_gettext_filter' );
function wppb_le_remove_gettext_filter_from_ajax(){
remove_filter( 'gettext', 'wppb_le_text_strings', 8 );
}
add_action('wp_ajax_wck_add_formpble', 'wppb_le_remove_gettext_filter_from_ajax');
add_action('wp_ajax_wck_refresh_listpble', 'wppb_le_remove_gettext_filter_from_ajax');
add_action('wp_ajax_wck_refresh_entrypble', 'wppb_le_remove_gettext_filter_from_ajax');
/* PB Labels Edit subpage content function */
function wppb_le_page() {
// create Labels Edit page
$args = array(
'menu_title' => __( 'Labels Edit', 'profile-builder' ),
'page_title' => __( 'Labels Edit', 'profile-builder' ),
'menu_slug' => 'pb-labels-edit',
'page_type' => 'submenu_page',
'capability' => 'manage_options',
'priority' => 5,
'parent_slug' => 'profile-builder'
);
if( class_exists( 'WCK_Page_Creator_PB' ) ) {
new WCK_Page_Creator_PB( $args );
}
// array with Profile Builder strings to edit
$wppb_strings = get_option( 'pble_backup', array() );
$pble_labels = $wppb_strings;
// array with fields for Edit Labels metabox
$pble_fields = array(
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' ) ),
array( 'type' => 'textarea', 'slug' => 'pble-newlabel', 'title' => __( 'New Label', 'profile-builder' ) ),
);
// create Edit Labels metabox
$pble_args = array(
'metabox_id' => 'pble-id',
'metabox_title' => __( 'Edit Labels', 'profile-builder' ),
'post_type' => 'pb-labels-edit',
'meta_name' => 'pble',
'meta_array' => $pble_fields,
'context' => 'option'
);
if( class_exists( 'Wordpress_Creation_Kit_PB' ) ) {
new Wordpress_Creation_Kit_PB( $pble_args );
}
}
add_action( 'init', 'wppb_le_page', 11 );
// add Rescan side meta-box
function wppb_le_side_metabox() {
add_meta_box(
'pble-id-side',
__( 'Rescan Lables', 'profile-builder' ),
'wppb_le_rescan_button',
'profile-builder_page_pb-labels-edit',
'normal'
);
}
add_action( 'add_meta_boxes', 'wppb_le_side_metabox' );
add_action( 'wck_add_meta_boxes', 'wppb_le_side_metabox' );
// Rescan side meta-box content
function wppb_le_rescan_button() {
?>
'. esc_html__( 'Rescan all Profile Builder labels.', 'profile-builder' ) .''; ?>
| # | '. __( 'Labels', 'profile-builder' ) .' | '. __( 'Edit', 'profile-builder' ) .' | '. __( 'Delete all', 'profile-builder' ) .' |
';
}
add_action( 'wck_metabox_content_header_pble', 'wppb_le_header' );
/* function that delete all edited labels */
add_action("wp_ajax_pble_delete_all_fields", 'wppb_le_delete_all_fields_callback' );
function wppb_le_delete_all_fields_callback(){
check_ajax_referer( "pble-delete-all-entries" );
if( !current_user_can( 'manage_options' ) )
die();
if( ! empty( $_POST['meta'] ) )
$meta_name = sanitize_text_field( $_POST['meta'] );
else
$meta_name = '';
if( $meta_name == 'pble' ) {
delete_option( 'pble' );
}
exit;
}
/* function that calls chosen after refresh */
function wppb_le_chosen_pble( $id ) {
echo "";
}
add_action( "wck_ajax_add_form_pble", "wppb_le_chosen_pble" );
add_action( "wck_after_adding_form_pble", "wppb_le_chosen_pble" );
/* import class arguments and call */
function wppb_le_import() {
if( isset( $_POST['pble-import'] ) && isset( $_POST['wppb_nonce'] ) && wp_verify_nonce( sanitize_text_field( $_POST['wppb_nonce'] ), 'wppb_import_labels' ) ) {
if( isset( $_FILES['pble-upload'] ) ) {
$pble_args = array(
'pble'
);
$pble_json_upload = new WPPB_LE_Import( $pble_args );
$pble_json_upload->upload_json_file();
/* show error/success messages */
$pble_messages = $pble_json_upload->get_messages();
foreach ( $pble_messages as $pble_message ) {
echo ''. $pble_message['message'] .'
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
}
}
/* export class arguments and call */
add_action( 'admin_init', 'wppb_le_export' );
function wppb_le_export() {
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' ) ) {
$check_export = get_option( 'pble', 'not_set' );
if( empty( $check_export ) || $check_export === 'not_set' ) {
echo '' . esc_html__('No labels edited, nothing to export!', 'profile-builder') . '
';
} else {
$pble_args = array(
'pble'
);
$pble_prefix = 'PBLE_';
$pble_json_export = new WPPB_LE_Export( $pble_args );
$pble_json_export->download_to_json_format( $pble_prefix );
}
}
}