Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions framework/ACF/ACF_Gutenberg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace JustCoded\WP\Framework\ACF;

use JustCoded\WP\Framework\Objects\Singleton;

/**
* Class ACF_Gutenberg
*/
abstract class ACF_Gutenberg {
use Singleton;

/**
* Block Slug Name
*
* @var string
*/
public $slug;

/**
* Block Title
*
* @var string
*/
public $title;

/**
* Block Description
*
* @var string
*/
public $description;

/**
* Block Icon Name
*
* @var string
*/
public $icon;

/**
* Block Keywords
*
* @var array
*/
public $keywords;

/**
* Class constructor.
*/
public function __construct() {
add_action( 'acf/init', array( $this, 'init' ) );
}

/**
* Action hook 'init'
* call $this->register_block()
*/
abstract public function init();


/**
* Register ACF Gutenberg Block.
*/
public function register_block(): void {
$block_defaults = array(
'category' => 'formatting',
'icon' => 'admin-generic',
);

$block = array(
'name' => $this->slug,
'title' => $this->title,
'description' => $this->description,
'icon' => $this->icon,
'keywords' => $this->keywords,
'render_template' => get_stylesheet_directory() . '/views/blocks/' . $this->slug . '.php',
);

$block = wp_parse_args( $block, $block_defaults );

acf_register_block( $block );

if ( isset( $block['fields'] ) ) {
acf_add_local_field_group( $block['fields'] );
}
}
}