-
Notifications
You must be signed in to change notification settings - Fork 57
feat[my-account-block]: add option to toggle off icon/text, and update tests #4443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c25371f
9d9a68d
84a9ef8
ced713a
d315db9
47dba2a
9fed074
0581242
81ee30d
a49f0e0
cf68793
86d6e24
44f111f
b47c2a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,10 +96,19 @@ public static function render_block( $attrs ) { | |
| ]; | ||
| $attrs = \wp_parse_args( $attrs, $default_attrs ); | ||
|
|
||
| $is_signed_in = \is_user_logged_in(); | ||
| $label = $is_signed_in ? $attrs['signedInLabel'] : $attrs['signedOutLabel']; | ||
| $is_signed_in = \is_user_logged_in(); | ||
| $signed_in_label = '' === trim( (string) $attrs['signedInLabel'] ) ? $default_attrs['signedInLabel'] : $attrs['signedInLabel']; | ||
| $signed_out_label = '' === trim( (string) $attrs['signedOutLabel'] ) ? $default_attrs['signedOutLabel'] : $attrs['signedOutLabel']; | ||
| $label = $is_signed_in ? $signed_in_label : $signed_out_label; | ||
| $show_label = isset( $attrs['showLabel'] ) ? (bool) $attrs['showLabel'] : true; | ||
| $show_icon = isset( $attrs['showIcon'] ) ? (bool) $attrs['showIcon'] : true; | ||
|
|
||
| if ( ! $show_label && ! $show_icon ) { | ||
| $show_label = true; | ||
| } | ||
|
|
||
| if ( '' === trim( (string) $label ) ) { | ||
| return ''; | ||
| $label = $is_signed_in ? $default_attrs['signedInLabel'] : $default_attrs['signedOutLabel']; | ||
| } | ||
|
|
||
| $account_url = self::get_account_url(); | ||
|
|
@@ -118,8 +127,8 @@ public static function render_block( $attrs ) { | |
| } | ||
|
|
||
| $labels = [ | ||
| 'signedin' => $attrs['signedInLabel'], | ||
| 'signedout' => $attrs['signedOutLabel'], | ||
| 'signedin' => $signed_in_label, | ||
| 'signedout' => $signed_out_label, | ||
| ]; | ||
|
|
||
| $extra_classes = [ | ||
|
|
@@ -153,20 +162,26 @@ public static function render_block( $attrs ) { | |
| $wrapper_div_classes = \array_merge( $wrapper_div_classes, $custom_classes ); | ||
| } | ||
|
|
||
| $wrapper_attributes = \get_block_wrapper_attributes( | ||
| [ | ||
| 'class' => implode( ' ', $extra_classes ), | ||
| 'href' => \esc_url_raw( $href ), | ||
| ] | ||
| ); | ||
| $wrapper_attribute_args = [ | ||
| 'class' => implode( ' ', $extra_classes ), | ||
| 'href' => \esc_url_raw( $href ), | ||
| 'data-wp-logged-in' => $is_signed_in ? '1' : '0', | ||
|
||
| ]; | ||
| $wrapper_attributes = \get_block_wrapper_attributes( $wrapper_attribute_args ); | ||
|
|
||
| $link = '<div class="' . \esc_attr( implode( ' ', $wrapper_div_classes ) ) . '">'; | ||
| $link .= '<div class="wp-block-button">'; | ||
| $link .= '<a ' . $wrapper_attributes . ' data-labels="' . \esc_attr( \wp_json_encode( $labels ) ) . '" ' . $should_modal_trigger . '>'; | ||
| $link .= '<span class="wp-block-newspack-my-account-button__icon" aria-hidden="true">'; | ||
| $link .= Newspack_UI_Icons::get_svg( 'account' ); | ||
| $link .= '</span>'; | ||
| $link .= '<span class="newspack-reader__account-link__label">' . \esc_html( $label ) . '</span>'; | ||
| if ( $show_icon ) { | ||
| $link .= '<span class="wp-block-newspack-my-account-button__icon" aria-hidden="true">'; | ||
| $link .= Newspack_UI_Icons::get_svg( 'account' ); | ||
| $link .= '</span>'; | ||
| } | ||
| $label_classes = [ 'newspack-reader__account-link__label' ]; | ||
| if ( ! $show_label ) { | ||
| $label_classes[] = 'screen-reader-text'; | ||
| } | ||
| $link .= '<span class="' . \esc_attr( implode( ' ', $label_classes ) ) . '">' . \esc_html( $label ) . '</span>'; | ||
| $link .= '</a>'; | ||
| $link .= '</div>'; | ||
| $link .= '</div>'; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.