Opened 10 years ago
Closed 9 years ago
#30779 closed defect (bug) (invalid)
Call to undefined function wp_json_encode()
Reported by: | pento | Owned by: | |
---|---|---|---|
Milestone: | Priority: | low | |
Severity: | minor | Version: | 4.1 |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
There seem to be some circumstances where class.wp-scripts.php
is loaded without functions.php
, which causes this error:
Fatal error: Call to undefined function wp_json_encode() in wp-includes/class.wp-scripts.php on line 186
When this happens, it causes the entire front end of a site to fail. Some examples.
Change History (9)
#2
in reply to:
↑ 1
;
follow-up:
↓ 3
@
10 years ago
Replying to azaozz:
This may happen because
class.wp-scripts.php
is included fromscript-loader.php
I don't think this is the case.
The only use (and the error here) is from the localize script printer, which should never be hit on those requests.
It's worth mentioning that load-(scripts|styles).php
does include a no-op json_encode()
compat method that should be altered to wp_json_encode()
though.
I suspect this may be from an install on which wp-includes/functions.php
didn't get updated, there's a handful of cases every release where similar issues happen.
My reasoning is:
- Only three locations include
script-loader.php
, those are:wp-load.php
,wp-admin/load-styles.php
,wp-admin/load-scripts.php
wp-admin/load-styles.php
&wp-admin/load-scripts.php
won't callwp_json_encode()
wp-load.php
includeswp-includes/functions.php
on line 72, andwp-includes/script-loader.php
on line 143, sowp_json_encode()
should always be loaded.
#3
in reply to:
↑ 2
@
10 years ago
Replying to dd32:
Right, just realized that and edited the above comment :) Same conclusion though: most likely something went wrong while upgrading.
#4
@
10 years ago
Agreed, it seems to be bad upgrades. See this forum discussion:
http://forum.wpde.org/installation/136899-probleme-beim-upgrade-auf-4-1-a.html
Summary: clicking the Update button caused this error twice, manually FTPing a fresh copy of WordPress fixed it.
Interestingly, all of the sites with this error seem to be non-English, though with no other pattern. I've seen German, Polish, Arabic and Indonesian.
#5
@
10 years ago
- Milestone changed from Awaiting Review to 4.2
- Priority changed from high to low
- Severity changed from major to minor
Yeah, I have a feeling this is happening on regular frontend hits, not even load-scripts.php hits, and is simply due to a bad upgrade.
Let's see if the no-op json_encode() in load-scripts.php needs to be changed to wp_json_encode() or can simply be removed.
#6
@
10 years ago
@nacin Should a second ticket be created to replace json_encode()
with wp_json_encode()
?
#7
@
10 years ago
- Milestone 4.2 deleted
- Resolution set to invalid
- Status changed from new to closed
There've been a few support forum threads for this, they've all been resolved by manually upgrading - it looks like there were some bad upgrades happening.
We don't need to do anything with wp_json_encode()
, so closing this ticket.
#8
follow-up:
↓ 9
@
9 years ago
- Resolution invalid deleted
- Status changed from closed to reopened
how did you solved? i am face to face same problem
my wp 4.2.1
#9
in reply to:
↑ 8
@
9 years ago
- Resolution set to invalid
- Status changed from reopened to closed
Replying to okulsayfam:
i had selected all plugins and disable but suddenly i face to face a white screen. my web side is crashed
Please try the support forums: https://wordpress.org/support/.
In theory this is possible to happen because
class.wp-scripts.php
is included fromscript-loader.php
which is included fromwp-admin/load-scripts.php
andwp-admin/load-styles.php
. Both of these run "outside" of WordPress and don't load functions.php. If that is ever triggered a workaround would be to adddefine('CONCATENATE_SCRIPTS', false);
ordefine('SCRIPT_DEBUG', true);
to wp-config.php.In practice this never happens as
WP_Scripts::localize()
is never called whenclass.wp-scripts.php
is included fromwp-admin/load-scripts.php
.Even if it did happen, this won't bring the site down. It will fail to output concatenated scripts or styles in the admin. Looking at the only report in the forum, this sounds more like a failed upgrade.