Skip to content

Commit

Permalink
fix: use default terms text in reg block if no text defined (#2078)
Browse files Browse the repository at this point in the history
* fix: use default terms text in reg block if no text defined

* feat: render link to terms URL if given

* fix: editor markup for terms link

* fix: terms link in Registration block editor

* chore: remove unneeded extra class name

* fix: use html string for link

Co-authored-by: Miguel Peixe <miguel.peixe@automattic.com>
  • Loading branch information
dkoo and miguelpeixe authored Oct 27, 2022
1 parent feee30b commit 443c59c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion assets/blocks/reader-registration/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"privacyLabel": {
"type": "string",
"default": "By signing up, you agree to our Terms and Conditions."
"default": ""
},
"newsletterSubscription": {
"type": "boolean",
Expand Down
8 changes: 7 additions & 1 deletion assets/blocks/reader-registration/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ export default function ReaderRegistrationEdit( {
} ) {
const blockProps = useBlockProps();
const [ editedState, setEditedState ] = useState( editedStateOptions[ 0 ].value );
let { reader_activation_terms: defaultTermsText, reader_activation_url: defaultTermsUrl } =
window.newspack_blocks;

if ( defaultTermsUrl ) {
defaultTermsText = `<a href="${ defaultTermsUrl }">` + defaultTermsText + '</a>';
}

const innerBlocksProps = useInnerBlocksProps(
{},
Expand Down Expand Up @@ -313,7 +319,7 @@ export default function ReaderRegistrationEdit( {
<RichText
onChange={ value => setAttributes( { privacyLabel: value } ) }
placeholder={ __( 'Terms & Conditions statement…', 'newspack' ) }
value={ privacyLabel }
value={ privacyLabel || defaultTermsText }
tagName="p"
/>
</div>
Expand Down
14 changes: 13 additions & 1 deletion assets/blocks/reader-registration/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,19 @@ function render_block( $attrs, $content ) {

<div class="newspack-registration__help-text">
<p>
<?php echo \wp_kses_post( $attrs['privacyLabel'] ); ?>
<?php
$terms_url = wp_http_validate_url( Reader_Activation::get_setting( 'terms_url' ) );
if ( $terms_url ) :
?>
<a href="<?php echo esc_url( $terms_url ); ?>">
<?php
endif;
$terms_text = empty( $attrs['privacyLabel'] ) ? Reader_Activation::get_setting( 'terms_text' ) : $attrs['privacyLabel'];
echo \wp_kses_post( $terms_text );
?>
<?php if ( $terms_url ) : ?>
</a>
<?php endif; ?>
</p>
</div>
</div>
Expand Down
12 changes: 7 additions & 5 deletions includes/class-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ public static function enqueue_block_editor_assets() {
'newspack-blocks',
'newspack_blocks',
[
'has_newsletters' => method_exists( 'Newspack_Newsletters_Subscription', 'add_contact' ),
'has_reader_activation' => Reader_Activation::is_enabled( false ),
'newsletters_url' => Wizards::get_wizard( 'engagement' )->newsletters_settings_url(),
'has_google_oauth' => Google_OAuth::is_oauth_configured(),
'google_logo_svg' => file_get_contents( dirname( NEWSPACK_PLUGIN_FILE ) . '/assets/blocks/reader-registration/icons/google.svg' ),
'has_newsletters' => method_exists( 'Newspack_Newsletters_Subscription', 'add_contact' ),
'has_reader_activation' => Reader_Activation::is_enabled( false ),
'newsletters_url' => Wizards::get_wizard( 'engagement' )->newsletters_settings_url(),
'has_google_oauth' => Google_OAuth::is_oauth_configured(),
'google_logo_svg' => file_get_contents( dirname( NEWSPACK_PLUGIN_FILE ) . '/assets/blocks/reader-registration/icons/google.svg' ),
'reader_activation_terms' => Reader_Activation::get_setting( 'terms_text' ),
'reader_activation_url' => Reader_Activation::get_setting( 'terms_url' ),
]
);
\wp_enqueue_style(
Expand Down

0 comments on commit 443c59c

Please sign in to comment.