Skip to content

Commit 13185a5

Browse files
authored
Merge pull request #541 from Automattic/master
Release 30/06/2020
2 parents 4427bf6 + 68089aa commit 13185a5

File tree

8 files changed

+47
-14
lines changed

8 files changed

+47
-14
lines changed

class-newspack-blocks.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ function ( $acc, $block ) use ( $block_name ) {
367367
}
368368
$args['post__not_in'] = array_merge(
369369
$args['post__not_in'] ?? [],
370-
array_keys( $newspack_blocks_post_id )
370+
array_keys( $newspack_blocks_post_id ),
371+
get_the_ID() ? [ get_the_ID() ] : []
371372
);
372373
if ( $authors && count( $authors ) ) {
373374
$args['author__in'] = $authors;

src/blocks/donate/edit.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
TextControl,
1919
ToggleControl,
2020
} from '@wordpress/components';
21+
import { RichText } from '@wordpress/block-editor';
2122

2223
class Edit extends Component {
2324
constructor( props ) {
@@ -141,7 +142,8 @@ class Edit extends Component {
141142
}
142143

143144
renderUntieredForm() {
144-
const { className } = this.props;
145+
const { attributes, className, setAttributes } = this.props;
146+
const { buttonText } = attributes;
145147
const { uid } = this.state;
146148
const { currencySymbol, customDonationAmounts, selectedFrequency } = this.blockData();
147149

@@ -196,15 +198,21 @@ class Edit extends Component {
196198
{ __( 'Your contribution is appreciated.', 'newspack-blocks' ) }
197199
</p>
198200
<button type="submit" onClick={ evt => evt.preventDefault() }>
199-
{ __( 'Donate now!', 'newspack-blocks' ) }
201+
<RichText
202+
onChange={ value => setAttributes( { buttonText: value } ) }
203+
placeholder={ __( 'Button text…', 'newspack-blocks' ) }
204+
value={ buttonText }
205+
tagName="span"
206+
/>
200207
</button>
201208
</form>
202209
</div>
203210
);
204211
}
205212

206213
renderTieredForm() {
207-
const { className } = this.props;
214+
const { attributes, className, setAttributes } = this.props;
215+
const { buttonText } = attributes;
208216
const { uid } = this.state;
209217
const {
210218
activeTier,
@@ -301,7 +309,12 @@ class Edit extends Component {
301309
{ __( 'Your contribution is appreciated.', 'newspack-blocks' ) }
302310
</p>
303311
<button type="submit" onClick={ evt => evt.preventDefault() }>
304-
{ __( 'Donate now!', 'newspack-blocks' ) }
312+
<RichText
313+
onChange={ value => setAttributes( { buttonText: value } ) }
314+
placeholder={ __( 'Button text…', 'newspack-blocks' ) }
315+
value={ buttonText }
316+
tagName="span"
317+
/>
305318
</button>
306319
</form>
307320
</div>

src/blocks/donate/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ export const settings = {
5858
campaign: {
5959
type: 'string',
6060
},
61+
buttonText: {
62+
type: 'string',
63+
default: __( 'Donate now!', 'newspack-blocks' ),
64+
},
6165
},
6266
supports: {
6367
html: false,

src/blocks/donate/view.php

+13-5
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ function newspack_blocks_render_block_donate( $attributes ) {
4040

4141
$campaign = $attributes['campaign'] ?? false;
4242

43-
$uid = rand(); // Unique identifier to prevent labels colliding with other instances of Donate block.
43+
$uid = wp_rand( 10000, 99999 ); // Unique identifier to prevent labels colliding with other instances of Donate block.
44+
45+
$button_text = $attributes['buttonText'];
4446

4547
ob_start();
4648

@@ -102,7 +104,7 @@ class='donate-label'
102104
<?php echo esc_html__( 'Your contribution is appreciated.', 'newspack-blocks' ); ?>
103105
</p>
104106
<button type='submit'>
105-
<?php echo esc_html__( 'Donate now!', 'newspack-blocks' ); ?>
107+
<?php echo wp_kses_post( $button_text ); ?>
106108
</button>
107109
<?php if ( $campaign ) : ?>
108110
<input type='hidden' name='campaign' value='<?php echo esc_attr( $campaign ); ?>' />
@@ -202,15 +204,14 @@ class='other-donate-label'
202204
<?php echo esc_html__( 'Your contribution is appreciated.', 'newspack-blocks' ); ?>
203205
</p>
204206
<button type='submit'>
205-
<?php echo esc_html__( 'Donate now!', 'newspack-blocks' ); ?>
207+
<?php echo wp_kses_post( $button_text ); ?>
206208
</button>
207209
<?php if ( $campaign ) : ?>
208210
<input type='hidden' name='campaign' value='<?php echo esc_attr( $campaign ); ?>' />
209211
<?php endif; ?>
210212
</form>
211213
</div>
212214
<?php
213-
214215
endif;
215216

216217
return apply_filters( 'newspack_blocks_donate_block_html', ob_get_clean() );
@@ -232,6 +233,9 @@ function newspack_blocks_register_donate() {
232233
],
233234
'suggestedAmounts' => [
234235
'type' => 'array',
236+
'items' => [
237+
'type' => 'integer',
238+
],
235239
'default' => [ 0, 0, 0 ],
236240
],
237241
'suggestedAmountUntiered' => [
@@ -242,8 +246,12 @@ function newspack_blocks_register_donate() {
242246
'default' => true,
243247
],
244248
'campaign' => [
249+
'type' => 'string',
250+
],
251+
'buttonText' => [
245252
'type' => 'string',
246-
]
253+
'default' => __( 'Donate now!', 'newspack-blocks' ),
254+
],
247255
),
248256
'render_callback' => 'newspack_blocks_render_block_donate',
249257
)

src/blocks/homepage-articles/store.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ const createFetchPostsSaga = blockName => {
117117
yield delay( 300 );
118118

119119
const { getBlocks } = select( 'core/block-editor' );
120+
const { getCurrentPostId } = select( 'core/editor' );
120121

121122
yield put( { type: 'DISABLE_UI' } );
122123

@@ -130,7 +131,7 @@ const createFetchPostsSaga = blockName => {
130131
return acc;
131132
}, [] );
132133

133-
let exclude = specificPostsId;
134+
let exclude = [ ...specificPostsId, getCurrentPostId() ];
134135
while ( blockQueries.length ) {
135136
const nextBlock = blockQueries.shift();
136137
nextBlock.postsQuery.exclude = exclude;

src/blocks/homepage-articles/view.js

+6
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ function getRenderedPostsIds() {
108108
);
109109
const postIds = Array.from( postEls ).map( el => el.getAttribute( 'data-post-id' ) );
110110

111+
postIds.push(
112+
document
113+
.querySelector( '.wp-block-newspack-blocks-homepage-articles > div[data-current-post-id]' )
114+
.getAttribute( 'data-current-post-id' )
115+
);
116+
111117
return [ ...new Set( postIds ) ]; // Make values unique with Set
112118
}
113119

src/blocks/homepage-articles/view.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function( $attribute ) {
111111
class="<?php echo esc_attr( $classes ); ?>"
112112
style="<?php echo esc_attr( $styles ); ?>"
113113
>
114-
<div data-posts>
114+
<div data-posts data-current-post-id="<?php the_ID(); ?>">
115115
<?php if ( '' !== $attributes['sectionHeader'] ) : ?>
116116
<h2 class="article-section-title">
117117
<span><?php echo wp_kses_post( $attributes['sectionHeader'] ); ?></span>
@@ -261,7 +261,7 @@ function newspack_blocks_inject_amp_state() {
261261
if ( ! $newspack_blocks_post_id || ! count( $newspack_blocks_post_id ) ) {
262262
return;
263263
}
264-
$post_ids = implode( ', ', array_keys( $newspack_blocks_post_id ) );
264+
$post_ids = implode( ', ', array_merge( array_keys( $newspack_blocks_post_id ), [ get_the_ID() ] ) );
265265
ob_start();
266266
?>
267267
<amp-state id='newspackHomepagePosts'>

src/blocks/homepage-articles/view.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@
329329
display: none;
330330
}
331331

332-
button {
332+
> button {
333333
margin-top: 1em;
334334
}
335335

0 commit comments

Comments
 (0)