\s*/', '', self::document( $settings ) );
echo '' . "\n";
echo wp_kses( (string) $document, self::document_tags() );
exit;
}
/**
* The tags and attributes document() is built from, for wp_kses() on output.
*
* @return array
*/
private static function document_tags() {
$class = array( 'class' => true );
return array(
'html' => array(
'lang' => true,
'dir' => true,
'class' => true,
),
'head' => array(),
'meta' => array(
'charset' => true,
'name' => true,
'content' => true,
),
'title' => array(),
'link' => array(
'rel' => true,
'id' => true,
'href' => true,
'media' => true,
'type' => true,
),
'style' => array(
'id' => true,
'type' => true,
),
'body' => $class,
'main' => $class,
'h1' => $class,
'h2' => $class,
'div' => $class,
'p' => $class,
'ul' => $class,
'li' => $class,
);
}
/**
* The page of its own: a document with the form, its stylesheet linked,
* not indexed.
*
* @param Settings $settings Plugin settings.
* @return string
*/
public static function document( Settings $settings ) {
unset( $settings );
self::register_style();
// A page of its own: its stylesheet is printed into it whatever this
// request printed before.
$styles = wp_styles();
$styles->done = array_diff( (array) $styles->done, array( self::HANDLE ) );
ob_start();
wp_print_styles( self::HANDLE );
$links = (string) ob_get_clean();
$title = sprintf(
/* translators: %s: the site title. */
__( 'Model withdrawal form – %s', 'careback' ),
wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES )
);
return '' . "\n"
. '' . "\n"
. '
' . "\n"
. '' . "\n"
. '' . "\n"
. '' . "\n"
. '' . esc_html( $title ) . '' . "\n"
. $links
. '' . "\n"
. '' . "\n"
. '' . "\n"
. self::form( 'h1' )
. '' . "\n"
. '' . "\n"
. '' . "\n";
}
/**
* The form: the official lines of Annex I(B), the trader's line filled in.
*
* @param string $heading Tag of the heading: 'h1' on the page of its own, 'h2' in a page.
* @return string
*/
private static function form( $heading ) {
$heading = 'h1' === $heading ? 'h1' : 'h2';
$trader = self::trader();
$to = implode( ', ', array_filter( array_merge( array( $trader['name'] ), $trader['address'], array( $trader['email'] ) ), 'strlen' ) );
$lines = array(
array(
'class' => 'careback-model-to',
/* translators: %s: the shop's name, geographical address and email address. Annex I(B) of Directive 2011/83/EU: use the official wording of your language. */
'text' => sprintf( __( 'To %s:', 'careback' ), $to ),
),
array(
'class' => 'careback-model-fill',
'text' => __( 'I/We (*) hereby give notice that I/We (*) withdraw from my/our (*) contract of sale of the following goods (*)/for the provision of the following service (*),', 'careback' ),
),
array(
'class' => 'careback-model-fill',
'text' => __( 'Ordered on (*)/received on (*),', 'careback' ),
),
array(
'class' => 'careback-model-fill',
'text' => __( 'Name of consumer(s),', 'careback' ),
),
array(
'class' => 'careback-model-fill',
'text' => __( 'Address of consumer(s),', 'careback' ),
),
array(
'class' => 'careback-model-fill',
'text' => __( 'Signature of consumer(s) (only if this form is notified on paper),', 'careback' ),
),
array(
'class' => 'careback-model-fill',
'text' => __( 'Date', 'careback' ),
),
);
$out = '' . "\n";
return $out;
}
/**
* The shop as the form names it, each part as plain text: its name, the
* lines of its geographical address (the country always named), its email.
*
* @return array{name:string,address:string[],email:string}
*/
public static function trader() {
$name = trim( wp_specialchars_decode( (string) get_option( 'woocommerce_email_from_name', '' ), ENT_QUOTES ) );
$name = '' !== $name ? $name : trim( wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) );
$email = sanitize_email( (string) get_option( 'woocommerce_email_from_address', '' ) );
$email = '' !== $email ? $email : sanitize_email( (string) get_option( 'admin_email' ) );
$address = array();
if ( function_exists( 'WC' ) && WC()->countries ) {
$countries = WC()->countries;
// The customer may live in another country: the shop's is always named.
$country = static function () {
return true;
};
add_filter( 'woocommerce_formatted_address_force_country_display', $country );
$text = $countries->get_formatted_address(
array(
'address_1' => $countries->get_base_address(),
'address_2' => $countries->get_base_address_2(),
'city' => $countries->get_base_city(),
'state' => $countries->get_base_state(),
'postcode' => $countries->get_base_postcode(),
'country' => $countries->get_base_country(),
),
"\n"
);
remove_filter( 'woocommerce_formatted_address_force_country_display', $country );
foreach ( explode( "\n", (string) $text ) as $line ) {
$line = trim( wp_specialchars_decode( wp_strip_all_tags( $line ), ENT_QUOTES ) );
if ( '' !== $line ) {
$address[] = $line;
}
}
}
return array(
'name' => $name,
'address' => $address,
'email' => $email,
);
}
/**
* Registers the stylesheet.
*
* @return void
*/
private static function register_style() {
if ( ! wp_style_is( self::HANDLE, 'registered' ) ) {
wp_register_style( self::HANDLE, CAREBACK_URL . 'assets/css/model-form.css', array(), CAREBACK_VERSION );
}
}
}