@automattic/newspack-blocks 1.53.0 → 1.54.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/1783de595f21d427355e559781275222.json.gz +0 -0
- package/.cache/babel/2a75259638488d555bb07fb4f54ddde6.json.gz +0 -0
- package/.cache/babel/{64cb5afd808420a679c0d56e7bdb7949.json.gz → 2dfe70bf8fa9218857f45826e2386a32.json.gz} +0 -0
- package/.cache/babel/2ef414e63685642b486b71a962a5cc09.json.gz +0 -0
- package/.cache/babel/5a94cdb1154d1770a8b0e8cd3145825b.json.gz +0 -0
- package/.cache/babel/678cc0f373236434bf692c16d26ba22f.json.gz +0 -0
- package/.cache/babel/71371fcf9db60a3a1e024991cb3b4bf3.json.gz +0 -0
- package/.cache/babel/725e695c6992a4d01573b83867255ea9.json.gz +0 -0
- package/.cache/babel/94ee8f45c55ecf01005a435ab588333b.json.gz +0 -0
- package/.cache/babel/a5759fe1915229088160b7f5eb8a2e75.json.gz +0 -0
- package/.cache/babel/{bdebf548c146fe858685d50dd0ebd031.json.gz → be383af4530fd3521ee3db177be1bbf4.json.gz} +0 -0
- package/.cache/babel/d298f58c94d221b643c4c009ea0d8002.json.gz +0 -0
- package/.cache/babel/dc7e2d653dbbdbd1939aa281435afa5d.json.gz +0 -0
- package/.cache/babel/f50f27ba4b367318e30e91dbe003e5c8.json.gz +0 -0
- package/CHANGELOG.md +35 -0
- 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/carousel/view.asset.php +1 -1
- package/dist/carousel/view.css +1 -1
- package/dist/carousel/view.js +1 -1
- package/dist/carousel/view.rtl.css +1 -1
- package/dist/donate/view.asset.php +1 -1
- package/dist/donate/view.css +1 -1
- package/dist/donate/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 +5 -5
- package/dist/editor.rtl.css +1 -1
- package/dist/homepage-articles/view.asset.php +1 -1
- package/dist/homepage-articles/view.css +1 -1
- package/dist/homepage-articles/view.rtl.css +1 -1
- package/dist/placeholder_blocks.asset.php +1 -0
- package/dist/placeholder_blocks.js +1 -0
- package/includes/class-newspack-blocks-api.php +14 -12
- package/includes/class-newspack-blocks-patterns.php +3 -2
- package/includes/class-newspack-blocks.php +64 -1
- package/newspack-blocks.php +3 -2
- package/package.json +17 -16
- package/src/block-patterns/homepage-posts-14.php +1 -1
- package/src/block-patterns/homepage-posts-2.php +1 -1
- package/src/block-patterns/homepage-posts-26.php +1 -1
- package/src/block-patterns/homepage-posts-31.php +13 -0
- package/src/block-patterns/homepage-posts-7.php +1 -1
- package/src/block-styles/core/columns/editor.scss +10 -10
- package/src/block-styles/core/columns/view.scss +8 -8
- package/src/block-styles/core/group/editor.scss +3 -3
- package/src/block-styles/core/group/view.scss +3 -3
- package/src/blocks/author-list/editor.scss +1 -1
- package/src/blocks/author-profile/edit.js +29 -6
- package/src/blocks/author-profile/editor.scss +4 -3
- package/src/blocks/author-profile/view.scss +9 -9
- package/src/blocks/carousel/edit.js +31 -15
- package/src/blocks/carousel/editor.scss +1 -1
- package/src/blocks/carousel/view.php +94 -87
- package/src/blocks/carousel/view.scss +52 -13
- package/src/blocks/donate/block.json +49 -0
- package/src/blocks/donate/edit.tsx +569 -0
- package/src/blocks/donate/editor.scss +68 -8
- package/src/blocks/donate/index.js +8 -41
- package/src/blocks/donate/streamlined/style.scss +17 -17
- package/src/blocks/donate/view.php +226 -174
- package/src/blocks/donate/view.scss +97 -114
- package/src/blocks/homepage-articles/edit.js +28 -22
- package/src/blocks/homepage-articles/editor.scss +5 -5
- package/src/blocks/homepage-articles/templates/article.php +78 -73
- package/src/blocks/homepage-articles/utils.ts +1 -3
- package/src/blocks/homepage-articles/view.scss +68 -40
- package/src/blocks/iframe/edit.js +18 -14
- package/src/blocks/iframe/editor.scss +3 -3
- package/src/blocks/video-playlist/editor.scss +2 -2
- package/src/setup/editor.scss +46 -4
- package/src/setup/placeholder-blocks.js +83 -0
- package/src/shared/sass/_mixins.scss +7 -5
- package/src/types/@wordpress/block-editor.d.ts +1 -0
- package/src/types/@wordpress/components.d.ts +1 -0
- package/src/types/{index.ts → index.d.ts} +5 -1
- package/src/types/newspack-components.d.ts +7 -0
- 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/webpack.config.js +4 -0
- package/.cache/babel/07169c73863508b392f15022920bd0b6.json.gz +0 -0
- package/.cache/babel/10faf7c74a89e9aa4d8b9528a654913e.json.gz +0 -0
- package/.cache/babel/3fc03f1e35bc1fde55a903cf25d74d3d.json.gz +0 -0
- package/.cache/babel/553094e2be86910f765ad110c8da1ba1.json.gz +0 -0
- package/.cache/babel/55dd64fbb5126117016b9edff26ca5ee.json.gz +0 -0
- package/.cache/babel/7cbfe1b298fdc2a21add34363b2a6046.json.gz +0 -0
- package/.cache/babel/95c79f7af2e88cb1c48e88f304b1a1fd.json.gz +0 -0
- package/.cache/babel/ac3be6086bb961d3a94ba6ba7728901c.json.gz +0 -0
- package/.cache/babel/c9354785521531ea2b4a9a8c2f526abf.json.gz +0 -0
- package/.cache/babel/ca34d0586d4fbcd06c357ff72bda9a19.json.gz +0 -0
- package/.cache/babel/edb4dcd474dbafd6ea1655b24469e261.json.gz +0 -0
- package/src/blocks/donate/edit.js +0 -587
|
@@ -10,6 +10,7 @@ import { payment } from '@wordpress/icons';
|
|
|
10
10
|
* Internal dependencies
|
|
11
11
|
*/
|
|
12
12
|
import edit from './edit';
|
|
13
|
+
import metadata from './block.json';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Style dependencies - will load in editor
|
|
@@ -17,7 +18,10 @@ import edit from './edit';
|
|
|
17
18
|
import './editor.scss';
|
|
18
19
|
import './view.scss';
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
const { name, attributes, category, supports } = metadata;
|
|
22
|
+
|
|
23
|
+
// Name must be exported separately.
|
|
24
|
+
export { name };
|
|
21
25
|
export const title = __( 'Donate', 'newspack-blocks' );
|
|
22
26
|
|
|
23
27
|
export const settings = {
|
|
@@ -26,7 +30,7 @@ export const settings = {
|
|
|
26
30
|
src: payment,
|
|
27
31
|
foreground: '#36f',
|
|
28
32
|
},
|
|
29
|
-
category
|
|
33
|
+
category,
|
|
30
34
|
keywords: [
|
|
31
35
|
__( 'donate', 'newspack-blocks' ),
|
|
32
36
|
__( 'memberships', 'newspack-blocks' ),
|
|
@@ -45,45 +49,8 @@ export const settings = {
|
|
|
45
49
|
</ExternalLink>
|
|
46
50
|
</>
|
|
47
51
|
),
|
|
48
|
-
attributes
|
|
49
|
-
|
|
50
|
-
type: 'string',
|
|
51
|
-
},
|
|
52
|
-
manual: {
|
|
53
|
-
type: 'boolean',
|
|
54
|
-
},
|
|
55
|
-
suggestedAmounts: {
|
|
56
|
-
type: 'array',
|
|
57
|
-
default: [ 0, 0, 0 ],
|
|
58
|
-
},
|
|
59
|
-
suggestedAmountUntiered: {
|
|
60
|
-
type: 'integer',
|
|
61
|
-
default: 0,
|
|
62
|
-
},
|
|
63
|
-
tiered: {
|
|
64
|
-
type: 'boolean',
|
|
65
|
-
default: true,
|
|
66
|
-
},
|
|
67
|
-
campaign: {
|
|
68
|
-
type: 'string',
|
|
69
|
-
},
|
|
70
|
-
thanksText: {
|
|
71
|
-
type: 'string',
|
|
72
|
-
default: __( 'Your contribution is appreciated.', 'newspack-blocks' ),
|
|
73
|
-
},
|
|
74
|
-
buttonText: {
|
|
75
|
-
type: 'string',
|
|
76
|
-
default: __( 'Donate Now', 'newspack-blocks' ),
|
|
77
|
-
},
|
|
78
|
-
defaultFrequency: {
|
|
79
|
-
type: 'string',
|
|
80
|
-
default: 'month',
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
supports: {
|
|
84
|
-
html: false,
|
|
85
|
-
align: false,
|
|
86
|
-
},
|
|
52
|
+
attributes,
|
|
53
|
+
supports,
|
|
87
54
|
edit,
|
|
88
55
|
save: () => null, // to use view.php
|
|
89
56
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
@
|
|
2
|
-
@
|
|
3
|
-
@
|
|
1
|
+
@use '../../../shared/sass/colors';
|
|
2
|
+
@use '../../../shared/sass/mixins';
|
|
3
|
+
@use '../../../shared/sass/variables';
|
|
4
4
|
|
|
5
5
|
@keyframes loader {
|
|
6
6
|
0% {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
&__card {
|
|
42
|
-
border: 1px solid
|
|
42
|
+
border: 1px solid variables.$color__border;
|
|
43
43
|
border-radius: 3px;
|
|
44
44
|
padding: 0.34rem 0.66rem;
|
|
45
45
|
min-height: 32px;
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
border-radius: 3px;
|
|
61
61
|
font-family: sans-serif;
|
|
62
62
|
|
|
63
|
-
@include media( tablet ) {
|
|
63
|
+
@include mixins.media( tablet ) {
|
|
64
64
|
font-size: 14px;
|
|
65
65
|
line-height: 1.2;
|
|
66
66
|
}
|
|
@@ -92,9 +92,9 @@
|
|
|
92
92
|
|
|
93
93
|
&__messages {
|
|
94
94
|
> div {
|
|
95
|
-
border: 0 solid
|
|
95
|
+
border: 0 solid colors.$color__info;
|
|
96
96
|
border-left-width: 4px;
|
|
97
|
-
font-size:
|
|
97
|
+
font-size: variables.$font__size-sm;
|
|
98
98
|
margin-top: 0.76rem;
|
|
99
99
|
padding: 0.38rem 0.76rem;
|
|
100
100
|
&:empty {
|
|
@@ -103,12 +103,12 @@
|
|
|
103
103
|
padding: 0;
|
|
104
104
|
}
|
|
105
105
|
&.type-error {
|
|
106
|
-
background-color: rgba(
|
|
107
|
-
border-color:
|
|
106
|
+
background-color: rgba( colors.$color__error, 0.075 );
|
|
107
|
+
border-color: colors.$color__error;
|
|
108
108
|
}
|
|
109
109
|
&.type-success {
|
|
110
|
-
background-color: rgba(
|
|
111
|
-
border-color:
|
|
110
|
+
background-color: rgba( colors.$color__success, 0.075 );
|
|
111
|
+
border-color: colors.$color__success;
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
}
|
|
@@ -136,12 +136,12 @@
|
|
|
136
136
|
align-items: flex-end;
|
|
137
137
|
justify-content: space-between;
|
|
138
138
|
flex-wrap: wrap;
|
|
139
|
-
@include media( tablet ) {
|
|
139
|
+
@include mixins.media( tablet ) {
|
|
140
140
|
flex-wrap: nowrap;
|
|
141
141
|
}
|
|
142
142
|
input {
|
|
143
143
|
margin-bottom: 0.5rem;
|
|
144
|
-
@include media( tablet ) {
|
|
144
|
+
@include mixins.media( tablet ) {
|
|
145
145
|
margin-bottom: 0;
|
|
146
146
|
width: 50%;
|
|
147
147
|
&:last-child {
|
|
@@ -153,7 +153,7 @@
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
&__info {
|
|
156
|
-
color:
|
|
156
|
+
color: colors.$color__text-light;
|
|
157
157
|
font-size: 0.7em;
|
|
158
158
|
font-style: italic;
|
|
159
159
|
padding-left: 1.5em;
|
|
@@ -192,7 +192,7 @@
|
|
|
192
192
|
> * {
|
|
193
193
|
margin-top: 10px;
|
|
194
194
|
width: 100%;
|
|
195
|
-
@include media( mobile ) {
|
|
195
|
+
@include mixins.media( mobile ) {
|
|
196
196
|
width: auto;
|
|
197
197
|
}
|
|
198
198
|
}
|
|
@@ -200,7 +200,7 @@
|
|
|
200
200
|
|
|
201
201
|
&__request-button {
|
|
202
202
|
min-width: 190px;
|
|
203
|
-
@include media( mobile ) {
|
|
203
|
+
@include mixins.media( mobile ) {
|
|
204
204
|
margin-right: 1em;
|
|
205
205
|
}
|
|
206
206
|
&--invisible {
|
|
@@ -212,7 +212,7 @@
|
|
|
212
212
|
&__stripe {
|
|
213
213
|
margin: 0.38rem 0.76rem 0.76rem;
|
|
214
214
|
|
|
215
|
-
@include media( tablet ) {
|
|
215
|
+
@include mixins.media( tablet ) {
|
|
216
216
|
margin-left: 1.5rem;
|
|
217
217
|
margin-right: 1.5rem;
|
|
218
218
|
}
|
|
@@ -5,6 +5,41 @@
|
|
|
5
5
|
* @package WordPress
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Renders the frequency selection of the donation form.
|
|
10
|
+
*
|
|
11
|
+
* @param string $frequency_slug Frequency slug.
|
|
12
|
+
* @param string $frequency_name Frequency name.
|
|
13
|
+
* @param number $uid Unique ID.
|
|
14
|
+
* @param array $configuration The donations settings.
|
|
15
|
+
*
|
|
16
|
+
* @return string
|
|
17
|
+
*/
|
|
18
|
+
function newspack_blocks_render_block_donate_frequency_selection( $frequency_slug, $frequency_name, $uid, $configuration ) {
|
|
19
|
+
ob_start();
|
|
20
|
+
?>
|
|
21
|
+
<input
|
|
22
|
+
type='radio'
|
|
23
|
+
value='<?php echo esc_attr( $frequency_slug ); ?>'
|
|
24
|
+
id='newspack-donate-<?php echo esc_attr( $frequency_slug . '-' . $uid ); ?>'
|
|
25
|
+
name='donation_frequency'
|
|
26
|
+
<?php
|
|
27
|
+
checked(
|
|
28
|
+
$configuration['defaultFrequency'],
|
|
29
|
+
$frequency_slug
|
|
30
|
+
);
|
|
31
|
+
?>
|
|
32
|
+
/>
|
|
33
|
+
<label
|
|
34
|
+
for='newspack-donate-<?php echo esc_attr( $frequency_slug . '-' . $uid ); ?>'
|
|
35
|
+
class='donation-frequency-label freq-label'
|
|
36
|
+
>
|
|
37
|
+
<?php echo esc_html( $frequency_name ); ?>
|
|
38
|
+
</label>
|
|
39
|
+
<?php
|
|
40
|
+
return ob_get_clean();
|
|
41
|
+
}
|
|
42
|
+
|
|
8
43
|
/**
|
|
9
44
|
* Renders the footer of the donation form.
|
|
10
45
|
*
|
|
@@ -167,8 +202,8 @@ function newspack_blocks_render_block_donate( $attributes ) {
|
|
|
167
202
|
|
|
168
203
|
Newspack_Blocks::enqueue_view_assets( 'donate' );
|
|
169
204
|
|
|
170
|
-
$
|
|
171
|
-
if ( is_wp_error( $
|
|
205
|
+
$configuration = Newspack\Donations::get_donation_settings();
|
|
206
|
+
if ( is_wp_error( $configuration ) ) {
|
|
172
207
|
return '';
|
|
173
208
|
}
|
|
174
209
|
|
|
@@ -179,30 +214,82 @@ function newspack_blocks_render_block_donate( $attributes ) {
|
|
|
179
214
|
$classname = 'is-style-default';
|
|
180
215
|
}
|
|
181
216
|
|
|
182
|
-
/* If block is in "manual" mode, override certain state properties with values stored in attributes */
|
|
183
|
-
if ( $attributes['manual'] ?? false ) {
|
|
184
|
-
$settings = array_merge( $settings, $attributes );
|
|
185
|
-
}
|
|
186
|
-
|
|
187
217
|
$frequencies = [
|
|
188
218
|
'once' => __( 'One-time', 'newspack-blocks' ),
|
|
189
219
|
'month' => __( 'Monthly', 'newspack-blocks' ),
|
|
190
220
|
'year' => __( 'Annually', 'newspack-blocks' ),
|
|
191
221
|
];
|
|
192
222
|
|
|
193
|
-
|
|
194
|
-
|
|
223
|
+
/* If block is in "manual" mode, override certain state properties with values stored in attributes */
|
|
224
|
+
if ( $attributes['manual'] ?? false ) {
|
|
225
|
+
// Migrate old attributes.
|
|
226
|
+
if ( empty( $attributes['amounts'] ) && isset( $attributes['suggestedAmounts'] ) ) {
|
|
227
|
+
$other_amount = $configuration['amounts']['month'][3];
|
|
228
|
+
if ( isset( $attributes['suggestedAmountUntiered'] ) ) {
|
|
229
|
+
$other_amount = $attributes['suggestedAmountUntiered'];
|
|
230
|
+
}
|
|
231
|
+
$suggested_amounts = $attributes['suggestedAmounts'];
|
|
232
|
+
$multiplied_amounts = [
|
|
233
|
+
$suggested_amounts[0] * 12,
|
|
234
|
+
$suggested_amounts[1] * 12,
|
|
235
|
+
$suggested_amounts[2] * 12,
|
|
236
|
+
$other_amount * 12,
|
|
237
|
+
];
|
|
238
|
+
$attributes['amounts'] = [
|
|
239
|
+
'once' => $multiplied_amounts,
|
|
240
|
+
'month' => [
|
|
241
|
+
$suggested_amounts[0],
|
|
242
|
+
$suggested_amounts[1],
|
|
243
|
+
$suggested_amounts[2],
|
|
244
|
+
$other_amount,
|
|
245
|
+
],
|
|
246
|
+
'year' => $multiplied_amounts,
|
|
247
|
+
];
|
|
248
|
+
}
|
|
249
|
+
if ( isset( $attributes['tiered'] ) ) {
|
|
250
|
+
$configuration['tiered'] = $attributes['tiered'];
|
|
251
|
+
}
|
|
252
|
+
if ( isset( $attributes['amounts'] ) && ! empty( $attributes['amounts'] ) ) {
|
|
253
|
+
$configuration['amounts'] = $attributes['amounts'];
|
|
254
|
+
}
|
|
195
255
|
|
|
196
|
-
|
|
256
|
+
if ( isset( $attributes['disabledFrequencies'] ) ) {
|
|
257
|
+
foreach ( $attributes['disabledFrequencies'] as $frequency_slug => $is_disabled ) {
|
|
258
|
+
if ( $is_disabled ) {
|
|
259
|
+
$configuration['disabledFrequencies'][ $frequency_slug ] = true; }
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
foreach ( array_keys( $frequencies ) as $frequency_slug ) {
|
|
265
|
+
if ( $configuration['disabledFrequencies'][ $frequency_slug ] ) {
|
|
266
|
+
unset( $frequencies[ $frequency_slug ] );
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// Ensure default frequency is valid (not disabled).
|
|
271
|
+
foreach ( array_keys( $configuration['disabledFrequencies'] ) as $frequency_slug ) {
|
|
272
|
+
if ( $configuration['defaultFrequency'] === $frequency_slug && $configuration['disabledFrequencies'][ $frequency_slug ] ) {
|
|
273
|
+
$non_disabled_frequencies = array_keys(
|
|
274
|
+
array_filter(
|
|
275
|
+
$configuration['disabledFrequencies'],
|
|
276
|
+
function ( $item ) {
|
|
277
|
+
return ! $item;
|
|
278
|
+
}
|
|
279
|
+
)
|
|
280
|
+
);
|
|
281
|
+
$configuration['defaultFrequency'] = $non_disabled_frequencies[0];
|
|
282
|
+
}
|
|
283
|
+
}
|
|
197
284
|
|
|
198
|
-
$
|
|
285
|
+
$uid = wp_rand( 10000, 99999 ); // Unique identifier to prevent labels colliding with other instances of Donate block.
|
|
199
286
|
|
|
200
287
|
if ( Newspack_Blocks::is_rendering_streamlined_block() ) {
|
|
201
|
-
$stripe_data
|
|
202
|
-
$currency
|
|
203
|
-
$
|
|
288
|
+
$stripe_data = \Newspack\Stripe_Connection::get_stripe_data();
|
|
289
|
+
$currency = $stripe_data['currency'];
|
|
290
|
+
$configuration_for_frontend = [
|
|
204
291
|
$currency,
|
|
205
|
-
$
|
|
292
|
+
$configuration['currencySymbol'],
|
|
206
293
|
get_bloginfo( 'name' ),
|
|
207
294
|
Newspack\Stripe_Connection::is_currency_zero_decimal( $currency ),
|
|
208
295
|
$stripe_data['location_code'],
|
|
@@ -212,8 +299,22 @@ function newspack_blocks_render_block_donate( $attributes ) {
|
|
|
212
299
|
$stripe_data['usedPublishableKey'],
|
|
213
300
|
];
|
|
214
301
|
} else {
|
|
215
|
-
$
|
|
302
|
+
$configuration_for_frontend = [];
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
$frequencies_count = count( $frequencies );
|
|
306
|
+
$container_classnames = 'wp-block-newspack-blocks-donate wpbnbd ' . $classname . ' wpbnbd-frequencies--' . $frequencies_count;
|
|
307
|
+
|
|
308
|
+
$frequency_padding = '(0.76rem + 1.6em + 1px)';
|
|
309
|
+
switch ( $classname ) {
|
|
310
|
+
case 'is-style-alternate':
|
|
311
|
+
$frequency_padding = '( 1.14rem + 1.6em ) + 8px';
|
|
312
|
+
break;
|
|
313
|
+
case 'is-style-minimal':
|
|
314
|
+
$frequency_padding = '( 0.76rem + 1.6em + 4px )';
|
|
315
|
+
break;
|
|
216
316
|
}
|
|
317
|
+
$frequencies_container_styles = 'padding-top: calc( ' . $frequencies_count . ' * ' . $frequency_padding . ' );';
|
|
217
318
|
|
|
218
319
|
ob_start();
|
|
219
320
|
|
|
@@ -222,201 +323,152 @@ function newspack_blocks_render_block_donate( $attributes ) {
|
|
|
222
323
|
* Each frequency and tier option is a radio input, styled to look like a button.
|
|
223
324
|
* As the radio inputs are checked/unchecked, fields are hidden/displayed using only CSS.
|
|
224
325
|
*/
|
|
225
|
-
if ( ! $
|
|
226
|
-
|
|
326
|
+
if ( ! $configuration['tiered'] ) :
|
|
227
327
|
?>
|
|
228
|
-
<div class="
|
|
229
|
-
<form data-settings="<?php echo esc_html( htmlspecialchars( wp_json_encode( $
|
|
328
|
+
<div class="untiered <?php echo esc_html( $container_classnames ); ?>">
|
|
329
|
+
<form data-settings="<?php echo esc_html( htmlspecialchars( wp_json_encode( $configuration_for_frontend ), ENT_QUOTES, 'UTF-8' ) ); ?>">
|
|
230
330
|
<input type='hidden' name='newspack_donate' value='1' />
|
|
231
331
|
<div class='wp-block-newspack-blocks-donate__options'>
|
|
232
|
-
|
|
233
|
-
<?php
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
<
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
<span class='currency'>
|
|
260
|
-
<?php echo esc_html( $settings['currencySymbol'] ); ?>
|
|
261
|
-
</span>
|
|
262
|
-
<input
|
|
263
|
-
type='number'
|
|
264
|
-
name='donation_value_<?php echo esc_attr( $frequency_slug ); ?>_untiered'
|
|
265
|
-
value='<?php echo esc_attr( $formatted_amount ); ?>'
|
|
266
|
-
id='newspack-<?php echo esc_attr( $frequency_slug . '-' . $uid ); ?>-untiered-input'
|
|
267
|
-
/>
|
|
332
|
+
<div class='wp-block-newspack-blocks-donate__frequencies frequencies' style="<?php echo esc_attr( $frequencies_container_styles ); ?>">
|
|
333
|
+
<?php foreach ( $frequencies as $frequency_slug => $frequency_name ) : ?>
|
|
334
|
+
<?php
|
|
335
|
+
$formatted_amount = $configuration['amounts'][ $frequency_slug ][3];
|
|
336
|
+
?>
|
|
337
|
+
|
|
338
|
+
<div class='wp-block-newspack-blocks-donate__frequency frequency'>
|
|
339
|
+
<?php echo newspack_blocks_render_block_donate_frequency_selection( $frequency_slug, $frequency_name, $uid, $configuration ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
|
340
|
+
<div class='input-container'>
|
|
341
|
+
<label
|
|
342
|
+
class='donate-label'
|
|
343
|
+
for='newspack-<?php echo esc_attr( $frequency_slug . '-' . $uid ); ?>-untiered-input'
|
|
344
|
+
>
|
|
345
|
+
<?php echo esc_html__( 'Donation amount', 'newspack-blocks' ); ?>
|
|
346
|
+
</label>
|
|
347
|
+
<div class='wp-block-newspack-blocks-donate__money-input money-input'>
|
|
348
|
+
<span class='currency'>
|
|
349
|
+
<?php echo esc_html( $configuration['currencySymbol'] ); ?>
|
|
350
|
+
</span>
|
|
351
|
+
<input
|
|
352
|
+
type='number'
|
|
353
|
+
min='0'
|
|
354
|
+
name='donation_value_<?php echo esc_attr( $frequency_slug ); ?>_untiered'
|
|
355
|
+
value='<?php echo esc_attr( $formatted_amount ); ?>'
|
|
356
|
+
id='newspack-<?php echo esc_attr( $frequency_slug . '-' . $uid ); ?>-untiered-input'
|
|
357
|
+
/>
|
|
358
|
+
</div>
|
|
268
359
|
</div>
|
|
269
360
|
</div>
|
|
270
|
-
|
|
271
|
-
|
|
361
|
+
|
|
362
|
+
<?php endforeach; ?>
|
|
363
|
+
</div>
|
|
272
364
|
</div>
|
|
273
|
-
<?php echo $
|
|
365
|
+
<?php echo newspack_blocks_render_block_donate_footer( $attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
|
274
366
|
</form>
|
|
275
367
|
</div>
|
|
368
|
+
|
|
276
369
|
<?php
|
|
277
|
-
|
|
370
|
+
else :
|
|
371
|
+
$suggested_amounts = $configuration['amounts'];
|
|
372
|
+
?>
|
|
278
373
|
|
|
279
|
-
?>
|
|
280
|
-
|
|
281
|
-
<form data-settings="<?php echo esc_html( htmlspecialchars( wp_json_encode( $settings_for_frontend ), ENT_QUOTES, 'UTF-8' ) ); ?>">
|
|
374
|
+
<div class="tiered <?php echo esc_html( $container_classnames ); ?>">
|
|
375
|
+
<form data-settings="<?php echo esc_html( htmlspecialchars( wp_json_encode( $configuration_for_frontend ), ENT_QUOTES, 'UTF-8' ) ); ?>">
|
|
282
376
|
<input type='hidden' name='newspack_donate' value='1' />
|
|
283
377
|
<div class='wp-block-newspack-blocks-donate__options'>
|
|
284
|
-
<div class='wp-block-newspack-blocks-donate__frequencies frequencies'>
|
|
378
|
+
<div class='wp-block-newspack-blocks-donate__frequencies frequencies' style="<?php echo esc_attr( $frequencies_container_styles ); ?>">
|
|
285
379
|
<?php foreach ( $frequencies as $frequency_slug => $frequency_name ) : ?>
|
|
286
380
|
|
|
287
381
|
<div class='wp-block-newspack-blocks-donate__frequency frequency'>
|
|
288
|
-
|
|
289
|
-
type='radio'
|
|
290
|
-
value='<?php echo esc_attr( $frequency_slug ); ?>'
|
|
291
|
-
id='newspack-donate-<?php echo esc_attr( $frequency_slug . '-' . $uid ); ?>'
|
|
292
|
-
name='donation_frequency'
|
|
293
|
-
<?php checked( $selected_frequency, $frequency_slug ); ?>
|
|
294
|
-
/>
|
|
295
|
-
<label
|
|
296
|
-
for='newspack-donate-<?php echo esc_attr( $frequency_slug . '-' . $uid ); ?>'
|
|
297
|
-
class='donation-frequency-label freq-label'
|
|
298
|
-
>
|
|
299
|
-
<?php echo esc_html( $frequency_name ); ?>
|
|
300
|
-
</label>
|
|
301
|
-
|
|
382
|
+
<?php echo newspack_blocks_render_block_donate_frequency_selection( $frequency_slug, $frequency_name, $uid, $configuration ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
|
302
383
|
<div class='wp-block-newspack-blocks-donate__tiers tiers'>
|
|
303
|
-
<?php foreach ( $suggested_amounts as $index => $
|
|
384
|
+
<?php foreach ( $suggested_amounts[ $frequency_slug ] as $index => $amount ) : ?>
|
|
304
385
|
<div class='wp-block-newspack-blocks-donate__tier'>
|
|
305
386
|
<?php
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
387
|
+
if ( 3 === $index ) : // The "other" tier.
|
|
388
|
+
?>
|
|
389
|
+
<input
|
|
390
|
+
type='radio'
|
|
391
|
+
class='other-input'
|
|
392
|
+
name='donation_value_<?php echo esc_attr( $frequency_slug ); ?>'
|
|
393
|
+
value='other'
|
|
394
|
+
id='newspack-tier-<?php echo esc_attr( $frequency_slug . '-' . $uid ); ?>-other'
|
|
395
|
+
/>
|
|
396
|
+
<label
|
|
397
|
+
class='tier-select-label tier-label'
|
|
398
|
+
for='newspack-tier-<?php echo esc_attr( $frequency_slug . '-' . $uid ); ?>-other'
|
|
399
|
+
>
|
|
400
|
+
<?php echo esc_html__( 'Other', 'newspack-blocks' ); ?>
|
|
401
|
+
</label>
|
|
402
|
+
<label
|
|
403
|
+
class='odl'
|
|
404
|
+
for='newspack-tier-<?php echo esc_attr( $frequency_slug . '-' . $uid ); ?>-other-input'
|
|
405
|
+
>
|
|
406
|
+
<?php echo esc_html__( 'Donation amount', 'newspack-blocks' ); ?>
|
|
407
|
+
</label>
|
|
408
|
+
<div class='wp-block-newspack-blocks-donate__money-input money-input'>
|
|
409
|
+
<span class='currency'>
|
|
410
|
+
<?php echo esc_html( $configuration['currencySymbol'] ); ?>
|
|
411
|
+
</span>
|
|
412
|
+
<input
|
|
413
|
+
type='number'
|
|
414
|
+
min='0'
|
|
415
|
+
name='donation_value_<?php echo esc_attr( $frequency_slug ); ?>_other'
|
|
416
|
+
value='<?php echo esc_attr( $amount ); ?>'
|
|
417
|
+
id='newspack-tier-<?php echo esc_attr( $frequency_slug . '-' . $uid ); ?>-other-input'
|
|
418
|
+
/>
|
|
419
|
+
</div>
|
|
420
|
+
<?php
|
|
421
|
+
else :
|
|
422
|
+
?>
|
|
423
|
+
<input
|
|
424
|
+
type='radio'
|
|
425
|
+
name='donation_value_<?php echo esc_attr( $frequency_slug ); ?>'
|
|
426
|
+
value='<?php echo esc_attr( $amount ); ?>'
|
|
427
|
+
id='newspack-tier-<?php echo esc_attr( $frequency_slug . '-' . $uid ); ?>-<?php echo (int) $index; ?>'
|
|
428
|
+
<?php checked( 1, $index ); ?>
|
|
429
|
+
/>
|
|
430
|
+
<label
|
|
431
|
+
class='tier-select-label tier-label'
|
|
432
|
+
for='newspack-tier-<?php echo esc_attr( $frequency_slug . '-' . $uid ); ?>-<?php echo (int) $index; ?>'
|
|
433
|
+
>
|
|
434
|
+
<?php echo esc_html( $configuration['currencySymbol'] . $amount ); ?>
|
|
435
|
+
</label>
|
|
436
|
+
<?php
|
|
437
|
+
endif;
|
|
438
|
+
?>
|
|
322
439
|
</div>
|
|
323
440
|
<?php endforeach; ?>
|
|
324
|
-
|
|
325
|
-
<div class='wp-block-newspack-blocks-donate__tier'>
|
|
326
|
-
<?php $amount = 'year' === $frequency_slug || 'once' === $frequency_slug ? 12 * $suggested_amounts[1] : $suggested_amounts[1]; ?>
|
|
327
|
-
<input
|
|
328
|
-
type='radio'
|
|
329
|
-
class='other-input'
|
|
330
|
-
name='donation_value_<?php echo esc_attr( $frequency_slug ); ?>'
|
|
331
|
-
value='other'
|
|
332
|
-
id='newspack-tier-<?php echo esc_attr( $frequency_slug . '-' . $uid ); ?>-other'
|
|
333
|
-
/>
|
|
334
|
-
<label
|
|
335
|
-
class='tier-select-label tier-label'
|
|
336
|
-
for='newspack-tier-<?php echo esc_attr( $frequency_slug . '-' . $uid ); ?>-other'
|
|
337
|
-
>
|
|
338
|
-
<?php echo esc_html__( 'Other', 'newspack-blocks' ); ?>
|
|
339
|
-
</label>
|
|
340
|
-
<label
|
|
341
|
-
class='other-donate-label odl'
|
|
342
|
-
for='newspack-tier-<?php echo esc_attr( $frequency_slug . '-' . $uid ); ?>-other-input'
|
|
343
|
-
>
|
|
344
|
-
<?php echo esc_html__( 'Donation amount', 'newspack-blocks' ); ?>
|
|
345
|
-
</label>
|
|
346
|
-
<div class='wp-block-newspack-blocks-donate__money-input money-input'>
|
|
347
|
-
<span class='currency'>
|
|
348
|
-
<?php echo esc_html( $settings['currencySymbol'] ); ?>
|
|
349
|
-
</span>
|
|
350
|
-
<input
|
|
351
|
-
type='number'
|
|
352
|
-
name='donation_value_<?php echo esc_attr( $frequency_slug ); ?>_other'
|
|
353
|
-
value='<?php echo esc_attr( $amount ); ?>'
|
|
354
|
-
id='newspack-tier-<?php echo esc_attr( $frequency_slug . '-' . $uid ); ?>-other-input'
|
|
355
|
-
/>
|
|
356
|
-
</div>
|
|
357
|
-
</div>
|
|
358
|
-
|
|
359
441
|
</div>
|
|
360
442
|
</div>
|
|
443
|
+
|
|
361
444
|
<?php endforeach; ?>
|
|
362
445
|
</div>
|
|
363
446
|
</div>
|
|
364
|
-
<?php echo $
|
|
447
|
+
<?php echo newspack_blocks_render_block_donate_footer( $attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
|
365
448
|
</form>
|
|
366
449
|
</div>
|
|
367
|
-
|
|
450
|
+
<?php
|
|
368
451
|
endif;
|
|
369
452
|
|
|
370
|
-
|
|
453
|
+
return apply_filters( 'newspack_blocks_donate_block_html', ob_get_clean(), $attributes );
|
|
371
454
|
}
|
|
372
455
|
|
|
373
456
|
/**
|
|
374
457
|
* Registers the `newspack-blocks/donate` block on server.
|
|
375
458
|
*/
|
|
376
459
|
function newspack_blocks_register_donate() {
|
|
460
|
+
$block_json = json_decode(
|
|
461
|
+
file_get_contents( __DIR__ . '/block.json' ), // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
|
|
462
|
+
true
|
|
463
|
+
);
|
|
464
|
+
|
|
377
465
|
register_block_type(
|
|
378
|
-
'newspack-blocks/
|
|
379
|
-
|
|
380
|
-
'attributes' =>
|
|
381
|
-
'className' => [
|
|
382
|
-
'type' => 'string',
|
|
383
|
-
],
|
|
384
|
-
'manual' => [
|
|
385
|
-
'type' => 'boolean',
|
|
386
|
-
],
|
|
387
|
-
'suggestedAmounts' => [
|
|
388
|
-
'type' => 'array',
|
|
389
|
-
'items' => [
|
|
390
|
-
'type' => 'number',
|
|
391
|
-
],
|
|
392
|
-
'default' => [ 0, 0, 0 ],
|
|
393
|
-
],
|
|
394
|
-
'suggestedAmountUntiered' => [
|
|
395
|
-
'type' => 'number',
|
|
396
|
-
],
|
|
397
|
-
'tiered' => [
|
|
398
|
-
'type' => 'boolean',
|
|
399
|
-
'default' => true,
|
|
400
|
-
],
|
|
401
|
-
'campaign' => [
|
|
402
|
-
'type' => 'string',
|
|
403
|
-
],
|
|
404
|
-
'thanksText' => [
|
|
405
|
-
'type' => 'string',
|
|
406
|
-
'default' => __( 'Your contribution is appreciated.', 'newspack-blocks' ),
|
|
407
|
-
],
|
|
408
|
-
'buttonText' => [
|
|
409
|
-
'type' => 'string',
|
|
410
|
-
'default' => __( 'Donate Now', 'newspack-blocks' ),
|
|
411
|
-
],
|
|
412
|
-
'defaultFrequency' => [
|
|
413
|
-
'type' => 'string',
|
|
414
|
-
'default' => 'month',
|
|
415
|
-
],
|
|
416
|
-
),
|
|
466
|
+
'newspack-blocks/' . $block_json['name'],
|
|
467
|
+
[
|
|
468
|
+
'attributes' => $block_json['attributes'],
|
|
417
469
|
'render_callback' => 'newspack_blocks_render_block_donate',
|
|
418
|
-
'supports' => [],
|
|
419
|
-
|
|
470
|
+
'supports' => $block_json['supports'],
|
|
471
|
+
]
|
|
420
472
|
);
|
|
421
473
|
}
|
|
422
474
|
add_action( 'init', 'newspack_blocks_register_donate' );
|