Error “Call to a member function switch_to_locale() on null” during insert_with_markers

Having an issue with my plugin updating the htaccess file. The code I used to do that is:

insert_with_markers($htaccess_file, $marker, $lines);

The parameters used in that function have been previously defined properly. There error message is:

Uncaught Error: Call to a member function switch_to_locale() on null
in /home2/path/to/site/fstraptest/wp-includes/l10n.php:1582

I tried ensuring that various functions used by switch_to_locale() are loaded:

if (! function_exists(‘get_home_path’))
{include_once(ABSPATH . ‘wp-admin/includes/file.php’);}
if (! function_exists(‘insert_with_markers’))
{include_once(ABSPATH . ‘wp-admin/includes/misc.php’);}
if (! function_exists(‘switch_to_locale’))
{
include_once(ABSPATH . ‘wp-admin/includes/l10n.php’);
include_once(ABSPATH . ‘wp-includes/class-wp-locale-switcher.php’);
}
if (! function_exists(‘got_mod_rewrite’))
{include_once(ABSPATH . ‘wp-admin/includes/misc.php’);}
if (! function_exists(‘is_multisite’))
{include_once(ABSPATH . ‘wp-admin/includes/load.php’);}

But that didn’t solve the issue.

This is with WP 5.3, PHP 7.3.11 . Similar code has worked before; this may have started with WP 5.3, but not sure.

The googles have not helped with this error. The language for the site is “en-US”. The plugin does not have any language files. Theme has been changed to “Twenty-Thirteen”; error also occurs in other themes, so does not appear theme-dependent.

Read more here:: Error “Call to a member function switch_to_locale() on null” during insert_with_markers

Leave a Reply

Your email address will not be published. Required fields are marked *