-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
84 lines (69 loc) · 2.27 KB
/
Copy pathfunctions.php
File metadata and controls
84 lines (69 loc) · 2.27 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
// Define plugin dir path
if ( ! defined('BUILD_REST__PLUGIN_DIR')) {
define( 'BUILD_REST__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
// Create custom post type (Project)
if ( !function_exists( 'create_projects_type' ) ) {
function create_projects_type() {
register_post_type('projects', array(
'labels' => array(
'name' => __('Projects'),
'singular_name' => __('Project')
),
'public' => true,
'has_archive' => true,
'show_in_rest' => true,
'rewrite' => array(
'slug' => 'project',
'with_front' => false,
),
));
}
}
// Add Projects post types on init
add_action('init', 'create_projects_type');
// Create custom post type (Works)
if ( !function_exists( 'create_works_type' ) ) {
function create_works_type() {
register_post_type('works', array(
'labels' => array(
'name' => __('Works'),
'singular_name' => __('Work')
),
'public' => true,
'has_archive' => true,
'show_in_rest' => true,
'rewrite' => array(
'slug' => 'work',
'with_front' => false,
),
));
}
}
// Add Works post types on init
add_action('init', 'create_works_type');
// Adds WP_REST_ROUTES to JS global
function build_routes() {
require_once( BUILD_REST__PLUGIN_DIR . 'includes/build_rest_routes.php' );
}
add_action('init', 'build_routes');
// Adds WP_REST_MENUS to JS global
require_once( BUILD_REST__PLUGIN_DIR . 'includes/build_rest_menus.php' );
// Adds WP_REST_INFO to JS global
require_once( BUILD_REST__PLUGIN_DIR . 'includes/build_rest_info.php' );
// Adds WP_REST_SETTINGS to JS global
// called on init to make custom post types available
function build_settings() {
require_once( BUILD_REST__PLUGIN_DIR . 'includes/build_rest_settings.php' );
}
add_action('init', 'build_settings');
// Adds Settings REST route
require_once( BUILD_REST__PLUGIN_DIR . 'includes/add_settings_rest_route.php' );
// Adds Menus REST route
require_once( BUILD_REST__PLUGIN_DIR . 'includes/add_menus_rest_route.php' );
// Adds Routes REST route
require_once( BUILD_REST__PLUGIN_DIR . 'includes/add_routes_rest_route.php' );
// Enqueue React bundle script
wp_enqueue_script('rest-theme-react', BUILD_REST__PLUGIN_DIR . '/build/bundle.js', array(), '1.0.0', true);
?>