| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Integrations\Blocks; |
| 4 |
|
| 5 |
use WPSEO_Admin_Asset_Manager; |
| 6 |
use Yoast\WP\SEO\Integrations\Integration_Interface; |
| 7 |
|
| 8 |
/** |
| 9 |
* Class to load assets required for structured data blocks. |
| 10 |
*/ |
| 11 |
class Structured_Data_Blocks implements Integration_Interface { |
| 12 |
|
| 13 |
/** |
| 14 |
* An instance of the WPSEO_Admin_Asset_Manager class. |
| 15 |
* |
| 16 |
* @var WPSEO_Admin_Asset_Manager |
| 17 |
*/ |
| 18 |
protected $asset_manager; |
| 19 |
|
| 20 |
/** |
| 21 |
* {@inheritDoc} |
| 22 |
*/ |
| 23 |
public static function get_conditionals() { |
| 24 |
return []; |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Structured_Data_Blocks constructor. |
| 29 |
* |
| 30 |
* @param WPSEO_Admin_Asset_Manager $asset_manager The asset manager. |
| 31 |
*/ |
| 32 |
public function __construct( WPSEO_Admin_Asset_Manager $asset_manager ) { |
| 33 |
$this->asset_manager = $asset_manager; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Registers hooks for Structured Data Blocks with WordPress. |
| 38 |
*/ |
| 39 |
public function register_hooks() { |
| 40 |
\add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_block_editor_assets' ] ); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Enqueue Gutenberg block assets for backend editor. |
| 45 |
*/ |
| 46 |
public function enqueue_block_editor_assets() { |
| 47 |
/** |
| 48 |
* Filter: 'wpseo_enable_structured_data_blocks' - Allows disabling Yoast's schema blocks entirely. |
| 49 |
* |
| 50 |
* @api bool If false, our structured data blocks won't show. |
| 51 |
*/ |
| 52 |
if ( ! \apply_filters( 'wpseo_enable_structured_data_blocks', true ) ) { |
| 53 |
return; |
| 54 |
} |
| 55 |
|
| 56 |
$this->asset_manager->enqueue_script( 'structured-data-blocks' ); |
| 57 |
$this->asset_manager->enqueue_style( 'structured-data-blocks' ); |
| 58 |
} |
| 59 |
} |
| 60 |
|