render_block_core_loginout

函式
render_block_core_loginout ( $attributes )
引數
  • (array) $attributes The block attributes.
    Required:
返回值
  • (string) Returns the login-out link or form.
定義位置
相關方法
register_block_core_loginoutrender_block_core_site_logorender_block_core_blockrender_block_core_commentsrender_block_core_tag_cloud
引入
-
棄用
-

render_block_core_loginout: 這個函式用來渲染WordPress中的登入/登出塊。登入/登出塊允許使用者在他們的網站上新增一個登入或登出連結: 這個函式負責生成Login/Logout塊的HTML標記。

渲染伺服器上的`core/loginout`區塊。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function render_block_core_loginout( $attributes ) {
// Build the redirect URL.
$current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$classes = is_user_logged_in() ? 'logged-in' : 'logged-out';
$contents = wp_loginout(
isset( $attributes['redirectToCurrent'] ) && $attributes['redirectToCurrent'] ? $current_url : '',
false
);
// If logged-out and displayLoginAsForm is true, show the login form.
if ( ! is_user_logged_in() && ! empty( $attributes['displayLoginAsForm'] ) ) {
// Add a class.
$classes .= ' has-login-form';
// Get the form.
$contents = wp_login_form( array( 'echo' => false ) );
}
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
return '<div ' . $wrapper_attributes . '>' . $contents . '</div>';
}
function render_block_core_loginout( $attributes ) { // Build the redirect URL. $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $classes = is_user_logged_in() ? 'logged-in' : 'logged-out'; $contents = wp_loginout( isset( $attributes['redirectToCurrent'] ) && $attributes['redirectToCurrent'] ? $current_url : '', false ); // If logged-out and displayLoginAsForm is true, show the login form. if ( ! is_user_logged_in() && ! empty( $attributes['displayLoginAsForm'] ) ) { // Add a class. $classes .= ' has-login-form'; // Get the form. $contents = wp_login_form( array( 'echo' => false ) ); } $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) ); return '<div ' . $wrapper_attributes . '>' . $contents . '</div>'; }
function render_block_core_loginout( $attributes ) {

	// Build the redirect URL.
	$current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

	$classes  = is_user_logged_in() ? 'logged-in' : 'logged-out';
	$contents = wp_loginout(
		isset( $attributes['redirectToCurrent'] ) && $attributes['redirectToCurrent'] ? $current_url : '',
		false
	);

	// If logged-out and displayLoginAsForm is true, show the login form.
	if ( ! is_user_logged_in() && ! empty( $attributes['displayLoginAsForm'] ) ) {
		// Add a class.
		$classes .= ' has-login-form';

		// Get the form.
		$contents = wp_login_form( array( 'echo' => false ) );
	}

	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );

	return '<div ' . $wrapper_attributes . '>' . $contents . '</div>';
}

常見問題

FAQs
檢視更多 >