@automattic/newspack-blocks 1.69.0 → 1.70.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/361f8dd5ae7703fe3972fcd6c5829188.json.gz +0 -0
- package/.cache/babel/6576303929ca1ea8e2c37c6bde278067.json.gz +0 -0
- package/.cache/babel/8bb7b96e12530d769c0fdf208bd68ba2.json.gz +0 -0
- package/.cache/babel/a4f1c74990ed908a9c8973d09c64c685.json.gz +0 -0
- package/.cache/babel/b097ee531eaf61b5821f9c41aaaa369c.json.gz +0 -0
- package/CHANGELOG.md +26 -0
- package/dist/donateStreamlined.asset.php +1 -1
- package/dist/donateStreamlined.js +1 -1
- package/dist/editor.asset.php +1 -1
- package/dist/editor.js +1 -1
- package/includes/class-newspack-blocks.php +59 -18
- package/newspack-blocks.php +2 -2
- package/package.json +5 -5
- package/src/blocks/carousel/edit.js +3 -19
- package/src/blocks/carousel/index.js +1 -1
- package/src/blocks/carousel/view.php +29 -18
- package/src/blocks/homepage-articles/block.json +15 -2
- package/src/blocks/homepage-articles/edit.js +3 -18
- package/src/blocks/homepage-articles/utils.ts +4 -4
- package/src/blocks/homepage-articles/view.php +14 -0
- package/src/components/query-controls.js +50 -32
- package/src/types/index.d.ts +1 -1
- package/vendor/autoload.php +1 -1
- package/vendor/composer/autoload_real.php +4 -4
- package/vendor/composer/autoload_static.php +2 -2
- package/vendor/composer/installed.php +2 -2
- package/.cache/babel/3807c3306deecdbdb91968cb3c978235.json.gz +0 -0
- package/.cache/babel/5ac50f37a9913d9f63c8751f5c415ba4.json.gz +0 -0
- package/.cache/babel/900ca42963bd0a74c1498a6d1212d82f.json.gz +0 -0
- package/.cache/babel/e452902bef688c901938b578c6834c50.json.gz +0 -0
- package/.cache/babel/f7fd26614549b5cbb31416d632c38ccd.json.gz +0 -0
|
@@ -202,6 +202,49 @@ class Newspack_Blocks {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
/**
|
|
206
|
+
* Gets the list of custom taxonomies that will be available for filtering in the blocks
|
|
207
|
+
*
|
|
208
|
+
* @return array Array of custom taxonomies where each taxonomy is an array with slug and label keys.
|
|
209
|
+
*/
|
|
210
|
+
public static function get_custom_taxonomies() {
|
|
211
|
+
$custom_taxonomies = array_map(
|
|
212
|
+
function( $tax ) {
|
|
213
|
+
if ( ! empty( array_intersect( [ 'post', 'page' ], $tax->object_type ) ) ) {
|
|
214
|
+
return [
|
|
215
|
+
'slug' => $tax->name,
|
|
216
|
+
'label' => $tax->label,
|
|
217
|
+
];
|
|
218
|
+
};
|
|
219
|
+
},
|
|
220
|
+
get_taxonomies(
|
|
221
|
+
[
|
|
222
|
+
'public' => true,
|
|
223
|
+
'_builtin' => false,
|
|
224
|
+
'show_in_rest' => true,
|
|
225
|
+
],
|
|
226
|
+
'objects'
|
|
227
|
+
)
|
|
228
|
+
);
|
|
229
|
+
$custom_taxonomies = array_values(
|
|
230
|
+
array_filter(
|
|
231
|
+
$custom_taxonomies,
|
|
232
|
+
function( $tax ) {
|
|
233
|
+
return ! empty( $tax );
|
|
234
|
+
}
|
|
235
|
+
)
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Filters the custom taxonomies that will be available in the Home Page block.
|
|
240
|
+
*
|
|
241
|
+
* By default, on the top of category and tags, will display any public taxonomy applied to post or pages
|
|
242
|
+
*
|
|
243
|
+
* @param array $custom_taxonomies Array of custom taxonomies where each taxonomy is an array with slug and label keys.
|
|
244
|
+
*/
|
|
245
|
+
return apply_filters( 'newspack_blocks_home_page_block_custom_taxonomies', $custom_taxonomies );
|
|
246
|
+
}
|
|
247
|
+
|
|
205
248
|
/**
|
|
206
249
|
* Enqueue block scripts and styles for editor.
|
|
207
250
|
*/
|
|
@@ -230,6 +273,7 @@ class Newspack_Blocks {
|
|
|
230
273
|
'supports_recaptcha' => class_exists( 'Newspack\Recaptcha' ),
|
|
231
274
|
'has_recaptcha' => class_exists( 'Newspack\Recaptcha' ) && \Newspack\Recaptcha::can_use_captcha(),
|
|
232
275
|
'recaptcha_url' => admin_url( 'admin.php?page=newspack-connections-wizard' ),
|
|
276
|
+
'custom_taxonomies' => self::get_custom_taxonomies(),
|
|
233
277
|
];
|
|
234
278
|
|
|
235
279
|
if ( class_exists( 'WP_REST_Newspack_Author_List_Controller' ) ) {
|
|
@@ -242,10 +286,6 @@ class Newspack_Blocks {
|
|
|
242
286
|
$localized_data['author_custom_fields'] = \Newspack\Authors_Custom_Fields::get_custom_fields();
|
|
243
287
|
}
|
|
244
288
|
|
|
245
|
-
if ( class_exists( 'Newspack_Multibranded_Site\Customizations\Theme_Colors' ) ) {
|
|
246
|
-
$localized_data['multibranded_sites_enabled'] = true;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
289
|
wp_localize_script(
|
|
250
290
|
'newspack-blocks-editor',
|
|
251
291
|
'newspack_blocks_data',
|
|
@@ -591,7 +631,7 @@ class Newspack_Blocks {
|
|
|
591
631
|
$authors = isset( $attributes['authors'] ) ? $attributes['authors'] : array();
|
|
592
632
|
$categories = isset( $attributes['categories'] ) ? $attributes['categories'] : array();
|
|
593
633
|
$tags = isset( $attributes['tags'] ) ? $attributes['tags'] : array();
|
|
594
|
-
$
|
|
634
|
+
$custom_taxonomies = isset( $attributes['customTaxonomies'] ) ? $attributes['customTaxonomies'] : array();
|
|
595
635
|
$tag_exclusions = isset( $attributes['tagExclusions'] ) ? $attributes['tagExclusions'] : array();
|
|
596
636
|
$category_exclusions = isset( $attributes['categoryExclusions'] ) ? $attributes['categoryExclusions'] : array();
|
|
597
637
|
$specific_posts = isset( $attributes['specificPosts'] ) ? $attributes['specificPosts'] : array();
|
|
@@ -637,18 +677,19 @@ class Newspack_Blocks {
|
|
|
637
677
|
if ( $category_exclusions && count( $category_exclusions ) ) {
|
|
638
678
|
$args['category__not_in'] = $category_exclusions;
|
|
639
679
|
}
|
|
640
|
-
if (
|
|
641
|
-
|
|
642
|
-
$
|
|
643
|
-
[
|
|
644
|
-
'taxonomy' => '
|
|
680
|
+
if ( ! empty( $custom_taxonomies ) ) {
|
|
681
|
+
foreach ( $custom_taxonomies as $taxonomy ) {
|
|
682
|
+
if ( ! empty( $taxonomy['slug'] ) && ! empty( $taxonomy['terms'] ) ) {
|
|
683
|
+
$args['tax_query'][] = [
|
|
684
|
+
'taxonomy' => $taxonomy['slug'],
|
|
645
685
|
'field' => 'term_id',
|
|
646
|
-
'terms' => $
|
|
686
|
+
'terms' => $taxonomy['terms'],
|
|
647
687
|
'include_children' => false,
|
|
648
|
-
]
|
|
649
|
-
|
|
688
|
+
];
|
|
689
|
+
}
|
|
650
690
|
}
|
|
651
691
|
}
|
|
692
|
+
|
|
652
693
|
$is_co_authors_plus_active = class_exists( 'CoAuthors_Guest_Authors' );
|
|
653
694
|
|
|
654
695
|
if ( $authors && count( $authors ) ) {
|
|
@@ -804,11 +845,11 @@ class Newspack_Blocks {
|
|
|
804
845
|
}
|
|
805
846
|
}
|
|
806
847
|
|
|
807
|
-
|
|
808
|
-
$
|
|
809
|
-
if ( ! empty( $
|
|
810
|
-
foreach ( $
|
|
811
|
-
$classes[] = '
|
|
848
|
+
foreach ( self::get_custom_taxonomies() as $tax ) {
|
|
849
|
+
$terms = get_the_terms( $post_id, $tax['slug'] );
|
|
850
|
+
if ( ! empty( $terms ) ) {
|
|
851
|
+
foreach ( $terms as $term ) {
|
|
852
|
+
$classes[] = $term->taxonomy . '-' . $term->slug;
|
|
812
853
|
}
|
|
813
854
|
}
|
|
814
855
|
}
|
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.70.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.70.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,26 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automattic/newspack-blocks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.70.0",
|
|
4
4
|
"author": "Automattic",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@rushstack/eslint-patch": "^1.3.0",
|
|
7
7
|
"@testing-library/dom": "^8.20.0",
|
|
8
8
|
"@testing-library/user-event": "^14.4.3",
|
|
9
|
-
"@types/lodash": "^4.14.
|
|
9
|
+
"@types/lodash": "^4.14.195",
|
|
10
10
|
"@types/lodash.debounce": "^4.0.7",
|
|
11
11
|
"eslint": "^7.32.0",
|
|
12
12
|
"fetch-mock-jest": "^1.5.1",
|
|
13
|
-
"html-entities": "^2.3.
|
|
13
|
+
"html-entities": "^2.3.4",
|
|
14
14
|
"identity-obj-proxy": "^3.0.0",
|
|
15
15
|
"lint-staged": "^13.2.2",
|
|
16
16
|
"newspack-scripts": "^5.1.0",
|
|
17
17
|
"postcss-scss": "^4.0.6",
|
|
18
18
|
"prettier": "npm:wp-prettier@^2.6.2-beta-1",
|
|
19
|
-
"stylelint": "^15.6.
|
|
19
|
+
"stylelint": "^15.6.3"
|
|
20
20
|
},
|
|
21
21
|
"description": "=== Newspack Blocks === Contributors: (this should be a list of wordpress.org userid's) Donate link: https://example.com/ Tags: comments, spam Requires at least: 4.5 Tested up to: 5.1.1 Stable tag: 0.1.0 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@stripe/stripe-js": "^1.
|
|
23
|
+
"@stripe/stripe-js": "^1.54.0",
|
|
24
24
|
"classnames": "^2.3.2",
|
|
25
25
|
"lodash": "^4.17.21",
|
|
26
26
|
"newspack-components": "^2.1.0",
|
|
@@ -48,16 +48,6 @@ import { postsBlockSelector, postsBlockDispatch, shouldReflow } from '../homepag
|
|
|
48
48
|
// Max number of slides that can be shown at once.
|
|
49
49
|
const MAX_NUMBER_OF_SLIDES = 6;
|
|
50
50
|
|
|
51
|
-
// Check if multi-branded site
|
|
52
|
-
let IS_MULTIBRANDED_SITE;
|
|
53
|
-
if (
|
|
54
|
-
typeof window === 'object' &&
|
|
55
|
-
window.newspack_blocks_data &&
|
|
56
|
-
window.newspack_blocks_data.multibranded_sites_enabled
|
|
57
|
-
) {
|
|
58
|
-
IS_MULTIBRANDED_SITE = true;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
51
|
class Edit extends Component {
|
|
62
52
|
constructor( props ) {
|
|
63
53
|
super( props );
|
|
@@ -160,7 +150,7 @@ class Edit extends Component {
|
|
|
160
150
|
authors,
|
|
161
151
|
autoplay,
|
|
162
152
|
categories,
|
|
163
|
-
|
|
153
|
+
customTaxonomies,
|
|
164
154
|
delay,
|
|
165
155
|
hideControls,
|
|
166
156
|
imageFit,
|
|
@@ -244,13 +234,6 @@ class Edit extends Component {
|
|
|
244
234
|
},
|
|
245
235
|
];
|
|
246
236
|
|
|
247
|
-
const brandProps = IS_MULTIBRANDED_SITE
|
|
248
|
-
? {
|
|
249
|
-
brands,
|
|
250
|
-
onBrandsChange: value => setAttributes( { brands: value } ),
|
|
251
|
-
}
|
|
252
|
-
: '';
|
|
253
|
-
|
|
254
237
|
return (
|
|
255
238
|
<Fragment>
|
|
256
239
|
<div className={ classes } ref={ this.carouselRef }>
|
|
@@ -393,7 +376,8 @@ class Edit extends Component {
|
|
|
393
376
|
onCategoriesChange={ value => setAttributes( { categories: value } ) }
|
|
394
377
|
tags={ tags }
|
|
395
378
|
onTagsChange={ value => setAttributes( { tags: value } ) }
|
|
396
|
-
{
|
|
379
|
+
onCustomTaxonomiesChange={ value => setAttributes( { customTaxonomies: value } ) }
|
|
380
|
+
customTaxonomies={ customTaxonomies }
|
|
397
381
|
specificMode={ specificMode }
|
|
398
382
|
onSpecificModeChange={ _specificMode =>
|
|
399
383
|
setAttributes( { specificMode: _specificMode } )
|
|
@@ -382,82 +382,93 @@ function newspack_blocks_register_carousel() {
|
|
|
382
382
|
'newspack_blocks_block_args',
|
|
383
383
|
array(
|
|
384
384
|
'attributes' => array(
|
|
385
|
-
'className'
|
|
385
|
+
'className' => array(
|
|
386
386
|
'type' => 'string',
|
|
387
387
|
),
|
|
388
|
-
'postsToShow'
|
|
388
|
+
'postsToShow' => array(
|
|
389
389
|
'type' => 'integer',
|
|
390
390
|
'default' => 3,
|
|
391
391
|
),
|
|
392
|
-
'authors'
|
|
392
|
+
'authors' => array(
|
|
393
393
|
'type' => 'array',
|
|
394
394
|
'default' => array(),
|
|
395
395
|
'items' => array(
|
|
396
396
|
'type' => 'integer',
|
|
397
397
|
),
|
|
398
398
|
),
|
|
399
|
-
'categories'
|
|
399
|
+
'categories' => array(
|
|
400
400
|
'type' => 'array',
|
|
401
401
|
'default' => array(),
|
|
402
402
|
'items' => array(
|
|
403
403
|
'type' => 'integer',
|
|
404
404
|
),
|
|
405
405
|
),
|
|
406
|
-
'tags'
|
|
406
|
+
'tags' => array(
|
|
407
407
|
'type' => 'array',
|
|
408
408
|
'default' => array(),
|
|
409
409
|
'items' => array(
|
|
410
410
|
'type' => 'integer',
|
|
411
411
|
),
|
|
412
412
|
),
|
|
413
|
-
'
|
|
413
|
+
'customTaxonomies' => array(
|
|
414
414
|
'type' => 'array',
|
|
415
415
|
'default' => array(),
|
|
416
416
|
'items' => array(
|
|
417
|
-
'type'
|
|
417
|
+
'type' => 'object',
|
|
418
|
+
'properties' => array(
|
|
419
|
+
'slug' => array(
|
|
420
|
+
'type' => 'string',
|
|
421
|
+
),
|
|
422
|
+
'terms' => array(
|
|
423
|
+
'type' => 'array',
|
|
424
|
+
'items' => array(
|
|
425
|
+
'type' => 'integer',
|
|
426
|
+
),
|
|
427
|
+
),
|
|
428
|
+
),
|
|
418
429
|
),
|
|
419
430
|
),
|
|
420
|
-
'autoplay'
|
|
431
|
+
'autoplay' => array(
|
|
421
432
|
'type' => 'boolean',
|
|
422
433
|
'default' => false,
|
|
423
434
|
),
|
|
424
|
-
'delay'
|
|
435
|
+
'delay' => array(
|
|
425
436
|
'type' => 'integer',
|
|
426
437
|
'default' => 5,
|
|
427
438
|
),
|
|
428
|
-
'showAuthor'
|
|
439
|
+
'showAuthor' => array(
|
|
429
440
|
'type' => 'boolean',
|
|
430
441
|
'default' => true,
|
|
431
442
|
),
|
|
432
|
-
'showAvatar'
|
|
443
|
+
'showAvatar' => array(
|
|
433
444
|
'type' => 'boolean',
|
|
434
445
|
'default' => true,
|
|
435
446
|
),
|
|
436
|
-
'showCategory'
|
|
447
|
+
'showCategory' => array(
|
|
437
448
|
'type' => 'boolean',
|
|
438
449
|
'default' => false,
|
|
439
450
|
),
|
|
440
|
-
'showDate'
|
|
451
|
+
'showDate' => array(
|
|
441
452
|
'type' => 'boolean',
|
|
442
453
|
'default' => true,
|
|
443
454
|
),
|
|
444
|
-
'imageFit'
|
|
455
|
+
'imageFit' => array(
|
|
445
456
|
'type' => 'string',
|
|
446
457
|
'default' => 'cover',
|
|
447
458
|
),
|
|
448
|
-
'showTitle'
|
|
459
|
+
'showTitle' => array(
|
|
449
460
|
'type' => 'boolean',
|
|
450
461
|
'default' => true,
|
|
451
462
|
),
|
|
452
|
-
'slidesPerView'
|
|
463
|
+
'slidesPerView' => array(
|
|
453
464
|
'type' => 'number',
|
|
454
465
|
'default' => 1,
|
|
455
466
|
),
|
|
456
|
-
'hideControls'
|
|
467
|
+
'hideControls' => array(
|
|
457
468
|
'type' => 'boolean',
|
|
458
469
|
'default' => false,
|
|
459
470
|
),
|
|
460
|
-
'aspectRatio'
|
|
471
|
+
'aspectRatio' => array(
|
|
461
472
|
'type' => 'number',
|
|
462
473
|
'default' => 0.75,
|
|
463
474
|
),
|
|
@@ -105,10 +105,23 @@
|
|
|
105
105
|
"default": [],
|
|
106
106
|
"items": { "type": "integer" }
|
|
107
107
|
},
|
|
108
|
-
"
|
|
108
|
+
"customTaxonomies": {
|
|
109
109
|
"type": "array",
|
|
110
110
|
"default": [],
|
|
111
|
-
"items": {
|
|
111
|
+
"items": {
|
|
112
|
+
"type": "object",
|
|
113
|
+
"properties": {
|
|
114
|
+
"slug": {
|
|
115
|
+
"type": "string"
|
|
116
|
+
},
|
|
117
|
+
"terms": {
|
|
118
|
+
"type": "array",
|
|
119
|
+
"items": {
|
|
120
|
+
"type": "integer"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
112
125
|
},
|
|
113
126
|
"tagExclusions": {
|
|
114
127
|
"type": "array",
|
|
@@ -72,15 +72,6 @@ if (
|
|
|
72
72
|
IS_SUBTITLE_SUPPORTED_IN_THEME = true;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
let IS_MULTIBRANDED_SITE;
|
|
76
|
-
if (
|
|
77
|
-
typeof window === 'object' &&
|
|
78
|
-
window.newspack_blocks_data &&
|
|
79
|
-
window.newspack_blocks_data.multibranded_sites_enabled
|
|
80
|
-
) {
|
|
81
|
-
IS_MULTIBRANDED_SITE = true;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
75
|
const landscapeIcon = (
|
|
85
76
|
<SVG xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
|
86
77
|
<Path
|
|
@@ -275,7 +266,7 @@ class Edit extends Component {
|
|
|
275
266
|
specificPosts,
|
|
276
267
|
postsToShow,
|
|
277
268
|
categories,
|
|
278
|
-
|
|
269
|
+
customTaxonomies,
|
|
279
270
|
columns,
|
|
280
271
|
colGap,
|
|
281
272
|
postType,
|
|
@@ -352,13 +343,6 @@ class Edit extends Component {
|
|
|
352
343
|
|
|
353
344
|
const handleAttributeChange = key => value => setAttributes( { [ key ]: value } );
|
|
354
345
|
|
|
355
|
-
const brandProps = IS_MULTIBRANDED_SITE
|
|
356
|
-
? {
|
|
357
|
-
brands,
|
|
358
|
-
onBrandsChange: handleAttributeChange( 'brands' ),
|
|
359
|
-
}
|
|
360
|
-
: '';
|
|
361
|
-
|
|
362
346
|
return (
|
|
363
347
|
<Fragment>
|
|
364
348
|
<PanelBody title={ __( 'Display Settings', 'newspack-blocks' ) } initialOpen={ true }>
|
|
@@ -377,7 +361,8 @@ class Edit extends Component {
|
|
|
377
361
|
onCategoriesChange={ handleAttributeChange( 'categories' ) }
|
|
378
362
|
tags={ tags }
|
|
379
363
|
onTagsChange={ handleAttributeChange( 'tags' ) }
|
|
380
|
-
{
|
|
364
|
+
onCustomTaxonomiesChange={ handleAttributeChange( 'customTaxonomies' ) }
|
|
365
|
+
customTaxonomies={ customTaxonomies }
|
|
381
366
|
tagExclusions={ tagExclusions }
|
|
382
367
|
onTagExclusionsChange={ handleAttributeChange( 'tagExclusions' ) }
|
|
383
368
|
categoryExclusions={ categoryExclusions }
|
|
@@ -29,7 +29,7 @@ const POST_QUERY_ATTRIBUTES = [
|
|
|
29
29
|
'categories',
|
|
30
30
|
'excerptLength',
|
|
31
31
|
'tags',
|
|
32
|
-
'
|
|
32
|
+
'customTaxonomies',
|
|
33
33
|
'showExcerpt',
|
|
34
34
|
'specificPosts',
|
|
35
35
|
'specificMode',
|
|
@@ -47,7 +47,7 @@ type HomepageArticlesAttributes = {
|
|
|
47
47
|
postType: PostType[];
|
|
48
48
|
showExcerpt: boolean;
|
|
49
49
|
tags: TagId[];
|
|
50
|
-
|
|
50
|
+
customTaxonomies: Taxonomy[];
|
|
51
51
|
specificPosts: string[];
|
|
52
52
|
specificMode: boolean;
|
|
53
53
|
tagExclusions: TagId[];
|
|
@@ -91,7 +91,7 @@ export const queryCriteriaFromAttributes = ( attributes: Block[ 'attributes' ] )
|
|
|
91
91
|
postType,
|
|
92
92
|
showExcerpt,
|
|
93
93
|
tags,
|
|
94
|
-
|
|
94
|
+
customTaxonomies,
|
|
95
95
|
specificPosts = [],
|
|
96
96
|
specificMode,
|
|
97
97
|
tagExclusions,
|
|
@@ -115,7 +115,7 @@ export const queryCriteriaFromAttributes = ( attributes: Block[ 'attributes' ] )
|
|
|
115
115
|
tags,
|
|
116
116
|
tagExclusions,
|
|
117
117
|
categoryExclusions,
|
|
118
|
-
|
|
118
|
+
customTaxonomies,
|
|
119
119
|
postType,
|
|
120
120
|
includedPostStatuses,
|
|
121
121
|
},
|
|
@@ -139,6 +139,20 @@ function newspack_blocks_render_block_homepage_articles( $attributes ) {
|
|
|
139
139
|
if ( '' !== $attributes['customTextColor'] ) {
|
|
140
140
|
$styles = 'color: ' . $attributes['customTextColor'] . ';';
|
|
141
141
|
}
|
|
142
|
+
|
|
143
|
+
// Handle custom taxonomies.
|
|
144
|
+
if ( isset( $attributes['customTaxonomies'] ) ) {
|
|
145
|
+
$custom_taxes = $attributes['customTaxonomies'];
|
|
146
|
+
unset( $attributes['customTaxonomies'] );
|
|
147
|
+
if ( is_array( $custom_taxes ) && ! empty( $custom_taxes ) ) {
|
|
148
|
+
foreach ( $custom_taxes as $tax ) {
|
|
149
|
+
if ( ! empty( $tax['slug'] ) && ! empty( $tax['terms'] ) ) {
|
|
150
|
+
$attributes[ $tax['slug'] ] = $tax['terms'];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
142
156
|
$articles_rest_url = add_query_arg(
|
|
143
157
|
array_merge(
|
|
144
158
|
array_map(
|
|
@@ -16,8 +16,7 @@ import AutocompleteTokenField from './autocomplete-tokenfield';
|
|
|
16
16
|
const getCategoryTitle = category =>
|
|
17
17
|
decodeEntities( category.name ) || __( '(no title)', 'newspack-blocks' );
|
|
18
18
|
|
|
19
|
-
const
|
|
20
|
-
decodeEntities( brand.name ) || __( '(no title)', 'newspack-blocks' );
|
|
19
|
+
const getTermTitle = term => decodeEntities( term.name ) || __( '(no title)', 'newspack-blocks' );
|
|
21
20
|
|
|
22
21
|
class QueryControls extends Component {
|
|
23
22
|
state = {
|
|
@@ -169,47 +168,47 @@ class QueryControls extends Component {
|
|
|
169
168
|
} );
|
|
170
169
|
};
|
|
171
170
|
|
|
172
|
-
|
|
171
|
+
fetchCustomTaxonomiesSuggestions = ( taxSlug, search ) => {
|
|
173
172
|
return apiFetch( {
|
|
174
|
-
path: addQueryArgs(
|
|
173
|
+
path: addQueryArgs( `/wp/v2/${ taxSlug }`, {
|
|
175
174
|
search,
|
|
176
175
|
per_page: 20,
|
|
177
176
|
_fields: 'id,name,parent',
|
|
178
177
|
orderby: 'count',
|
|
179
178
|
order: 'desc',
|
|
180
179
|
} ),
|
|
181
|
-
} ).then(
|
|
180
|
+
} ).then( terms =>
|
|
182
181
|
Promise.all(
|
|
183
|
-
|
|
184
|
-
if (
|
|
182
|
+
terms.map( term => {
|
|
183
|
+
if ( term.parent > 0 ) {
|
|
185
184
|
return apiFetch( {
|
|
186
|
-
path: addQueryArgs( `/wp/v2
|
|
185
|
+
path: addQueryArgs( `/wp/v2/${ taxSlug }/${ term.parent }`, {
|
|
187
186
|
_fields: 'name',
|
|
188
187
|
} ),
|
|
189
|
-
} ).then(
|
|
190
|
-
value:
|
|
191
|
-
label: `${
|
|
188
|
+
} ).then( parentTerm => ( {
|
|
189
|
+
value: term.id,
|
|
190
|
+
label: `${ getTermTitle( term ) } – ${ getTermTitle( parentTerm ) }`,
|
|
192
191
|
} ) );
|
|
193
192
|
}
|
|
194
193
|
return Promise.resolve( {
|
|
195
|
-
value:
|
|
196
|
-
label:
|
|
194
|
+
value: term.id,
|
|
195
|
+
label: getTermTitle( term ),
|
|
197
196
|
} );
|
|
198
197
|
} )
|
|
199
198
|
)
|
|
200
199
|
);
|
|
201
200
|
};
|
|
202
|
-
|
|
201
|
+
fetchSavedCustomTaxonomies = ( taxSlug, termIDs ) => {
|
|
203
202
|
return apiFetch( {
|
|
204
|
-
path: addQueryArgs(
|
|
203
|
+
path: addQueryArgs( `/wp/v2/${ taxSlug }`, {
|
|
205
204
|
per_page: 100,
|
|
206
205
|
_fields: 'id,name',
|
|
207
|
-
include:
|
|
206
|
+
include: termIDs.join( ',' ),
|
|
208
207
|
} ),
|
|
209
|
-
} ).then( function (
|
|
210
|
-
return
|
|
211
|
-
value:
|
|
212
|
-
label: decodeEntities(
|
|
208
|
+
} ).then( function ( terms ) {
|
|
209
|
+
return terms.map( term => ( {
|
|
210
|
+
value: term.id,
|
|
211
|
+
label: decodeEntities( term.name ) || __( '(no title)', 'newspack-blocks' ),
|
|
213
212
|
} ) );
|
|
214
213
|
} );
|
|
215
214
|
};
|
|
@@ -226,8 +225,8 @@ class QueryControls extends Component {
|
|
|
226
225
|
onCategoriesChange,
|
|
227
226
|
tags,
|
|
228
227
|
onTagsChange,
|
|
229
|
-
|
|
230
|
-
|
|
228
|
+
customTaxonomies,
|
|
229
|
+
onCustomTaxonomiesChange,
|
|
231
230
|
tagExclusions,
|
|
232
231
|
onTagExclusionsChange,
|
|
233
232
|
categoryExclusions,
|
|
@@ -236,6 +235,19 @@ class QueryControls extends Component {
|
|
|
236
235
|
} = this.props;
|
|
237
236
|
const { showAdvancedFilters } = this.state;
|
|
238
237
|
|
|
238
|
+
const registeredCustomTaxonomies = window.newspack_blocks_data?.custom_taxonomies;
|
|
239
|
+
|
|
240
|
+
const customTaxonomiesPrepareChange = ( taxSlug, value ) => {
|
|
241
|
+
let newValue = customTaxonomies.filter( tax => tax.slug !== taxSlug );
|
|
242
|
+
newValue = [ ...newValue, { slug: taxSlug, terms: value } ];
|
|
243
|
+
onCustomTaxonomiesChange( newValue );
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
const getTermsOfCustomTaxonomy = taxSlug => {
|
|
247
|
+
const tax = customTaxonomies.find( taxObj => taxObj.slug === taxSlug );
|
|
248
|
+
return tax ? tax.terms : [];
|
|
249
|
+
};
|
|
250
|
+
|
|
239
251
|
return (
|
|
240
252
|
<>
|
|
241
253
|
{ enableSpecific && (
|
|
@@ -287,15 +299,21 @@ class QueryControls extends Component {
|
|
|
287
299
|
label={ __( 'Tags', 'newspack-blocks' ) }
|
|
288
300
|
/>
|
|
289
301
|
) }
|
|
290
|
-
{
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
302
|
+
{ onCustomTaxonomiesChange &&
|
|
303
|
+
registeredCustomTaxonomies.map( tax => (
|
|
304
|
+
<AutocompleteTokenField
|
|
305
|
+
key={ `${ customTaxonomies[ tax.slug ] }-selector` }
|
|
306
|
+
tokens={ getTermsOfCustomTaxonomy( tax.slug ) }
|
|
307
|
+
onChange={ value => {
|
|
308
|
+
customTaxonomiesPrepareChange( tax.slug, value );
|
|
309
|
+
} }
|
|
310
|
+
fetchSuggestions={ search =>
|
|
311
|
+
this.fetchCustomTaxonomiesSuggestions( tax.slug, search )
|
|
312
|
+
}
|
|
313
|
+
fetchSavedInfo={ termIds => this.fetchSavedCustomTaxonomies( tax.slug, termIds ) }
|
|
314
|
+
label={ tax.label }
|
|
315
|
+
/>
|
|
316
|
+
) ) }
|
|
299
317
|
{ onTagExclusionsChange && (
|
|
300
318
|
<p>
|
|
301
319
|
<Button
|
|
@@ -343,7 +361,7 @@ QueryControls.defaultProps = {
|
|
|
343
361
|
authors: [],
|
|
344
362
|
categories: [],
|
|
345
363
|
tags: [],
|
|
346
|
-
|
|
364
|
+
customTaxonomies: [],
|
|
347
365
|
tagExclusions: [],
|
|
348
366
|
};
|
|
349
367
|
|
package/src/types/index.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ declare global {
|
|
|
28
28
|
type PostId = number;
|
|
29
29
|
type CategoryId = number;
|
|
30
30
|
type TagId = number;
|
|
31
|
-
type
|
|
31
|
+
type Taxonomy = { slug: string, terms: number[] }[];
|
|
32
32
|
type AuthorId = number;
|
|
33
33
|
|
|
34
34
|
type PostType = { name: string; slug: string; supports: { newspack_blocks: boolean } };
|
package/vendor/autoload.php
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// autoload_real.php @generated by Composer
|
|
4
4
|
|
|
5
|
-
class
|
|
5
|
+
class ComposerAutoloaderInit38e1831bc3238b056046f21415de1ef9
|
|
6
6
|
{
|
|
7
7
|
private static $loader;
|
|
8
8
|
|
|
@@ -22,12 +22,12 @@ class ComposerAutoloaderInitf29693c46abc4c2490d10d0fd49977ef
|
|
|
22
22
|
return self::$loader;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
spl_autoload_register(array('
|
|
25
|
+
spl_autoload_register(array('ComposerAutoloaderInit38e1831bc3238b056046f21415de1ef9', 'loadClassLoader'), true, true);
|
|
26
26
|
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
|
27
|
-
spl_autoload_unregister(array('
|
|
27
|
+
spl_autoload_unregister(array('ComposerAutoloaderInit38e1831bc3238b056046f21415de1ef9', 'loadClassLoader'));
|
|
28
28
|
|
|
29
29
|
require __DIR__ . '/autoload_static.php';
|
|
30
|
-
call_user_func(\Composer\Autoload\
|
|
30
|
+
call_user_func(\Composer\Autoload\ComposerStaticInit38e1831bc3238b056046f21415de1ef9::getInitializer($loader));
|
|
31
31
|
|
|
32
32
|
$loader->register(true);
|
|
33
33
|
|