예제 #1
0
    $into_id = $_POST['into_id'];
    $area_id = $_POST['area_id'];
    if (wpb_block_template_by_buid($buid) == null) {
        return;
    }
    $post_id = wp_insert_post(array('post_parent' => $page_id, 'post_type' => 'wpb-block', 'post_title' => sprintf('Page %s : Block %s', $page_id, $buid), 'post_content' => '', 'post_status' => 'publish'));
    $page_blocks = wpb_get_blocks($page_id);
    if ($page_blocks == null) {
        $page_blocks = array();
    }
    $page_block = array('buid' => $buid, 'area_id' => $area_id, 'post_id' => (int) $post_id, 'page_id' => (int) $page_id, 'into_id' => (int) $into_id);
    $page_blocks[] = $page_block;
    update_post_meta($page_id, '_wpb_blocks', $page_blocks);
    $post = get_post($page_id);
    setup_postdata($post);
    wpb_render_block_preview($buid, $post_id, $page_id);
    exit;
});
/**
 * Moves a block to another page.
 * @action wp_ajax_move_page_block
 * @since 1.0.0
 */
add_action('wp_ajax_move_page_block', function () {
    $source_page_id = $_POST['source_page_id'];
    $source_post_id = $_POST['source_post_id'];
    $target_page_id = $_POST['target_page_id'];
    $source_page_blocks = wpb_get_blocks($source_page_id);
    $target_page_blocks = wpb_get_blocks($target_page_id);
    if ($source_page_blocks == null) {
        $source_page_blocks = array();
예제 #2
0
/**
 * @function wpb_render_block_area
 * @since 0.3.0
 */
function wpb_render_block_area($area_id)
{
    $block = Block::get_current();
    if ($block == null) {
        return;
    }
    $page_id = $block->get_page_id();
    $post_id = $block->get_post_id();
    echo '<ul class="blocks" data-area-id="' . $area_id . '">';
    $page_blocks = wpb_get_blocks($page_id);
    $page_blocks = apply_filters('wpb/children_blocks', $page_blocks, $block);
    if ($page_blocks) {
        foreach ($page_blocks as $page_block) {
            if (!isset($page_block['buid']) || !isset($page_block['page_id']) || !isset($page_block['post_id']) || !isset($page_block['area_id'])) {
                continue;
            }
            $disable = isset($page_block['disable']);
            if ($page_block['into_id'] == $post_id && $page_block['area_id'] == $area_id) {
                wpb_render_block_preview($page_block['buid'], $page_block['post_id'], $page_block['page_id'], array('disable' => $disable, 'into_id' => $post_id, 'area_id' => $area_id));
            }
        }
    }
    echo '</ul>';
    echo '<div class="button block-add-button" data-area-id="' . $area_id . '">Add block</div>';
}