PluginProbe
Gutenberg / 12.1.0
Gutenberg v12.1.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / build / block-library / blocks / loginout.php

loginout.php in Gutenberg 12.1.0, at build/block-library/blocks/loginout.php

52 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Server-side rendering of the `core/loginout` block.
4 *
5 * @package WordPress
6 */
7
8 /**
9 * Renders the `core/loginout` block on server.
10 *
11 * @param array $attributes The block attributes.
12 *
13 * @return string Returns the login-out link or form.
14 */
15 function gutenberg_render_block_core_loginout( $attributes ) {
16
17 // Build the redirect URL.
18 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
19
20 $classes = is_user_logged_in() ? 'logged-in' : 'logged-out';
21 $contents = wp_loginout(
22 isset( $attributes['redirectToCurrent'] ) && $attributes['redirectToCurrent'] ? $current_url : '',
23 false
24 );
25
26 // If logged-out and displayLoginAsForm is true, show the login form.
27 if ( ! is_user_logged_in() && ! empty( $attributes['displayLoginAsForm'] ) ) {
28 // Add a class.
29 $classes .= ' has-login-form';
30
31 // Get the form.
32 $contents = wp_login_form( array( 'echo' => false ) );
33 }
34
35 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
36
37 return '<div ' . $wrapper_attributes . '>' . $contents . '</div>';
38 }
39
40 /**
41 * Registers the `core/loginout` block on server.
42 */
43 function gutenberg_register_block_core_loginout() {
44 register_block_type_from_metadata(
45 __DIR__ . '/loginout',
46 array(
47 'render_callback' => 'gutenberg_render_block_core_loginout',
48 )
49 );
50 }
51 add_action( 'init', 'gutenberg_register_block_core_loginout', 20 );
52