array( 'default' => Constants::DEFAULT_LOGO_URL, 'sanitize' => 'esc_url_raw' ), 'heading' => array( 'default' => Constants::DEFAULT_HEADING, 'sanitize' => 'sanitize_text_field' ), 'message' => array( 'default' => Constants::DEFAULT_MESSAGE, 'sanitize' => 'sanitize_text_field' ), 'button_text' => array( 'default' => Constants::DEFAULT_BUTTON_TEXT, 'sanitize' => 'sanitize_text_field' ), 'button_colour' => array( 'default' => Constants::DEFAULT_BUTTON_COLOUR, 'sanitize' => 'sanitize_hex_color' ), 'accent_colour' => array( 'default' => Constants::DEFAULT_ACCENT_COLOUR, 'sanitize' => 'sanitize_hex_color' ), 'background_colour' => array( 'default' => Constants::DEFAULT_BACKGROUND_COLOUR, 'sanitize' => 'sanitize_hex_color' ), 'heading_colour' => array( 'default' => Constants::DEFAULT_HEADING_COLOUR, 'sanitize' => 'sanitize_hex_color' ), 'message_colour' => array( 'default' => Constants::DEFAULT_MESSAGE_COLOUR, 'sanitize' => 'sanitize_hex_color' ), 'heading_typography_mode' => array( 'default' => Constants::DEFAULT_HEADING_TYPOGRAPHY_MODE, 'sanitize' => array( $this, 'sanitize_typography_mode' ) ), 'heading_font' => array( 'default' => Constants::DEFAULT_HEADING_FONT, 'sanitize' => array( $this, 'sanitize_font_family' ) ), 'heading_font_size' => array( 'default' => Constants::DEFAULT_HEADING_FONT_SIZE, 'sanitize' => array( $this, 'sanitize_font_size' ) ), 'heading_font_weight' => array( 'default' => Constants::DEFAULT_HEADING_FONT_WEIGHT, 'sanitize' => array( $this, 'sanitize_font_weight' ) ), 'message_typography_mode' => array( 'default' => Constants::DEFAULT_MESSAGE_TYPOGRAPHY_MODE, 'sanitize' => array( $this, 'sanitize_typography_mode' ) ), 'message_font' => array( 'default' => Constants::DEFAULT_MESSAGE_FONT, 'sanitize' => array( $this, 'sanitize_font_family' ) ), 'message_font_size' => array( 'default' => Constants::DEFAULT_MESSAGE_FONT_SIZE, 'sanitize' => array( $this, 'sanitize_font_size' ) ), 'message_font_weight' => array( 'default' => Constants::DEFAULT_MESSAGE_FONT_WEIGHT, 'sanitize' => array( $this, 'sanitize_font_weight' ) ), 'blur_enabled' => array( 'default' => Constants::DEFAULT_BLUR_ENABLED, 'sanitize' => array( $this, 'sanitize_checkbox' ) ), ); foreach ( $settings as $key => $setting ) { register_setting( Constants::OPTION_GROUP, Constants::OPTION_PREFIX . $key, array( 'type' => 'string', 'default' => $setting['default'], 'sanitize_callback' => $setting['sanitize'], ) ); } add_settings_section( 'articlevault_appearance', 'Appearance', array( $this, 'render_section' ), Constants::SETTINGS_PAGE_SLUG ); $fields = array( 'heading' => 'Paywall Heading', 'message' => 'Paywall Message', 'button_text' => 'Button Text', ); foreach ( $fields as $key => $label ) { add_settings_field( Constants::OPTION_PREFIX . $key, $label, array( $this, 'render_' . $key . '_field' ), Constants::SETTINGS_PAGE_SLUG, 'articlevault_appearance' ); } } public function render_section(): void { echo '
Customise the customer-facing paywall design.
'; } public function render_logo_url_field(): void { $this->render_text_field( 'logo_url', $this->get_logo_url(), 'Paste your logo image URL here.' ); } public function render_heading_field(): void { $this->render_text_field( 'heading', $this->get_heading() ); } public function render_message_field(): void { $this->render_text_field( 'message', $this->get_raw_message(), 'The article price is displayed separately beneath the heading.' ); } public function render_button_text_field(): void { $this->render_text_field( 'button_text', $this->get_button_text() ); } public function render_button_colour_field(): void { $this->render_colour_field( 'button_colour', $this->get_button_colour() ); } public function render_background_colour_field(): void { $this->render_colour_field( 'background_colour', $this->get_background_colour() ); } public function render_heading_colour_field(): void { $this->render_colour_field( 'heading_colour', $this->get_heading_colour() ); } public function render_message_colour_field(): void { $this->render_colour_field( 'message_colour', $this->get_message_colour() ); } public function render_heading_font_field(): void { $this->render_typography_field( 'heading', $this->get_heading_typography_mode(), $this->get_heading_font(), $this->get_heading_font_size(), $this->get_heading_font_weight() ); } public function render_message_font_field(): void { $this->render_typography_field( 'message', $this->get_message_typography_mode(), $this->get_message_font(), $this->get_message_font_size(), $this->get_message_font_weight() ); } public function render_blur_enabled_field(): void { $value = $this->is_blur_enabled(); ?> > get_raw_message(); } public function get_button_text(): string { return get_option( Constants::OPTION_PREFIX . 'button_text', Constants::DEFAULT_BUTTON_TEXT ); } public function get_button_colour(): string { return get_option( Constants::OPTION_PREFIX . 'button_colour', Constants::DEFAULT_BUTTON_COLOUR ); } public function get_accent_colour(): string { return get_option( Constants::OPTION_PREFIX . 'accent_colour', Constants::DEFAULT_ACCENT_COLOUR ); } public function get_background_colour(): string { return get_option( Constants::OPTION_PREFIX . 'background_colour', Constants::DEFAULT_BACKGROUND_COLOUR ); } public function get_heading_colour(): string { return get_option( Constants::OPTION_PREFIX . 'heading_colour', Constants::DEFAULT_HEADING_COLOUR ); } public function get_message_colour(): string { return get_option( Constants::OPTION_PREFIX . 'message_colour', Constants::DEFAULT_MESSAGE_COLOUR ); } public function get_heading_typography_mode(): string { return get_option( Constants::OPTION_PREFIX . 'heading_typography_mode', Constants::DEFAULT_HEADING_TYPOGRAPHY_MODE ); } public function get_heading_font(): string { $new_value = get_option( Constants::OPTION_PREFIX . 'heading_font', '' ); if ( '' !== $new_value ) { return $new_value; } return get_option( Constants::OPTION_PREFIX . 'heading_font', Constants::DEFAULT_HEADING_FONT ); } public function get_heading_font_size(): int { return (int) get_option( Constants::OPTION_PREFIX . 'heading_font_size', Constants::DEFAULT_HEADING_FONT_SIZE ); } public function get_heading_font_weight(): string { return get_option( Constants::OPTION_PREFIX . 'heading_font_weight', Constants::DEFAULT_HEADING_FONT_WEIGHT ); } public function get_message_typography_mode(): string { return get_option( Constants::OPTION_PREFIX . 'message_typography_mode', Constants::DEFAULT_MESSAGE_TYPOGRAPHY_MODE ); } public function get_message_font(): string { $new_value = get_option( Constants::OPTION_PREFIX . 'message_font', '' ); if ( '' !== $new_value ) { return $new_value; } return get_option( Constants::OPTION_PREFIX . 'message_font', Constants::DEFAULT_MESSAGE_FONT ); } public function get_message_font_size(): int { return (int) get_option( Constants::OPTION_PREFIX . 'message_font_size', Constants::DEFAULT_MESSAGE_FONT_SIZE ); } public function get_message_font_weight(): string { return get_option( Constants::OPTION_PREFIX . 'message_font_weight', Constants::DEFAULT_MESSAGE_FONT_WEIGHT ); } public function is_blur_enabled(): bool { return (bool) get_option( Constants::OPTION_PREFIX . 'blur_enabled', Constants::DEFAULT_BLUR_ENABLED ); } public function sanitize_checkbox( $value ): bool { return (bool) $value; } public function sanitize_typography_mode( $value ): string { return in_array( $value, array( 'inherit', 'custom' ), true ) ? $value : 'inherit'; } public function sanitize_font_family( $value ): string { $value = sanitize_text_field( $value ); $value = preg_replace( '/[^a-zA-Z0-9\s,\-"\']/', '', $value ); return ! empty( $value ) ? $value : 'inherit'; } public function sanitize_font_size( $value ): int { $value = absint( $value ); return max( 8, min( 120, $value ) ); } public function sanitize_font_weight( $value ): string { $value = (string) $value; return in_array( $value, array( '400', '500', '600', '700' ), true ) ? $value : '400'; } }