Created
July 16, 2016 22:40
-
-
Save ncserny/6184f32e74af6615cfc49fc84288f21e to your computer and use it in GitHub Desktop.
WordPress Instant Articles Sanitize Post
This file contains hidden or 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 | |
// Sanitizing / replace the table shortcode with the table before the post gets transformed to IA. | |
add_action('instant_articles_before_transform_post', function () { | |
add_filter('the_content', 'sanitize_content_for_ia'); | |
}); | |
function sanitize_content_for_ia($content) { | |
if (in_category(array('videos', 'mehrseitig'))) { | |
$content = preg_replace('@\[sam id=.*?\]@', '', $content); // sam id repalcement | |
$shortcode_pattern = '@\[table id=\s*(\d+).*?\]@'; // Pattern to match the [table id=N /] | |
$matches = array(); | |
// replacment if table shortcode found | |
if (preg_match_all($shortcode_pattern, $content, $matches)) { | |
if (isset($matches[1]) && !empty($matches[1])) { | |
$table_ids = $matches[1]; | |
$table_data = replace_table_shortcode_with_table($content, $table_ids); | |
$content = $table_data; // table + content | |
} | |
} | |
$content = sanitize_post_content($content); | |
} | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment