Exemplo n.º 1
0
/**
 * Returns the block template data using a block unique identifier. This
 * identifier is made from the block path relative to the app directory.
 * @function wpb_block_template_by_buid
 * @since 0.1.0
 */
function wpb_block_template_by_buid($buib)
{
    static $block_template_infos = null;
    if ($block_template_infos == null) {
        $block_template_infos = wpb_block_template_infos();
    }
    foreach ($block_template_infos as $block_template_info) {
        if ($block_template_info['buid'] == $buib) {
            return $block_template_info;
        }
    }
    return null;
}
Exemplo n.º 2
0
        return $page_block['post_id'] != $post_id;
    });
    update_post_meta($page_id, '_page_blocks', $page_blocks);
    wp_delete_post($post_id);
});
//------------------------------------------------------------------------------
// ACF
//------------------------------------------------------------------------------
/**
 * @filter acf/settings/load_jsonk
 * @since 0.1.0
 */
add_filter('acf/settings/load_json', function ($paths) {
    static $block_template_infos = null;
    if ($block_template_infos == null) {
        $block_template_infos = wpb_block_template_infos();
    }
    foreach ($block_template_infos as $block_template_info) {
        $paths[] = $block_template_info['path'] . '/fields';
    }
    return $paths;
});
/**
 * @filter acf/get_field_groups
 * @since 0.1.0
 */
add_filter('acf/get_field_groups', function ($field_groups) {
    if (get_post_type() != 'block') {
        return;
    }
    $post_id = $_GET['post'];
Exemplo n.º 3
0
    }
    foreach ($block_template_infos as $block_template_info) {
        $paths[] = $block_template_info['path'] . '/fields';
    }
    return $paths;
});
/**
 * @filter acf/get_field_groups
 * @since 1.0.0
 */
add_filter('acf/get_field_groups', function ($field_groups) {
    if (isset($_GET['post_status']) && $_GET['post_status'] === 'sync') {
        return $field_groups;
    }
    if (get_post_type() != 'wpb-block') {
        $page_blocks = wpb_block_template_infos();
        foreach ($page_blocks as $page_block) {
            $block_template = wpb_block_template_by_buid($page_block['buid']);
            if ($block_template == null) {
                continue;
            }
            $path = $block_template['path'];
            foreach ($block_template['fields'] as $json) {
                $json['ID'] = null;
                $json['style'] = 'seamless';
                $json['position'] = 'normal';
                $json['location'] = array(array(array('param' => 'post_type', 'operator' => '==', 'value' => 'block')));
                $field_groups[] = $json;
            }
        }
        return $field_groups;
Exemplo n.º 4
0
/**
 * @function wpb_block_metabox
 * @since 1.0.0
 */
function wpb_block_metabox()
{
    foreach (wpb_block_context() as $post_type) {
        add_meta_box('wpb_block_metabox', wpb_block_metabox_title($post_type), function () {
            $block_template_infos = wpb_block_template_infos();
            $block_template_paths = wpb_block_template_paths();
            $filter = function ($page_block) {
                return wpb_block_template_by_buid($page_block['buid']);
            };
            $page_blocks = wpb_get_blocks(get_the_id());
            if ($page_blocks) {
                $page_blocks = array_filter($page_blocks, $filter);
            }
            $categories = array();
            foreach ($block_template_infos as $block_template_info) {
                $categories[$block_template_info['category']] = array();
            }
            foreach ($block_template_infos as $block_template_info) {
                $categories[$block_template_info['category']][] = $block_template_info;
            }
            ksort($categories);
            $pages = wp_list_pages(array('title_li' => '', 'echo' => false, 'walker' => new WPB_Walker_Page()));
            $data = Timber::get_context();
            $data['pages'] = $pages;
            $data['categories'] = $categories;
            $data['page_blocks'] = $page_blocks;
            $data['block_template_infos'] = $block_template_infos;
            $data['block_template_paths'] = $block_template_paths;
            Timber::render('block-metabox.twig', $data);
        }, $post_type, 'normal', wpb_block_metabox_priority($post_type));
        add_filter('postbox_classes_' . $post_type . '_wpb_block_metabox', function ($classes = array()) {
            $classes[] = 'wpb-postbox';
            $classes[] = 'seamless';
            return $classes;
        });
    }
}