This repository has been archived by the owner on Apr 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.php
136 lines (121 loc) · 4.86 KB
/
functions.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
function setup() {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 825, 510, true );
register_nav_menus( array(
'main' => __('Main Menu', 'rooftopcms'),
'footer' => __('Footer Menu', 'rooftopcms'),
));
// FIXME: move these rest_query_vars filters into the rooftop-request-parser plugin
add_filter( 'rest_query_vars', function( $valid_vars ) {
$valid_vars = array_merge( $valid_vars, array( 'post__in', 'post__not_in' ) );
return $valid_vars;
});
add_filter ( 'rest_query_vars', function( $valid_vars ) {
$valid_vars = array_merge( $valid_vars, array( 'meta_key', 'meta_value', 'meta_query' ) );
return $valid_vars;
});
}
setup();
use ICanBoogie\Inflector;
class RooftopCMS {
static function addContentType($type, $args = null) {
$inflector = ICanBoogie\Inflector::get('en');
$sanitised = str_replace(" ","_",strtolower($type));
$singular = $inflector->titleize($type);
$plural = $inflector->pluralize($singular);
$default_args = array(
'hierarchical' => false,
'labels' => array(
'name' => $plural,
'singular_name' => $singular,
'menu_name' => $plural,
'name_admin_bar' => $singular,
'all_items' => "All $plural",
'add_new' => "New $singular",
'add_new_item' => "New $singular",
'edit_item' => "Edit $singular",
'new_item' => "New $singular",
'view_item' => "View $singular",
'search_items' => "Search $plural",
'not_found' => "No $plural found",
'not_found_in_trash' => "No $plural found in trash",
'parent_item_colon' => "Parent $singular:"
),
'description' => "A $type",
'public' => true,
'supports' => array(
'title', 'editor'
),
'show_ui' => true,
'menu_position' => 20,
'capability_type' => 'page',
'has_archive' => true,
'show_in_rest' => true,
'rest_base' => $inflector->underscore($inflector->pluralize($type)),
'include_taxonomies_in_response' => true
);
if(is_null($args) || !is_array($args)){
$args = $default_args;
}else {
$args = array_merge($default_args, $args);
}
register_post_type($sanitised, $args);
}
static function addTaxonomy($name, $content_type, $args = null) {
$inflector = ICanBoogie\Inflector::get('en');
$sanitised = str_replace(" ","_",strtolower($name));
$human = $inflector->titleize($sanitised);
$plural = $inflector->pluralize($human);
$singular = $inflector->singularize($human);
$default_args = array(
'name' => $plural,
'singular_name' => $singular,
'labels' => array(
'name' => $plural,
'singular_name' => $singular,
'menu_name' => $plural,
'all_items' => "All $plural",
'edit_item' => "Edit $singular",
'view_item' => "View $singular",
'update_item' => "Update $singular",
'add_new_item' => "Add new $singular",
'new_item_name' => "New $singular name",
'parent_item' => "Parent $singular",
'parent_item_colon' => "Parent $singular:",
'search_items' => "Search $plural",
'popular_items' => "Popular $plural",
'separate_items_with_commas' => "Separate $plural with commas",
'add_or_remove_items' => "Add or remove $plural",
'choose_from_most_used' => "Most used $plural",
'not_found' => "No $plural found"
),
'show_in_rest' => true,
'query_var' => true
);
if(is_null($args) || !is_array($args)){
$args = $default_args;
}else {
$args = array_merge($default_args, $args);
}
if(is_array($content_type)){
$types = $content_type;
}elseif($content_type == 'all') {
$types = get_post_types(array('public' => true));
}else {
$types = [$content_type];
}
foreach($types as $key => $type) {
register_taxonomy($sanitised, $type, $args);
}
}
}
add_action( 'login_enqueue_scripts', function() {
wp_enqueue_style( 'rooftop-login', get_stylesheet_directory_uri() . '/rooftop-login.css' );
} );
add_action( 'login_body_class', function() {
$env = @$_ENV['WP_ENV'];
$locale = "locale-" . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
return ["env-${env}", "login-action-login", "wp-core-ui", $locale];
})
?>