← All changes
|
includes/block-formatters/class-convertkit-block-formatter-product-link.php
+13
-10
2.2.1
→
3.4.4
View file →
| @@ -38,10 +38,14 @@ | ||
| 38 | 38 | * @since 2.2.0 |
| 39 | 39 | */ |
| 40 | 40 | public function __construct() { |
| 41 | 41 | |
| 42 | - // Register this as a Gutenberg block formatter in the ConvertKit Plugin. | |
| 43 | - add_filter( 'convertkit_get_block_formatters', array( $this, 'register' ) ); | |
| 42 | + // Register this as a Gutenberg block formatter in the ConvertKit Plugin, | |
| 43 | + // if forms exist on ConvertKit. | |
| 44 | + $this->products = new ConvertKit_Resource_Products( 'block_formatter_register' ); | |
| 45 | + if ( $this->products->exist() ) { | |
| 46 | + add_filter( 'convertkit_get_block_formatters', array( $this, 'register' ) ); | |
| 47 | + } | |
| 44 | 48 | |
| 45 | 49 | } |
| 46 | 50 | |
| 47 | 51 | /** |
| @@ -66,14 +70,14 @@ | ||
| 66 | 70 | */ |
| 67 | 71 | public function get_overview() { |
| 68 | 72 | |
| 69 | 73 | return array( |
| 70 | - 'title' => __( 'ConvertKit Product Trigger', 'convertkit' ), | |
| 74 | + 'title' => __( 'Kit Product Trigger', 'convertkit' ), | |
| 71 | 75 | 'description' => __( 'Displays the Product modal when the link is pressed.', 'convertkit' ), |
| 72 | - 'icon' => 'resources/backend/images/block-icon-product.png', | |
| 76 | + 'icon' => 'resources/backend/images/block-icon-product.svg', | |
| 73 | 77 | |
| 74 | 78 | // Gutenberg: Block Icon in Editor. |
| 75 | - 'gutenberg_icon' => file_get_contents( CONVERTKIT_PLUGIN_PATH . '/resources/backend/images/block-icon-product.svg' ), /* phpcs:ignore */ | |
| 79 | + 'gutenberg_icon' => convertkit_get_file_contents( CONVERTKIT_PLUGIN_PATH . '/resources/backend/images/block-icon-product.svg' ), | |
| 76 | 80 | ); |
| 77 | 81 | |
| 78 | 82 | } |
| 79 | 83 | |
| @@ -110,13 +114,12 @@ | ||
| 110 | 114 | return false; |
| 111 | 115 | } |
| 112 | 116 | |
| 113 | 117 | // Get ConvertKit Products. |
| 114 | - $products = array(); | |
| 115 | - $products_data = array(); | |
| 116 | - $convertkit_products = new ConvertKit_Resource_Products(); | |
| 117 | - if ( $convertkit_products->exist() ) { | |
| 118 | - foreach ( $convertkit_products->get() as $product ) { | |
| 118 | + $products = array(); | |
| 119 | + $products_data = array(); | |
| 120 | + if ( $this->products->exist() ) { | |
| 121 | + foreach ( $this->products->get() as $product ) { | |
| 119 | 122 | $products[ absint( $product['id'] ) ] = sanitize_text_field( $product['name'] ); |
| 120 | 123 | $products_data[ absint( $product['id'] ) ] = array( |
| 121 | 124 | 'data-id' => sanitize_text_field( $product['id'] ), |
| 122 | 125 | 'data-commerce' => '1', |