lib/experimental/dashboard-widgets
class-wp-rest-widget-modules-controller.php
7.6 KB
3 months ago
class-wp-widget-type-registry.php
5.1 KB
3 months ago
class-wp-widget-type.php
2.2 KB
3 months ago
dashboard-layout.php
5.2 KB
3 months ago
default-layout-seed.php
1.6 KB
3 months ago
load.php
821 B
3 months ago
widget-types.php
3.6 KB
3 months ago
class-wp-widget-type.php in Gutenberg 23.2.0, at lib/experimental/dashboard-widgets/class-wp-widget-type.php
| 1 | <?php |
| 2 | /** |
| 3 | * Widget Types API: WP_Widget_Type class. |
| 4 | * |
| 5 | * @package gutenberg |
| 6 | */ |
| 7 | |
| 8 | if ( ! class_exists( 'WP_Widget_Type' ) ) { |
| 9 | |
| 10 | /** |
| 11 | * Internal class representing a widget type. |
| 12 | * |
| 13 | * Holds the metadata for a widget discovered by the build pipeline. Stored |
| 14 | * inside `WP_Widget_Type_Registry` once registered, and consumed by surface |
| 15 | * code that needs to enumerate or look up widget types. |
| 16 | * |
| 17 | * The shape is intentionally minimal: identity (`name`) plus the |
| 18 | * script-module handles the build pipeline produced for the widget. |
| 19 | * Placement and surface concerns (which page or sidebar uses the widget) |
| 20 | * live with the consumer, not on the type definition. |
| 21 | */ |
| 22 | #[AllowDynamicProperties] |
| 23 | class WP_Widget_Type { |
| 24 | |
| 25 | /** |
| 26 | * Widget type key. Namespaced identifier, e.g. `core/hello-world`. |
| 27 | * |
| 28 | * @var string |
| 29 | */ |
| 30 | public $name; |
| 31 | |
| 32 | /** |
| 33 | * Script-module handle for the widget render module. |
| 34 | * |
| 35 | * Null when the widget folder did not ship a render entry point at |
| 36 | * build time. |
| 37 | * |
| 38 | * @var string|null |
| 39 | */ |
| 40 | public $render_module = null; |
| 41 | |
| 42 | /** |
| 43 | * Script-module handle for the widget metadata module. |
| 44 | * |
| 45 | * Null when the widget folder did not ship a widget entry point at |
| 46 | * build time. |
| 47 | * |
| 48 | * @var string|null |
| 49 | */ |
| 50 | public $widget_module = null; |
| 51 | |
| 52 | /** |
| 53 | * Constructor. |
| 54 | * |
| 55 | * @param string $name Widget type name including namespace. |
| 56 | * @param array $args Optional. Widget type arguments. Each key is |
| 57 | * copied onto the corresponding object property. |
| 58 | * Default empty array. |
| 59 | */ |
| 60 | public function __construct( $name, $args = array() ) { |
| 61 | $this->name = $name; |
| 62 | $this->set_props( $args ); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Returns whether this widget type ships a renderable script module. |
| 67 | * |
| 68 | * @return bool |
| 69 | */ |
| 70 | public function is_renderable() { |
| 71 | return ! empty( $this->render_module ); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Hydrates the widget type properties from the args array. |
| 76 | * |
| 77 | * @param array $args Widget type arguments. |
| 78 | */ |
| 79 | public function set_props( $args ) { |
| 80 | if ( ! is_array( $args ) ) { |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | unset( $args['name'] ); |
| 85 | |
| 86 | foreach ( $args as $property_name => $property_value ) { |
| 87 | $this->$property_name = $property_value; |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 |