-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
94 lines (74 loc) · 2.02 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
<?php
global $SITE;
$SITE = new SiteObject();
$SITE->init();
function SITE() {
global $SITE;
return $SITE;
}
// add css and js
wp_enqueue_style( 'main', get_template_directory_uri() . '/build/css/app.css',false,'1.1','all');
wp_enqueue_script( 'main', get_template_directory_uri() . '/build/js/app.js', array(), '1.0.0', true );
// disable for posts
add_filter('use_block_editor_for_post', '__return_false', 10);
// disable for post types
add_filter('use_block_editor_for_post_type', '__return_false', 10);
class SiteObject {
public $meta_title = '';
public $meta_desc = '';
public $meta_img = '';
function init() {
add_action('init', function() {
register_nav_menu('main-menu', __( 'Main Menu' ));
add_image_size('1280', 1280);
add_image_size('1920', 1920);
});
if (!is_admin()) {
add_action('wp', [$this, 'setupMeta']);
}
}
function setupMeta() {
$post = get_post();
if ($post) {
$this->meta_title = trim(get_the_title($post->ID));
$this->meta_desc = trim(get_the_excerpt($post));
$this->meta_img = get_the_post_thumbnail_url($post->ID, 'large');
}
$home_post = get_post(url_to_postid('home'));
if ($home_post) {
if (empty($this->meta_title)) {
$this->meta_title = trim(get_the_title($home_post->ID));
}
if (empty($this->meta_desc)) {
$this->meta_desc = trim(get_the_excerpt($home_post));
}
if (empty($this->meta_img)) {
$this->meta_img = get_the_post_thumbnail_url($home_post->ID, 'large');
}
}
}
function getMeta($type) {
return esc_attr($this->$type);
}
function resource($file) {
return bloginfo('template_url')."/src/{$file}";
}
function svg($file) {
return file_get_contents(__DIR__."/src/{$file}");
}
function dir($parent = 0) {
$pages = new WP_Query([
'post_type' => 'page',
'post_parent' => $parent,
'orderby' => 'menu_order',
'order' => 'ASC',
'posts_per_page' => -1
]);
foreach($pages->posts as $page) {
$template = get_page_template_slug($page->ID);
$data = get_fields($page->ID);
include $template;
}
}
}
?>