-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
313 lines (197 loc) · 9.2 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
<?php
//
// Recommended way to include parent theme styles.
// (Please see http://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme)
//
function tanin_enqueue_styles() {
wp_enqueue_style( 'tanin-parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'tanin-style',
get_stylesheet_directory_uri() . '/style.css',
array('parent-style')
);
/**
* Theme Front end main js
*/
wp_enqueue_script( "tanin-script" , get_stylesheet_directory_uri() . '/assets/js/script.js' , array( 'jquery', 'carousel' , 'sed-livequery' , 'jquery-ui-accordion' , 'jquery-ui-tabs' ) , "1.0.0" , true );
//wp_enqueue_script('sed-masonry');
wp_enqueue_script('lightbox');
wp_enqueue_script('jquery-scrollbar');
wp_enqueue_style('custom-scrollbar');
wp_enqueue_style("carousel");
wp_enqueue_style("lightbox");
}
add_action( 'wp_enqueue_scripts', 'tanin_enqueue_styles' , 0 );
add_action( 'after_setup_theme', 'sed_tanin_theme_setup' );
function sed_tanin_theme_setup() {
load_child_theme_textdomain( 'tanin', get_stylesheet_directory() . '/languages' );
remove_filter( 'excerpt_more', 'twentyseventeen_excerpt_more' );
/**
* Short Description (excerpt).
*/
add_filter( 'tanin_short_description', 'wptexturize' );
add_filter( 'tanin_short_description', 'convert_smilies' );
add_filter( 'tanin_short_description', 'convert_chars' );
add_filter( 'tanin_short_description', 'wpautop' );
add_filter( 'tanin_short_description', 'shortcode_unautop' );
add_filter( 'tanin_short_description', 'prepend_attachment' );
add_filter( 'tanin_short_description', 'do_shortcode', 11 ); // AFTER wpautop()
// This theme uses wp_nav_menu() in two locations.
register_nav_menus( array(
'services' => __( 'Services Menu', 'twentyseventeen' ),
) );
}
function tanin_excerpt_more( $link ) {
if ( is_admin() ) {
return $link;
}
return ' … ';
}
add_filter( 'excerpt_more', 'tanin_excerpt_more' );
function tanin_excerpt_length( $length ) {
return 650;
}
add_filter( 'excerpt_length', 'tanin_excerpt_length', 999 );
/**
* Add Site Editor Modules
*
* @param $modules
* @return mixed
*/
function sed_tanin_add_modules( $modules ){
global $sed_pb_modules;
$module_name = "themes/tanin/site-editor/modules/posts/posts.php";
$modules[$module_name] = $sed_pb_modules->get_module_data(get_stylesheet_directory() . '/site-editor/modules/posts/posts.php', true, true);
$module_name = "themes/tanin/site-editor/modules/terms/terms.php";
$modules[$module_name] = $sed_pb_modules->get_module_data(get_stylesheet_directory() . '/site-editor/modules/terms/terms.php', true, true);
//$module_name = "themes/tanin/site-editor/modules/tanin-products/tanin-products.php";
//$modules[$module_name] = $sed_pb_modules->get_module_data(get_stylesheet_directory() . '/site-editor/modules/tanin-products/tanin-products.php', true, true);
$module_name = "themes/tanin/site-editor/modules/in-btn-back/in-btn-back.php";
$modules[$module_name ] = $sed_pb_modules->get_module_data(get_stylesheet_directory() . '/site-editor/modules/in-btn-back/in-btn-back.php', true, true);
$module_name = "themes/tanin/site-editor/modules/vertical-header/vertical-header.php";
$modules[$module_name ] = $sed_pb_modules->get_module_data(get_stylesheet_directory() . '/site-editor/modules/vertical-header/vertical-header.php', true, true);
$module_name = "themes/tanin/site-editor/modules/subscription/subscription.php";
$modules[$module_name ] = $sed_pb_modules->get_module_data(get_stylesheet_directory() . '/site-editor/modules/subscription/subscription.php', true, true);
return $modules;
}
add_filter("sed_modules" , "sed_tanin_add_modules" );
function tanin_register_theme_fields( $fields ){
$fields['products_archive_description'] = array(
'type' => 'textarea',
'label' => __('Product Archive Description', 'site-editor'),
//'description' => '',
'transport' => 'postMessage' ,
'setting_id' => 'tanin_products_archive_description',
'default' => '',
"panel" => "general_settings" ,
);
$fields['home_page_products_description'] = array(
'type' => 'textarea',
'label' => __('Home Page Product Description', 'site-editor'),
//'description' => '',
'transport' => 'postMessage' ,
'setting_id' => 'tanin_home_page_products_description',
'default' => '',
"panel" => "general_settings" ,
);
$locale = get_locale();
if( $locale == 'fa_IR' ) {
$fields['english_site_url'] = array(
'type' => 'text',
'label' => __('English Site Url', 'site-editor'),
//'description' => '',
'transport' => 'postMessage',
'setting_id' => 'tanin_english_site_url',
'default' => 'http://eng.tanin.com',
"panel" => "general_settings",
);
}
$fields[ 'intro_logo' ] = array(
'setting_id' => 'tanin_intro_logo',
'label' => __('Intro Logo', 'translation_domain'),
'type' => 'image',
//'priority' => 10,
'default' => '',
'transport' => 'postMessage' ,
'panel' => 'general_settings'
);
return $fields;
}
//add_filter( "sed_theme_options_fields_filter" , 'tanin_register_theme_fields' , 10000 );
add_action( 'pre_get_posts', 'tanin_per_page_query' );
/**
* Customize category query using pre_get_posts.
*
* @author FAT Media <http://youneedfat.com>
* @copyright Copyright (c) 2013, FAT Media, LLC
* @license GPL-2.0+
* @todo Change prefix to theme or plugin prefix
*
*/
function tanin_per_page_query( $query ) {
$is_blog = ( is_home() && is_front_page() ) || ( is_home() && !is_front_page() );
if ( $query->is_main_query() && ! $query->is_feed() && ! is_admin() && ( is_category() || is_tag() || $is_blog ) ) {
$query->set( 'posts_per_page', '2' ); //Change this number to anything you like.
}
/*$taxonomy = is_tax() ? get_queried_object()->taxonomy:"";
$is_taxonomy = in_array( $taxonomy , array( 'product-category' ) );
if ( $query->is_main_query() && ! $query->is_feed() && ! is_admin() && $is_taxonomy ) {
$query->set( 'posts_per_page', '6' ); //Change this number to anything you like.
}
$post_type = $query->get('post_type');
$is_post_type = in_array( $post_type , array( 'product' , 'project' ) );
if ( $query->is_main_query() && ! $query->is_feed() && ! is_admin() && $is_post_type && is_post_type_archive() ) {
$query->set( 'posts_per_page', '6' ); //Change this number to anything you like.
}
$is_post_type = in_array( $post_type , array( 'service' ) );
if ( $query->is_main_query() && ! $query->is_feed() && ! is_admin() && $is_post_type && is_post_type_archive() ) {
$query->set( 'posts_per_page', '80' ); //Change this number to anything you like.
}*/
}
function tanin_one_click_checkout(){
if( !is_admin() && isset( $_REQUEST['tanin_quick_checkout'] ) && $_REQUEST['tanin_quick_checkout'] == 1 && isset( $_REQUEST['add_to_cart'] ) ){
$product_id = (int)$_REQUEST['add_to_cart'];
WC()->cart->empty_cart();
WC()->cart->add_to_cart( $product_id );
$wo_checkout_url = WC()->cart->get_checkout_url();
wp_safe_redirect( $wo_checkout_url );
exit();
}
}
add_action( 'wp_loaded' , 'tanin_one_click_checkout' );
function tanin_add_google_font( $google_fonts ){
$google_fonts["David Libre"] = "David Libre";
return $google_fonts;
}
add_filter( 'sed_google_fonts_filter' , 'tanin_add_google_font' );
function tanin_go_to_services(){
if( is_post_type_archive( 'services-blog' ) && !is_admin() ){
wp_safe_redirect( site_url('/tservices') );
exit;
}
}
add_action( "wp" , "tanin_go_to_services" );
function tanin_check_exist_parent_term( $term , $list ){
if( !$term->parent ){
return false;
}
if( in_array( $term->parent , $list ) ){
return $term->parent;
}
return tanin_check_exist_parent_term( get_term( $term->parent ) , $list );
}
/**
* Site Editor Shop WooCommerce
*/
require dirname(__FILE__) . '/inc/woocommerce.php';
add_filter( 'woocommerce_currencies', 'add_my_currency' );
function add_my_currency( $currencies ) {
$currencies['ABC'] = __( 'Rial', 'woocommerce' );
return $currencies;
}
add_filter('woocommerce_currency_symbol', 'add_my_currency_symbol', 10, 2);
function add_my_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case 'ABC': $currency_symbol = ' Rial'; break;
}
return $currency_symbol;
}