im facing this error on my wordpress, im a totally beginner,
Fatal error: Uncaught Error: Call to undefined function json_decode()
in /home/livingth/public_html/wp-includes/functions.php:4629 Stack
trace: #0 /home/livingth/public_html/wp-includes/blocks.php(372):
wp_json_file_decode(‘/home/livingth/…’) #1
/home/livingth/public_html/wp-includes/blocks.php(487):
get_block_metadata_i18n_schema() #2
/home/livingth/public_html/wp-includes/blocks/legacy-widget.php(68):
register_block_type_from_metadata(‘/home/livingth/…’, Array) #3
/home/livingth/public_html/wp-includes/class-wp-hook.php(324):
register_block_core_legacy_widget(”) #4
/home/livingth/public_html/wp-includes/class-wp-hook.php(348):
WP_Hook->apply_filters(NULL, Array) #5
/home/livingth/public_html/wp-includes/plugin.php(517):
WP_Hook->do_action(Array) #6
/home/livingth/public_html/wp-settings.php(700): do_action(‘init’) #7
/home/livingth/public_html/wp-config.php(85):
require_once(‘/home/livingth/…’) #8
/home/livingth/public_html/wp-load.php(50):
require_once(‘/home/livingth/…’) #9
/home/livingth/public_html/wp-admin in
/home/livingth/public_html/wp-includes/functions.php on line 4629
And this is my script in cpanel > funtions.php starting from line 4629
$decoded_file = json_decode( file_get_contents( $filename ), $options['associative'] );
if ( JSON_ERROR_NONE !== json_last_error() ) {
wp_trigger_error(
__FUNCTION__,
sprintf(
/* translators: 1: Path to the JSON file, 2: Error message. */
__( 'Error when decoding a JSON file at path %1$s: %2$s' ),
$filename,
json_last_error_msg()
)
);
return $result;
}
return $decoded_file;
Hope you can guide me on this in a detailed solution.
Thank you in advance!
2
Answers
I see that the errors are caused in the core WordPress files, If your WordPress version is greater then 6 then, You can try replacing the core files with the same version which you are using. It will resolve the issue.
Changing the $wp_version does not replace the core files for the WordPress so the issue is not resolved.
I have used the HostGator hosting it had the easy option to replace the core files under the website settings.
If you have command line access to the website doc root then you can try running these, commands to replace the core files.
wp core version // This command checks the current version of your WordPress.
wp core download –version= –force //replaces the core file for the wordpress site.
Make sure you run these command where you have your website doc root (example public_html which is the default doc root ), also do take a backup of the database before you run these command as some times wrong core files replacement may damage the data files.
Once this is done, To check if the issue is resolved for the website please access the website in the incognito window as the normal window might still show the error because of the cache.