Created
March 19, 2014 11:07
-
-
Save aschanMarcus/9639539 to your computer and use it in GitHub Desktop.
Remove inline CSS from body fields in Drupal.
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
/** | |
* For removing inline CSS from body fields in Drupal. | |
* | |
* -Install devel module. | |
* -Navigate to devel/php. | |
* -Paste the following code and execute. | |
*/ | |
$results = db_select('field_data_body', 'f') | |
->fields('f', array('entity_id', 'body_value')) | |
->execute() | |
->fetchAll(); | |
foreach ($results as $result) { | |
$body = preg_replace('/(<[^>]*) style=("[^"]+"|\'[^\']+\')([^>]*>)/i', '$1$3', $result->body_value); | |
db_update('field_data_body') | |
->fields(array( | |
'body_value' => $body, | |
)) | |
->condition('entity_id', $result->entity_id) | |
->execute(); | |
} |
It would be a good idea to update field revisions as well.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!