-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwordpress-function-sample.php
More file actions
492 lines (445 loc) · 18.2 KB
/
wordpress-function-sample.php
File metadata and controls
492 lines (445 loc) · 18.2 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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
<?php
define('THEME_PATH', trailingslashit(get_stylesheet_directory()));
/**
* Theme Support: Vida Plena
*/
if (!function_exists('theme_setup')) :
function theme_setup($wp_customize)
{
add_theme_support('menus');
add_theme_support('widgets');
add_theme_support('widgets-block-editor');
add_theme_support('wp-block-styles');
/** automatic feed link*/
add_theme_support('automatic-feed-links');
/** tag-title **/
add_theme_support('title-tag');
/** post formats */
$post_formats = array('aside', 'image', 'gallery', 'video', 'audio', 'link', 'quote', 'status');
add_theme_support('post-formats', $post_formats);
/** post thumbnail **/
add_theme_support('post-thumbnails');
/** HTML5 support **/
add_theme_support('html5', array('comment-list', 'comment-form', 'search-form', 'gallery', 'caption'));
/** refresh widgest **/
add_theme_support('customize-selective-refresh-widgets');
/** custom log **/
add_theme_support('custom-logo', array(
'height' => 62,
'width' => 140,
'flex-height' => true,
'flex-width' => true,
'header-text' => array('site-title', 'site-description'),
));
// Image size for single posts
add_image_size( 'single_post_thumbnail', 320, 180 );
add_image_size( 'single_filter_thumbnail', 206, 114 );
add_image_size( 'page_top_banner', 960, 230 );
register_nav_menus(
array(
'menu-header' => __('Cabeçalho', 'vida-plena'),
'menu-principal' => __('Principal', 'vida-plena'),
'menu-footer-left' => __("Rodapé - Esquerdo", 'vida-plena'),
'menu-footer-right' => __("Rodapé - Direito", 'vida-plena')
)
);
}
endif; // theme_setup
add_action('after_setup_theme', 'theme_setup');
/**
* Widgets Registration
*
* @param $name - string - widget name.
* @param $id - string - widget id/slug.
* @param $description - string.
* @param $beforeWidget - string - element insert before the widget.
* @param $afterWidget - string - element insert after the widget.
* @param $beforeTitle - string - element insert after the widget title.
* @param $afterTitle - string - element insert after the widget title.
* @return void
*/
function custom_theme_widget_registration($name, $id, $description, $beforeWidget, $afterWidget, $beforeTitle, $afterTitle)
{
register_sidebar(array(
'name' => $name,
'id' => $id,
'description' => $description,
'before_widget' => $beforeWidget,
'after_widget' => $afterWidget,
'before_title' => $beforeTitle,
'after_title' => $afterTitle,
));
}
function custom_theme_multiple_widget_init()
{
custom_theme_widget_registration('Footer Logo - Vida Plena', 'footer-logo', 'Footer logo - Vida Plena', '<li id="%1$s" class="footer-logo widget %2$s">', '</li>', '', '');
custom_theme_widget_registration('Footer Imagem - Informações de contato', 'footer-contato', 'Footer Imagem Contato - Vida Plena', '<li id="%1$s" class="footer-contact widget %2$s">', '</li>', '', '');
custom_theme_widget_registration('Footer Disclaimer', 'footer-disclaimer', 'Footer Disclaimer - Vida Plena', '', '', '', '');
custom_theme_widget_registration('Footer Redes Sociais', 'footer-social-links', 'Footer Redes Sociais - Vida Plena', '', '', '', '');
}
add_action('widgets_init', 'custom_theme_multiple_widget_init');
/**
* Gutenberg Blocks - Register category "Vida Plena" and update it's order
*
* @param $categories - array
* @return $newCategories - array
*/
function custom_theme_blocks_category_order($categories)
{
//custom category array
$temp = array(
'slug' => 'vida-plena',
'title' => 'Vida Plena'
);
//new categories array and adding new custom category at first location
$newCategories = array();
$newCategories[0] = $temp;
//appending original categories in the new array
foreach ($categories as $category) {
$newCategories[] = $category;
}
//return new categories
return $newCategories;
}
add_filter( 'block_categories', 'custom_theme_blocks_category_order', 99, 1);
/*
* Gutenberg - Define blocks
*/
function custom_theme_define_blocks()
{
if (function_exists('acf_register_block_type')) {
acf_register_block_type(array(
'name' => 'social-links',
'title' => __('Redes sociais - Footer'),
'description' => __('Redes sociais do Rodapé'),
'render_callback' => 'custom_theme_render_social_links_block',
'category' => 'vida-plena',
'icon' => 'share',
'keywords' => array('Vida Plena', 'Redes socais', "Social links", 'acf'),
'example' => array(
'attributes' => array(
'mode' => 'preview',
'data' => array(
'_is_preview' => 'true',
'preview_image_help' => get_template_directory_uri() . '/assets/img/ACF/acf-social-footer-preview.jpg'
)
)
),
));
acf_register_block_type(array(
'name' => 'block-image-left',
'title' => __('Bloco Imagem + texto - Esquerda'),
'description' => __('Bloco Imagem + texto - Esquerda'),
'render_callback' => 'custom_theme_render_block_image_left',
'category' => 'vida-plena',
'icon' => 'align-pull-left',
'keywords' => array('Vida Plena', 'Blocos', "Imagem", 'acf'),
'example' => array(
'attributes' => array(
'mode' => 'preview',
'data' => array(
'_is_preview' => 'true',
'preview_image_help' => get_template_directory_uri() . '/assets/img/ACF/acf-block-image-left.jpg'
)
)
),
));
acf_register_block_type(array(
'name' => 'block-image-right',
'title' => __('Bloco Imagem + texto - Direita'),
'description' => __('Bloco Imagem + texto - Direita'),
'render_callback' => 'custom_theme_render_block_image_right',
'category' => 'vida-plena',
'icon' => 'align-pull-right',
'keywords' => array('Vida Plena', 'Blocos', "Imagem", 'acf'),
'example' => array(
'attributes' => array(
'mode' => 'preview',
'data' => array(
'_is_preview' => 'true',
'preview_image_help' => get_template_directory_uri() . '/assets/img/ACF/acf-block-image-right.jpg'
)
)
),
));
acf_register_block_type(array(
'name' => 'block-divider',
'title' => __('Divisória'),
'description' => __('Divisória'),
'render_callback' => 'custom_theme_render_block_divider',
'category' => 'vida-plena',
'icon' => 'minus',
'keywords' => array('Vida Plena', 'Divisória', 'acf'),
'example' => array(
'attributes' => array(
'mode' => 'preview',
'data' => array(
'_is_preview' => 'true',
'preview_image_help' => get_template_directory_uri() . '/assets/img/ACF/acf-block-divider.jpg'
)
)
),
));
acf_register_block_type(array(
'name' => 'block-posts',
'title' => __('Bloco estilo posts'),
'description' => __('Bloco estilo posts'),
'render_callback' => 'custom_theme_render_block_posts',
'category' => 'vida-plena',
'icon' => 'layout',
'keywords' => array('Vida Plena', 'Post', 'acf'),
'example' => array(
'attributes' => array(
'mode' => 'preview',
'data' => array(
'_is_preview' => 'true',
'preview_image_help' => get_template_directory_uri() . '/assets/img/ACF/acf-block-posts.jpg'
)
)
),
));
acf_register_block_type(array(
'name' => 'theme-button',
'title' => __('Botão - Tema'),
'description' => __('Botão - Tema'),
'render_callback' => 'custom_theme_render_button',
'category' => 'vida-plena',
'icon' => 'button',
'keywords' => array('Vida Plena', 'Botão', 'acf'),
'example' => array(
'attributes' => array(
'mode' => 'preview',
'data' => array(
'_is_preview' => 'true',
'preview_image_help' => get_template_directory_uri() . '/assets/img/ACF/acf-button.jpg'
)
)
),
));
/* Theme Citation */
acf_register_block_type(array(
'name' => 'block-theme-quote',
'title' => __('Citação - Simples'),
'description' => __('Citaação - Simples'),
'render_callback' => 'custom_theme_render_block_theme_quote',
'category' => 'vida-plena',
'icon' => 'editor-quote',
'keywords' => array('Vida Plena', 'Citação', 'acf'),
'example' => array(
'attributes' => array(
'mode' => 'preview',
'data' => array(
'_is_preview' => 'true',
'preview_image_help' => get_template_directory_uri() . '/assets/img/ACF/acf-quote.jpg'
)
)
),
));
/* Theme Author Citation */
acf_register_block_type(array(
'name' => 'block-author-quote',
'title' => __('Citação - Autor'),
'description' => __('Citação - Autor'),
'render_callback' => 'custom_theme_render_block_author_quote',
'category' => 'vida-plena',
'icon' => 'editor-quote',
'keywords' => array('Vida Plena', 'Citação', 'acf'),
'example' => array(
'attributes' => array(
'mode' => 'preview',
'data' => array(
'_is_preview' => 'true',
'preview_image_help' => get_template_directory_uri() . '/assets/img/ACF/acf-author-quote.jpg'
)
)
),
));
/* Theme Vídeo Full */
acf_register_block_type(array(
'name' => 'block-video-full',
'title' => __('Vídeo - Full'),
'description' => __('Vídeo - Full'),
'render_callback' => 'custom_theme_render_block_video_full',
'category' => 'vida-plena',
'icon' => 'format-video',
'keywords' => array('Vida Plena', 'Vídeo', 'acf'),
'example' => array(
'attributes' => array(
'mode' => 'preview',
'data' => array(
'_is_preview' => 'true',
'preview_image_help' => get_template_directory_uri() . '/assets/img/ACF/acf-video-full.jpg'
)
)
),
));
acf_register_block_type(array(
'name' => 'block-newsletter',
'title' => __('Bloco Newsletter'),
'description' => __('Bloco Newsletter'),
'render_callback' => 'custom_theme_render_block_newsletter',
'category' => 'vida-plena',
'icon' => 'email-alt',
'keywords' => array('Vida Plena', 'Newsletter', 'acf'),
'example' => array(
'attributes' => array(
'mode' => 'preview',
'data' => array(
'_is_preview' => 'true',
'preview_image_help' => get_template_directory_uri() . '/assets/img/ACF/acf-block-newsletter.jpg'
)
)
),
));
}
}
add_action('acf/init', 'custom_theme_define_blocks');
function custom_theme_render_social_links_block($block)
{
$slug = str_replace('acf/', '', $block['name']);
if (file_exists(THEME_PATH . "blocks/content-{$slug}.php")) {
include(THEME_PATH . "blocks/content-{$slug}.php");
}
}
function custom_theme_render_block_image_left($block)
{
$slug = str_replace('acf/', '', $block['name']);
if (file_exists(THEME_PATH . "blocks/content-{$slug}.php")) {
include(THEME_PATH . "blocks/content-{$slug}.php");
}
}
function custom_theme_render_block_image_right($block)
{
$slug = str_replace('acf/', '', $block['name']);
if (file_exists(THEME_PATH . "blocks/content-{$slug}.php")) {
include(THEME_PATH . "blocks/content-{$slug}.php");
}
}
function custom_theme_render_block_divider($block)
{
$slug = str_replace('acf/', '', $block['name']);
if (file_exists(THEME_PATH . "blocks/content-{$slug}.php")) {
include(THEME_PATH . "blocks/content-{$slug}.php");
}
}
function custom_theme_render_block_posts($block)
{
$slug = str_replace('acf/', '', $block['name']);
if (file_exists(THEME_PATH . "blocks/content-{$slug}.php")) {
include(THEME_PATH . "blocks/content-{$slug}.php");
}
}
function custom_theme_render_button($block)
{
$slug = str_replace('acf/', '', $block['name']);
if (file_exists(THEME_PATH . "blocks/content-{$slug}.php")) {
include(THEME_PATH . "blocks/content-{$slug}.php");
}
}
function custom_theme_render_block_theme_quote($block)
{
$slug = str_replace('acf/', '', $block['name']);
if (file_exists(THEME_PATH . "blocks/content-{$slug}.php")) {
include(THEME_PATH . "blocks/content-{$slug}.php");
}
}
function custom_theme_render_block_author_quote($block)
{
$slug = str_replace('acf/', '', $block['name']);
if (file_exists(THEME_PATH . "blocks/content-{$slug}.php")) {
include(THEME_PATH . "blocks/content-{$slug}.php");
}
}
function custom_theme_render_block_video_full($block)
{
$slug = str_replace('acf/', '', $block['name']);
if (file_exists(THEME_PATH . "blocks/content-{$slug}.php")) {
include(THEME_PATH . "blocks/content-{$slug}.php");
}
}
function custom_theme_render_block_newsletter($block)
{
$slug = str_replace('acf/', '', $block['name']);
if (file_exists(THEME_PATH . "blocks/content-{$slug}.php")) {
include(THEME_PATH . "blocks/content-{$slug}.php");
}
}
/*
* Register Theme Styles
*/
function custom_theme_register_styles()
{
// $version = wp_get_theme()->get( 'Version' );
$version = rand(11111, 99999);
// Font Awesome
wp_enqueue_style('custom_theme-fontawesome-style', get_template_directory_uri() . "/assets/vendor/fontawesome/css/all.min.css", array(), '5.15.3', 'all');
// Animate Plugin
wp_enqueue_style('custom_theme-animate-style', get_template_directory_uri() . "/assets/vendor/animate.css/animate.min.css", array(), '4.1.1', 'all');
// Slick Slide
wp_enqueue_style('custom_theme-slick-style', get_template_directory_uri() . "/assets/vendor/slick/slick.css", array(), '1.8.0', 'all');
wp_enqueue_style('custom_theme-slick-theme-style', get_template_directory_uri() . "/assets/vendor/slick/slick-theme.css", array(), '1.8.0', 'all');
// Custom Scrollbar
wp_enqueue_style('custom_theme-custom-scrollbar-style', get_template_directory_uri() . "/assets/vendor/custom-scrollbar/jquery.mCustomScrollbar.min.css", array(), '3.1.13', 'all');
// Theme Style
wp_enqueue_style('custom_theme-style', get_template_directory_uri() . "/assets/css/style.min.css", array(), $version, 'all');
}
add_action('wp_enqueue_scripts', 'custom_theme_register_styles');
/**
* Gutenberg - Add block editor styles
*/
function add_block_editor_assets()
{
wp_enqueue_style('block_editor_css', get_template_directory_uri() . "/assets/css/editor-blocks.css");
wp_enqueue_style('block_fonts_css', get_template_directory_uri() . "/assets/css/editor-fonts.css");
}
add_action('enqueue_block_editor_assets', 'add_block_editor_assets', 10, 0);
/**
* Hook for additional special mail tag - Date formt d/m/Y H:i
*
* @param $output - string
* @param $name - string
* @param $html - string
* @return $output - string - data formatted
*/
add_filter( 'wpcf7_special_mail_tags', 'custom_theme_wti_format_date_tag', 20, 3 );
function custom_theme_wti_format_date_tag( $output, $name, $html )
{
// For backwards compatibility
$name = preg_replace( '/^wpcf7\./', '_', $name );
if ( '_format_date_time' == $name ) {
date_default_timezone_set('America/Sao_Paulo');
$output = date("d/m/Y H:i");
}
return $output;
}
/*
* Check if email_already_in_db - Newsletter - Advanced contact form 7
*/
add_filter( 'wpcf7_validate', 'custom_theme_newsletter_email_already_in_db', 10, 2 );
function custom_theme_newsletter_email_already_in_db ( $result, $tags ) {
$form = WPCF7_Submission::get_instance();
$form_posted_data = $form->get_posted_data();
$contact_form = WPCF7_ContactForm::get_current();
$contact_form_id = $contact_form -> id;
$unique_field_name = preg_grep("/unique(\w+)/", array_keys($form_posted_data));
reset($unique_field_name);
$first_key = key($unique_field_name);
$unique_field_name = $unique_field_name[$first_key];
// Check the form submission unique field vs what is already in the database
$email = $form->get_posted_data($unique_field_name);
global $wpdb;
$entry = $wpdb->get_results( "SELECT * FROM vp_db7_forms WHERE form_post_id = $contact_form_id AND form_value LIKE '%$unique_field_name%' AND form_value LIKE '%$email%'" );
// If already in database, invalidate
if (!empty($entry)) {
$result->invalidate($unique_field_name, 'E-mail já cadastrado!');
}
// return the filtered value
return $result;
}
/**
* Custom Login CSS
*/
function custom_theme_login_stylesheet() {
wp_enqueue_style( 'custom-login', get_template_directory_uri() . '/css/admin-style-login.css' );
}
add_action( 'login_enqueue_scripts', 'custom_theme_login_stylesheet' );