Forked from ipokkel/gettext-multiple-memberships-per-user.php
Created
September 13, 2023 18:27
-
-
Save kimwhite/801d9a6fe548f6f6040265a7013bf27e 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/ | |
* | |
* @param string $output_text this represents the end result | |
* @param string $input_text what is written in the code that we want to change | |
* @param string $domain text-domain of the plugin/theme that contains the code | |
* | |
* @return string the result of the text transformation | |
*/ | |
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; | |
} | |
// Let's see if current or deprecated text domains are available. | |
if ( 'pmpro-multiple-memberships-per-user' === $domain || 'paid-memberships-pro' === $domain || 'pmprommpu' === $domain || 'pmpro' === $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 = 'change me'; | |
break; | |
case 'You can choose multiple levels from this group.': | |
$output_text = 'change me'; | |
break; | |
} | |
} | |
return $output_text; | |
} | |
add_filter( 'gettext', 'my_gettext_pmpro_mmpu', 10, 3 ); | |
// 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