Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
38.14% |
37 / 97 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Post | |
38.14% |
37 / 97 |
|
66.67% |
2 / 3 |
5.13 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| register_wallet_post_type | |
100.00% |
36 / 36 |
|
100.00% |
1 / 1 |
1 | |||
| register_address_post_type | |
0.00% |
0 / 60 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Add a custom post type for Bitcoin address. |
| 4 | * Will have statuses 'unused', 'used', 'assigned'. |
| 5 | * Will have postmeta for: |
| 6 | * * its derive path |
| 7 | * * which order it is for |
| 8 | * * its transactions |
| 9 | * * its balance |
| 10 | * Its parent will be its xpub. |
| 11 | * |
| 12 | * WP_List_Table can show all addresses and their orders and balances and last activity date. |
| 13 | * |
| 14 | * @see \BrianHenryIE\WP_Bitcoin_Gateway\Admin\Addresses_List_Table |
| 15 | * @see \BrianHenryIE\WP_Bitcoin_Gateway\Admin\Wallets_List_Table |
| 16 | * |
| 17 | * @package brianhenryie/bh-wp-bitcoin-gateway |
| 18 | */ |
| 19 | |
| 20 | namespace BrianHenryIE\WP_Bitcoin_Gateway\WP_Includes; |
| 21 | |
| 22 | use BrianHenryIE\WP_Bitcoin_Gateway\API\Addresses\Bitcoin_Address; |
| 23 | use BrianHenryIE\WP_Bitcoin_Gateway\API\Addresses\Bitcoin_Wallet; |
| 24 | use BrianHenryIE\WP_Bitcoin_Gateway\API_Interface; |
| 25 | |
| 26 | /** |
| 27 | * Register the custom post types with WordPress. |
| 28 | * |
| 29 | * @see register_post_type() |
| 30 | * @see register_post_status() |
| 31 | * |
| 32 | * @see wp-admin/edit.php?post_type=bh-bitcoin-wallet |
| 33 | * @see wp-admin/edit.php?post_type=bh-bitcoin-address |
| 34 | */ |
| 35 | class Post { |
| 36 | |
| 37 | /** |
| 38 | * Array of plugin objects to pass to post types. |
| 39 | * |
| 40 | * @var array{api:API_Interface} $plugin_objects |
| 41 | */ |
| 42 | protected array $plugin_objects = array(); |
| 43 | |
| 44 | /** |
| 45 | * Constructor |
| 46 | * |
| 47 | * @param API_Interface $api The main plugin functions. |
| 48 | */ |
| 49 | public function __construct( API_Interface $api ) { |
| 50 | $this->plugin_objects['api'] = $api; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Registers the bh-bitcoin-wallet post type and its statuses. |
| 55 | * |
| 56 | * @hooked init |
| 57 | */ |
| 58 | public function register_wallet_post_type(): void { |
| 59 | |
| 60 | $labels = array( |
| 61 | 'name' => _x( 'Bitcoin Wallets', 'post type general name', 'bh-wp-bitcoin-gateway' ), |
| 62 | 'singular_name' => _x( 'Bitcoin Wallet', 'post type singular name', 'bh-wp-bitcoin-gateway' ), |
| 63 | 'menu_name' => 'Bitcoin Wallets', |
| 64 | ); |
| 65 | |
| 66 | $args = array( |
| 67 | 'labels' => $labels, |
| 68 | 'description' => 'Wallets used with WooCommerce Bitcoin gateways.', |
| 69 | 'public' => true, |
| 70 | 'menu_position' => 8, |
| 71 | 'supports' => array( 'title', 'thumbnail', 'excerpt', 'comments' ), |
| 72 | 'has_archive' => false, |
| 73 | 'show_in_menu' => false, |
| 74 | 'plugin_objects' => $this->plugin_objects, |
| 75 | ); |
| 76 | |
| 77 | register_post_type( BITCOIN_WALLET::POST_TYPE, $args ); |
| 78 | |
| 79 | register_post_status( |
| 80 | 'active', |
| 81 | array( |
| 82 | 'label' => _x( 'Active', 'post', 'bh-wp-bitcoin-gateway' ), |
| 83 | 'public' => true, |
| 84 | 'show_in_admin_all_list' => true, |
| 85 | 'show_in_admin_status_list' => true, |
| 86 | /* translators: %s is the number of Bitcoin wallets that are in use. */ |
| 87 | 'label_count' => _n_noop( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>' ), |
| 88 | ) |
| 89 | ); |
| 90 | |
| 91 | register_post_status( |
| 92 | 'inactive', |
| 93 | array( |
| 94 | 'label' => _x( 'Inactive', 'post', 'bh-wp-bitcoin-gateway' ), |
| 95 | 'public' => true, |
| 96 | 'show_in_admin_all_list' => true, |
| 97 | 'show_in_admin_status_list' => true, |
| 98 | /* translators: %s is the number of Bitcoin wallets that have been created but are not currently in use. */ |
| 99 | 'label_count' => _n_noop( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>' ), |
| 100 | ) |
| 101 | ); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Registers the bh-bitcoin-address post type and its statuses. |
| 106 | * |
| 107 | * @hooked init |
| 108 | */ |
| 109 | public function register_address_post_type(): void { |
| 110 | |
| 111 | $labels = array( |
| 112 | 'name' => _x( 'Bitcoin Addresses', 'post type general name', 'bh-wp-bitcoin-gateway' ), |
| 113 | 'singular_name' => _x( 'Bitcoin Address', 'post type singular name', 'bh-wp-bitcoin-gateway' ), |
| 114 | 'menu_name' => 'Bitcoin Addresses', |
| 115 | ); |
| 116 | $args = array( |
| 117 | 'labels' => $labels, |
| 118 | 'description' => 'Addresses used with WooCommerce Bitcoin gateways.', |
| 119 | 'public' => true, |
| 120 | 'menu_position' => 8, |
| 121 | 'supports' => array( 'title', 'thumbnail', 'excerpt', 'comments' ), |
| 122 | 'has_archive' => false, |
| 123 | 'show_in_menu' => false, |
| 124 | 'plugin_objects' => $this->plugin_objects, |
| 125 | ); |
| 126 | register_post_type( BITCOIN_ADDRESS::POST_TYPE, $args ); |
| 127 | |
| 128 | register_post_status( |
| 129 | 'unknown', |
| 130 | array( |
| 131 | 'post_type' => array( Bitcoin_Address::POST_TYPE ), |
| 132 | 'label' => _x( 'Unknown', 'post' ), |
| 133 | 'public' => true, |
| 134 | 'show_in_admin_all_list' => true, |
| 135 | 'show_in_admin_status_list' => true, |
| 136 | /* translators: %s is the number of Bitcoin addresses whose status is unknown. */ |
| 137 | 'label_count' => _n_noop( 'Unknown <span class="count">(%s)</span>', 'Unknown <span class="count">(%s)</span>' ), |
| 138 | ) |
| 139 | ); |
| 140 | |
| 141 | register_post_status( |
| 142 | 'unused', |
| 143 | array( |
| 144 | 'post_type' => array( Bitcoin_Address::POST_TYPE ), |
| 145 | 'label' => _x( 'Unused', 'post' ), |
| 146 | 'public' => true, |
| 147 | 'show_in_admin_all_list' => true, |
| 148 | 'show_in_admin_status_list' => true, |
| 149 | /* translators: %s is the number of Bitcoin addresses that have yet to be used. */ |
| 150 | 'label_count' => _n_noop( 'Unused <span class="count">(%s)</span>', 'Unused <span class="count">(%s)</span>' ), |
| 151 | ) |
| 152 | ); |
| 153 | |
| 154 | register_post_status( |
| 155 | 'assigned', |
| 156 | array( |
| 157 | 'post_type' => array( Bitcoin_Address::POST_TYPE ), |
| 158 | 'label' => _x( 'Assigned', 'post' ), |
| 159 | 'public' => true, |
| 160 | 'show_in_admin_all_list' => true, |
| 161 | 'show_in_admin_status_list' => true, |
| 162 | /* translators: %s is the number of Bitcoin addresses that have been assigned. */ |
| 163 | 'label_count' => _n_noop( 'Assigned <span class="count">(%s)</span>', 'Assigned <span class="count">(%s)</span>' ), |
| 164 | ) |
| 165 | ); |
| 166 | |
| 167 | register_post_status( |
| 168 | 'used', |
| 169 | array( |
| 170 | 'post_type' => array( Bitcoin_Address::POST_TYPE ), |
| 171 | 'label' => _x( 'Used', 'post' ), |
| 172 | 'public' => true, |
| 173 | 'show_in_admin_all_list' => true, |
| 174 | 'show_in_admin_status_list' => true, |
| 175 | /* translators: %s is the number of Bitcoin addresses that have been used. */ |
| 176 | 'label_count' => _n_noop( 'Used <span class="count">(%s)</span>', 'Used <span class="count">(%s)</span>' ), |
| 177 | ) |
| 178 | ); |
| 179 | } |
| 180 | } |