Changeset 10491
- Timestamp:
- 02/01/2016 07:44:36 PM (9 years ago)
- Location:
- trunk/src/bp-core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-functions.php
r10487 r10491 3048 3048 ), $object ); 3049 3049 } 3050 3051 /** 3052 * Replace all tokens in the input text with appropriate values. 3053 * 3054 * Intended for use with the email system introduced in BuddyPress 2.5.0. 3055 * 3056 * @since 2.5.0 3057 * 3058 * @param string $text 3059 * @param array $tokens Token names and replacement values for the $text. 3060 * @return string 3061 */ 3062 function bp_core_replace_tokens_in_text( $text, $tokens ) { 3063 $unescaped = array(); 3064 $escaped = array(); 3065 3066 foreach ( $tokens as $token => $value ) { 3067 if ( is_callable( $value ) ) { 3068 $value = call_user_func( $value ); 3069 } 3070 3071 // Tokens could be objects or arrays. 3072 if ( ! is_scalar( $value ) ) { 3073 continue; 3074 } 3075 3076 $unescaped[ '{{{' . $token . '}}}' ] = $value; 3077 $escaped[ '{{' . $token . '}}' ] = esc_html( $value ); 3078 } 3079 3080 $text = strtr( $text, $unescaped ); // Do first. 3081 $text = strtr( $text, $escaped ); 3082 3083 /** 3084 * Filters text that has had tokens replaced. 3085 * 3086 * @since 2.5.0 3087 * 3088 * @param string $text 3089 * @param array $tokens Token names and replacement values for the $text. 3090 */ 3091 return apply_filters( 'bp_core_replace_tokens_in_text', $text, $tokens ); 3092 } -
trunk/src/bp-core/classes/class-bp-email.php
r10489 r10491 244 244 245 245 case 'replace-tokens': 246 $retval = self::replace_tokens( $retval, $this->get_tokens( 'raw' ) );246 $retval = bp_core_replace_tokens_in_text( $retval, $this->get_tokens( 'raw' ) ); 247 247 // Fall through. 248 248 … … 949 949 return apply_filters( 'bp_email_validate', $retval, $this ); 950 950 } 951 952 953 /*954 * Utility functions.955 *956 * Unlike other methods in this class, utility functions are not chainable.957 */958 959 /**960 * Replace all tokens in the input with appropriate values.961 *962 * Unlike most other methods in this class, this one is not chainable.963 *964 * @since 2.5.0965 *966 * @param string $text967 * @param array $tokens Token names and replacement values for the $text.968 * @return string969 */970 public static function replace_tokens( $text, $tokens ) {971 $unescaped = array();972 $escaped = array();973 974 foreach ( $tokens as $token => $value ) {975 if ( is_callable( $value ) ) {976 $value = call_user_func( $value );977 }978 979 // Some tokens are objects or arrays for backwards compatibilty. See bp_core_deprecated_email_filters().980 if ( ! is_scalar( $value ) ) {981 continue;982 }983 984 $unescaped[ '{{{' . $token . '}}}' ] = $value;985 $escaped[ '{{' . $token . '}}' ] = esc_html( $value );986 }987 988 $text = strtr( $text, $unescaped ); // Do first.989 $text = strtr( $text, $escaped );990 991 /**992 * Filters text that has had tokens replaced.993 *994 * @since 2.5.0995 *996 * @param string $text997 * @param array $tokens Token names and replacement values for the $text.998 */999 return apply_filters( 'bp_email_replace_tokens', $text, $tokens );1000 }1001 951 }
Note: See TracChangeset
for help on using the changeset viewer.