Created
July 10, 2018 10:15
-
-
Save nikitasinelnikov/e9f2dd69862965e507d4fd913f5fff76 to your computer and use it in GitHub Desktop.
Change roles by regexp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$posts = get_posts( array( | |
'numberposts' => -1, | |
'post_type' => 'any', | |
'post_status' => 'publish' | |
) ); | |
foreach ( $posts as $post ) { | |
$content = preg_replace_callback( "/(\[um_show_content roles=\')(.*?)(\'\])/im", "um_custom_change_show_content_roles", $post->post_content ); | |
$post->post_content = $content; | |
wp_update_post(array( | |
'ID' => $post->ID, | |
'post_content' => $post->post_content | |
)); | |
} | |
function um_custom_change_show_content_roles( $matches ) { | |
$roles = $matches[2]; | |
$roles = explode( ',', $roles ); | |
$roles = array_map( function( $item ) { | |
return 'um_' . $item; | |
}, $roles ); | |
$roles = implode( ',', $roles ); | |
return $matches[1]. $roles . $matches[3]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment