id = 'recaptcha-for-woocommerce'; $this->label = esc_html__( 'reCaptcha', 'recaptcha-for-woocommerce' ); parent::__construct(); } /** * Get own sections. * * @return array */ protected function get_own_sections() { return array( '' => __( 'General', 'recaptcha-for-woocommerce' ), 'woocommerce' => __( 'WooCommerce', 'recaptcha-for-woocommerce' ) ); } public function output() { global $current_section, $hide_save_button; $settings = $this->get_settings( $current_section ); $this->output_fields( $settings ); } public function get_settings_for_default_section() { $settings = array( array( 'type' => 'title', 'id' => 'wc_recaptcha_default_options', 'title' => esc_html__( 'reCaptcha for WooCommerce Settings', 'recaptcha-for-woocommerce' ), 'desc' => '
' . esc_html__( 'The following options control the "reCaptcha for WooCommerce" extension.', 'recaptcha-for-woocommerce' ) . '
' ), array( 'id' => 'wc_recaptcha_version', 'type' => 'select', 'class' => 'wc-enhanced-select', 'title' => esc_html__( 'reCaptcha version', 'recaptcha-for-woocommerce' ), 'desc_tip' => esc_html__( 'reCaptcha v3 does not show any challenge to solve like I am not robot etc. ReCaptcha v3 uses a behind-the-scenes scoring system to detect abusive traffic, and lets you decide the minimum passing score.', 'recaptcha-for-woocommerce' ), 'default' => 'v2', 'options' => array( 'v2' => esc_html__( 'reCaptcha v2 (checkbox)', 'recaptcha-for-woocommerce' ), 'v3' => esc_html__( 'reCaptcha v3 (no checkbox)', 'recaptcha-for-woocommerce' ), ), ), array( 'id' => 'wc_recaptcha_site_key_v2', 'type' => 'text', 'title' => esc_html__( 'Site Key v2', 'recaptcha-for-woocommerce' ), 'desc' => __( 'Get the site key from here.', 'recaptcha-for-woocommerce' ), 'default' => '', 'require' => $this->dependency_required_attribute( array( 'wc_recaptcha_version' => array( 'type' => '==', 'value' => 'v2' ) ) ), ), array( 'id' => 'wc_recaptcha_secret_key_v2', 'type' => 'text', 'title' => esc_html__( 'Secret Key v2', 'recaptcha-for-woocommerce' ), 'desc' => __( 'Get the secret key from here.', 'recaptcha-for-woocommerce' ), 'default' => '', 'require' => $this->dependency_required_attribute( array( 'wc_recaptcha_version' => array( 'type' => '==', 'value' => 'v2' ) ) ), ), array( 'id' => 'wc_recaptcha_site_key_v3', 'type' => 'text', 'title' => esc_html__( 'Site Key v3', 'recaptcha-for-woocommerce' ), 'desc' => __( 'Get the site key from here.', 'recaptcha-for-woocommerce' ), 'default' => '', 'require' => $this->dependency_required_attribute( array( 'wc_recaptcha_version' => array( 'type' => '==', 'value' => 'v3' ) ) ), ), array( 'id' => 'wc_recaptcha_secret_key_v3', 'type' => 'text', 'title' => esc_html__( 'Secret Key v3', 'recaptcha-for-woocommerce' ), 'desc' => __( 'Get the secret key from here.', 'recaptcha-for-woocommerce' ), 'default' => '', 'require' => $this->dependency_required_attribute( array( 'wc_recaptcha_version' => array( 'type' => '==', 'value' => 'v3' ) ) ), ), array( 'id' => 'wc_recaptcha_theme', 'type' => 'select', 'class' => 'wc-enhanced-select', 'title' => esc_html__( 'reCaptcha theme', 'recaptcha-for-woocommerce' ), 'default' => 'light', 'options' => array( 'light' => esc_html__( 'Light', 'recaptcha-for-woocommerce' ), 'dark' => esc_html__( 'Dark', 'recaptcha-for-woocommerce' ), ), 'require' => $this->dependency_required_attribute( array( 'wc_recaptcha_version' => array( 'type' => '==', 'value' => 'v2' ) ) ), ), array( 'id' => 'wc_recaptcha_size', 'type' => 'select', 'class' => 'wc-enhanced-select', 'title' => esc_html__( 'reCaptcha size', 'recaptcha-for-woocommerce' ), 'default' => 'normal', 'options' => array( 'normal' => esc_html__( 'Normal', 'recaptcha-for-woocommerce' ), 'compact' => esc_html__( 'Compact', 'recaptcha-for-woocommerce' ), ), 'require' => $this->dependency_required_attribute( array( 'wc_recaptcha_version' => array( 'type' => '==', 'value' => 'v2' ) ) ), ), array( 'id' => 'wc_recaptcha_language', 'type' => 'select', 'class' => 'wc-enhanced-select', 'title' => esc_html__( 'reCaptcha language', 'recaptcha-for-woocommerce' ), 'default' => '', 'options' => $this->get_langs() ), // Section End array( 'type' => 'sectionend', 'id' => 'wc_recaptcha_default_options' ), ); $settings = apply_filters( 'wc_recaptcha_default_settings_fields', $settings ); return apply_filters( 'wc_recaptcha_default_settings', $settings ); } public function get_settings_for_woocommerce_section() { $settings = array( // WooCommerce login array( 'type' => 'title', 'id' => 'wc_recaptcha_login_options', 'title' => esc_html__( 'WooCommerce Login', 'recaptcha-for-woocommerce' ), ), array( 'id' => 'wc_enable_login_recaptcha', 'type' => 'checkbox', 'title' => esc_html__( 'Enable Login reCaptcha', 'recaptcha-for-woocommerce' ), 'default' => 'yes', ), // Section End array( 'type' => 'sectionend', 'id' => 'wc_recaptcha_login_options' ), // WooCommerce register array( 'type' => 'title', 'id' => 'wc_recaptcha_register_options', 'title' => esc_html__( 'WooCommerce Register', 'recaptcha-for-woocommerce' ), ), array( 'id' => 'wc_enable_register_recaptcha', 'type' => 'checkbox', 'title' => esc_html__( 'Enable Register reCaptcha', 'recaptcha-for-woocommerce' ), 'default' => 'yes', ), // Section End array( 'type' => 'sectionend', 'id' => 'wc_recaptcha_register_options' ), // WooCommerce password reset array( 'type' => 'title', 'id' => 'wc_recaptcha_password_reset_options', 'title' => esc_html__( 'WooCommerce Password Reset', 'recaptcha-for-woocommerce' ), ), array( 'id' => 'wc_enable_password_reset_recaptcha', 'type' => 'checkbox', 'title' => esc_html__( 'Enable Password Reset reCaptcha', 'recaptcha-for-woocommerce' ), 'default' => 'yes', ), // Section End array( 'type' => 'sectionend', 'id' => 'wc_recaptcha_password_reset_options' ), // WooCommerce Checkout array( 'type' => 'title', 'id' => 'wc_recaptcha_checkout_options', 'title' => esc_html__( 'WooCommerce Checkout', 'recaptcha-for-woocommerce' ), ), array( 'id' => 'wc_enable_checkout_recaptcha', 'type' => 'checkbox', 'title' => esc_html__( 'Enable Checkout reCaptcha', 'recaptcha-for-woocommerce' ), 'default' => 'yes', ), // Section End array( 'type' => 'sectionend', 'id' => 'wc_recaptcha_checkout_options' ), ); $settings = apply_filters( 'wc_recaptcha_styles_settings_fields', $settings ); return apply_filters( 'wc_recaptcha_styles_settings', $settings ); } /** * Escape JSON for use on HTML or attribute text nodes. * * @param string $json JSON to escape. * @param bool $html True if escaping for HTML text node, false for attributes. Determines how quotes are handled. * * @return string Escaped JSON. */ public static function esc_json( $json, $html = false ) { return _wp_specialchars( $json, $html ? ENT_NOQUOTES : ENT_QUOTES, // Escape quotes in attribute nodes only. 'UTF-8', // json_encode() outputs UTF-8 (really just ASCII), not the blog's charset. true // Double escape entities: `&` -> `&`. ); } public static function dependency_attribute( $value ){ if( $value && isset( $value['require'] ) ) { return sprintf('data-rfw_dependency="%s"', self::esc_json( wp_json_encode( $value['require'] ) ) ); } return ''; } public function output_fields( $options ) { foreach ( $options as $value ) { if ( ! isset( $value['type'] ) ) { continue; } if ( ! isset( $value['id'] ) ) { $value['id'] = ''; } if ( ! isset( $value['title'] ) ) { $value['title'] = isset( $value['name'] ) ? $value['name'] : ''; } if ( ! isset( $value['class'] ) ) { $value['class'] = ''; } if ( ! isset( $value['css'] ) ) { $value['css'] = ''; } if ( ! isset( $value['default'] ) ) { $value['default'] = ''; } if ( ! isset( $value['desc'] ) ) { $value['desc'] = ''; } if ( ! isset( $value['desc_tip'] ) ) { $value['desc_tip'] = false; } if ( ! isset( $value['placeholder'] ) ) { $value['placeholder'] = ''; } if ( ! isset( $value['suffix'] ) ) { $value['suffix'] = ''; } if ( ! isset( $value['is_pro'] ) ) { $value['is_pro'] = false; } if ( ! isset( $value['value'] ) ) { $value['value'] = WC_Admin_Settings::get_option( $value['id'], $value['default'] ); } $classes = array(); if ( ! function_exists( 'recaptcha_for_woocommerce_pro' ) ) { if( $value['is_pro'] ){ $classes[] = 'is-pro'; } } $class = implode( ' ', array_values( array_unique( $classes ) ) ); // Custom attribute handling. $custom_attributes = array(); if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) { foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) { $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"'; } } $custom_attributes = implode( ' ', $custom_attributes ); // Description handling. $field_description = WC_Admin_Settings::get_field_description( $value ); $description = $field_description['description']; $tooltip_html = $field_description['tooltip_html']; // Switch based on type. switch ( $value['type'] ) { // Section Titles. case 'title': if ( ! empty( $value['title'] ) ) { echo '