diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md index 7e031fa525e1ff..e5ab7ed7b8f819 100644 --- a/docs/reference-guides/core-blocks.md +++ b/docs/reference-guides/core-blocks.md @@ -436,7 +436,7 @@ Show login & logout links. ([Source](https://github.com/WordPress/gutenberg/tree - **Name:** core/loginout - **Category:** theme - **Supports:** className, color (background, gradients, link, ~~text~~), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight) -- **Attributes:** displayLoginAsForm, redirectToCurrent +- **Attributes:** displayAsButton, displayLoginAsForm, redirectToCurrent ## Media & Text diff --git a/packages/block-library/src/loginout/block.json b/packages/block-library/src/loginout/block.json index f2aaafd60fde05..d3288180019470 100644 --- a/packages/block-library/src/loginout/block.json +++ b/packages/block-library/src/loginout/block.json @@ -12,6 +12,10 @@ "type": "boolean", "default": false }, + "displayAsButton": { + "type": "boolean", + "default": false + }, "redirectToCurrent": { "type": "boolean", "default": true diff --git a/packages/block-library/src/loginout/edit.js b/packages/block-library/src/loginout/edit.js index 9af634c87371cf..99aa9649f4fd23 100644 --- a/packages/block-library/src/loginout/edit.js +++ b/packages/block-library/src/loginout/edit.js @@ -14,7 +14,8 @@ import { __ } from '@wordpress/i18n'; import { useToolsPanelDropdownMenuProps } from '../utils/hooks'; export default function LoginOutEdit( { attributes, setAttributes } ) { - const { displayLoginAsForm, redirectToCurrent } = attributes; + const { displayLoginAsForm, displayAsButton, redirectToCurrent } = + attributes; const dropdownMenuProps = useToolsPanelDropdownMenuProps(); return ( @@ -49,6 +50,25 @@ export default function LoginOutEdit( { attributes, setAttributes } ) { } /> + displayAsButton } + onDeselect={ () => + setAttributes( { displayAsButton: false } ) + } + > + + setAttributes( { + displayAsButton: ! displayAsButton, + } ) + } + /> +
- { __( 'Log out' ) } + { displayAsButton ? ( +
+ { __( 'Log out' ) } +
+ ) : ( + { __( 'Log out' ) } + ) }
); diff --git a/packages/block-library/src/loginout/index.php b/packages/block-library/src/loginout/index.php index de90ebc12e379a..316211c87da56a 100644 --- a/packages/block-library/src/loginout/index.php +++ b/packages/block-library/src/loginout/index.php @@ -25,6 +25,15 @@ function render_block_core_loginout( $attributes ) { false ); + // If display as button is enabled, wrap the link in button classes + if ( ! empty( $attributes['displayAsButton'] ) ) { + $classes .= ' wp-block-button'; + $contents = sprintf( + '', + $contents + ); + } + // If logged-out and displayLoginAsForm is true, show the login form. if ( ! is_user_logged_in() && ! empty( $attributes['displayLoginAsForm'] ) ) { // Add a class.