Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
41.18% |
7 / 17 |
|
37.50% |
3 / 8 |
CRAP | |
0.00% |
0 / 1 |
Settings | |
41.18% |
7 / 17 |
|
37.50% |
3 / 8 |
47.40 | |
0.00% |
0 / 1 |
get_log_level | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
get_plugin_name | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
get_plugin_slug | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get_plugin_basename | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
get_plugin_version | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
get_plugin_url | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
get_master_public_key | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
get_plugin_dir | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | /** |
3 | * Object containing the plugin settings. |
4 | * |
5 | * @package brianhenryie/bh-wp-bitcoin-gateway |
6 | */ |
7 | |
8 | namespace BrianHenryIE\WP_Bitcoin_Gateway\API; |
9 | |
10 | use BrianHenryIE\WP_Bitcoin_Gateway\Admin\Dependencies_Notice; |
11 | use BrianHenryIE\WP_Bitcoin_Gateway\Admin\Plugins_Page; |
12 | use BrianHenryIE\WP_Bitcoin_Gateway\Frontend\Frontend_Assets; |
13 | use BrianHenryIE\WP_Bitcoin_Gateway\WP_Logger\Logger_Settings_Interface; |
14 | use BrianHenryIE\WP_Bitcoin_Gateway\WP_Logger\Logger_Settings_Trait; |
15 | use BrianHenryIE\WP_Bitcoin_Gateway\WP_Logger\WooCommerce_Logger_Settings_Interface; |
16 | use BrianHenryIE\WP_Bitcoin_Gateway\Settings_Interface; |
17 | use Psr\Log\LogLevel; |
18 | |
19 | /** |
20 | * Plain object pulling setting from wp_options. |
21 | */ |
22 | class Settings implements Settings_Interface, WooCommerce_Logger_Settings_Interface { |
23 | use Logger_Settings_Trait; |
24 | |
25 | /** |
26 | * The minimum severity of logs to record. |
27 | * |
28 | * @see LogLevel |
29 | * |
30 | * @return string |
31 | */ |
32 | public function get_log_level(): string { |
33 | $gateway_id = 'bitcoin_gateway'; |
34 | $saved_settings = get_option( 'woocommerce_' . $gateway_id . '_settings', array() ); |
35 | $log_levels = array( LogLevel::DEBUG, LogLevel::INFO, LogLevel::ERROR, LogLevel::NOTICE, LogLevel::WARNING, 'none' ); |
36 | $level = $saved_settings['log_level'] ?? 'info'; |
37 | return in_array( $level, $log_levels, true ) ? $level : 'info'; |
38 | } |
39 | |
40 | /** |
41 | * Plugin name for use by the logger in friendly messages printed to WordPress admin UI. |
42 | * |
43 | * @see Logger |
44 | * |
45 | * @return string |
46 | */ |
47 | public function get_plugin_name(): string { |
48 | return 'Bitcoin Gateway'; |
49 | } |
50 | |
51 | /** |
52 | * The plugin slug is used by the logger in file and URL paths. |
53 | * |
54 | * @return string |
55 | */ |
56 | public function get_plugin_slug(): string { |
57 | return 'bh-wp-bitcoin-gateway'; |
58 | } |
59 | |
60 | /** |
61 | * Used to add links on plugins.php, and to add "Deactivate plugin" link when GMP PHP extension is missing. |
62 | * |
63 | * @used-by Plugins_Page |
64 | * @used-by Dependencies_Notice::print_dependencies_notice() |
65 | * |
66 | * @see Logger_Settings_Interface::get_plugin_basename() |
67 | * |
68 | * @return string |
69 | */ |
70 | public function get_plugin_basename(): string { |
71 | return defined( 'BH_WP_BITCOIN_GATEWAY_BASENAME' ) ? BH_WP_BITCOIN_GATEWAY_BASENAME : 'bh-wp-bitcoin-gateway/bh-wp-bitcoin-gateway.php'; |
72 | } |
73 | |
74 | /** |
75 | * The plugin version, as used in caching JS and CSS assets. |
76 | * |
77 | * @return string |
78 | */ |
79 | public function get_plugin_version(): string { |
80 | return defined( 'BH_WP_BITCOIN_GATEWAY_VERSION' ) ? BH_WP_BITCOIN_GATEWAY_VERSION : '2.0.0'; |
81 | } |
82 | |
83 | /** |
84 | * Return the URL of the base of the plugin. |
85 | * |
86 | * @used-by Frontend_Assets::enqueue_scripts() |
87 | * @used-by Frontend_Assets::enqueue_styles() |
88 | */ |
89 | public function get_plugin_url(): string { |
90 | return defined( 'BH_WP_BITCOIN_GATEWAY_URL' ) |
91 | ? BH_WP_BITCOIN_GATEWAY_URL |
92 | : plugins_url( $this->get_plugin_basename() ); |
93 | } |
94 | |
95 | /** |
96 | * Get the master public key (xpub...) for the specified gateway instance. |
97 | * |
98 | * @param string $gateway_id The id of the Bitcoin gateway. |
99 | * |
100 | * @return string |
101 | */ |
102 | public function get_master_public_key( string $gateway_id = 'bitcoin_gateway' ): string { |
103 | $saved_settings = get_option( 'woocommerce_' . $gateway_id . '_settings', array() ); |
104 | return $saved_settings['xpub'] ?? ''; |
105 | } |
106 | |
107 | /** |
108 | * Get the absolute path to the plugin root on the server filesystem, with trailingslash. |
109 | */ |
110 | public function get_plugin_dir(): string { |
111 | return defined( 'BH_WP_BITCOIN_GATEWAY_PATH' ) |
112 | ? BH_WP_BITCOIN_GATEWAY_PATH |
113 | : WP_PLUGIN_DIR . '/' . plugin_dir_path( $this->get_plugin_basename() ); |
114 | } |
115 | } |