Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Bitcoin_Image_Block
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 add_bitcoin_image_variation
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 * Extend the image block to always show to Bitcoin title image.
4 *
5 * @package brianhenryie/bh-wp-bitcoin-gateway
6 */
7
8namespace BrianHenryIE\WP_Bitcoin_Gateway\Frontend\Blocks;
9
10use BrianHenryIE\WP_Bitcoin_Gateway\Settings_Interface;
11use WP_Block_Type;
12
13/**
14 * @phpstan-type BlockVariationArray array{name:string,title:string,description:string,isDefault?:bool,attributes:array<mixed>,isActive?:array<string>,scope?:array<string>}
15 */
16class Bitcoin_Image_Block {
17
18    /**
19     * Constructor
20     *
21     * @param Settings_Interface $settings Plugin settings, used to determine the plugin url.
22     */
23    public function __construct(
24        protected Settings_Interface $settings,
25    ) {
26    }
27
28    /**
29     * Add a core/image variation that uses the Bitcoin logo.
30     *
31     * /wp-content/plugins/bh-wp-bitcoin-gateway/assets/bitcoin.png
32     *
33     * @hooked get_block_type_variations
34     * @see WP_Block_Type::get_variations()
35     *
36     * @param array<BlockVariationArray> $variations The existing block variations registered for this block type.
37     * @param WP_Block_Type              $block_type The WordPress block type object being filtered.
38     *
39     * @return array<BlockVariationArray> Array of block variations.
40     */
41    public function add_bitcoin_image_variation( array $variations, WP_Block_Type $block_type ): array {
42
43        if ( 'core/image' !== $block_type->name ) {
44            return $variations;
45        }
46
47        $image_url = plugins_url( 'assets/bitcoin.png', $this->settings->get_plugin_basename() );
48
49        $variations[] = array(
50            'name'        => 'bh-bitcoin-image',
51            'title'       => __( 'Bitcoin image', 'bh-wp-bitcoin-gateway' ),
52            'description' => __( 'The Bitcoin logo', 'bh-wp-bitcoin-gateway' ),
53            /** TODO: look up what scope:inserter is here. */
54            'isDefault'   => false,
55            'attributes'  => array(
56                'url' => $image_url,
57            ),
58        );
59
60        return $variations;
61    }
62}