array( 'label' => __( 'Name', 'acs-contact-form' ), 'enabled' => '1', 'required' => '1', 'fixed' => true, ), 'email' => array( 'label' => __( 'Email address', 'acs-contact-form' ), 'enabled' => '1', 'required' => '1', 'fixed' => true, ), 'message' => array( 'label' => __( 'Message', 'acs-contact-form' ), 'enabled' => '1', 'required' => '1', 'fixed' => true, ), 'tel' => array( 'label' => __( 'Phone number', 'acs-contact-form' ), 'enabled' => '0', 'required' => '0', 'fixed' => false, ), 'company' => array( 'label' => __( 'Company', 'acs-contact-form' ), 'enabled' => '0', 'required' => '0', 'fixed' => false, ), 'address' => array( 'label' => __( 'Address', 'acs-contact-form' ), 'enabled' => '0', 'required' => '0', 'fixed' => false, ), 'subject' => array( 'label' => __( 'Subject', 'acs-contact-form' ), 'enabled' => '0', 'required' => '0', 'fixed' => false, ), ); } /** * Default attachment settings. * * @return array */ function acscf_get_default_file_settings() { return array( 'enabled' => '0', 'label' => __( 'Attach a file', 'acs-contact-form' ), 'types' => 'jpg, jpeg, png, gif, pdf, doc, docx', 'max_size' => '5', 'max_count' => '3', 'required' => '0', ); } /** * Default mail settings. * * @return array */ function acscf_get_default_email_settings() { return array( 'to' => get_option( 'admin_email' ), 'subject' => '【{form_name}】{subject}', 'auto_reply' => '0', 'auto_reply_subject' => __( '[Auto-reply] Thank you for your inquiry', 'acs-contact-form' ), 'auto_reply_body' => __( "Hello {name},\n\nThank you for getting in touch.\nWe have received your message as follows.\n\n---\n{all_fields}\n---\n\nOne of our team will get back to you shortly.", 'acs-contact-form' ), ); } /** * Fill in the missing mail settings. * * @param mixed $email_settings Stored settings. * @return array */ function acscf_normalize_email_settings( $email_settings ) { return wp_parse_args( is_array( $email_settings ) ? $email_settings : array(), acscf_get_default_email_settings() ); } /** * Default design settings. * * @return array */ function acscf_get_default_design_settings() { return array( 'primary_color' => '#0071e3', 'text_color' => '#1d1d1f', 'label_color' => '#1d1d1f', 'bg_color' => '#ffffff', 'input_bg_color' => '#fbfbfd', 'input_text_color' => '#1d1d1f', 'input_border_color' => '#d2d2d7', 'button_bg_color' => '#0071e3', 'button_text_color' => '#ffffff', 'required_bg_color' => '#0071e3', 'required_text_color' => '#ffffff', 'error_color' => '#e53935', 'radius' => '8', 'button_radius' => '20', ); } /** * Fill in the missing design settings. * * @param mixed $design Stored settings. * @return array */ function acscf_normalize_design_settings( $design ) { return wp_parse_args( is_array( $design ) ? $design : array(), acscf_get_default_design_settings() ); } /** * Default order of the fields. * * @param array $standard_fields Standard fields. * @param array $custom_fields Custom fields. * @param array $file_settings Attachment settings. * @return array */ function acscf_build_default_field_order( $standard_fields, $custom_fields, $file_settings ) { $order = array(); $preferred = array( 'name', 'company', 'address', 'tel', 'email', 'subject', 'message' ); foreach ( $preferred as $key ) { if ( isset( $standard_fields[ $key ] ) ) { $order[] = 'standard:' . $key; } } if ( is_array( $custom_fields ) ) { foreach ( array_keys( $custom_fields ) as $index ) { $order[] = 'custom:' . (int) $index; } } if ( ! empty( $file_settings ) ) { $order[] = 'file'; } return $order; } /** * Clean an order coming from the builder. * * @param mixed $raw_order Raw order. * @param array $standard_fields Standard fields. * @param array $custom_fields Custom fields. * @param array $custom_index_map Map of posted index to stored index. * @return array */ function acscf_sanitize_field_order( $raw_order, $standard_fields, $custom_fields, $custom_index_map = array() ) { $clean = array(); if ( is_array( $raw_order ) ) { foreach ( $raw_order as $item ) { $item = sanitize_text_field( $item ); if ( 'file' === $item ) { $clean[] = 'file'; continue; } if ( 0 === strpos( $item, 'standard:' ) ) { $key = substr( $item, strlen( 'standard:' ) ); if ( isset( $standard_fields[ $key ] ) ) { $clean[] = 'standard:' . $key; } continue; } if ( 0 === strpos( $item, 'custom:' ) ) { $raw_index = substr( $item, strlen( 'custom:' ) ); $mapped = array_key_exists( $raw_index, $custom_index_map ) ? $custom_index_map[ $raw_index ] : (int) $raw_index; if ( isset( $custom_fields[ $mapped ] ) ) { $clean[] = 'custom:' . (int) $mapped; } } } } foreach ( acscf_build_default_field_order( $standard_fields, $custom_fields, acscf_get_default_file_settings() ) as $fallback ) { if ( ! in_array( $fallback, $clean, true ) ) { $clean[] = $fallback; } } return array_values( array_unique( $clean ) ); } /** * Effective field order of a form. * * @param int $form_id Form post ID. * @param array $standard_fields Standard fields. * @param array $custom_fields Custom fields. * @param array $file_settings Attachment settings. * @return array */ function acscf_get_field_order( $form_id, $standard_fields, $custom_fields, $file_settings ) { $field_order = get_post_meta( $form_id, '_acscf_field_order', true ); if ( ! is_array( $field_order ) || empty( $field_order ) ) { return acscf_build_default_field_order( $standard_fields, $custom_fields, $file_settings ); } return acscf_sanitize_field_order( $field_order, $standard_fields, is_array( $custom_fields ) ? $custom_fields : array() ); } /** * The form builder. * * @param WP_Post $post Current form. * @return void */ function acscf_builder_meta_box_html( $post ) { wp_nonce_field( 'acscf_save_meta_box_data', 'acscf_meta_box_nonce' ); $standard_fields = get_post_meta( $post->ID, '_acscf_standard_fields', true ); if ( empty( $standard_fields ) ) { $standard_fields = acscf_get_default_standard_fields(); } $custom_fields = get_post_meta( $post->ID, '_acscf_custom_fields', true ); if ( ! is_array( $custom_fields ) ) { $custom_fields = array(); } $file_settings = get_post_meta( $post->ID, '_acscf_file_settings', true ); if ( empty( $file_settings ) ) { $file_settings = acscf_get_default_file_settings(); } $email_settings = acscf_normalize_email_settings( get_post_meta( $post->ID, '_acscf_email_settings', true ) ); $field_order = acscf_get_field_order( $post->ID, $standard_fields, $custom_fields, $file_settings ); ?>
| > |
|
|
|
| MB | |
| > |
' . esc_html__( 'Settings', 'acs-contact-form' ) . '' ); ?>
px
px