Skip to content

Commit

Permalink
Fix errors caused by adding widgets to WordPress core
Browse files Browse the repository at this point in the history
  • Loading branch information
noisysocks committed May 25, 2021
1 parent 6848e3c commit 724ab4c
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 213 deletions.
2 changes: 1 addition & 1 deletion lib/class-wp-rest-widget-types-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ protected function get_widgets() {
$widgets = array();

foreach ( $wp_registered_widgets as $widget ) {
$parsed_id = gutenberg_parse_widget_id( $widget['id'] );
$parsed_id = wp_parse_widget_id( $widget['id'] );
$widget_object = gutenberg_get_widget_object( $parsed_id['id_base'] );

$widget['id'] = $parsed_id['id_base'];
Expand Down
24 changes: 12 additions & 12 deletions lib/class-wp-rest-widgets-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function get_item_permissions_check( $request ) { // phpcs:ignore Variabl
*/
public function get_item( $request ) {
$widget_id = $request['id'];
$sidebar_id = gutenberg_find_widgets_sidebar( $widget_id );
$sidebar_id = wp_find_widgets_sidebar( $widget_id );

if ( is_null( $sidebar_id ) ) {
return new WP_Error(
Expand Down Expand Up @@ -192,7 +192,7 @@ public function create_item( $request ) {
return $widget_id;
}

gutenberg_assign_widget_to_sidebar( $widget_id, $sidebar_id );
wp_assign_widget_to_sidebar( $widget_id, $sidebar_id );

$request['context'] = 'edit';

Expand Down Expand Up @@ -229,10 +229,10 @@ public function update_item_permissions_check( $request ) { // phpcs:ignore Vari
*/
public function update_item( $request ) {
$widget_id = $request['id'];
$sidebar_id = gutenberg_find_widgets_sidebar( $widget_id );
$sidebar_id = wp_find_widgets_sidebar( $widget_id );

// Allow sidebar to be unset or missing when widget is not a WP_Widget.
$parsed_id = gutenberg_parse_widget_id( $widget_id );
$parsed_id = wp_parse_widget_id( $widget_id );
$widget_object = gutenberg_get_widget_object( $parsed_id['id_base'] );
if ( is_null( $sidebar_id ) && $widget_object ) {
return new WP_Error(
Expand All @@ -255,7 +255,7 @@ public function update_item( $request ) {
if ( $request->has_param( 'sidebar' ) ) {
if ( $sidebar_id !== $request['sidebar'] ) {
$sidebar_id = $request['sidebar'];
gutenberg_assign_widget_to_sidebar( $widget_id, $sidebar_id );
wp_assign_widget_to_sidebar( $widget_id, $sidebar_id );
}
}

Expand Down Expand Up @@ -286,7 +286,7 @@ public function delete_item_permissions_check( $request ) { // phpcs:ignore Vari
*/
public function delete_item( $request ) {
$widget_id = $request['id'];
$sidebar_id = gutenberg_find_widgets_sidebar( $widget_id );
$sidebar_id = wp_find_widgets_sidebar( $widget_id );

if ( is_null( $sidebar_id ) ) {
return new WP_Error(
Expand All @@ -300,15 +300,15 @@ public function delete_item( $request ) {

if ( $request['force'] ) {
$prepared = $this->prepare_item_for_response( compact( 'widget_id', 'sidebar_id' ), $request );
gutenberg_assign_widget_to_sidebar( $widget_id, '' );
wp_assign_widget_to_sidebar( $widget_id, '' );
$prepared->set_data(
array(
'deleted' => true,
'previous' => $prepared->get_data(),
)
);
} else {
gutenberg_assign_widget_to_sidebar( $widget_id, 'wp_inactive_widgets' );
wp_assign_widget_to_sidebar( $widget_id, 'wp_inactive_widgets' );
$prepared = $this->prepare_item_for_response(
array(
'sidebar_id' => 'wp_inactive_widgets',
Expand Down Expand Up @@ -359,7 +359,7 @@ protected function save_widget( $request ) {
if ( isset( $request['id'] ) ) {
// Saving an existing widget.
$id = $request['id'];
$parsed_id = gutenberg_parse_widget_id( $id );
$parsed_id = wp_parse_widget_id( $id );
$id_base = $parsed_id['id_base'];
$number = isset( $parsed_id['number'] ) ? $parsed_id['number'] : null;
$widget_object = gutenberg_get_widget_object( $id_base );
Expand Down Expand Up @@ -495,7 +495,7 @@ public function prepare_item_for_response( $item, $request ) {
}

$widget = $wp_registered_widgets[ $widget_id ];
$parsed_id = gutenberg_parse_widget_id( $widget_id );
$parsed_id = wp_parse_widget_id( $widget_id );
$fields = $this->get_fields_for_response( $request );

$prepared = array(
Expand All @@ -511,11 +511,11 @@ public function prepare_item_for_response( $item, $request ) {
rest_is_field_included( 'rendered', $fields ) &&
'wp_inactive_widgets' !== $sidebar_id
) {
$prepared['rendered'] = trim( gutenberg_render_widget( $widget_id, $sidebar_id ) );
$prepared['rendered'] = trim( wp_render_widget( $widget_id, $sidebar_id ) );
}

if ( rest_is_field_included( 'rendered_form', $fields ) ) {
$rendered_form = gutenberg_render_widget_control( $widget_id );
$rendered_form = wp_render_widget_control( $widget_id );
if ( ! is_null( $rendered_form ) ) {
$prepared['rendered_form'] = trim( $rendered_form );
}
Expand Down
4 changes: 3 additions & 1 deletion lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
die( 'Silence is golden.' );
}

global $wp_version;

require_once __DIR__ . '/init.php';
require_once __DIR__ . '/upgrade.php';

Expand Down Expand Up @@ -73,7 +75,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/rest-api.php';
}

if ( ! class_exists( 'WP_Widget_Block' ) ) {
if ( version_compare( $wp_version, '5.8-alpha', '<' ) ) {
require_once __DIR__ . '/class-wp-widget-block.php';
}

Expand Down
Loading

0 comments on commit 724ab4c

Please sign in to comment.