-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.php
More file actions
60 lines (51 loc) · 1.74 KB
/
plugin.php
File metadata and controls
60 lines (51 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* Plugin Name: Gutenberg Recipe Block
* Description: Custom recipe block for the Gutenberg editor using Advanced Custom Fields
* Author: Joi Polloi
* Version: 1.0.0
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Register custom category
function joipolloi_custom_category( $categories, $post ) {
// Check if custom category has already been created
$custom_category_exists = false;
foreach ($categories as $key => $category) {
if ($category['slug'] === 'joipolloi-blocks') {
$custom_category_exists = true;
}
}
if ( $custom_category_exists) {
return $categories;
} else {
return array_merge(
$categories,
array(
array(
'slug' => 'joipolloi-blocks',
'title' => 'Joi Polloi Custom Blocks',
),
)
);
}
}
add_filter( 'block_categories', 'joipolloi_custom_category', 10, 2);
// Register block
function register_recipe_block_and_fields() {
acf_register_block_type(array(
'name' => 'recipe',
'title' => 'Recipe',
'render_template' => plugin_dir_path( __FILE__ ) . 'recipe.php',
'category' => 'joipolloi-blocks',
'icon' => 'buddicons-community',
'mode' => 'edit',
'supports' => array('mode' => false),
'enqueue_style' => plugin_dir_url( __FILE__ ) . 'recipe.css',
));
require_once plugin_dir_path( __FILE__ ) . 'functions/register-fields.php';
wp_enqueue_script('recipe', plugin_dir_url( __FILE__ ) . 'main.js', [], '1.0.0', true);
}
add_action('acf/init', 'register_recipe_block_and_fields');