Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Jan Boddez

    (@janboddez)

    Oh, that shouldn’t be happening. That would indicate WordPress hasn’t yet saved the title or URL or something, when the post goes live. (The exact same code is used for scheduled posts and “normal” ones.)

    I’m going to have to experiment a bit.

    Which editor are you using? Block editor or the “classic” editor?

    Any “Share on Mastodon” settings that I should know about? Custom PHP snippets? Do you sometimes modify the status message, or use a template, or just the defaults?

    Thread Starter empeiria

    (@empeiria)

    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;
        }
    
    Plugin Author Jan Boddez

    (@janboddez)

    Hmm, guessing there’s somehow a conflict with some of your custom code, or perhaps another plugin.

    In any case, Share on Mastodon itself just uses get_permalink( $post_id ), like WordPress itself.

    And to initiate sharing, it uses the save_post_{$post->post_type} hook, with a priority of 20.

    So if you were to somehow overwrite post slugs whenever, e.g., the save_post or wp_insert_post hook runs, and thus after the hook Share on Mastodon uses, it could be there’s a kind of “conflict” there. Not really a “race condition,” but similar.

    Have you tried setting a delay? If it’s a prio thing, that actually may work. Just 60 seconds or so.

    If you use the Gutenberg editor but have not enabled the plugin’s “classic meta box” option, and you publish immediately, sharing to Mastodon doesn’t actually happen until the rest_after_insert_{$post->post_type} hook, which does run later in time, so that could indicate why it works in that case …

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘does not work on scheduled posts’ is closed to new replies.