From 9070a45ae42a4d06b2021d919e61af6ba46c2b1e Mon Sep 17 00:00:00 2001 From: Alexandre Faustino Date: Thu, 16 Jan 2025 12:13:59 +0000 Subject: [PATCH] New: email input callback function for settings #1010 --- assets/css/settings-styles.css | 1 + includes/Settings/SettingsCallbacks.php | 29 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/assets/css/settings-styles.css b/assets/css/settings-styles.css index 0a0c383d7..c597044f4 100644 --- a/assets/css/settings-styles.css +++ b/assets/css/settings-styles.css @@ -401,6 +401,7 @@ body.woocommerce_page_wpo_wcpdf_options_page { #wpo-wcpdf-preview-wrapper .sidebar .form-table > tbody > tr > td > input[type="text"], #wpo-wcpdf-preview-wrapper .sidebar .form-table > tbody > tr > td > input[type="url"], +#wpo-wcpdf-preview-wrapper .sidebar .form-table > tbody > tr > td > input[type="email"], #wpo-wcpdf-preview-wrapper .sidebar .form-table > tbody > tr > td > select, #wpo-wcpdf-preview-wrapper .sidebar .form-table > tbody > tr > td > textarea { max-width: none; diff --git a/includes/Settings/SettingsCallbacks.php b/includes/Settings/SettingsCallbacks.php index d6c18f43b..92fa2f714 100644 --- a/includes/Settings/SettingsCallbacks.php +++ b/includes/Settings/SettingsCallbacks.php @@ -145,6 +145,35 @@ public function url_input( $args ) { } } + /** + * Email input callback. + * + * args: + * option_name - name of the main option + * id - key of the setting + * size - size of the text input (em) + * default - default setting (optional) + * description - description (optional) + * type - type (optional) + * + * @return void. + */ + public function email_input( $args ) { + extract( $this->normalize_settings_args( $args ) ); + + if ( empty( $type ) ) { + $type = 'email'; + } + + $size = ! empty( $size ) ? sprintf( 'size="%s"', esc_attr( $size ) ) : ''; + printf( '', esc_attr( $type ), esc_attr( $id ), esc_attr( $setting_name ), sanitize_email( $current ), $size, esc_attr( $placeholder ), ! empty( $disabled ) ? 'disabled="disabled"' : '' ); + + // output description. + if ( ! empty( $description ) ) { + printf( '

%s

', wp_kses_post( $description ) ); + } + } + /** * Combined checkbox & text input callback. *