'', 'placeholder' => '', 'class' => 'form-control', 'style' => '', 'wrapper_class' => '', 'value' => '', 'name' => $field['id'], 'description' => '', 'type' => 'text', 'limit' => 0, 'conditional_logic' => '', 'show_wrapper' => true, 'custom_attributes' => array(), 'data_type' => '', 'required' => false, 'invalid_message' => 'This is a required field.', 'conditional_operator' => 'OR', 'datalist' => array() ) ); $field['conditional_logic'] = ( '' != $field['conditional_logic'] ) ? json_encode($field['conditional_logic']) : ''; switch ( $field['data_type'] ) { case 'url': $field['class'] .= ' notifier_input_url'; $field['value'] = esc_url( $field['value'] ); break; default: break; } $show_limit_text = ''; if ( 0 != $field['limit'] ) { $show_limit_text = '0 / ' . $field['limit'] . ''; $field['custom_attributes']['data-limit'] = $field['limit']; $field['class'] = $field['class'] . ' force-text-limit'; } // Custom attribute handling $custom_attributes = array(); if ( isset($field['custom_attributes']['disabled']) && 'disabled' == $field['custom_attributes']['disabled'] ) { $field['custom_attributes']['data-disabled'] = 'yes'; } if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) { foreach ( $field['custom_attributes'] as $attribute => $value ) { $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"'; } } if ( $field['required'] ) { $custom_attributes[] = 'required="required"'; } $custom_attributes_string = implode( ' ', $custom_attributes ); if ( $field['show_wrapper'] ) { do_action('notifier_before_meta_field_wrapper', $field, $post); echo '

'; } if ( '' != $field['label'] ) { echo ''; } $datalist_attr = ''; if(!empty($field['datalist'])){ $datalist_attr = ' list="' . esc_attr( $field['id'] ) . '_datalist" data-min-length="0" data-no-results-text=""'; $field['class'] = $field['class'] . ' datalist-field'; } do_action('notifier_before_meta_field', $field, $post); echo ' '; if(!empty($field['datalist'])){ echo ''; foreach($field['datalist'] as $item){ echo ''; } if ( $field['required'] ) { echo '' . wp_kses_post($field['invalid_message']) . ''; } do_action('notifier_after_meta_field', $field, $post); if ( '' != $field['description'] ) { echo '' . wp_kses_post( $field['description'] ) . ''; } do_action('notifier_after_meta_field_description', $field, $post); if ( $field['show_wrapper'] ) { echo '

