← All changes
|
jetpack_vendor/automattic/jetpack-premium-analytics/src/class-dashboard-section.php
+18
-8
16.2
→
16.3-beta
View file →
| @@ -169,15 +169,8 @@ | ||
| 169 | 169 | * |
| 170 | 170 | * @return bool |
| 171 | 171 | */ |
| 172 | 172 | public function is_available() { |
| 173 | - // The preview scope is about the rollout rather than the site, so it sits ahead of the | |
| 174 | - // section's own check. The default-layout route answers the same question separately, | |
| 175 | - // because it runs before the registry is populated. | |
| 176 | - if ( ! is_dashboard_section_in_preview_scope( $this->dashboard_name, $this->slug ) ) { | |
| 177 | - return false; | |
| 178 | - } | |
| 179 | - | |
| 180 | 173 | if ( is_callable( $this->is_available ) ) { |
| 181 | 174 | return (bool) call_user_func( $this->is_available, $this ); |
| 182 | 175 | } |
| 183 | 176 | |
| @@ -184,9 +177,9 @@ | ||
| 184 | 177 | return (bool) $this->is_available; |
| 185 | 178 | } |
| 186 | 179 | |
| 187 | 180 | /** |
| 188 | - * Returns the section's default widget layout. | |
| 181 | + * Returns the section's default widget layout, run through the default-layout filter. | |
| 189 | 182 | * |
| 190 | 183 | * @return array Array of widget instances. |
| 191 | 184 | */ |
| 192 | 185 | public function get_default_layout() { |
| @@ -192,8 +185,25 @@ | ||
| 192 | 185 | public function get_default_layout() { |
| 193 | 186 | $layout = is_callable( $this->default_layout ) |
| 194 | 187 | ? call_user_func( $this->default_layout, $this ) |
| 195 | 188 | : $this->default_layout; |
| 189 | + $layout = is_array( $layout ) ? array_values( $layout ) : array(); | |
| 190 | + | |
| 191 | + /** | |
| 192 | + * Filters a dashboard section's default widget layout. | |
| 193 | + * | |
| 194 | + * Each entry matches the dashboard's widget instance shape: `uuid`, `type`, optional | |
| 195 | + * `attributes`, optional `placement`. Runs for every section, so a callback adding an | |
| 196 | + * instance to one switches on `$section_id`. | |
| 197 | + * | |
| 198 | + * @since 0.8.0 Runs from the section, with its declared layout and its | |
| 199 | + * namespaced id; it received an empty array and any alias before. | |
| 200 | + * | |
| 201 | + * @param array $layout The section's declared default widget instances. | |
| 202 | + * @param string $section_id Namespaced section identifier, e.g. `analytics/traffic`. | |
| 203 | + * @param Dashboard_Section $section The section. | |
| 204 | + */ | |
| 205 | + $layout = apply_filters( DASHBOARD_DEFAULT_LAYOUT_FILTER, $layout, $this->id, $this ); | |
| 196 | 206 | |
| 197 | 207 | return is_array( $layout ) ? array_values( $layout ) : array(); |
| 198 | 208 | } |
| 199 | 209 | |