Skip to content
Advertisement

WP-lightbox Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead

My plugin wp-lightbox evolution is showing me an error

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead

And when I replace that with preg_replace_callback I’m getting an error:

Warning: preg_replace_callback(): Requires argument 2, ‘stripslashes(strstr(“13”, “class=”) ? “” : “”)’, to be a valid callback

Any Help would be appreciated.

Regards

Advertisement

Answer

preg_replace with the /e modifier used to accept the PHP code as string.

preg_replace_callback accepts a callable. The function that preg_replace_callback should accept an array of matches and return the string to be used as a replacement.

If you don’t use this code anywhere else, it makes sense to use an anonymous function, like this:

preg_replace_callback(YOUR_PATTERN_HERE, function ($matches) {
  return stripslashes(
    strstr($matches[1] . $matches[3], "class=")
      ? $matches[0]
      : "");
}, YOUR_STRING_TO_BE_CHANGED_HERE);

See a question Replace preg_replace() e modifier with preg_replace_callback for more info.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement