name; } /** * Get field type * * @return string */ public function get_type() { return $this->input_type; } /** * Get the fontawesome icon for this field * * @return string */ public function get_icon() { return $this->icon; } /** * Render of the field in the frontend * * @param array $field_settings The field configuration from the db * @param int $form_id The form id * * @return void */ abstract public function render( $field_settings, $form_id, $type = 'post', $post_id = null ); /** * Get the field option settings for form builder * * @return array */ abstract public function get_options_settings(); /** * Get the field props * * Field props are the field properties that saves in the database * * @return array */ abstract public function get_field_props(); public function get_user_data( $user_id, $field ) { return get_user_by( 'id', $user_id )->$field; } /** * Check if its a meta field * * @param array $attr * * @return bool */ public function is_meta( $field_settings ) { if ( isset( $field_settings['is_meta'] ) && $field_settings['is_meta'] === 'yes' ) { return true; } return false; } /** * Get a meta value * * @param int $object_id user_ID or post_ID * @param string $meta_key * @param string $type post or user * @param bool $single * * @return string */ public function get_meta( $object_id, $meta_key, $type = 'post', $single = true ) { if ( ! $object_id ) { return ''; } if ( $type === 'post' ) { return get_post_meta( $object_id, $meta_key, $single ); } return get_user_meta( $object_id, $meta_key, $single ); } /** * The JS template for using in the form builder * * @return array */ public function get_js_settings() { $settings = [ 'template' => $this->get_type(), 'title' => $this->get_name(), 'icon' => $this->get_icon(), 'pro_feature' => $this->is_pro(), 'settings' => $this->get_options_settings(), 'field_props' => $this->get_field_props(), 'is_full_width' => $this->is_full_width(), ]; $validator = $this->get_validator(); if ( $validator ) { $settings['validator'] = $validator; } return apply_filters( 'wpuf_field_get_js_settings', $settings ); } /** * Custom field validator if exists * * @return bool|array */ public function get_validator() { return false; } /** * Check if it's a pro feature * * @return bool */ public function is_pro() { return false; } /** * If this field is full width * * Used in form builder preview (hides the label) * * @return bool */ public function is_full_width() { return false; } /** * Conditional property for all fields * * @return array */ public function default_conditional_prop() { return [ 'condition_status' => 'no', 'cond_field' => [], 'cond_operator' => [ '=' ], 'cond_option' => [ __( '- select -', 'wp-user-frontend' ) ], 'cond_logic' => 'all', ]; } /** * Default attributes of a field * * Child classes should use this default setting and extend it by using `get_field_settings()` function * * @return array */ public function default_attributes() { return [ 'template' => $this->get_type(), 'name' => '', 'label' => $this->get_name(), 'required' => 'no', 'id' => 0, 'width' => 'large', 'css' => '', 'placeholder' => '', 'default' => '', 'size' => 40, 'help' => '', 'is_meta' => 'yes', // wpuf uses it to differentiate meta fields with core fields, maybe removed 'is_new' => true, // introduced by @edi, not sure what it does. Have to remove 'wpuf_cond' => $this->default_conditional_prop(), 'wpuf_visibility' => $this->get_default_visibility_prop(), ]; } /** * Common properties for all kinds of fields * * @param bool $is_meta * * @return array */ public static function get_default_option_settings( $is_meta = true, $exclude = [] ) { $common_properties = [ [ 'name' => 'label', 'title' => __( 'Field Label', 'wp-user-frontend' ), 'type' => 'text', 'section' => 'basic', 'priority' => 10, 'help_text' => __( 'Enter a title of this field', 'wp-user-frontend' ), ], [ 'name' => 'help', 'title' => __( 'Help text', 'wp-user-frontend' ), 'type' => 'text', 'section' => 'basic', 'priority' => 20, 'help_text' => __( 'Give the user some information about this field', 'wp-user-frontend' ), ], [ 'name' => 'required', 'title' => __( 'Required', 'wp-user-frontend' ), 'type' => 'radio', 'options' => [ 'yes' => __( 'Yes', 'wp-user-frontend' ), 'no' => __( 'No', 'wp-user-frontend' ), ], 'section' => 'basic', 'priority' => 21, 'default' => 'no', 'inline' => true, 'help_text' => __( 'Check this option to mark the field required. A form will not submit unless all required fields are provided.', 'wp-user-frontend' ), ], [ 'name' => 'width', 'title' => __( 'Field Size', 'wp-user-frontend' ), 'type' => 'radio', 'options' => [ 'small' => __( 'Small', 'wp-user-frontend' ), 'medium' => __( 'Medium', 'wp-user-frontend' ), 'large' => __( 'Large', 'wp-user-frontend' ), ], 'section' => 'advanced', 'priority' => 21, 'default' => 'large', 'inline' => true, ], [ 'name' => 'css', 'title' => __( 'CSS Class Name', 'wp-user-frontend' ), 'type' => 'text', 'section' => 'advanced', 'priority' => 22, 'help_text' => __( 'Provide a container class name for this field. Available classes: wpuf-col-half, wpuf-col-half-last, wpuf-col-one-third, wpuf-col-one-third-last', 'wp-user-frontend' ), ], // array( // 'name' => 'dynamic', // 'title' => '', // 'type' => 'dynamic-field', // 'section' => 'advanced', // 'priority' => 23, // 'help_text' => __( 'Check this option to allow field to be populated dynamically using hooks/query string/shortcode', 'wp-user-frontend' ), // ), ]; if ( is_wpuf_post_form_builder() ) { $common_properties[] = [ 'name' => 'wpuf_visibility', 'title' => __( 'Visibility', 'wp-user-frontend' ), 'type' => 'visibility', 'section' => 'advanced', 'options' => [ 'everyone' => __( 'Everyone', 'wp-user-frontend' ), 'hidden' => __( 'Hidden', 'wp-user-frontend' ), 'logged_in' => __( 'Logged in users only', 'wp-user-frontend' ), 'subscribed_users' => __( 'Subscription users only', 'wp-user-frontend' ), ], 'priority' => 30, 'inline' => true, 'help_text' => __( 'Select option', 'wp-user-frontend' ), ]; } if ( $is_meta ) { $common_properties[] = [ 'name' => 'name', 'title' => __( 'Meta Key', 'wp-user-frontend' ), 'type' => 'text-meta', 'section' => 'basic', 'priority' => 11, 'help_text' => __( 'Name of the meta key this field will save to', 'wp-user-frontend' ), ]; if ( is_wpuf_post_form_builder() ) { $common_properties = array_merge( $common_properties, [ [ 'name' => 'show_in_post', 'title' => __( 'Show Data in Post', 'wp-user-frontend' ), 'type' => 'radio', 'options' => [ 'yes' => __( 'Yes', 'wp-user-frontend' ), 'no' => __( 'No', 'wp-user-frontend' ), ], 'section' => 'advanced', 'priority' => 24, 'default' => 'yes', 'inline' => true, 'help_text' => __( 'Select Yes if you want to show the field data in single post.', 'wp-user-frontend' ), ], [ 'name' => 'hide_field_label', 'title' => __( 'Hide Field Label in Post', 'wp-user-frontend' ), 'type' => 'radio', 'options' => [ 'yes' => __( 'Yes', 'wp-user-frontend' ), 'no' => __( 'No', 'wp-user-frontend' ), ], 'section' => 'advanced', 'priority' => 24, 'default' => 'no', 'inline' => true, 'help_text' => __( 'Select Yes if you want to hide the field label in single post.', 'wp-user-frontend' ), ], ] ); } } if ( count( $exclude ) ) { foreach ( $common_properties as $key => &$option ) { if ( in_array( $option['name'], $exclude, true ) ) { unset( $common_properties[ $key ] ); } } } return $common_properties; } /** * Common properties of a taxonomy select field * * @param bool $word_restriction * * @return array */ public function get_default_taxonomy_option_setttings( $content_restriction = false, $tax_name ) { $properties = [ [ 'name' => 'type', 'title' => __( 'Type', 'wp-user-frontend' ), 'type' => 'select', 'options' => [ 'select' => __( 'Select', 'wp-user-frontend' ), 'multiselect' => __( 'Multi Select', 'wp-user-frontend' ), 'checkbox' => __( 'Checkbox', 'wp-user-frontend' ), 'text' => __( 'Text Input', 'wp-user-frontend' ), 'ajax' => __( 'Ajax', 'wp-user-frontend' ), ], 'section' => 'advanced', 'priority' => 23, 'default' => 'select', ], [ 'name' => 'first', 'title' => __( 'Select Text', 'wp-user-frontend' ), 'type' => 'text', 'section' => 'basic', 'priority' => 13, 'help_text' => __( "First element of the select dropdown. Leave this empty if you don't want to show this field", 'wp-user-frontend' ), ], [ 'name' => 'show_inline', 'title' => __( 'Show in inline list', 'wp-user-frontend' ), 'type' => 'radio', 'options' => [ 'yes' => __( 'Yes', 'wp-user-frontend' ), 'no' => __( 'No', 'wp-user-frontend' ), ], 'default' => 'no', 'inline' => true, 'section' => 'advanced', 'priority' => 23, 'help_text' => __( 'Show this option in an inline list', 'wp-user-frontend' ), ], [ 'name' => 'orderby', 'title' => __( 'Order By', 'wp-user-frontend' ), 'type' => 'select', 'options' => [ 'name' => __( 'Name', 'wp-user-frontend' ), 'term_id' => __( 'Term ID', 'wp-user-frontend' ), // NOTE: before 2.5 the key was 'id' not 'term_id' 'slug' => __( 'Slug', 'wp-user-frontend' ), 'count' => __( 'Count', 'wp-user-frontend' ), 'term_group' => __( 'Term Group', 'wp-user-frontend' ), ], 'section' => 'advanced', 'priority' => 24, 'default' => 'name', ], [ 'name' => 'order', 'title' => __( 'Order', 'wp-user-frontend' ), 'type' => 'radio', 'inline' => true, 'options' => [ 'ASC' => __( 'ASC', 'wp-user-frontend' ), 'DESC' => __( 'DESC', 'wp-user-frontend' ), ], 'section' => 'advanced', 'priority' => 25, 'default' => 'ASC', ], [ 'name' => 'exclude_type', 'title' => __( 'Selection Type', 'wp-user-frontend' ), 'type' => 'select', 'options' => [ 'exclude' => __( 'Exclude', 'wp-user-frontend' ), 'include' => __( 'Include', 'wp-user-frontend' ), 'child_of' => __( 'Child of', 'wp-user-frontend' ), ], 'section' => 'advanced', 'priority' => 26, 'default' => '', ], [ 'name' => 'exclude', 'title' => __( 'Selection Terms', 'wp-user-frontend' ), 'type' => 'multiselect', 'section' => 'advanced', 'priority' => 27, 'help_text' => __( 'Search the terms name. use ⇦ ⇨ for navigate', 'wp-user-frontend' ), 'options' => wpuf_get_terms( $tax_name ), ], [ 'name' => 'woo_attr', 'type' => 'checkbox', 'is_single_opt' => true, 'options' => [ 'yes' => __( 'This taxonomy is a WooCommerce attribute', 'wp-user-frontend' ), ], 'section' => 'advanced', 'priority' => 28, ], [ 'name' => 'woo_attr_vis', 'type' => 'checkbox', 'is_single_opt' => true, 'options' => [ 'yes' => __( 'Visible on product page', 'wp-user-frontend' ), ], 'section' => 'advanced', 'priority' => 29, 'dependencies' => [ 'woo_attr' => 'yes', ], ], ]; if ( $content_restriction ) { $properties = array_merge( $properties, [ [ 'name' => 'restriction_type', 'title' => __( 'Content restricted by', 'wp-user-frontend' ), 'type' => 'radio', 'options' => [ 'character' => __( 'Character', 'wp-user-frontend' ), 'word' => __( 'Word', 'wp-user-frontend' ), ], 'section' => 'advanced', 'priority' => 15, 'inline' => true, 'default' => 'character', ], [ 'name' => 'content_restriction', 'title' => __( 'Content Restriction', 'wp-user-frontend' ), 'type' => 'text', 'section' => 'advanced', 'priority' => 16, 'help_text' => __( 'Number of characters or words the author to be restricted in', 'wp-user-frontend' ), ], ] ); } return apply_filters( 'wpuf-form-builder-common-taxonomy-fields-properties', $properties ); } /** * Common properties of a text input field * * @param bool $content_restriction * * @return array */ public static function get_default_text_option_settings( $content_restriction = false ) { $properties = [ [ 'name' => 'placeholder', 'title' => __( 'Placeholder text', 'wp-user-frontend' ), // 'type' => 'text-with-tag', 'type' => 'text', 'tag_filter' => 'no_fields', // we don't want to show any fields with merge tags, just basic tags 'section' => 'advanced', 'priority' => 10, 'help_text' => __( 'Text for HTML5 placeholder attribute', 'wp-user-frontend' ), ], [ 'name' => 'default', 'title' => __( 'Default value', 'wp-user-frontend' ), // 'type' => 'text-with-tag', 'type' => 'text', 'tag_filter' => 'no_fields', 'section' => 'advanced', 'priority' => 11, 'help_text' => __( 'The default value this field will have', 'wp-user-frontend' ), ], [ 'name' => 'size', 'title' => __( 'Size', 'wp-user-frontend' ), 'type' => 'text', 'variation' => 'number', 'section' => 'advanced', 'priority' => 20, 'help_text' => __( 'Size of this input field', 'wp-user-frontend' ), ], ]; if ( $content_restriction ) { $properties = array_merge( $properties, [ [ 'name' => 'restriction_type', 'title' => __( 'Content restricted by', 'wp-user-frontend' ), 'type' => 'radio', 'options' => [ 'character' => __( 'Character', 'wp-user-frontend' ), 'word' => __( 'Word', 'wp-user-frontend' ), ], 'section' => 'advanced', 'priority' => 15, 'inline' => true, 'default' => 'character', ], [ 'name' => 'content_restriction', 'title' => __( 'Content Restriction', 'wp-user-frontend' ), 'type' => 'text', 'section' => 'advanced', 'priority' => 16, 'help_text' => __( 'Number of characters or words the author to be restricted in', 'wp-user-frontend' ), ], ] ); } return apply_filters( 'wpuf-form-builder-common-text-fields-properties', $properties ); } /** * Option data for option based fields * * @param bool $is_multiple * * @return array */ public function get_default_option_dropdown_settings( $is_multiple = false ) { return [ 'name' => 'options', 'title' => __( 'Options', 'wp-user-frontend' ), 'type' => 'option-data', 'is_multiple' => $is_multiple, 'section' => 'basic', 'priority' => 12, 'help_text' => __( 'Add options for the form field', 'wp-user-frontend' ), ]; } /** * Common properties of a textarea field * * @return array */ public function get_default_textarea_option_settings() { return [ [ 'name' => 'rows', 'title' => __( 'Rows', 'wp-user-frontend' ), 'type' => 'text', 'section' => 'advanced', 'priority' => 10, 'help_text' => __( 'Number of rows in textarea', 'wp-user-frontend' ), ], [ 'name' => 'cols', 'title' => __( 'Columns', 'wp-user-frontend' ), 'type' => 'text', 'section' => 'advanced', 'priority' => 11, 'help_text' => __( 'Number of columns in textarea', 'wp-user-frontend' ), ], [ 'name' => 'placeholder', 'title' => __( 'Placeholder text', 'wp-user-frontend' ), 'type' => 'text', 'section' => 'advanced', 'priority' => 12, 'help_text' => __( 'Text for HTML5 placeholder attribute', 'wp-user-frontend' ), 'dependencies' => [ 'rich' => 'no', ], ], [ 'name' => 'default', 'title' => __( 'Default value', 'wp-user-frontend' ), 'type' => 'text', 'section' => 'advanced', 'priority' => 13, 'help_text' => __( 'The default value this field will have', 'wp-user-frontend' ), ], [ 'name' => 'rich', 'title' => __( 'Textarea', 'wp-user-frontend' ), 'type' => 'radio', 'options' => [ 'no' => __( 'Normal', 'wp-user-frontend' ), 'yes' => __( 'Rich textarea', 'wp-user-frontend' ), 'teeny' => __( 'Teeny Rich textarea', 'wp-user-frontend' ), ], 'section' => 'advanced', 'priority' => 14, 'default' => 'no', ], [ 'name' => 'restriction_type', 'title' => __( 'Content restricted by', 'wp-user-frontend' ), 'type' => 'radio', 'options' => [ 'character' => __( 'Character', 'wp-user-frontend' ), 'word' => __( 'Word', 'wp-user-frontend' ), ], 'section' => 'advanced', 'priority' => 15, 'inline' => true, 'default' => 'character', ], [ 'name' => 'content_restriction', 'title' => __( 'Content Restriction', 'wp-user-frontend' ), 'type' => 'text', 'section' => 'advanced', 'priority' => 16, 'help_text' => __( 'Number of characters or words the author to be restricted in', 'wp-user-frontend' ), ], ]; } /** * Prints form input label for admin * * @param array $attr * @param int $form_id */ public function field_print_label( $field, $form_id = 0 ) { if ( is_admin() ) { ?>