bp_email_add_link_color_to_template

Add email link styles to rendered email template.

Description

(string) bp_email_add_link_color_to_template( (string) $value, (string) $property_name, (string) $transform ); 

This is only used when the email content has been merged into the email template.

Returns (string)

Updated value.

Parameters (3)

0. $value (string)
Property value.
1. $property_name (string)
Email template property name.
2. $transform (string)
How the return value was transformed.

Usage

  1. if ( !function_exists( 'bp_email_add_link_color_to_template' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-filters.php'; 
  3.  
  4. // Property value. 
  5. $value = ''; 
  6.  
  7. // Email template property name. 
  8. $property_name = ''; 
  9.  
  10. // How the return value was transformed. 
  11. $transform = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bp_email_add_link_color_to_template($value, $property_name, $transform); 
  15.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-filters.php  
  1. function bp_email_add_link_color_to_template( $value, $property_name, $transform ) { 
  2. if ( $property_name !== 'template' || $transform !== 'add-content' ) { 
  3. return $value; 
  4.  
  5. $replacement = 'style="color: ' . esc_attr( $settings['highlight_color'] ) . ';'; 
  6.  
  7. // Find all links. 
  8. preg_match_all( '#<a[^>]+>#i', $value, $links, PREG_SET_ORDER ); 
  9. foreach ( $links as $link ) { 
  10. $new_link = $link = array_shift( $link ); 
  11.  
  12. // Add/modify style property. 
  13. if ( strpos( $link, 'style="' ) !== false ) { 
  14. $new_link = str_replace( 'style="', $replacement, $link ); 
  15. } else { 
  16. $new_link = str_replace( '<a ', "<a {$replacement}\" ", $link ); 
  17.  
  18. if ( $new_link !== $link ) { 
  19. $value = str_replace( $link, $new_link, $value ); 
  20.  
  21. return $value;