Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Menu
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 add_woocommerce_payments_submenu
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2/**
3 * Add an admin submenu of the WooCommerce "Payments" menu item, linking to the Bitcoin gateway.
4 *
5 * @package brianhenryie/bh-wp-bitcoin-gateway
6 */
7
8namespace BrianHenryIE\WP_Bitcoin_Gateway\Integrations\WooCommerce;
9
10/**
11 * @see \Automattic\WooCommerce\Internal\Admin\Settings\PaymentsController::add_menu()
12 */
13class Menu {
14
15    /**
16     * Constructor
17     *
18     * @param API_WooCommerce_Interface $api_woocommerce To get the list of Bitcoin gateways and their ids.
19     */
20    public function __construct(
21        protected API_WooCommerce_Interface $api_woocommerce,
22    ) {
23    }
24
25    /**
26     * @hooked admin_menu
27     */
28    public function add_woocommerce_payments_submenu(): void {
29
30        $bitcoin_gateways = $this->api_woocommerce->get_bitcoin_gateways();
31
32        foreach ( $bitcoin_gateways as $bitcoin_gateway ) {
33            $id_in_title = count( $bitcoin_gateways ) === 1 ? '' : " ({$bitcoin_gateway->id})";
34            add_submenu_page(
35                'admin.php?page=wc-settings&tab=checkout&from=PAYMENTS_MENU_ITEM',
36                'Bitcoin Gateway',
37                'Bitcoin' . $id_in_title,
38                'manage_woocommerce',
39                'admin.php?page=wc-settings&tab=checkout&section=' . $bitcoin_gateway->id
40            );
41        }
42    }
43}