Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/design settings improvements #2670

Merged
merged 12 commits into from
Oct 5, 2023
20 changes: 19 additions & 1 deletion assets/wizards/site-design/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies.
*/
import { withWizard } from '../../components/src';
import { withWizard, utils } from '../../components/src';
import Router from '../../components/src/proxied-imports/router';
import { ThemeSettings, Main } from './views';

Expand All @@ -36,6 +36,24 @@ class SiteDesignWizard extends Component {
updateThemeMods = () => {
const { setError, wizardApiFetch } = this.props;
const { themeMods } = this.state;

// Warn user before overwriting existing posts.
if (
themeMods.featured_image_all_posts !== 'none' ||
dkoo marked this conversation as resolved.
Show resolved Hide resolved
themeMods.post_template_all_posts !== 'none'
) {
if (
! utils.confirmAction(
__(
'Saving will overwrite existing posts, this cannot be undone. Are you sure you want to proceed?',
'newspack'
dkoo marked this conversation as resolved.
Show resolved Hide resolved
)
)
) {
return;
}
}

const params = {
path: '/newspack/v1/wizard/newspack-setup-wizard/theme/',
method: 'POST',
Expand Down
107 changes: 91 additions & 16 deletions assets/wizards/site-design/views/theme-settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { Fragment, useEffect, useState } from '@wordpress/element';
import { RadioControl, ToggleControl } from '@wordpress/components';
import { SelectControl, Notice, ToggleControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
Expand All @@ -28,7 +28,10 @@ const ThemeSettings = props => {
show_author_bio: authorBio = true,
show_author_email: authorEmail = false,
author_bio_length: authorBioLength = 200,
featured_image_default: featuredImageDefault,
featured_image_default: featuredImageDefault = 'large',
post_template_default: postTemplateDefault = 'default',
featured_image_all_posts: featuredImageAllPosts = 'none',
post_template_all_posts: postTemplateAllPosts = 'none',
newspack_image_credits_placeholder_url: imageCreditsPlaceholderUrl,
newspack_image_credits_class_name: imageCreditsClassName = '',
newspack_image_credits_prefix_label: imageCreditsPrefix = '',
Expand Down Expand Up @@ -80,22 +83,94 @@ const ThemeSettings = props => {
</Grid>

<SectionHeader
title={ __( 'Featured Image', 'newspack' ) }
description={ __( 'Set a default featured image position for new posts.', 'newspack' ) }
title={ __( 'Default Featured Image Position And Post Template', 'newspack' ) }
description={ __(
'Modify how the featured image and post template settings are applied to new posts.',
'newspack'
) }
/>
<RadioControl
label={ __( 'Default Position', 'newspack' ) }
hideLabelFromVision
selected={ featuredImageDefault || 'large' }
options={ [
{ label: __( 'Large', 'newspack' ), value: 'large' },
{ label: __( 'Small', 'newspack' ), value: 'small' },
{ label: __( 'Behind article title', 'newspack' ), value: 'behind' },
{ label: __( 'Beside article title', 'newspack' ), value: 'beside' },
{ label: __( 'Hidden', 'newspack' ), value: 'hidden' },
] }
onChange={ value => setThemeMods( { featured_image_default: value } ) }
<Grid gutter={ 32 }>
<SelectControl
label={ __( 'Default featured image position for new posts', 'newspack' ) }
help={ __( 'Set a default featured image position for new posts.', 'newspack' ) }
value={ featuredImageDefault }
options={ [
{ label: __( 'Large', 'newspack' ), value: 'large' },
{ label: __( 'Small', 'newspack' ), value: 'small' },
{ label: __( 'Behind article title', 'newspack' ), value: 'behind' },
{ label: __( 'Beside article title', 'newspack' ), value: 'beside' },
{ label: __( 'Hidden', 'newspack' ), value: 'hidden' },
] }
onChange={ value => setThemeMods( { featured_image_default: value } ) }
/>
<SelectControl
label={ __( 'Default template for new posts', 'newspack' ) }
help={ __( 'Set a default template for new posts.', 'newspack' ) }
value={ postTemplateDefault }
options={ [
{ label: __( 'Default', 'newspack' ), value: 'default' },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might warrant an opinion from @laurelfulford, but with the new feature to set a "default" post template for new or existing posts, the name of the "Default" template is confusing to me. It's especially confusing if I change the default template for new posts to something other than "Default", then change the "Template for all posts" to "Default"—part of me thinks doing the latter will change the posts to the default template I had specified in the other setting.

I propose we change the labels for the "Default" template to say something more descriptive like "With sidebar" instead, which would also require renaming the options in the Customizer. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, "Default" is confusing here. I'll update it to "With sidebar" – @laurelfulford let me know if you'd prefer it differently when you're available :)

{ label: __( 'One Column', 'newspack' ), value: 'single-feature.php' },
{ label: __( 'One Column Wide', 'newspack' ), value: 'single-wide.php' },
] }
onChange={ value => setThemeMods( { post_template_default: value } ) }
/>
</Grid>
<SectionHeader
title={ __( 'Featured Image Position And Post Template For All Posts', 'newspack' ) }
description={ __(
'Modify how the featured image and post template settings are applied to existing posts. Warning: saving these options will override all posts.',
'newspack'
) }
/>
<Grid gutter={ 32 }>
<div>
<SelectControl
label={ __( 'Featured image position for all posts', 'newspack' ) }
help={ __( 'Set a featured image position for all posts.', 'newspack' ) }
value={ featuredImageAllPosts }
options={ [
{ label: __( 'Select to change all posts', 'newspack' ), value: 'none' },
adekbadek marked this conversation as resolved.
Show resolved Hide resolved
{ label: __( 'Large', 'newspack' ), value: 'large' },
{ label: __( 'Small', 'newspack' ), value: 'small' },
{ label: __( 'Behind article title', 'newspack' ), value: 'behind' },
{ label: __( 'Beside article title', 'newspack' ), value: 'beside' },
{ label: __( 'Hidden', 'newspack' ), value: 'hidden' },
] }
onChange={ value => setThemeMods( { featured_image_all_posts: value } ) }
/>
{ featuredImageAllPosts !== 'none' && (
<Notice isDismissible={ false } status="warning" className="ma0 mt2">
{ __(
'After saving the settings with this option selected, all post will be updated. This cannot be undone.',
adekbadek marked this conversation as resolved.
Show resolved Hide resolved
'newspack-newsletters'
adekbadek marked this conversation as resolved.
Show resolved Hide resolved
) }
</Notice>
) }
</div>

<div>
<SelectControl
label={ __( 'Template for all posts', 'newspack' ) }
help={ __( 'Set a template for all posts.', 'newspack' ) }
value={ postTemplateAllPosts }
options={ [
{ label: __( 'Select to change all posts', 'newspack' ), value: 'none' },
{ label: __( 'Default', 'newspack' ), value: 'default' },
{ label: __( 'One Column', 'newspack' ), value: 'single-feature.php' },
{ label: __( 'One Column Wide', 'newspack' ), value: 'single-wide.php' },
] }
onChange={ value => setThemeMods( { post_template_all_posts: value } ) }
/>
{ postTemplateAllPosts !== 'none' && (
<Notice isDismissible={ false } status="warning" className="ma0 mt2">
{ __(
'After saving the settings with this option selected, all post will be updated. This cannot be undone.',
adekbadek marked this conversation as resolved.
Show resolved Hide resolved
'newspack-newsletters'
adekbadek marked this conversation as resolved.
Show resolved Hide resolved
) }
</Notice>
) }
</div>
</Grid>

<SectionHeader
title={ __( 'Media Credits', 'newspack' ) }
Expand Down
29 changes: 29 additions & 0 deletions includes/wizards/class-setup-wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,35 @@ public function api_update_theme_with_mods( $request ) {
continue;
}

if ( substr_compare( $key, '_all_posts', -strlen( '_all_posts' ) ) === 0 ) {
$post_ids = get_posts(
[
'posts_per_page' => -1,
adekbadek marked this conversation as resolved.
Show resolved Hide resolved
'post_type' => 'post',
'fields' => 'ids',
]
);
// Update the featured image position on all posts.
if ( 'featured_image_all_posts' === $key ) {
foreach ( $post_ids as $post_id ) {
update_post_meta( $post_id, 'newspack_featured_image_position', $value );
Logger::log(
sprintf( 'Updated featured image position to "%s" on post #%s.', $value, $post_id )
);
}
}
// Update the template on all posts.
if ( 'post_template_all_posts' === $key ) {
foreach ( $post_ids as $post_id ) {
update_post_meta( $post_id, '_wp_page_template', $value );
Logger::log(
sprintf( 'Updated template to "%s" on post #%s.', $value, $post_id )
);
}
}
continue;
}

if ( null !== $value && in_array( $key, $this->media_theme_mods ) ) {
$value = $value['id'];
}
Expand Down