Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
57.14% |
16 / 28 |
|
25.00% |
1 / 4 |
CRAP | |
0.00% |
0 / 1 |
Plugins_Page | |
57.14% |
16 / 28 |
|
25.00% |
1 / 4 |
20.52 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
add_settings_action_link | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
3 | |||
add_orders_action_link | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
split_author_link_into_two_links | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
4.03 |
1 | <?php |
2 | /** |
3 | * The plugin page output of the plugin. |
4 | * Adds a "Settings" link |
5 | * Adds an "Orders" link when Filter WooCommerce Orders by Payment Method plugin is installed. |
6 | * |
7 | * @package brianhenryie/bh-wp-bitcoin-gateway |
8 | */ |
9 | |
10 | namespace BrianHenryIE\WP_Bitcoin_Gateway\Admin; |
11 | |
12 | use BrianHenryIE\WP_Bitcoin_Gateway\API_Interface; |
13 | use BrianHenryIE\WP_Bitcoin_Gateway\Settings_Interface; |
14 | use BrianHenryIE\WP_Bitcoin_Gateway\WooCommerce\Bitcoin_Gateway; |
15 | use WC_Payment_Gateway; |
16 | |
17 | /** |
18 | * Adds items to the plugin's row on plugins.php. |
19 | * |
20 | * @see \WP_Plugins_List_Table |
21 | */ |
22 | class Plugins_Page { |
23 | |
24 | /** |
25 | * The plugin basename is needed when checking with plugin's row meta is being filtered. |
26 | * |
27 | * @var Settings_Interface |
28 | */ |
29 | protected Settings_Interface $settings; |
30 | |
31 | /** |
32 | * Used to conditionally print the gateway settings link only if the server dependencies are present. |
33 | * |
34 | * @var API_Interface |
35 | */ |
36 | protected API_Interface $api; |
37 | |
38 | /** |
39 | * Constructor |
40 | * |
41 | * @param API_Interface $api The main plugin functions. |
42 | * @param Settings_Interface $settings The plugin's settings. |
43 | */ |
44 | public function __construct( API_Interface $api, Settings_Interface $settings ) { |
45 | $this->settings = $settings; |
46 | $this->api = $api; |
47 | } |
48 | |
49 | /** |
50 | * Adds 'Settings' link to the configuration under WooCommerce's payment gateway settings page. |
51 | * |
52 | * @hooked plugin_action_links_{plugin basename} |
53 | * |
54 | * @param string[] $links_array The links that will be shown below the plugin name on plugins.php (usually "Deactivate"). |
55 | * |
56 | * @return string[] |
57 | * @see \WP_Plugins_List_Table::display_rows() |
58 | */ |
59 | public function add_settings_action_link( array $links_array ): array { |
60 | |
61 | if ( ! $this->api->is_server_has_dependencies() ) { |
62 | return $links_array; |
63 | } |
64 | |
65 | if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) { |
66 | return $links_array; |
67 | } |
68 | |
69 | /** |
70 | * Default gateway id. |
71 | * |
72 | * @see Bitcoin_Gateway::$id |
73 | */ |
74 | $gateway_id = 'bitcoin_gateway'; |
75 | |
76 | $setting_link = admin_url( "admin.php?page=wc-settings&tab=checkout§ion={$gateway_id}" ); |
77 | $plugin_links = array(); |
78 | $plugin_links[] = '<a href="' . $setting_link . '">' . __( 'Settings', 'bh-wp-bitcoin-gateway' ) . '</a>'; |
79 | |
80 | return array_merge( $plugin_links, $links_array ); |
81 | } |
82 | |
83 | /** |
84 | * Adds 'Orders' link if Filter WooCommerce Orders by Payment Method plugin is installed. |
85 | * |
86 | * @hooked plugin_action_links_{plugin basename} |
87 | * |
88 | * @param string[] $links_array The links that will be shown below the plugin name on plugins.php (usually "Deactivate"). |
89 | * |
90 | * @return string[] |
91 | * @see \WP_Plugins_List_Table::display_rows() |
92 | */ |
93 | public function add_orders_action_link( array $links_array ): array { |
94 | |
95 | $plugin_links = array(); |
96 | |
97 | /** |
98 | * Add an "Orders" link to a filtered list of orders if the Filter WooCommerce Orders by Payment Method plugin is installed. |
99 | * |
100 | * @see https://www.skyverge.com/blog/filtering-woocommerce-orders/ |
101 | */ |
102 | if ( is_plugin_active( 'wc-filter-orders-by-payment/filter-wc-orders-by-gateway.php' ) && is_plugin_active( 'woocommerce/woocommerce.php' ) ) { |
103 | |
104 | $params = array( |
105 | 'post_type' => 'shop_order', |
106 | '_shop_order_payment_method' => 'bitcoin_gateway', |
107 | ); |
108 | |
109 | $orders_link = add_query_arg( $params, admin_url( 'edit.php' ) ); |
110 | $plugin_links[] = '<a href="' . $orders_link . '">' . __( 'Orders', 'bh-wp-bitcoin-gateway' ) . '</a>'; |
111 | } |
112 | |
113 | return array_merge( $plugin_links, $links_array ); |
114 | } |
115 | |
116 | /** |
117 | * There are two authors in the plugin header but WordPress only allows one author link. |
118 | * This function just replaces the generated HTML with two links. |
119 | * |
120 | * @param array<int|string, string> $plugin_meta The meta information/links displayed by the plugin description. |
121 | * @param string $plugin_file_name The plugin filename to match when filtering. |
122 | * |
123 | * @return array<int|string, string> |
124 | */ |
125 | public function split_author_link_into_two_links( array $plugin_meta, string $plugin_file_name ): array { |
126 | |
127 | if ( $this->settings->get_plugin_basename() !== $plugin_file_name ) { |
128 | |
129 | return $plugin_meta; |
130 | } |
131 | |
132 | $updated_plugin_meta = array(); |
133 | foreach ( $plugin_meta as $key => $entry ) { |
134 | |
135 | if ( 0 === strpos( $entry, 'By' ) ) { |
136 | $entry = 'By <a href="https://github.com/Nullcorps/">Nullcorps</a>, <a href="https://brianhenry.ie/">BrianHenryIE</a>'; |
137 | } |
138 | |
139 | $updated_plugin_meta[ $key ] = $entry; |
140 | |
141 | } |
142 | |
143 | return $updated_plugin_meta; |
144 | } |
145 | } |