Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
38 / 38
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Post_BH_Bitcoin_Wallet
100.00% covered (success)
100.00%
38 / 38
100.00% covered (success)
100.00%
2 / 2
2
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
 register_wallet_post_type
100.00% covered (success)
100.00%
37 / 37
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * Add a custom post type for Bitcoin wallet.
4 *
5 * @see \BrianHenryIE\WP_Bitcoin_Gateway\Admin\Wallets_List_Table
6 *
7 * @package brianhenryie/bh-wp-bitcoin-gateway
8 */
9
10namespace BrianHenryIE\WP_Bitcoin_Gateway\WP_Includes;
11
12use BrianHenryIE\WP_Bitcoin_Gateway\API\Model\Wallet\Bitcoin_Wallet_WP_Post_Interface;
13use BrianHenryIE\WP_Bitcoin_Gateway\API_Interface;
14
15/**
16 * Register the custom post types with WordPress.
17 *
18 * @see register_post_type()
19 * @see register_post_status()
20 *
21 * @see wp-admin/edit.php?post_type=bh-bitcoin-wallet
22 */
23class Post_BH_Bitcoin_Wallet {
24
25    /**
26     * Array of plugin objects to pass to post types.
27     *
28     * @var array{api:API_Interface} $plugin_objects
29     */
30    protected array $plugin_objects = array();
31
32    /**
33     * Constructor
34     *
35     * @param API_Interface $api The main plugin functions.
36     */
37    public function __construct( API_Interface $api ) {
38        $this->plugin_objects['api'] = $api;
39    }
40
41    /**
42     * Registers the bh-bitcoin-wallet post type and its statuses.
43     *
44     * @hooked init
45     */
46    public function register_wallet_post_type(): void {
47
48        $labels = array(
49            'name'          => _x( 'Bitcoin Wallets', 'post type general name', 'bh-wp-bitcoin-gateway' ),
50            'singular_name' => _x( 'Bitcoin Wallet', 'post type singular name', 'bh-wp-bitcoin-gateway' ),
51            'menu_name'     => 'Bitcoin Wallets',
52        );
53
54        $args = array(
55            'labels'         => $labels,
56            'description'    => 'Wallets used with WooCommerce Bitcoin gateways.',
57            'public'         => true,
58            'menu_position'  => 8,
59            'supports'       => array( 'title', 'thumbnail', 'excerpt', 'comments' ),
60            'has_archive'    => false,
61            'show_in_menu'   => false,
62            'plugin_objects' => $this->plugin_objects,
63            'show_in_rest'   => false, // TODO: change to `true` after ensuring correct authorization.
64        );
65
66        register_post_type( Bitcoin_Wallet_WP_Post_Interface::POST_TYPE, $args );
67
68        register_post_status(
69            'active',
70            array(
71                'label'                     => _x( 'Active', 'post', 'bh-wp-bitcoin-gateway' ),
72                'public'                    => true,
73                'show_in_admin_all_list'    => true,
74                'show_in_admin_status_list' => true,
75                /* translators: %s is the number of Bitcoin wallets that are in use. */
76                'label_count'               => _n_noop( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>' ),
77            )
78        );
79
80        register_post_status(
81            'inactive',
82            array(
83                'label'                     => _x( 'Inactive', 'post', 'bh-wp-bitcoin-gateway' ),
84                'public'                    => true,
85                'show_in_admin_all_list'    => true,
86                'show_in_admin_status_list' => true,
87                /* translators: %s is the number of Bitcoin wallets that have been created but are not currently in use. */
88                'label_count'               => _n_noop( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>' ),
89            )
90        );
91    }
92}