This repository was archived by the owner on Jan 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.php
More file actions
137 lines (108 loc) · 3.4 KB
/
functions.php
File metadata and controls
137 lines (108 loc) · 3.4 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
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
137
<?php
use CG\Gutenberg\Gutenberg;
use CG\Integrations\ThemeIntegrations;
use CG\Plugins\ContactForm\ContactForm;
use CG\Plugins\RepositoryUpdateWebHook\RepositoryUpdateWebHook;
use CG\Seo\Seo;
use CG\ThemeOptions;
require_once __DIR__.'/vendor/autoload.php';
Seo::turn_on();
ContactForm::init();
Gutenberg::turn_on();
ThemeIntegrations::turn_on_all();
RepositoryUpdateWebHook::init();
// @todo move this somewhere else
add_action('all_admin_notices', 'check_required_plugins');
function check_required_plugins() {
$required_plugins = [
[
'name' => 'ACF',
'url' => 'https://www.advancedcustomfields.com/',
'slugs' => ['advanced-custom-fields/acf.php', 'advanced-custom-fields-pro/acf.php'],
],
];
foreach($required_plugins as $plugin) {
$is_active = false;
foreach($plugin['slugs'] as $slug) {
if(is_plugin_active($slug)) {
$is_active = true;
break;
}
}
if(!$is_active) {
show_missing_plugin_error($plugin['name'], $plugin['url']);
}
}
}
function show_missing_plugin_error($name, $url) {
?>
<div class="notice notice-error">
<p>The
<?= $name ?> plugin is required for this theme. Please <a href="<?= $url ?>">install it here</a>.
</p>
</div>
<?php
}
add_image_size('post_tile', 320, 180, array('center', 'center'));
function get_thumbnail_id_from_tree(): int {
if(has_post_thumbnail()) {
return get_post_thumbnail_id();
}
$terms = get_the_category();
foreach($terms as $term) {
$field = get_field('44008F46AA4D4368B1634E38B19A873F', $term);
if($field !== false && $field !== null) {
return $field['id'];
}
}
$default = ThemeOptions::get_default_thumbnail();
return $default['id'];
}
function mytheme_register_nav_menu(): void {
register_nav_menus(array(
'main-menu' => __('Main menu', 'cg'),
));
}
add_action('after_setup_theme', 'mytheme_register_nav_menu', 0);
add_theme_support('html5', array(
'search-form',
'comment-list',
'comment-form',
'gallery',
'caption',
)
);
add_theme_support('post-thumbnails');
function no_self_ping(&$links): void {
$home = get_option('home');
foreach($links as $l => $link) {
if(str_contains($link, $home)) {
unset($links[$l]);
}
}
}
add_action('pre_ping', 'no_self_ping');
function remove_wp_block_library_css(): void {
wp_dequeue_style('wp-block-library');
wp_dequeue_style('wp-block-library-theme');
wp_dequeue_style('wc-blocks-style');
wp_dequeue_style('global-styles'); // REMOVE THEME.JSON
}
add_action('wp_enqueue_scripts', 'remove_wp_block_library_css', 100);
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action('admin_print_scripts', 'print_emoji_detection_script');
remove_action('admin_print_styles', 'print_emoji_styles');
function redirect_to_full_url_if_needed(): void {
if(get_the_ID() === false || is_single() === false) {
return;
}
$current_url = get_home_url().$_SERVER['REQUEST_URI'];
$full_url = get_permalink();
if(str_contains($current_url, $full_url)) {
return;
}
wp_redirect($full_url, 301);
}
add_action('wp', 'redirect_to_full_url_if_needed');