String regex match replace for role ‘contributor’ only

There’s author_can() for that: add_action( ‘loop_start’, ‘wpse105294_nofollow_author’ ); function wpse105294_nofollow_author() { ! author_can( $GLOBALS[‘post’]->ID, ‘edit_others_posts’ ) AND add_filter( ‘the_content’, ‘cn_nf_url_parse’); } So you only add that filter callback for authors and other roles that don’t have the possibility to edit_others_posts. By default this is Subscriber and Author. For more info, take a look at the … Read more

Custom rewrite_rules – only pass numbers and not alphabetic characters

Instead of index.php/reco/?b=$1, try this: “$wp_rewrite->index?pagename=reco&b=” . $wp_rewrite->preg_index( 1 ) You should also append a $ to your reco/([^/]*)/? regex to ensure the rule only matches the entire path, and not just the beginning. Then flush your rules afterwards (just re-save your permalink settings in admin). Update: Try using the page_rewrite_rules filter instead, and use … Read more

Modify Image Source With The_Content Filter?

Let’s give it a try: $str=”<img src=”http://myserver.mydomain/picture.png” />”; $pattern =’#<img src=”http://.*/(.*)” />#’; $replace=”<img src=”http://http://i0.wp.com/$1?quality=70&strip=all />””; $result = preg_replace($pattern, $replace, $str); The $pattern is quite simple and very specific. You might need to generalize it a bit more but it should show you the direction to go. E.g. it takes no care of possible whitespace. A … Read more

optimize wordpress rewrite rule regex

With all part optional with ?, you obtain one rule to rule them all : add_rewrite_rule( ‘^cities/(.*)/(browse)?/?(.*)?/?(.*)?/?(.*)?/?(.*)?/?’, ‘index.php?city_name=$matches[1]&cat_name[]=$matches[3]&cat_name[]=$matches[4]&cat_name[]=$matches[5]’, ‘top’ ); but the [] cannot work with the WordPress logic then you need to define the rewrite tag with a number. try that : add_rewrite_tag(“%cat_name.%”, “([^&]+)”); add_rewrite_rule( ‘^cities/([^/]*)/(browse)?/?([^/]*)?/?(^/)?/?([^/]*)?/?([^/]*)?/?’, ‘index.php?city_name=$matches[1]&cat_name1=$matches[3]&cat_name2=$matches[4]&cat_name3=$matches[5]’, ‘top’ );