'array', 'sanitize_callback' => array( 'Logvia_Texts', 'sanitize' ), ) ); } /** * Builder assets on Settings → Logvia → Form builder. * * @param string $hook Admin page hook. */ public static function assets( $hook ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Tab check only. if ( 'settings_page_logvia' !== $hook || ! isset( $_GET['tab'] ) || 'forms' !== $_GET['tab'] ) { return; } wp_enqueue_style( 'logvia-builder', LOGVIA_URL . 'assets/css/admin-builder.css', array(), LOGVIA_VERSION ); wp_enqueue_script( 'logvia-builder', LOGVIA_URL . 'assets/js/admin-builder.js', array(), LOGVIA_VERSION, true ); $types = array(); foreach ( Logvia_Forms::types() as $key => $t ) { $types[] = array( 'type' => $key, 'label' => $t[0], 'group' => $t[1], 'icon' => $t[2], ); } $preview = Logvia_Plugin::page_id() ? Logvia_Plugin::url( 'register', array( 'logvia_preview' => '1' ) ) : ''; wp_localize_script( 'logvia-builder', 'LogviaBuilder', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'logvia_save_form' ), 'fields' => Logvia_Forms::fields(), 'defaults' => Logvia_Forms::default_fields(), 'types' => $types, 'core' => array( 'core_email' => __( 'Email', 'logvia' ), 'core_password' => __( 'Password', 'logvia' ), 'core_password_confirm' => __( 'Confirm password', 'logvia' ), ), 'maps' => Logvia_Forms::maps(), 'mapsFor' => array_combine( array_keys( Logvia_Forms::types() ), array_map( array( 'Logvia_Forms', 'maps_for' ), array_keys( Logvia_Forms::types() ) ) ), 'singles' => Logvia_Forms::single_types(), 'roles' => Logvia_Forms::assignable_roles(), 'hasWoo' => class_exists( 'WooCommerce' ), 'preview' => $preview, 'i18n' => array( 'groups' => array( 'input' => __( 'Inputs', 'logvia' ), 'choice' => __( 'Choices', 'logvia' ), 'content' => __( 'Content', 'logvia' ), 'account' => __( 'Account', 'logvia' ), 'upload' => __( 'Uploads', 'logvia' ), ), 'countryCode' => __( 'Show a country code picker', 'logvia' ), 'fileTypes' => __( 'Allowed files', 'logvia' ), 'images' => __( 'Images (JPG, PNG, GIF, WebP)', 'logvia' ), 'documents' => __( 'Documents (PDF, Word, Excel, text)', 'logvia' ), 'anyFile' => __( 'Images and documents', 'logvia' ), 'maxSize' => __( 'Maximum size (MB)', 'logvia' ), 'roles' => __( 'Account types visitors can choose', 'logvia' ), 'rolesHint' => __( 'Only roles without admin, editing or shop-management rights are listed.', 'logvia' ), 'fixedSave' => __( 'Saved automatically', 'logvia' ), 'single' => __( 'Already in the form', 'logvia' ), 'addHint' => __( 'Drag a field into the form, or click it to add it at the end.', 'logvia' ), 'empty' => __( 'Select a field to edit its settings.', 'logvia' ), 'save' => __( 'Save form', 'logvia' ), 'saving' => __( 'Saving…', 'logvia' ), 'saved' => __( 'Saved', 'logvia' ), 'saveFailed' => __( 'Could not save. Please reload the page and try again.', 'logvia' ), 'unsaved' => __( 'Unsaved changes', 'logvia' ), 'preview' => __( 'Preview', 'logvia' ), 'reset' => __( 'Reset to default', 'logvia' ), 'resetConfirm' => __( 'Replace the form with the default fields? Your custom fields will be removed after you save.', 'logvia' ), 'leave' => __( 'You have unsaved changes.', 'logvia' ), 'label' => __( 'Label', 'logvia' ), 'headingText' => __( 'Heading text', 'logvia' ), 'placeholder' => __( 'Placeholder', 'logvia' ), 'help' => __( 'Help text', 'logvia' ), 'required' => __( 'Required', 'logvia' ), 'width' => __( 'Width', 'logvia' ), 'full' => __( 'Full width', 'logvia' ), 'half' => __( 'Half width', 'logvia' ), 'options' => __( 'Options (one per line)', 'logvia' ), 'default' => __( 'Default value', 'logvia' ), 'checkedDefault'=> __( 'Checked by default', 'logvia' ), 'content' => __( 'Text (links allowed)', 'logvia' ), 'checkboxText' => __( 'Checkbox text (links allowed)', 'logvia' ), 'checkboxHint' => __( 'Example: I agree to the terms', 'logvia' ), 'maxlength' => __( 'Maximum length (0 = no limit)', 'logvia' ), 'saveTo' => __( 'Save value to', 'logvia' ), 'metaKey' => __( 'Meta key', 'logvia' ), 'metaHint' => __( 'Lowercase letters, numbers, - and _. Leave empty to generate one.', 'logvia' ), 'enabled' => __( 'Ask visitors to type the password twice', 'logvia' ), 'coreNote' => __( 'Built-in field: it can be moved and renamed but not removed.', 'logvia' ), 'moveUp' => __( 'Move up', 'logvia' ), 'moveDown' => __( 'Move down', 'logvia' ), 'duplicate' => __( 'Duplicate', 'logvia' ), 'remove' => __( 'Remove', 'logvia' ), 'drag' => __( 'Drag to reorder', 'logvia' ), 'fieldSettings' => __( 'Field settings', 'logvia' ), 'hidden' => __( 'Off', 'logvia' ), 'newField' => __( 'New field', 'logvia' ), 'required_star' => __( 'Required', 'logvia' ), ), ) ); } /** * Builder screen markup (the JavaScript renders the rest). */ public static function render_builder() { ?>

$keys ) : ?>

$def ) : if ( '_' === $key[0] ) { continue; } $id = 'logvia-text-' . $screen . '-' . $key; $value = isset( $saved[ $screen ][ $key ] ) ? $saved[ $screen ][ $key ] : ''; ?>
__( 'Your session expired. Please reload the page.', 'logvia' ) ), 403 ); } $raw = isset( $_POST['fields'] ) ? json_decode( wp_unslash( $_POST['fields'] ), true ) : null; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Decoded JSON is sanitized field by field in Logvia_Forms::save(). if ( ! is_array( $raw ) ) { wp_send_json_error( array( 'message' => __( 'Invalid form data.', 'logvia' ) ), 400 ); } wp_send_json_success( array( 'fields' => Logvia_Forms::save( $raw ) ) ); } /** * Custom fields on the user profile screen. * * @param WP_User $user User. */ public static function profile_fields( $user ) { $fields = Logvia_Forms::meta_fields(); if ( ! $fields || ! current_user_can( 'edit_user', $user->ID ) ) { return; } ?>

ID, $f['meta_key'], true ); $label = '' !== $f['label'] ? $f['label'] : Logvia_Forms::type_label( $f['type'] ); ?>