forked from BuildTheEarth-Italia/Wordpress-Theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
223 lines (192 loc) · 6.35 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
/* ============================== */
/* Foto della galleria */
/* ============================== */
function get_photos_from_bte_theme_showcase($show_hidden = false)
{
global $wpdb;
//nome tabella
$table_name = $wpdb->prefix . "bte_theme_showcase";
//eseguo query
$photos = $wpdb->get_results("SELECT * FROM $table_name " . ($show_hidden ? "" : "WHERE `visible` = true") . ";");
//ritorno l'array
return $photos;
}
function add_photo_to_bte_theme_showcase($id = NULL, $path, $title, $description)
{
global $wpdb;
//nome tabella
$table_name = $wpdb->prefix . "bte_theme_showcase";
//eseguo query
$wpdb->query($wpdb->prepare("INSERT INTO $table_name (`id`, `path`, `title`, `description` ) VALUES ( %d, %s, %s, %s )", $id, $path, $title, $description));
}
function delete_photo_from_bte_theme_showcase($id)
{
global $wpdb;
//nome tabella
$table_name = $wpdb->prefix . "bte_theme_showcase";
//eseguo query
$wpdb->delete($table_name, array('id' => $id), array('%d'));
}
function show_photo_of_bte_theme_showcase($id)
{
global $wpdb;
//nome tabella
$table_name = $wpdb->prefix . "bte_theme_showcase";
//aggiorno db
$wpdb->update(
$table_name,
array(
'visible' => true
),
array(
'id' => $id
)
);
}
function hide_photo_of_bte_theme_showcase($id)
{
global $wpdb;
//nome tabella
$table_name = $wpdb->prefix . "bte_theme_showcase";
//aggiorno db
$wpdb->update(
$table_name,
array(
'visible' => false
),
array(
'id' => $id
)
);
}
/* ============================== */
/* Cambio custom background */
/* ============================== */
function change_bte_theme_custom_background_cb()
{
ob_start();
_custom_background_cb();
echo str_replace('.custom-background', '', ob_get_clean());
}
/* ============================== */
/* Impostazioni e blocchi */
/* ============================== */
require(get_template_directory() . '/settings.php');
require(get_template_directory() . '/blocks.php');
/* ============================== */
/* Inizzializzazione */
/* ============================== */
function init_bte_theme()
{
//versione installata e corrente
$installed_ver = get_option('bte_theme_version');
$current_ver = wp_get_theme()->get('Version');
//sfondo personalizzato
$bg = array(
'default-color' => 'ffffff',
'default-image' => get_template_directory_uri() . '/resources/uploads/bg.png',
'default-size' => 'cover',
'default-repeat' => 'no-repeat',
'default-position-x' => 'left',
'default-position-y' => 'top',
'default-attachment' => 'fixed',
'wp-head-callback' => 'change_bte_theme_custom_background_cb'
);
add_theme_support('custom-background', $bg);
//titolo personalizzato
add_theme_support('title-tag');
//menù
register_nav_menus(
array(
'header-menu' => __('Header Menu'),
'footer-menu-1' => __('Footer Menu 1'),
'footer-menu-2' => __('Footer Menu 2'),
'footer-menu-3' => __('Footer Menu 3'),
)
);
// Creo Custom types per faq e pagine di aiuto
register_post_type(
'bte_faqs',
array(
'labels' => array(
'name' => __('Faqs'),
'singular_name' => __('Faq')
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'faqs'),
'show_in_rest' => true,
'menu_icon' => 'dashicons-editor-help',
'menu_position' => 5,
'supports' => array('title', 'editor', 'author'),
)
);
// Aggiorno i link di rewrite
add_action('after_switch_theme', 'flush_rewrite_rules');
//galleria foto
global $wpdb;
$wpdb->show_errors();
//creo tabella per foto se non esiste o versione precedente
if (!isset($installed_ver) || $installed_ver != $current_ver) {
//dettagli per la creazione della tabella
$table_name = $wpdb->prefix . 'bte_theme_showcase';
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE `$table_name` (
`id` int(4) NOT NULL AUTO_INCREMENT,
`path` text NOT NULL,
`title` text NOT NULL,
`description` blob NOT NULL,
`visible` BOOLEAN NOT NULL DEFAULT TRUE
) $charset_collate COMMENT='Tabella per le foto dello showcase del tema BTE';";
//creo tabella
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
//aggiorno versione
update_option('bte_theme_version', $current_ver);
}
}
//avvio funzioni per il tema
add_action('after_setup_theme', 'init_bte_theme');
//rimuovo supporto per commenti
function remove_comments_page()
{
remove_menu_page('edit-comments.php');
}
function remove_admin_bar_comments()
{
global $wp_admin_bar;
$wp_admin_bar->remove_menu('comments');
}
function remove_comment_support()
{
remove_post_type_support('post', 'comments');
remove_post_type_support('page', 'comments');
}
add_action('init', 'remove_comment_support', 100);
add_action('admin_menu', 'remove_comments_page');
add_action('wp_before_admin_bar_render', 'remove_admin_bar_comments');
//registro gli scripts
//lax.js
wp_register_script('lax', 'https://cdn.jsdelivr.net/npm/lax.js@1.2.5', null, null, true);
//Three.js
wp_register_script('threejs', 'https://cdn.jsdelivr.net/npm/three/build/three.min.js', null, null, true);
// Script per utils
wp_register_script('bte_script_utils', get_template_directory_uri() . '/js/utils.js', null, true);
//script per galleria in pagina amministrazione
wp_register_script('bte_script_admin_media', get_template_directory_uri() . '/js/admin_media.js', array('jquery'), null, true);
//script per galleria in home.php
wp_register_script('bte_script_gallery', get_template_directory_uri() . '/js/gallery.js', array('bte_script_utils'), null, true);
//script per parallax in pagine pubbliche
wp_register_script('bte_script_parallax', get_template_directory_uri() . '/js/parallax.js', array('jquery', 'lax'), null, true);
//script per testi dinamici in homepage
wp_register_script('bte_text_changer', get_template_directory_uri() . '/js/text_changer.js', null, null, true);
//script per caricare utenti online in classifica
wp_register_script('bte_points_online_players_loader', get_template_directory_uri() . '/js/points_online_players_loader.js', null, null, true);
// Registro gli stili
// Post styles
wp_register_style('bte_post_style', get_template_directory_uri() . '/style/content.css');
// Faqs styles
wp_register_style('bte_faq_style', get_template_directory_uri() . '/style/faq.css', array('bte_post_style'));
// Stile per classifica
wp_register_style('bte_points_style', get_template_directory_uri() . '/style/points.css');