diff --git a/templates/form-fields/term-select-field.php b/templates/form-fields/term-select-field.php index 14934ad8b..8c16be95b 100644 --- a/templates/form-fields/term-select-field.php +++ b/templates/form-fields/term-select-field.php @@ -8,20 +8,30 @@ * @author Automattic * @package wp-job-manager * @category Template - * @version 1.31.1 + * @version $$next-version$$ + * + * @var array $key Form field name. + * @var array $field Form field data. + * */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } +$placeholder = array_key_exists( 'placeholder', $field ) && ! empty( $field['placeholder'] ) ? $field['placeholder'] : esc_html__( 'Select an Option...', 'wp-job-manager' ); +$selected = null; + // Get selected value. if ( isset( $field['value'] ) ) { $selected = $field['value']; } elseif ( is_int( $field['default'] ) ) { $selected = $field['default']; -} elseif ( ! empty( $field['default'] ) && ( $term = get_term_by( 'slug', $field['default'], $field['taxonomy'] ) ) ) { - $selected = $term->term_id; +} elseif ( ! empty( $field['default'] ) ) { + $default = get_term_by( 'slug', $field['default'], $field['taxonomy'] ); + if ( ! empty( $default ) ) { + $selected = $default->term_id; + } } else { $selected = ''; } @@ -31,14 +41,18 @@ $selected = current( $selected ); } -wp_dropdown_categories( apply_filters( 'job_manager_term_select_field_wp_dropdown_categories_args', [ - 'taxonomy' => $field['taxonomy'], - 'hierarchical' => 1, - 'show_option_all' => false, - 'show_option_none' => $field['required'] ? '' : '-', - 'name' => isset( $field['name'] ) ? $field['name'] : $key, - 'orderby' => 'name', - 'selected' => $selected, - 'hide_empty' => false -], $key, $field ) ); +$args = [ + 'taxonomy' => $field['taxonomy'], + 'hierarchical' => 1, + 'show_option_all' => false, + 'option_none_value' => '', + 'show_option_none' => $placeholder, + 'name' => isset( $field['name'] ) ? $field['name'] : $key, + 'orderby' => 'name', + 'selected' => $selected, + 'hide_empty' => false, +]; + +wp_dropdown_categories( apply_filters( 'job_manager_term_select_field_wp_dropdown_categories_args', $args, $key, $field ) ); + if ( ! empty( $field['description'] ) ) : ?>