/**
 * Return a block
 *
 * @param string $name The name of the block
 *
 * @return string
 */
function get_the_block($name)
{
    if (!empty($name)) {
        $post = mcb_get_post();
        $filename = explode('.', basename($post->page_template))[0];
        $manifest = sprintf('%s/mu-plugins/content-blocks/%s.json', WP_CONTENT_DIR, $filename);
        if (file_exists($manifest)) {
            $args = (array) json_decode(file_get_contents($manifest), true);
        }
        $meta = get_post_meta($post->ID, '_mcb-' . sanitize_title($name), true);
        if (isset($args['apply_filters']) && $args['apply_filters']) {
            return apply_filters('the_content', $meta);
        }
        if ($meta && 0 < count($meta)) {
            return htmlentities($meta, null, 'UTF-8', false);
        }
    }
    return '';
}
示例#2
0
/**
 * Reset which blocks are used when visiting the page
 */
function mcb_refresh_blocks()
{
    $post = mcb_get_post();
    if (isset($post)) {
        delete_post_meta($post->ID, '_mcb-blocks');
    }
}