WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#11827 closed defect (bug) (fixed)

json_encode and json_decode functions in compat.php do not safely include class-json.php

Reported by: alexkingorg Owned by:
Milestone: 3.0 Priority: high
Severity: major Version: 2.9
Component: General Keywords: has-patch commit
Focuses: Cc:

Description

The implementation of the json_encode and decode compatibility functions is incompatible with plugins that already included the Services_JSON class (such as my Twitter Tools plugin).

Though I wrapped the inclusion of the Services_JSON in a check in my plugin to try to keep it from being loaded twice, the conditional loading of class-json.php from compat.php happens after plugins is loaded and creates a fatal error by declaring the class a second time.

Attached are two patches, one that patches the class file in the same way class-snoopy.php handles this (recommended), the other patches compat.php.

Unfortunately, since this is in the wild already I believe plugin/theme developers will need to work around this. Suggestion to plugin/theme devs: do the same function definition approach that is in WP 2.9 rather than version sniffing.

Attachments (3)

patch-class-json.diff (418 bytes) - added by alexkingorg 4 years ago.
Patch to avoid double-declaration of Services_JSON class
patch-compat.diff (733 bytes) - added by alexkingorg 4 years ago.
More careful inclusion of Services_JSON in compat.php
patch.2.diff (1.1 KB) - added by alexkingorg 4 years ago.
Standardized conditional loading in the library file for Services_JSON, SimplePie and Snoopy

Download all attachments as: .zip

Change History (13)

alexkingorg4 years ago

Patch to avoid double-declaration of Services_JSON class

alexkingorg4 years ago

More careful inclusion of Services_JSON in compat.php

comment:1 nacin4 years ago

I think this makes sense for compat.php, not in class-json.php, though it should be using class_exists().

comment:2 alexkingorg4 years ago

I prefer class_exists better too, but was using the code used elsewhere in WP under the assumption is was preferred for some reason. Patching the class file means every plugin/theme doesn't have to do the check, which is nice.

comment:3 azaozz4 years ago

Seems that get_declared_classes() returns the classnames as lowercase in PHP4 and with normal capitalization in PHP5. Perhaps better to use class_exists() in Snoopy too.

comment:4 alexkingorg4 years ago

Ok, here is a new patch that uses class_exists for Services_JSON, Snoopy and SimplePie.

alexkingorg4 years ago

Standardized conditional loading in the library file for Services_JSON, SimplePie and Snoopy

comment:5 scribu4 years ago

  • Keywords has-patch added
  • Milestone changed from Unassigned to 3.0

comment:6 scribu4 years ago

  • Version set to 2.9

comment:7 scribu4 years ago

  • Keywords commit added

comment:8 azaozz4 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [12705]) Safely include class-json.php, class-simplepie.php and class-snoopy.php, props alexkingorg, fixes #11827

comment:9 seanklein4 years ago

Please apply this to the 2.9 Branch.

comment:10 nacin4 years ago

This was introduced in 2.9, so applying this to 2.9 does make some sense. Isn't there a way around the fatal error though?

Note: See TracTickets for help on using tickets.