Current Path : /home/ephorei/www/wp-includes/images/media/q2m9hb/ |
Current File : /home/ephorei/www/wp-includes/images/media/q2m9hb/fields.tar |
class-wp-rest-comment-meta-fields.php 0000644 00000001577 15006000045 0013611 0 ustar 00 <?php /** * REST API: WP_REST_Comment_Meta_Fields class * * @package WordPress * @subpackage REST_API * @since 4.7.0 */ /** * Core class to manage comment meta via the REST API. * * @since 4.7.0 * * @see WP_REST_Meta_Fields */ class WP_REST_Comment_Meta_Fields extends WP_REST_Meta_Fields { /** * Retrieves the comment type for comment meta. * * @since 4.7.0 * * @return string The meta type. */ protected function get_meta_type() { return 'comment'; } /** * Retrieves the comment meta subtype. * * @since 4.9.8 * * @return string 'comment' There are no subtypes. */ protected function get_meta_subtype() { return 'comment'; } /** * Retrieves the type for register_rest_field() in the context of comments. * * @since 4.7.0 * * @return string The REST field type. */ public function get_rest_field_type() { return 'comment'; } } class-wp-rest-meta-fields.php 0000644 00000044122 15006000045 0012142 0 ustar 00 <?php /** * REST API: WP_REST_Meta_Fields class * * @package WordPress * @subpackage REST_API * @since 4.7.0 */ /** * Core class to manage meta values for an object via the REST API. * * @since 4.7.0 */ #[AllowDynamicProperties] abstract class WP_REST_Meta_Fields { /** * Retrieves the object meta type. * * @since 4.7.0 * * @return string One of 'post', 'comment', 'term', 'user', or anything * else supported by `_get_meta_table()`. */ abstract protected function get_meta_type(); /** * Retrieves the object meta subtype. * * @since 4.9.8 * * @return string Subtype for the meta type, or empty string if no specific subtype. */ protected function get_meta_subtype() { return ''; } /** * Retrieves the object type for register_rest_field(). * * @since 4.7.0 * * @return string The REST field type, such as post type name, taxonomy name, 'comment', or `user`. */ abstract protected function get_rest_field_type(); /** * Registers the meta field. * * @since 4.7.0 * @deprecated 5.6.0 * * @see register_rest_field() */ public function register_field() { _deprecated_function( __METHOD__, '5.6.0' ); register_rest_field( $this->get_rest_field_type(), 'meta', array( 'get_callback' => array( $this, 'get_value' ), 'update_callback' => array( $this, 'update_value' ), 'schema' => $this->get_field_schema(), ) ); } /** * Retrieves the meta field value. * * @since 4.7.0 * * @param int $object_id Object ID to fetch meta for. * @param WP_REST_Request $request Full details about the request. * @return array Array containing the meta values keyed by name. */ public function get_value( $object_id, $request ) { $fields = $this->get_registered_fields(); $response = array(); foreach ( $fields as $meta_key => $args ) { $name = $args['name']; $all_values = get_metadata( $this->get_meta_type(), $object_id, $meta_key, false ); if ( $args['single'] ) { if ( empty( $all_values ) ) { $value = $args['schema']['default']; } else { $value = $all_values[0]; } $value = $this->prepare_value_for_response( $value, $request, $args ); } else { $value = array(); if ( is_array( $all_values ) ) { foreach ( $all_values as $row ) { $value[] = $this->prepare_value_for_response( $row, $request, $args ); } } } $response[ $name ] = $value; } return $response; } /** * Prepares a meta value for a response. * * This is required because some native types cannot be stored correctly * in the database, such as booleans. We need to cast back to the relevant * type before passing back to JSON. * * @since 4.7.0 * * @param mixed $value Meta value to prepare. * @param WP_REST_Request $request Current request object. * @param array $args Options for the field. * @return mixed Prepared value. */ protected function prepare_value_for_response( $value, $request, $args ) { if ( ! empty( $args['prepare_callback'] ) ) { $value = call_user_func( $args['prepare_callback'], $value, $request, $args ); } return $value; } /** * Updates meta values. * * @since 4.7.0 * * @param array $meta Array of meta parsed from the request. * @param int $object_id Object ID to fetch meta for. * @return null|WP_Error Null on success, WP_Error object on failure. */ public function update_value( $meta, $object_id ) { $fields = $this->get_registered_fields(); $error = new WP_Error(); foreach ( $fields as $meta_key => $args ) { $name = $args['name']; if ( ! array_key_exists( $name, $meta ) ) { continue; } $value = $meta[ $name ]; /* * A null value means reset the field, which is essentially deleting it * from the database and then relying on the default value. * * Non-single meta can also be removed by passing an empty array. */ if ( is_null( $value ) || ( array() === $value && ! $args['single'] ) ) { $args = $this->get_registered_fields()[ $meta_key ]; if ( $args['single'] ) { $current = get_metadata( $this->get_meta_type(), $object_id, $meta_key, true ); if ( is_wp_error( rest_validate_value_from_schema( $current, $args['schema'] ) ) ) { $error->add( 'rest_invalid_stored_value', /* translators: %s: Custom field key. */ sprintf( __( 'The %s property has an invalid stored value, and cannot be updated to null.' ), $name ), array( 'status' => 500 ) ); continue; } } $result = $this->delete_meta_value( $object_id, $meta_key, $name ); if ( is_wp_error( $result ) ) { $error->merge_from( $result ); } continue; } if ( ! $args['single'] && is_array( $value ) && count( array_filter( $value, 'is_null' ) ) ) { $error->add( 'rest_invalid_stored_value', /* translators: %s: Custom field key. */ sprintf( __( 'The %s property has an invalid stored value, and cannot be updated to null.' ), $name ), array( 'status' => 500 ) ); continue; } $is_valid = rest_validate_value_from_schema( $value, $args['schema'], 'meta.' . $name ); if ( is_wp_error( $is_valid ) ) { $is_valid->add_data( array( 'status' => 400 ) ); $error->merge_from( $is_valid ); continue; } $value = rest_sanitize_value_from_schema( $value, $args['schema'] ); if ( $args['single'] ) { $result = $this->update_meta_value( $object_id, $meta_key, $name, $value ); } else { $result = $this->update_multi_meta_value( $object_id, $meta_key, $name, $value ); } if ( is_wp_error( $result ) ) { $error->merge_from( $result ); continue; } } if ( $error->has_errors() ) { return $error; } return null; } /** * Deletes a meta value for an object. * * @since 4.7.0 * * @param int $object_id Object ID the field belongs to. * @param string $meta_key Key for the field. * @param string $name Name for the field that is exposed in the REST API. * @return true|WP_Error True if meta field is deleted, WP_Error otherwise. */ protected function delete_meta_value( $object_id, $meta_key, $name ) { $meta_type = $this->get_meta_type(); if ( ! current_user_can( "delete_{$meta_type}_meta", $object_id, $meta_key ) ) { return new WP_Error( 'rest_cannot_delete', /* translators: %s: Custom field key. */ sprintf( __( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ), array( 'key' => $name, 'status' => rest_authorization_required_code(), ) ); } if ( null === get_metadata_raw( $meta_type, $object_id, wp_slash( $meta_key ) ) ) { return true; } if ( ! delete_metadata( $meta_type, $object_id, wp_slash( $meta_key ) ) ) { return new WP_Error( 'rest_meta_database_error', __( 'Could not delete meta value from database.' ), array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR, ) ); } return true; } /** * Updates multiple meta values for an object. * * Alters the list of values in the database to match the list of provided values. * * @since 4.7.0 * @since 6.7.0 Stores values into DB even if provided registered default value. * * @param int $object_id Object ID to update. * @param string $meta_key Key for the custom field. * @param string $name Name for the field that is exposed in the REST API. * @param array $values List of values to update to. * @return true|WP_Error True if meta fields are updated, WP_Error otherwise. */ protected function update_multi_meta_value( $object_id, $meta_key, $name, $values ) { $meta_type = $this->get_meta_type(); if ( ! current_user_can( "edit_{$meta_type}_meta", $object_id, $meta_key ) ) { return new WP_Error( 'rest_cannot_update', /* translators: %s: Custom field key. */ sprintf( __( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ), array( 'key' => $name, 'status' => rest_authorization_required_code(), ) ); } $current_values = get_metadata_raw( $meta_type, $object_id, $meta_key, false ); $subtype = get_object_subtype( $meta_type, $object_id ); if ( ! is_array( $current_values ) ) { $current_values = array(); } $to_remove = $current_values; $to_add = $values; foreach ( $to_add as $add_key => $value ) { $remove_keys = array_keys( array_filter( $current_values, function ( $stored_value ) use ( $meta_key, $subtype, $value ) { return $this->is_meta_value_same_as_stored_value( $meta_key, $subtype, $stored_value, $value ); } ) ); if ( empty( $remove_keys ) ) { continue; } if ( count( $remove_keys ) > 1 ) { // To remove, we need to remove first, then add, so don't touch. continue; } $remove_key = $remove_keys[0]; unset( $to_remove[ $remove_key ] ); unset( $to_add[ $add_key ] ); } /* * `delete_metadata` removes _all_ instances of the value, so only call once. Otherwise, * `delete_metadata` will return false for subsequent calls of the same value. * Use serialization to produce a predictable string that can be used by array_unique. */ $to_remove = array_map( 'maybe_unserialize', array_unique( array_map( 'maybe_serialize', $to_remove ) ) ); foreach ( $to_remove as $value ) { if ( ! delete_metadata( $meta_type, $object_id, wp_slash( $meta_key ), wp_slash( $value ) ) ) { return new WP_Error( 'rest_meta_database_error', /* translators: %s: Custom field key. */ sprintf( __( 'Could not update the meta value of %s in database.' ), $meta_key ), array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR, ) ); } } foreach ( $to_add as $value ) { if ( ! add_metadata( $meta_type, $object_id, wp_slash( $meta_key ), wp_slash( $value ) ) ) { return new WP_Error( 'rest_meta_database_error', /* translators: %s: Custom field key. */ sprintf( __( 'Could not update the meta value of %s in database.' ), $meta_key ), array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR, ) ); } } return true; } /** * Updates a meta value for an object. * * @since 4.7.0 * @since 6.7.0 Stores values into DB even if provided registered default value. * * @param int $object_id Object ID to update. * @param string $meta_key Key for the custom field. * @param string $name Name for the field that is exposed in the REST API. * @param mixed $value Updated value. * @return true|WP_Error True if the meta field was updated, WP_Error otherwise. */ protected function update_meta_value( $object_id, $meta_key, $name, $value ) { $meta_type = $this->get_meta_type(); // Do the exact same check for a duplicate value as in update_metadata() to avoid update_metadata() returning false. $old_value = get_metadata_raw( $meta_type, $object_id, $meta_key ); $subtype = get_object_subtype( $meta_type, $object_id ); if ( is_array( $old_value ) && 1 === count( $old_value ) && $this->is_meta_value_same_as_stored_value( $meta_key, $subtype, $old_value[0], $value ) ) { return true; } if ( ! current_user_can( "edit_{$meta_type}_meta", $object_id, $meta_key ) ) { return new WP_Error( 'rest_cannot_update', /* translators: %s: Custom field key. */ sprintf( __( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ), array( 'key' => $name, 'status' => rest_authorization_required_code(), ) ); } if ( ! update_metadata( $meta_type, $object_id, wp_slash( $meta_key ), wp_slash( $value ) ) ) { return new WP_Error( 'rest_meta_database_error', /* translators: %s: Custom field key. */ sprintf( __( 'Could not update the meta value of %s in database.' ), $meta_key ), array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR, ) ); } return true; } /** * Checks if the user provided value is equivalent to a stored value for the given meta key. * * @since 5.5.0 * * @param string $meta_key The meta key being checked. * @param string $subtype The object subtype. * @param mixed $stored_value The currently stored value retrieved from get_metadata(). * @param mixed $user_value The value provided by the user. * @return bool */ protected function is_meta_value_same_as_stored_value( $meta_key, $subtype, $stored_value, $user_value ) { $args = $this->get_registered_fields()[ $meta_key ]; $sanitized = sanitize_meta( $meta_key, $user_value, $this->get_meta_type(), $subtype ); if ( in_array( $args['type'], array( 'string', 'number', 'integer', 'boolean' ), true ) ) { // The return value of get_metadata will always be a string for scalar types. $sanitized = (string) $sanitized; } return $sanitized === $stored_value; } /** * Retrieves all the registered meta fields. * * @since 4.7.0 * * @return array Registered fields. */ protected function get_registered_fields() { $registered = array(); $meta_type = $this->get_meta_type(); $meta_subtype = $this->get_meta_subtype(); $meta_keys = get_registered_meta_keys( $meta_type ); if ( ! empty( $meta_subtype ) ) { $meta_keys = array_merge( $meta_keys, get_registered_meta_keys( $meta_type, $meta_subtype ) ); } foreach ( $meta_keys as $name => $args ) { if ( empty( $args['show_in_rest'] ) ) { continue; } $rest_args = array(); if ( is_array( $args['show_in_rest'] ) ) { $rest_args = $args['show_in_rest']; } $default_args = array( 'name' => $name, 'single' => $args['single'], 'type' => ! empty( $args['type'] ) ? $args['type'] : null, 'schema' => array(), 'prepare_callback' => array( $this, 'prepare_value' ), ); $default_schema = array( 'type' => $default_args['type'], 'title' => empty( $args['label'] ) ? '' : $args['label'], 'description' => empty( $args['description'] ) ? '' : $args['description'], 'default' => isset( $args['default'] ) ? $args['default'] : null, ); $rest_args = array_merge( $default_args, $rest_args ); $rest_args['schema'] = array_merge( $default_schema, $rest_args['schema'] ); $type = ! empty( $rest_args['type'] ) ? $rest_args['type'] : null; $type = ! empty( $rest_args['schema']['type'] ) ? $rest_args['schema']['type'] : $type; if ( null === $rest_args['schema']['default'] ) { $rest_args['schema']['default'] = static::get_empty_value_for_type( $type ); } $rest_args['schema'] = rest_default_additional_properties_to_false( $rest_args['schema'] ); if ( ! in_array( $type, array( 'string', 'boolean', 'integer', 'number', 'array', 'object' ), true ) ) { continue; } if ( empty( $rest_args['single'] ) ) { $rest_args['schema'] = array( 'type' => 'array', 'items' => $rest_args['schema'], ); } $registered[ $name ] = $rest_args; } return $registered; } /** * Retrieves the object's meta schema, conforming to JSON Schema. * * @since 4.7.0 * * @return array Field schema data. */ public function get_field_schema() { $fields = $this->get_registered_fields(); $schema = array( 'description' => __( 'Meta fields.' ), 'type' => 'object', 'context' => array( 'view', 'edit' ), 'properties' => array(), 'arg_options' => array( 'sanitize_callback' => null, 'validate_callback' => array( $this, 'check_meta_is_array' ), ), ); foreach ( $fields as $args ) { $schema['properties'][ $args['name'] ] = $args['schema']; } return $schema; } /** * Prepares a meta value for output. * * Default preparation for meta fields. Override by passing the * `prepare_callback` in your `show_in_rest` options. * * @since 4.7.0 * * @param mixed $value Meta value from the database. * @param WP_REST_Request $request Request object. * @param array $args REST-specific options for the meta key. * @return mixed Value prepared for output. If a non-JsonSerializable object, null. */ public static function prepare_value( $value, $request, $args ) { if ( $args['single'] ) { $schema = $args['schema']; } else { $schema = $args['schema']['items']; } if ( '' === $value && in_array( $schema['type'], array( 'boolean', 'integer', 'number' ), true ) ) { $value = static::get_empty_value_for_type( $schema['type'] ); } if ( is_wp_error( rest_validate_value_from_schema( $value, $schema ) ) ) { return null; } return rest_sanitize_value_from_schema( $value, $schema ); } /** * Check the 'meta' value of a request is an associative array. * * @since 4.7.0 * * @param mixed $value The meta value submitted in the request. * @param WP_REST_Request $request Full details about the request. * @param string $param The parameter name. * @return array|false The meta array, if valid, false otherwise. */ public function check_meta_is_array( $value, $request, $param ) { if ( ! is_array( $value ) ) { return false; } return $value; } /** * Recursively add additionalProperties = false to all objects in a schema if no additionalProperties setting * is specified. * * This is needed to restrict properties of objects in meta values to only * registered items, as the REST API will allow additional properties by * default. * * @since 5.3.0 * @deprecated 5.6.0 Use rest_default_additional_properties_to_false() instead. * * @param array $schema The schema array. * @return array */ protected function default_additional_properties_to_false( $schema ) { _deprecated_function( __METHOD__, '5.6.0', 'rest_default_additional_properties_to_false()' ); return rest_default_additional_properties_to_false( $schema ); } /** * Gets the empty value for a schema type. * * @since 5.3.0 * * @param string $type The schema type. * @return mixed */ protected static function get_empty_value_for_type( $type ) { switch ( $type ) { case 'string': return ''; case 'boolean': return false; case 'integer': return 0; case 'number': return 0.0; case 'array': case 'object': return array(); default: return null; } } } class-wp-rest-term-meta-fields.php 0000644 00000002331 15006000045 0013103 0 ustar 00 <?php /** * REST API: WP_REST_Term_Meta_Fields class * * @package WordPress * @subpackage REST_API * @since 4.7.0 */ /** * Core class used to manage meta values for terms via the REST API. * * @since 4.7.0 * * @see WP_REST_Meta_Fields */ class WP_REST_Term_Meta_Fields extends WP_REST_Meta_Fields { /** * Taxonomy to register fields for. * * @since 4.7.0 * @var string */ protected $taxonomy; /** * Constructor. * * @since 4.7.0 * * @param string $taxonomy Taxonomy to register fields for. */ public function __construct( $taxonomy ) { $this->taxonomy = $taxonomy; } /** * Retrieves the term meta type. * * @since 4.7.0 * * @return string The meta type. */ protected function get_meta_type() { return 'term'; } /** * Retrieves the term meta subtype. * * @since 4.9.8 * * @return string Subtype for the meta type, or empty string if no specific subtype. */ protected function get_meta_subtype() { return $this->taxonomy; } /** * Retrieves the type for register_rest_field(). * * @since 4.7.0 * * @return string The REST field type. */ public function get_rest_field_type() { return 'post_tag' === $this->taxonomy ? 'tag' : $this->taxonomy; } } class-wp-rest-user-meta-fields.php 0000644 00000001530 15006000045 0013112 0 ustar 00 <?php /** * REST API: WP_REST_User_Meta_Fields class * * @package WordPress * @subpackage REST_API * @since 4.7.0 */ /** * Core class used to manage meta values for users via the REST API. * * @since 4.7.0 * * @see WP_REST_Meta_Fields */ class WP_REST_User_Meta_Fields extends WP_REST_Meta_Fields { /** * Retrieves the user meta type. * * @since 4.7.0 * * @return string The user meta type. */ protected function get_meta_type() { return 'user'; } /** * Retrieves the user meta subtype. * * @since 4.9.8 * * @return string 'user' There are no subtypes. */ protected function get_meta_subtype() { return 'user'; } /** * Retrieves the type for register_rest_field(). * * @since 4.7.0 * * @return string The user REST field type. */ public function get_rest_field_type() { return 'user'; } } class-wp-rest-post-meta-fields.php 0000644 00000002334 15006000045 0013124 0 ustar 00 <?php /** * REST API: WP_REST_Post_Meta_Fields class * * @package WordPress * @subpackage REST_API * @since 4.7.0 */ /** * Core class used to manage meta values for posts via the REST API. * * @since 4.7.0 * * @see WP_REST_Meta_Fields */ class WP_REST_Post_Meta_Fields extends WP_REST_Meta_Fields { /** * Post type to register fields for. * * @since 4.7.0 * @var string */ protected $post_type; /** * Constructor. * * @since 4.7.0 * * @param string $post_type Post type to register fields for. */ public function __construct( $post_type ) { $this->post_type = $post_type; } /** * Retrieves the post meta type. * * @since 4.7.0 * * @return string The meta type. */ protected function get_meta_type() { return 'post'; } /** * Retrieves the post meta subtype. * * @since 4.9.8 * * @return string Subtype for the meta type, or empty string if no specific subtype. */ protected function get_meta_subtype() { return $this->post_type; } /** * Retrieves the type for register_rest_field(). * * @since 4.7.0 * * @see register_rest_field() * * @return string The REST field type. */ public function get_rest_field_type() { return $this->post_type; } } number-markup.php 0000644 00000006726 15006154643 0010061 0 ustar 00 <?php /** * Sureforms Number Markup Class file. * * @package sureforms. * @since 0.0.1 */ namespace SRFM\Inc\Fields; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * Sureforms Number Field Markup Class. * * @since 0.0.1 */ class Number_Markup extends Base { /** * Minimum value allowed for the input field. * * @var string * @since 0.0.2 */ protected $min_value; /** * Maximum value allowed for the input field. * * @var string * @since 0.0.2 */ protected $max_value; /** * Format type for the input field. * * @var string * @since 0.0.2 */ protected $format_type; /** * HTML attribute string for the format type. * * @var string * @since 0.0.2 */ protected $format_attr; /** * HTML attribute string for the minimum value. * * @var string * @since 0.0.2 */ protected $min_value_attr; /** * HTML attribute string for the maximum value. * * @var string * @since 0.0.2 */ protected $max_value_attr; /** * Initialize the properties based on block attributes. * * @param array<mixed> $attributes Block attributes. * @since 0.0.2 */ public function __construct( $attributes ) { $this->set_properties( $attributes ); $this->slug = 'number'; $this->min_value = $attributes['minValue'] ?? ''; $this->max_value = $attributes['maxValue'] ?? ''; $this->format_type = $attributes['formatType'] ?? ''; $this->format_attr = $this->format_type ? ' format-type="' . $this->format_type . '" ' : ''; $this->min_value_attr = $this->min_value ? ' min="' . $this->min_value . '" ' : ''; $this->max_value_attr = $this->max_value ? ' max="' . $this->max_value . '" ' : ''; $this->set_input_label( __( 'Number', 'sureforms' ) ); $this->set_error_msg( $attributes, 'srfm_number_block_required_text' ); $this->set_unique_slug(); $this->set_field_name( $this->unique_slug ); $this->set_markup_properties( $this->input_label ); $this->set_aria_described_by(); $this->set_label_as_placeholder( $this->input_label ); } /** * Render the sureforms number classic styling * * @since 0.0.2 * @return string|bool */ public function markup() { ob_start(); ?> <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<?php echo esc_attr( $this->block_width ); ?><?php echo esc_attr( $this->class_name ); ?> <?php echo esc_attr( $this->conditional_class ); ?>"> <?php echo wp_kses_post( $this->label_markup ); ?> <?php echo wp_kses_post( $this->help_markup ); ?> <div class="srfm-block-wrap"> <input class="srfm-input-common srfm-input-<?php echo esc_attr( $this->slug ); ?>" type="text" name="<?php echo esc_attr( $this->field_name ); ?>" id="<?php echo esc_attr( $this->unique_slug ); ?>" <?php echo ! empty( $this->aria_described_by ) ? "aria-describedby='" . esc_attr( trim( $this->aria_described_by ) ) . "'" : ''; ?> data-required="<?php echo esc_attr( $this->data_require_attr ); ?>" <?php echo wp_kses_post( $this->placeholder_attr . '' . $this->default_value_attr . '' . $this->format_attr . '' . $this->min_value_attr . '' . $this->max_value_attr ); ?> /> <?php echo $this->error_svg; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Ignored to render svg ?> </div> <div class="srfm-error-wrap"> <?php echo wp_kses_post( $this->error_msg_markup ); ?> </div> </div> <?php return ob_get_clean(); } } dropdown-markup.php 0000644 00000011256 15006154643 0010417 0 ustar 00 <?php /** * Sureforms Dropdown Markup Class file. * * @package sureforms. * @since 0.0.1 */ namespace SRFM\Inc\Fields; require SRFM_DIR . 'modules/gutenberg/classes/class-spec-gb-helper.php'; use Spec_Gb_Helper; use SRFM\Inc\Helper; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * Sureforms Dropdown Markup Class. * * @since 0.0.1 */ class Dropdown_Markup extends Base { /** * Stores the multi select attribute value. * * @var string * @since 0.0.7 */ protected $multi_select_attr; /** * Stores the search attribute value. * * @var string * @since 0.0.7 */ protected $search_attr; /** * Initialize the properties based on block attributes. * * @param array<mixed> $attributes Block attributes. * @since 0.0.2 */ public function __construct( $attributes ) { $this->set_properties( $attributes ); $this->set_input_label( __( 'Dropdown', 'sureforms' ) ); $this->set_error_msg( $attributes, 'srfm_dropdown_block_required_text' ); $this->slug = 'dropdown'; $this->multi_select_attr = ! empty( $attributes['multiSelect'] ) ? 'true' : 'false'; $this->search_attr = ! empty( $attributes['searchable'] ) ? 'true' : 'false'; $this->set_markup_properties(); $this->set_aria_described_by(); $this->set_label_as_placeholder( $this->input_label ); $this->placeholder = ! empty( $this->placeholder_attr ) ? $this->label : __( 'Select an option', 'sureforms' ); } /** * Render the sureforms dropdown classic styling * * @since 0.0.2 * @return string|bool */ public function markup() { ob_start(); ?> <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 srf-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?>-block<?php echo esc_attr( $this->block_width ); ?><?php echo esc_attr( $this->class_name ); ?> <?php echo esc_attr( $this->conditional_class ); ?>"> <fieldset> <input class="srfm-input-<?php echo esc_attr( $this->slug ); ?>-hidden" data-required="<?php echo esc_attr( $this->data_require_attr ); ?>" <?php echo wp_kses_post( $this->data_attribute_markup() ); ?> name="srfm-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?><?php echo esc_attr( $this->field_name ); ?>" type="hidden" value=""/> <legend class="srfm-block-legend"> <?php echo wp_kses_post( $this->label_markup ); ?> <?php echo wp_kses_post( $this->help_markup ); ?> </legend> <div class="srfm-block-wrap srfm-dropdown-common-wrap"> <?php if ( is_array( $this->options ) ) { ?> <select class="srfm-dropdown-common srfm-<?php echo esc_attr( $this->slug ); ?>-input" <?php echo ! empty( $this->aria_described_by ) ? "aria-describedby='" . esc_attr( trim( $this->aria_described_by ) ) . "'" : ''; ?> data-required="<?php echo esc_attr( $this->data_require_attr ); ?>" <?php echo wp_kses_post( $this->data_attribute_markup() ); ?> name="srfm-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?><?php echo esc_attr( $this->field_name ); ?>" data-multiple="<?php echo esc_attr( $this->multi_select_attr ); ?>" data-searchable="<?php echo esc_attr( $this->search_attr ); ?>" tabindex="0" aria-hidden="true"> <option class="srfm-dropdown-placeholder" value="" disabled selected><?php echo esc_html( $this->placeholder ); ?></option> <?php foreach ( $this->options as $option ) { ?> <?php $icon_svg = Spec_Gb_Helper::render_svg_html( $option['icon'] ?? '', true ); $escaped_icon_svg = htmlspecialchars( Helper::get_string_value( $icon_svg ), ENT_QUOTES, 'UTF-8' ); ?> <option value="<?php echo isset( $option['label'] ) ? esc_html( $option['label'] ) : ''; ?>" data-icon="<?php echo ! empty( $escaped_icon_svg ) ? esc_attr( $escaped_icon_svg ) : ''; ?>"><?php echo isset( $option['label'] ) ? esc_html( $option['label'] ) : ''; ?></option> <?php } ?> </select> <?php } ?> </div> <div class="srfm-error-wrap"> <?php echo wp_kses_post( $this->error_msg_markup ); ?> </div> </fieldset> </div> <?php return ob_get_clean(); } /** * Data attribute markup for min and max value * * @since 0.0.13 * @return string */ protected function data_attribute_markup() { $data_attr = ''; if ( 'false' === $this->multi_select_attr ) { return ''; } if ( $this->min_selection ) { $data_attr .= 'data-min-selection="' . esc_attr( $this->min_selection ) . '"'; } if ( $this->max_selection ) { $data_attr .= 'data-max-selection="' . esc_attr( $this->max_selection ) . '"'; } return $data_attr; } } gdpr-markup.php 0000644 00000006240 15006154643 0007514 0 ustar 00 <?php /** * Sureforms GDPR Markup Class file. * * @package sureforms. * @since 0.0.2 */ namespace SRFM\Inc\Fields; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * Sureforms GDPR Markup Class. * * @since 0.0.2 */ class GDPR_Markup extends Base { /** * Initialize the properties based on block attributes. * * @param array<mixed> $attributes Block attributes. * @since 0.0.2 */ public function __construct( $attributes ) { $this->set_properties( $attributes ); $this->set_input_label( __( 'I consent to have this website store my submitted information so they can respond to my inquiry.', 'sureforms' ) ); $this->set_error_msg( $attributes, 'srfm_gdpr_block_required_text' ); $this->slug = 'gdpr'; $this->required = true; $this->data_require_attr = 'true'; $this->set_markup_properties(); $this->set_aria_described_by(); } /** * Render the sureforms GDPR classic styling * * @since 0.0.2 * @return string|bool */ public function markup() { $label_random_id = 'srfm-' . $this->slug . '-' . wp_rand(); ob_start(); ?> <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 srf-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?>-block<?php echo esc_attr( $this->block_width ); ?><?php echo esc_attr( $this->class_name ); ?> <?php echo esc_attr( $this->conditional_class ); ?>"> <div class="srfm-block-wrap"> <input class="srfm-input-common screen-reader-text srfm-input-<?php echo esc_attr( $this->slug ); ?>" id="<?php echo esc_attr( $label_random_id ); ?>" name="srfm-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?><?php echo esc_attr( $this->field_name ); ?>" <?php echo ! empty( $this->aria_described_by ) ? "aria-describedby='" . esc_attr( trim( $this->aria_described_by ) ) . "'" : ''; ?> data-required="<?php echo esc_attr( $this->data_require_attr ); ?>" type="checkbox" <?php echo esc_attr( $this->checked_attr ); ?>/> <label class="srfm-cbx" for="<?php echo esc_attr( $label_random_id ); ?>"> <span class="srfm-span-wrap"> <svg class="srfm-check-icon" width="12px" height="10px" aria-hidden="true"> <use xlink:href="#srfm-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?>-check"></use> </svg> </span> <span class="srfm-span-wrap srfm-block-label"><?php echo wp_kses( $this->label, $this->allowed_tags ); ?> <span class="srfm-required" aria-label="<?php echo esc_html__( 'Required', 'sureforms' ); ?>"><span aria-hidden="true"> *</span></span></span> </label> <svg class="srfm-inline-svg" aria-hidden="true"> <symbol id="srfm-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?>-check" viewbox="0 0 12 10"> <polyline points="1.5 6 4.5 9 10.5 1"></polyline> </symbol> </svg> </div> <?php echo wp_kses_post( $this->help_markup ); ?> <div class="srfm-error-wrap"> <?php echo wp_kses_post( $this->error_msg_markup ); ?> </div> </div> <?php return ob_get_clean(); } } checkbox-markup.php 0000644 00000006117 15006154643 0010351 0 ustar 00 <?php /** * Sureforms Checkbox Markup Class file. * * @package sureforms. * @since 0.0.1 */ namespace SRFM\Inc\Fields; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * Sureforms Checkbox Markup Class. * * @since 0.0.1 */ class Checkbox_Markup extends Base { /** * Initialize the properties based on block attributes. * * @param array<mixed> $attributes Block attributes. * @since 0.0.2 */ public function __construct( $attributes ) { $this->set_properties( $attributes ); $this->set_input_label( __( 'Checkbox', 'sureforms' ) ); $this->set_error_msg( $attributes, 'srfm_checkbox_block_required_text' ); $this->slug = 'checkbox'; $this->set_markup_properties(); $this->set_aria_described_by(); } /** * Render the sureforms checkbox classic styling * * @since 0.0.2 * @return string|bool */ public function markup() { $label_random_id = 'srfm-' . $this->slug . '-' . wp_rand(); ob_start(); ?> <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 srf-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?>-block<?php echo esc_attr( $this->block_width ); ?><?php echo esc_attr( $this->class_name ); ?> <?php echo esc_attr( $this->conditional_class ); ?>"> <div class="srfm-block-wrap"> <input class="srfm-input-common screen-reader-text srfm-input-<?php echo esc_attr( $this->slug ); ?>" id="<?php echo esc_attr( $label_random_id ); ?>" <?php echo ! empty( $this->aria_described_by ) ? "aria-describedby='" . esc_attr( trim( $this->aria_described_by ) ) . "'" : ''; ?> name="srfm-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?><?php echo esc_attr( $this->field_name ); ?>" data-required="<?php echo esc_attr( $this->data_require_attr ); ?>" type="checkbox" <?php echo esc_attr( $this->checked_attr ); ?>/> <label class="srfm-cbx" for="<?php echo esc_attr( $label_random_id ); ?>"> <span class="srfm-span-wrap"> <svg class="srfm-check-icon" width="12px" height="10px" aria-hidden="true"> <use xlink:href="#srfm-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?>-check"></use> </svg> </span> <span class="srfm-span-wrap srfm-block-label"><?php echo wp_kses( $this->label, $this->allowed_tags ); ?> <?php if ( $this->required ) { ?> <span class="srfm-required" aria-label="<?php echo esc_html__( 'Required', 'sureforms' ); ?>"><span aria-hidden="true"> *</span></span> <?php } ?> </span> </label> <svg class="srfm-inline-svg" aria-hidden="true"> <symbol id="srfm-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?>-check" viewbox="0 0 12 10"> <polyline points="1.5 6 4.5 9 10.5 1"></polyline> </symbol> </svg> </div> <?php echo wp_kses_post( $this->help_markup ); ?> <div class="srfm-error-wrap"> <?php echo wp_kses_post( $this->error_msg_markup ); ?> </div> </div> <?php return ob_get_clean(); } } address-markup.php 0000644 00000003222 15006154643 0010202 0 ustar 00 <?php /** * Sureforms Address Markup Class file. * * @package sureforms. * @since 0.0.1 */ namespace SRFM\Inc\Fields; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * Sureforms Address Markup Class. * * @since 0.0.1 */ class Address_Markup extends Base { /** * Initialize the properties based on block attributes. * * @param array<mixed> $attributes Block attributes. * @since 0.0.2 */ public function __construct( $attributes ) { $this->set_properties( $attributes ); $this->set_input_label( __( 'Address', 'sureforms' ) ); $this->slug = 'address'; $this->set_markup_properties(); } /** * Render the sureforms address classic styling * * @param string $content inner block content. * @since 0.0.2 * @return string|bool */ public function markup( $content = '' ) { ob_start(); ?> <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 srf-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?>-block<?php echo esc_attr( $this->block_width ); ?><?php echo esc_attr( $this->class_name ); ?> <?php echo esc_attr( $this->conditional_class ); ?>"> <fieldset> <legend class="srfm-block-legend"> <?php echo wp_kses_post( $this->label_markup ); ?> <?php echo wp_kses_post( $this->help_markup ); ?> </legend> <div class="srfm-block-wrap"> <?php // phpcs:ignore echo $content; // phpcs:ignoreEnd ?> </div> </fieldset> </div> <?php return ob_get_clean(); } } url-markup.php 0000644 00000004364 15006154643 0007367 0 ustar 00 <?php /** * Sureforms Url Markup Class file. * * @package sureforms. * @since 0.0.1 */ namespace SRFM\Inc\Fields; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * Sureforms Url Field Markup Class. * * @since 0.0.1 */ class Url_Markup extends Base { /** * Initialize the properties based on block attributes. * * @param array<mixed> $attributes Block attributes. * @since 0.0.2 */ public function __construct( $attributes ) { $this->slug = 'url'; $this->set_properties( $attributes ); $this->set_input_label( __( 'Url', 'sureforms' ) ); $this->set_error_msg( $attributes, 'srfm_url_block_required_text' ); $this->set_unique_slug(); $this->set_field_name( $this->unique_slug ); $this->set_markup_properties( $this->input_label, true ); $this->set_aria_described_by(); $this->set_label_as_placeholder( $this->input_label ); } /** * Render the sureforms url classic styling * * @since 0.0.2 * @return string|bool */ public function markup() { ob_start(); ?> <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<?php echo esc_attr( $this->block_width ); ?><?php echo esc_attr( $this->class_name ); ?> <?php echo esc_attr( $this->conditional_class ); ?>"> <?php echo wp_kses_post( $this->label_markup ); ?> <?php echo wp_kses_post( $this->help_markup ); ?> <div class="srfm-block-wrap"> <input class="srfm-input-common srfm-input-<?php echo esc_attr( $this->slug ); ?>" type="text" name="<?php echo esc_attr( $this->field_name ); ?>" id="<?php echo esc_attr( $this->unique_slug ); ?>" <?php echo ! empty( $this->aria_described_by ) ? "aria-describedby='" . esc_attr( trim( $this->aria_described_by ) ) . "'" : ''; ?> data-required="<?php echo esc_attr( $this->data_require_attr ); ?>" <?php echo wp_kses_post( $this->default_value_attr ); ?> <?php echo wp_kses_post( $this->placeholder_attr ); ?>/> <?php echo $this->error_svg; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Ignored to render svg ?> </div> <div class="srfm-error-wrap"> <?php echo wp_kses_post( $this->error_msg_markup ); ?> </div> </div> <?php return ob_get_clean(); } } phone-markup.php 0000644 00000005144 15006154643 0007673 0 ustar 00 <?php /** * Sureforms Phone Markup Class file. * * @package sureforms. * @since 0.0.1 */ namespace SRFM\Inc\Fields; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * Sureforms_Phone_Markup Class. * * @since 0.0.1 */ class Phone_Markup extends Base { /** * Stores the boolean string indicating if the country should be automatically determined. * * @var string * @since 0.0.2 */ protected $auto_country; /** * Initialize the properties based on block attributes. * * @param array<mixed> $attributes Block attributes. * @since 0.0.2 */ public function __construct( $attributes ) { $this->set_properties( $attributes ); $this->set_input_label( __( 'Phone', 'sureforms' ) ); $this->set_error_msg( $attributes, 'srfm_phone_block_required_text' ); $this->set_duplicate_msg( $attributes, 'srfm_phone_block_unique_text' ); $this->slug = 'phone'; $this->auto_country = $attributes['autoCountry'] ?? ''; $this->set_unique_slug(); $this->set_field_name( $this->unique_slug ); $this->set_markup_properties( $this->input_label, true ); $this->set_aria_described_by(); $this->set_label_as_placeholder( $this->input_label ); } /** * Render the sureforms phone classic styling * * @since 0.0.2 * @return string|bool */ public function markup() { ob_start(); ?> <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 srf-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?>-block<?php echo esc_attr( $this->block_width ); ?><?php echo esc_attr( $this->class_name ); ?> <?php echo esc_attr( $this->conditional_class ); ?>"> <?php echo wp_kses_post( $this->label_markup ); ?> <?php echo wp_kses_post( $this->help_markup ); ?> <div class="srfm-block-wrap"> <input type="tel" class="srfm-input-common srfm-input-<?php echo esc_attr( $this->slug ); ?>" name="<?php echo esc_attr( $this->field_name ); ?>" id="<?php echo esc_attr( $this->unique_slug ); ?>" <?php echo ! empty( $this->aria_described_by ) ? "aria-describedby='" . esc_attr( trim( $this->aria_described_by ) ) . "'" : ''; ?> data-required="<?php echo esc_attr( $this->data_require_attr ); ?>" auto-country="<?php echo esc_attr( $this->auto_country ? 'true' : 'false' ); ?>" value="" <?php echo wp_kses_post( $this->placeholder_attr ); ?> data-unique="<?php echo esc_attr( $this->aria_unique ); ?>"> </div> <div class="srfm-error-wrap"> <?php echo wp_kses_post( $this->duplicate_msg_markup ); ?> </div> </div> <?php return ob_get_clean(); } } multichoice-markup.php 0000644 00000014720 15006154643 0011067 0 ustar 00 <?php /** * Sureforms Multichoice Markup Class file. * * @package sureforms. * @since 0.0.1 */ namespace SRFM\Inc\Fields; use Spec_Gb_Helper; use SRFM\Inc\Helper; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * SureForms Multichoice Markup Class. * * @since 0.0.1 */ class Multichoice_Markup extends Base { /** * Flag indicating if only a single selection is allowed. * * @var bool * @since 0.0.2 */ protected $single_selection; /** * Width of the choice input field. * * @var string * @since 0.0.2 */ protected $choice_width; /** * HTML attribute string for the choice width. * * @var string * @since 0.0.2 */ protected $choice_width_attr; /** * HTML attribute string for the input type (radio or checkbox). * * @var string * @since 0.0.2 */ protected $type_attr; /** * SVG type for the input field. * * @var string * @since 0.0.7 */ protected $svg_type; /** * HTML attribute string for the name attribute of the input field. * * @var string * @since 0.0.2 */ protected $name_attr; /** * Flag indicating if the layout is vertical. * * @var bool * @since 0.0.7 */ protected $vertical_layout; /** * Contains value if the option contains icon / image * * @var mixed * @since 0.0.7 */ protected $option_type; /** * Initialize the properties based on block attributes. * * @param array<mixed> $attributes Block attributes. * @since 0.0.2 */ public function __construct( $attributes ) { $this->set_properties( $attributes ); $this->set_input_label( __( 'Multi Choice', 'sureforms' ) ); $this->set_error_msg( $attributes, 'srfm_multi_choice_block_required_text' ); $this->slug = 'multi-choice'; $this->single_selection = $attributes['singleSelection'] ?? false; $this->choice_width = $attributes['choiceWidth'] ?? ''; $this->vertical_layout = $attributes['verticalLayout'] ?? false; $this->option_type = ! empty( $attributes['optionType'] ) && in_array( $attributes['optionType'], [ 'icon', 'image' ], true ) ? $attributes['optionType'] : 'icon'; $this->type_attr = $this->single_selection ? 'radio' : 'checkbox'; $this->svg_type = $this->single_selection ? 'circle' : 'square'; $this->name_attr = $this->single_selection ? 'name="srfm-input-' . esc_attr( $this->slug ) . '-' . esc_attr( $this->block_id ) . '"' : ''; $this->choice_width_attr = $this->choice_width ? 'srfm-choice-width-' . str_replace( '.', '-', $this->choice_width ) : ''; $this->set_markup_properties(); $this->set_aria_described_by(); } /** * Render the sureforms Multichoice classic styling * * @since 0.0.2 * @return string|bool */ public function markup() { $check_svg = Helper::fetch_svg( $this->svg_type . '-checked', 'srfm-' . $this->slug . '-icon', 'aria-hidden="true"' ); $unchecked_svg = Helper::fetch_svg( $this->svg_type . '-unchecked', 'srfm-' . $this->slug . '-icon-unchecked', 'aria-hidden="true"' ); ob_start(); ?> <div data-block-id="<?php echo esc_attr( $this->block_id ); ?>" class="srfm-block-single srfm-block srfm-<?php echo esc_attr( $this->type_attr ); ?>-mode srfm-<?php echo esc_attr( $this->slug ); ?>-block srf-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?>-block<?php echo wp_kses_post( $this->block_width ); ?><?php echo esc_attr( $this->class_name ); ?> <?php echo esc_attr( $this->conditional_class ); ?>"> <fieldset> <input class="srfm-input-<?php echo esc_attr( $this->slug ); ?>-hidden" data-required="<?php echo esc_attr( $this->data_require_attr ); ?>" <?php echo wp_kses_post( $this->data_attribute_markup() ); ?> name="srfm-input-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?><?php echo esc_attr( $this->field_name ); ?>" type="hidden" value=""/> <legend class="srfm-block-legend"> <?php echo wp_kses_post( $this->label_markup ); ?> </legend> <?php echo wp_kses_post( $this->help_markup ); ?> <?php if ( is_array( $this->options ) ) { ?> <div class="srfm-block-wrap <?php echo esc_attr( $this->choice_width_attr ); ?> <?php echo $this->vertical_layout ? 'srfm-vertical-layout' : ''; ?>"> <?php foreach ( $this->options as $i => $option ) { ?> <div class="srfm-<?php echo esc_attr( $this->slug ); ?>-single"> <input type="<?php echo esc_attr( $this->type_attr ); ?>" id="srfm-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id . '-' . $i ); ?>" class="srfm-input-<?php echo esc_attr( $this->slug ); ?>-single" <?php echo wp_kses_post( $this->name_attr ); ?> <?php echo 0 === $i ? 'aria-describedby="' . ( ! empty( $this->aria_described_by ) ? esc_attr( trim( $this->aria_described_by ) ) : '' ) . '"' : ''; ?> /> <div class="srfm-block-content-wrap"> <div class="srfm-option-container"> <?php if ( 'icon' === $this->option_type && ! empty( $option['icon'] ) ) { ?> <span class="srfm-option-icon" aria-hidden="true"> <?php Spec_Gb_Helper::render_svg_html( $option['icon'] ); ?> </span> <?php } elseif ( 'image' === $this->option_type && ! empty( $option['image'] ) ) { ?> <span class="srfm-option-image" aria-hidden="true"> <img src="<?php echo esc_url( $option['image'] ); ?>"/> </span> <?php } ?> <label for="srfm-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id . '-' . $i ); ?>"><?php echo isset( $option['optionTitle'] ) ? esc_html( $option['optionTitle'] ) : ''; ?></label> </div> <div class="srfm-icon-container"><?php echo $check_svg . $unchecked_svg; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Ignored to render svg ?></div> </div> </div> <?php } ?> </div> <?php } ?> <div class="srfm-error-wrap"><?php echo wp_kses_post( $this->error_msg_markup ); ?></div> </fieldset> </div> <?php return ob_get_clean(); } /** * Data attribute markup for min and max value * * @since 0.0.13 * @return string */ protected function data_attribute_markup() { $data_attr = ''; if ( $this->single_selection ) { return ''; } if ( $this->min_selection ) { $data_attr .= 'data-min-selection="' . esc_attr( $this->min_selection ) . '"'; } if ( $this->max_selection ) { $data_attr .= 'data-max-selection="' . esc_attr( $this->max_selection ) . '"'; } return $data_attr; } } textarea-markup.php 0000644 00000006414 15006154643 0010400 0 ustar 00 <?php /** * Sureforms Textarea Markup Class file. * * @package sureforms. * @since 0.0.1 */ namespace SRFM\Inc\Fields; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * Sureforms Textarea Markup Class. * * @since 0.0.1 */ class Textarea_Markup extends Base { /** * Maximum length of text allowed for the textarea. * * @var string * @since 0.0.2 */ protected $max_length; /** * HTML attribute string for the maximum length. * * @var string * @since 0.0.2 */ protected $max_length_attr; /** * HTML string for displaying the maximum length in the UI. * * @var string * @since 0.0.2 */ protected $max_length_html; /** * Number of rows for the textarea. * * @var string * @since 0.0.2 */ protected $rows; /** * HTML attribute string for the number of rows. * * @var string * @since 0.0.2 */ protected $rows_attr; /** * Initialize the properties based on block attributes. * * @param array<mixed> $attributes Block attributes. * @since 0.0.2 */ public function __construct( $attributes ) { $this->set_properties( $attributes ); $this->set_input_label( __( 'Textarea', 'sureforms' ) ); $this->set_error_msg( $attributes, 'srfm_textarea_block_required_text' ); $this->slug = 'textarea'; $this->max_length = $attributes['maxLength'] ?? ''; $this->rows = $attributes['rows'] ?? ''; // html attributes. $this->max_length_attr = $this->max_length ? ' maxLength="' . $this->max_length . '" ' : ''; $this->rows_attr = $this->rows ? ' rows="' . $this->rows . '" ' : ''; $this->max_length_html = '' !== $this->max_length ? '0/' . $this->max_length : ''; $this->set_unique_slug(); $this->set_field_name( $this->unique_slug ); $this->set_markup_properties( $this->input_label ); $this->set_aria_described_by(); $this->set_label_as_placeholder( $this->input_label ); } /** * Render the sureforms textarea classic styling * * @since 0.0.2 * @return string|bool */ public function markup() { ob_start(); ?> <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 srf-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?>-block<?php echo esc_attr( $this->block_width ); ?><?php echo esc_attr( $this->class_name ); ?> <?php echo esc_attr( $this->conditional_class ); ?>"> <?php echo wp_kses_post( $this->label_markup ); ?> <?php echo wp_kses_post( $this->help_markup ); ?> <div class="srfm-block-wrap"> <textarea class="srfm-input-common srfm-input-<?php echo esc_attr( $this->slug ); ?>" name="<?php echo esc_attr( $this->field_name ); ?>" id="<?php echo esc_attr( $this->unique_slug ); ?>" <?php echo ! empty( $this->aria_described_by ) ? "aria-describedby='" . esc_attr( trim( $this->aria_described_by ) ) . "'" : ''; ?> data-required="<?php echo esc_attr( $this->data_require_attr ); ?>" <?php echo wp_kses_post( $this->max_length_attr . '' . $this->rows_attr ); ?> <?php echo wp_kses_post( $this->placeholder_attr ); ?>><?php echo esc_html( $this->default ); ?></textarea> </div> <div class="srfm-error-wrap"> <?php echo wp_kses_post( $this->error_msg_markup ); ?> </div> </div> <?php return ob_get_clean(); } } email-markup.php 0000644 00000013177 15006154643 0007656 0 ustar 00 <?php /** * Sureforms Email Markup Class file. * * @package sureforms. * @since 0.0.1 */ namespace SRFM\Inc\Fields; use SRFM\Inc\Helper; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * SureForms Email Markup Class. * * @since 0.0.1 */ class Email_Markup extends Base { /** * Flag indicating whether email confirmation is required. * * @var bool * @since 0.0.2 */ protected $is_confirm_email; /** * Fallback label for the confirmation input field. * * @var string * @since 0.0.2 */ protected $input_confirm_label_fallback; /** * Encrypted label for the confirmation input field. * * @var string * @since 0.0.2 */ protected $input_confirm_label; /** * Unique slug for the confirmation input field, combining the form slug, block ID, and encrypted label. * * @var string * @since 0.0.2 */ protected $unique_confirm_slug; /** * Retains a copy of Confirmation Email input label. * * @var string * @since 0.0.7 */ protected $confirm_label; /** * Initialize the properties based on block attributes. * * @param array<mixed> $attributes Block attributes. * @since 0.0.2 */ public function __construct( $attributes ) { $this->set_properties( $attributes ); $this->set_input_label( __( 'Email', 'sureforms' ) ); $this->set_error_msg( $attributes, 'srfm_email_block_required_text' ); $this->set_duplicate_msg( $attributes, 'srfm_email_block_unique_text' ); $this->slug = 'email'; $this->is_confirm_email = $attributes['isConfirmEmail'] ?? false; $this->input_confirm_label_fallback = __( 'Confirm ', 'sureforms' ) . $this->input_label_fallback; $this->input_confirm_label = '-lbl-' . Helper::encrypt( $this->input_confirm_label_fallback ); $this->unique_confirm_slug = 'srfm-' . $this->slug . '-confirm-' . $this->block_id . $this->input_confirm_label; $this->set_unique_slug(); $this->set_field_name( $this->unique_slug ); $this->set_markup_properties( $this->input_label, true ); $this->set_aria_described_by(); // Translators: %s is label of block. $this->confirm_label = sprintf( __( 'Confirm %s', 'sureforms' ), $this->label ); $this->set_label_as_placeholder( $this->input_label ); } /** * Render the sureforms email classic styling * * @since 0.0.2 * @return string|bool */ public function markup() { ob_start(); ?> <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 ); ?>"> <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"> <?php echo wp_kses_post( $this->label_markup ); ?> <?php echo wp_kses_post( $this->help_markup ); ?> <div class="srfm-block-wrap"> <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 ); ?>" <?php echo ! empty( $this->aria_described_by ) ? "aria-describedby='" . esc_attr( trim( $this->aria_described_by ) ) . "'" : ''; ?> data-required="<?php echo esc_attr( strval( $this->data_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 ); ?> /> <?php echo $this->error_svg; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Ignored to render svg ?> </div> <div class="srfm-error-wrap"> <?php echo wp_kses_post( $this->duplicate_msg_markup ); ?> </div> </div> <?php if ( true === $this->is_confirm_email ) { $confirm_label_markup = Helper::generate_common_form_markup( $this->form_id, 'label', $this->confirm_label, $this->slug . '-confirm', $this->block_id . $this->input_confirm_label, boolval( $this->required ) ); $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 ) ); $this->placeholder_attr = ''; if ( ! empty( $placeholder ) ) { $confirm_label_markup = ''; $this->placeholder_attr = ' placeholder="' . $placeholder . '" '; } ?> <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"> <?php echo wp_kses_post( $confirm_label_markup ); ?> <div class="srfm-block-wrap"> <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 ); ?>" <?php echo ! empty( $this->aria_described_by ) ? "aria-describedby='" . esc_attr( trim( $this->aria_described_by ) ) . "'" : ''; ?> data-required="<?php echo esc_attr( $this->data_require_attr ); ?>" <?php echo wp_kses_post( $this->default_value_attr ); ?> <?php echo wp_kses_post( $this->placeholder_attr ); ?> /> <?php echo $this->error_svg; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Ignored to render svg ?> </div> <div class="srfm-error-wrap"> <?php echo wp_kses_post( $this->error_msg_markup ); ?> </div> </div> <?php } ?> </div> <?php return ob_get_clean(); } } inlinebutton-markup.php 0000644 00000020425 15006154643 0011273 0 ustar 00 <?php /** * Sureforms Inline Button Markup Class file. * * @package sureforms. * @since 0.0.1 */ namespace SRFM\Inc\Fields; use SRFM\Inc\Helper; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * Sureforms Inline Button Markup Class. * * @since 0.0.2 */ class Inlinebutton_Markup extends Base { /** * Text displayed on the button. * * @var string * @since 0.0.2 */ protected $button_text; /** * Button style inherited from the theme. * * @var string * @since 0.0.2 */ protected $btn_from_theme; /** * Used as a flag which decides whether page break is added. * * @var bool * @since 0.0.2 */ protected $is_page_break; /** * Version of reCAPTCHA to use. * * @var string * @since 0.0.2 */ protected $recaptcha_version; /** * Site key for Google reCAPTCHA. * * @var string * @since 0.0.2 */ protected $google_captcha_site_key; /** * Global setting options for security settings. * * @var array<mixed>|mixed * @since 0.0.2 */ protected $global_setting_options; /** * Flag indicating if padding should be added to the button. * * @var bool * @since 0.0.2 */ protected $add_button_padding; /** * Security type. * * @var string * @since 0.0.5 */ protected $captcha_security_type; /** * Cloudflare Turnstile site key. * * @var string * @since 0.0.5 */ protected $cf_turnstile_site_key; /** * Cloudflare Turnstile appearance mode * * @var string * @since 0.0.5 */ protected $cf_appearance_mode; /** * Security - hCaptcha site key. * * @var string * @since 0.0.5 */ protected $hcaptcha_site_key; /** * Initialize the properties based on block attributes. * * @param array<mixed> $attributes Block attributes. * @since 0.0.2 */ public function __construct( $attributes ) { $this->set_properties( $attributes ); $this->slug = 'inline-button'; $this->button_text = $attributes['buttonText'] ?? ''; $this->btn_from_theme = Helper::get_meta_value( $this->form_id, '_srfm_inherit_theme_button' ); $page_break_settings = defined( 'SRFM_PRO_VER' ) ? get_post_meta( (int) $this->form_id, '_srfm_page_break_settings', true ) : []; $page_break_settings = is_array( $page_break_settings ) ? $page_break_settings : []; $this->is_page_break = $page_break_settings['is_page_break'] ?? false; $this->captcha_security_type = Helper::get_meta_value( $this->form_id, '_srfm_captcha_security_type' ); $this->recaptcha_version = Helper::get_meta_value( $this->form_id, '_srfm_form_recaptcha' ); $this->google_captcha_site_key = ''; $this->global_setting_options = []; if ( 'none' !== $this->captcha_security_type ) { $this->global_setting_options = get_option( 'srfm_security_settings_options' ); } if ( is_array( $this->global_setting_options ) ) { switch ( $this->recaptcha_version ) { case 'v2-checkbox': $this->google_captcha_site_key = $this->global_setting_options['srfm_v2_checkbox_site_key'] ?? ''; break; case 'v2-invisible': $this->google_captcha_site_key = $this->global_setting_options['srfm_v2_invisible_site_key'] ?? ''; break; case 'v3-reCAPTCHA': $this->google_captcha_site_key = $this->global_setting_options['srfm_v3_site_key'] ?? ''; break; default: break; } if ( 'cf-turnstile' === $this->captcha_security_type ) { $this->cf_turnstile_site_key = $this->global_setting_options['srfm_cf_turnstile_site_key'] ?? ''; $this->cf_appearance_mode = $this->global_setting_options['srfm_cf_appearance_mode'] ?? 'auto'; } if ( 'hcaptcha' === $this->captcha_security_type ) { $this->hcaptcha_site_key = $this->global_setting_options['srfm_hcaptcha_site_key'] ?? ''; } } $theme_name = wp_get_theme()->get( 'Name' ); $this->add_button_padding = true; if ( 'Astra' === $theme_name || 'Blocksy' === $theme_name ) { $this->add_button_padding = false; } } /** * Render inline button markup * * @since 0.0.2 * @return string|bool|void */ public function markup() { ob_start(); ?> <?php if ( ! $this->is_page_break ) { ?> <?php if ( $this->captcha_security_type && 'none' !== $this->captcha_security_type ) { ?> <div class="srfm-captcha-container <?php echo esc_attr( 'v3-reCAPTCHA' === $this->recaptcha_version || 'v2-invisible' === $this->recaptcha_version ? 'srfm-display-none' : '' ); ?>"> <?php if ( 'g-recaptcha' === $this->captcha_security_type && 'v2-checkbox' === $this->recaptcha_version ) { ?> <?php echo "<div class='g-recaptcha' data-callback='onSuccess' recaptcha-type='" . esc_attr( $this->recaptcha_version ) . "' data-sitekey='" . esc_attr( strval( $this->google_captcha_site_key ) ) . "'></div>"; ?> <?php } ?> <?php if ( 'cf-turnstile' === $this->captcha_security_type && $this->cf_turnstile_site_key ) { ?> <?php echo "<div id='srfm-cf-sitekey' class='cf-turnstile' data-callback='onSuccess' data-theme='" . esc_attr( strval( $this->cf_appearance_mode ) ) . "' data-sitekey='" . esc_attr( strval( $this->cf_turnstile_site_key ) ) . "'></div>"; ?> <?php } ?> <?php if ( 'hcaptcha' === $this->captcha_security_type && $this->hcaptcha_site_key ) { ?> <?php echo "<div id='srfm-hcaptcha-sitekey' data-callback='onSuccess' class='h-captcha' data-sitekey='" . esc_attr( strval( $this->hcaptcha_site_key ) ) . "'></div>"; ?> <?php } ?> <div class="srfm-validation-error" id="captcha-error" style="display: none;"><?php echo esc_attr__( 'Please verify that you are not a robot.', 'sureforms' ); ?></div> </div> <?php } ?> <div data-block-id="<?php echo esc_attr( $this->block_id ); ?>" class="<?php echo esc_attr( $this->class_name ); ?> <?php echo esc_attr( $this->conditional_class ); ?> srf-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?>-block<?php echo esc_attr( $this->block_width ); ?> srfm-block srfm-custom-button-ctn <?php echo esc_attr( '1' === $this->btn_from_theme ? 'wp-block-button' : '' ); ?>"> <?php if ( 'g-recaptcha' === $this->captcha_security_type ) { if ( 'v3-reCAPTCHA' === $this->recaptcha_version ) { wp_enqueue_script( 'srfm-google-recaptchaV3', 'https://www.google.com/recaptcha/api.js?render=' . esc_js( $this->google_captcha_site_key ), [], SRFM_VER, true ); } if ( 'v2-checkbox' === $this->recaptcha_version ) { wp_enqueue_script( 'google-recaptcha', 'https://www.google.com/recaptcha/api.js', [], SRFM_VER, true ); } if ( 'v2-invisible' === $this->recaptcha_version ) { wp_enqueue_script( 'google-recaptcha-invisible', 'https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit', [ SRFM_SLUG . '-form-submit' ], SRFM_VER, true ); } } if ( 'cf-turnstile' === $this->captcha_security_type ) { // Cloudflare Turnstile script. wp_enqueue_script( // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion SRFM_SLUG . '-cf-turnstile', 'https://challenges.cloudflare.com/turnstile/v0/api.js', [], null, [ false, 'defer' => true, ] ); } if ( 'hcaptcha' === $this->captcha_security_type ) { wp_enqueue_script( 'hcaptcha', 'https://js.hcaptcha.com/1/api.js', [], null, [ 'strategy' => 'defer' ] ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion } ?> <button style="<?php echo $this->btn_from_theme ? '' : ' font-family: inherit; font-weight: var(--wp--custom--font-weight--medium); line-height: normal;'; ?>width:100%;" id="srfm-submit-btn" class="<?php echo esc_attr( 'v2-invisible' === $this->recaptcha_version || 'v3-reCAPTCHA' === $this->recaptcha_version ? 'g-recaptcha ' : '' ); ?> <?php echo esc_attr( '1' === $this->btn_from_theme ? 'wp-block-button__link' : 'srfm-button srfm-submit-button srfm-btn-frontend srfm-custom-button' ); ?> " <?php echo 'v2-invisible' === $this->recaptcha_version || 'v3-reCAPTCHA' === $this->recaptcha_version ? esc_attr( 'recaptcha-type=' . $this->recaptcha_version . ' data-sitekey=' . $this->google_captcha_site_key ) : ''; ?>> <div class="srfm-submit-wrap"> <?php echo esc_html( $this->button_text ); ?> <div class="srfm-loader"></div> </div> </button> <div class="srfm-error-wrap"></div> </div> <?php } return ob_get_clean(); } } input-markup.php 0000644 00000006333 15006154643 0007722 0 ustar 00 <?php /** * Sureforms Input Markup Class file. * * @package sureforms. * @since 0.0.1 */ namespace SRFM\Inc\Fields; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * Sureforms Input Markup Class. * * @since 0.0.1 */ class Input_Markup extends Base { /** * Maximum length of text allowed for an input field. * * @var string * @since 0.0.2 */ protected $max_text_length; /** * Input mask for the input field. * * @var string * @since 0.0.11 */ protected $input_mask; /** * Custom input mask for the input field. * * @var string * @since 0.0.11 */ protected $custom_input_mask; /** * Initialize the properties based on block attributes. * * @param array<mixed> $attributes Block attributes. * @since 0.0.2 */ public function __construct( $attributes ) { $this->slug = 'input'; $this->max_text_length = $attributes['textLength'] ?? ''; $this->input_mask = $attributes['inputMask'] ?? ''; $this->custom_input_mask = 'custom-mask' === $this->input_mask && isset( $attributes['customInputMask'] ) ? $attributes['customInputMask'] : ''; $this->set_properties( $attributes ); $this->set_input_label( __( 'Text Field', 'sureforms' ) ); $this->set_error_msg( $attributes, 'srfm_input_block_required_text' ); $this->set_duplicate_msg( $attributes, 'srfm_input_block_unique_text' ); $this->set_unique_slug(); $this->set_field_name( $this->unique_slug ); $this->set_markup_properties( $this->input_label, true ); $this->set_aria_described_by(); $this->set_label_as_placeholder( $this->input_label ); } /** * Render input markup * * @since 0.0.2 * @return string|bool */ public function markup() { ob_start(); ?> <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 srf-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?>-block<?php echo esc_attr( $this->block_width ); ?><?php echo esc_attr( $this->class_name ); ?> <?php echo esc_attr( $this->conditional_class ); ?>"> <?php echo wp_kses_post( $this->label_markup ); ?> <?php echo wp_kses_post( $this->help_markup ); ?> <div class="srfm-block-wrap"> <input class="srfm-input-common srfm-input-<?php echo esc_attr( $this->slug ); ?>" type="text" name="<?php echo esc_attr( $this->field_name ); ?>" id="<?php echo esc_attr( $this->unique_slug ); ?>" <?php echo ! empty( $this->aria_described_by ) ? "aria-describedby='" . esc_attr( trim( $this->aria_described_by ) ) . "'" : ''; ?> data-required="<?php echo esc_attr( strval( $this->data_require_attr ) ); ?>" data-unique="<?php echo esc_attr( $this->aria_unique ); ?>" maxlength="<?php echo esc_attr( $this->max_text_length ); ?>" value="<?php echo esc_attr( $this->default ); ?>" <?php echo wp_kses_post( $this->placeholder_attr ); ?> data-srfm-mask="<?php echo esc_attr( $this->input_mask ); ?>" <?php echo ! empty( $this->custom_input_mask ) ? 'data-custom-srfm-mask="' . esc_attr( $this->custom_input_mask ) . '"' : ''; ?> /> </div> <div class="srfm-error-wrap"> <?php echo wp_kses_post( $this->duplicate_msg_markup ); ?> </div> </div> <?php return ob_get_clean(); } } countries.json 0000644 00000040762 15006154643 0007467 0 ustar 00 [ { "name": "Afghanistan", "dial_code": "+93", "code": "AF" }, { "name": "Aland Islands", "dial_code": "+358", "code": "AX" }, { "name": "Albania", "dial_code": "+355", "code": "AL" }, { "name": "Algeria", "dial_code": "+213", "code": "DZ" }, { "name": "American Samoa", "dial_code": "+1684", "code": "AS" }, { "name": "Andorra", "dial_code": "+376", "code": "AD" }, { "name": "Angola", "dial_code": "+244", "code": "AO" }, { "name": "Anguilla", "dial_code": "+1264", "code": "AI" }, { "name": "Antarctica", "dial_code": "+672", "code": "AQ" }, { "name": "Antigua and Barbuda", "dial_code": "+1268", "code": "AG" }, { "name": "Argentina", "dial_code": "+54", "code": "AR" }, { "name": "Armenia", "dial_code": "+374", "code": "AM" }, { "name": "Aruba", "dial_code": "+297", "code": "AW" }, { "name": "Australia", "dial_code": "+61", "code": "AU" }, { "name": "Austria", "dial_code": "+43", "code": "AT" }, { "name": "Azerbaijan", "dial_code": "+994", "code": "AZ" }, { "name": "Bahamas", "dial_code": "+1242", "code": "BS" }, { "name": "Bahrain", "dial_code": "+973", "code": "BH" }, { "name": "Bangladesh", "dial_code": "+880", "code": "BD" }, { "name": "Barbados", "dial_code": "+1246", "code": "BB" }, { "name": "Belarus", "dial_code": "+375", "code": "BY" }, { "name": "Belgium", "dial_code": "+32", "code": "BE" }, { "name": "Belize", "dial_code": "+501", "code": "BZ" }, { "name": "Benin", "dial_code": "+229", "code": "BJ" }, { "name": "Bermuda", "dial_code": "+1441", "code": "BM" }, { "name": "Bhutan", "dial_code": "+975", "code": "BT" }, { "name": "Bolivia, Plurinational State of", "dial_code": "+591", "code": "BO" }, { "name": "Bosnia and Herzegovina", "dial_code": "+387", "code": "BA" }, { "name": "Botswana", "dial_code": "+267", "code": "BW" }, { "name": "Brazil", "dial_code": "+55", "code": "BR" }, { "name": "British Indian Ocean Territory", "dial_code": "+246", "code": "IO" }, { "name": "Brunei Darussalam", "dial_code": "+673", "code": "BN" }, { "name": "Bulgaria", "dial_code": "+359", "code": "BG" }, { "name": "Burkina Faso", "dial_code": "+226", "code": "BF" }, { "name": "Burundi", "dial_code": "+257", "code": "BI" }, { "name": "Cambodia", "dial_code": "+855", "code": "KH" }, { "name": "Cameroon", "dial_code": "+237", "code": "CM" }, { "name": "Canada", "dial_code": "+1", "code": "CA" }, { "name": "Cape Verde", "dial_code": "+238", "code": "CV" }, { "name": "Cayman Islands", "dial_code": "+ 345", "code": "KY" }, { "name": "Central African Republic", "dial_code": "+236", "code": "CF" }, { "name": "Chad", "dial_code": "+235", "code": "TD" }, { "name": "Chile", "dial_code": "+56", "code": "CL" }, { "name": "China", "dial_code": "+86", "code": "CN" }, { "name": "Christmas Island", "dial_code": "+61", "code": "CX" }, { "name": "Cocos (Keeling) Islands", "dial_code": "+61", "code": "CC" }, { "name": "Colombia", "dial_code": "+57", "code": "CO" }, { "name": "Comoros", "dial_code": "+269", "code": "KM" }, { "name": "Congo", "dial_code": "+242", "code": "CG" }, { "name": "Congo, The Democratic Republic of the Congo", "dial_code": "+243", "code": "CD" }, { "name": "Cook Islands", "dial_code": "+682", "code": "CK" }, { "name": "Costa Rica", "dial_code": "+506", "code": "CR" }, { "name": "Cote d'Ivoire", "dial_code": "+225", "code": "CI" }, { "name": "Croatia", "dial_code": "+385", "code": "HR" }, { "name": "Cuba", "dial_code": "+53", "code": "CU" }, { "name": "Cyprus", "dial_code": "+357", "code": "CY" }, { "name": "Czech Republic", "dial_code": "+420", "code": "CZ" }, { "name": "Denmark", "dial_code": "+45", "code": "DK" }, { "name": "Djibouti", "dial_code": "+253", "code": "DJ" }, { "name": "Dominica", "dial_code": "+1767", "code": "DM" }, { "name": "Dominican Republic", "dial_code": "+1849", "code": "DO" }, { "name": "Ecuador", "dial_code": "+593", "code": "EC" }, { "name": "Egypt", "dial_code": "+20", "code": "EG" }, { "name": "El Salvador", "dial_code": "+503", "code": "SV" }, { "name": "Equatorial Guinea", "dial_code": "+240", "code": "GQ" }, { "name": "Eritrea", "dial_code": "+291", "code": "ER" }, { "name": "Estonia", "dial_code": "+372", "code": "EE" }, { "name": "Ethiopia", "dial_code": "+251", "code": "ET" }, { "name": "Falkland Islands (Malvinas)", "dial_code": "+500", "code": "FK" }, { "name": "Faroe Islands", "dial_code": "+298", "code": "FO" }, { "name": "Fiji", "dial_code": "+679", "code": "FJ" }, { "name": "Finland", "dial_code": "+358", "code": "FI" }, { "name": "France", "dial_code": "+33", "code": "FR" }, { "name": "French Guiana", "dial_code": "+594", "code": "GF" }, { "name": "French Polynesia", "dial_code": "+689", "code": "PF" }, { "name": "Gabon", "dial_code": "+241", "code": "GA" }, { "name": "Gambia", "dial_code": "+220", "code": "GM" }, { "name": "Georgia", "dial_code": "+995", "code": "GE" }, { "name": "Germany", "dial_code": "+49", "code": "DE" }, { "name": "Ghana", "dial_code": "+233", "code": "GH" }, { "name": "Gibraltar", "dial_code": "+350", "code": "GI" }, { "name": "Greece", "dial_code": "+30", "code": "GR" }, { "name": "Greenland", "dial_code": "+299", "code": "GL" }, { "name": "Grenada", "dial_code": "+1473", "code": "GD" }, { "name": "Guadeloupe", "dial_code": "+590", "code": "GP" }, { "name": "Guam", "dial_code": "+1671", "code": "GU" }, { "name": "Guatemala", "dial_code": "+502", "code": "GT" }, { "name": "Guernsey", "dial_code": "+44", "code": "GG" }, { "name": "Guinea", "dial_code": "+224", "code": "GN" }, { "name": "Guinea-Bissau", "dial_code": "+245", "code": "GW" }, { "name": "Guyana", "dial_code": "+595", "code": "GY" }, { "name": "Haiti", "dial_code": "+509", "code": "HT" }, { "name": "Holy See (Vatican City State)", "dial_code": "+379", "code": "VA" }, { "name": "Honduras", "dial_code": "+504", "code": "HN" }, { "name": "Hong Kong", "dial_code": "+852", "code": "HK" }, { "name": "Hungary", "dial_code": "+36", "code": "HU" }, { "name": "Iceland", "dial_code": "+354", "code": "IS" }, { "name": "India", "dial_code": "+91", "code": "IN" }, { "name": "Indonesia", "dial_code": "+62", "code": "ID" }, { "name": "Iran, Islamic Republic of Persian Gulf", "dial_code": "+98", "code": "IR" }, { "name": "Iraq", "dial_code": "+964", "code": "IQ" }, { "name": "Ireland", "dial_code": "+353", "code": "IE" }, { "name": "Isle of Man", "dial_code": "+44", "code": "IM" }, { "name": "Israel", "dial_code": "+972", "code": "IL" }, { "name": "Italy", "dial_code": "+39", "code": "IT" }, { "name": "Jamaica", "dial_code": "+1876", "code": "JM" }, { "name": "Japan", "dial_code": "+81", "code": "JP" }, { "name": "Jersey", "dial_code": "+44", "code": "JE" }, { "name": "Jordan", "dial_code": "+962", "code": "JO" }, { "name": "Kazakhstan", "dial_code": "+77", "code": "KZ" }, { "name": "Kenya", "dial_code": "+254", "code": "KE" }, { "name": "Kiribati", "dial_code": "+686", "code": "KI" }, { "name": "Korea, Democratic People's Republic of Korea", "dial_code": "+850", "code": "KP" }, { "name": "Korea, Republic of South Korea", "dial_code": "+82", "code": "KR" }, { "name": "Kuwait", "dial_code": "+965", "code": "KW" }, { "name": "Kyrgyzstan", "dial_code": "+996", "code": "KG" }, { "name": "Laos", "dial_code": "+856", "code": "LA" }, { "name": "Latvia", "dial_code": "+371", "code": "LV" }, { "name": "Lebanon", "dial_code": "+961", "code": "LB" }, { "name": "Lesotho", "dial_code": "+266", "code": "LS" }, { "name": "Liberia", "dial_code": "+231", "code": "LR" }, { "name": "Libyan Arab Jamahiriya", "dial_code": "+218", "code": "LY" }, { "name": "Liechtenstein", "dial_code": "+423", "code": "LI" }, { "name": "Lithuania", "dial_code": "+370", "code": "LT" }, { "name": "Luxembourg", "dial_code": "+352", "code": "LU" }, { "name": "Macao", "dial_code": "+853", "code": "MO" }, { "name": "Macedonia", "dial_code": "+389", "code": "MK" }, { "name": "Madagascar", "dial_code": "+261", "code": "MG" }, { "name": "Malawi", "dial_code": "+265", "code": "MW" }, { "name": "Malaysia", "dial_code": "+60", "code": "MY" }, { "name": "Maldives", "dial_code": "+960", "code": "MV" }, { "name": "Mali", "dial_code": "+223", "code": "ML" }, { "name": "Malta", "dial_code": "+356", "code": "MT" }, { "name": "Marshall Islands", "dial_code": "+692", "code": "MH" }, { "name": "Martinique", "dial_code": "+596", "code": "MQ" }, { "name": "Mauritania", "dial_code": "+222", "code": "MR" }, { "name": "Mauritius", "dial_code": "+230", "code": "MU" }, { "name": "Mayotte", "dial_code": "+262", "code": "YT" }, { "name": "Mexico", "dial_code": "+52", "code": "MX" }, { "name": "Micronesia, Federated States of Micronesia", "dial_code": "+691", "code": "FM" }, { "name": "Moldova", "dial_code": "+373", "code": "MD" }, { "name": "Monaco", "dial_code": "+377", "code": "MC" }, { "name": "Mongolia", "dial_code": "+976", "code": "MN" }, { "name": "Montenegro", "dial_code": "+382", "code": "ME" }, { "name": "Montserrat", "dial_code": "+1664", "code": "MS" }, { "name": "Morocco", "dial_code": "+212", "code": "MA" }, { "name": "Mozambique", "dial_code": "+258", "code": "MZ" }, { "name": "Myanmar", "dial_code": "+95", "code": "MM" }, { "name": "Namibia", "dial_code": "+264", "code": "NA" }, { "name": "Nauru", "dial_code": "+674", "code": "NR" }, { "name": "Nepal", "dial_code": "+977", "code": "NP" }, { "name": "Netherlands", "dial_code": "+31", "code": "NL" }, { "name": "Netherlands Antilles", "dial_code": "+599", "code": "AN" }, { "name": "New Caledonia", "dial_code": "+687", "code": "NC" }, { "name": "New Zealand", "dial_code": "+64", "code": "NZ" }, { "name": "Nicaragua", "dial_code": "+505", "code": "NI" }, { "name": "Niger", "dial_code": "+227", "code": "NE" }, { "name": "Nigeria", "dial_code": "+234", "code": "NG" }, { "name": "Niue", "dial_code": "+683", "code": "NU" }, { "name": "Norfolk Island", "dial_code": "+672", "code": "NF" }, { "name": "Northern Mariana Islands", "dial_code": "+1670", "code": "MP" }, { "name": "Norway", "dial_code": "+47", "code": "NO" }, { "name": "Oman", "dial_code": "+968", "code": "OM" }, { "name": "Pakistan", "dial_code": "+92", "code": "PK" }, { "name": "Palau", "dial_code": "+680", "code": "PW" }, { "name": "Palestinian Territory, Occupied", "dial_code": "+970", "code": "PS" }, { "name": "Panama", "dial_code": "+507", "code": "PA" }, { "name": "Papua New Guinea", "dial_code": "+675", "code": "PG" }, { "name": "Paraguay", "dial_code": "+595", "code": "PY" }, { "name": "Peru", "dial_code": "+51", "code": "PE" }, { "name": "Philippines", "dial_code": "+63", "code": "PH" }, { "name": "Pitcairn", "dial_code": "+872", "code": "PN" }, { "name": "Poland", "dial_code": "+48", "code": "PL" }, { "name": "Portugal", "dial_code": "+351", "code": "PT" }, { "name": "Puerto Rico", "dial_code": "+1939", "code": "PR" }, { "name": "Qatar", "dial_code": "+974", "code": "QA" }, { "name": "Romania", "dial_code": "+40", "code": "RO" }, { "name": "Russia", "dial_code": "+7", "code": "RU" }, { "name": "Rwanda", "dial_code": "+250", "code": "RW" }, { "name": "Reunion", "dial_code": "+262", "code": "RE" }, { "name": "Saint Barthelemy", "dial_code": "+590", "code": "BL" }, { "name": "Saint Helena, Ascension and Tristan Da Cunha", "dial_code": "+290", "code": "SH" }, { "name": "Saint Kitts and Nevis", "dial_code": "+1869", "code": "KN" }, { "name": "Saint Lucia", "dial_code": "+1758", "code": "LC" }, { "name": "Saint Martin", "dial_code": "+590", "code": "MF" }, { "name": "Saint Pierre and Miquelon", "dial_code": "+508", "code": "PM" }, { "name": "Saint Vincent and the Grenadines", "dial_code": "+1784", "code": "VC" }, { "name": "Samoa", "dial_code": "+685", "code": "WS" }, { "name": "San Marino", "dial_code": "+378", "code": "SM" }, { "name": "Sao Tome and Principe", "dial_code": "+239", "code": "ST" }, { "name": "Saudi Arabia", "dial_code": "+966", "code": "SA" }, { "name": "Senegal", "dial_code": "+221", "code": "SN" }, { "name": "Serbia", "dial_code": "+381", "code": "RS" }, { "name": "Seychelles", "dial_code": "+248", "code": "SC" }, { "name": "Sierra Leone", "dial_code": "+232", "code": "SL" }, { "name": "Singapore", "dial_code": "+65", "code": "SG" }, { "name": "Slovakia", "dial_code": "+421", "code": "SK" }, { "name": "Slovenia", "dial_code": "+386", "code": "SI" }, { "name": "Solomon Islands", "dial_code": "+677", "code": "SB" }, { "name": "Somalia", "dial_code": "+252", "code": "SO" }, { "name": "South Africa", "dial_code": "+27", "code": "ZA" }, { "name": "South Sudan", "dial_code": "+211", "code": "SS" }, { "name": "South Georgia and the South Sandwich Islands", "dial_code": "+500", "code": "GS" }, { "name": "Spain", "dial_code": "+34", "code": "ES" }, { "name": "Sri Lanka", "dial_code": "+94", "code": "LK" }, { "name": "Sudan", "dial_code": "+249", "code": "SD" }, { "name": "Suriname", "dial_code": "+597", "code": "SR" }, { "name": "Svalbard and Jan Mayen", "dial_code": "+47", "code": "SJ" }, { "name": "Swaziland", "dial_code": "+268", "code": "SZ" }, { "name": "Sweden", "dial_code": "+46", "code": "SE" }, { "name": "Switzerland", "dial_code": "+41", "code": "CH" }, { "name": "Syrian Arab Republic", "dial_code": "+963", "code": "SY" }, { "name": "Taiwan", "dial_code": "+886", "code": "TW" }, { "name": "Tajikistan", "dial_code": "+992", "code": "TJ" }, { "name": "Tanzania, United Republic of Tanzania", "dial_code": "+255", "code": "TZ" }, { "name": "Thailand", "dial_code": "+66", "code": "TH" }, { "name": "Timor-Leste", "dial_code": "+670", "code": "TL" }, { "name": "Togo", "dial_code": "+228", "code": "TG" }, { "name": "Tokelau", "dial_code": "+690", "code": "TK" }, { "name": "Tonga", "dial_code": "+676", "code": "TO" }, { "name": "Trinidad and Tobago", "dial_code": "+1868", "code": "TT" }, { "name": "Tunisia", "dial_code": "+216", "code": "TN" }, { "name": "Turkey", "dial_code": "+90", "code": "TR" }, { "name": "Turkmenistan", "dial_code": "+993", "code": "TM" }, { "name": "Turks and Caicos Islands", "dial_code": "+1649", "code": "TC" }, { "name": "Tuvalu", "dial_code": "+688", "code": "TV" }, { "name": "Uganda", "dial_code": "+256", "code": "UG" }, { "name": "Ukraine", "dial_code": "+380", "code": "UA" }, { "name": "United Arab Emirates", "dial_code": "+971", "code": "AE" }, { "name": "United Kingdom", "dial_code": "+44", "code": "GB" }, { "name": "United States", "dial_code": "+1", "code": "US" }, { "name": "Uruguay", "dial_code": "+598", "code": "UY" }, { "name": "Uzbekistan", "dial_code": "+998", "code": "UZ" }, { "name": "Vanuatu", "dial_code": "+678", "code": "VU" }, { "name": "Venezuela, Bolivarian Republic of Venezuela", "dial_code": "+58", "code": "VE" }, { "name": "Vietnam", "dial_code": "+84", "code": "VN" }, { "name": "Virgin Islands, British", "dial_code": "+1284", "code": "VG" }, { "name": "Virgin Islands, U.S.", "dial_code": "+1340", "code": "VI" }, { "name": "Wallis and Futuna", "dial_code": "+681", "code": "WF" }, { "name": "Yemen", "dial_code": "+967", "code": "YE" }, { "name": "Zambia", "dial_code": "+260", "code": "ZM" }, { "name": "Zimbabwe", "dial_code": "+263", "code": "ZW" } ] base.php 0000644 00000027305 15006154643 0006202 0 ustar 00 <?php /** * Form Field Base Class. * * This file defines the base class for form fields in the SureForms package. * * @package SureForms * @since 0.0.1 */ namespace SRFM\Inc\Fields; use SRFM\Inc\Helper; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * Field Base Class * * Defines the base class for form fields. * * @since 0.0.1 */ class Base { /** * Flag indicating if the field is required. * * @var bool * @since 0.0.2 */ protected $required; /** * Width of the field. * * @var string * @since 0.0.2 */ protected $field_width; /** * Stores the label for an input field. * The value of this variable specifies the text displayed as the label for the corresponding input field when rendered. * * @var string $label Label used for the input field. * @since 0.0.2 */ protected $label; /** * Stores the string that provides help text. * * @var string $help * @since 0.0.2 */ protected $help; /** * Validation error message for the fields. * * @var string $error_msg Input field validation error message. * @since 0.0.2 */ protected $error_msg; /** * Represents the identifier of the block. * * @var string $block_id Unique identifier representing the block. * @since 0.0.2 */ protected $block_id; /** * Stores the ID of the form. * * @var string $form_id Form ID. * @since 0.0.2 */ protected $form_id; /** * Stores the block slug. * * @var string * @since 0.0.2 */ protected $block_slug; /** * Stores the conditional class. * * @var string $conditional_class class name. * @since 0.0.2 */ protected $conditional_class; /** * Indicates whether the attribute should be set to true or false. * * @var string $data_require_attr Value of the data-required attribute. * @since 0.0.2 */ protected $data_require_attr; /** * Dynamically sets the CSS class for block width based on the field width. * * @var string $block_width The CSS class for block width, dynamically generated from $field_width. * @since 0.0.2 */ protected $block_width; /** * Stores the class name. * * @var string $class_name The value of the class name attribute. * @since 0.0.2 */ protected $class_name; /** * Stores the placeholder text. * * @var string $placeholder HTML field placeholder. * @since 0.0.2 */ protected $placeholder; /** * Stores the HTML placeholder attribute. * * @var string $placeholder_attr HTML field placeholder attribute. * @since 0.0.2 */ protected $placeholder_attr; /** * Default value for the field. * * @var string * @since 0.0.2 */ protected $default; /** * HTML attribute string for the default value. * * @var string * @since 0.0.2 */ protected $default_value_attr; /** * Stores the input label. * * @var string $input_label input label. * @since 0.0.2 */ protected $input_label; /** * Stores the default fallback value of the label for an input field if nothing is specified. * * @var string $input_label_fallback Default fallback value for the input label. * @since 0.0.2 */ protected $input_label_fallback; /** * Stores the field name. * * @var string $field_name HTML field name. * @since 0.0.2 */ protected $field_name; /** * Stores the slug. * * @var string $slug slug value. * @since 0.0.2 */ protected $slug; /** * Unique slug which combines the slug, block ID, and input label. * * @var string * @since 0.0.2 */ protected $unique_slug; /** * Checked state for the field. * * @var string * @since 0.0.2 */ protected $checked; /** * HTML attribute string for the checked state. * * @var string * @since 0.0.2 */ protected $checked_attr; /** * Options for the field. * * @var array<mixed> * @since 0.0.2 */ protected $options; /** * Allowed HTML tags for the field. * * @var array<string, array<array<string>>> * @since 0.0.2 */ protected $allowed_tags; /** * Flag indicating if the field value must be unique. * * @var bool * @since 0.0.2 */ protected $is_unique; /** * Stores the flag if the field value must be unique. * * @var string * @since 0.0.2 */ protected $aria_unique; /** * Duplicate value message for the field. * * @var string * @since 0.0.2 */ protected $duplicate_msg; /** * Stores the help text markup. * * @var string * @since 0.0.2 */ protected $help_markup; /** * Stores the error message markup. * * @var string * @since 0.0.2 */ protected $error_msg_markup; /** * Stores the HTML label markup. * * @var string * @since 0.0.2 */ protected $label_markup; /** * Stores the error icon to be used in HTML markup. * * @var string * @since 0.0.2 */ protected $error_svg; /** * Stores the duplicate message markup for a field. * * @var string * @since 0.0.2 */ protected $duplicate_msg_markup; /** * Stores attribute for aria-describedby. * * @var string * @since 0.0.6 */ protected $aria_described_by; /** * Stores the minimum number of selections required. * * @var string * @since 0.0.13 */ protected $min_selection; /** * Stores the maximum number of selections allowed. * * @var string * @since 0.0.13 */ protected $max_selection; /** * Render the sureforms default * * @since 0.0.2 * @return string|bool */ public function markup() { return ''; } /** * Setter for the properties of class based on block attributes. * * @param array<mixed> $attributes Block attributes. * @since 0.0.2 * @return void */ protected function set_properties( $attributes ) { $this->required = $attributes['required'] ?? false; $this->field_width = $attributes['fieldWidth'] ?? ''; $this->label = $attributes['label'] ?? ''; $this->help = $attributes['help'] ?? ''; $this->block_id = isset( $attributes['block_id'] ) ? Helper::get_string_value( $attributes['block_id'] ) : ''; $this->form_id = isset( $attributes['formId'] ) ? Helper::get_string_value( $attributes['formId'] ) : ''; $this->block_slug = $attributes['slug'] ?? ''; $this->class_name = isset( $attributes['className'] ) ? ' ' . $attributes['className'] : ''; $this->placeholder = $attributes['placeholder'] ?? ''; $this->default = $attributes['defaultValue'] ?? ''; $this->checked = $attributes['checked'] ?? ''; $this->options = $attributes['options'] ?? ''; $this->is_unique = $attributes['isUnique'] ?? false; $this->conditional_class = apply_filters( 'srfm_conditional_logic_classes', $this->form_id, $this->block_id ); $this->data_require_attr = $this->required ? 'true' : 'false'; $this->block_width = $this->field_width ? ' srfm-block-width-' . str_replace( '.', '-', $this->field_width ) : ''; $this->placeholder_attr = $this->placeholder ? ' placeholder="' . $this->placeholder . '" ' : ''; $this->default_value_attr = $this->default ? ' value="' . $this->default . '" ' : ''; $this->checked_attr = $this->checked ? 'checked' : ''; $this->aria_unique = $this->is_unique ? 'true' : 'false'; $this->allowed_tags = [ 'a' => [ 'href' => [], 'target' => [], ], ]; $this->min_selection = $attributes['minValue'] ?? ''; $this->max_selection = $attributes['maxValue'] ?? ''; } /** * Setter for the label of input field if available, otherwise provided value is utilized. * Invokes the set_field_name() function to set the field_name property. * * @param string $value The default fallback text. * @since 0.0.2 * @return void */ protected function set_input_label( $value ) { $this->input_label_fallback = $this->label ? $this->label : $value; $this->input_label = '-lbl-' . Helper::encrypt( $this->input_label_fallback ); $this->set_field_name( $this->input_label ); } /** * Setter for the field name property. * * @param string $string Contains $input_label value or the $unique_slug based on the block. * @since 0.0.2 * @return void */ protected function set_field_name( $string ) { $this->field_name = $string . '-' . $this->block_slug; } /** * Setter for error message for the block. * * @param array<mixed> $attributes Block attributes, expected to contain 'errorMsg' key. * @param string $key meta key name. * @since 0.0.2 * @return void */ protected function set_error_msg( $attributes, $key = '' ) { if ( empty( $key ) ) { $this->error_msg = $attributes['errorMsg'] ?? ''; } else { $this->error_msg = isset( $attributes['errorMsg'] ) && $attributes['errorMsg'] ? $attributes['errorMsg'] : Helper::get_default_dynamic_block_option( $key ); } } /** * Setter for duplicate message value for the block. * * @param array<mixed> $attributes Block attributes, expected to contain 'errorMsg' key. * @param string $key meta key name. * @since 0.0.2 * @return void */ protected function set_duplicate_msg( $attributes, $key ) { $this->duplicate_msg = ! empty( $attributes['duplicateMsg'] ) ? $attributes['duplicateMsg'] : Helper::get_default_dynamic_block_option( $key ); } /** * Setter for unique slug. * * @since 0.0.2 * @return void */ protected function set_unique_slug() { $this->unique_slug = 'srfm-' . $this->slug . '-' . $this->block_id . $this->input_label; } /** * Setter for the markup properties used in rendering the HTML markup of blocks. * The parameters are for generating the label and error message markup of blocks. * * @param string $input_label Optional. Additional label to be appended to the block ID. * @param bool $override Optional. Override for error markup. Default is false. * @since 0.0.2 * @return void */ protected function set_markup_properties( $input_label = '', $override = false ) { $this->help_markup = Helper::generate_common_form_markup( $this->form_id, 'help', '', '', $this->block_id, false, $this->help ); $this->error_msg_markup = Helper::generate_common_form_markup( $this->form_id, 'error', '', '', $this->block_id, boolval( $this->required || $this->min_selection || $this->max_selection ), '', $this->error_msg, false, '', $override ); $type = in_array( $this->slug, [ 'multi-choice', 'dropdown', 'address' ], true ) ? 'label_text' : 'label'; $this->label_markup = Helper::generate_common_form_markup( $this->form_id, $type, $this->label, $this->slug, $this->block_id . $input_label, boolval( $this->required ) ); $this->error_svg = Helper::fetch_svg( 'error', 'srfm-error-icon' ); $this->duplicate_msg_markup = Helper::generate_common_form_markup( $this->form_id, 'error', '', '', $this->block_id, boolval( $this->required ), '', $this->error_msg, false, $this->duplicate_msg, $override ); } /** * This function creates placeholder markup from label * works when user selects option 'Use labels as placeholder' * * @param string $input_label label of block where functionality is required. * @since 0.0.7 * @return void */ protected function set_label_as_placeholder( $input_label = '' ) { $this->placeholder_attr = ''; $placeholder = Helper::generate_common_form_markup( $this->form_id, 'placeholder', $this->label, $this->slug, $this->block_id . $input_label, boolval( $this->required ) ); if ( ! empty( $placeholder ) ) { $this->label_markup = ''; $this->placeholder_attr = ' placeholder="' . $placeholder . '" '; } } /** * Setter for the aria-describedby attribute. * * @since 0.0.6 * @return void */ protected function set_aria_described_by() { $this->aria_described_by .= ' srfm-error-' . $this->block_id; $this->aria_described_by .= ! empty( $this->help ) ? ' srfm-description-' . $this->block_id : ''; } }