-1

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("\1\3", "class=") ? "\0" : "")', to be a valid callback

Any Help would be appreciated.

Regards

IMSoP
  • 89,526
  • 13
  • 117
  • 169
  • Does this answer your question? [Replace preg\_replace() e modifier with preg\_replace\_callback](https://stackoverflow.com/questions/15454220/replace-preg-replace-e-modifier-with-preg-replace-callback) – IMSoP Jan 08 '21 at 10:52

1 Answers1

0

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.