Skip to content

Commit

Permalink
feat: editable donate button text (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jefferson Rabb authored Jun 25, 2020
1 parent af31efe commit 6261e3f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
21 changes: 17 additions & 4 deletions src/blocks/donate/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
TextControl,
ToggleControl,
} from '@wordpress/components';
import { RichText } from '@wordpress/block-editor';

class Edit extends Component {
constructor( props ) {
Expand Down Expand Up @@ -141,7 +142,8 @@ class Edit extends Component {
}

renderUntieredForm() {
const { className } = this.props;
const { attributes, className, setAttributes } = this.props;
const { buttonText } = attributes;
const { uid } = this.state;
const { currencySymbol, customDonationAmounts, selectedFrequency } = this.blockData();

Expand Down Expand Up @@ -196,15 +198,21 @@ class Edit extends Component {
{ __( 'Your contribution is appreciated.', 'newspack-blocks' ) }
</p>
<button type="submit" onClick={ evt => evt.preventDefault() }>
{ __( 'Donate now!', 'newspack-blocks' ) }
<RichText
onChange={ value => setAttributes( { buttonText: value } ) }
placeholder={ __( 'Button text…', 'newspack-blocks' ) }
value={ buttonText }
tagName="span"
/>
</button>
</form>
</div>
);
}

renderTieredForm() {
const { className } = this.props;
const { attributes, className, setAttributes } = this.props;
const { buttonText } = attributes;
const { uid } = this.state;
const {
activeTier,
Expand Down Expand Up @@ -301,7 +309,12 @@ class Edit extends Component {
{ __( 'Your contribution is appreciated.', 'newspack-blocks' ) }
</p>
<button type="submit" onClick={ evt => evt.preventDefault() }>
{ __( 'Donate now!', 'newspack-blocks' ) }
<RichText
onChange={ value => setAttributes( { buttonText: value } ) }
placeholder={ __( 'Button text…', 'newspack-blocks' ) }
value={ buttonText }
tagName="span"
/>
</button>
</form>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/blocks/donate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export const settings = {
campaign: {
type: 'string',
},
buttonText: {
type: 'string',
default: __( 'Donate now!', 'newspack-blocks' ),
},
},
supports: {
html: false,
Expand Down
12 changes: 9 additions & 3 deletions src/blocks/donate/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ function newspack_blocks_render_block_donate( $attributes ) {

$uid = rand(); // Unique identifier to prevent labels colliding with other instances of Donate block.

$button_text = $attributes['buttonText'];

ob_start();

/**
Expand Down Expand Up @@ -102,7 +104,7 @@ class='donate-label'
<?php echo esc_html__( 'Your contribution is appreciated.', 'newspack-blocks' ); ?>
</p>
<button type='submit'>
<?php echo esc_html__( 'Donate now!', 'newspack-blocks' ); ?>
<?php echo wp_kses_post( $button_text ); ?>
</button>
<?php if ( $campaign ) : ?>
<input type='hidden' name='campaign' value='<?php echo esc_attr( $campaign ); ?>' />
Expand Down Expand Up @@ -202,7 +204,7 @@ class='other-donate-label'
<?php echo esc_html__( 'Your contribution is appreciated.', 'newspack-blocks' ); ?>
</p>
<button type='submit'>
<?php echo esc_html__( 'Donate now!', 'newspack-blocks' ); ?>
<?php echo wp_kses_post( $button_text ); ?>
</button>
<?php if ( $campaign ) : ?>
<input type='hidden' name='campaign' value='<?php echo esc_attr( $campaign ); ?>' />
Expand Down Expand Up @@ -243,7 +245,11 @@ function newspack_blocks_register_donate() {
],
'campaign' => [
'type' => 'string',
]
],
'buttonText' => [
'type' => 'string',
'default' => __( 'Donate now!', 'newspack-blocks' ),
],
),
'render_callback' => 'newspack_blocks_render_block_donate',
)
Expand Down

0 comments on commit 6261e3f

Please sign in to comment.