ProductTemplate.php
195 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WooCommerce Product Editor Product Template compatibility shim. |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Admin\Features\ProductBlockEditor; |
| 7 | |
| 8 | /** |
| 9 | * Removed product editor product template value object. |
| 10 | * |
| 11 | * @deprecated 10.9.0 Product editor extension APIs were deprecated. The product block editor was removed in 11.0.0 with no replacement. |
| 12 | */ |
| 13 | class ProductTemplate { |
| 14 | /** |
| 15 | * Whether the removal warning has already been logged for the current request. |
| 16 | * |
| 17 | * @var bool |
| 18 | */ |
| 19 | private static $removal_warning_logged = false; |
| 20 | |
| 21 | /** |
| 22 | * Constructor. |
| 23 | * |
| 24 | * @param array $data Template data. |
| 25 | */ |
| 26 | public function __construct( array $data ) { |
| 27 | unset( $data ); |
| 28 | |
| 29 | self::maybe_log_removal_warning(); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Get the template ID. |
| 34 | * |
| 35 | * @return string |
| 36 | */ |
| 37 | public function get_id() { |
| 38 | self::maybe_log_removal_warning(); |
| 39 | |
| 40 | return ''; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Get the template title. |
| 45 | * |
| 46 | * @return string |
| 47 | */ |
| 48 | public function get_title() { |
| 49 | self::maybe_log_removal_warning(); |
| 50 | |
| 51 | return ''; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Get the layout template ID. |
| 56 | * |
| 57 | * @return string|null |
| 58 | */ |
| 59 | public function get_layout_template_id() { |
| 60 | self::maybe_log_removal_warning(); |
| 61 | |
| 62 | return null; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Set the layout template ID. |
| 67 | * |
| 68 | * @param string $layout_template_id The layout template ID. |
| 69 | * @return void |
| 70 | */ |
| 71 | public function set_layout_template_id( string $layout_template_id ) { |
| 72 | unset( $layout_template_id ); |
| 73 | |
| 74 | self::maybe_log_removal_warning(); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Get the product data. |
| 79 | * |
| 80 | * @return array |
| 81 | */ |
| 82 | public function get_product_data() { |
| 83 | self::maybe_log_removal_warning(); |
| 84 | |
| 85 | return array(); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Get the template description. |
| 90 | * |
| 91 | * @return string|null |
| 92 | */ |
| 93 | public function get_description() { |
| 94 | self::maybe_log_removal_warning(); |
| 95 | |
| 96 | return null; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Set the template description. |
| 101 | * |
| 102 | * @param string $description The template description. |
| 103 | * @return void |
| 104 | */ |
| 105 | public function set_description( string $description ) { |
| 106 | unset( $description ); |
| 107 | |
| 108 | self::maybe_log_removal_warning(); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Get the template icon. |
| 113 | * |
| 114 | * @return string|null |
| 115 | */ |
| 116 | public function get_icon() { |
| 117 | self::maybe_log_removal_warning(); |
| 118 | |
| 119 | return null; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Set the template icon. |
| 124 | * |
| 125 | * @param string $icon The icon name or an external image URL. |
| 126 | * @return void |
| 127 | */ |
| 128 | public function set_icon( string $icon ) { |
| 129 | unset( $icon ); |
| 130 | |
| 131 | self::maybe_log_removal_warning(); |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Get the template order. |
| 136 | * |
| 137 | * @return int |
| 138 | */ |
| 139 | public function get_order() { |
| 140 | self::maybe_log_removal_warning(); |
| 141 | |
| 142 | return 999; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Get the selectable attribute. |
| 147 | * |
| 148 | * @return bool |
| 149 | */ |
| 150 | public function get_is_selectable_by_user() { |
| 151 | self::maybe_log_removal_warning(); |
| 152 | |
| 153 | return false; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Set the template order. |
| 158 | * |
| 159 | * @param int $order The template order. |
| 160 | * @return void |
| 161 | */ |
| 162 | public function set_order( int $order ) { |
| 163 | unset( $order ); |
| 164 | |
| 165 | self::maybe_log_removal_warning(); |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Get the product template as JSON-like data. |
| 170 | * |
| 171 | * @return array |
| 172 | */ |
| 173 | public function to_json() { |
| 174 | self::maybe_log_removal_warning(); |
| 175 | |
| 176 | return array(); |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Log a warning about the removed compatibility class. |
| 181 | */ |
| 182 | private static function maybe_log_removal_warning(): void { |
| 183 | if ( self::$removal_warning_logged || ! function_exists( 'wc_get_logger' ) ) { |
| 184 | return; |
| 185 | } |
| 186 | |
| 187 | self::$removal_warning_logged = true; |
| 188 | |
| 189 | wc_get_logger()->warning( |
| 190 | 'Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplate is a temporary compatibility shim and will be removed soon. Product editor extension APIs were deprecated in WooCommerce 10.9.0, and the product block editor was removed in WooCommerce 11.0.0 with no replacement.', |
| 191 | array( 'source' => 'product-block-editor' ) |
| 192 | ); |
| 193 | } |
| 194 | } |
| 195 |