/
functions.php
341 lines (312 loc) · 12.6 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
<?php
// Recommended plugins installer
require_once 'include/plugins/init.php';
require_once('include/wpadmin/admin-addons.php');
function my_acf_init()
{
acf_update_setting('google_api_key', 'AIzaSyAOfuigGs3rWzZsdcWmQTeGU82RGccVqfc');
}
add_action('acf/init', 'my_acf_init');
function style_js()
{
if (is_page_template("tpl-contact.php") || is_front_page()) {
wp_enqueue_script('gmap', "//maps.googleapis.com/maps/api/js?v=3.exp&language=en&key=AIzaSyAOfuigGs3rWzZsdcWmQTeGU82RGccVqfc", '', null);
}
wp_enqueue_script('lib', get_template_directory_uri() . '/js/lib.js', array('jquery'), '1.0', true);
wp_enqueue_script('logic', get_template_directory_uri() . '/js/logic.js', array('jquery'), '1.0', true);
wp_enqueue_style('fonts', get_template_directory_uri() . '/style/fonts.css');
wp_enqueue_style('outer', get_template_directory_uri() . '/style/outer.css');
wp_enqueue_style('style', get_template_directory_uri() . '/style/style.css');
}
add_action('wp_enqueue_scripts', 'style_js');
// HTML5 support for IE
function wp_IEhtml5_js () {
global $is_IE;
if ($is_IE)
echo '<!--[if lt IE 9]><script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script><script src="//css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]--><!--[if lte IE 9]><link href="'.theme().'/style/animations-ie-fix.css" rel="stylesheet" /><![endif]-->';
}
add_action('wp_head', 'wp_IEhtml5_js');
// Custom theme url
function theme($filepath = NULL){
return preg_replace( '(https?://)', '//', get_stylesheet_directory_uri() . ($filepath?'/' . $filepath:'') );
}
//register menus
register_nav_menus(array(
'main_menu' => 'Main menu',
));
//register sidebar
$reg_sidebars = array (
'page_sidebar' => 'Page Sidebar',
'blog_sidebar' => 'Blog Sidebar',
'footer_sidebar' => 'Footer Area'
);
foreach ( $reg_sidebars as $id => $name ) {
register_sidebar(
array (
'name' => __( $name ),
'id' => $id,
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widgetTitle">',
'after_title' => '</h2>',
)
);
}
if(function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'Theme General Settings',
'menu_title' => 'Theme Settings',
'menu_slug' => 'theme-general-settings',
'capability' => 'edit_posts',
'redirect' => false
));
}
add_theme_support( 'post-thumbnails' );
//images sizes
add_image_size( 'free', '1920', '', true );
//light function fo wp_get_attachment_image_src()
function image_src($id, $size = 'full', $background_image = false, $height = false) {
if ($image = wp_get_attachment_image_src($id, $size, true)) {
return $background_image ? 'background-image: url('.$image[0].');' . ($height?'min-height:'.$image[2].'px':'') : $image[0];
}
}
//clear wp_head
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'parent_post_rel_link', 10, 0);
remove_action('wp_head', 'start_post_rel_link', 10, 0);
remove_action('wp_head', 'wp_shortlink_wp_head' );
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head' );
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'rel_canonical');
//remove_action('wp_head', 'qtrans_header', 10, 0);
add_action('widgets_init', 'my_remove_recent_comments_style');
function my_remove_recent_comments_style() {
global $wp_widget_factory;
remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style'));
}
// Remove Emoji js/styles
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
// Remove wp version param from any enqueued scripts
function vc_remove_wp_ver_css_js( $src ) {
if ( strpos( $src, 'ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'vc_remove_wp_ver_css_js', 9999 );
add_filter( 'script_loader_src', 'vc_remove_wp_ver_css_js', 9999 );
/* BEGIN: Theme config section*/
define ('HOME_PAGE_ID', get_option('page_on_front'));
define ('BLOG_ID', get_option('page_for_posts'));
define ('POSTS_PER_PAGE', get_option('posts_per_page'));
/*define ('SHOP_ID', get_option('woocommerce_shop_page_id'));
define ('ACCOUNT_ID', get_option('woocommerce_myaccount_page_id'));
define ('CART_ID', get_option('woocommerce_cart_page_id'));
define ('CHECKOUT_ID', get_option('woocommerce_checkout_page_id'));*/
/* END: Theme config section*/
//New Body Classes
function new_body_classes( $classes ){
if( is_page() ){
global $post;
$temp = get_page_template();
if ( $temp != null ) {
$path = pathinfo($temp);
$tmp = $path['filename'] . "." . $path['extension'];
$tn= str_replace(".php", "", $tmp);
$classes[] = $tn;
}
if (is_active_sidebar('sidebar')) {
$classes[] = 'with_sidebar';
}
foreach($classes as $k => $v) {
if(
$v == 'page-template' ||
$v == 'page-id-'.$post->ID ||
$v == 'page-template-default' ||
$v == 'woocommerce-page' ||
($temp != null?($v == 'page-template-'.$tn.'-php' || $v == 'page-template-'.$tn):'')) unset($classes[$k]);
}
}
if( is_single() ){
global $post;
$f = get_post_format( $post->ID );
foreach($classes as $k => $v) {
if($v == 'postid-'.$post->ID || $v == 'single-format-'.(!$f?'standard':$f)) unset($classes[$k]);
}
}
global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
$browser = $_SERVER[ 'HTTP_USER_AGENT' ];
// Mac, PC ...or Linux
if ( preg_match( "/Mac/", $browser ) ){
$classes[] = 'macos';
} elseif ( preg_match( "/Windows/", $browser ) ){
$classes[] = 'windows';
} elseif ( preg_match( "/Linux/", $browser ) ) {
$classes[] = 'linux';
} else {
$classes[] = 'unknown-os';
}
// Checks browsers in this order: Chrome, Safari, Opera, MSIE, FF
if ( preg_match( "/Chrome/", $browser ) ) {
$classes[] = 'chrome';
preg_match( "/Chrome\/(\d.\d)/si", $browser, $matches);
@$classesh_version = 'ch' . str_replace( '.', '-', $matches[1] );
$classes[] = $classesh_version;
} elseif ( preg_match( "/Safari/", $browser ) ) {
$classes[] = 'safari';
preg_match( "/Version\/(\d.\d)/si", $browser, $matches);
$sf_version = 'sf' . str_replace( '.', '-', $matches[1] );
$classes[] = $sf_version;
} elseif ( preg_match( "/Opera/", $browser ) ) {
$classes[] = 'opera';
preg_match( "/Opera\/(\d.\d)/si", $browser, $matches);
$op_version = 'op' . str_replace( '.', '-', $matches[1] );
$classes[] = $op_version;
} elseif ( preg_match( "/MSIE/", $browser ) ) {
$classes[] = 'msie';
if( preg_match( "/MSIE 6.0/", $browser ) ) {
$classes[] = 'ie6';
} elseif ( preg_match( "/MSIE 7.0/", $browser ) ){
$classes[] = 'ie7';
} elseif ( preg_match( "/MSIE 8.0/", $browser ) ){
$classes[] = 'ie8';
} elseif ( preg_match( "/MSIE 9.0/", $browser ) ){
$classes[] = 'ie9';
}
} elseif ( preg_match( "/Firefox/", $browser ) && preg_match( "/Gecko/", $browser ) ) {
$classes[] = 'firefox';
preg_match( "/Firefox\/(\d)/si", $browser, $matches);
$ff_version = 'ff' . str_replace( '.', '-', $matches[1] );
$classes[] = $ff_version;
} else {
$classes[] = 'unknown-browser';
}
//qtranslate classes
if(defined('QTX_VERSION')) {
$classes[] = 'qtrans-' . qtranxf_getLanguage();
}
return $classes;
}
add_filter( 'body_class', 'new_body_classes' );
//remove ID in menu list
add_filter('nav_menu_item_id', 'clear_nav_menu_item_id', 10, 3);
function clear_nav_menu_item_id($id, $item, $args) {
return "";
}
function content_button($atts,$content = null){
extract(shortcode_atts(array(
'link' => '#',
'class' => false,
'target' => false
), $atts ));
return '<a href="' . $link . '" class="button'.($class?' '.$class:'').'" '.($target?'target="'.$target.'"':'').'>' . do_shortcode($content) . '</a>';
}
add_shortcode("button", "content_button");
//custom SEO title
function seo_title(){
global $post;
if(!defined('WPSEO_VERSION')) {
if(is_404()) {
echo '404 Page not found - ';
} elseif((is_single() || is_page()) && $post->post_parent) {
$parent_title = get_the_title($post->post_parent);
echo wp_title('-', true, 'right') . $parent_title.' - ';
} elseif(class_exists('Woocommerce') && is_shop()) {
echo get_the_title(SHOP_ID) . ' - ';
} else {
wp_title('-', true, 'right');
}
bloginfo('name');
} else {
wp_title();
}
}
/* Update wp-scss setings
========================================================================== */
if (class_exists('Wp_Scss_Settings')) {
$wpscss = get_option('wpscss_options');
if (empty($wpscss['css_dir']) && empty($wpscss['scss_dir'])) {
update_option('wpscss_options', array('css_dir' => '/style/', 'scss_dir' => '/style/', 'compiling_options' => 'scss_formatter_compressed'));
}
}
function cc_mime_types($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
function wpa_fix_svg_thumb() {
echo '<style>td.media-icon img[src$=".svg"], img[src$=".svg"].attachment-post-thumbnail {width: 100% !important;height: auto !important}</style>';
}
add_action('admin_head', 'wpa_fix_svg_thumb');
// Contact form 7 remove AUTOTOP
if(defined('WPCF7_VERSION')) {
function maybe_reset_autop( $form ) {
$form_instance = WPCF7_ContactForm::get_current();
$manager = WPCF7_ShortcodeManager::get_instance();
$form_meta = get_post_meta( $form_instance->id(), '_form', true );
$form = $manager->do_shortcode( $form_meta );
$form_instance->set_properties( array(
'form' => $form
) );
return $form;
}
add_filter( 'wpcf7_form_elements', 'maybe_reset_autop' );
}
//Widgets extension
add_filter('widget_categories_args','show_empty_widget_links');
add_filter('widget_tag_cloud_args','show_empty_widget_links');
//Show empty categories in category widget
function show_empty_widget_links($args) {
$args['hide_empty'] = 0;
return $args;
}
/* ACF Repeater Styles */
function acf_repeater_even() {
$scheme = get_user_option( 'admin_color' );
$color = '';
if($scheme == 'fresh') {
$color = '#0073aa';
} else if($scheme == 'light') {
$color = '#d64e07';
} else if($scheme == 'blue') {
$color = '#52accc';
} else if($scheme == 'coffee') {
$color = '#59524c';
} else if($scheme == 'ectoplasm') {
$color = '#523f6d';
} else if($scheme == 'midnight') {
$color = '#e14d43';
} else if($scheme == 'ocean') {
$color = '#738e96';
} else if($scheme == 'sunrise') {
$color = '#dd823b';
}
echo '<style>.acf-repeater > table > tbody > tr:nth-child(even) > td.order {color: #fff !important;background-color: '.$color.' !important; text-shadow: none}.acf-fc-layout-handle {color: #fff !important;background-color: #23282d!important; text-shadow: none}</style>';
}
add_action('admin_footer', 'acf_repeater_even');
function some() {
$some = get_field('some', 'option');
$soc = '';
if($some) {
$soc .= '<div class="some">';
foreach($some as $sm) {
$soc .= '<a class="fa fa-'.$sm['icon'].'" target="_blank" href="'.$sm['link'].'" rel="nofollow"></a>';
}
$soc .= '</div>';
}
return $soc;
}
add_shortcode("social", "some");
/*add_theme_support("woocommerce");
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
// Remove the sorting dropdown from Woocommerce
remove_action( 'woocommerce_before_shop_loop' , 'woocommerce_catalog_ordering', 30 );
// Remove the result count from WooCommerce
remove_action( 'woocommerce_before_shop_loop' , 'woocommerce_result_count', 20 );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );*/