-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
111 lines (91 loc) · 3.05 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
<?php
define('PP_VERSION', '1.6.3');
// movie / game ratings
define('PP_RATINGS', [
'pele' => '💩 Era melhor ter ido ver o Pelé...',
'tela_quente' => '📺 Espera passar na Tela Quente...',
'streaming' => '💻 Vale o streaming',
'ingresso' => '🎟️ Vale o ingresso!',
'3d' => '🍿 Tão bom que vale até o 3D!!!'
]);
add_theme_support( 'post-thumbnails' );
add_theme_support( 'custom-logo' );
function add_nav_menus() {
register_nav_menu('header-menu',__('Header Menu'));
register_nav_menu('footer-menu',__('Footer Menu'));
}
add_action('init','add_nav_menus');
function excerpt($limit, $postId = null) {
if ($postId)
$excerpt = explode(' ', get_the_excerpt($postId), $limit);
else
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt) >= $limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).' [...]';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`[[^]]*]`', '', $excerpt);
return $excerpt;
}
function create_custom_posttypes() {
register_post_type( 'home',
array(
'labels' => array(
'name' => __( 'Home Content' ),
'singular_name' => __( 'Home Content' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'home'),
'show_in_rest' => true,
'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields')
)
);
register_post_type( 'playlist',
[
'labels' => [
'name' => __( 'Playlists' ),
'singular_name' => __( 'Playlists' )
],
'public' => true,
'has_archive' => true,
'rewrite' => ['slug' => 'playlist'],
'show_in_rest' => true,
'supports' => ['title', 'excerpt', 'thumbnail', 'custom-fields']
]
);
}
add_action( 'init', 'create_custom_posttypes' );
// ========== CONTACT ==========
function pp_contact() {
$to = '[email protected]';
$name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$email = filter_var($_POST['email'], FILTER_SANITIZE_STRING);
$msg = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
$headers = ['Content-Type: text/html; charset=ISO-8859-1'];
$message .= 'Nome: ' . $name . '<br/>' .
'E-mail: ' . $email . '<br/>' .
'Mensagem: ' . $msg . '<br/>';
$sentMail = wp_mail( $to, 'Formulário de Contato', $message, $headers);
if ($sentMail)
echo 'Obrigado pelo contato!';
else
echo 'Ocorreu um erro ao entregar sua mensagem!';
die();
}
add_action('wp_ajax_pp_contact', 'pp_contact');
add_action('wp_ajax_nopriv_pp_contact', 'pp_contact');
function pp_getRatingLabel($rating) {
if (is_numeric($rating)) {
$starsLabel = '';
$star = ($rating >= 4) ? (($rating >= 6) ? (($rating >= 8.5) ? '⭐' : '★') : '☆') : '👾';
for ($i=0; $i < intval($rating); $i++) {
$starsLabel .= $star;
}
return $starsLabel;
} else {
return PP_RATINGS[$rating];
}
}