-
Notifications
You must be signed in to change notification settings - Fork 0
/
matiere-noire-blocks-library.php
100 lines (85 loc) · 2.21 KB
/
matiere-noire-blocks-library.php
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* Plugin Name: Matière Noire Blocks Library
* Description: Des bloc créés par l'équipe de Matière Noire
* Author: matière Noire
* Version: 1.0.0
* Author URI: https://matierenoire.io
*/
/**
* Enqueue blocks script
*/
function mn_blocks_enqueue_block_editor_assets()
{
wp_enqueue_script(
'mn-blocks-scripts',
plugins_url('build/index.js', __FILE__),
['wp-components', 'wp-blocks', 'wp-element', 'wp-block-editor', 'wp-data', 'wp-compose', 'wp-dom-ready', 'wp-edit-post', 'wp-api-fetch'],
'1.0.0'
);
}
add_action('enqueue_block_editor_assets', 'mn_blocks_enqueue_block_editor_assets');
/**
* Registers the plugin's blocks
*
* @since 1.0.0
*/
function mn_blocks_register_blocks()
{
register_block_type('mn-blocks/post-type-archive', [
'render_callback' => 'mn_blocks_post_type_archive',
'attributes' => [
'numberOfPosts' => [
'type' => 'integer',
'default' => 3,
],
'postType' => [
'type' => 'string',
'default' => 'post',
]
]
]);
}
add_action('init', 'mn_blocks_register_blocks');
/**
* Register MN Blocks catégory
*
* @param $categories
* @param $post
* @return array
*/
function mn_blocks_library_block_categories($categories, $post)
{
$cat = array_merge(
$categories,
array(
array(
'slug' => 'mn-blocks',
'title' => 'MN Blocs',
'icon' => null
)
)
);
return $cat;
}
add_filter('block_categories', 'mn_blocks_library_block_categories', 10, 2);
/**
*
*/
function mn_blocks_post_type_archive($attributes)
{
$post_type = new WP_Query([
'posts_per_page' => $attributes['numberOfPosts'],
'post_type' => $attributes['postType']
]);
$return = '';
if ($post_type->have_posts()) {
$return .= '<div class="card-grid">';
while ($post_type->have_posts()) {
$post_type->the_post();
$return .= Hybrid\View\render('entry/archive', Hybrid\Post\hierarchy());
}
$return .= '</div>';
}
return $return;
}