0 ? $value : ( $site > 0 ? ( $allow_default ? min( 3650, $site ) : $site ) : 365 ); if ( in_array( $submitted_mode, array( 'default', 'manual', 'days' ), true ) ) { $mode = $submitted_mode; if ( 'days' === $mode ) { $days = $raw; } } echo '
'; if ( $allow_default ) { $default_label = $site > 0 ? sprintf( /* translators: %d: site retention period in days. */ __( 'Site default: delete after %d days.', 'accessible-forms-by-accessible-org' ), $site ) : __( 'Site default: keep until manually deleted.', 'accessible-forms-by-accessible-org' ); echo '

' . esc_html( $default_label ) . '

'; } echo '
' . esc_html( $allow_default ? __( 'Used only when deleting after a set number of days. Between 1 and 3,650 days.', 'accessible-forms-by-accessible-org' ) : __( 'Used only when deleting after a set number of days. Enter a whole number of at least 1 day.', 'accessible-forms-by-accessible-org' ) ) . '
'; echo '

' . esc_html__( 'Applies to new entries. Each submission keeps the retention policy in effect when it was received. Scheduled deletion runs daily.', 'accessible-forms-by-accessible-org' ) . '

'; if ( $locked ) { echo '

' . esc_html__( 'Set in wp-config.php.', 'accessible-forms-by-accessible-org' ) . '

'; } echo '
'; } public static function input( $name, $label, $value = '', $type = 'text', $help = '', $attrs = array() ) { $id = 'af-opt-' . sanitize_html_class( str_replace( array( '[', ']' ), array( '-', '' ), $name ) ); if ( $help ) { $attrs['aria-describedby'] = $id . '-help'; } echo '

'; if ( 'textarea' === $type ) { echo ''; } else { echo ' $attribute ) { echo ' ' . esc_attr( $key ) . '="' . esc_attr( $attribute ) . '"'; } echo '>'; } if ( $help ) { echo '' . esc_html( $help ) . ''; } echo '

'; } public static function select( $name, $label, array $options, $value, $id = '' ) { $id = $id ?: 'af-opt-' . sanitize_html_class( str_replace( array( '[', ']' ), array( '-', '' ), $name ) ); echo '

'; } public static function check( $name, $label, $value ) { echo '

'; } public static function notification_templates( array $schema, $legacy ) { if ( current_user_can( 'manage_options' ) ) { self::input( 'af_schema[cc]', __( 'CC (optional)', 'accessible-forms-by-accessible-org' ), implode( "\n", (array) ( $schema['cc'] ?? array() ) ), 'textarea', __( 'Enter one email address per line. CC addresses are visible to the other recipients of the main notification.', 'accessible-forms-by-accessible-org' ), array( 'maxlength' => 5500 ) ); } if ( $legacy ) { self::check( 'af_schema[merge_subject]', __( 'Use page and submission tags in this subject', 'accessible-forms-by-accessible-org' ), ! empty( $schema['merge_subject'] ) ); echo '

' . esc_html__( 'This subject already uses a tag name that now has a built-in meaning. To keep using a question’s answer after switching, use its explicit tag, such as {field:date}.', 'accessible-forms-by-accessible-org' ) . '

'; } self::tag_picker( 'subject', 'af-subject_template', __( 'Tag for email subject', 'accessible-forms-by-accessible-org' ), __( 'Insert tag in email subject', 'accessible-forms-by-accessible-org' ), $schema ); self::input( 'af_schema[body_template]', __( 'Email body (optional)', 'accessible-forms-by-accessible-org' ), $schema['body_template'] ?? '', 'textarea', __( 'Leave blank to use the generated email. Write plain text and use {all_fields} to include the answers.', 'accessible-forms-by-accessible-org' ), array( 'maxlength' => 10000 ) ); self::tag_picker( 'body', 'af-opt-af_schema-body_template', __( 'Tag for email body', 'accessible-forms-by-accessible-org' ), __( 'Insert tag in email body', 'accessible-forms-by-accessible-org' ), $schema ); } private static function tag_picker( $key, $target, $label, $button, array $schema ) { $id = 'af-' . $key . '-answer'; echo '
'; echo '
'; } /** * Fields of the form being edited, in order. * * @return array[] */ public static function fields() { return self::$fields; } public static function top( $post, array $schema ) { self::$fields = $schema['fields']; Flow::top( $post, $schema ); } public static function field_type_options( $base, array $field ) { $type = $field['type']; echo '
'; self::input( $base . '[content]', __( 'Content block text', 'accessible-forms-by-accessible-org' ), $field['content'] ?? '', 'textarea', __( 'Separate paragraphs with a blank line. To format text, use for bold, for italics, for links, and
    or
      with
    1. for lists. Give links descriptive text.', 'accessible-forms-by-accessible-org' ), array( 'maxlength' => 12000 ) ); echo '
' . esc_html__( 'Email domain rule', 'accessible-forms-by-accessible-org' ) . ''; $mode = $field['email_domain_mode'] ?? 'any'; self::select( $base . '[email_domain_mode]', __( 'Accepted email domains', 'accessible-forms-by-accessible-org' ), array( 'any' => __( 'Any valid email address', 'accessible-forms-by-accessible-org' ), 'work' => __( 'Work email only', 'accessible-forms-by-accessible-org' ), 'allow' => __( 'Allow only listed domains', 'accessible-forms-by-accessible-org' ), 'deny' => __( 'Block listed domains', 'accessible-forms-by-accessible-org' ), ), $mode ); $help = __( 'Enter one domain per line, such as example.org. Subdomains are listed separately.', 'accessible-forms-by-accessible-org' ); echo '
'; self::input( $base . '[free_email_domains]', __( 'Free email providers to block in Work email only mode', 'accessible-forms-by-accessible-org' ), implode( "\n", (array) ( $field['free_email_domains'] ?? \AccessibleForms\EmailDomains::FREE_PROVIDERS ) ), 'textarea', $help ); echo '
'; self::input( $base . '[email_domains]', __( 'Domains for the allow or block list', 'accessible-forms-by-accessible-org' ), implode( "\n", (array) ( $field['email_domains'] ?? array() ) ), 'textarea', $help ); echo '
'; } public static function field( $base, $id, array $field ) { echo '
'; // Add-ons add per-field settings here, named under $base[extensions][slug]. Extensions::notify( 'accessible_forms_field_editor', $base, $id, $field ); self::select( $base . '[autofill_section]', __( 'Address purpose', 'accessible-forms-by-accessible-org' ), array( '' => __( 'General', 'accessible-forms-by-accessible-org' ), 'shipping' => __( 'Shipping', 'accessible-forms-by-accessible-org' ), 'billing' => __( 'Billing', 'accessible-forms-by-accessible-org' ), ), $field['autofill_section'] ?? '' ); echo '

' . esc_html__( 'Answer limits', 'accessible-forms-by-accessible-org' ) . '

'; foreach ( array( 'min_length' => __( 'Minimum characters', 'accessible-forms-by-accessible-org' ), 'max_length' => __( 'Maximum characters', 'accessible-forms-by-accessible-org' ), 'min_choices' => __( 'Minimum choices', 'accessible-forms-by-accessible-org' ), 'max_choices' => __( 'Maximum choices', 'accessible-forms-by-accessible-org' ), ) as $key => $label ) { self::input( $base . '[' . $key . ']', $label, $field[ $key ] ?? 0, 'number', __( '0 uses the default.', 'accessible-forms-by-accessible-org' ), array( 'min' => 0, 'max' => 10000, ) ); } echo '

' . esc_html__( 'Number range', 'accessible-forms-by-accessible-org' ) . '

'; foreach ( array( 'min' => __( 'Minimum number', 'accessible-forms-by-accessible-org' ), 'max' => __( 'Maximum number', 'accessible-forms-by-accessible-org' ), 'increment' => __( 'Increment', 'accessible-forms-by-accessible-org' ), ) as $key => $label ) { self::input( $base . '[' . $key . ']', $label, $field[ $key ] ?? '', 'number', '', array( 'step' => 'any', ) ); } echo '

' . esc_html__( 'Web address', 'accessible-forms-by-accessible-org' ) . '

' . esc_html__( 'Useful on a “Report a problem” page: when a visitor arrives from another page of this site, its address (without any query string) is filled in. Visitors can change or clear it. Requires JavaScript.', 'accessible-forms-by-accessible-org' ) . '

'; } public static function choices( $base, $id, array $field ) { $values = is_array( $field['options'] ?? null ) ? $field['options'] : preg_split( '/\r\n|\r|\n/', (string) ( $field['options'] ?? '' ) ); $rows = $field['choices'] ?? array_map( static function ( $value ) use ( $field ) { return array( 'value' => $value, 'label' => \AccessibleForms\Choices::label( $field, $value ), ); }, $values ); if ( ! $rows ) { $rows = array( array(), array() ); } echo '
' . esc_html__( 'Choices', 'accessible-forms-by-accessible-org' ) . '

' . esc_html__( 'Edit a label without changing saved answers or routing. Add at least two choices.', 'accessible-forms-by-accessible-org' ) . '

'; foreach ( array_values( $rows ) as $index => $row ) { echo '
'; } echo '
' . esc_html__( 'Paste several choices', 'accessible-forms-by-accessible-org' ) . '
'; } public static function options( $post, array $schema, $step = 'all' ) { $schema = wp_parse_args( $schema, FormOptions::defaults() ); $emails = array( '' => __( 'Choose an email field', 'accessible-forms-by-accessible-org' ) ); foreach ( $schema['fields'] as $field ) { if ( 'email' === $field['type'] ) { $emails[ $field['name'] ] = $field['label']; } } if ( in_array( $step, array( 'all', 'delivery' ), true ) ) { echo '
' . esc_html__( 'Advanced email options', 'accessible-forms-by-accessible-org' ) . '
'; ob_start(); self::select( 'af_schema[reply_to]', __( 'Reply to', 'accessible-forms-by-accessible-org' ), array( '' => __( 'First email field', 'accessible-forms-by-accessible-org' ) ) + $emails, $schema['reply_to'] ); // The list follows the email fields while the form is edited. echo str_replace( ' ' . esc_html( $field['label'] ) . ''; } } echo '
'; } }