'; private const DEFAULT_COLOR = '#2a69b8'; public function render( int $org_id, string $lang, string $subject, string $body_html, int $user_id = 0 ): string { if ( str_contains( $body_html, self::MARKER ) ) { return $body_html; } $org = $org_id > 0 ? Services::org_repo()->get( $org_id ) : null; $branding = null === $org ? null : OrgBranding::of( $org, $lang, $user_id ); $site = wp_specialchars_decode( (string) get_bloginfo( 'name' ), ENT_QUOTES ); $name = null === $branding ? $site : $branding->name; $color = null !== $branding && '' !== $branding->color ? $branding->color : self::DEFAULT_COLOR; $text = self::readable_text( $color ); $logo = null !== $branding && null !== $branding->logo_id ? (string) wp_get_attachment_image_url( $branding->logo_id, 'medium' ) : ''; $site_img = self::site_logo(); $footer = null === $branding ? '' : $branding->footer; $left = ''; if ( '' !== $logo ) { $left .= '' . esc_attr( $name ) . ''; } $left .= '' . esc_html( $name ) . ''; $right = '' !== $site_img ? '' . esc_attr( $site ) . '' : '' . esc_html( $site ) . ''; $foot = '' !== $footer ? '
' . nl2br( esc_html( $footer ) ) . '
' : ''; $dir = is_rtl() ? 'rtl' : 'ltr'; $html = self::MARKER . '' . esc_html( $subject ) . '' . '' . '
' . '' . '' . '' . '
' . $left . '' . $right . '
' . '
' . $body_html . '
' . $foot . '
'; $filtered = apply_filters( 'rooster_lms_branded_mail', $html, $org_id, $lang ); return is_string( $filtered ) ? $filtered : $html; } public static function readable_text( string $hex ): string { $hex = ltrim( $hex, '#' ); if ( 3 === strlen( $hex ) ) { $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; } if ( 6 !== strlen( $hex ) || ! ctype_xdigit( $hex ) ) { return '#ffffff'; } $lum = ( 0.299 * hexdec( substr( $hex, 0, 2 ) ) + 0.587 * hexdec( substr( $hex, 2, 2 ) ) + 0.114 * hexdec( substr( $hex, 4, 2 ) ) ) / 255; return $lum > 0.6 ? '#1e1e1e' : '#ffffff'; } private static function site_logo(): string { $logo = (int) get_theme_mod( 'custom_logo' ); if ( $logo > 0 ) { $url = wp_get_attachment_image_url( $logo, 'medium' ); if ( is_string( $url ) && '' !== $url ) { return $url; } } return (string) get_site_icon_url( 128 ); } }