$location = $location . '#block_saved'; break; } return $location; }, 10, 2); /** * Hides the page content and displays block instead. * @filter the_content * @since 1.0.0 */ add_filter('the_content', function ($content) { global $post; if (is_admin()) { return $content; } foreach (wpb_block_context() as $post_type) { if (get_post_type() == $post_type) { $page_blocks = wpb_get_blocks($post->ID); if ($page_blocks) { ob_start(); foreach ($page_blocks as $page_block) { if (!isset($page_block['buid']) || !isset($page_block['page_id']) || !isset($page_block['post_id'])) { continue; } if (is_preview() === false && isset($page_block['post_revision_id'])) { $rev = wp_get_post_revision($page_block['post_revision_id']); if ($rev) { $page_block['post_id'] = $rev->ID; } } if ($page_block['into_id'] == 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; }); } }