PhilD123 Posted January 14, 2017 Share Posted January 14, 2017 I am getting the following warning on my wordpress website after doing an update. Warning: preg_replace_callback(): Requires argument 2, 'stripslashes(strstr("\1", "columns=\"$columns\"") ? "\1" : "[gallery \2 \4 columns=\"$columns\"]")', to be a valid callback I have a very basic PHP knowledge and need to get rid of this warning quickly so any help will be greatly appreciated. Below is the code: //FORCE GALLERY TO HAVE NO LINE BREAKS, allows for max columns.. function gallery_columns($content){$columns = 0;$pattern = array('#(\[gallery(.*?)columns="([0-9])"(.*?)\])#ie','#(\[gallery\])#ie', '#(\[gallery(.*?)\])#ie');$replace = 'stripslashes(strstr("\1", "columns=\"$columns\"") ? "\1" : " [gallery \2 \4 columns=\"$columns\"]")';return preg_replace_callback($pattern, $replace, $content); } Please Help Quote Link to comment https://forums.phpfreaks.com/topic/302932-warning-preg_replace_callback-requires-argument-2-%E2%80%A6-to-be-a-valid-callback/ Share on other sites More sharing options...
codefossa Posted January 15, 2017 Share Posted January 15, 2017 Your parameters aren't quite right for preg_replace_callback(). <?php $new_str = preg_replace_callback('/regexp/', function($m) { // $m is an array of the current match }, $str); ?> Quote Link to comment https://forums.phpfreaks.com/topic/302932-warning-preg_replace_callback-requires-argument-2-%E2%80%A6-to-be-a-valid-callback/#findComment-1541396 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.