[]`, the one array shape WooCommerce's modal passes through, and * each rename as its own flat `_name_` field. * - bbmmp_test_button: the "Test connection" button; assets/admin.js does * the rest. It stores nothing. */ declare(strict_types=1); namespace BlueBrainMedia\MapleParcel\Settings; use BlueBrainMedia\MapleParcel\Shipping\Services; defined( 'ABSPATH' ) || exit; trait CustomFields { /** @param array $data */ public function generate_bbmmp_secret_html( string $key, array $data ): string { $field_key = $this->get_field_key( $key ); $stored = (string) $this->get_option( $key ); $unreadable = '' !== $stored && null === SecretBox::open( $stored ); $saved = '' !== $stored && ! $unreadable; $data = wp_parse_args( $data, array( 'title' => '', 'description' => '', 'desc_tip' => false, ) ); if ( $unreadable ) { $data['description'] = __( 'The saved secret can no longer be read on this site, usually because the site\'s security keys in wp-config.php changed. Enter it again.', 'maple-parcel' ); } ob_start(); ?>

/> get_description_html( $data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- WooCommerce builds and escapes it. ?>
get_option( $key ) : SecretBox::seal( $value ); } /** @param array $data */ public function generate_bbmmp_services_html( string $key, array $data ): string { $field_key = $this->get_field_key( $key ); $choices = Services::choices( $this->get_option( $key ) ); $data = wp_parse_args( $data, array( 'title' => '', 'description' => '', 'desc_tip' => false, ) ); $groups = array( Services::DOMESTIC => __( 'Within Canada', 'maple-parcel' ), Services::UNITED_STATES => __( 'To the United States', 'maple-parcel' ), Services::INTERNATIONAL => __( 'International', 'maple-parcel' ), ); ob_start(); ?> get_description_html( $data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- WooCommerce builds and escapes it. ?> $heading ) : ?> $name ) : if ( Services::group( $code ) !== $group ) { continue; } $id = $field_key . '_' . str_replace( '.', '_', $code ); ?>
/>
*/ public function validate_bbmmp_services_field( string $key, mixed $value ): array { $ticked = is_array( $value ) ? array_map( 'strval', $value ) : array(); $posted = $this->get_post_data(); $field_key = $this->get_field_key( $key ); $saved = array(); foreach ( array_keys( Services::all() ) as $code ) { $name = $posted[ self::serviceNameField( $field_key, $code ) ] ?? ''; $saved[ $code ] = array( 'enabled' => in_array( $code, $ticked, true ), 'name' => is_string( $name ) ? sanitize_text_field( stripslashes( $name ) ) : '', ); } return $saved; } /** @param array $data */ public function generate_bbmmp_test_button_html( string $key, array $data ): string { unset( $key ); // get_description_html() reads desc_tip without checking it is there. $data = wp_parse_args( $data, array( 'title' => '', 'description' => '', 'desc_tip' => false, ) ); ob_start(); ?> get_description_html( $data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- WooCommerce builds and escapes it. ?>