-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglutenblocks.php
96 lines (82 loc) · 2.7 KB
/
glutenblocks.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
<?php
/**
* Plugin Name: Glutenblocks
* Plugin URI: https://github.com/eXolnet/glutenblocks
* Description: Collection of Wordpress blocks for the Gutenberg editor.
* Version: 1.3.0
* Author: eXolnet
* Text Domain: glutenblocks
*
* @package glutenblocks
*/
glutenblocks_pre_init();
/**
* Display a version notice and deactivate the Gutenberg plugin.
*
* @since 0.1.0
*/
function glutenblocks_wordpress_version_notice()
{
echo '<div class="error"><p>';
/* translators: %s: Minimum required version */
printf(__('Glutenblocks requires WordPress %s or later to function properly. Please upgrade WordPress before activating Glutenblocks.', 'glutenblocks'), '5.0.0');
echo '</p></div>';
}
/**
* Verify that we can initialize the Glutenblocks, then load it.
*
* @since 1.0.0
*/
function glutenblocks_pre_init()
{
// Get unmodified $wp_version.
include ABSPATH . WPINC . '/version.php';
// Strip '-src' from the version string. Messes up version_compare().
$version = str_replace('-src', '', $wp_version);
if (version_compare($version, '5.0.0', '<')) {
add_action('admin_notices', 'gutenberg_wordpress_version_notice');
return;
}
require_once dirname(__FILE__) .'/lib/load.php';
}
function gb_get_post_types() {
$post_types = get_post_types( ['glutenblock_rest' => true, 'public' => true], 'names', 'or');
return array_keys($post_types);
}
function gb_get_field_types($data){
$args = array(
'post_type'=> $data['field'],
'posts_per_page'=> -1,
'numberposts'=> -1
);
$posts = get_posts($args);
return $posts;
}
function gb_get_post_attributes($data){
return get_fields($data['id']);
}
function gb_is_acf_plugin_active(){
return is_plugin_active( 'acf-to-rest-api/class-acf-to-rest-api.php' );
}
add_action( 'rest_api_init', function () {
register_rest_route( 'glutenblocks/v1', '/wp_get_post_types', array(
'methods' => 'GET',
'callback' => 'gb_get_post_types',
'permission_callback' => '__return_true',
) );
register_rest_route( 'glutenblocks/v1', '/gb_get_field_types/field=(?P<field>[a-zA-Z0-9-]+)', array(
'methods' => 'GET',
'callback' => 'gb_get_field_types',
'permission_callback' => '__return_true',
) );
register_rest_route( 'glutenblocks/v1', '/gb_get_post_attributes/id=(?P<id>[a-zA-Z0-9-]+)', array(
'methods' => 'GET',
'callback' => 'gb_get_post_attributes',
'permission_callback' => '__return_true',
) );
register_rest_route( 'glutenblocks/v1', '/gb_is_acf_plugin_active', array(
'methods' => 'GET',
'callback' => 'gb_is_acf_plugin_active',
'permission_callback' => '__return_true',
) );
});