Skip to content

Commit c8517bc

Browse files
authored
feat: Editor theme styles preferences align with web defaults (#24958)
* feat: Relocate editor theme style preference to site settings Site settings is a more appropriate long-term location than experimental features. * task: Remove unused editor theme styles feature flag * feat: Enable editor theme styles by default Align with the web editor defaults. * feat: Display editor theme styles preference for WPCOM Simple sites * feat: Hide the editor theme styles toggle when GutenbergKit is disabled This toggle only impacts GutenbergKit. * feat: Separate footnotes for editor preference toggles * refactor: Remove unused SiteSettingsEditor enum This became unnecessary once we used two sections for each toggle.
1 parent 6e614e3 commit c8517bc

File tree

7 files changed

+109
-34
lines changed

7 files changed

+109
-34
lines changed

WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public enum FeatureFlag: Int, CaseIterable {
2020
case googleDomainsCard
2121
case voiceToContent
2222
case allowApplicationPasswords
23-
case newGutenbergThemeStyles
2423
case selfHostedSiteUserManagement
2524
case readerGutenbergCommentComposer
2625
case pluginManagementOverhaul
@@ -72,8 +71,6 @@ public enum FeatureFlag: Int, CaseIterable {
7271
return app == .jetpack && BuildConfiguration.current.isInternal
7372
case .allowApplicationPasswords:
7473
return false
75-
case .newGutenbergThemeStyles:
76-
return false
7774
case .selfHostedSiteUserManagement:
7875
return false
7976
case .readerGutenbergCommentComposer:
@@ -126,7 +123,6 @@ extension FeatureFlag {
126123
case .googleDomainsCard: "Google Domains Promotional Card"
127124
case .voiceToContent: "Voice to Content"
128125
case .allowApplicationPasswords: "Allow creating Application Passwords"
129-
case .newGutenbergThemeStyles: "Experimental Block Editor Styles"
130126
case .selfHostedSiteUserManagement: "Self-hosted Site User Management"
131127
case .pluginManagementOverhaul: "Plugin Management Overhaul"
132128
case .readerGutenbergCommentComposer: "Gutenberg Comment Composer"

WordPress/Classes/Utility/Editor/EditorConfiguration+Blog.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extension EditorConfiguration {
4242
.setSiteApiNamespace(siteApiNamespace)
4343
.setNamespaceExcludedPaths(["/wpcom/v2/following/recommendations", "/wpcom/v2/following/mine"])
4444
.setAuthHeader(authHeader)
45-
.setShouldUseThemeStyles(FeatureFlag.newGutenbergThemeStyles.enabled)
45+
.setShouldUseThemeStyles(GutenbergSettings().isThemeStylesEnabled(for: blog))
4646
// Limited to Jetpack-connected sites until editor assets endpoint is available in WordPress core
4747
.setShouldUsePlugins(Self.shouldEnablePlugins(for: blog, appPassword: applicationPassword))
4848
.setLocale(WordPressComLanguageDatabase().deviceLanguage.slug)

WordPress/Classes/Utility/Editor/GutenbergSettings.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class GutenbergSettings {
1616
let url = urlString(fromBlogURL: url)
1717
return "kShowGutenbergPhase2Dialog-" + url
1818
}
19+
static func themeStylesEnabled(forBlogURL url: String?) -> String {
20+
let url = urlString(fromBlogURL: url)
21+
return "com.wordpress.gutenberg-theme-styles-" + url
22+
}
1923
static let focalPointPickerTooltipShown = "kGutenbergFocalPointPickerTooltipShown"
2024
static let blockTypeImpressions = "kBlockTypeImpressions"
2125

@@ -214,6 +218,33 @@ class GutenbergSettings {
214218
database.set(true, forKey: Key.enabledOnce(forBlogURL: blog.url))
215219
return .gutenberg
216220
}
221+
222+
// MARK: - Theme Styles
223+
224+
/// Returns whether theme styles should be enabled for the given blog.
225+
///
226+
/// - Parameter blog: The blog to check theme styles setting for
227+
/// - Returns: true if theme styles are enabled (default: true), false if explicitly disabled
228+
func isThemeStylesEnabled(for blog: Blog) -> Bool {
229+
let key = Key.themeStylesEnabled(forBlogURL: blog.url)
230+
231+
// If the preference has been explicitly set, return its value
232+
if database.object(forKey: key) != nil {
233+
return database.bool(forKey: key)
234+
}
235+
236+
// Default to enabled for sites that haven't set a preference
237+
return true
238+
}
239+
240+
/// Sets whether theme styles should be enabled for the given blog.
241+
///
242+
/// - Parameters:
243+
/// - isEnabled: Whether to enable theme styles
244+
/// - blog: The blog to set theme styles setting for
245+
func setThemeStylesEnabled(_ isEnabled: Bool, for blog: Blog) {
246+
database.set(isEnabled, forKey: Key.themeStylesEnabled(forBlogURL: blog.url))
247+
}
217248
}
218249

219250
@objc(GutenbergSettings)
@@ -232,6 +263,16 @@ public class GutenbergSettingsBridge: NSObject {
232263
public static func isSimpleWPComSite(_ blog: Blog) -> Bool {
233264
return GutenbergSettings().isSimpleWPComSite(blog)
234265
}
266+
267+
@objc(isThemeStylesEnabledForBlog:)
268+
public static func isThemeStylesEnabled(for blog: Blog) -> Bool {
269+
return GutenbergSettings().isThemeStylesEnabled(for: blog)
270+
}
271+
272+
@objc(setThemeStylesEnabled:forBlog:)
273+
public static func setThemeStylesEnabled(_ isEnabled: Bool, for blog: Blog) {
274+
GutenbergSettings().setThemeStylesEnabled(isEnabled, for: blog)
275+
}
235276
}
236277

237278
private extension String {

WordPress/Classes/ViewRelated/Blog/Site Settings/SiteSettingsViewController+Swift.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,20 @@ extension SiteSettingsViewController {
190190
return footer
191191
}
192192

193-
@objc(getEditorSettingsSectionFooterView)
194-
public func editorSettingsSectionFooterView() -> UIView {
193+
@objc(getBlockEditorSectionFooterView)
194+
public func blockEditorSectionFooterView() -> UIView {
195195
let footer = makeFooterView()
196196
footer.textLabel?.text = NSLocalizedString("Edit new posts and pages with the block editor.", comment: "Explanation for the option to enable the block editor")
197197
return footer
198198
}
199199

200+
@objc(getThemeStylesSectionFooterView)
201+
public func themeStylesSectionFooterView() -> UIView {
202+
let footer = makeFooterView()
203+
footer.textLabel?.text = NSLocalizedString("Make the block editor look like your theme.", comment: "Explanation for the option to enable theme styles")
204+
return footer
205+
}
206+
200207
private func makeFooterView() -> UITableViewHeaderFooterView {
201208
let footer = UITableViewHeaderFooterView()
202209
footer.textLabel?.numberOfLines = 0

WordPress/Classes/ViewRelated/Blog/Site Settings/SiteSettingsViewController.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ typedef NS_ENUM(NSInteger, SiteSettingsSection) {
88
SiteSettingsSectionBlogging,
99
SiteSettingsSectionHomepage,
1010
SiteSettingsSectionAccount,
11-
SiteSettingsSectionEditor,
11+
SiteSettingsSectionBlockEditor,
12+
SiteSettingsSectionThemeStyles,
1213
SiteSettingsSectionWriting,
1314
SiteSettingsSectionMedia,
1415
SiteSettingsSectionDiscussion,

WordPress/Classes/ViewRelated/Blog/Site Settings/SiteSettingsViewController.m

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525
SiteSettingsHomepageCount,
2626
};
2727

28-
NS_ENUM(NSInteger, SiteSettingsEditor) {
29-
SiteSettingsEditorSelector = 0,
30-
SiteSettingsEditorCount,
31-
};
32-
3328
NS_ENUM(NSInteger, SiteSettingsWriting) {
3429
SiteSettingsWritingDefaultCategory = 0,
3530
SiteSettingsWritingTags,
@@ -61,6 +56,7 @@ @interface SiteSettingsViewController () <UITableViewDelegate, UITextFieldDelega
6156
@property (nonatomic, strong) SettingTableViewCell *passwordTextCell;
6257
#pragma mark - Writing Section
6358
@property (nonatomic, strong) SwitchTableViewCell *editorSelectorCell;
59+
@property (nonatomic, strong) SwitchTableViewCell *themeStylesSelectorCell;
6460
@property (nonatomic, strong) SettingTableViewCell *defaultCategoryCell;
6561
@property (nonatomic, strong) SettingTableViewCell *tagsCell;
6662
@property (nonatomic, strong) SettingTableViewCell *customTaxonomiesCell;
@@ -170,9 +166,14 @@ - (NSArray *)tableSections
170166
[sections addObject:@(SiteSettingsSectionAccount)];
171167
}
172168

173-
// Only add the editor section if the site is not a Simple WP.com site
169+
// Only show "Use block editor" toggle for non-Simple WP.com sites
174170
if (![GutenbergSettings isSimpleWPComSite:self.blog]) {
175-
[sections addObject:@(SiteSettingsSectionEditor)];
171+
[sections addObject:@(SiteSettingsSectionBlockEditor)];
172+
}
173+
174+
// Only show theme styles toggle when GutenbergKit is enabled
175+
if ([RemoteFeature enabled:RemoteFeatureFlagNewGutenberg]) {
176+
[sections addObject:@(SiteSettingsSectionThemeStyles)];
176177
}
177178

178179
if ([self.blog supports:BlogFeatureWPComRESTAPI] && self.blog.isAdmin) {
@@ -251,9 +252,13 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
251252
{
252253
return SiteSettingsAccountCount;
253254
}
254-
case SiteSettingsSectionEditor:
255+
case SiteSettingsSectionBlockEditor:
255256
{
256-
return SiteSettingsEditorCount;
257+
return 1;
258+
}
259+
case SiteSettingsSectionThemeStyles:
260+
{
261+
return 1;
257262
}
258263
case SiteSettingsSectionWriting:
259264
{
@@ -347,6 +352,20 @@ - (SwitchTableViewCell *)editorSelectorCell
347352
return _editorSelectorCell;
348353
}
349354

355+
- (SwitchTableViewCell *)themeStylesSelectorCell
356+
{
357+
if (!_themeStylesSelectorCell) {
358+
_themeStylesSelectorCell = [SwitchTableViewCell new];
359+
_themeStylesSelectorCell.name = NSLocalizedString(@"Use theme styles", @"Option to enable theme styles in the block editor");
360+
_themeStylesSelectorCell.flipSwitch.accessibilityIdentifier = @"useThemeStylesSwitch";
361+
__weak Blog *blog = self.blog;
362+
_themeStylesSelectorCell.onChange = ^(BOOL value){
363+
[GutenbergSettings setThemeStylesEnabled:value forBlog:blog];
364+
};
365+
}
366+
return _themeStylesSelectorCell;
367+
}
368+
350369
- (SettingTableViewCell *)defaultCategoryCell
351370
{
352371
if (_defaultCategoryCell){
@@ -508,6 +527,11 @@ - (void)configureEditorSelectorCell
508527
[self.editorSelectorCell setOn:self.blog.isGutenbergEnabled];
509528
}
510529

530+
- (void)configureThemeStylesSelectorCell
531+
{
532+
[self.themeStylesSelectorCell setOn:[GutenbergSettings isThemeStylesEnabledForBlog:self.blog]];
533+
}
534+
511535
- (void)configureDefaultCategoryCell
512536
{
513537
PostCategory *postCategory = [PostCategory lookupWithBlogObjectID:self.blog.objectID
@@ -526,16 +550,6 @@ - (void)configurePostsPerPageCell
526550
[self.postsPerPageCell setTextValue:self.blog.settings.postsPerPage.stringValue];
527551
}
528552

529-
- (UITableViewCell *)tableView:(UITableView *)tableView cellForEditorSettingsAtRow:(NSInteger)row
530-
{
531-
switch (row) {
532-
case (SiteSettingsEditorSelector):
533-
[self configureEditorSelectorCell];
534-
return self.editorSelectorCell;
535-
}
536-
return nil;
537-
}
538-
539553
- (UITableViewCell *)tableView:(UITableView *)tableView cellForWritingSettingsAtRow:(NSInteger)row
540554
{
541555
NSInteger writingRow = [self.writingSectionRows[row] integerValue];
@@ -665,8 +679,13 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
665679
case SiteSettingsSectionAccount:
666680
return [self tableView:tableView cellForAccountSettingsInRow:indexPath.row];
667681

668-
case SiteSettingsSectionEditor:
669-
return [self tableView:tableView cellForEditorSettingsAtRow:indexPath.row];
682+
case SiteSettingsSectionBlockEditor:
683+
[self configureEditorSelectorCell];
684+
return self.editorSelectorCell;
685+
686+
case SiteSettingsSectionThemeStyles:
687+
[self configureThemeStylesSelectorCell];
688+
return self.themeStylesSelectorCell;
670689

671690
case SiteSettingsSectionWriting:
672691
return [self tableView:tableView cellForWritingSettingsAtRow:indexPath.row];
@@ -729,8 +748,16 @@ - (NSString *)titleForHeaderInSection:(NSInteger)section
729748
headingTitle = NSLocalizedString(@"Account", @"Title for the account section in site settings screen");
730749
break;
731750

732-
case SiteSettingsSectionEditor:
733-
headingTitle = NSLocalizedString(@"Editor", @"Title for the editor settings section");
751+
case SiteSettingsSectionBlockEditor:
752+
headingTitle = NSLocalizedString(@"Editor", @"Title for the editor section in site settings screen");
753+
break;
754+
755+
case SiteSettingsSectionThemeStyles:
756+
// Only show "Editor" header if this is the first editor section
757+
// (i.e., if block editor section is not present)
758+
if (![self.tableSections containsObject:@(SiteSettingsSectionBlockEditor)]) {
759+
headingTitle = NSLocalizedString(@"Editor", @"Title for the editor section in site settings screen");
760+
}
734761
break;
735762

736763
case SiteSettingsSectionWriting:
@@ -761,8 +788,12 @@ -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)
761788
NSInteger settingsSection = [self.tableSections[section] integerValue];
762789
UIView *footerView = nil;
763790
switch (settingsSection) {
764-
case SiteSettingsSectionEditor:
765-
footerView = [self getEditorSettingsSectionFooterView];
791+
case SiteSettingsSectionBlockEditor:
792+
footerView = [self getBlockEditorSectionFooterView];
793+
break;
794+
795+
case SiteSettingsSectionThemeStyles:
796+
footerView = [self getThemeStylesSectionFooterView];
766797
break;
767798

768799
case SiteSettingsSectionTraffic:

WordPress/Classes/ViewRelated/Me/App Settings/ExperimentalFeaturesDataProvider.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class ExperimentalFeaturesDataProvider: ExperimentalFeaturesViewModel.DataProvid
1010
FeatureFlag.newStats,
1111
FeatureFlag.allowApplicationPasswords,
1212
RemoteFeatureFlag.newGutenberg,
13-
FeatureFlag.newGutenbergThemeStyles,
1413
FeatureFlag.newSupport,
1514
]
1615

0 commit comments

Comments
 (0)