Skip to content

Commit 7276c5d

Browse files
feat: settings use value instead of placeholder (#36)
1 parent 8138a11 commit 7276c5d

File tree

2 files changed

+23
-47
lines changed

2 files changed

+23
-47
lines changed

includes/class-newspack-sponsors-settings.php

+17-32
Original file line numberDiff line numberDiff line change
@@ -78,34 +78,22 @@ public static function get_settings_list() {
7878

7979
return [
8080
[
81-
'label' => __( 'Default Sponsor Byline Prefix', 'newspack-sponsors' ),
82-
'placeholder' => sprintf(
83-
// Translators: placeholder for default byline value.
84-
__( 'Default: “%s”', 'newspack-sponsors' ),
85-
$defaults['byline']
86-
),
87-
'key' => 'newspack_sponsors_default_byline',
88-
'type' => 'input',
81+
'label' => __( 'Default Sponsor Byline Prefix', 'newspack-sponsors' ),
82+
'value' => $defaults['byline'],
83+
'key' => 'newspack_sponsors_default_byline',
84+
'type' => 'input',
8985
],
9086
[
91-
'label' => __( 'Default Sponsored Flag Label', 'newspack-sponsors' ),
92-
'placeholder' => sprintf(
93-
// Translators: placeholder for default flag value.
94-
__( 'Default: “%s”', 'newspack-sponsors' ),
95-
$defaults['flag']
96-
),
97-
'key' => 'newspack_sponsors_default_flag',
98-
'type' => 'input',
87+
'label' => __( 'Default Sponsored Flag Label', 'newspack-sponsors' ),
88+
'value' => $defaults['flag'],
89+
'key' => 'newspack_sponsors_default_flag',
90+
'type' => 'input',
9991
],
10092
[
101-
'label' => __( 'Default Sponsorship Disclaimer', 'newspack-sponsors' ),
102-
'placeholder' => sprintf(
103-
// Translators: placeholder for default disclaimer value.
104-
__( 'Default: “%s”', 'newspack-sponsors' ),
105-
$defaults['disclaimer']
106-
),
107-
'key' => 'newspack_sponsors_default_disclaimer',
108-
'type' => 'textarea',
93+
'label' => __( 'Default Sponsorship Disclaimer', 'newspack-sponsors' ),
94+
'value' => $defaults['disclaimer'],
95+
'key' => 'newspack_sponsors_default_disclaimer',
96+
'type' => 'textarea',
10997
],
11098
];
11199
}
@@ -174,25 +162,22 @@ public static function page_init() {
174162
* @param array $setting Settings array.
175163
*/
176164
public static function newspack_sponsors_settings_callback( $setting ) {
177-
$key = $setting['key'];
178-
$type = $setting['type'];
179-
$placeholder = $setting['placeholder'];
180-
$value = get_option( $key, false );
165+
$key = $setting['key'];
166+
$type = $setting['type'];
167+
$value = ( '' !== get_option( $key, false ) ) ? get_option( $key, false ) : $setting['value'];
181168

182169
if ( 'textarea' === $type ) {
183170
printf(
184-
'<textarea id="%s" name="%s" class="widefat" rows="4" placeholder="%s">%s</textarea>',
171+
'<textarea id="%s" name="%s" class="widefat" rows="4">%s</textarea>',
185172
esc_attr( $key ),
186173
esc_attr( $key ),
187-
esc_attr( $placeholder ),
188174
esc_attr( $value )
189175
);
190176
} else {
191177
printf(
192-
'<input type="text" id="%s" name="%s" placeholder="%s" value="%s" class="widefat" />',
178+
'<input type="text" id="%s" name="%s" value="%s" class="widefat" />',
193179
esc_attr( $key ),
194180
esc_attr( $key ),
195-
esc_attr( $placeholder ),
196181
esc_attr( $value )
197182
);
198183
}

src/editor/sidebar/index.js

+6-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* WordPress dependencies
33
*/
4-
import { __, sprintf } from '@wordpress/i18n';
4+
import { __ } from '@wordpress/i18n';
55
import { SelectControl, TextareaControl, TextControl, ToggleControl } from '@wordpress/components';
66
import { compose } from '@wordpress/compose';
77
import { withDispatch, withSelect } from '@wordpress/data';
@@ -63,11 +63,7 @@ const SidebarComponent = props => {
6363
<TextControl
6464
className="newspack-sponsors__text-control"
6565
label={ __( 'Sponsor Flag Override (Optional)', 'newspack-sponsors' ) }
66-
placeholder={ sprintf(
67-
// Translators: placeholder text for Sponsor Flag field.
68-
__( 'Default: “%s”', 'newspack-sponsors' ),
69-
settings.flag || defaults.flag
70-
) }
66+
placeholder={ settings.flag || defaults.flag }
7167
help={ __(
7268
'The label for the flag that appears in lieu of category flags. If not empty, this field will override the site-wide setting.',
7369
'newspack-sponsors'
@@ -79,10 +75,9 @@ const SidebarComponent = props => {
7975
<TextareaControl
8076
className="newspack-sponsors__textarea-control"
8177
label={ __( 'Sponsor Disclaimer Override (Optional)', 'newspack-sponsors' ) }
82-
placeholder={ sprintf(
83-
// Translators: placeholder text for Sponsor Disclaimer field.
84-
__( 'Default: “%s”', 'newspack-sponsors' ),
85-
( settings.disclaimer || defaults.disclaimer ).replace( '[sponsor name]', title )
78+
placeholder={ ( settings.disclaimer || defaults.disclaimer ).replace(
79+
'[sponsor name]',
80+
title
8681
) }
8782
help={ __(
8883
'Text shown to explain sponsorship by this sponsor. If not empty, this field will override the site-wide setting.',
@@ -98,11 +93,7 @@ const SidebarComponent = props => {
9893
'The prefix for the sponsor attribution that appears in lieu of author byline. If not empty, this field will override the site-wide setting.',
9994
'newspack-sponsors'
10095
) }
101-
placeholder={ sprintf(
102-
// Translators: placeholder text for Sponsor Byline Prefix field.
103-
__( 'Default: “%s”', 'newspack-sponsors' ),
104-
settings.byline || defaults.byline
105-
) }
96+
placeholder={ settings.byline || defaults.byline }
10697
type="url"
10798
value={ newspack_sponsor_byline_prefix }
10899
onChange={ value => updateMetaValue( 'newspack_sponsor_byline_prefix', value ) }

0 commit comments

Comments
 (0)