0

I am working on a Wordpress site and recently I have begun getting this warning:

Warning: preg_match() [function.preg-match]: Unknown modifier '-'

It started when I changed the permalink structure to /%postname%/, which is needed for BuddyPress to function. If use the default permalink structure, the problem goes away.

Here is the code from the wp-includes/class-wp.php where the error is occurring:

if ( preg_match("#^$match#", $request_match, $matches) ||
 preg_match("#^$match#", urldecode($request_match), $matches) ) {
PeeHaa
  • 71,436
  • 58
  • 190
  • 262

2 Answers2

1

this is because - and / are special symbols, you can change this code to:

if ( preg_match("/^".preg_quote($match)."/", $request_match, $matches) ||
 preg_match("/^".preg_quote($match)."/", urldecode($request_match), $matches) ) {

but I assume that problem is somewhere deeper, in core logic of wp

Iłya Bursov
  • 23,342
  • 4
  • 33
  • 57
0

Without the $match variable content it is difficult to know what the problem is, but if you obtain this warning, it's because $match contains #- (i.e. the pattern delimiter used and the - character). Then all characters after this # are seen as modifiers.

You can try to change the delimiter (and pray) to ~:

if ( preg_match("~^$match~", $request_match, $matches) ||
preg_match("~^$match~", urldecode($request_match), $matches) ) {

If it doesn't work try other delimiters.

Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125