Make WordPress Core

Opened 10 years ago

Closed 9 years ago

#30779 closed defect (bug) (invalid)

Call to undefined function wp_json_encode()

Reported by: pento's profile 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)

#1 follow-up: @azaozz
10 years ago

In theory this is possible to happen because class.wp-scripts.php is included from script-loader.php which is included from wp-admin/load-scripts.php and wp-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 add define('CONCATENATE_SCRIPTS', false); or define('SCRIPT_DEBUG', true); to wp-config.php.

In practice this never happens as WP_Scripts::localize() is never called when class.wp-scripts.php is included from wp-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.

Last edited 10 years ago by azaozz (previous) (diff)

#2 in reply to: ↑ 1 ; follow-up: @dd32
10 years ago

Replying to azaozz:

This may happen because class.wp-scripts.php is included from script-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 call wp_json_encode()
  • wp-load.php includes wp-includes/functions.php on line 72, and wp-includes/script-loader.php on line 143, so wp_json_encode() should always be loaded.

#3 in reply to: ↑ 2 @azaozz
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 @pento
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 @nacin
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 @valendesigns
10 years ago

@nacin Should a second ticket be created to replace json_encode() with wp_json_encode()?

#7 @pento
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: @okulsayfam
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

Version 0, edited 9 years ago by okulsayfam (next)

#9 in reply to: ↑ 8 @SergeyBiryukov
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/.

Note: See TracTickets for help on using tickets.