|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Presspack\Framework; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
|
6
|
|
|
|
|
7
|
|
|
class Setup |
|
8
|
|
|
{ |
|
9
|
|
|
public $config; |
|
10
|
|
|
|
|
11
|
|
|
public function __construct($path) |
|
12
|
|
|
{ |
|
13
|
|
|
$basePath = \dirname($path, 2); |
|
14
|
|
|
|
|
15
|
|
|
$this->config = require_once $basePath.'/config/presspack.php'; |
|
16
|
|
|
|
|
17
|
|
|
add_action('init', [$this, 'themeSetup']); |
|
|
|
|
|
|
18
|
|
|
add_action('init', [$this, 'registerPostTypes']); |
|
19
|
|
|
add_action('init', [$this, 'registerTemplates']); |
|
20
|
|
|
add_action('init', [$this, 'registerTaxonomies']); |
|
21
|
|
|
add_action('init', [$this, 'registerMenus']); |
|
22
|
|
|
add_action('after_setup_theme', [$this, 'registerImageSizes']); |
|
23
|
|
|
add_filter('flush_rewrite_rules_hard', '__return_false'); |
|
|
|
|
|
|
24
|
|
|
add_filter('use_block_editor_for_post', '__return_false', 10); // disable gutenberg for posts |
|
25
|
|
|
add_filter('use_block_editor_for_post_type', '__return_false', 10); // disable gutenberg for post types |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public static function bootstrap($path) |
|
29
|
|
|
{ |
|
30
|
|
|
return new static($path); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function themeSetup() |
|
34
|
|
|
{ |
|
35
|
|
|
load_theme_textdomain('presspack'); |
|
|
|
|
|
|
36
|
|
|
add_theme_support('post-thumbnails'); |
|
|
|
|
|
|
37
|
|
|
add_theme_support('automatic-feed-links'); |
|
38
|
|
|
add_theme_support('title-tag'); |
|
39
|
|
|
|
|
40
|
|
|
if (\function_exists('acf_add_options_page')) { |
|
41
|
|
|
acf_add_options_page(); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function registerPostTypes() |
|
46
|
|
|
{ |
|
47
|
|
|
foreach ($this->config['post_types'] as $postType) { |
|
48
|
|
|
$data = new $postType(); |
|
49
|
|
|
register_post_type($data->postType, $data->postTypeargs()); |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function registerTaxonomies() |
|
54
|
|
|
{ |
|
55
|
|
|
foreach ($this->config['taxonomies'] as $taxonomy => $value) { |
|
56
|
|
|
$singularName = isset($value['singular']) ? $value['singular'] : $taxonomy; |
|
57
|
|
|
$pluralName = isset($value['plural']) ? $value['plural'] : Str::plural($taxonomy); |
|
58
|
|
|
|
|
59
|
|
|
register_taxonomy(Str::slug($taxonomy), $value['post_types'], [ |
|
|
|
|
|
|
60
|
|
|
'labels' => [ |
|
61
|
|
|
'name' => $pluralName, |
|
62
|
|
|
'singular_name' => $singularName, |
|
63
|
|
|
'menu_name' => $pluralName, |
|
64
|
|
|
], |
|
65
|
|
|
'description' => '', |
|
66
|
|
|
'public' => true, |
|
67
|
|
|
'hierarchical' => true, |
|
68
|
|
|
'show_ui' => true, |
|
69
|
|
|
'show_admin_column' => false, |
|
70
|
|
|
'show_in_nav_menus' => true, |
|
71
|
|
|
'show_tagcloud' => false, |
|
72
|
|
|
'single_value' => false, |
|
73
|
|
|
]); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function registerTemplates() |
|
78
|
|
|
{ |
|
79
|
|
|
foreach ($this->config['templates'] as $postType => $templates) { |
|
80
|
|
|
add_filter("theme_{$postType}_templates", function ($registeredTemplates) use ($templates) { |
|
|
|
|
|
|
81
|
|
|
return array_merge($registeredTemplates, $templates); |
|
82
|
|
|
}); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function registerMenus() |
|
87
|
|
|
{ |
|
88
|
|
|
foreach ($this->config['menus'] as $menu) { |
|
89
|
|
|
register_nav_menu($menu, $menu); |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function registerImageSizes() |
|
94
|
|
|
{ |
|
95
|
|
|
foreach ($this->config['image_sizes'] as $key => $sizes) { |
|
96
|
|
|
add_image_size($key, $sizes[0], $sizes[1], isset($sizes[2]) ? $sizes[2] : true); |
|
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|