Skip to content

Commit 60add77

Browse files
authored
Subscriber Login: Allow custom link labels (#35179)
1 parent 69ab0bd commit 60add77

File tree

4 files changed

+59
-8
lines changed

4 files changed

+59
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: other
3+
4+
Subscriber Login: Allow custom link labels

projects/plugins/jetpack/extensions/blocks/subscriber-login/block.json

+9
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@
3535
"redirectToCurrent": {
3636
"type": "boolean",
3737
"default": true
38+
},
39+
"logInLabel": {
40+
"type": "string"
41+
},
42+
"logOutLabel": {
43+
"type": "string"
44+
},
45+
"manageSubscriptionsLabel": {
46+
"type": "string"
3847
}
3948
}
4049
}

projects/plugins/jetpack/extensions/blocks/subscriber-login/edit.js

+38-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
import { InspectorControls } from '@wordpress/block-editor';
2-
import { PanelBody, ToggleControl } from '@wordpress/components';
2+
import { PanelBody, ToggleControl, BaseControl, TextControl } from '@wordpress/components';
3+
import { useInstanceId } from '@wordpress/compose';
34
import { __ } from '@wordpress/i18n';
5+
import { getValidatedAttributes } from '../../shared/get-validated-attributes';
6+
import metadata from './block.json';
47

58
function SubscriberLoginEdit( { attributes, setAttributes, className } ) {
6-
const { redirectToCurrent } = attributes;
9+
const logInInputId = useInstanceId( TextControl, 'inspector-text-control' );
10+
const logOutInputId = useInstanceId( TextControl, 'inspector-text-control' );
11+
const manageSubscriptionsInputId = useInstanceId( TextControl, 'inspector-text-control' );
12+
const validatedAttributes = getValidatedAttributes( metadata.attributes, attributes );
13+
const { redirectToCurrent, logInLabel, logOutLabel, manageSubscriptionsLabel } =
14+
validatedAttributes;
715

816
return (
917
<>
@@ -14,10 +22,37 @@ function SubscriberLoginEdit( { attributes, setAttributes, className } ) {
1422
checked={ redirectToCurrent }
1523
onChange={ () => setAttributes( { redirectToCurrent: ! redirectToCurrent } ) }
1624
/>
25+
<BaseControl label={ __( 'Log in label', 'jetpack' ) } id={ logInInputId }>
26+
<TextControl
27+
placeholder={ __( 'Log in', 'jetpack' ) }
28+
onChange={ value => setAttributes( { logInLabel: value } ) }
29+
value={ logInLabel }
30+
id={ logInInputId }
31+
/>
32+
</BaseControl>
33+
<BaseControl label={ __( 'Log out label', 'jetpack' ) } id={ logOutInputId }>
34+
<TextControl
35+
placeholder={ __( 'Log out', 'jetpack' ) }
36+
onChange={ value => setAttributes( { logOutLabel: value } ) }
37+
value={ logOutLabel }
38+
id={ logOutInputId }
39+
/>
40+
</BaseControl>
41+
<BaseControl
42+
label={ __( 'Manage subscriptions label', 'jetpack' ) }
43+
id={ manageSubscriptionsInputId }
44+
>
45+
<TextControl
46+
placeholder={ __( 'Manage subscriptions', 'jetpack' ) }
47+
onChange={ value => setAttributes( { manageSubscriptionsLabel: value } ) }
48+
value={ manageSubscriptionsLabel }
49+
id={ manageSubscriptionsInputId }
50+
/>
51+
</BaseControl>
1752
</PanelBody>
1853
</InspectorControls>
1954
<div className={ className }>
20-
<a href="#logout-pseudo-link">{ __( 'Log out', 'jetpack' ) }</a>
55+
<a href="#logout-pseudo-link">{ logOutLabel || __( 'Log out', 'jetpack' ) }</a>
2156
</div>
2257
</>
2358
);

projects/plugins/jetpack/extensions/blocks/subscriber-login/subscriber-login.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,18 @@ function is_subscriber_logged_in() {
110110
function render_block( $attributes ) {
111111
Jetpack_Gutenberg::load_assets_as_required( __DIR__ );
112112

113-
$block_template = '<div %1$s><a href="%2$s">%3$s</a></div>';
114-
$redirect_to_current = isset( $attributes['redirectToCurrent'] ) && $attributes['redirectToCurrent'];
113+
$block_template = '<div %1$s><a href="%2$s">%3$s</a></div>';
114+
$redirect_to_current = ! empty( $attributes['redirectToCurrent'] );
115+
$log_in_label = ! empty( $attributes['logInLabel'] ) ? sanitize_text_field( $attributes['logInLabel'] ) : esc_html__( 'Log in', 'jetpack' );
116+
$log_out_label = ! empty( $attributes['logOutLabel'] ) ? sanitize_text_field( $attributes['logOutLabel'] ) : esc_html__( 'Log out', 'jetpack' );
117+
$manage_subscriptions_label = ! empty( $attributes['manageSubscriptionsLabel'] ) ? sanitize_text_field( $attributes['manageSubscriptionsLabel'] ) : esc_html__( 'Manage subscriptions', 'jetpack' );
115118

116119
if ( ! is_subscriber_logged_in() ) {
117120
return sprintf(
118121
$block_template,
119122
get_block_wrapper_attributes(),
120123
get_subscriber_login_url( $redirect_to_current ? get_current_url() : '' ),
121-
__( 'Log in', 'jetpack' )
124+
$log_in_label
122125
);
123126
}
124127

@@ -127,14 +130,14 @@ function render_block( $attributes ) {
127130
$block_template,
128131
get_block_wrapper_attributes(),
129132
'https://wordpress.com/read/subscriptions',
130-
__( 'Manage subscriptions', 'jetpack' )
133+
$manage_subscriptions_label
131134
);
132135
}
133136

134137
return sprintf(
135138
$block_template,
136139
get_block_wrapper_attributes(),
137140
wp_logout_url( $redirect_to_current ? get_current_url() : '' ),
138-
__( 'Log out', 'jetpack' )
141+
$log_out_label
139142
);
140143
}

0 commit comments

Comments
 (0)