@wordpress/block-library 9.27.0 → 9.27.1-next.46f643fa0.0
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.
- package/build/categories/edit.js +15 -3
- package/build/categories/edit.js.map +1 -1
- package/build/cover/edit/inspector-controls.js +4 -2
- package/build/cover/edit/inspector-controls.js.map +1 -1
- package/build/file/edit.js +2 -1
- package/build/file/edit.js.map +1 -1
- package/build/latest-posts/edit.js +0 -2
- package/build/latest-posts/edit.js.map +1 -1
- package/build/paragraph/edit.js +2 -2
- package/build/paragraph/edit.js.map +1 -1
- package/build/post-date/deprecated.js +104 -1
- package/build/post-date/deprecated.js.map +1 -1
- package/build/post-date/edit.js +32 -32
- package/build/post-date/edit.js.map +1 -1
- package/build/post-date/index.js +4 -4
- package/build/post-date/index.js.map +1 -1
- package/build/post-date/variations.js +32 -3
- package/build/post-date/variations.js.map +1 -1
- package/build/social-link/variations.js +51 -49
- package/build/social-link/variations.js.map +1 -1
- package/build/utils/poster-image.js +93 -0
- package/build/utils/poster-image.js.map +1 -0
- package/build/video/edit.js +6 -2
- package/build/video/edit.js.map +1 -1
- package/build-module/categories/edit.js +15 -3
- package/build-module/categories/edit.js.map +1 -1
- package/build-module/cover/edit/inspector-controls.js +4 -2
- package/build-module/cover/edit/inspector-controls.js.map +1 -1
- package/build-module/file/edit.js +2 -1
- package/build-module/file/edit.js.map +1 -1
- package/build-module/latest-posts/edit.js +0 -2
- package/build-module/latest-posts/edit.js.map +1 -1
- package/build-module/paragraph/edit.js +2 -2
- package/build-module/paragraph/edit.js.map +1 -1
- package/build-module/post-date/deprecated.js +104 -1
- package/build-module/post-date/deprecated.js.map +1 -1
- package/build-module/post-date/edit.js +35 -35
- package/build-module/post-date/edit.js.map +1 -1
- package/build-module/post-date/index.js +4 -4
- package/build-module/post-date/index.js.map +1 -1
- package/build-module/post-date/variations.js +32 -3
- package/build-module/post-date/variations.js.map +1 -1
- package/build-module/social-link/variations.js +52 -50
- package/build-module/social-link/variations.js.map +1 -1
- package/build-module/utils/poster-image.js +85 -0
- package/build-module/utils/poster-image.js.map +1 -0
- package/build-module/video/edit.js +6 -2
- package/build-module/video/edit.js.map +1 -1
- package/build-style/editor-rtl.css +67 -10
- package/build-style/editor.css +67 -10
- package/build-style/navigation/editor-rtl.css +6 -6
- package/build-style/navigation/editor.css +6 -6
- package/build-style/page-list/editor-rtl.css +0 -4
- package/build-style/page-list/editor.css +0 -4
- package/build-style/style-rtl.css +1 -0
- package/build-style/style.css +1 -0
- package/build-style/video/style-rtl.css +1 -0
- package/build-style/video/style.css +1 -0
- package/package.json +35 -35
- package/src/categories/edit.js +13 -1
- package/src/cover/edit/inspector-controls.js +6 -2
- package/src/editor.scss +1 -0
- package/src/file/edit.js +4 -1
- package/src/latest-posts/edit.js +0 -2
- package/src/page-list/editor.scss +0 -6
- package/src/paragraph/edit.js +2 -2
- package/src/post-date/block.json +4 -4
- package/src/post-date/deprecated.js +104 -1
- package/src/post-date/edit.js +74 -86
- package/src/post-date/index.php +55 -28
- package/src/post-date/variations.js +37 -3
- package/src/social-link/README.md +21 -0
- package/src/social-link/index.php +49 -49
- package/src/social-link/variations.js +51 -49
- package/src/utils/poster-image.js +131 -0
- package/src/utils/poster-image.scss +75 -0
- package/src/video/edit.js +7 -2
- package/src/video/index.php +91 -0
- package/src/video/style.native.scss +1 -0
- package/src/video/style.scss +1 -0
- package/build/cover/edit/poster-image.js +0 -81
- package/build/cover/edit/poster-image.js.map +0 -1
- package/build/video/poster-image.js +0 -81
- package/build/video/poster-image.js.map +0 -1
- package/build-module/cover/edit/poster-image.js +0 -74
- package/build-module/cover/edit/poster-image.js.map +0 -1
- package/build-module/video/poster-image.js +0 -74
- package/build-module/video/poster-image.js.map +0 -1
- package/src/cover/edit/poster-image.js +0 -91
- package/src/video/poster-image.js +0 -91
package/src/paragraph/edit.js
CHANGED
|
@@ -81,8 +81,8 @@ function DropCapControl( { clientId, attributes, setAttributes, name } ) {
|
|
|
81
81
|
hasValue={ () => !! dropCap }
|
|
82
82
|
label={ __( 'Drop cap' ) }
|
|
83
83
|
isShownByDefault={ isDropCapControlEnabledByDefault }
|
|
84
|
-
onDeselect={ () => setAttributes( { dropCap:
|
|
85
|
-
resetAllFilter={ () => ( { dropCap:
|
|
84
|
+
onDeselect={ () => setAttributes( { dropCap: false } ) }
|
|
85
|
+
resetAllFilter={ () => ( { dropCap: false } ) }
|
|
86
86
|
panelId={ clientId }
|
|
87
87
|
>
|
|
88
88
|
<ToggleControl
|
package/src/post-date/block.json
CHANGED
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
"description": "Display the publish date for an entry such as a post or page.",
|
|
8
8
|
"textdomain": "default",
|
|
9
9
|
"attributes": {
|
|
10
|
+
"datetime": {
|
|
11
|
+
"type": "string",
|
|
12
|
+
"role": "content"
|
|
13
|
+
},
|
|
10
14
|
"textAlign": {
|
|
11
15
|
"type": "string"
|
|
12
16
|
},
|
|
@@ -17,10 +21,6 @@
|
|
|
17
21
|
"type": "boolean",
|
|
18
22
|
"default": false,
|
|
19
23
|
"role": "content"
|
|
20
|
-
},
|
|
21
|
-
"displayType": {
|
|
22
|
-
"type": "string",
|
|
23
|
-
"default": "date"
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"usesContext": [ "postId", "postType", "queryId" ],
|
|
@@ -1,8 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* Internal dependencies
|
|
3
8
|
*/
|
|
4
9
|
import migrateFontFamily from '../utils/migrate-font-family';
|
|
5
10
|
|
|
11
|
+
const v2 = {
|
|
12
|
+
attributes: {
|
|
13
|
+
textAlign: {
|
|
14
|
+
type: 'string',
|
|
15
|
+
},
|
|
16
|
+
format: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
},
|
|
19
|
+
isLink: {
|
|
20
|
+
type: 'boolean',
|
|
21
|
+
default: false,
|
|
22
|
+
role: 'content',
|
|
23
|
+
},
|
|
24
|
+
displayType: {
|
|
25
|
+
type: 'string',
|
|
26
|
+
default: 'date',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
supports: {
|
|
30
|
+
html: false,
|
|
31
|
+
color: {
|
|
32
|
+
gradients: true,
|
|
33
|
+
link: true,
|
|
34
|
+
__experimentalDefaultControls: {
|
|
35
|
+
background: true,
|
|
36
|
+
text: true,
|
|
37
|
+
link: true,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
spacing: {
|
|
41
|
+
margin: true,
|
|
42
|
+
padding: true,
|
|
43
|
+
},
|
|
44
|
+
typography: {
|
|
45
|
+
fontSize: true,
|
|
46
|
+
lineHeight: true,
|
|
47
|
+
__experimentalFontFamily: true,
|
|
48
|
+
__experimentalFontWeight: true,
|
|
49
|
+
__experimentalFontStyle: true,
|
|
50
|
+
__experimentalTextTransform: true,
|
|
51
|
+
__experimentalTextDecoration: true,
|
|
52
|
+
__experimentalLetterSpacing: true,
|
|
53
|
+
__experimentalDefaultControls: {
|
|
54
|
+
fontSize: true,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
interactivity: {
|
|
58
|
+
clientNavigation: true,
|
|
59
|
+
},
|
|
60
|
+
__experimentalBorder: {
|
|
61
|
+
radius: true,
|
|
62
|
+
color: true,
|
|
63
|
+
width: true,
|
|
64
|
+
style: true,
|
|
65
|
+
__experimentalDefaultControls: {
|
|
66
|
+
radius: true,
|
|
67
|
+
color: true,
|
|
68
|
+
width: true,
|
|
69
|
+
style: true,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
save() {
|
|
74
|
+
return null;
|
|
75
|
+
},
|
|
76
|
+
migrate( { className, displayType, metadata, ...otherAttributes } ) {
|
|
77
|
+
if ( displayType === 'date' || displayType === 'modified' ) {
|
|
78
|
+
if ( displayType === 'modified' ) {
|
|
79
|
+
className = clsx(
|
|
80
|
+
className,
|
|
81
|
+
'wp-block-post-date__modified-date'
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
...otherAttributes,
|
|
87
|
+
className,
|
|
88
|
+
metadata: {
|
|
89
|
+
...metadata,
|
|
90
|
+
bindings: {
|
|
91
|
+
datetime: {
|
|
92
|
+
source: 'core/post-data',
|
|
93
|
+
args: { key: displayType },
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
isEligible( attributes ) {
|
|
101
|
+
// If there's neither an explicit `datetime` attribute nor a block binding for that attribute,
|
|
102
|
+
// then we're dealing with an old version of the block.
|
|
103
|
+
return (
|
|
104
|
+
! attributes.datetime && ! attributes?.metadata?.bindings?.datetime
|
|
105
|
+
);
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
|
|
6
109
|
const v1 = {
|
|
7
110
|
attributes: {
|
|
8
111
|
textAlign: {
|
|
@@ -49,4 +152,4 @@ const v1 = {
|
|
|
49
152
|
*
|
|
50
153
|
* See block-deprecation.md
|
|
51
154
|
*/
|
|
52
|
-
export default [ v1 ];
|
|
155
|
+
export default [ v2, v1 ];
|
package/src/post-date/edit.js
CHANGED
|
@@ -7,7 +7,7 @@ import clsx from 'clsx';
|
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
9
|
import { useEntityProp, store as coreStore } from '@wordpress/core-data';
|
|
10
|
-
import { useMemo, useState } from '@wordpress/element';
|
|
10
|
+
import { useEffect, useMemo, useState } from '@wordpress/element';
|
|
11
11
|
import {
|
|
12
12
|
dateI18n,
|
|
13
13
|
humanTimeDiff,
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
AlignmentControl,
|
|
18
18
|
BlockControls,
|
|
19
19
|
InspectorControls,
|
|
20
|
+
store as blockEditorStore,
|
|
20
21
|
useBlockProps,
|
|
21
22
|
__experimentalDateFormatPicker as DateFormatPicker,
|
|
22
23
|
__experimentalPublishDateTimePicker as PublishDateTimePicker,
|
|
@@ -32,7 +33,7 @@ import {
|
|
|
32
33
|
import { __, _x, sprintf } from '@wordpress/i18n';
|
|
33
34
|
import { edit } from '@wordpress/icons';
|
|
34
35
|
import { DOWN } from '@wordpress/keycodes';
|
|
35
|
-
import { useSelect } from '@wordpress/data';
|
|
36
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
36
37
|
|
|
37
38
|
/**
|
|
38
39
|
* Internal dependencies
|
|
@@ -40,14 +41,17 @@ import { useSelect } from '@wordpress/data';
|
|
|
40
41
|
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';
|
|
41
42
|
|
|
42
43
|
export default function PostDateEdit( {
|
|
43
|
-
attributes: { textAlign, format, isLink,
|
|
44
|
-
context: {
|
|
44
|
+
attributes: { datetime, textAlign, format, isLink, metadata },
|
|
45
|
+
context: { postType: postTypeSlug, queryId },
|
|
45
46
|
setAttributes,
|
|
46
47
|
} ) {
|
|
48
|
+
const displayType =
|
|
49
|
+
metadata?.bindings?.datetime?.source === 'core/post-data' &&
|
|
50
|
+
metadata?.bindings?.datetime?.args?.key;
|
|
51
|
+
|
|
47
52
|
const blockProps = useBlockProps( {
|
|
48
53
|
className: clsx( {
|
|
49
54
|
[ `has-text-align-${ textAlign }` ]: textAlign,
|
|
50
|
-
[ `wp-block-post-date__modified-date` ]: displayType === 'modified',
|
|
51
55
|
} ),
|
|
52
56
|
} );
|
|
53
57
|
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
|
|
@@ -61,6 +65,19 @@ export default function PostDateEdit( {
|
|
|
61
65
|
[ popoverAnchor ]
|
|
62
66
|
);
|
|
63
67
|
|
|
68
|
+
const { __unstableMarkNextChangeAsNotPersistent } =
|
|
69
|
+
useDispatch( blockEditorStore );
|
|
70
|
+
|
|
71
|
+
// We need to set the datetime to a default value upon first loading
|
|
72
|
+
// to discern the block from its legacy version (which would default
|
|
73
|
+
// to the containing post's publish date).
|
|
74
|
+
useEffect( () => {
|
|
75
|
+
if ( datetime === undefined ) {
|
|
76
|
+
__unstableMarkNextChangeAsNotPersistent();
|
|
77
|
+
setAttributes( { datetime: new Date() } );
|
|
78
|
+
}
|
|
79
|
+
}, [ datetime ] );
|
|
80
|
+
|
|
64
81
|
const isDescendentOfQueryLoop = Number.isFinite( queryId );
|
|
65
82
|
const dateSettings = getDateSettings();
|
|
66
83
|
const [ siteFormat = dateSettings.formats.date ] = useEntityProp(
|
|
@@ -73,12 +90,6 @@ export default function PostDateEdit( {
|
|
|
73
90
|
'site',
|
|
74
91
|
'time_format'
|
|
75
92
|
);
|
|
76
|
-
const [ date, setDate ] = useEntityProp(
|
|
77
|
-
'postType',
|
|
78
|
-
postTypeSlug,
|
|
79
|
-
displayType,
|
|
80
|
-
postId
|
|
81
|
-
);
|
|
82
93
|
|
|
83
94
|
const postType = useSelect(
|
|
84
95
|
( select ) =>
|
|
@@ -88,20 +99,15 @@ export default function PostDateEdit( {
|
|
|
88
99
|
[ postTypeSlug ]
|
|
89
100
|
);
|
|
90
101
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
let postDate = date ? (
|
|
95
|
-
<time dateTime={ dateI18n( 'c', date ) } ref={ setPopoverAnchor }>
|
|
102
|
+
let postDate = (
|
|
103
|
+
<time dateTime={ dateI18n( 'c', datetime ) } ref={ setPopoverAnchor }>
|
|
96
104
|
{ format === 'human-diff'
|
|
97
|
-
? humanTimeDiff(
|
|
98
|
-
: dateI18n( format || siteFormat,
|
|
105
|
+
? humanTimeDiff( datetime )
|
|
106
|
+
: dateI18n( format || siteFormat, datetime ) }
|
|
99
107
|
</time>
|
|
100
|
-
) : (
|
|
101
|
-
dateLabel
|
|
102
108
|
);
|
|
103
109
|
|
|
104
|
-
if ( isLink &&
|
|
110
|
+
if ( isLink && datetime ) {
|
|
105
111
|
postDate = (
|
|
106
112
|
<a
|
|
107
113
|
href="#post-date-pseudo-link"
|
|
@@ -121,49 +127,53 @@ export default function PostDateEdit( {
|
|
|
121
127
|
setAttributes( { textAlign: nextAlign } );
|
|
122
128
|
} }
|
|
123
129
|
/>
|
|
124
|
-
{
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
130
|
+
{ displayType !== 'modified' && ! isDescendentOfQueryLoop && (
|
|
131
|
+
<ToolbarGroup>
|
|
132
|
+
<Dropdown
|
|
133
|
+
popoverProps={ popoverProps }
|
|
134
|
+
renderContent={ ( { onClose } ) => (
|
|
135
|
+
<PublishDateTimePicker
|
|
136
|
+
title={
|
|
137
|
+
displayType === 'date'
|
|
138
|
+
? __( 'Publish Date' )
|
|
139
|
+
: __( 'Date' )
|
|
140
|
+
}
|
|
141
|
+
currentDate={ datetime }
|
|
142
|
+
onChange={ ( newDatetime ) =>
|
|
143
|
+
setAttributes( {
|
|
144
|
+
datetime: newDatetime,
|
|
145
|
+
} )
|
|
146
|
+
}
|
|
147
|
+
is12Hour={ is12HourFormat(
|
|
148
|
+
siteTimeFormat
|
|
149
|
+
) }
|
|
150
|
+
onClose={ onClose }
|
|
151
|
+
dateOrder={
|
|
152
|
+
/* translators: Order of day, month, and year. Available formats are 'dmy', 'mdy', and 'ymd'. */
|
|
153
|
+
_x( 'dmy', 'date order' )
|
|
154
|
+
}
|
|
155
|
+
/>
|
|
156
|
+
) }
|
|
157
|
+
renderToggle={ ( { isOpen, onToggle } ) => {
|
|
158
|
+
const openOnArrowDown = ( event ) => {
|
|
159
|
+
if ( ! isOpen && event.keyCode === DOWN ) {
|
|
160
|
+
event.preventDefault();
|
|
161
|
+
onToggle();
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
return (
|
|
165
|
+
<ToolbarButton
|
|
166
|
+
aria-expanded={ isOpen }
|
|
167
|
+
icon={ edit }
|
|
168
|
+
title={ __( 'Change Date' ) }
|
|
169
|
+
onClick={ onToggle }
|
|
170
|
+
onKeyDown={ openOnArrowDown }
|
|
142
171
|
/>
|
|
143
|
-
)
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
event.keyCode === DOWN
|
|
149
|
-
) {
|
|
150
|
-
event.preventDefault();
|
|
151
|
-
onToggle();
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
return (
|
|
155
|
-
<ToolbarButton
|
|
156
|
-
aria-expanded={ isOpen }
|
|
157
|
-
icon={ edit }
|
|
158
|
-
title={ __( 'Change Date' ) }
|
|
159
|
-
onClick={ onToggle }
|
|
160
|
-
onKeyDown={ openOnArrowDown }
|
|
161
|
-
/>
|
|
162
|
-
);
|
|
163
|
-
} }
|
|
164
|
-
/>
|
|
165
|
-
</ToolbarGroup>
|
|
166
|
-
) }
|
|
172
|
+
);
|
|
173
|
+
} }
|
|
174
|
+
/>
|
|
175
|
+
</ToolbarGroup>
|
|
176
|
+
) }
|
|
167
177
|
</BlockControls>
|
|
168
178
|
|
|
169
179
|
<InspectorControls>
|
|
@@ -171,9 +181,9 @@ export default function PostDateEdit( {
|
|
|
171
181
|
label={ __( 'Settings' ) }
|
|
172
182
|
resetAll={ () => {
|
|
173
183
|
setAttributes( {
|
|
184
|
+
datetime: undefined,
|
|
174
185
|
format: undefined,
|
|
175
186
|
isLink: false,
|
|
176
|
-
displayType: 'date',
|
|
177
187
|
} );
|
|
178
188
|
} }
|
|
179
189
|
dropdownMenuProps={ dropdownMenuProps }
|
|
@@ -225,28 +235,6 @@ export default function PostDateEdit( {
|
|
|
225
235
|
checked={ isLink }
|
|
226
236
|
/>
|
|
227
237
|
</ToolsPanelItem>
|
|
228
|
-
<ToolsPanelItem
|
|
229
|
-
hasValue={ () => displayType !== 'date' }
|
|
230
|
-
label={ __( 'Display last modified date' ) }
|
|
231
|
-
onDeselect={ () =>
|
|
232
|
-
setAttributes( { displayType: 'date' } )
|
|
233
|
-
}
|
|
234
|
-
isShownByDefault
|
|
235
|
-
>
|
|
236
|
-
<ToggleControl
|
|
237
|
-
__nextHasNoMarginBottom
|
|
238
|
-
label={ __( 'Display last modified date' ) }
|
|
239
|
-
onChange={ ( value ) =>
|
|
240
|
-
setAttributes( {
|
|
241
|
-
displayType: value ? 'modified' : 'date',
|
|
242
|
-
} )
|
|
243
|
-
}
|
|
244
|
-
checked={ displayType === 'modified' }
|
|
245
|
-
help={ __(
|
|
246
|
-
'Only shows if the post has been modified'
|
|
247
|
-
) }
|
|
248
|
-
/>
|
|
249
|
-
</ToolsPanelItem>
|
|
250
238
|
</ToolsPanel>
|
|
251
239
|
</InspectorControls>
|
|
252
240
|
|
package/src/post-date/index.php
CHANGED
|
@@ -16,14 +16,62 @@
|
|
|
16
16
|
* @return string Returns the filtered post date for the current post wrapped inside "time" tags.
|
|
17
17
|
*/
|
|
18
18
|
function render_block_core_post_date( $attributes, $content, $block ) {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
$classes = array();
|
|
20
|
+
|
|
21
|
+
if ( ! isset( $attributes['datetime'] ) ) {
|
|
22
|
+
/*
|
|
23
|
+
* This can mean two things:
|
|
24
|
+
*
|
|
25
|
+
* 1. We're dealing with the legacy version of the block that didn't have the `datetime` attribute.
|
|
26
|
+
* 2. The `datetime` attribute is bound to a Block Bindings source, but we're on a version of WordPress
|
|
27
|
+
* that doesn't support binding that attribute to a Block Bindings source.
|
|
28
|
+
*
|
|
29
|
+
* In both cases, we set the `datetime` attribute to its correct value by applying Block Bindings manually.
|
|
30
|
+
*/
|
|
31
|
+
if (
|
|
32
|
+
isset( $attributes['metadata']['bindings']['datetime']['source'] ) &&
|
|
33
|
+
isset( $attributes['metadata']['bindings']['datetime']['args'] )
|
|
34
|
+
) {
|
|
35
|
+
// We're using a version of WordPress that doesn't support binding the block's `datetime` attribute to a Block Bindings source.
|
|
36
|
+
// This branch can be removed once the minimum required WordPress version supports the `core/post-data` source.
|
|
37
|
+
$source = get_block_bindings_source( $attributes['metadata']['bindings']['datetime']['source'] );
|
|
38
|
+
$source_args = $attributes['metadata']['bindings']['datetime']['args'];
|
|
39
|
+
} else {
|
|
40
|
+
// This is the legacy version of the block that didn't have the `datetime` attribute.
|
|
41
|
+
// This branch needs to be kept for backward compatibility.
|
|
42
|
+
$source = get_block_bindings_source( 'core/post-data' );
|
|
43
|
+
if ( isset( $attributes['displayType'] ) && 'modified' === $attributes['displayType'] ) {
|
|
44
|
+
$source_args = array(
|
|
45
|
+
'key' => 'modified',
|
|
46
|
+
);
|
|
47
|
+
} else {
|
|
48
|
+
$source_args = array(
|
|
49
|
+
'key' => 'date',
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
$attributes['datetime'] = $source->get_value( $source_args, $block, 'datetime' );
|
|
55
|
+
|
|
56
|
+
if ( isset( $source_args['key'] ) && 'modified' === $source_args['key'] ) {
|
|
57
|
+
$classes[] = 'wp-block-post-date__modified-date';
|
|
58
|
+
}
|
|
21
59
|
}
|
|
22
60
|
|
|
23
|
-
|
|
61
|
+
if ( empty( $attributes['datetime'] ) ) {
|
|
62
|
+
// If the `datetime` attribute is set but empty, it could be because Block Bindings
|
|
63
|
+
// set it that way. This can happen e.g. if the block is bound to the
|
|
64
|
+
// post's last modified date, and the latter lies before the publish date.
|
|
65
|
+
// (See https://github.com/WordPress/gutenberg/pull/46839 where this logic was originally
|
|
66
|
+
// implemented.)
|
|
67
|
+
// In this case, we have to respect and return the empty value.
|
|
68
|
+
return $attributes['datetime'];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
$unformatted_date = $attributes['datetime'];
|
|
72
|
+
$post_timestamp = strtotime( $unformatted_date );
|
|
24
73
|
|
|
25
74
|
if ( isset( $attributes['format'] ) && 'human-diff' === $attributes['format'] ) {
|
|
26
|
-
$post_timestamp = get_post_timestamp( $post_ID );
|
|
27
75
|
if ( $post_timestamp > time() ) {
|
|
28
76
|
// translators: %s: human-readable time difference.
|
|
29
77
|
$formatted_date = sprintf( __( '%s from now' ), human_time_diff( $post_timestamp ) );
|
|
@@ -32,10 +80,8 @@ function render_block_core_post_date( $attributes, $content, $block ) {
|
|
|
32
80
|
$formatted_date = sprintf( __( '%s ago' ), human_time_diff( $post_timestamp ) );
|
|
33
81
|
}
|
|
34
82
|
} else {
|
|
35
|
-
$formatted_date =
|
|
83
|
+
$formatted_date = gmdate( empty( $attributes['format'] ) ? get_option( 'date_format' ) : $attributes['format'], $post_timestamp );
|
|
36
84
|
}
|
|
37
|
-
$unformatted_date = esc_attr( get_the_date( 'c', $post_ID ) );
|
|
38
|
-
$classes = array();
|
|
39
85
|
|
|
40
86
|
if ( isset( $attributes['textAlign'] ) ) {
|
|
41
87
|
$classes[] = 'has-text-align-' . $attributes['textAlign'];
|
|
@@ -44,29 +90,10 @@ function render_block_core_post_date( $attributes, $content, $block ) {
|
|
|
44
90
|
$classes[] = 'has-link-color';
|
|
45
91
|
}
|
|
46
92
|
|
|
47
|
-
/*
|
|
48
|
-
* If the "Display last modified date" setting is enabled,
|
|
49
|
-
* only display the modified date if it is later than the publishing date.
|
|
50
|
-
*/
|
|
51
|
-
if ( isset( $attributes['displayType'] ) && 'modified' === $attributes['displayType'] ) {
|
|
52
|
-
if ( get_the_modified_date( 'Ymdhi', $post_ID ) > get_the_date( 'Ymdhi', $post_ID ) ) {
|
|
53
|
-
if ( isset( $attributes['format'] ) && 'human-diff' === $attributes['format'] ) {
|
|
54
|
-
// translators: %s: human-readable time difference.
|
|
55
|
-
$formatted_date = sprintf( __( '%s ago' ), human_time_diff( get_post_timestamp( $post_ID, 'modified' ) ) );
|
|
56
|
-
} else {
|
|
57
|
-
$formatted_date = get_the_modified_date( empty( $attributes['format'] ) ? '' : $attributes['format'], $post_ID );
|
|
58
|
-
}
|
|
59
|
-
$unformatted_date = esc_attr( get_the_modified_date( 'c', $post_ID ) );
|
|
60
|
-
$classes[] = 'wp-block-post-date__modified-date';
|
|
61
|
-
} else {
|
|
62
|
-
return '';
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
93
|
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );
|
|
67
94
|
|
|
68
|
-
if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) {
|
|
69
|
-
$formatted_date = sprintf( '<a href="%1s">%2s</a>', get_the_permalink( $
|
|
95
|
+
if ( isset( $attributes['isLink'] ) && $attributes['isLink'] && isset( $block->context['postId'] ) ) {
|
|
96
|
+
$formatted_date = sprintf( '<a href="%1s">%2s</a>', get_the_permalink( $block->context['postId'] ), $formatted_date );
|
|
70
97
|
}
|
|
71
98
|
|
|
72
99
|
return sprintf(
|
|
@@ -5,14 +5,48 @@ import { __ } from '@wordpress/i18n';
|
|
|
5
5
|
import { postDate } from '@wordpress/icons';
|
|
6
6
|
|
|
7
7
|
const variations = [
|
|
8
|
+
{
|
|
9
|
+
name: 'post-date',
|
|
10
|
+
title: __( 'Post Date' ),
|
|
11
|
+
description: __( "Display a post's publish date." ),
|
|
12
|
+
attributes: {
|
|
13
|
+
metadata: {
|
|
14
|
+
bindings: {
|
|
15
|
+
datetime: {
|
|
16
|
+
source: 'core/post-data',
|
|
17
|
+
args: { key: 'date' },
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
scope: [ 'block', 'inserter', 'transform' ],
|
|
23
|
+
isActive: ( blockAttributes ) =>
|
|
24
|
+
blockAttributes?.metadata?.bindings?.datetime?.source ===
|
|
25
|
+
'core/post-data' &&
|
|
26
|
+
blockAttributes?.metadata?.bindings?.datetime?.args?.key === 'date',
|
|
27
|
+
icon: postDate,
|
|
28
|
+
},
|
|
8
29
|
{
|
|
9
30
|
name: 'post-date-modified',
|
|
10
31
|
title: __( 'Modified Date' ),
|
|
11
32
|
description: __( "Display a post's last updated date." ),
|
|
12
|
-
attributes: {
|
|
13
|
-
|
|
33
|
+
attributes: {
|
|
34
|
+
metadata: {
|
|
35
|
+
bindings: {
|
|
36
|
+
datetime: {
|
|
37
|
+
source: 'core/post-data',
|
|
38
|
+
args: { key: 'modified' },
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
className: 'wp-block-post-date__modified-date',
|
|
43
|
+
},
|
|
44
|
+
scope: [ 'block', 'inserter', 'transform' ],
|
|
14
45
|
isActive: ( blockAttributes ) =>
|
|
15
|
-
blockAttributes
|
|
46
|
+
blockAttributes?.metadata?.bindings?.datetime?.source ===
|
|
47
|
+
'core/post-data' &&
|
|
48
|
+
blockAttributes?.metadata?.bindings?.datetime?.args?.key ===
|
|
49
|
+
'modified',
|
|
16
50
|
icon: postDate,
|
|
17
51
|
},
|
|
18
52
|
];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Social Icon block
|
|
2
|
+
|
|
3
|
+
The Social Icon is a foundational block that displays various icons linking to different social profiles or sites. Each social service is registered as a variation of this block.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Adding new social icons
|
|
7
|
+
|
|
8
|
+
The core maintains certain standards for adding new social icons. To add a new variation to WordPress, it must be well-established and popular.
|
|
9
|
+
|
|
10
|
+
To evaluate if a social service should be added, contributors will consider the following factors:
|
|
11
|
+
|
|
12
|
+
* Is the service popular enough for core developers to have heard of it before? Is it "mainstream?"
|
|
13
|
+
* How long has the service been online?
|
|
14
|
+
* Does it have a Wikipedia article?
|
|
15
|
+
* Is there a plugin adding social icons in the repository that includes the services in question and has a considerable number of active installations?
|
|
16
|
+
* Is this social service frequently requested?
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## Adding custom social icons
|
|
20
|
+
|
|
21
|
+
Starting from WordPress 6.9, it's possible to add custom social icons to your site. See: [#70261](https://github.com/WordPress/gutenberg/pull/70261).
|