• Hi,

    I have a post type that I convert all titles to uppercase with below filter, works with the post type and it worked before Gutenberg, but now the Gutenberg editor wont save any pages, post until I remove the filter. AND I dont understand why, any ideas?

    This is what I use:

    /**
    * Change title to upper case on save
    */
    add_filter( ‘wp_insert_post_data’, function( array $data ) {

    $screen = get_current_screen();

    if ( “my_custom_post” == $screen->post_type ){
    // list of words not to change
    $protected_words = [
    ‘SQL’,
    ‘CSS’,
    ‘BBC’
    ];

    if ( empty( $data[‘post_title’] ) )
    return $data;

    $words = explode( ‘ ‘, $data[‘post_title’] );

    $words = array_map( function( $word ) use ( $protected_words ) {
    return in_array( $word, $protected_words )
    ? $word
    : mb_strtoupper( $word, ‘UTF-8’ );
    }, $words );

    // There is no mb_ucfirst()
    $words[0] = mb_convert_case( $words[0], MB_CASE_UPPER, “UTF-8”);

    $data[‘post_title’] = join( ‘ ‘, $words );

    return $data;
    }
    else{
    return $data;
    }
    });

The topic ‘wp_insert_post_data, Publishing failed’ is closed to new replies.