Here is the Custom Code my colleague Joachim Happel wrote:
static public function share_on_mastodon_status($status, WP_Post $post){
if('material' === $post->post_type){
global $post;
$map =[
'elementary' => '#Kita',
'church' => '#Kirche',
'youth' => '#Jugendarbeit',
'children' => '#Kinder',
'adult-education' => '#Erwachsenenbildung',
'sunday-school' => '#Kindergottesdienst',
'confirmation-work' => '#Konfis',
'school' => '#ReligionEdu #FediLZ',
'professional' => '#Berufsschule',
'primary' => '#Grundschule',
'advanced' => '#Oberstufe',
'secondary' => '#Sekundarstufe',
'teachers' => '#Lehrerbildung',
'relpaed' => '#ReligionStudieren'
];
$words =[
'globales-lernen' => '#bne',
'Nachhaltigkeit' => '#bne',
];
$short = Materialpool_Material::get_shortdescription().":\n";
$url = Materialpool_Material::get_url()."\n";
$shortinfo = "\n".$short.$url;
$data=[];
$term_list = wp_get_post_terms( $post->ID, 'bildungsstufe' );
if ( is_array( $term_list)) {
foreach ( $term_list as $tax ) {
$data[] = $map[$tax->slug];
}
}
$zielgruppen = implode(' ', $data);
$data=[];
$term_list = wp_get_post_terms( $post->ID, 'schlagwort' );
if ( is_array( $term_list)) {
foreach ( $term_list as $tax ) {
if(in_array($tax->slug, $words)){
$data[] = $words[$tax->slug];
}else{
$data[] = "#{$tax->slug}";
}
}
}
$data = array_unique($data);
$tags = implode(' ', $data);
if(strlen($status." \n" .$zielgruppen )<450){
$status .= " \n" .$zielgruppen ;
}
if(strlen($status." \n" .$shortinfo )<300){
$status .= " \n" .$shortinfo ;
}
if(strlen($status." \n" .$tags )<450){
$status .= " \n" .wp_trim_words($tags,5) ;
}
$status = self::truncate($status,500);
}
return $status;
}
and:
static function truncate($string,$length=100,$append="")
{
$string = trim($string);
if (strlen($string) > $length) {
$string = wordwrap($string, $length);
$string = explode("\n", $string, 2);
$string = $string[0] . $append;
}
return $string;
}