preg_replace regex problem

I finally got it figured out. In order to see the content that I was trying to edit, I turned on debugging in wp-config.php: define(‘WP_DEBUG’, true); // set true if ( WP_DEBUG ) { define(‘WP_DEBUG_LOG’, ‘../logs/debug.log’ ); define(‘WP_DEBUG_DISPLAY’, false); // don’t display errors on pages @ini_set( ‘display_errors’, 0 ); } Then, in the function that … Read more

How to redirect Webp files?

If I’m reading it right, your regex has only two items in (), which means that only $1 and $2 have any meaning. I copied your sample text and went to https://regex101.com/ (note: this is not an endorsement) to try to assemble a regex that’ll cover all your images. Here’s what I ended up with: … Read more

Register GET REST API route with multiple parameters

You don’t need to include query parameters in the endpoint. Just the path: register_rest_route( ‘myplugin/v1’, ‘/posts’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘my_rest_function’, ‘permission_callback’ => ‘__return_true’, ‘args’ => array( ‘number’ => array( ‘validate_callback’ => function( $param, $request, $key ) { return is_numeric( $param ); } ), ‘offset’ => array( ‘validate_callback’ => function( $param, $request, $key … Read more

Preg_Match(): compilation failed unknown property name

Xan is a georgian letter as I can find in Google, but it’s not a valid Unicode Script for RegEx, you can find a list of the Unicode Scripts here: http://www.regular-expressions.info/unicode.html Maybe try using another one than Xan, maybe Georgian: preg_match( ‘/[\p{Georgian}]/u’, $content, $results ); Let me know how that goes.

Using preg_replace() with the_content filter

Turns out I had multiple problems, @bonger pointed out the first one and then I found and solved issues with the global flag on the regular expression not being valid in php and me not accounting for links without a / after the .com. Final fix looks like this: add_filter(‘the_content’, ‘linkAppend’); function linkAppend($content) { global … Read more

rest api endpoint – accept diacritic characters

Looks to me like WordPress doesn’t enable UTF-8 mode when it runs the regex. https://github.com/WordPress/WordPress/blob/5.2.1/wp-includes/rest-api/class-wp-rest-server.php#L837 In PHP, matching multibyte characters requires the u flag. (The code above just adds the case-insensitive flag). So although some strings will still match (like “Département”), they’re not matching as whole Unicode characters. For example the following pattern matches when … Read more

Adding span tags to post titles using regex

It’s nice to use regex, but you can also achieve the same thing here by just splitting the string on ‘:’ with explode e.g.: $matches = explode(“:”, get_the_title()) ; if (count($matches) == 2) { $result = “foo bar $matches[0] foo bar $matches[1]”; } else { // case with no : in title $result = “foo … Read more

get_users meta_query: REGEXP not working for matching new lines

I found the problem and also fixed a bug in the regex. Final code: ‘meta_query’ => array( array( ‘key’ => ‘my_meta_field’, ‘value’ => “(^|\n|\r\n)99999($|\n|\r\n)”, ‘compare’ => ‘REGEXP’, ), ), The problem here was WordPress was adding extra backslashes on the special characters. By wrapping the expression in double quotes, this problem was solved. Also added … Read more