Quicky

Fixing Notice: Function _load_textdomain_just_in_time was called incorrectly for WordPress 6.7 update


Since the WordPress version update 6.7.0, I ran into this notice Function _load_textdomain_just_in_time was called incorrectly. Normally it was indicating that it has something to do with including text-domain of the plugin using ‘plugin-loaded’ action hook. Unfortunately, it was not the case. The problem was caused by using the get_plugin_data() function too early, specifically inside the constructor of my plugin’s main class. Here’s how I fixed it.

What I Was Doing Before

I was directly calling get_plugin_data() in the constructor, like this:

if ( ! function_exists( 'get_plugin_data' ) ) {
    require_once ABSPATH . 'wp-admin/includes/plugin.php';
}

$this->version = get_plugin_data( __FILE__ )['Version'];

This caused notices because it’s not safe to call this function before WordPress is fully initialized.

The Fix

I created a separate function in my class to fetch plugin details only when needed:

public function get_plugin_details( $key = 'Version' ) {

    require_once ABSPATH . 'wp-admin/includes/plugin.php';

    $plugin_data = get_plugin_data( __FILE__, false, false );

    return $plugin_data[ $key ];
}

Then, I used this function wherever required:

this->plugin_name = $this->get_plugin_details( 'Name' );
self::$version     = $this->get_plugin_details();

Why It Works

By delaying the call to get_plugin_data() and using it only when necessary, I avoided notices and made my plugin more stable.

Conclusion

If you’re getting notices while using get_plugin_data(), avoid calling it in the constructor. Use a dedicated function to fetch the data when needed, and you’ll save yourself a lot of headaches!

WordPress
Remove Category or Tag Slug from url
There are currently no comments.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Hassan Raza