'; do_action('notifier_after_meta_field_wrapper', $field, $post); } } /** * Output a hidden input box. * * @param array $field */ function notifier_wp_hidden_input( $field ) { global $post; $field = apply_filters ('notifier_wp_hidden_input', $field, $post); $field = wp_parse_args( $field, array( 'class' => '', 'value' => '' ) ); do_action('notifier_before_meta_field', $field, $post); echo ' '; do_action('notifier_after_meta_field', $field, $post); } /** * Output a textarea input box. * * @param array $field */ function notifier_wp_textarea_input( $field ) { global $post; $field = apply_filters ('notifier_wp_textarea_input', $field, $post); $field = wp_parse_args( $field, array( 'label' => '', 'placeholder' => '', 'class' => 'form-control', 'style' => '', 'wrapper_class' => '', 'value' => '', 'name' => $field['id'], 'description' => '', 'limit' => 0, 'conditional_logic' => '', 'show_wrapper' => true, 'custom_attributes' => array(), 'rows' => 2, 'cols' => 20, 'required' => false, 'conditional_operator' => 'OR' ) ); $field['conditional_logic'] = ( '' != $field['conditional_logic'] ) ? json_encode($field['conditional_logic']) : ''; $show_limit_text = ''; if ( $field['limit'] != 0 ) { $show_limit_text = '0 / ' . $field['limit'] . ''; $field['custom_attributes']['data-limit'] = $field['limit']; $field['class'] = $field['class'] . ' force-text-limit'; } // Custom attribute handling $custom_attributes = array(); if ( isset($field['custom_attributes']['disabled']) && 'disabled' == $field['custom_attributes']['disabled'] ) { $field['custom_attributes']['data-disabled'] = 'yes'; } if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) { foreach ( $field['custom_attributes'] as $attribute => $value ) { $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"'; } } if ( $field['required'] ) { $custom_attributes[] = 'required="required"'; } $custom_attributes_string = implode( ' ', $custom_attributes ); if ( $field['show_wrapper'] ) { do_action('notifier_before_meta_field_wrapper', $field, $post); echo '

'; } if ( '' != $field['label'] ) { echo ''; } do_action('notifier_before_meta_field', $field, $post); echo ' '; if ( $field['required'] ) { echo 'This is a required field.'; } do_action('notifier_after_meta_field', $field, $post); if ( '' != $field['description'] ) { echo '' . wp_kses_post( $field['description'] ) . ''; } do_action('notifier_after_meta_field_description', $field, $post); if ( $field['show_wrapper'] ) { echo '

'; do_action('notifier_after_meta_field_wrapper', $field, $post); } } /** * Output a checkbox input box. * * @param array $field */ function notifier_wp_checkbox( $field ) { global $post; $field = apply_filters ('notifier_wp_checkbox', $field, $post); $field = wp_parse_args( $field, array( 'label' => '', 'class' => 'form-control', 'style' => '', 'wrapper_class' => '', 'value' => '', 'cbvalue' => 'yes', 'name' => $field['id'], 'description' => '', 'conditional_logic' => '', 'show_wrapper' => true, 'custom_attributes' => array(), 'required' => false ) ); $field['conditional_logic'] = ( '' != $field['conditional_logic'] ) ? json_encode($field['conditional_logic']) : ''; // Custom attribute handling $custom_attributes = array(); if ( isset($field['custom_attributes']['disabled']) && 'disabled' == $field['custom_attributes']['disabled'] ) { $field['custom_attributes']['data-disabled'] = 'yes'; } if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) { foreach ( $field['custom_attributes'] as $attribute => $value ) { $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"'; } } if ( $field['required'] ) { $custom_attributes[] = 'required="required"'; } $custom_attributes_string = implode( ' ', $custom_attributes ); if ( $field['show_wrapper'] ) { do_action('notifier_before_meta_field_wrapper', $field, $post); echo '

'; } if ( '' != $field['label'] ) { echo ''; } do_action('notifier_before_meta_field', $field, $post); echo ' '; if ( $field['required'] ) { echo 'This is a required field.'; } do_action('notifier_after_meta_field', $field, $post); if ( '' != $field['description'] ) { echo '' . wp_kses_post( $field['description'] ) . ''; } do_action('notifier_after_meta_field_description', $field, $post); if ( $field['show_wrapper'] ) { echo '

'; do_action('notifier_after_meta_field_wrapper', $field, $post); } } /** * Output multiple checkboxes * * @param array $field */ function notifier_wp_multi_checkboxes( $field ) { global $post; $field = apply_filters ('notifier_wp_multi_checkboxes', $field, $post); $field = wp_parse_args( $field, array( 'label' => '', 'class' => 'form-check-input', 'style' => '', 'wrapper_class' => '', 'value' => '', 'name' => $field['id'], 'description' => '', 'conditional_logic' => '', 'show_wrapper' => true, 'custom_attributes' => array(), 'required' => false ) ); $field['conditional_logic'] = ( '' != $field['conditional_logic'] ) ? json_encode($field['conditional_logic']) : ''; // Custom attribute handling $custom_attributes = array(); if ( isset($field['custom_attributes']['disabled']) && 'disabled' == $field['custom_attributes']['disabled'] ) { $field['custom_attributes']['data-disabled'] = 'yes'; } if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) { foreach ( $field['custom_attributes'] as $attribute => $value ) { $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"'; } } $custom_attributes_string = implode( ' ', $custom_attributes ); if ( $field['show_wrapper'] ) { do_action('notifier_before_meta_field_wrapper', $field, $post); echo '
'; } if ( '' != $field['label'] ) { echo '' . wp_kses_post( $field['label'] ) . ''; } do_action('notifier_before_meta_field', $field, $post); echo '
'; foreach ( $field['options'] as $key => $value ) { if(in_array($key, (array) $field['value'])){ $checked = true; $checked_class = 'form-check-checked'; } else{ $checked = false; $checked_class = ''; } echo '
'; } echo '
'; if ( $field['required'] ) { echo 'Please select at least one '.wp_kses_post( strtolower($field['label']) ).'.'; } do_action('notifier_after_meta_field', $field, $post); if ( '' != $field['description'] ) { echo '' . wp_kses_post( $field['description'] ) . ''; } do_action('notifier_after_meta_field_description', $field, $post); if ( $field['show_wrapper'] ) { echo '
'; do_action('notifier_after_meta_field_wrapper', $field, $post); } } /** * Output a select input box. * * @param array $field Data about the field to render. */ function notifier_wp_select( $field ) { global $post; $field = apply_filters ('notifier_wp_select', $field, $post); $field = wp_parse_args( $field, array( 'label' => '', 'class' => 'form-select', 'style' => '', 'wrapper_class' => '', 'value' => '', 'name' => $field['id'], 'description' => '', 'conditional_logic' => '', 'show_wrapper' => true, 'custom_attributes' => array(), 'required' => false ) ); $field['conditional_logic'] = ( '' != $field['conditional_logic'] ) ? json_encode($field['conditional_logic']) : ''; // Custom attribute handling $custom_attributes = array(); if ( isset($field['custom_attributes']['disabled']) && 'disabled' == $field['custom_attributes']['disabled'] ) { $field['custom_attributes']['data-disabled'] = 'yes'; } if ( $field['required'] ) { $custom_attributes[] = 'required="required"'; } if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) { foreach ( $field['custom_attributes'] as $attribute => $value ) { $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"'; } } $custom_attributes_string = implode( ' ', $custom_attributes ); $description = ! empty( $field['description'] ) ? $field['description'] : ''; if ( $field['show_wrapper'] ) { do_action('notifier_before_meta_field_wrapper', $field, $post); echo '

'; } if ( '' != $field['label'] ) { echo ''; } do_action('notifier_before_meta_field', $field, $post); echo ''; if ( $field['required'] ) { echo 'This is a required field.'; } do_action('notifier_after_meta_field', $field, $post); if ( '' != $field['description'] ) { echo '' . wp_kses_post( $field['description'] ) . ''; } do_action('notifier_after_meta_field_description', $field, $post); if ( $field['show_wrapper'] ) { echo '

'; do_action('notifier_after_meta_field_wrapper', $field, $post); } } /** * Output a radio input box. * * @param array $field */ function notifier_wp_radio( $field ) { global $post; $field = apply_filters ('notifier_wp_radio', $field, $post); $field = wp_parse_args( $field, array( 'label' => '', 'class' => 'form-check-input', 'style' => '', 'wrapper_class' => '', 'value' => '', 'name' => $field['id'], 'description' => '', 'conditional_logic' => '', 'show_wrapper' => true, 'custom_attributes' => array() ) ); $field['conditional_logic'] = ( '' != $field['conditional_logic'] ) ? json_encode($field['conditional_logic']) : ''; // Custom attribute handling $custom_attributes = array(); if ( isset($field['custom_attributes']['disabled']) && 'disabled' == $field['custom_attributes']['disabled'] ) { $field['custom_attributes']['data-disabled'] = 'yes'; } if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) { foreach ( $field['custom_attributes'] as $attribute => $value ) { $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"'; } } $custom_attributes_string = implode( ' ', $custom_attributes ); if ( $field['show_wrapper'] ) { do_action('notifier_before_meta_field_wrapper', $field, $post); echo '
'; } if ( '' != $field['label'] ) { echo '' . wp_kses_post( $field['label'] ) . ''; } do_action('notifier_before_meta_field', $field, $post); foreach ( $field['options'] as $key => $value ) { echo '
'; } do_action('notifier_after_meta_field', $field, $post); if ( '' != $field['description'] ) { echo '' . wp_kses_post( $field['description'] ) . ''; } do_action('notifier_after_meta_field_description', $field, $post); if ( $field['show_wrapper'] ) { echo '
'; do_action('notifier_after_meta_field_wrapper', $field, $post); } } /** * Output a file upload input box. * * @param array $field */ function notifier_wp_file_input( $field ) { global $post; $field = apply_filters ('notifier_wp_text_input_args', $field, $post); $field = wp_parse_args( $field, array( 'label' => '', 'placeholder' => '', 'class' => '', 'wrapper_class' => '', 'value' => '', 'name' => $field['id'], 'description' => '', 'conditional_logic' => '', 'show_wrapper' => true, 'custom_attributes' => array(), 'file_types' => array(), 'required' => false ) ); $field['conditional_logic'] = ( '' != $field['conditional_logic'] ) ? json_encode($field['conditional_logic']) : ''; $image_thumb = ''; $video_url = ''; $show_image = 'd-none'; $show_video = 'd-none'; $show_wrapper = 'd-none'; $attachment_id = isset($field['value']) ? $field['value'] : ''; $attachment_data = wp_get_attachment_metadata($attachment_id); if ( '' != $attachment_id ) { $file_types = $field['file_types']; $media_url = isset($attachment_data['url']) ? $attachment_data['url'] : ''; if ( in_array('video/mp4', $file_types) ) { $video_url = $media_url; $show_image = 'd-none'; $show_video = ''; $field['custom_attributes']['data-url'] = $video_url; } else { $image_thumb = isset($attachment_data['thumb_url']) ? $attachment_data['thumb_url'] : $media_url; $file_mime_type = get_post_mime_type($attachment_id); $file_mime_type = explode('/', $file_mime_type); $show_image = ''; $show_video = 'd-none'; $field['custom_attributes']['data-url'] = $image_thumb; } } if ( $show_image == '' || $show_video == '' ) { $show_wrapper = ''; } $field['custom_attributes']['accept'] = implode( ',', $field['file_types'] ); $is_disabled = false; if ( isset($field['custom_attributes']['disabled']) && $field['custom_attributes']['disabled'] == 'disabled' ) { $is_disabled = true; } // Custom attribute handling $custom_attributes = array(); if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) { foreach ( $field['custom_attributes'] as $attribute => $v ) { $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $v ) . '"'; } } $required_field = ''; if ( $field['required'] ) { $required_field = 'required="required"'; } $custom_attributes_string = implode( ' ', $custom_attributes ); if ( $field['show_wrapper'] ) { do_action('notifier_before_meta_field_wrapper', $field, $post); echo '

'; } if ( '' != $field['label'] ) { echo ''; } do_action('notifier_before_meta_field', $field, $post); echo ''; echo ''; echo '
'; echo '
'; echo ''; echo ''; if ( ! $is_disabled ) { echo ''; echo ''; } echo ' Uploading...'; echo ' Upload done!'; echo ' There was an error during upload. Please try again later.'; if ( $field['required'] ) { echo 'This is a required field.'; } do_action('notifier_after_meta_field', $field, $post); if ( '' != $field['description'] ) { echo '' . wp_kses_post( $field['description'] ) . ''; } do_action('notifier_after_meta_field_description', $field, $post); if ( $field['show_wrapper'] ) { echo '

'; do_action('notifier_after_meta_field_wrapper', $field, $post); } } /** * Notifier repeater field * * @param array $fields_data */ function notifier_wp_repeater($fields_data) { $fields_data = wp_parse_args( $fields_data, array( 'label' => '', 'name' => $fields_data['id'], 'wrapper_class' => '', 'conditional_logic' => '', 'conditional_operator' => 'OR' ) ); echo '
'; echo ''; echo ''; // Table header echo ''; echo ''; foreach($fields_data['fields'] as $field){ echo ''; } echo ''; echo ''; echo ''; echo ''; echo ''; foreach($fields_data['fields'] as $field){ $field['custom_attributes'] = array('disabled' => 'disabled'); $field['label'] = ''; $field['name'] = $field['id'] . '[]'; $field['id'] = $field['id'] . '_dummy'; echo ''; } echo ''; echo ''; if(!empty($fields_data['values'])){ $x = 0; foreach($fields_data['values'] as $values){ echo ''; foreach($fields_data['fields'] as $key => $field){ $field['label'] = ''; $field['value'] = $values[$key]; $field['name'] = $field['id'] . '[]'; $field['id'] = $field['id'] . '_' . $x; echo ''; } echo ''; echo ''; $x++; } } echo ''; echo '
' . $field['label'] . '
'; switch($field['type']) { case 'text': notifier_wp_text_input($field); break; } echo '
'; switch($field['type']) { case 'text': notifier_wp_text_input($field); break; } echo '
'; echo '

'.$fields_data['description'].' '.$fields_data['button_name'].'

'; echo '
'; }