PluginProbe
Gutenberg / 23.2.2
Gutenberg v23.2.2
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / lib / experimental / dashboard-widgets / class-wp-widget-type.php

class-wp-widget-type.php in Gutenberg 23.2.2, at lib/experimental/dashboard-widgets/class-wp-widget-type.php

92 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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