@wordpress/block-library 8.12.11 → 8.12.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -83,136 +83,132 @@ function register_block_core_footnotes() {
83
83
  }
84
84
  add_action( 'init', 'register_block_core_footnotes' );
85
85
 
86
- add_action(
87
- 'wp_after_insert_post',
88
- /**
89
- * Saves the footnotes meta value to the revision.
90
- *
91
- * @since 6.3.0
92
- *
93
- * @param int $revision_id The revision ID.
94
- */
95
- static function( $revision_id ) {
96
- $post_id = wp_is_post_revision( $revision_id );
97
-
98
- if ( $post_id ) {
86
+ /**
87
+ * Saves the footnotes meta value to the revision.
88
+ *
89
+ * @since 6.3.0
90
+ *
91
+ * @param int $revision_id The revision ID.
92
+ */
93
+ function wp_save_footnotes_meta( $revision_id ) {
94
+ $post_id = wp_is_post_revision( $revision_id );
95
+
96
+ if ( $post_id ) {
97
+ $footnotes = get_post_meta( $post_id, 'footnotes', true );
98
+
99
+ if ( $footnotes ) {
100
+ // Can't use update_post_meta() because it doesn't allow revisions.
101
+ update_metadata( 'post', $revision_id, 'footnotes', $footnotes );
102
+ }
103
+ }
104
+ }
105
+ add_action( 'wp_after_insert_post', 'wp_save_footnotes_meta' );
106
+
107
+ /**
108
+ * Keeps track of the revision ID for "rest_after_insert_{$post_type}".
109
+ *
110
+ * @since 6.3.0
111
+ *
112
+ * @global int $wp_temporary_footnote_revision_id The footnote revision ID.
113
+ *
114
+ * @param int $revision_id The revision ID.
115
+ */
116
+ function wp_keep_footnotes_revision_id( $revision_id ) {
117
+ global $wp_temporary_footnote_revision_id;
118
+ $wp_temporary_footnote_revision_id = $revision_id;
119
+ }
120
+ add_action( '_wp_put_post_revision', 'wp_keep_footnotes_revision_id' );
121
+
122
+ /**
123
+ * This is a specific fix for the REST API. The REST API doesn't update
124
+ * the post and post meta in one go (through `meta_input`). While it
125
+ * does fix the `wp_after_insert_post` hook to be called correctly after
126
+ * updating meta, it does NOT fix hooks such as post_updated and
127
+ * save_post, which are normally also fired after post meta is updated
128
+ * in `wp_insert_post()`. Unfortunately, `wp_save_post_revision` is
129
+ * added to the `post_updated` action, which means the meta is not
130
+ * available at the time, so we have to add it afterwards through the
131
+ * `"rest_after_insert_{$post_type}"` action.
132
+ *
133
+ * @since 6.3.0
134
+ *
135
+ * @global int $wp_temporary_footnote_revision_id The footnote revision ID.
136
+ *
137
+ * @param WP_Post $post The post object.
138
+ */
139
+ function wp_add_footnotes_revisions_to_post_meta( $post ) {
140
+ global $wp_temporary_footnote_revision_id;
141
+
142
+ if ( $wp_temporary_footnote_revision_id ) {
143
+ $revision = get_post( $wp_temporary_footnote_revision_id );
144
+
145
+ if ( ! $revision ) {
146
+ return;
147
+ }
148
+
149
+ $post_id = $revision->post_parent;
150
+
151
+ // Just making sure we're updating the right revision.
152
+ if ( $post->ID === $post_id ) {
99
153
  $footnotes = get_post_meta( $post_id, 'footnotes', true );
100
154
 
101
155
  if ( $footnotes ) {
102
156
  // Can't use update_post_meta() because it doesn't allow revisions.
103
- update_metadata( 'post', $revision_id, 'footnotes', $footnotes );
157
+ update_metadata( 'post', $wp_temporary_footnote_revision_id, 'footnotes', $footnotes );
104
158
  }
105
159
  }
106
160
  }
107
- );
108
-
109
- add_action(
110
- '_wp_put_post_revision',
111
- /**
112
- * Keeps track of the revision ID for "rest_after_insert_{$post_type}".
113
- *
114
- * @param int $revision_id The revision ID.
115
- */
116
- static function( $revision_id ) {
117
- global $_gutenberg_revision_id;
118
- $_gutenberg_revision_id = $revision_id;
119
- }
120
- );
161
+ }
121
162
 
122
163
  foreach ( array( 'post', 'page' ) as $post_type ) {
123
- add_action(
124
- "rest_after_insert_{$post_type}",
125
- /**
126
- * This is a specific fix for the REST API. The REST API doesn't update
127
- * the post and post meta in one go (through `meta_input`). While it
128
- * does fix the `wp_after_insert_post` hook to be called correctly after
129
- * updating meta, it does NOT fix hooks such as post_updated and
130
- * save_post, which are normally also fired after post meta is updated
131
- * in `wp_insert_post()`. Unfortunately, `wp_save_post_revision` is
132
- * added to the `post_updated` action, which means the meta is not
133
- * available at the time, so we have to add it afterwards through the
134
- * `"rest_after_insert_{$post_type}"` action.
135
- *
136
- * @since 6.3.0
137
- *
138
- * @param WP_Post $post The post object.
139
- */
140
- static function( $post ) {
141
- global $_gutenberg_revision_id;
142
-
143
- if ( $_gutenberg_revision_id ) {
144
- $revision = get_post( $_gutenberg_revision_id );
145
- $post_id = $revision->post_parent;
146
-
147
- // Just making sure we're updating the right revision.
148
- if ( $post->ID === $post_id ) {
149
- $footnotes = get_post_meta( $post_id, 'footnotes', true );
150
-
151
- if ( $footnotes ) {
152
- // Can't use update_post_meta() because it doesn't allow revisions.
153
- update_metadata( 'post', $_gutenberg_revision_id, 'footnotes', $footnotes );
154
- }
155
- }
156
- }
157
- }
158
- );
164
+ add_action( "rest_after_insert_{$post_type}", 'wp_add_footnotes_revisions_to_post_meta' );
159
165
  }
160
166
 
161
- add_action(
162
- 'wp_restore_post_revision',
163
- /**
164
- * Restores the footnotes meta value from the revision.
165
- *
166
- * @since 6.3.0
167
- *
168
- * @param int $post_id The post ID.
169
- * @param int $revision_id The revision ID.
170
- */
171
- static function( $post_id, $revision_id ) {
172
- $footnotes = get_post_meta( $revision_id, 'footnotes', true );
167
+ /**
168
+ * Restores the footnotes meta value from the revision.
169
+ *
170
+ * @since 6.3.0
171
+ *
172
+ * @param int $post_id The post ID.
173
+ * @param int $revision_id The revision ID.
174
+ */
175
+ function wp_restore_footnotes_from_revision( $post_id, $revision_id ) {
176
+ $footnotes = get_post_meta( $revision_id, 'footnotes', true );
173
177
 
174
- if ( $footnotes ) {
175
- update_post_meta( $post_id, 'footnotes', $footnotes );
176
- } else {
177
- delete_post_meta( $post_id, 'footnotes' );
178
- }
179
- },
180
- 10,
181
- 2
182
- );
183
-
184
- add_filter(
185
- '_wp_post_revision_fields',
186
- /**
187
- * Adds the footnotes field to the revision.
188
- *
189
- * @since 6.3.0
190
- *
191
- * @param array $fields The revision fields.
192
- * @return array The revision fields.
193
- */
194
- static function( $fields ) {
195
- $fields['footnotes'] = __( 'Footnotes' );
196
- return $fields;
178
+ if ( $footnotes ) {
179
+ update_post_meta( $post_id, 'footnotes', $footnotes );
180
+ } else {
181
+ delete_post_meta( $post_id, 'footnotes' );
197
182
  }
198
- );
199
-
200
- add_filter(
201
- 'wp_post_revision_field_footnotes',
202
- /**
203
- * Gets the footnotes field from the revision.
204
- *
205
- * @since 6.3.0
206
- *
207
- * @param string $revision_field The field value, but $revision->$field
208
- * (footnotes) does not exist.
209
- * @param string $field The field name, in this case "footnotes".
210
- * @param object $revision The revision object to compare against.
211
- * @return string The field value.
212
- */
213
- static function( $revision_field, $field, $revision ) {
214
- return get_metadata( 'post', $revision->ID, $field, true );
215
- },
216
- 10,
217
- 3
218
- );
183
+ }
184
+ add_action( 'wp_restore_post_revision', 'wp_restore_footnotes_from_revision', 10, 2 );
185
+
186
+ /**
187
+ * Adds the footnotes field to the revision.
188
+ *
189
+ * @since 6.3.0
190
+ *
191
+ * @param array $fields The revision fields.
192
+ * @return array The revision fields.
193
+ */
194
+ function wp_add_footnotes_to_revision( $fields ) {
195
+ $fields['footnotes'] = __( 'Footnotes' );
196
+ return $fields;
197
+ }
198
+ add_filter( '_wp_post_revision_fields', 'wp_add_footnotes_to_revision' );
199
+
200
+ /**
201
+ * Gets the footnotes field from the revision.
202
+ *
203
+ * @since 6.3.0
204
+ *
205
+ * @param string $revision_field The field value, but $revision->$field
206
+ * (footnotes) does not exist.
207
+ * @param string $field The field name, in this case "footnotes".
208
+ * @param object $revision The revision object to compare against.
209
+ * @return string The field value.
210
+ */
211
+ function wp_get_footnotes_from_revision( $revision_field, $field, $revision ) {
212
+ return get_metadata( 'post', $revision->ID, $field, true );
213
+ }
214
+ add_filter( 'wp_post_revision_field_footnotes', 'wp_get_footnotes_from_revision', 10, 3 );
@@ -9,7 +9,8 @@ import classnames from 'classnames';
9
9
  import {
10
10
  RichText,
11
11
  useBlockProps,
12
- __experimentalGetElementClassName as getBorderClassesAndStyles,
12
+ __experimentalGetElementClassName,
13
+ __experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,
13
14
  } from '@wordpress/block-editor';
14
15
 
15
16
  /**
@@ -545,11 +546,114 @@ const v5 = {
545
546
 
546
547
  /**
547
548
  * Deprecation for adding width and height as style rules on the inner img.
548
- * It also updates the widht and height attributes to be strings instead of numbers.
549
549
  *
550
550
  * @see https://github.com/WordPress/gutenberg/pull/31366
551
551
  */
552
552
  const v6 = {
553
+ attributes: {
554
+ align: {
555
+ type: 'string',
556
+ },
557
+ url: {
558
+ type: 'string',
559
+ source: 'attribute',
560
+ selector: 'img',
561
+ attribute: 'src',
562
+ __experimentalRole: 'content',
563
+ },
564
+ alt: {
565
+ type: 'string',
566
+ source: 'attribute',
567
+ selector: 'img',
568
+ attribute: 'alt',
569
+ default: '',
570
+ __experimentalRole: 'content',
571
+ },
572
+ caption: {
573
+ type: 'string',
574
+ source: 'html',
575
+ selector: 'figcaption',
576
+ __experimentalRole: 'content',
577
+ },
578
+ title: {
579
+ type: 'string',
580
+ source: 'attribute',
581
+ selector: 'img',
582
+ attribute: 'title',
583
+ __experimentalRole: 'content',
584
+ },
585
+ href: {
586
+ type: 'string',
587
+ source: 'attribute',
588
+ selector: 'figure > a',
589
+ attribute: 'href',
590
+ __experimentalRole: 'content',
591
+ },
592
+ rel: {
593
+ type: 'string',
594
+ source: 'attribute',
595
+ selector: 'figure > a',
596
+ attribute: 'rel',
597
+ },
598
+ linkClass: {
599
+ type: 'string',
600
+ source: 'attribute',
601
+ selector: 'figure > a',
602
+ attribute: 'class',
603
+ },
604
+ id: {
605
+ type: 'number',
606
+ __experimentalRole: 'content',
607
+ },
608
+ width: {
609
+ type: 'number',
610
+ },
611
+ height: {
612
+ type: 'number',
613
+ },
614
+ aspectRatio: {
615
+ type: 'string',
616
+ },
617
+ scale: {
618
+ type: 'string',
619
+ },
620
+ sizeSlug: {
621
+ type: 'string',
622
+ },
623
+ linkDestination: {
624
+ type: 'string',
625
+ },
626
+ linkTarget: {
627
+ type: 'string',
628
+ source: 'attribute',
629
+ selector: 'figure > a',
630
+ attribute: 'target',
631
+ },
632
+ },
633
+ supports: {
634
+ anchor: true,
635
+ behaviors: {
636
+ lightbox: true,
637
+ },
638
+ color: {
639
+ text: false,
640
+ background: false,
641
+ },
642
+ filter: {
643
+ duotone: true,
644
+ },
645
+ __experimentalBorder: {
646
+ color: true,
647
+ radius: true,
648
+ width: true,
649
+ __experimentalSkipSerialization: true,
650
+ __experimentalDefaultControls: {
651
+ color: true,
652
+ radius: true,
653
+ width: true,
654
+ },
655
+ },
656
+ },
553
657
  save( { attributes } ) {
554
658
  const {
555
659
  url,
@@ -618,7 +722,9 @@ const v6 = {
618
722
  ) }
619
723
  { ! RichText.isEmpty( caption ) && (
620
724
  <RichText.Content
621
- className={ getBorderClassesAndStyles( 'caption' ) }
725
+ className={ __experimentalGetElementClassName(
726
+ 'caption'
727
+ ) }
622
728
  tagName="figcaption"
623
729
  value={ caption }
624
730
  />
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { __, sprintf } from '@wordpress/i18n';
4
+ import { __, _x, sprintf } from '@wordpress/i18n';
5
5
  import { useMemo, useState } from '@wordpress/element';
6
6
  import { useDispatch, useSelect, useRegistry } from '@wordpress/data';
7
7
  import {
@@ -163,7 +163,7 @@ export function TemplatePartImportControls( { area, setAttributes } ) {
163
163
  isBusy={ isBusy }
164
164
  aria-disabled={ isBusy || ! selectedSidebar }
165
165
  >
166
- { __( 'Import' ) }
166
+ { _x( 'Import', 'button label' ) }
167
167
  </Button>
168
168
  </FlexItem>
169
169
  </HStack>
@@ -250,7 +250,7 @@ function build_template_part_block_instance_variations() {
250
250
  'area' => $template_part->area,
251
251
  ),
252
252
  'scope' => array( 'inserter' ),
253
- 'icon' => $icon_by_area[ $template_part->area ],
253
+ 'icon' => isset( $icon_by_area[ $template_part->area ] ) ? $icon_by_area[ $template_part->area ] : null,
254
254
  'example' => array(
255
255
  'attributes' => array(
256
256
  'slug' => $template_part->slug,