Forked from kimwhite/gettext-multiple-memberships-per-user.php
Last active
February 19, 2024 09:50
-
-
Save dwanjuki/71bf6ee72192ac570c857f81deebf799 to your computer and use it in GitHub Desktop.
Change or translate text strings for PMPro Multiple Memberships Per User.
This file contains hidden or 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 | |
/** | |
* Change or translate text strings for PMPro Multiple Memberships Per User. | |
* | |
* This recipe assumes and requires that both PMPro core and PMPro Multiple Memberships Per User are active. | |
* | |
* 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/ | |
* | |
*/ | |
function my_gettext_pmpro_mmpu( $output_text, $input_text, $domain ) { | |
// Is PMPro and MMPU active? | |
if ( ! defined( 'PMPRO_VERSION' ) || ! defined( 'PMPROMMPU_VER' ) ) { | |
return $output_text; | |
} | |
if ( 'pmpro-multiple-memberships-per-user' === $domain ) { | |
// Find and replace strings with translation strings | |
switch ( $input_text ) { | |
case 'You have selected the following level': | |
$output_text = 'Your translation string here'; | |
break; | |
case 'You have selected the following levels': | |
$output_text = 'Your translation string here'; | |
break; | |
case 'Do you have a discount code?': | |
$output_text = 'Your translation string here'; | |
break; | |
case 'You can only choose one level from this group.': | |
$output_text = 'Your translation string here'; | |
break; | |
case 'You can choose multiple levels from this group.': | |
$output_text = 'Your translation string here'; | |
break; | |
case 'Membership Selections': | |
$output_text = 'Your translation string here'; | |
break; | |
case 'Select levels to complete checkout.': | |
$output_text = 'Your translation string here'; | |
break; | |
case 'No levels selected.': | |
$output_text = 'Your translation string here'; | |
break; | |
case 'Checkout': | |
$output_text = 'Your translation string here'; | |
break; | |
case 'Add': | |
$output_text = 'Your translation string here'; | |
break; | |
} | |
} | |
return $output_text; | |
} | |
add_filter( 'gettext', 'my_gettext_pmpro_mmpu', 10, 3 ); | |
function my_gettext_with_context_pmpro_mmpu( $output_text, $input_text, $context, $domain ) { | |
// Is PMPro and MMPU active? | |
if ( ! defined( 'PMPRO_VERSION' ) || ! defined( 'PMPROMMPU_VER' ) ) { | |
return $output_text; | |
} | |
if ( 'pmpro-multiple-memberships-per-user' === $domain ) { | |
// Find and replace strings with translation strings | |
switch ( $input_text ) { | |
case 'Current Levels': | |
if( $context == 'title for currently selected levels' ) { | |
$output_text = 'Your translation string here'; | |
} | |
break; | |
case 'Added Levels': | |
if( $context == 'title for added levels' ) { | |
$output_text = 'Your translation string here'; | |
} | |
break; | |
case 'Removed Levels': | |
if( $context == 'title for removed levels' ) { | |
$output_text = 'Your translation string here'; | |
} | |
break; | |
case 'None': | |
if( $context == 'value displayed when no levels selected' ) { | |
$output_text = 'Your translation string here'; | |
} | |
break; | |
} | |
} | |
return $output_text; | |
} | |
add_filter( 'gettext_with_context', 'my_gettext_with_context_pmpro_mmpu', 10, 4 ); | |
// Support _n calls. | |
function my_ngettext_pmpro_mmpu( $output_text, $single, $plural, $number, $domain ) { | |
if ( 1 === $number ) { | |
return my_gettext_pmpro_mmpu( $output_text, $single, $domain ); | |
} else { | |
return my_gettext_pmpro_mmpu( $output_text, $plural, $domain ); | |
} | |
} | |
add_filter( 'ngettext', 'my_ngettext_pmpro_mmpu', 10, 5 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment