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