16
16
* This class is used to get and update Jetpack_Social_Settings.
17
17
* Currently supported features:
18
18
* - Social Image Generator
19
+ * - UTM Settings
20
+ * - Social Notes
19
21
*/
20
22
class Settings {
21
23
/**
@@ -37,6 +39,17 @@ class Settings {
37
39
'enabled ' => false ,
38
40
);
39
41
42
+ const NOTES_CONFIG = 'notes_config ' ;
43
+
44
+ const DEFAULT_NOTES_CONFIG = array (
45
+ 'append_link ' => true ,
46
+ );
47
+
48
+ // Legacy named options.
49
+ const JETPACK_SOCIAL_NOTE_CPT_ENABLED = 'jetpack-social-note ' ;
50
+ const JETPACK_SOCIAL_SHOW_PRICING_PAGE = 'jetpack-social_show_pricing_page ' ;
51
+ const NOTES_FLUSH_REWRITE_RULES_FLUSHED = 'jetpack_social_rewrite_rules_flushed ' ;
52
+
40
53
/**
41
54
* Feature flags. Each item has 3 keys because of the naming conventions:
42
55
* - flag_name: The name of the feature flag for the option check.
@@ -154,6 +167,58 @@ public function register_settings() {
154
167
)
155
168
);
156
169
170
+ register_setting (
171
+ 'jetpack_social ' ,
172
+ self ::JETPACK_SOCIAL_SHOW_PRICING_PAGE ,
173
+ array (
174
+ 'type ' => 'boolean ' ,
175
+ 'default ' => true ,
176
+ 'show_in_rest ' => array (
177
+ 'schema ' => array (
178
+ 'type ' => 'boolean ' ,
179
+ ),
180
+ ),
181
+ )
182
+ );
183
+
184
+ register_setting (
185
+ 'jetpack_social ' ,
186
+ self ::JETPACK_SOCIAL_NOTE_CPT_ENABLED ,
187
+ array (
188
+ 'type ' => 'boolean ' ,
189
+ 'default ' => false ,
190
+ 'show_in_rest ' => array (
191
+ 'schema ' => array (
192
+ 'type ' => 'boolean ' ,
193
+ ),
194
+ ),
195
+ )
196
+ );
197
+
198
+ register_setting (
199
+ 'jetpack_social ' ,
200
+ self ::OPTION_PREFIX . self ::NOTES_CONFIG ,
201
+ array (
202
+ 'type ' => 'object ' ,
203
+ 'default ' => self ::DEFAULT_NOTES_CONFIG ,
204
+ 'show_in_rest ' => array (
205
+ 'schema ' => array (
206
+ 'type ' => 'object ' ,
207
+ 'context ' => array ( 'view ' , 'edit ' ),
208
+ 'properties ' => array (
209
+ 'append_link ' => array (
210
+ 'type ' => 'boolean ' ,
211
+ ),
212
+ 'link_format ' => array (
213
+ 'type ' => 'string ' ,
214
+ 'enum ' => array ( 'full_url ' , 'shortlink ' , 'permashortcitation ' ),
215
+ ),
216
+ ),
217
+ ),
218
+ ),
219
+ )
220
+ );
221
+
157
222
add_filter ( 'rest_pre_update_setting ' , array ( $ this , 'update_settings ' ), 10 , 3 );
158
223
}
159
224
@@ -175,6 +240,24 @@ public function get_utm_settings() {
175
240
return get_option ( self ::OPTION_PREFIX . self ::UTM_SETTINGS , self ::DEFAULT_UTM_SETTINGS );
176
241
}
177
242
243
+ /**
244
+ * Get the social notes config.
245
+ *
246
+ * @return array The social notes config.
247
+ */
248
+ public function get_social_notes_config () {
249
+ return get_option ( self ::OPTION_PREFIX . self ::NOTES_CONFIG , self ::DEFAULT_NOTES_CONFIG );
250
+ }
251
+
252
+ /**
253
+ * Get if the social notes feature is enabled.
254
+ *
255
+ * @return bool
256
+ */
257
+ public function is_social_notes_enabled () {
258
+ return get_option ( self ::JETPACK_SOCIAL_NOTE_CPT_ENABLED , false );
259
+ }
260
+
178
261
/**
179
262
* Get the current settings.
180
263
*
@@ -253,10 +336,12 @@ public function get_initial_state() {
253
336
*/
254
337
public function update_settings ( $ updated , $ name , $ value ) {
255
338
339
+ // Social Image Generator.
256
340
if ( self ::OPTION_PREFIX . self ::IMAGE_GENERATOR_SETTINGS === $ name ) {
257
341
return $ this ->update_social_image_generator_settings ( $ value );
258
342
}
259
343
344
+ // UTM Settings.
260
345
if ( self ::OPTION_PREFIX . self ::UTM_SETTINGS === $ name ) {
261
346
$ current_utm_settings = $ this ->get_utm_settings ();
262
347
@@ -267,6 +352,22 @@ public function update_settings( $updated, $name, $value ) {
267
352
return update_option ( self ::OPTION_PREFIX . self ::UTM_SETTINGS , array_replace_recursive ( $ current_utm_settings , $ value ) );
268
353
}
269
354
355
+ // Social Notes.
356
+ if ( self ::JETPACK_SOCIAL_NOTE_CPT_ENABLED === $ name ) {
357
+ // Delete this option, so the rules get flushed in maybe_flush_rewrite_rules when the CPT is registered.
358
+ delete_option ( self ::NOTES_FLUSH_REWRITE_RULES_FLUSHED );
359
+ return update_option ( self ::JETPACK_SOCIAL_NOTE_CPT_ENABLED , (bool ) $ value );
360
+ }
361
+ if ( self ::OPTION_PREFIX . self ::NOTES_CONFIG === $ name ) {
362
+ $ old_config = $ this ->get_social_notes_config ();
363
+ $ new_config = array_merge ( $ old_config , $ value );
364
+ return update_option ( self ::OPTION_PREFIX . self ::NOTES_CONFIG , $ new_config );
365
+ }
366
+
367
+ if ( self ::JETPACK_SOCIAL_SHOW_PRICING_PAGE === $ name ) {
368
+ return update_option ( self ::JETPACK_SOCIAL_SHOW_PRICING_PAGE , (int ) $ value );
369
+ }
370
+
270
371
return $ updated ;
271
372
}
272
373
0 commit comments