Currently I’m using a small search and replace snippet for one of my WordPress sites:
if ( ! function_exists( 'cor_remove_personal_options' ) ) {
function cor_remove_personal_options( $subject ) {
$pattern = '#<h3>Personal Options</h3>.+?/table>#s';
$subject = preg_replace( $pattern, '', $subject, 1 );
return $subject;
}
function cor_profile_subject_start() {
ob_start( 'cor_remove_personal_options' );
}
function cor_profile_subject_end() {
ob_end_flush();
}
}
add_action( 'admin_head-profile.php', 'cor_profile_subject_start' );
add_action( 'admin_footer-profile.php', 'cor_profile_subject_end' );
Being relatively new with preg_replace I was wondering about the exact functionality of the opening and closing number signs # #s.
I was wondering if someone could perhaps explain this to me?
You can use / as opening and closing characters or #. If you use #, then the slash will not be taken as a special character, so this will be valid too escaping the slash character:
/s or #s means a modifier, telling to PHP that any dot in the regular expression will be evaluated as any character, including new lines.