PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 All 508 releases
jetpack / jetpack_vendor / automattic / jetpack-premium-analytics / src / dashboard-layout.php

dashboard-layout.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-a.3, at jetpack_vendor/automattic/jetpack-premium-analytics/src/dashboard-layout.php

96 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Dashboard Layout: the default-layout primitives shared by the section API and its registrants.
4 *
5 * A section declares its default layout when it registers, and
6 * Dashboard_Section::get_default_layout() runs it through DASHBOARD_DEFAULT_LAYOUT_FILTER: the
7 * package drops the widget types the site cannot serve there, and a plugin may add its own
8 * instances to any section.
9 *
10 * @package automattic/jetpack-premium-analytics
11 */
12
13 namespace Automattic\Jetpack\PremiumAnalytics;
14
15 // Availability policy for default layout instances: defaults are read outside
16 // the widget registry bootstrap, so the policy must be loaded here explicitly.
17 require_once __DIR__ . '/widget-type-support.php';
18
19 /**
20 * Identifier of the Premium Analytics dashboard, formatted as `<plugin>_<page>`
21 * to match the underscore form produced by the wp-build pipeline. Used as the
22 * `{name}` segment of the sections REST route.
23 */
24 const DASHBOARD_NAME = 'jetpack-premium-analytics_dashboard';
25
26 /**
27 * Filter through which a section's default layout is resolved. Documented where it
28 * runs, in Dashboard_Section::get_default_layout().
29 */
30 const DASHBOARD_DEFAULT_LAYOUT_FILTER = 'jetpack_premium_analytics_dashboard_default_layout';
31
32 /**
33 * Builds a widget instance for a section's default layout.
34 *
35 * @param string $uuid Widget instance UUID.
36 * @param string $type Widget type.
37 * @param int $order Widget placement order.
38 * @param int $width Widget placement width.
39 * @param int $height Widget placement height.
40 * @param array $attributes Optional widget attributes.
41 * @return array Widget instance.
42 */
43 function get_dashboard_default_widget_instance(
44 $uuid,
45 $type,
46 $order,
47 $width = 1,
48 $height = 1,
49 $attributes = array()
50 ) {
51 $widget = array(
52 'uuid' => $uuid,
53 'type' => $type,
54 );
55
56 if ( ! empty( $attributes ) ) {
57 $widget['attributes'] = $attributes;
58 }
59
60 $widget['placement'] = array(
61 'width' => $width,
62 'height' => $height,
63 'order' => $order,
64 );
65
66 return $widget;
67 }
68
69 /**
70 * Drops the widget instances the site cannot serve from a section's default layout.
71 *
72 * A persisted layout keeps such an instance as a removable ghost widget; a default must not
73 * seed one. Hooked late, after the callbacks that add instances, so it covers those too.
74 *
75 * @param array $layout Default widget instances.
76 * @return array The layout minus the unsupported instances.
77 */
78 function remove_unsupported_default_layout_items( $layout ) {
79 return remove_unsupported_widget_items(
80 is_array( $layout ) ? $layout : array(),
81 'type',
82 get_widget_support_context()
83 );
84 }
85 add_filter( DASHBOARD_DEFAULT_LAYOUT_FILTER, __NAMESPACE__ . '\\remove_unsupported_default_layout_items', 100 );
86
87 /**
88 * No-op kept for older copies of the package: they guard their include of this file on this
89 * symbol and call it from boot_routes(), so a newer copy loading first must still define it.
90 *
91 * @since 0.8.0 Registers nothing; the route it registered is gone.
92 *
93 * @return void
94 */
95 function register_dashboard_default_layout_route() {}
96