Support » Plugin: Native Gettext for Wordpress » headers already sent in …

  • Resolved Carsten Bach

    (@carstenbach)


    This is really neat. Thank you @colinleroy!

    Only one warning reappears sometimes.
    PHP Warning: Cannot modify header information - headers already sent in .../plugins/native-gettext/classes/class-native-mo.php on line 119

    And right now I’m not able to reproduce triggering this warning. Unlikely.

    So I thought about, what could be the reason, had a look into line 119 and so on and came up with:

    add_filter( 'override_load_textdomain', array( $this, 'nltd_load_textdomain_override' ), 0, 3 );

    Because all of the plugins logic happens inside the running filter hook, we’re not allowed to output anything here, even headers. But what if you use wp_headers instead?

    I tested it replacing your existing line 119 by the following lines, what – indeed – is an ugly hack, but worked.

    add_filter( 'wp_headers', function ( array $headers ) : array
    {
        $headers[] = "X-Native-Gettext: 1";
        return $headers;
    } );

    What do you think?

    • This topic was modified 5 months, 3 weeks ago by Carsten Bach.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.