Created
June 23, 2018 10:12
-
-
Save kadimi/4b511c511eafadf605fbb627c21dfd9d to your computer and use it in GitHub Desktop.
BuddyPress Label for SportsPress
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 | |
/* | |
Plugin Name: BuddyPress Label for SportsPress | |
Plugin URI: https://www.themeboy.com/sportspress-extensions/buddypress/ | |
Description: Plugin allows changing the label of SportPress within BuddyPress pages, go to "SportsPress > Settings > Text" then scroll down to the latest option "SportsPress (BuddyPress)" and fill it with your choice. | |
Author: Nabil Kadimi - Support Engineer at ThemeBoy | |
Version: 1.0.0 | |
License: GNU General Public License v3.0 | |
License URI: http://www.gnu.org/licenses/gpl-3.0.html | |
*/ | |
/** | |
* Predifined values. | |
*/ | |
$bp_sportspress_text = [ | |
'id' => 'SportPress (BuddyPress)', | |
'default' => __( 'SportsPress', 'bp-sportspresss' ), | |
'title' => sprintf( '%s (%s)' | |
, __( 'SportsPress', 'bp-sportspresss' ) | |
, __( 'BuddyPress', 'buddypress' ) | |
), | |
]; | |
/** | |
* Add text option. | |
*/ | |
add_filter( 'sportspress_text_settings', function( $settings ) use ( $bp_sportspress_text ) { | |
$last = array_pop( $settings ); | |
$settings[] = [ | |
'title' => $bp_sportspress_text['title'], | |
'id' => sprintf( 'sportspress_text[%s]', $bp_sportspress_text['id'] ), | |
'placeholder' => $bp_sportspress_text['default'], | |
'value' => NULL, | |
'type' => 'text', | |
]; | |
$settings[] = $last; | |
return $settings; | |
} ); | |
/** | |
* Use text option. | |
*/ | |
add_filter( 'gettext', function( $text, $unused, $domain ) use ( $bp_sportspress_text ) { | |
if ( in_array( $domain, [ 'bp-sportspress', 'bp-sportspresss' ] ) ) { | |
if ( $bp_sportspress_text['default'] === $text ) { | |
$sportspress_text = get_option( 'sportspress_text', [] ); | |
$new_text = ! empty( $sportspress_text[ $bp_sportspress_text['id'] ] ) | |
? $sportspress_text[ $bp_sportspress_text['id'] ] | |
: $bp_sportspress_text['default'] | |
; | |
return $new_text; | |
} | |
} | |
return $text; | |
}, 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment