$atts Block attributes (`loginPageId`) or * shortcode attributes (`login_page_id`). */ public function render( array $atts ): string { $loginPageId = Val::int( $atts['loginPageId'] ?? $atts['login_page_id'] ?? 0 ); $loginUrl = $this->pageUrl( $loginPageId ); wp_enqueue_style( 'us-scheduler' ); if ( ! is_user_logged_in() ) { if ( null === $loginUrl ) { return ''; } return sprintf( '
%s
', esc_url( $loginUrl ), esc_html__( 'Sign in', 'unsupervised-schedular' ) ); } // Always a WP_User here — is_user_logged_in() above rules out the // id-0 placeholder wp_get_current_user() returns for a visitor. $user = wp_get_current_user(); $name = UserName::format( $user, get_current_user_id() ); $email = $user->user_email; // Back to where they were, so signing out of a header link does not also // navigate them somewhere. The login page is the better landing spot when // one is configured, since the current page may be members-only. $logoutUrl = wp_logout_url( $loginUrl ?? (string) get_permalink() ); ob_start(); include USC_PLUGIN_DIR . 'templates/frontend/account-page.php'; return (string) ob_get_clean(); } /** * Permalink of a configured page, or null when none is chosen or the chosen * page has since been deleted. */ private function pageUrl( int $pageId ): ?string { if ( $pageId <= 0 ) { return null; } $url = get_permalink( $pageId ); return is_string( $url ) ? $url : null; } }