forked from redelivre/coletivo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
358 lines (311 loc) · 11.1 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
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
<?php
/**
* Coletivo functions and definitions.
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package Coletivo
*/
defined( 'ABSPATH' ) || exit;
/**
* Current version number
*
* @var string
* @since 1.7
*/
const VERSION = '1.7';
/**
* Theme URI
*
* @var string
* @since 1.7
*/
const THEME_URI = 'https://tema.coletivowp.com.br';
/**
* Theme Wiki GitHub URI
*
* @var string
* @since 1.7
*/
const THEME_WIKI_GITHUB_URI = 'https://github.com/redelivre/coletivo/wiki/Inicial';
if ( ! function_exists( 'coletivo_setup' ) ) {
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function coletivo_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on coletivo, use a find and replace
* to change 'coletivo' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'coletivo', get_template_directory() . '/languages' );
/*
* Add default posts and comments RSS feed links to head.
*/
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/**
* Excerpt for page
*/
add_post_type_support( 'page', 'excerpt' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
add_image_size( 'coletivo-blog-small', 300, 150, true );
add_image_size( 'coletivo-small', 480, 300, true );
add_image_size( 'coletivo-medium', 640, 400, true );
/*
* This theme uses wp_nav_menu() in one location.
*/
register_nav_menus(
array(
'primary' => esc_html__( 'Primary Menu', 'coletivo' ),
'secondary' => esc_html__( 'Page Menu', 'coletivo' ),
)
);
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
)
);
/*
* This theme styles the visual editor to resemble the theme style.
*/
add_editor_style( array( 'assets/css/editor-style.css', coletivo_fonts_url() ) );
/*
* WooCommerce support.
*/
add_theme_support( 'woocommerce' );
/**
* Add theme Support custom logo
*
* @since WP 4.5
* @since 1.2.1
*/
add_theme_support(
'custom-logo',
array(
'height' => 36,
'width' => 160,
'flex-height' => true,
'flex-width' => true,
)
);
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
}
}
add_action( 'after_setup_theme', 'coletivo_setup' );
/**
* Set the initial configs in theme activation
*/
add_action( 'after_setup_theme', 'coletivo_initial_config' );
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
function coletivo_content_width() {
$GLOBALS['content_width'] = apply_filters( 'coletivo_content_width', 800 );
}
add_action( 'after_setup_theme', 'coletivo_content_width', 0 );
/**
* Add theme support for Portfolio Custom Post Type.
*/
function slug_jetpack_portfolio_cpt() {
add_theme_support( 'jetpack-portfolio' );
}
add_action( 'after_setup_theme', 'slug_jetpack_portfolio_cpt' );
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function coletivo_widgets_init() {
register_sidebar(
array(
'name' => esc_html__( 'Sidebar', 'coletivo' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Default sidebar for blog template', 'coletivo' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => esc_html__( 'Page', 'coletivo' ),
'id' => 'sidebar-2',
'description' => esc_html__( 'Sidebar for template With Sidebar', 'coletivo' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
add_action( 'widgets_init', 'coletivo_widgets_init' );
/**
* Enqueue scripts and styles.
*/
function coletivo_scripts() {
// Check if a child theme or a plugin disable default fonts.
if ( true === apply_filters( 'coletivo_load_default_fonts', true ) ) {
wp_enqueue_style( 'coletivo-fonts', coletivo_fonts_url(), array(), VERSION );
}
wp_enqueue_style( 'coletivo-animate', get_template_directory_uri() . '/assets/css/animate.min.css', array(), '1.0.0' );
wp_enqueue_style( 'coletivo-fa', get_template_directory_uri() . '/assets/css/font-awesome.min.css', array(), '4.4.0' );
wp_enqueue_style( 'coletivo-bootstrap', get_template_directory_uri() . '/assets/css/bootstrap.min.css', false, '4.0.0' );
wp_enqueue_style( 'coletivo-style', get_template_directory_uri() . '/style.css', false, VERSION );
if ( is_child_theme() ) {
wp_enqueue_style( 'coletivo-style-child', get_stylesheet_directory_uri() . '/style.css', false, VERSION );
}
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'coletivo-js-plugins', get_template_directory_uri() . '/assets/js/plugins.js', array(), '1.0.0', true );
wp_enqueue_script( 'coletivo-js-bootstrap', get_template_directory_uri() . '/assets/js/bootstrap.min.js', array(), '4.0.0', true );
wp_enqueue_script( 'coletivo-theme', get_template_directory_uri() . '/assets/js/theme.js', array(), '20120206', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
// Animation from settings.
$coletivo_js_settings = array(
'coletivo_disable_animation' => get_theme_mod( 'coletivo_animation_disable' ),
'coletivo_disable_sticky_header' => get_theme_mod( 'coletivo_sticky_header_disable' ),
'coletivo_vertical_align_menu' => get_theme_mod( 'coletivo_vertical_align_menu' ),
'hero_animation' => get_theme_mod( 'coletivo_hero_option_animation', 'flipInX' ),
'hero_speed' => intval( get_theme_mod( 'coletivo_hero_option_speed', 5000 ) ),
);
wp_localize_script( 'jquery', 'coletivo_js_settings', $coletivo_js_settings );
// Load gallery scripts.
$galley_disable = 1 === get_theme_mod( 'coletivo_gallery_disable' ) ? true : false;
if ( ! $galley_disable || is_customize_preview() ) {
$coletivo_js_settings['gallery_enable'] = 1;
$display = get_theme_mod( 'coletivo_gallery_display', 'grid' );
if ( ! is_customize_preview() ) {
switch ( $display ) {
case 'masonry':
wp_enqueue_script( 'coletivo-gallery-masonry', get_template_directory_uri() . '/assets/js/isotope.pkgd.min.js', array(), VERSION, true );
break;
case 'justified':
wp_enqueue_script( 'coletivo-gallery-justified', get_template_directory_uri() . '/assets/js/jquery.justifiedGallery.min.js', array(), VERSION, true );
break;
case 'slider':
case 'carousel':
wp_enqueue_script( 'coletivo-gallery-carousel', get_template_directory_uri() . '/assets/js/owl.carousel.min.js', array(), VERSION, true );
break;
default:
break;
}
} else {
wp_enqueue_script( 'coletivo-gallery-masonry', get_template_directory_uri() . '/assets/js/isotope.pkgd.min.js', array(), VERSION, true );
wp_enqueue_script( 'coletivo-gallery-justified', get_template_directory_uri() . '/assets/js/jquery.justifiedGallery.min.js', array(), VERSION, true );
wp_enqueue_script( 'coletivo-gallery-carousel', get_template_directory_uri() . '/assets/js/owl.carousel.min.js', array(), VERSION, true );
}
}
wp_enqueue_style( 'coletivo-gallery-lightgallery', get_template_directory_uri() . '/assets/css/lightgallery.css', false, VERSION );
wp_enqueue_script( 'coletivo-theme', get_template_directory_uri() . '/assets/js/theme.js', array(), VERSION, true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
if ( is_front_page() && is_page_template( 'template-frontpage.php' ) ) {
if ( get_theme_mod( 'coletivo_header_scroll_logo' ) ) {
$coletivo_js_settings['is_home'] = 1;
}
}
wp_localize_script( 'jquery', 'coletivo_js_settings', $coletivo_js_settings );
}
add_action( 'wp_enqueue_scripts', 'coletivo_scripts' );
if ( ! function_exists( 'coletivo_fonts_url' ) ) {
/**
* Register default Google fonts
*/
function coletivo_fonts_url() {
$fonts_url = '';
/*
* Translators: If there are characters in your language that are not
* supported by Open Sans, translate this to 'off'. Do not translate
* into your own language.
*/
$open_sans = _x( 'on', 'Open Sans font: on or off', 'coletivo' );
/*
* Translators: If there are characters in your language that are not
* supported by Raleway, translate this to 'off'. Do not translate
* into your own language.
*/
$raleway = _x( 'on', 'Raleway font: on or off', 'coletivo' );
if ( 'off' !== $raleway || 'off' !== $open_sans ) {
$font_families = array();
if ( 'off' !== $raleway ) {
$font_families[] = 'Raleway:400,500,600,700,300,100,800,900';
}
if ( 'off' !== $open_sans ) {
$font_families[] = 'Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic';
}
$query_args = array(
'family' => rawurlencode( implode( '|', $font_families ) ),
'subset' => rawurlencode( 'latin,latin-ext' ),
);
$fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
}
return esc_url_raw( $fonts_url );
}
}
if ( ! function_exists( 'coletivo_admin_scripts' ) ) {
/**
* Enqueue scripts for admin page only: Theme info page
*
* @param string $hook The hook.
*/
function coletivo_admin_scripts( $hook ) {
if ( 'widgets.php' === $hook || 'appearance_page_ft_coletivo' === $hook ) {
wp_enqueue_style( 'coletivo-admin-css', get_template_directory_uri() . '/assets/css/admin.css', false, VERSION );
}
}
}
add_action( 'admin_enqueue_scripts', 'coletivo_admin_scripts' );
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Custom functions that act independently of the theme templates.
*/
require get_template_directory() . '/inc/extras.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Update customizer fields from version < 1.5.1.
*/
require get_template_directory() . '/inc/customizer-update-fields.php';
/**
* Add theme info page
*/
require get_template_directory() . '/inc/dashboard.php';