false, 'is_meta' => true, // in object as public (bool) $meta; 'forms' => array( 'registration' => false, 'submission' => true, 'vendor-contact' => false, 'profile' => false, 'login' => false, ), 'position' => 'custom', 'permissions' => array( 'can_remove_from_formbuilder' => true, 'can_change_meta_key' => true, 'can_add_to_formbuilder' => true, ), 'template' => 'olam_fes_download_features_field', 'title' => 'Olam download features', 'phoenix' => false, ); /** @var array Characteristics are things that can change from field to field of the same field type. Like the placeholder between two email fields. Stored in db. */ public $characteristics = array( 'name' => '', 'template' => 'olam_fes_download_features_field', 'public' => false, 'required' => false, 'label' => '', 'css' => '', 'default' => '', 'size' => '', 'help' => '', 'placeholder' => '', 'multiple' => array(), 'columns' => false, 'size' => '40', ); public function set_title() { $title = _x( 'Olam download features', 'FES Field title translation', 'bmci' ); $title = apply_filters( 'fes_' . $this->name() . '_field_title', $title ); $this->supports['title'] = $title; } /** Returns the HTML to render a field in admin */ public function render_field_admin( $user_id = -2, $readonly = -2 ) { if ( $user_id === -2 ) { $user_id = get_current_user_id(); } if ( $readonly === -2 ) { $readonly = $this->readonly; } $user_id = apply_filters( 'fes_render_repeat_field_user_id_admin', $user_id, $this->id ); $readonly = apply_filters( 'fes_render_repeat_field_readonly_admin', $readonly, $user_id, $this->id ); $value = $this->get_field_value_admin( $this->save_id, $user_id, $readonly ); $add = fes_assets_url .'img/add.png'; $remove = fes_assets_url. 'img/remove.png'; $required = $this->required( $readonly ); $output = ''; $output .= sprintf( '
', $this->template(), $this->name(), $this->css() ); $output .= $this->label( $readonly ); ob_start(); ?>
characteristics['multiple'] ) ) { ?> characteristics['columns'] ); foreach ( $this->characteristics['columns'] as $column ) { ?> 0 ? count( $value ) - 1 : 0; if ( $row_count > 0 ) { for ( $row = 0; $row <= $row_count; $row++ ) { ?>
required_html5( $readonly ); ?> /> <?php esc_attr_e( 'Add another', 'bmci' ); ?> <?php esc_attr_e( 'Remove this choice', 'bmci' ); ?>
required_html5( $readonly ); ?> /> <?php esc_attr_e( 'Add another', 'bmci' ); ?> <?php esc_attr_e( 'Remove this choice', 'bmci' ); ?>
1 ) { foreach ( $value as $item ) { ?>
required_html5( $readonly ); ?> name="name() ); ?>[]" placeholder="placeholder() ); ?>" value="" size="size() ) ?>" /> add another choice remove this choice
required_html5( $readonly ); ?> name="name() ); ?>[]" placeholder="placeholder() ); ?>" value="characteristics['default'] ) ?>" size="size() ); ?>" /> add another choice remove this choice
'; return $output; } /** Returns the HTML to render a field in frontend */ public function render_field_frontend( $user_id = -2, $readonly = -2 ) { if ( $user_id === -2 ) { $user_id = get_current_user_id(); } if ( $readonly === -2 ) { $readonly = $this->readonly; } $user_id = apply_filters( 'fes_render_repeat_field_user_id_frontend', $user_id, $this->id ); $readonly = apply_filters( 'fes_render_repeat_field_readonly_frontend', $readonly, $user_id, $this->id ); $value = $this->get_field_value_frontend( $this->save_id, $user_id, $readonly ); $add = fes_assets_url .'img/add.png'; $remove = fes_assets_url. 'img/remove.png'; $required = $this->required( $readonly ); $output = ''; $output .= sprintf( '
', $this->template(), $this->name(), $this->css() ); $output .= $this->label( $readonly ); ob_start(); ?>
characteristics['multiple'] ) ) { ?> characteristics['columns'] ); foreach ( $this->characteristics['columns'] as $column ) { ?> 0 ? count( $value ) - 1 : 0; if ( $row_count > 0 ) { for ( $row = 0; $row <= $row_count; $row++ ) { ?>
required_html5( $readonly ); ?> /> <?php esc_attr_e( 'Add another', 'bmci' ); ?> <?php esc_attr_e( 'Remove this choice', 'bmci' ); ?>
required_html5( $readonly ); ?> /> <?php esc_attr_e( 'Add another', 'bmci' ); ?> <?php esc_attr_e( 'Remove this choice', 'bmci' ); ?>
1 ) { foreach ( $value as $item ) { ?>
required_html5( $readonly ); ?> name="name() ); ?>[]" placeholder="placeholder() ); ?>" value="" size="size() ) ?>" /> add another choice remove this choice
required_html5( $readonly ); ?> name="name() ); ?>[]" placeholder="placeholder() ); ?>" value="characteristics['default'] ) ?>" size="size() ); ?>" /> add another choice remove this choice
'; return $output; } /** Returns the HTML to render a field for the formbuilder */ public function render_formbuilder_field( $index = -2, $insert = false ) { $removable = $this->can_remove_from_formbuilder(); $tpl = '%s[%d][%s]'; $enable_column_name = sprintf( '%s[%d][multiple]', 'fes_input', $index ); $column_names = sprintf( '%s[%d][columns]', 'fes_input', $index ); $has_column = isset( $this->characteristics['columns'] ) && count( $this->characteristics['columns'] ) > 1 ? true : false; $placeholder_name = sprintf( $tpl, 'fes_input', $index, 'placeholder' ); $default_name = sprintf( $tpl, 'fes_input', $index, 'default' ); $size_name = sprintf( $tpl, 'fes_input', $index, 'size' ); $placeholder_value = esc_attr( $this->placeholder() ); $default_value = esc_attr( $this->characteristics['default'] ); $size_value = esc_attr( $this->size() ); $add = fes_assets_url .'img/add.png'; $remove = fes_assets_url. 'img/remove.png'; ob_start(); ?>
  • legend( $this->title(), $this->get_label(), $removable ); ?> template() ); ?> name(), $this->characteristics, $insert ); ?> characteristics, $this->form_name, true ); ?>
    characteristics['columns'] > 0 ) { foreach ( $this->characteristics['columns'] as $key => $value ) { ?>
    add another choice remove this choice
    add another choice remove this choice
  • template() . '_field_user_id', $user_id, $this->id ); $value = $this->get_field_value_frontend( $this->save_id, $user_id ); ob_start(); ?>
    get_label(); ?>
    template() . '_field_user_id', $user_id, $this->id ); $values = $this->get_field_value_frontend( $this->save_id, $user_id ); $output = ''; return $output; } public function validate( $values = array(), $save_id = -2, $user_id = -2 ) { $name = $this->name(); $return_value = false; if ( !empty( $values[ $name ] ) && $this->required() ) { if ( !empty( $this->characteristics['multiple'] ) ) { if ( is_array( $values[ $name ] ) ){ foreach( $values[ $name ] as $key => $index ){ if ( !empty( $index ) && is_array( $index ) ){ foreach( $index as $column => $value ){ if ( empty( $values[ $name ][ $key ][ $column ] ) ){ $return_value = __( 'Please fill out this field.', 'bmci' ); break; } } } else { $return_value = __( 'Please fill out this field.', 'bmci' ); break; } } } else { $return_value = __( 'Please fill out this field.', 'bmci' ); } } else { if ( is_array( $values[ $name ] ) ){ foreach( $values[ $name ] as $key => $value ){ if ( empty( $values[ $name ][ $key ] ) ){ $return_value = __( 'Please fill out this field.', 'bmci' ); break; } } } else { $return_value = __( 'Please fill out this field.', 'bmci' ); } } } else { // if required but isn't present if ( $this->required() ) { $return_value = __( 'Please fill out this field.', 'bmci' ); } } return apply_filters( 'fes_validate_' . $this->template() . '_field', $return_value, $values, $name, $save_id, $user_id ); } public function sanitize( $values = array(), $save_id = -2, $user_id = -2 ) { $name = $this->name(); if ( ! empty( $values[ $name ] ) ) { $new_value = array(); if ( !empty( $this->characteristics['multiple'] ) ){ if ( is_array( $values[ $name ] ) ){ $i = 0; // we need to re_key the row indexes, as rows may have been deleted foreach( $values[ $name ] as $row_id => $row_values ) { // for each row in table, as $row_id => single row value or array of row_values if ( !empty( $row_values ) && is_array( $row_values ) ) { // if there's more than 1 column in a row foreach( $row_values as $column => $value ){ // for each value in a row $new_value[ $i ][ $column ] = sanitize_text_field( trim( $value ) ); } } $i++; } } } else { // we can only have 1 column if ( is_array( $values[ $name ] ) ){ $i = 0; foreach( $values[ $name ] as $key => $value ){ $new_value[ $i ] = sanitize_text_field( trim( $value ) ); $i++; } } } $values[ $name ] = $new_value; } return apply_filters( 'fes_sanitize_' . $this->template() . '_field', $values, $name, $save_id, $user_id ); } }