Skip to content

Commit

Permalink
Merge pull request #3430 from Automattic/feat/ia-settings-display-set…
Browse files Browse the repository at this point in the history
…tings__part-2

feat(ia): display settings - part 2
  • Loading branch information
jaredrethman authored Oct 14, 2024
2 parents 19afca0 + 7a6416d commit 776b7ff
Show file tree
Hide file tree
Showing 9 changed files with 475 additions and 31 deletions.
8 changes: 8 additions & 0 deletions includes/wizards/class-setup-wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,9 @@ public function api_update_theme_with_mods( $request ) {

// All-posts updates: featured image and post template.
if ( substr_compare( $key, '_all_posts', -strlen( '_all_posts' ) ) === 0 ) {
if ( 'none' === $value ) {
continue;
}
switch ( $key ) {
case 'featured_image_all_posts':
self::update_meta_key_in_batches( 'newspack_featured_image_position', $value );
Expand Down Expand Up @@ -541,11 +544,16 @@ private static function update_meta_key_in_batches( $meta_key, $value, $page = 0
'post_type' => 'post',
'fields' => 'ids',
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
'relation' => 'OR',
[
'key' => $meta_key,
'value' => $value,
'compare' => '!=',
],
[
'key' => $meta_key,
'compare' => 'NOT EXISTS',
],
],
];
$results = new \WP_Query( $args );
Expand Down
16 changes: 12 additions & 4 deletions src/admin/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,29 @@ h1 {
.newspack-select-control {
animation: opacity-pulse 1.4s infinite;

.components-select-control__input {
// Specificity necessary to override @emotion/* styles
select.components-select-control__input {
background-color: var(--np-color-wp-gray-100);
}

select {
border: 1px solid var(--np-color-wp-gray-100);
cursor: progress;
}

// Specificity necessary to override @emotion/* styles
div.components-input-control__backdrop {
border: none;
}

optgroup,
option,
.components-input-control__suffix,
.components-select-control__arrow-wrapper {
display: none;
}
}

.newspack-image-upload__image {
animation: opacity-pulse 1.4s infinite;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/**
* Newspack > Settings > Display Settings > Featured Image Posts All
*/

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Fragment } from '@wordpress/element';
import { Notice } from '@wordpress/components';

/**
* Internal dependencies
*/
import { Grid, SelectControl } from '../../../../../components/src';

export default function FeaturedImagePostsAll( {
data,
update,
postCount,
}: ThemeModComponentProps< DisplaySettings > & { postCount: string } ) {
return (
<Fragment>
{ Number( postCount ) > 1000 && (
<Notice
isDismissible={ false }
status="warning"
className="ma0 mb2"
>
{ __(
'You have more than 1000 posts. Applying these settings might take a moment.',
'newspack-plugin'
) }
</Notice>
) }
<Grid gutter={ 32 }>
<div>
<SelectControl
label={ __(
'Featured image position for all posts',
'newspack-plugin'
) }
help={ __(
'Set a featured image position for all posts.',
'newspack-plugin'
) }
value={ data.featured_image_all_posts }
options={ [
{
label: __(
'Select to change all posts',
'newspack-plugin'
),
value: 'none',
},
{
label: __( 'Large', 'newspack-plugin' ),
value: 'large',
},
{
label: __( 'Small', 'newspack-plugin' ),
value: 'small',
},
{
label: __(
'Behind article title',
'newspack-plugin'
),
value: 'behind',
},
{
label: __(
'Beside article title',
'newspack-plugin'
),
value: 'beside',
},
{
label: __( 'Hidden', 'newspack-plugin' ),
value: 'hidden',
},
] }
onChange={ ( featured_image_all_posts: string ) =>
update( { featured_image_all_posts } )
}
/>
{ data.featured_image_all_posts !== 'none' && (
<Notice
isDismissible={ false }
status="warning"
className="ma0 mt2"
>
{ __(
'After saving the settings with this option selected, all posts will be updated. This cannot be undone.',
'newspack-plugin'
) }
</Notice>
) }
</div>

<div>
<SelectControl
label={ __(
'Template for all posts',
'newspack-plugin'
) }
help={ __(
'Set a template for all posts.',
'newspack-plugin'
) }
value={ data.post_template_all_posts }
options={ [
{
label: __(
'Select to change all posts',
'newspack-plugin'
),
value: 'none',
},
{
label: __( 'With sidebar', 'newspack-plugin' ),
value: 'default',
},
{
label: __( 'One Column', 'newspack-plugin' ),
value: 'single-feature.php',
},
{
label: __(
'One Column Wide',
'newspack-plugin'
),
value: 'single-wide.php',
},
] }
onChange={ ( post_template_all_posts: string ) =>
update( { post_template_all_posts } )
}
/>
{ data.post_template_all_posts !== 'none' && (
<Notice
isDismissible={ false }
status="warning"
className="ma0 mt2"
>
{ __(
'After saving the settings with this option selected, all posts will be updated. This cannot be undone.',
'newspack-plugin'
) }
</Notice>
) }
</div>
</Grid>
</Fragment>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* Newspack > Settings > Display Settings > Featured Image Posts New
*/

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { Grid, SelectControl } from '../../../../../components/src';

export default function FeaturedImagePostsNew( {
data,
update,
}: ThemeModComponentProps< DisplaySettings > ) {
return (
<Grid gutter={ 32 }>
<SelectControl
label={ __(
'Default featured image position for new posts',
'newspack-plugin'
) }
help={ __(
'Set a default featured image position for new posts.',
'newspack-plugin'
) }
value={ data.featured_image_default }
options={ [
{ label: __( 'Large', 'newspack-plugin' ), value: 'large' },
{ label: __( 'Small', 'newspack-plugin' ), value: 'small' },
{
label: __( 'Behind article title', 'newspack-plugin' ),
value: 'behind',
},
{
label: __( 'Beside article title', 'newspack-plugin' ),
value: 'beside',
},
{
label: __( 'Hidden', 'newspack-plugin' ),
value: 'hidden',
},
] }
onChange={ ( featured_image_default: string ) =>
update( { featured_image_default } )
}
/>
<SelectControl
label={ __(
'Default template for new posts',
'newspack-plugin'
) }
help={ __(
'Set a default template for new posts.',
'newspack-plugin'
) }
value={ data.post_template_default }
options={ [
{
label: __( 'With sidebar', 'newspack-plugin' ),
value: 'default',
},
{
label: __( 'One Column', 'newspack-plugin' ),
value: 'single-feature.php',
},
{
label: __( 'One Column Wide', 'newspack-plugin' ),
value: 'single-wide.php',
},
] }
onChange={ ( post_template_default: string ) =>
update( { post_template_default } )
}
/>
</Grid>
);
}
Loading

0 comments on commit 776b7ff

Please sign in to comment.