Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 41
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Shipping_Settings_Page
0.00% covered (danger)
0.00%
0 / 41
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 address_validation_section
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 address_validation_settings
0.00% covered (danger)
0.00%
0 / 39
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2/**
3 * The setting pages for the plugin.
4 *
5 * @link       https://github.com/BrianHenryIE/bh-wc-address-validation
6 * @since      1.0.0
7 *
8 * @package    BH_WC_Address_Validation
9 * @subpackage BH_WC_Address_Validation/admin
10 */
11
12namespace BrianHenryIE\WC_Address_Validation\WooCommerce;
13
14use BrianHenryIE\WC_Address_Validation\API\Settings;
15use Psr\Log\LogLevel;
16
17/**
18 * The settings page for the plugin.
19 *
20 * @package    BH_WC_Address_Validation
21 * @subpackage BH_WC_Address_Validation/admin
22 * @author     Brian Henry <BrianHenryIE@gmail.com>
23 */
24class Shipping_Settings_Page {
25
26    /**
27     * @hooked woocommerce_get_sections_shipping
28     *
29     * @param array<string, string> $sections
30     * @return array<string, string>
31     */
32    public function address_validation_section( $sections ): array {
33
34        $sections['bh-wc-address-validation'] = __( 'Address Validation', 'bh-wc-address-validation' );
35
36        return $sections;
37    }
38
39    /**
40     *
41     * @hooked woocommerce_get_settings_shipping
42     *
43     * @param array  $settings
44     * @param string $current_section
45     */
46    public function address_validation_settings( array $settings, string $current_section ): array {
47
48        /**
49         * Check the current section is what we want
50         */
51        if ( 'bh-wc-address-validation' === $current_section ) {
52
53            $settings = array();
54
55            // Add Title to the Settings
56            $settings[] = array(
57                'name' => __( 'Address Validation', 'text-domain' ),
58                'type' => 'title',
59                'desc' => __( 'The following options are used to configure USPS address verification. You must sign up at <a target="_blank" href="https://registration.shippingapis.com/">USPS Web Tools Registration Page</a>.', 'bh-wc-address-validation' ),
60                'id'   => 'bh-wc-address-validation',
61            );
62
63            // USPS username text input.
64            $settings[] = array(
65                'name' => __( 'USPS Username', 'bh-wc-address-validation' ),
66                'desc' => __( 'Your USPS Web Tools API username', 'bh-wc-address-validation' ),
67                'id'   => Settings::USPS_USERNAME_OPTION,
68                'type' => 'text',
69            );
70
71            $settings[] = array(
72                'name' => __( 'EasyPost API Key', 'bh-wc-address-validation' ),
73                'desc' => __( 'Your EasyPost API Key', 'bh-wc-address-validation' ),
74                'id'   => Settings::EASYPOST_API_KEY_OPTION,
75                'type' => 'text',
76            );
77
78            $log_levels        = array( 'none', LogLevel::ERROR, LogLevel::WARNING, LogLevel::NOTICE, LogLevel::INFO, LogLevel::DEBUG );
79            $log_levels_option = array();
80            foreach ( $log_levels as $log_level ) {
81                $log_levels_option[ $log_level ] = ucfirst( $log_level );
82            }
83
84            $settings[] = array(
85                'title'    => __( 'Log Level', 'text-domain' ),
86                'label'    => __( 'Enable Logging', 'text-domain' ),
87                'type'     => 'select',
88                'options'  => $log_levels_option,
89                'desc'     => __( 'Increasing levels of logs.', 'text-domain' ),
90                'desc_tip' => true,
91                'default'  => 'notice',
92                'id'       => 'bh-wc-address-validation-log-level',
93            );
94
95            $settings[] = array(
96                'type' => 'sectionend',
97                'id'   => 'bh-wc-address-validation',
98            );
99
100        }
101
102        return $settings;
103    }
104}