@automattic/newspack-blocks 1.60.1 → 1.61.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cache/babel/3a66da0fe7ab175effa6a338812e46cb.json.gz +0 -0
- package/.cache/babel/9ed09b96b5f2df9daa6ce37304a7440e.json.gz +0 -0
- package/.cache/babel/dd70bbfe108da5e2fc7bd73bc688a05a.json.gz +0 -0
- package/CHANGELOG.md +30 -0
- package/composer.lock +6 -6
- package/dist/author-profile/view.asset.php +1 -1
- package/dist/author-profile/view.css +1 -1
- package/dist/author-profile/view.rtl.css +1 -1
- package/dist/donateStreamlined.asset.php +1 -1
- package/dist/donateStreamlined.js +1 -1
- package/dist/editor.asset.php +1 -1
- package/dist/editor.css +1 -1
- package/dist/editor.js +1 -1
- package/dist/editor.rtl.css +1 -1
- package/includes/class-newspack-blocks-api.php +3 -13
- package/includes/class-newspack-blocks.php +48 -39
- package/newspack-blocks.php +2 -2
- package/package.json +3 -3
- package/src/blocks/author-profile/editor.scss +5 -1
- package/src/blocks/author-profile/view.scss +4 -2
- package/src/blocks/donate/streamlined/index.ts +7 -1
- package/src/blocks/homepage-articles/class-wp-rest-newspack-articles-controller.php +1 -2
- package/src/blocks/homepage-articles/edit.js +10 -18
- package/src/blocks/homepage-articles/templates/article.php +8 -1
- package/src/blocks/homepage-articles/view.php +65 -0
- package/src/blocks/iframe/class-wp-rest-newspack-iframe-controller.php +0 -1
- package/src/components/query-controls.js +90 -94
- package/vendor/autoload.php +19 -1
- package/vendor/composer/ClassLoader.php +24 -15
- package/vendor/composer/InstalledVersions.php +9 -7
- package/vendor/composer/autoload_classmap.php +1 -1
- package/vendor/composer/autoload_namespaces.php +1 -1
- package/vendor/composer/autoload_psr4.php +1 -1
- package/vendor/composer/autoload_real.php +7 -26
- package/vendor/composer/autoload_static.php +2 -2
- package/vendor/composer/installed.php +3 -3
- package/.cache/babel/62b5d63d437188c9504804ced0783c31.json.gz +0 -0
- package/.cache/babel/9b4ddedacf987769a9fe17e8aa8aa4cd.json.gz +0 -0
- package/.cache/babel/de3c26fe430ad8ad5100705a33cb0cc3.json.gz +0 -0
|
@@ -96,19 +96,9 @@ class Newspack_Blocks_API {
|
|
|
96
96
|
$authors = get_coauthors();
|
|
97
97
|
|
|
98
98
|
foreach ( $authors as $author ) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if ( get_post_thumbnail_id( $author->ID ) ) {
|
|
103
|
-
$author_avatar = coauthors_get_avatar( $author, 48 );
|
|
104
|
-
} else {
|
|
105
|
-
// If there is no avatar, force it to return the current fallback image.
|
|
106
|
-
$author_avatar = get_avatar( ' ' );
|
|
107
|
-
}
|
|
108
|
-
} else {
|
|
109
|
-
$author_avatar = coauthors_get_avatar( $author, 48 );
|
|
110
|
-
}
|
|
111
|
-
$author_link = null;
|
|
99
|
+
$author_avatar = coauthors_get_avatar( $author, 48 );
|
|
100
|
+
$author_link = null;
|
|
101
|
+
|
|
112
102
|
if ( function_exists( 'coauthors_posts_links' ) ) {
|
|
113
103
|
$author_link = get_author_posts_url( $author->ID, $author->user_nicename );
|
|
114
104
|
}
|
|
@@ -430,55 +430,67 @@ class Newspack_Blocks {
|
|
|
430
430
|
public static function image_size_for_orientation( $orientation = 'landscape' ) {
|
|
431
431
|
$sizes = array(
|
|
432
432
|
'landscape' => array(
|
|
433
|
-
'large'
|
|
433
|
+
'large' => array(
|
|
434
434
|
1200,
|
|
435
435
|
900,
|
|
436
436
|
),
|
|
437
|
-
'medium'
|
|
437
|
+
'medium' => array(
|
|
438
438
|
800,
|
|
439
439
|
600,
|
|
440
440
|
),
|
|
441
|
-
'
|
|
441
|
+
'intermediate' => array(
|
|
442
|
+
600,
|
|
443
|
+
450,
|
|
444
|
+
),
|
|
445
|
+
'small' => array(
|
|
442
446
|
400,
|
|
443
447
|
300,
|
|
444
448
|
),
|
|
445
|
-
'tiny'
|
|
449
|
+
'tiny' => array(
|
|
446
450
|
200,
|
|
447
451
|
150,
|
|
448
452
|
),
|
|
449
453
|
),
|
|
450
454
|
'portrait' => array(
|
|
451
|
-
'large'
|
|
455
|
+
'large' => array(
|
|
452
456
|
900,
|
|
453
457
|
1200,
|
|
454
458
|
),
|
|
455
|
-
'medium'
|
|
459
|
+
'medium' => array(
|
|
456
460
|
600,
|
|
457
461
|
800,
|
|
458
462
|
),
|
|
459
|
-
'
|
|
463
|
+
'intermediate' => array(
|
|
464
|
+
450,
|
|
465
|
+
600,
|
|
466
|
+
),
|
|
467
|
+
'small' => array(
|
|
460
468
|
300,
|
|
461
469
|
400,
|
|
462
470
|
),
|
|
463
|
-
'tiny'
|
|
471
|
+
'tiny' => array(
|
|
464
472
|
150,
|
|
465
473
|
200,
|
|
466
474
|
),
|
|
467
475
|
),
|
|
468
476
|
'square' => array(
|
|
469
|
-
'large'
|
|
477
|
+
'large' => array(
|
|
470
478
|
1200,
|
|
471
479
|
1200,
|
|
472
480
|
),
|
|
473
|
-
'medium'
|
|
481
|
+
'medium' => array(
|
|
474
482
|
800,
|
|
475
483
|
800,
|
|
476
484
|
),
|
|
477
|
-
'
|
|
485
|
+
'intermediate' => array(
|
|
486
|
+
600,
|
|
487
|
+
600,
|
|
488
|
+
),
|
|
489
|
+
'small' => array(
|
|
478
490
|
400,
|
|
479
491
|
400,
|
|
480
492
|
),
|
|
481
|
-
'tiny'
|
|
493
|
+
'tiny' => array(
|
|
482
494
|
200,
|
|
483
495
|
200,
|
|
484
496
|
),
|
|
@@ -510,6 +522,10 @@ class Newspack_Blocks {
|
|
|
510
522
|
add_image_size( 'newspack-article-block-portrait-medium', 600, 800, true );
|
|
511
523
|
add_image_size( 'newspack-article-block-square-medium', 800, 800, true );
|
|
512
524
|
|
|
525
|
+
add_image_size( 'newspack-article-block-landscape-intermediate', 600, 450, true );
|
|
526
|
+
add_image_size( 'newspack-article-block-portrait-intermediate', 450, 600, true );
|
|
527
|
+
add_image_size( 'newspack-article-block-square-intermediate', 600, 600, true );
|
|
528
|
+
|
|
513
529
|
add_image_size( 'newspack-article-block-landscape-small', 400, 300, true );
|
|
514
530
|
add_image_size( 'newspack-article-block-portrait-small', 300, 400, true );
|
|
515
531
|
add_image_size( 'newspack-article-block-square-small', 400, 400, true );
|
|
@@ -616,11 +632,13 @@ class Newspack_Blocks {
|
|
|
616
632
|
$args['category__not_in'] = $category_exclusions;
|
|
617
633
|
}
|
|
618
634
|
|
|
635
|
+
$is_co_authors_plus_active = class_exists( 'CoAuthors_Guest_Authors' );
|
|
636
|
+
|
|
619
637
|
if ( $authors && count( $authors ) ) {
|
|
620
638
|
$co_authors_names = [];
|
|
621
639
|
$author_names = [];
|
|
622
640
|
|
|
623
|
-
if (
|
|
641
|
+
if ( $is_co_authors_plus_active ) {
|
|
624
642
|
$co_authors_guest_authors = new CoAuthors_Guest_Authors();
|
|
625
643
|
|
|
626
644
|
foreach ( $authors as $index => $author_id ) {
|
|
@@ -669,21 +687,23 @@ class Newspack_Blocks {
|
|
|
669
687
|
} elseif ( empty( $co_authors_names ) && count( $authors ) ) {
|
|
670
688
|
$args['author__in'] = $authors;
|
|
671
689
|
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
[
|
|
675
|
-
'relation' => 'OR',
|
|
676
|
-
[
|
|
677
|
-
'taxonomy' => 'author',
|
|
678
|
-
'operator' => 'NOT EXISTS',
|
|
679
|
-
],
|
|
690
|
+
if ( $is_co_authors_plus_active ) {
|
|
691
|
+
// Don't get any posts that are attributed to other CAP guest authors.
|
|
692
|
+
$args['tax_query'] = [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
|
|
680
693
|
[
|
|
681
|
-
'
|
|
682
|
-
|
|
683
|
-
|
|
694
|
+
'relation' => 'OR',
|
|
695
|
+
[
|
|
696
|
+
'taxonomy' => 'author',
|
|
697
|
+
'operator' => 'NOT EXISTS',
|
|
698
|
+
],
|
|
699
|
+
[
|
|
700
|
+
'field' => 'name',
|
|
701
|
+
'taxonomy' => 'author',
|
|
702
|
+
'terms' => $author_names,
|
|
703
|
+
],
|
|
684
704
|
],
|
|
685
|
-
]
|
|
686
|
-
|
|
705
|
+
];
|
|
706
|
+
}
|
|
687
707
|
} else {
|
|
688
708
|
// The query contains both WP users and CAP guest authors. We need to filter the SQL query.
|
|
689
709
|
self::$filter_clauses = [
|
|
@@ -727,19 +747,8 @@ class Newspack_Blocks {
|
|
|
727
747
|
if ( function_exists( 'coauthors_posts_links' ) && ! empty( get_coauthors() ) ) {
|
|
728
748
|
$authors = get_coauthors();
|
|
729
749
|
foreach ( $authors as $author ) {
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
// If yes, make sure the author actually has an avatar set; otherwise, coauthors_get_avatar returns a featured image.
|
|
733
|
-
if ( get_post_thumbnail_id( $author->ID ) ) {
|
|
734
|
-
$author->avatar = coauthors_get_avatar( $author, 48 );
|
|
735
|
-
} else {
|
|
736
|
-
// If there is no avatar, force it to return the current fallback image.
|
|
737
|
-
$author->avatar = get_avatar( ' ' );
|
|
738
|
-
}
|
|
739
|
-
} else {
|
|
740
|
-
$author->avatar = coauthors_get_avatar( $author, 48 );
|
|
741
|
-
}
|
|
742
|
-
$author->url = get_author_posts_url( $author->ID, $author->user_nicename );
|
|
750
|
+
$author->avatar = coauthors_get_avatar( $author, 48 );
|
|
751
|
+
$author->url = get_author_posts_url( $author->ID, $author->user_nicename );
|
|
743
752
|
}
|
|
744
753
|
return $authors;
|
|
745
754
|
}
|
package/newspack-blocks.php
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Author URI: https://newspack.blog/
|
|
8
8
|
* Text Domain: newspack-blocks
|
|
9
9
|
* Domain Path: /languages
|
|
10
|
-
* Version: 1.
|
|
10
|
+
* Version: 1.61.0
|
|
11
11
|
*
|
|
12
12
|
* @package Newspack_Blocks
|
|
13
13
|
*/
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
define( 'NEWSPACK_BLOCKS__PLUGIN_FILE', __FILE__ );
|
|
16
16
|
define( 'NEWSPACK_BLOCKS__BLOCKS_DIRECTORY', 'dist/' );
|
|
17
17
|
define( 'NEWSPACK_BLOCKS__PLUGIN_DIR', plugin_dir_path( NEWSPACK_BLOCKS__PLUGIN_FILE ) );
|
|
18
|
-
define( 'NEWSPACK_BLOCKS__VERSION', '1.
|
|
18
|
+
define( 'NEWSPACK_BLOCKS__VERSION', '1.61.0' );
|
|
19
19
|
|
|
20
20
|
require_once NEWSPACK_BLOCKS__PLUGIN_DIR . 'includes/class-newspack-blocks.php';
|
|
21
21
|
require_once NEWSPACK_BLOCKS__PLUGIN_DIR . 'includes/class-newspack-blocks-api.php';
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automattic/newspack-blocks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.61.0",
|
|
4
4
|
"author": "Automattic",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@rushstack/eslint-patch": "^1.2.0",
|
|
7
|
-
"@testing-library/dom": "^8.19.
|
|
7
|
+
"@testing-library/dom": "^8.19.1",
|
|
8
8
|
"@testing-library/user-event": "^14.4.3",
|
|
9
9
|
"@types/lodash": "^4.14.191",
|
|
10
10
|
"@types/lodash.debounce": "^4.0.7",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"html-entities": "^2.3.3",
|
|
14
14
|
"identity-obj-proxy": "^3.0.0",
|
|
15
15
|
"lint-staged": "^13.1.0",
|
|
16
|
-
"newspack-scripts": "^4.
|
|
16
|
+
"newspack-scripts": "^4.6.0",
|
|
17
17
|
"postcss-scss": "^4.0.6",
|
|
18
18
|
"prettier": "npm:wp-prettier@^2.6.2-beta-1",
|
|
19
19
|
"stylelint": "^14.9.1"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
@use '../../shared/sass/mixins';
|
|
3
3
|
|
|
4
4
|
.editor-styles-wrapper {
|
|
5
|
-
.newspack-blocks-author-profile {
|
|
5
|
+
.wp-block-newspack-blocks-author-profile {
|
|
6
6
|
.components-notice {
|
|
7
7
|
margin: 0 0 2rem 0;
|
|
8
8
|
width: 100%;
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
pointer-events: none;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
p {
|
|
26
|
+
font-size: 1em;
|
|
27
|
+
}
|
|
28
|
+
|
|
25
29
|
&__bio {
|
|
26
30
|
@include mixins.media( mobile ) {
|
|
27
31
|
flex: 4;
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
margin-bottom: 0.5em;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
p
|
|
18
|
-
font-size: 1em
|
|
17
|
+
p {
|
|
18
|
+
font-size: 1em;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
&.text-size-small {
|
|
@@ -66,9 +66,11 @@
|
|
|
66
66
|
margin-top: 0;
|
|
67
67
|
margin-bottom: 0;
|
|
68
68
|
}
|
|
69
|
+
|
|
69
70
|
&__employment {
|
|
70
71
|
font-size: 0.8em !important;
|
|
71
72
|
}
|
|
73
|
+
|
|
72
74
|
&__social-links {
|
|
73
75
|
display: flex;
|
|
74
76
|
flex-wrap: wrap;
|
|
@@ -277,7 +277,13 @@ export const processStreamlinedElements = ( parentElement = document ) =>
|
|
|
277
277
|
el.classList.remove( 'stripe-payment--invisible' );
|
|
278
278
|
};
|
|
279
279
|
|
|
280
|
-
|
|
280
|
+
// Initialise Stripe once the element is visible.
|
|
281
|
+
const observer = new IntersectionObserver( entries => {
|
|
282
|
+
if ( entries[ 0 ].isIntersecting ) {
|
|
283
|
+
initStripe();
|
|
284
|
+
}
|
|
285
|
+
} );
|
|
286
|
+
observer.observe( el );
|
|
281
287
|
|
|
282
288
|
// Card form unravelling.
|
|
283
289
|
const submitButtonEl: HTMLButtonElement | null = el.querySelector( 'button[type="submit"]' );
|
|
@@ -26,7 +26,6 @@ class WP_REST_Newspack_Articles_Controller extends WP_REST_Controller {
|
|
|
26
26
|
*/
|
|
27
27
|
public function __construct() {
|
|
28
28
|
$this->namespace = 'newspack-blocks/v1';
|
|
29
|
-
$this->rest_base = 'articles';
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
/**
|
|
@@ -38,7 +37,7 @@ class WP_REST_Newspack_Articles_Controller extends WP_REST_Controller {
|
|
|
38
37
|
// Endpoint to get articles on the front-end.
|
|
39
38
|
register_rest_route(
|
|
40
39
|
$this->namespace,
|
|
41
|
-
'/'
|
|
40
|
+
'/articles',
|
|
42
41
|
[
|
|
43
42
|
[
|
|
44
43
|
'methods' => WP_REST_Server::READABLE,
|
|
@@ -341,6 +341,8 @@ class Edit extends Component {
|
|
|
341
341
|
},
|
|
342
342
|
];
|
|
343
343
|
|
|
344
|
+
const handleAttributeChange = key => value => setAttributes( { [ key ]: value } );
|
|
345
|
+
|
|
344
346
|
return (
|
|
345
347
|
<Fragment>
|
|
346
348
|
<PanelBody title={ __( 'Display Settings', 'newspack-blocks' ) } initialOpen={ true }>
|
|
@@ -350,29 +352,19 @@ class Edit extends Component {
|
|
|
350
352
|
setAttributes( { postsToShow: _postsToShow || 1 } )
|
|
351
353
|
}
|
|
352
354
|
specificMode={ specificMode }
|
|
353
|
-
onSpecificModeChange={
|
|
354
|
-
setAttributes( { specificMode: _specificMode } )
|
|
355
|
-
}
|
|
355
|
+
onSpecificModeChange={ handleAttributeChange( 'specificMode' ) }
|
|
356
356
|
specificPosts={ specificPosts }
|
|
357
|
-
onSpecificPostsChange={
|
|
358
|
-
setAttributes( { specificPosts: _specificPosts } )
|
|
359
|
-
}
|
|
357
|
+
onSpecificPostsChange={ handleAttributeChange( 'specificPosts' ) }
|
|
360
358
|
authors={ authors }
|
|
361
|
-
onAuthorsChange={
|
|
359
|
+
onAuthorsChange={ handleAttributeChange( 'authors' ) }
|
|
362
360
|
categories={ categories }
|
|
363
|
-
onCategoriesChange={
|
|
361
|
+
onCategoriesChange={ handleAttributeChange( 'categories' ) }
|
|
364
362
|
tags={ tags }
|
|
365
|
-
onTagsChange={
|
|
366
|
-
setAttributes( { tags: _tags } );
|
|
367
|
-
} }
|
|
363
|
+
onTagsChange={ handleAttributeChange( 'tags' ) }
|
|
368
364
|
tagExclusions={ tagExclusions }
|
|
369
|
-
onTagExclusionsChange={
|
|
370
|
-
setAttributes( { tagExclusions: _tagExclusions } )
|
|
371
|
-
}
|
|
365
|
+
onTagExclusionsChange={ handleAttributeChange( 'tagExclusions' ) }
|
|
372
366
|
categoryExclusions={ categoryExclusions }
|
|
373
|
-
onCategoryExclusionsChange={
|
|
374
|
-
setAttributes( { categoryExclusions: _categoryExclusions } )
|
|
375
|
-
}
|
|
367
|
+
onCategoryExclusionsChange={ handleAttributeChange( 'categoryExclusions' ) }
|
|
376
368
|
postType={ postType }
|
|
377
369
|
/>
|
|
378
370
|
{ postLayout === 'grid' && (
|
|
@@ -380,7 +372,7 @@ class Edit extends Component {
|
|
|
380
372
|
<RangeControl
|
|
381
373
|
label={ __( 'Columns', 'newspack-blocks' ) }
|
|
382
374
|
value={ columns }
|
|
383
|
-
onChange={
|
|
375
|
+
onChange={ handleAttributeChange( 'columns' ) }
|
|
384
376
|
min={ 2 }
|
|
385
377
|
max={ 6 }
|
|
386
378
|
required
|
|
@@ -39,6 +39,11 @@ call_user_func(
|
|
|
39
39
|
'data-hero-candidate' => true,
|
|
40
40
|
'alt' => trim( wp_strip_all_tags( get_the_title( $post_id ) ) ),
|
|
41
41
|
);
|
|
42
|
+
|
|
43
|
+
// This global will be used by the newspack_blocks_filter_hpb_srcset filter.
|
|
44
|
+
global $newspack_blocks_hpb_rendering_context;
|
|
45
|
+
$newspack_blocks_hpb_rendering_context = [ 'attrs' => $attributes ];
|
|
46
|
+
|
|
42
47
|
// If the image position is behind, pass the object-fit setting to maintain styles with AMP.
|
|
43
48
|
if ( 'behind' === $attributes['mediaPosition'] ) {
|
|
44
49
|
$thumbnail_args['object-fit'] = 'cover';
|
|
@@ -83,7 +88,9 @@ call_user_func(
|
|
|
83
88
|
<?php if ( $post_link ) : ?>
|
|
84
89
|
<a href="<?php echo esc_url( $post_link ); ?>" rel="bookmark" tabindex="-1" aria-hidden="true">
|
|
85
90
|
<?php endif; ?>
|
|
86
|
-
|
|
91
|
+
<?php add_filter( 'wp_calculate_image_sizes', 'newspack_blocks_filter_hpb_sizes' ); ?>
|
|
92
|
+
<?php the_post_thumbnail( $image_size, $thumbnail_args ); ?>
|
|
93
|
+
<?php remove_filter( 'wp_calculate_image_sizes', 'newspack_blocks_filter_hpb_sizes' ); ?>
|
|
87
94
|
<?php if ( $post_link ) : ?>
|
|
88
95
|
</a>
|
|
89
96
|
<?php endif; ?>
|
|
@@ -5,6 +5,71 @@
|
|
|
5
5
|
* @package WordPress
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Calculate the maximum width of an image in the Homepage Posts block.
|
|
10
|
+
*/
|
|
11
|
+
function newspack_blocks_hpb_maximum_image_width() {
|
|
12
|
+
$max_width = 0;
|
|
13
|
+
|
|
14
|
+
global $newspack_blocks_hpb_rendering_context;
|
|
15
|
+
if ( isset( $newspack_blocks_hpb_rendering_context['attrs'] ) ) {
|
|
16
|
+
$attributes = $newspack_blocks_hpb_rendering_context['attrs'];
|
|
17
|
+
if ( empty( $attributes ) ) {
|
|
18
|
+
return $max_width;
|
|
19
|
+
}
|
|
20
|
+
if ( isset( $attributes['align'] ) && in_array( $attributes['align'], [ 'full', 'wide' ], true ) ) {
|
|
21
|
+
// For full and wide alignments, the image width is more than 100% of the content width
|
|
22
|
+
// and depends on site width. Can't make assumptions about the site width.
|
|
23
|
+
return $max_width;
|
|
24
|
+
}
|
|
25
|
+
$site_content_width = 1200;
|
|
26
|
+
$is_image_half_width = in_array( $attributes['mediaPosition'], [ 'left', 'right' ], true );
|
|
27
|
+
if ( 'grid' === $attributes['postLayout'] ) {
|
|
28
|
+
$columns = $attributes['columns'];
|
|
29
|
+
if ( $is_image_half_width ) {
|
|
30
|
+
// If the media position is on left or right, the image is 50% of the column width.
|
|
31
|
+
$columns = $columns * 2;
|
|
32
|
+
}
|
|
33
|
+
return $site_content_width / $columns;
|
|
34
|
+
} elseif ( 'list' === $attributes['postLayout'] && $is_image_half_width ) {
|
|
35
|
+
return $site_content_width / 2;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return $max_width;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Set image `sizes` attribute based on the maximum image width.
|
|
43
|
+
*
|
|
44
|
+
* @param array $sizes Sizes for the sizes attribute.
|
|
45
|
+
*/
|
|
46
|
+
function newspack_blocks_filter_hpb_sizes( $sizes ) {
|
|
47
|
+
if ( defined( 'NEWSPACK_DISABLE_HPB_IMAGE_OPTIMISATION' ) && NEWSPACK_DISABLE_HPB_IMAGE_OPTIMISATION ) {
|
|
48
|
+
// Allow disabling the image optimisation per-site.
|
|
49
|
+
return $sizes;
|
|
50
|
+
}
|
|
51
|
+
global $newspack_blocks_hpb_current_theme;
|
|
52
|
+
if ( ! $newspack_blocks_hpb_current_theme ) {
|
|
53
|
+
$newspack_blocks_hpb_current_theme = wp_get_theme()->template;
|
|
54
|
+
}
|
|
55
|
+
if ( stripos( $newspack_blocks_hpb_current_theme, 'newspack' ) === false ) {
|
|
56
|
+
// Bail if not using a Newspack theme – assumptions about the site content width can't be made then.
|
|
57
|
+
return $sizes;
|
|
58
|
+
}
|
|
59
|
+
$max_width = newspack_blocks_hpb_maximum_image_width();
|
|
60
|
+
if ( 0 !== $max_width ) {
|
|
61
|
+
// >=782px is the desktop size – set width as computed.
|
|
62
|
+
$sizes = '(min-width: 782px) ' . $max_width . 'px';
|
|
63
|
+
// Between 600-782px is the tablet size – all columns will collapse to two-column layout
|
|
64
|
+
// (assuming 5% padding on each side and between columns).
|
|
65
|
+
$sizes .= ', (min-width: 600px) 42.5vw';
|
|
66
|
+
// <=600px is the mobile size – columns will stack to full width
|
|
67
|
+
// (assumming 5% side padding on each side).
|
|
68
|
+
$sizes .= ', 90vw';
|
|
69
|
+
}
|
|
70
|
+
return $sizes;
|
|
71
|
+
}
|
|
72
|
+
|
|
8
73
|
/**
|
|
9
74
|
* Renders the `newspack-blocks/homepage-posts` block on server.
|
|
10
75
|
*
|