[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
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 * @since 5.8.0 12 * 13 * @param array $attributes The block attributes. 14 * 15 * @return string Returns the login-out link or form. 16 */ 17 function render_block_core_loginout( $attributes ) { 18 19 // Build the redirect URL. 20 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 21 22 $classes = is_user_logged_in() ? 'logged-in' : 'logged-out'; 23 $contents = wp_loginout( 24 isset( $attributes['redirectToCurrent'] ) && $attributes['redirectToCurrent'] ? $current_url : '', 25 false 26 ); 27 28 // If logged-out and displayLoginAsForm is true, show the login form. 29 if ( ! is_user_logged_in() && ! empty( $attributes['displayLoginAsForm'] ) ) { 30 // Add a class. 31 $classes .= ' has-login-form'; 32 33 // Get the form. 34 $contents = wp_login_form( array( 'echo' => false ) ); 35 } 36 37 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) ); 38 39 return '<div ' . $wrapper_attributes . '>' . $contents . '</div>'; 40 } 41 42 /** 43 * Registers the `core/loginout` block on server. 44 * 45 * @since 5.8.0 46 */ 47 function register_block_core_loginout() { 48 register_block_type_from_metadata( 49 __DIR__ . '/loginout', 50 array( 51 'render_callback' => 'render_block_core_loginout', 52 ) 53 ); 54 } 55 add_action( 'init', 'register_block_core_loginout' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Thu Nov 21 08:20:01 2024 | Cross-referenced by PHPXref |