class-structured-data-blocks.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin
  6. */
  7. /**
  8. * Class to load assets required for structured data blocks.
  9. */
  10. class WPSEO_Structured_Data_Blocks implements WPSEO_WordPress_Integration {
  11. /**
  12. * @var WPSEO_Admin_Asset_Manager
  13. */
  14. protected $asset_manager;
  15. /**
  16. * WPSEO_Structured_Data_Blocks constructor.
  17. */
  18. public function __construct() {
  19. $this->asset_manager = new WPSEO_Admin_Asset_Manager();
  20. }
  21. /**
  22. * Registers hooks for Structured Data Blocks with WordPress.
  23. */
  24. public function register_hooks() {
  25. add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ) );
  26. add_filter( 'block_categories', array( $this, 'add_block_category' ) );
  27. $block_integrations = array(
  28. new WPSEO_How_To_Block(),
  29. new WPSEO_FAQ_Block(),
  30. );
  31. foreach ( $block_integrations as $block_integration ) {
  32. $block_integration->register_hooks();
  33. }
  34. }
  35. /**
  36. * Enqueue Gutenberg block assets for backend editor.
  37. */
  38. public function enqueue_block_editor_assets() {
  39. $this->asset_manager->enqueue_script( 'structured-data-blocks' );
  40. $this->asset_manager->enqueue_style( 'structured-data-blocks' );
  41. }
  42. /**
  43. * Adds the structured data blocks category to the Gutenberg categories.
  44. *
  45. * @param array $categories The current categories.
  46. *
  47. * @return array The updated categories.
  48. */
  49. public function add_block_category( $categories ) {
  50. $categories[] = array(
  51. 'slug' => 'yoast-structured-data-blocks',
  52. 'title' => sprintf(
  53. /* translators: %1$s expands to Yoast. */
  54. __( '%1$s Structured Data Blocks', 'wordpress-seo' ),
  55. 'Yoast'
  56. ),
  57. );
  58. return $categories;
  59. }
  60. }