'required|sanitizeText|maxLength:200', 'post_status' => ['nullable', 'string'], 'detail.fulfillment_type' => ['sanitizeText', function ($attribute, $value) { if (!in_array($value, ['physical', 'digital'])) { return __('Invalid fulfillment type.', 'fluent-cart'); } return null; }], 'detail.variation_type' => ['sanitizeText', function ($attribute, $value) { if ($value !== null && $value !== '' && !in_array($value, Helper::getVariationTypes(false), true)) { return __('Invalid variation type.', 'fluent-cart'); } return null; }], ]; } /** * @return array */ public function messages(): array { return [ 'post_title.required' => esc_html__('Title is required.', 'fluent-cart'), 'post_title.max' => esc_html__('Title may not be greater than 200 characters.', 'fluent-cart'), 'detail.fulfillment_type.required' => esc_html__('Fulfilment Type is required.', 'fluent-cart'), ]; } /** * @return array */ public function sanitize(): array { return [ 'post_title' => 'sanitize_text_field', 'post_status' => 'sanitize_text_field', 'detail.fulfillment_type' => function ($value) { if (empty($value)) { return 'digital'; } return sanitize_text_field($value); }, 'detail.variation_type' => function ($value) { return in_array($value, Helper::getVariationTypes(false), true) ? $value : 'simple'; }, 'detail.other_info.is_bundle_product' => function ($value) { return $value === 'yes' ? 'yes' : 'no'; } ]; } }