-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
170 lines (119 loc) · 5.12 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
<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'lemonade', get_stylesheet_directory_uri() . '/css/lemonade.css' );
wp_enqueue_script( 'jquery-ui-autocomplete' );
wp_enqueue_script( 'autocomplete', get_stylesheet_directory_uri() . '/js/autocomplete.js',array( 'jquery', 'jquery-ui-autocomplete' ), 1.0, true );
if(is_page(8)) {
wp_enqueue_script('more-results', get_stylesheet_directory_uri() . '/js/more-results.js', 1.0, true);
}
wp_enqueue_script('scroll-me', get_stylesheet_directory_uri() . '/js/jquery.scrollme.js', array( 'jquery', 'jquery-ui-autocomplete' ), 1.0, true);
}
add_action( 'wp_enqueue_scripts', 'load_dashicons_front_end' );
function load_dashicons_front_end() {
wp_enqueue_style( 'dashicons' );
}
function film_search_form() {
include_once get_stylesheet_directory() . '/includes/handler-requests-class.php';
$handler = new Handler();
if(isset($_GET['t'])) {
$search_field = $handler->sanitizeRequest($_GET['t']);
}
$form = '<form role="search" method="get" id="searchform" class="searchform" action="/api-ricerca/" >
<div><label class="screen-reader-text" for="s">' . __( 'Cerca film:' ) . '</label>
<input type="text" value="' . ((!empty($search_field)) ? $search_field : "") . '" name="t" id="search-film-imdb" />
<button type="submit" id="searchsubmit" value="search"><i class="fas fa-search"></i></button>
</div>
</form>';
return $form;
}
function rating_stars($atts) {
$star = '<span class="dashicons dashicons-star-filled"></span>';
$star_half = '<span class="dashicons dashicons-star-half"></span>';
$empty_star = '<span class="dashicons dashicons-star-empty"></span>';
extract(shortcode_atts(array(
'rate' => 'rating'
), $atts));
if(isset($rate)) {
switch ($rate) {
case 1:
return str_repeat($star, 1) . str_repeat($empty_star, 4);
break;
case 2:
return str_repeat($star, 2) . str_repeat($empty_star, 3);
break;
case 2.5:
return str_repeat($star, 2) . $star_half . str_repeat($empty_star, 2);
break;
case 3:
return str_repeat($star, 3) . str_repeat($empty_star, 2);
break;
case 3.5:
return str_repeat($star, 3) . $star_half . str_repeat($empty_star, 1);
break;
case 4:
return str_repeat($star, 4) . str_repeat($empty_star, 1);
break;
case 4.5:
return str_repeat($star, 4) . $star_half;
break;
case 5:
return str_repeat($star, 5);
break;
}
}
}
add_shortcode('rating_stars', 'rating_stars');
// Shortcode metabox
function rating_meta_box_markup() { ?>
<p> [rating_stars rate="n.stelle"] </p>
<?php }
function add_rating_meta_box() {
add_meta_box("rating-meta-box", "Box Rating Stars Shortcode", "rating_meta_box_markup", "post", "side", "high", null);
}
add_action("add_meta_boxes", "add_rating_meta_box");
// Metabox per votazione
add_action('add_meta_boxes','rating_stars_meta_box_init');
function rating_stars_meta_box_init() {
add_meta_box("ratingstars-meta", "Votazione film", "rating_stars_meta_box", "post", "side", "high", null);
}
function rating_stars_meta_box($post,$box) {
$rating_stars = get_post_meta($post->ID,'_rating_stars', true);
wp_nonce_field( plugin_basename(__FILE__), 'rating_stars_save_meta_box');
echo '<p>Voto: <input type="number" name="rating_stars" value="'.esc_attr($rating_stars).'" min="1" max="5" step=".5" /></p>';
}
add_action('save_post','rating_stars_save_meta_box');
function rating_stars_save_meta_box($post_id) {
if(isset($_POST['rating_stars'])) {
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return;
wp_verify_nonce( plugin_basename(__FILE__), 'rating_stars_save_meta_box');
update_post_meta($post_id,'_rating_stars',sanitize_text_field($_POST['rating_stars']));
}
}
// Metabox per scheda film
add_action('add_meta_boxes','movie_box_meta_box_init');
function movie_box_meta_box_init() {
add_meta_box("moviebox-meta", "Scheda film", "movie_box_meta_box", "post", "side", "high", null);
}
function movie_box_meta_box($post) {
$movie_box = get_post_meta($post->ID,'_movie_box', true);
wp_nonce_field( plugin_basename(__FILE__), 'movie_box_save_meta_box');
echo '<p>ID film: <input type="text" name="movie_box" value="'.esc_attr($movie_box).'" /></p>';
}
add_action('save_post','movie_box_save_meta_box');
function movie_box_save_meta_box($post_id) {
if(isset($_POST['movie_box'])) {
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return;
wp_verify_nonce( plugin_basename(__FILE__), 'movie_box_save_meta_box');
update_post_meta($post_id,'_movie_box',sanitize_text_field($_POST['movie_box']));
}
}
// Aggiungi variabile query placeholder id per singolo film
function add_custom_query_var( $vars ){
$vars[] = "id";
return $vars;
}
add_filter( 'query_vars', 'add_custom_query_var' );