|
<?php |
|
|
|
/* |
|
ACF Blocks for Avenidas CPTS |
|
*/ |
|
|
|
// Enqueue Assets |
|
function av_enqueue_block_assets(){ |
|
wp_enqueue_style( |
|
'acf-blocks-editor', |
|
plugins_url( 'acf-blocks/acf-blocks.css', dirname(__FILE__) ), |
|
array( 'wp-edit-blocks' ), |
|
filemtime( plugin_dir_path( dirname(__FILE__) ) . 'acf-blocks/acf-blocks.css' ) |
|
); |
|
|
|
wp_enqueue_style( |
|
'acf-blocks', |
|
plugins_url( 'acf-blocks/acf-blocks.css', dirname(__FILE__) ), |
|
array(), |
|
filemtime( plugin_dir_path( dirname(__FILE__) ) . 'acf-blocks/acf-blocks.css' ) |
|
); |
|
} |
|
|
|
// Create Blocks |
|
add_action('acf/init', 'av_register_blocks' ); |
|
function av_register_blocks() { |
|
if( ! function_exists('acf_register_block_type') ) |
|
return; |
|
|
|
acf_register_block_type( |
|
array( |
|
'name' => 'pdf-thumbnail', |
|
'title' => __( 'PDF Thumbnail Link', 'avenidas' ), |
|
'render_callback' => 'av_types_render_callback', |
|
'category' => 'custom', |
|
'icon' => 'media-document', |
|
'mode' => 'edit', |
|
'supports' => array( |
|
'align' => array('left', 'center', 'right'), |
|
), |
|
'keywords' => array( 'pdf', 'image', 'newsletter' ), |
|
'post_types' => array( 'av_newsletter', 'conference', 'news', 'page', 'post' ), |
|
'enqueue_assets' => 'av_enqueue_block_assets', |
|
) |
|
); |
|
} |
|
// Block Categories |
|
add_filter( 'block_categories', 'avenidas_block_categories', 10, 2 ); |
|
function avenidas_block_categories($categories) { |
|
return array_merge( |
|
$categories, |
|
array( |
|
array( |
|
'slug' => 'custom', |
|
'title' => __( 'Custom', 'avenidas' ), |
|
'icon' => 'admin-generic', |
|
), |
|
), |
|
); |
|
} |
|
|
|
// Render Callback |
|
function av_types_render_callback($block) { |
|
// convert name ("acf/whatever") into path friendly slug ("whatever") |
|
$slug = str_replace('acf/', '', $block['name']); |
|
|
|
// include a template part from within the "template-parts/block" folder |
|
if( file_exists( AV_TYPES_PATH . "/acf-blocks/block-templates/content-{$slug}.php") ) { |
|
include( AV_TYPES_PATH . "/acf-blocks/block-templates/content-{$slug}.php" ); |
|
} |
|
} |