slug ); add_filter( 'post_row_actions', array( $this, 'post_row_actions' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'list_tables_style' ) ); } /** * Register the custom post type. * * @return void */ public function register_post_type() { $labels = array( 'name' => _x( 'Custom Blocks', 'post type general name', 'advanced-custom-blocks' ), 'singular_name' => _x( 'Custom Block', 'post type singular name', 'advanced-custom-blocks' ), 'menu_name' => _x( 'Custom Blocks', 'admin menu', 'advanced-custom-blocks' ), 'name_admin_bar' => _x( 'Custom Block', 'add new on admin bar', 'advanced-custom-blocks' ), 'add_new' => _x( 'Add New', 'book', 'advanced-custom-blocks' ), 'add_new_item' => __( 'Add New Custom Block', 'advanced-custom-blocks' ), 'new_item' => __( 'New Custom Block', 'advanced-custom-blocks' ), 'edit_item' => __( 'Edit Custom Block', 'advanced-custom-blocks' ), 'view_item' => __( 'View Custom Block', 'advanced-custom-blocks' ), 'all_items' => __( 'Custom Blocks', 'advanced-custom-blocks' ), 'search_items' => __( 'Search Custom Blocks', 'advanced-custom-blocks' ), 'parent_item_colon' => __( 'Parent Custom Blocks:', 'advanced-custom-blocks' ), 'not_found' => __( 'No custom blocks found.', 'advanced-custom-blocks' ), 'not_found_in_trash' => __( 'No custom blocks found in Trash.', 'advanced-custom-blocks' ) ); $args = array( 'labels' => $labels, 'public' => false, 'show_ui' => true, 'show_in_menu' => 'acb', 'query_var' => true, 'rewrite' => array( 'slug' => 'acb_block' ), 'capability_type' => 'post', 'supports' => array( 'title' ) ); register_post_type( $this->slug, $args ); } /** * Enqueue scripts and styles used by the Block post type. * * @return void */ public function enqueue_scripts() { $screen = get_current_screen(); if ( ! is_object( $screen ) ) { return; } // Enqueue scripts and styles on the edit screen of the Block post type. if ( $this->slug === $screen->post_type && 'post' === $screen->base ) { wp_enqueue_style( 'block-post', $this->plugin->get_url( 'css/admin.block-post.css' ), array(), filemtime( $this->plugin->get_path( 'css/admin.block-post.css' ) ) ); wp_enqueue_script( 'block-post', $this->plugin->get_url( 'js/admin.block-post.js' ), array( 'jquery', 'jquery-ui-sortable', 'wp-util', 'wp-blocks' ), filemtime( $this->plugin->get_path( 'js/admin.block-post.js' ) ) ); } } /** * Add meta boxes. * * @return void */ public function add_meta_boxes() { add_meta_box( 'acb_block_properties', __( 'Block Properties', 'advanced-custom-blocks' ), array( $this, 'render_properties_meta_box' ), $this->slug, 'normal', 'high' ); add_meta_box( 'acb_block_fields', __( 'Block Fields', 'advanced-custom-blocks' ), array( $this, 'render_fields_meta_box' ), $this->slug, 'normal', 'high' ); add_meta_box( 'acb_block_template', __( 'Template', 'advanced-custom-blocks' ), array( $this, 'render_template_meta_box' ), $this->slug, 'side', 'default' ); } /** * Render the Block Fields meta box. * * @return void */ public function render_properties_meta_box() { global $post; $block = new Custom_Block( $post->ID ); ?>

ID ); ?>
fields as $field ) { $this->render_fields_meta_box_row( $field, uniqid() ); } ?>
label ); ?>
 | 
name ); ?>
control ); ?>

Close Field
post_name ) || empty( $post->post_name ) ) { ?>

post_name . '.php' ) ) ) { ?>

post_name . '.php'; $parent_template = str_replace( get_theme_root(), '', get_template_directory() ) . '/blocks/block-' . $post->post_name . '.php'; if ( $child_template !== $parent_template ) { ?>

post_name . '.php'; $parent_template = str_replace( get_theme_root(), '', get_template_directory() ) . '/blocks/block-' . $post->post_name . '.php'; if ( $child_template !== $parent_template ) { ?>

name = sanitize_key( $data['post_name'] ); if ( '' === $block->name ) { $block->name = $post_id; } // Block title $block->title = sanitize_text_field( $data['post_title'] ); if ( '' === $block->title ) { $block->title = $post_id; } // Block category if ( isset( $_POST['acb-properties-category'] ) ) { $block->category = sanitize_key( $_POST['acb-properties-category'] ); if ( '__custom' === $block->category && isset( $_POST['acb-properties-category-custom'] ) ) { $block->category = sanitize_text_field( $_POST['acb-properties-category-custom'] ); // Prevent category from being set to a reserved category name if ( 'reusable' === $block->category ) { $block->category = ''; } } } // Block description if ( isset( $_POST['acb-properties-description'] ) ) { $block->description = sanitize_textarea_field( $_POST['acb-properties-description'] ); } // Block keywords if ( isset( $_POST['acb-properties-keywords'] ) ) { $keywords = sanitize_text_field( $_POST['acb-properties-keywords'] ); $keywords = explode( ',', $keywords ); $keywords = array_map( 'trim', $keywords ); $keywords = array_slice( $keywords, 0, 3 ); $block->keywords = $keywords; } // Block fields if ( isset( $_POST['acb-fields-name'] ) && is_array( $_POST['acb-fields-name'] ) ) { foreach ( $_POST['acb-fields-name'] as $key => $name ) { // Field name and order $field_config = array( 'name' => sanitize_key( $name ), 'order' => sanitize_key( $key ), ); // Field label if ( isset( $_POST['acb-fields-label'][ $key ] ) ) { $field_config['label'] = sanitize_text_field( $_POST['acb-fields-label'][ $key ] ); } // Field control if ( isset( $_POST['acb-fields-control'][ $key ] ) ) { $field_config['control'] = sanitize_text_field( $_POST['acb-fields-control'][ $key ] ); } $field = new Custom_Field( $field_config ); $block->fields[ $name ] = $field; } } $data['post_content'] = $block->to_json(); return $data; } /** * Change the default "Enter Title Here" placeholder on the edit post screen. * * @param string $title * * @return string */ public function post_title_placeholder( $title ) { $screen = get_current_screen(); // Enqueue scripts and styles on the edit screen of the Block post type. if ( is_object( $screen ) && $this->slug === $screen->post_type ) { $title = __( 'Enter block name here', 'advanced-custom-blocks' ); } return $title; } /** * Hide the search box and top pagination. * * @return void */ public function list_tables_style() { $custom_css = '.post-type-acb_block .tablenav.top { display: none; }'; $custom_css .= '.post-type-acb_block .search-box { display: none; }'; wp_add_inline_style( 'list-tables', $custom_css ); } /** * Hide the Quick Edit row action. * * @param array $actions * * @return array */ public function post_row_actions( $actions = array() ) { global $post; // Abort if the post type is incorrect if ( $post->post_type !== $this->slug ) { return $actions; } // Remove the Quick Edit link if ( isset( $actions['inline hide-if-no-js'] ) ) { unset( $actions['inline hide-if-no-js'] ); } // Return the set of links without Quick Edit return $actions; } }