Last active
December 7, 2023 20:50
-
-
Save azamatx/9f46a15ae4811d188bc6d973532a3fe0 to your computer and use it in GitHub Desktop.
wp greeting user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add Shortcode | |
function subform() { | |
ob_start(); | |
// Greet guests, if user is not logged in. | |
$user_display_name = __( 'Guest', 'wpmudev' ); | |
// Get the current user's display name. | |
if ( is_user_logged_in() ) { | |
$current_user = wp_get_current_user(); | |
$user_display_name = $current_user->display_name; | |
} | |
// Get the blog name. | |
$blog_name = get_bloginfo( 'name' ); | |
/* translators: 1. User name, 2. Blog name */ | |
$greeting = sprintf( esc_html__( 'Hey %1$s, welcome to %2$s! You can subscribe to our newsletter here:', 'wpmudev' ), $user_display_name, $blog_name ); | |
?> | |
<p><?php echo esc_html( $greeting ); ?></p> | |
<form action="<?php echo esc_url( get_site_url( null, '/thank-you/' ) ); ?>"> | |
<label for="email"><?php esc_html_e( 'Enter your email:', 'wpmudev' ); ?></label> | |
<input type="email" id="email" name="email"> | |
<input type="submit" value="<?php esc_attr_e( 'Submit', 'wpmudev' ); ?>"> | |
</form> | |
<?php | |
return ob_get_clean(); | |
} | |
add_shortcode( 'subscriptionform', 'subform' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment