PluginProbe
Parse.ly / 3.24.2
Parse.ly v3.24.2
3.24.3 3.24.2 3.24.1 3.24.0 3.23.7 3.23.6 3.23.5 3.23.4 3.23.3 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.17.0 3.18.0 3.18.1 3.19.0 3.19.1 3.19.2 3.19.3 3.2.0 3.2.1 3.20.0 3.20.1 All 107 releases
← All changes | src/rest-api/settings/class-endpoint-editor-sidebar-settings.php +134 -8 3.19.1 → 3.24.2 View file →
@@ -9,10 +9,13 @@
9 9 declare(strict_types=1);
10 10
11 11 namespace Parsely\REST_API\Settings;
12 12
13 +use Parsely\Content_Helper\Suggestion_Defaults;
14 +
13 15 /**
14 - * Endpoint for saving and retrieving Content Helper Editor Sidebar settings.
16 + * Endpoint for saving and retrieving Content Intelligence Editor Sidebar
17 + * settings.
15 18 *
16 19 * @since 3.17.0
17 20 *
18 21 * @phpstan-import-type Subvalue_Spec from Base_Settings_Endpoint
@@ -18,10 +21,55 @@
18 21 * @phpstan-import-type Subvalue_Spec from Base_Settings_Endpoint
19 22 */
20 23 class Endpoint_Editor_Sidebar_Settings extends Base_Settings_Endpoint {
21 24 /**
22 - * Returns the endpoint name.
25 + * The minimum desired excerpt length, in characters.
23 26 *
27 + * @since 3.24.0
28 + *
29 + * @var int
30 + */
31 + public const MIN_EXCERPT_LENGTH = Suggestion_Defaults::MIN_LENGTH;
32 +
33 + /**
34 + * The maximum desired excerpt length, in characters.
35 + *
36 + * @since 3.24.0
37 + *
38 + * @var int
39 + */
40 + public const MAX_EXCERPT_LENGTH = Suggestion_Defaults::MAX_LENGTH;
41 +
42 + /**
43 + * The default desired excerpt length, in characters.
44 + *
45 + * @since 3.24.0
46 + *
47 + * @var int
48 + */
49 + public const DEFAULT_EXCERPT_LENGTH = Suggestion_Defaults::DEFAULT_LENGTH;
50 +
51 + /**
52 + * The default persona used when generating excerpts.
53 + *
54 + * @since 3.24.0
55 + *
56 + * @var string
57 + */
58 + public const DEFAULT_EXCERPT_PERSONA = Suggestion_Defaults::DEFAULT_PERSONA;
59 +
60 + /**
61 + * The default tone used when generating excerpts.
62 + *
63 + * @since 3.24.0
64 + *
65 + * @var string
66 + */
67 + public const DEFAULT_EXCERPT_TONE = Suggestion_Defaults::DEFAULT_TONE;
68 +
69 + /**
70 + * Returns the endpoint's name.
71 + *
24 72 * @since 3.17.0
25 73 *
26 74 * @return string
27 75 */
@@ -45,23 +93,31 @@
45 93 * Returns the endpoint's subvalues specifications.
46 94 *
47 95 * @since 3.13.0
48 96 * @since 3.17.0 Moved from Editor_Sidebar_Settings_Endpoint.
97 + * @since 3.24.0 Added the ExcerptSuggestions `Length` setting.
98 + * @since 3.24.0 Removed the ExcerptSuggestions `Open` setting, as the panel's
99 + * collapsed state is now persisted by the block editor itself.
100 + * @since 3.24.0 The ExcerptSuggestions and TitleSuggestions defaults come
101 + * from the site-wide settings of their respective features.
49 102 *
50 103 * @return array<string, Subvalue_Spec>
51 104 */
52 105 protected function get_subvalues_specs(): array {
106 + $excerpt_options = Suggestion_Defaults::get_feature_options( $this->parsely, 'excerpt_suggestions' );
107 + $title_options = Suggestion_Defaults::get_feature_options( $this->parsely, 'title_suggestions' );
108 +
53 109 return array(
54 110 'ExcerptSuggestions' => array(
55 111 'values' => array(
56 - 'Open' => array( true, false ),
112 + 'Length' => array(),
57 113 'Persona' => array(),
58 114 'Tone' => array(),
59 115 ),
60 116 'default' => array(
61 - 'Open' => false,
62 - 'Persona' => 'journalist',
63 - 'Tone' => 'neutral',
117 + 'Length' => Suggestion_Defaults::get_default_length( $excerpt_options ),
118 + 'Persona' => Suggestion_Defaults::get_default_persona( $excerpt_options ),
119 + 'Tone' => Suggestion_Defaults::get_default_tone( $excerpt_options ),
64 120 ),
65 121 ),
66 122 'InitialTabName' => array(
67 123 'values' => array( 'tools', 'performance' ),
@@ -110,11 +166,81 @@
110 166 'Tone' => array(),
111 167 ),
112 168 'default' => array(
113 169 'Open' => false,
114 - 'Persona' => 'journalist',
115 - 'Tone' => 'neutral',
170 + 'Persona' => Suggestion_Defaults::get_default_persona( $title_options ),
171 + 'Tone' => Suggestion_Defaults::get_default_tone( $title_options ),
116 172 ),
117 173 ),
118 174 );
175 + }
176 +
177 + /**
178 + * Returns the composite keys of the settings that inherit their default.
179 + *
180 + * These are the settings whose default the plugin's settings page makes
181 + * configurable.
182 + *
183 + * @since 3.24.1
184 + *
185 + * @return array<string> The composite keys.
186 + */
187 + protected function get_inheritable_keys(): array {
188 + return array(
189 + 'ExcerptSuggestions.Length',
190 + 'ExcerptSuggestions.Persona',
191 + 'ExcerptSuggestions.Tone',
192 + 'TitleSuggestions.Persona',
193 + 'TitleSuggestions.Tone',
194 + );
195 + }
196 +
197 + /**
198 + * Returns the defaults that the inheritable settings had before 3.24.0 made
199 + * them configurable.
200 + *
201 + * Spelled out rather than taken from Suggestion_Defaults, whose constants
202 + * describe the present rather than the past. `Length` is absent, as it did
203 + * not exist before it became configurable.
204 + *
205 + * @since 3.24.1
206 + *
207 + * @return array<string, mixed> The defaults, as composite key => value pairs.
208 + */
209 + protected function get_legacy_defaults(): array {
210 + return array(
211 + 'ExcerptSuggestions.Persona' => 'journalist',
212 + 'ExcerptSuggestions.Tone' => 'neutral',
213 + 'TitleSuggestions.Persona' => 'journalist',
214 + 'TitleSuggestions.Tone' => 'neutral',
215 + );
216 + }
217 +
218 + /**
219 + * Sanitizes the passed subvalue.
220 + *
221 + * Extends the parent implementation with a range check for the desired
222 + * excerpt length, which the enumerated valid values cannot express.
223 + *
224 + * @since 3.24.0
225 + *
226 + * @param string $composite_key The subvalue's key.
227 + * @param mixed $value The value to sanitize.
228 + * @return mixed The sanitized subvalue.
229 + */
230 + protected function sanitize_subvalue( string $composite_key, $value ) {
231 + if ( 'ExcerptSuggestions.Length' === $composite_key ) {
232 + if ( ! is_int( $value ) ||
233 + $value < self::MIN_EXCERPT_LENGTH ||
234 + $value > self::MAX_EXCERPT_LENGTH
235 + ) {
236 + return Suggestion_Defaults::get_default_length(
237 + Suggestion_Defaults::get_feature_options( $this->parsely, 'excerpt_suggestions' )
238 + );
239 + }
240 +
241 + return $value;
242 + }
243 +
244 + return parent::sanitize_subvalue( $composite_key, $value );
119 245 }
120 246 }