Skip to content

Commit

Permalink
Instagram Widget: Remove from legacy-widget block (#21050)
Browse files Browse the repository at this point in the history
* Hide wpcom_instagram_widget from core/legacy-widget block

* Move filter into _construct and renamed function

* Add transforms for deprecating instagram widget

* Add header block and transfer widget settings including token

* Removed core/group and core/heading

* [not verified] Hide wpcom_instagram_widget from core/legacy-widget block

* [not verified] Move filter into _construct and renamed function

* [not verified] Add transforms for deprecating instagram widget

* [not verified] Add header block and transfer widget settings including token

* [not verified] Removed core/group and core/heading
  • Loading branch information
arcangelini authored Sep 20, 2021
1 parent b943145 commit 5b4a560
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/instagram-widget-block
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: compat

Instagram Widget: removed from Legacy Widget block
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* WordPress dependencies
*/
import { __, _x } from '@wordpress/i18n';
import { createBlock } from '@wordpress/blocks';

/**
* Internal dependencies
Expand Down Expand Up @@ -32,6 +33,28 @@ export const settings = {
align: true,
html: false,
},
// Transform from classic widget
transforms: {
from: [
{
type: 'block',
blocks: [ 'core/legacy-widget' ],
isMatch: ( { idBase, instance } ) => {
if ( ! instance?.raw ) {
return false;
}
return idBase === 'wpcom_instagram_widget';
},
transform: ( { instance } ) => {
return createBlock( 'jetpack/instagram-gallery', {
columns: instance.raw.columns,
count: instance.raw.count,
accessToken: instance.raw.token_id,
} );
},
},
],
},
attributes,
edit,
save: ( { attributes: { instagramUser } } ) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public function __construct() {
/** This filter is documented in modules/widgets/facebook-likebox.php */
apply_filters( 'jetpack_widget_name', esc_html__( 'Instagram', 'jetpack' ) ),
array(
'description' => __( 'Display your latest Instagram photos.', 'jetpack' ),
'description' => __( 'Display your latest Instagram photos.', 'jetpack' ),
'show_instance_in_rest' => true,
)
);

Expand Down Expand Up @@ -72,6 +73,19 @@ public function __construct() {
'columns' => 2,
'count' => 6,
);

add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_widget_in_block_editor' ) );
}

/**
* Remove Instagram widget from Legacy Widget block.
*
* @param array $widget_types Widget type data.
* This only applies to new blocks being added.
*/
public function hide_widget_in_block_editor( $widget_types ) {
$widget_types[] = self::ID_BASE;
return $widget_types;
}

/**
Expand Down Expand Up @@ -624,3 +638,4 @@ function () {
}
}
);

0 comments on commit 5b4a560

Please sign in to comment.