Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Move instance retrieval out of constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
NateWr committed Jan 31, 2016
1 parent 98f9973 commit 03cc526
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions lib/class-wp-rest-widgets-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,6 @@ public function __construct( $widgets ) {
$this->rest_base = 'widgets';
$this->widgets = $widgets;

foreach( $this->widgets as $widget ) {
$settings = $widget->get_settings();
foreach( $settings as $key => $values ) {
$this->instances[] = array(
'id' => $widget->id_base . '-' . $key,
'array_index' => $key,
'id_base' => $widget->id_base,
'settings' => $values,
);
}
}

$this->sidebars = wp_get_sidebars_widgets();

// @todo Now given $this->widgets, inject schema information for Core widgets in lieu of them being in core now. See #35574.
Expand Down Expand Up @@ -150,6 +138,19 @@ public function get_items_permissions_check( $request ) {
* @return WP_Error|WP_REST_Response
*/
public function get_items( $request ) {

foreach( $this->widgets as $widget ) {
$settings = $widget->get_settings();
foreach( $settings as $key => $values ) {
$this->instances[] = array(
'id' => $widget->id_base . '-' . $key,
'array_index' => $key,
'id_base' => $widget->id_base,
'settings' => $values,
);
}
}

if ( empty( $this->instances ) ) {
return rest_ensure_response( array() );
};
Expand Down

0 comments on commit 03cc526

Please sign in to comment.