Skip to:
Content

Opened 4 years ago

Closed 4 years ago

#5701 closed defect (bug) (fixed)

like_escape() is deprecated as of WP 4.0

Reported by: boonebgorges Owned by: boonebgorges
Milestone: 2.1 Priority: normal
Severity: normal Version:
Component: Core Keywords: has-patch
Cc:

Description

See https://core.trac.wordpress.org/ticket/10041 and https://core.trac.wordpress.org/changeset/28711

It's causing our Travis CI trunk builds to due due to unexpected deprecated notices: https://travis-ci.org/buddypress/BuddyPress/builds/27215588

For the moment, I'm going to mark these tests with expectedDeprecated, so we can get our build passing again.

For 2.1, we should have a proper solution. Given that the function is deprecated *and* its replacement is introduced in 4.0, we can't just swap it out (and still support earlier versions of WP). So either:

  1. We do nothing and just live with the deprecated notices, at least until we drop support for WP < 4.0
  2. We create a wrapper function bp_esc_like() that does the necessary check

As much as I find the latter option unpleasant, I think it's probably the right way to go. Feedback welcome.

Attachments (1)

5701.patch (42.1 KB) - added by boonebgorges 4 years ago.

Download all attachments as: .zip

Change History (12)

#1 @boonebgorges
4 years ago

See r8496 for expectedDeprecated flags.

#2 @boonebgorges
4 years ago

In 8497:

expectedDeprecated like_escape flags for multisite-only tests

See #5701

#3 @boonebgorges
4 years ago

So, it turns out that adding the @expectedDeprecated flags fixes the build for trunk, but actually breaks it for older versions where the function is not in fact deprecated. I'm going to revert r8496 and r8497 and we'll just have to live with failing builds for a while, until we have a real solution.

#4 @boonebgorges
4 years ago

In 8499:

Remove @expectedDeprecated like_escape flags from unit tests

This was intended to be a workaround for #5701, but it turns out that it breaks
non-trunk builds.

Reverts r8496 and r8497.

See #5701

#6 @boonebgorges
4 years ago

In 8506:

Add some search_terms related tests. See #5701

#7 @boonebgorges
4 years ago

In 8507:

Add search_terms test for BP_Notifications_Notification::get()

See #5701

#8 @boonebgorges
4 years ago

  • Keywords has-patch added

5701.patch adds the proposed bp_esc_like() wrapper function, and implements throughout BuddyPress. For the most part, this was fairly straightforward, though there were a few places where query structure had to be rearranged to make sure that strings like LIKE '%foo%' weren't getting run through $wpdb->prepare() again (which would strip the % marks).

I've written unit tests for all instances of like_escape() that weren't already covered (see r8506, r8506), with the exception of those that are specific to bbPress 1.x (I don't feel much like figuring out how to install bbPress during automated testing).

I'd like to have a sanity check from another dev that this is the route we want to take before committing the changes. As I see it, this is kinda our only choice.

@boonebgorges
4 years ago

#9 @boonebgorges
4 years ago

I haven't heard from any other devs, but I've heard it through the grapevine that WP is going ahead with the current changes for 4.0, so I think we have no choice but to adopt the patch I've put here. I'm going to commit it (so we can get our CI tests passing again) and if anyone has an issue with the nature of the fix, we can have another look at it.

#10 @johnjamesjacoby
4 years ago

Sounds good to me.

#11 @boonebgorges
4 years ago

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

In 8541:

Refactor all uses of like_escape() to use bp_esc_like()

WordPress 4.0 will deprecate like_escape(), due to a history of inconsistent
documentation and usage. Its replacement is a new method, $wpdb->esc_like(),
which will be available only in WP 4.0. For this reason, and because the
return value of $wpdb->esc_like() will not always be identical to that of
like_escape(), BP cannot do a straight swap of the old function for the new
one. Instead, we introduce a wrapper function that uses the core method if
available, and otherwise reproduces the logic of that method (for earlier
versions of WordPress).

Fixes #5701
slightly different syntax in some cases

Note: See TracTickets for help on using tickets.