Skip to content

Commit 140c39b

Browse files
committed
add title prop to image layer
1 parent 28fafbb commit 140c39b

File tree

10 files changed

+199
-125
lines changed

10 files changed

+199
-125
lines changed

assets/settings/index.asset.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array(), 'version' => '8a8928b693bc70028398');
1+
<?php return array('dependencies' => array(), 'version' => '7697aabeefbf722e7f9f');

assets/settings/index.js

+18-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/settings/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/sidebar/index.asset.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-components', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-notices', 'wp-plugins'), 'version' => 'cdd6702828dce54613f5');
1+
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-components', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-notices', 'wp-plugins'), 'version' => '183d2446adda7b070f64');

assets/sidebar/index.js

+63-45
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/sidebar/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

classes/class-settings.php

+4
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,10 @@ private function sanitize_image_layer( $layer ) {
13301330
$sanitized['collapsed'] = 1;
13311331
}
13321332

1333+
if ( isset( $layer['title'] ) ) {
1334+
$sanitized['title'] = sanitize_text_field( $layer['title'] );
1335+
}
1336+
13331337
if ( ! empty( $layer['dynamic'] ) ) {
13341338
$sanitized['dynamic'] = 'dynamic';
13351339
}

src/settings/pages/editor/index.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ function createTextDynamicFields( layer, name, data ) {
188188

189189
fields[ fields.length ] = Build.control( {
190190
classes: [ 'sharing-image-editor-control', 'control-extend', 'control-hidden' ],
191-
help: wp.i18n.__( 'Displayed only in the metabox.', 'sharing-image' ),
191+
help: wp.i18n.__( 'Only visible on the admin side.', 'sharing-image' ),
192192
fields: [
193193
{
194194
group: 'input',
@@ -1201,6 +1201,26 @@ function createLayerImage( data, name ) {
12011201
append: layer,
12021202
} );
12031203

1204+
Build.control( {
1205+
classes: [ 'sharing-image-editor-control', 'control-extend' ],
1206+
help: wp.i18n.__( 'Only visible on the admin side.', 'sharing-image' ),
1207+
fields: [
1208+
{
1209+
group: 'input',
1210+
classes: [ 'sharing-image-editor-control-input' ],
1211+
attributes: {
1212+
name: name + '[title]',
1213+
value: data.title,
1214+
},
1215+
dataset: {
1216+
caption: 'title',
1217+
},
1218+
label: wp.i18n.__( 'Field name', 'sharing-image' ),
1219+
},
1220+
],
1221+
append: layer,
1222+
} );
1223+
12041224
// Create static/dynamic image fields.
12051225
createImageDynamicFields( layer, name, data );
12061226

src/sidebar/index.js

+34-36
Original file line numberDiff line numberDiff line change
@@ -109,44 +109,42 @@ const SharingImageSidebar = ( { meta, templates } ) => {
109109
}, [ templates, template ] );
110110

111111
return (
112-
<PluginDocumentSettingPanel name="sharing-image-setting" title={ __( 'Sharing Image', 'sharimg-image' ) }>
113-
{ postMeta[ meta.source ]?.poster && (
114-
<img
115-
src={ postMeta[ meta.source ].poster }
116-
alt={ __( 'Sharing Image poster', 'sharimg-image' ) }
117-
style={ { marginBottom: '10px' } }
112+
<PluginDocumentSettingPanel name="sharing-image-setting" title={ __( 'Sharing Image', 'sharing-image' ) }>
113+
<Flex direction={ 'column' } gap={ 2 }>
114+
{ postMeta[ meta.source ]?.poster && (
115+
<img src={ postMeta[ meta.source ].poster } alt={ __( 'Sharing Image poster', 'sharing-image' ) } />
116+
) }
117+
118+
<SelectControl
119+
value={ template }
120+
options={ Object.keys( templates ).map( ( index ) => ( {
121+
label: templates[ index ].title || __( 'Untitled', 'sharing-image' ),
122+
value: index,
123+
} ) ) }
124+
onChange={ changeTemplate }
118125
/>
119-
) }
120-
121-
<SelectControl
122-
value={ template }
123-
options={ Object.keys( templates ).map( ( index ) => ( {
124-
label: templates[ index ].title,
125-
value: index,
126-
} ) ) }
127-
onChange={ changeTemplate }
128-
/>
129-
130-
{ templates[ template ] && (
131-
<Flex direction={ 'column' }>
132-
<TemplateFields
133-
layers={ templates[ template ].layers || [] }
134-
updateFieldset={ updateFieldset }
135-
fields={ postMeta[ meta.fieldset ] }
136-
/>
137-
</Flex>
138-
) }
139-
140-
<Flex justify={ 'flex-start' }>
141-
<Button variant="secondary" isDestructive={ false } type={ 'button' } onClick={ generateButton }>
142-
{ __( 'Generate', 'sharing-image' ) }
143-
</Button>
144126

145-
<Button variant="ternary" isDestructive={ true }>
146-
{ __( 'Remove', 'sharing-image' ) }
147-
</Button>
148-
149-
{ loading && <Spinner /> }
127+
{ templates[ template ] && (
128+
<Flex direction={ 'column' } gap={ 4 }>
129+
<TemplateFields
130+
layers={ templates[ template ].layers || [] }
131+
updateFieldset={ updateFieldset }
132+
fields={ postMeta[ meta.fieldset ] }
133+
/>
134+
</Flex>
135+
) }
136+
137+
<Flex justify={ 'flex-start' }>
138+
<Button variant="secondary" isDestructive={ false } type={ 'button' } onClick={ generateButton }>
139+
{ __( 'Generate', 'sharing-image' ) }
140+
</Button>
141+
142+
<Button variant="ternary" isDestructive={ true }>
143+
{ __( 'Remove', 'sharing-image' ) }
144+
</Button>
145+
146+
{ loading && <Spinner /> }
147+
</Flex>
150148
</Flex>
151149
</PluginDocumentSettingPanel>
152150
);

0 commit comments

Comments
 (0)