'', 'prefix' => '', 'translation_strings' => array(), ); $args = wp_parse_args( $args, $defaults ); foreach ( $args as $name => $value ) { $this->$name = $value; } } /** * Get field description for display. * * @param array $args settings Arguments array. * * @return string Description of the field. */ public function get_field_description( $args ) { $desc = ! empty( $args['desc'] ) ? '
' . wp_kses_post( $args['desc'] ) . '
' : ''; /** * After Settings Output filter * * @param string $desc Description of the field. * @param array $args Arguments array. */ $desc = apply_filters( $this->prefix . '_setting_field_description', $desc, $args ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound return $desc; } /** * Get the value of a settings field. * * @param string $option Settings field name. * @param mixed $default_value Default value if option is not found. * @return mixed */ public function get_option( $option, $default_value = '' ) { $options = \get_option( $this->settings_key ); if ( isset( $options[ $option ] ) ) { return $options[ $option ]; } return $default_value; } /** * Get field value from args or options. * * @param array $args Field arguments. * @return mixed Field value. */ protected function get_field_value( $args ) { return $args['value'] ?? $this->get_option( $args['id'], $args['default'] ?? '' ); } /** * Get sanitized field class string. * * @param array $args Field arguments. * @param string $default_class Default class to prepend. * @return string Sanitized class string. */ protected function get_field_class( $args, $default_class = '' ) { $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['field_class'] ?? '' ) ) ); if ( $default_class ) { $class = $default_class . ' ' . $class; } return trim( $class ); } /** * Get placeholder attribute string. * * @param array $args Field arguments. * @return string Placeholder attribute or empty string. */ protected function get_placeholder_attribute( $args ) { return empty( $args['placeholder'] ) ? '' : ' placeholder="' . esc_attr( $args['placeholder'] ) . '"'; } /** * Get boolean state attributes (disabled, readonly, required). * * @param array $args Field arguments. * @return string Concatenated boolean attributes. */ protected function get_boolean_attributes( $args ) { $disabled = ( ! empty( $args['disabled'] ) || ! empty( $args['pro'] ) ) ? ' disabled="disabled"' : ''; $readonly = ( isset( $args['readonly'] ) && true === $args['readonly'] ) ? ' readonly="readonly"' : ''; $required = ( isset( $args['required'] ) && true === $args['required'] ) ? ' required' : ''; return $disabled . $readonly . $required; } /** * Get field ID and name attributes. * * @param array $args Field arguments. * @return array Array containing field_id and field_name. */ protected function get_field_attributes( $args ) { $id = sanitize_key( $args['id'] ); if ( isset( $args['_repeater_id'] ) && isset( $args['_index'] ) ) { $field_id = sprintf( '%s-%s-%s-fields-%s', $this->settings_key, $args['_repeater_id'], $args['_index'], $id ); $field_name = sprintf( '%s[%s][%s][fields][%s]', $this->settings_key, $args['_repeater_id'], $args['_index'], $id ); } else { $field_id = $this->settings_key . '-' . $id; $field_name = $this->settings_key . '[' . $id . ']'; } return array( 'field_id' => $field_id, 'field_name' => $field_name, ); } /** * Returns the allowed HTML tags and attributes for settings form output. * * Use the `{prefix}_settings_form_allowed_html` filter to add extra tags or * attributes needed by custom field types or `field_attributes` entries. * * @return array