preg_replace specific Text to small latter strtolower [closed]

function emailleftappend($content){ $content = preg_replace_callback(‘/(?<=get\/)(.*?)-(.*?)(?=\/”>)/’, function ($m) { return sanitize_title($m[1]). ‘-‘. sanitize_title($m[2]); }, $content); return $content; } add_filter(‘the_content’, ’emailleftappend’); the above fixed the issue for me. another way is below. function emailleftappend($content){ $content = preg_replace_callback(‘/(?<=get\/)(.*?)-(.*?)(?=\/”>)/’, function ($m) { return slug($m[1]). ‘-‘. slug($m[2]); }, $content); return $content; } add_filter(‘the_content’, ’emailleftappend’); function slug($z){ $z = strtolower($z); $z … Read more

Test for IP in Array Always Fails on First IP

There are two pieces to this code: 1) Interpreting the list of allowed IPs from a textarea, delimited by newline character, and 2) Checking if a given user’s IP is in the allowed list of IPs. Part 1) Parse list of IPs delimited by newline character, and trim whitespace: $_POST[‘allowed_ips’] = ” 67.6.134.102 97.118.69.236 “; … Read more

Alphanumeric usernames and error message for it

Check for alphanumeric For more details, look at the regex Q on SO. $name=”input string 123″; // Doesn”t allow: // Pre-/Appending white space // Not more than one space in between // Non-alphanumeric characters (lower case) if( ! preg_match( “/^[a-z0-9]+([\\s]{1}[a-z0-9]|[a-z0-9])+$/i”, $name ) ) { // Output Error Message } // Or: Does only allow // … Read more

Dynamically append custom post type to end of url

Here is something I came up with to solve this exact problem. add_action(‘wp_list_categories’,’example_wp_list_categories’); function example_wp_list_categories($output) { global $post; foreach (get_categories() as $cat) { if (preg_match(“/\/category\/$cat->slug\//”, $output)) { $output = str_replace(‘/category/’ . $cat->slug . “https://wordpress.stackexchange.com/”, ‘/category/’ . $cat->slug . ‘/?post_type=” . $post->post_type, $output); } } return $output; } Regex isn”t a strong point of mine, so … Read more