Created
July 27, 2015 20:36
-
-
Save daggerhart/ef28ee65e75328fa5a07 to your computer and use it in GitHub Desktop.
WordPress post data cleanup. Very basic.
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
<?php | |
/** | |
* Example of using wp_kses() to clean up WordPress post data. | |
*/ | |
function __cleanup_post_data(){ | |
global $wpdb; | |
// default wordpress "allowed html" for posts | |
$allowed_tags = wp_kses_allowed_html( 'post' ); | |
// posts | |
$posts = $wpdb->get_results('SELECT ID,post_content,post_excerpt FROM wp_posts WHERE post_content like "%style%" OR post_excerpt like "%style%"'); | |
foreach( $posts as $i => $post ){ | |
// clean content | |
$post->post_content = wp_kses( $post->post_content, $allowed_tags ); | |
// clean excerpt | |
$post->post_excerpt = wp_kses( $post->post_excerpt, $allowed_tags ); | |
// update row in the db with new values | |
$update_sql = $wpdb->prepare("UPDATE {$wpdb->posts} SET post_content = %s, post_excerpt = %s WHERE ID = %d", | |
$post->post_content, | |
$post->post_excerpt, | |
$post->ID ); | |
$wpdb->query( $update_sql ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment