function layotter_make_search_dump($data, $raw_post) { $post_id = $raw_post['ID']; // don't change anything if not editing a Layotter-enabled post if (!Layotter::is_enabled_for_post($post_id) or !isset($raw_post['layotter_json'])) { return $data; } // copy JSON from POST and strip slashes that were added by Wordpress $json = $raw_post['layotter_json']; $unslashed_json = stripslashes_deep($json); // turn JSON into post content HTML $layotter_post = new Layotter_Post($unslashed_json); $content = $layotter_post->get_frontend_view(); // save JSON to a custom field (oddly enough, Wordpress breaks JSON if it's stripslashed) update_post_meta($post_id, 'layotter_json', $json); // insert spaces to prevent <p>foo</p><p>bar</p> becoming "foobar" instead of "foo bar" // then strip all tags except <img> // then remove excess whitespace $spaced_content = str_replace('<', ' <', $content); $clean_content = strip_tags($spaced_content, '<img>'); $normalized_content = trim($clean_content); if (function_exists('mb_ereg_replace')) { $normalized_content = mb_ereg_replace('/\\s+/', ' ', $normalized_content); } // wrap search dump with a [layotter] shortcode and return modified post data to be saved to the database // add the post ID because otherwise the shortcode handler would have no reliable way to get the post ID through // which the JSON data will be fetched $shortcoded_content = '[layotter post="' . $post_id . '"]' . $normalized_content . '[/layotter]'; $data['post_content'] = $shortcoded_content; return $data; }
function layotter_disable_wpautop($content) { if (Layotter::is_enabled_for_post(get_the_ID())) { remove_filter('the_content', 'wpautop'); } return $content; }