Skip to content

Commit

Permalink
feat: render link to terms URL if given
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoo committed Oct 20, 2022
1 parent 0b2fb63 commit 6b8c095
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions assets/blocks/reader-registration/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export default function ReaderRegistrationEdit( {
} ) {
const blockProps = useBlockProps();
const [ editedState, setEditedState ] = useState( editedStateOptions[ 0 ].value );
const { reader_activation_terms: defaultTermsText } = window.newspack_blocks;
const { reader_activation_terms: defaultTermsText, reader_activation_url: defaultTermsUrl } =
window.newspack_blocks;

const innerBlocksProps = useInnerBlocksProps(
{},
Expand Down Expand Up @@ -315,7 +316,7 @@ export default function ReaderRegistrationEdit( {
onChange={ value => setAttributes( { privacyLabel: value } ) }
placeholder={ __( 'Terms & Conditions statement…', 'newspack' ) }
value={ privacyLabel || defaultTermsText }
tagName="p"
tagName={ defaultTermsUrl ? 'a' : 'p' }
/>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions assets/blocks/reader-registration/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
&__help-text {
margin-top: 1em;

a,
p {
font-size: 0.55em !important;
margin: 0;
Expand Down
9 changes: 9 additions & 0 deletions assets/blocks/reader-registration/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,18 @@ function render_block( $attrs, $content ) {
<div class="newspack-registration__help-text">
<p>
<?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
1 change: 1 addition & 0 deletions includes/class-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static function enqueue_block_editor_assets() {
'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 6b8c095

Please sign in to comment.