| @@ -19,9 +19,8 @@ | ||
| 19 | 19 | * |
| 20 | 20 | * @since 0.0.1 |
| 21 | 21 | */ |
| 22 | 22 | class Email_Markup extends Base { |
| 23 | - | |
| 24 | 23 | /** |
| 25 | 24 | * Flag indicating whether email confirmation is required. |
| 26 | 25 | * |
| 27 | 26 | * @var bool |
| @@ -37,9 +36,9 @@ | ||
| 37 | 36 | */ |
| 38 | 37 | protected $input_confirm_label_fallback; |
| 39 | 38 | |
| 40 | 39 | /** |
| 41 | - * Encrypted label for the confirmation input field. | |
| 40 | + * Encoded label for the confirmation input field. | |
| 42 | 41 | * |
| 43 | 42 | * @var string |
| 44 | 43 | * @since 0.0.2 |
| 45 | 44 | */ |
| @@ -45,9 +44,9 @@ | ||
| 45 | 44 | */ |
| 46 | 45 | protected $input_confirm_label; |
| 47 | 46 | |
| 48 | 47 | /** |
| 49 | - * Unique slug for the confirmation input field, combining the form slug, block ID, and encrypted label. | |
| 48 | + * Unique slug for the confirmation input field, combining the form slug, block ID, and encoded label. | |
| 50 | 49 | * |
| 51 | 50 | * @var string |
| 52 | 51 | * @since 0.0.2 |
| 53 | 52 | */ |
| @@ -61,8 +60,16 @@ | ||
| 61 | 60 | */ |
| 62 | 61 | protected $confirm_label; |
| 63 | 62 | |
| 64 | 63 | /** |
| 64 | + * Read-only attribute for the email field. | |
| 65 | + * | |
| 66 | + * @var bool | |
| 67 | + * @since 1.7.2 | |
| 68 | + */ | |
| 69 | + protected $read_only; | |
| 70 | + | |
| 71 | + /** | |
| 65 | 72 | * Initialize the properties based on block attributes. |
| 66 | 73 | * |
| 67 | 74 | * @param array<mixed> $attributes Block attributes. |
| 68 | 75 | * @since 0.0.2 |
| @@ -72,18 +79,19 @@ | ||
| 72 | 79 | $this->set_input_label( __( 'Email', 'sureforms' ) ); |
| 73 | 80 | $this->set_error_msg( $attributes, 'srfm_email_block_required_text' ); |
| 74 | 81 | $this->set_duplicate_msg( $attributes, 'srfm_email_block_unique_text' ); |
| 75 | 82 | $this->slug = 'email'; |
| 76 | - $this->is_confirm_email = isset( $attributes['isConfirmEmail'] ) ? $attributes['isConfirmEmail'] : false; | |
| 83 | + $this->is_confirm_email = $attributes['isConfirmEmail'] ?? false; | |
| 77 | 84 | $this->input_confirm_label_fallback = __( 'Confirm ', 'sureforms' ) . $this->input_label_fallback; |
| 78 | - $this->input_confirm_label = '-lbl-' . Helper::encrypt( $this->input_confirm_label_fallback ); | |
| 85 | + $this->input_confirm_label = '-lbl-' . Helper::encode( $this->input_confirm_label_fallback ); | |
| 79 | 86 | $this->unique_confirm_slug = 'srfm-' . $this->slug . '-confirm-' . $this->block_id . $this->input_confirm_label; |
| 87 | + $this->read_only = ! empty( trim( $this->default ) ) && $attributes['readOnly']; | |
| 80 | 88 | $this->set_unique_slug(); |
| 81 | 89 | $this->set_field_name( $this->unique_slug ); |
| 82 | 90 | $this->set_markup_properties( $this->input_label, true ); |
| 83 | 91 | $this->set_aria_described_by(); |
| 84 | 92 | // Translators: %s is label of block. |
| 85 | - $this->confirm_label = sprintf( __( 'Confirm %s', 'sureforms' ), $this->label ); | |
| 93 | + $this->confirm_label = ! empty( $attributes['confirmLabel'] ) ? sanitize_text_field( $attributes['confirmLabel'] ) : sprintf( __( 'Confirm %s', 'sureforms' ), $this->label ); | |
| 86 | 94 | $this->set_label_as_placeholder( $this->input_label ); |
| 87 | 95 | } |
| 88 | 96 | |
| 89 | 97 | /** |
| @@ -89,13 +97,22 @@ | ||
| 89 | 97 | /** |
| 90 | 98 | * Render the sureforms email classic styling |
| 91 | 99 | * |
| 92 | 100 | * @since 0.0.2 |
| 93 | - * @return string|boolean | |
| 101 | + * @return string|bool | |
| 94 | 102 | */ |
| 95 | 103 | public function markup() { |
| 104 | + $extra_classes = [ | |
| 105 | + 'srfm-' . $this->slug . '-block-wrap', | |
| 106 | + ]; | |
| 107 | + | |
| 108 | + if ( $this->read_only ) { | |
| 109 | + $extra_classes[] = 'srfm-read-only'; | |
| 110 | + } | |
| 111 | + | |
| 112 | + $this->class_name = $this->get_field_classes( $extra_classes ); | |
| 96 | 113 | ob_start(); ?> |
| 97 | - <div data-block-id="<?php echo esc_attr( $this->block_id ); ?>" class="srfm-block-single srfm-block srfm-<?php echo esc_attr( $this->slug ); ?>-block-wrap<?php echo esc_attr( $this->block_width ); ?><?php echo esc_attr( $this->class_name ); ?> <?php echo esc_attr( $this->conditional_class ); ?>"> | |
| 114 | + <div data-block-id="<?php echo esc_attr( $this->block_id ); ?>" class="<?php echo esc_attr( $this->class_name ); ?>"> | |
| 98 | 115 | <div class="srfm-<?php echo esc_attr( $this->slug ); ?>-block srf-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?>-block"> |
| 99 | 116 | <?php echo wp_kses_post( $this->label_markup ); ?> |
| 100 | 117 | <?php echo wp_kses_post( $this->help_markup ); ?> |
| 101 | 118 | <div class="srfm-block-wrap"> |
| @@ -100,10 +117,9 @@ | ||
| 100 | 117 | <?php echo wp_kses_post( $this->help_markup ); ?> |
| 101 | 118 | <div class="srfm-block-wrap"> |
| 102 | 119 | <input class="srfm-input-common srfm-input-<?php echo esc_attr( $this->slug ); ?>" type="email" name="<?php echo esc_attr( $this->field_name ); ?>" id="<?php echo esc_attr( $this->unique_slug ); ?>" |
| 103 | 120 | <?php echo ! empty( $this->aria_described_by ) ? "aria-describedby='" . esc_attr( trim( $this->aria_described_by ) ) . "'" : ''; ?> |
| 104 | - aria-required="<?php echo esc_attr( strval( $this->aria_require_attr ) ); ?>" data-unique="<?php echo esc_attr( $this->aria_unique ); ?>" <?php echo wp_kses_post( $this->default_value_attr ); ?> <?php echo wp_kses_post( $this->placeholder_attr ); ?> /> | |
| 105 | - <?php echo $this->error_svg; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Ignored to render svg ?> | |
| 121 | + data-required="<?php echo esc_attr( strval( $this->data_require_attr ) ); ?>" aria-required="<?php echo esc_attr( $this->data_require_attr ); ?>" data-unique="<?php echo esc_attr( $this->aria_unique ); ?>" value="<?php echo esc_attr( $this->default ); ?>" <?php echo wp_kses_post( $this->placeholder_attr ); ?> <?php echo $this->read_only ? 'readonly' : ''; ?> /> | |
| 106 | 122 | </div> |
| 107 | 123 | <div class="srfm-error-wrap"> |
| 108 | 124 | <?php echo wp_kses_post( $this->duplicate_msg_markup ); ?> |
| 109 | 125 | </div> |
| @@ -114,27 +130,38 @@ | ||
| 114 | 130 | $placeholder = Helper::generate_common_form_markup( $this->form_id, 'placeholder', $this->confirm_label, $this->slug, $this->block_id . $this->block_id . $this->input_confirm_label, boolval( $this->required ) ); |
| 115 | 131 | $this->placeholder_attr = ''; |
| 116 | 132 | if ( ! empty( $placeholder ) ) { |
| 117 | 133 | $confirm_label_markup = ''; |
| 118 | - $this->placeholder_attr = ' placeholder="' . $placeholder . '" '; | |
| 134 | + $this->placeholder_attr = ' placeholder="' . esc_attr( $placeholder ) . '" '; | |
| 119 | 135 | } |
| 120 | 136 | |
| 137 | + $confirm_error_markup = Helper::generate_common_form_markup( $this->form_id, 'error', '', '', $this->block_id, boolval( $this->required ), '', $this->error_msg, false, '', true ); | |
| 121 | 138 | ?> |
| 122 | 139 | <div class="srfm-<?php echo esc_attr( $this->slug ); ?>-confirm-block srf-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?>-confirm-block"> |
| 123 | 140 | <?php echo wp_kses_post( $confirm_label_markup ); ?> |
| 124 | 141 | <div class="srfm-block-wrap"> |
| 125 | - <input class="srfm-input-common srfm-input-<?php echo esc_attr( $this->slug ); ?>-confirm" type="email" name="<?php echo esc_attr( $this->unique_confirm_slug ); ?>" id="<?php echo esc_attr( $this->unique_confirm_slug ); ?>" | |
| 142 | + <input class="srfm-input-common srfm-input-<?php echo esc_attr( $this->slug ); ?>-confirm" type="email" id="<?php echo esc_attr( $this->unique_confirm_slug ); ?>" | |
| 126 | 143 | <?php echo ! empty( $this->aria_described_by ) ? "aria-describedby='" . esc_attr( trim( $this->aria_described_by ) ) . "'" : ''; ?> |
| 127 | - aria-required="<?php echo esc_attr( $this->aria_require_attr ); ?>" <?php echo wp_kses_post( $this->default_value_attr ); ?> <?php echo wp_kses_post( $this->placeholder_attr ); ?> /> | |
| 128 | - <?php echo $this->error_svg; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Ignored to render svg ?> | |
| 144 | + data-required="<?php echo esc_attr( $this->data_require_attr ); ?>" aria-required="<?php echo esc_attr( $this->data_require_attr ); ?>" value="<?php echo esc_attr( $this->default ); ?>" <?php echo wp_kses_post( $this->placeholder_attr ); ?> <?php echo $this->read_only ? 'readonly' : ''; ?> /> | |
| 129 | 145 | </div> |
| 130 | 146 | <div class="srfm-error-wrap"> |
| 131 | - <?php echo wp_kses_post( $this->error_msg_markup ); ?> | |
| 147 | + <?php echo wp_kses_post( $confirm_error_markup ); ?> | |
| 132 | 148 | </div> |
| 133 | 149 | </div> |
| 134 | 150 | <?php } ?> |
| 135 | 151 | </div> |
| 136 | 152 | <?php |
| 137 | - return ob_get_clean(); | |
| 153 | + $markup = ob_get_clean(); | |
| 154 | + | |
| 155 | + return apply_filters( | |
| 156 | + 'srfm_block_field_markup', | |
| 157 | + $markup, | |
| 158 | + [ | |
| 159 | + 'slug' => $this->slug, | |
| 160 | + 'is_editing' => $this->is_editing, | |
| 161 | + 'field_name' => $this->field_name, | |
| 162 | + 'attributes' => $this->attributes, | |
| 163 | + ] | |
| 164 | + ); | |
| 138 | 165 | } |
| 139 | 166 | |
| 140 | 167 | } |