*/ public array $only = array(); /** * Values to pre-fill, keyed by field id. * * @var array */ public array $values = array(); /** * Constructor. * * @param \WC_Product $product Product. * @param int $user_id Reviewer, 0 for guests. * @param FormConfig $config Configuration. * @param \WP_Comment|null $review Review being edited. * @param string $prefix Element id prefix. */ public function __construct( \WC_Product $product, int $user_id, FormConfig $config, ?\WP_Comment $review = null, string $prefix = '' ) { $this->product = $product; $this->user_id = $user_id; $this->config = $config; $this->review = $review; $this->prefix = '' !== $prefix ? $prefix : 'wpipr-form-' . $product->get_id(); } /** * Pre-filled value of a field. * * @param string $field_id Field id. * @param mixed $default_value Value when none is set. * @return mixed */ public function value( string $field_id, $default_value = null ) { return array_key_exists( $field_id, $this->values ) ? $this->values[ $field_id ] : $default_value; } /** * Element id for a field part. * * @param string $suffix Part name. */ public function id( string $suffix ): string { return $this->prefix . '-' . $suffix; } /** * A field's wording: its label, placeholder or help text. * * @param string $field Field id. * @param string $part label, placeholder or help. * @param string $default_value The plugin's own text. */ public function text( string $field, string $part, string $default_value = '' ): string { /** * Filter a review form field's wording (Pro's form builder sets it). * * @since 1.0.0 * @param string $text Text. * @param string $field Field id, such as "title". * @param string $part label, placeholder or help. * @param FormContext $context Form context. */ $text = apply_filters( 'wpipr_form_field_text', $default_value, $field, $part, $this ); return is_string( $text ) ? $text : $default_value; } /** * A field's help text, if it has one. * * @param string $field Field id. * @param string $element Id of the field's input; the help gets "{id}-help". */ public function help_html( string $field, string $element ): string { $help = $this->text( $field, 'help' ); return '' === $help ? '' : '' . esc_html( $help ) . ''; } /** * Ids that describe an input: its help, if any, and its error. * * @param string $field Field id. * @param string $element Id of the field's input. */ public function described_by( string $field, string $element ): string { return ( '' === $this->text( $field, 'help' ) ? '' : $element . '-help ' ) . $element . '-error'; } }