class-wp-block-editor-context.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Blocks API: WP_Block_Editor_Context class
  4. *
  5. * @package WordPress
  6. * @since 5.8.0
  7. */
  8. /**
  9. * Contains information about a block editor being rendered.
  10. *
  11. * @since 5.8.0
  12. */
  13. #[AllowDynamicProperties]
  14. final class WP_Block_Editor_Context {
  15. /**
  16. * String that identifies the block editor being rendered. Can be one of:
  17. *
  18. * - `'core/edit-post'` - The post editor at `/wp-admin/edit.php`.
  19. * - `'core/edit-widgets'` - The widgets editor at `/wp-admin/widgets.php`.
  20. * - `'core/customize-widgets'` - The widgets editor at `/wp-admin/customize.php`.
  21. * - `'core/edit-site'` - The site editor at `/wp-admin/site-editor.php`.
  22. *
  23. * Defaults to 'core/edit-post'.
  24. *
  25. * @since 6.0.0
  26. *
  27. * @var string
  28. */
  29. public $name = 'core/edit-post';
  30. /**
  31. * The post being edited by the block editor. Optional.
  32. *
  33. * @since 5.8.0
  34. *
  35. * @var WP_Post|null
  36. */
  37. public $post = null;
  38. /**
  39. * Constructor.
  40. *
  41. * Populates optional properties for a given block editor context.
  42. *
  43. * @since 5.8.0
  44. *
  45. * @param array $settings The list of optional settings to expose in a given context.
  46. */
  47. public function __construct( array $settings = array() ) {
  48. if ( isset( $settings['name'] ) ) {
  49. $this->name = $settings['name'];
  50. }
  51. if ( isset( $settings['post'] ) ) {
  52. $this->post = $settings['post'];
  53. }
  54. }
  55. }