Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ipokkel/e701b1cd398048511a2c29be534beb8b to your computer and use it in GitHub Desktop.
Save ipokkel/e701b1cd398048511a2c29be534beb8b to your computer and use it in GitHub Desktop.
<?php
/**
* This recipe will change the "Username or Email Address" text string
* on the login page and login widget.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
// Apply text changes by adding our filter.
function my_pmpro_login_page_only_gettext() {
// Add the filter that will change the text strings.
add_filter( 'gettext', 'my_pmpro_login_change_text_strings', 10, 3 );
}
// Hook into wp for the login page context.
add_action( 'wp', 'my_pmpro_login_check' );
// Hook into widgets_init for the widget context.
add_action( 'widgets_init', 'my_pmpro_login_page_only_gettext' );
// Only add our text filter when on the login page.
function my_pmpro_login_check() {
// Check if we're on the login page.
if ( function_exists( 'pmpro_is_login_page' ) && pmpro_is_login_page() ) {
my_pmpro_login_page_only_gettext();
}
}
// Change the "Username or Email Address" text string on the login page and widget.
function my_pmpro_login_change_text_strings( $translated_text, $original_text, $domain ) {
// Let's change the text strings.
switch ( $original_text ) {
case 'Username or Email Address':
$translated_text = __( 'Email Address', 'paid-memberships-pro' );
break;
case 'Please enter your username or email address. You will receive a link to create a new password via email.':
$translated_text = __( 'Please enter your email address. You will receive a link to create a new password via email', 'paid-memberships-pro' );
break;
}
return $translated_text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment