-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
386 lines (289 loc) · 12.5 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
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
<?php
//
// Recommended way to include parent theme styles.
// (Please see http://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme)
//
function iott_enqueue_styles() {
wp_enqueue_style( 'iott-parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'iott-style',
get_stylesheet_directory_uri() . '/style.css',
array('parent-style')
);
//wp_enqueue_style( 'iott-main-style', get_stylesheet_directory_uri() . '/css/style.css' );
wp_enqueue_script( "typed-js" , get_stylesheet_directory_uri() . '/assets/js/typed.js/dist/typed.min.js' , array( 'jquery' ) , "1.0.0" , true );
/**
* Theme Front end main js
*/
wp_enqueue_script( "iott-script" , get_stylesheet_directory_uri() . '/assets/js/script.js' , array( 'jquery', 'carousel' , 'sed-livequery' , 'jquery-ui-accordion' ) , "1.0.0" , true );
wp_enqueue_script('jquery-scrollbar');
wp_enqueue_style('custom-scrollbar');
wp_enqueue_style("carousel");
}
add_action( 'wp_enqueue_scripts', 'iott_enqueue_styles' , 0 );
add_action( 'after_setup_theme', 'sed_iott_theme_setup' );
function sed_iott_theme_setup() {
load_child_theme_textdomain( 'iott', get_stylesheet_directory() . '/languages' );
remove_filter( 'excerpt_more', 'twentyseventeen_excerpt_more' );
}
function iott_excerpt_more( $link ) {
if ( is_admin() ) {
return $link;
}
return ' … ';
}
add_filter( 'excerpt_more', 'iott_excerpt_more' );
/**
* Add Site Editor Modules
*
* @param $modules
* @return mixed
*/
function sed_iott_add_modules( $modules ){
global $sed_pb_modules;
$module_name = "themes/sed-iott/site-editor/modules/iott-header/iott-header.php";
$modules[$module_name] = $sed_pb_modules->get_module_data(get_stylesheet_directory() . '/site-editor/modules/iott-header/iott-header.php', true, true);
$module_name = "themes/sed-iott/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/sed-iott/site-editor/modules/iott-events/iott-events.php";
$modules[$module_name] = $sed_pb_modules->get_module_data(get_stylesheet_directory() . '/site-editor/modules/iott-events/iott-events.php', true, true);
*/
return $modules;
}
add_filter("sed_modules" , "sed_iott_add_modules" );
function sed_iott_breadcrumbs() {
$delimiter = '<span class="delimiter">/</span>';
$name = get_bloginfo('site_url'); //text for the 'Home' link
$currentBefore = '<span class="current">';
$currentAfter = '</span>';
if (!is_home() && !is_front_page() || is_paged()) {
echo '<div class="armanam_breadcrumbs">';
global $post;
$home = get_bloginfo('url');
echo '<a href="' . $home . '">' . $name . '</a> ' . $delimiter . ' ';
if (is_category()) {
global $wp_query;
$cat_obj = $wp_query->get_queried_object();
$thisCat = $cat_obj->term_id;
$thisCat = get_category($thisCat);
$parentCat = get_category($thisCat->parent);
if ($thisCat->parent != 0)
echo (get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
echo $currentBefore . '';
single_cat_title();
echo '' . $currentAfter;
} //is_category()
elseif (is_day()) {
echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
echo '<a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
echo $currentBefore . get_the_time('d') . $currentAfter;
} //is_day()
elseif (is_month()) {
echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
echo $currentBefore . get_the_time('F') . $currentAfter;
} //is_month()
elseif (is_year()) {
echo $currentBefore . get_the_time('Y') . $currentAfter;
} //is_year()
elseif (is_single() && !is_attachment() && is_singular('post')) {
$cat = get_the_category();
$cat = $cat[0];
echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
// echo get_post_type($post->ID);
echo $currentBefore;
the_title();
echo $currentAfter;
} //is_single() && !is_attachment()
elseif (is_attachment()) {
$parent = get_post($post->post_parent);
$cat = get_the_category($parent->ID);
$cat = $cat[0];
echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . ' ';
echo $currentBefore;
the_title();
echo $currentAfter;
} //is_attachment()
elseif (is_page() && !$post->post_parent) {
echo $currentBefore;
the_title();
echo $currentAfter;
} //is_page() && !$post->post_parent
elseif (is_page() && $post->post_parent) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
$parent_id = $page->post_parent;
} //$parent_id
$breadcrumbs = array_reverse($breadcrumbs);
foreach ($breadcrumbs as $crumb)
echo $crumb . ' ' . $delimiter . ' ';
echo $currentBefore;
the_title();
echo $currentAfter;
} //is_page() && $post->post_parent
elseif (is_search()) {
echo $currentBefore . 'نتایج جستوجو: ' . get_search_query() . '' . $currentAfter;
} //is_search()
elseif (is_tag()) {
echo $currentBefore . 'برچسب: ';
single_tag_title();
echo '' . $currentAfter;
} //is_tag()
elseif (is_author()) {
global $author;
$userdata = get_userdata($author);
echo $currentBefore . 'نویسنده: ' . $userdata->display_name . $currentAfter;
} //is_author()
elseif (is_404()) {
echo $currentBefore . 'خطای ۴۰۴!' . $currentAfter;
} //is_404()
if (get_query_var('paged')) {
if (is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author())
echo ' (';
echo "صفحه" . ' ' . get_query_var('paged');
if (is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author())
echo ')';
} //get_query_var('paged')
echo '</div>';
} //!is_home() && !is_front_page() || is_paged()
}
/*
* Get post-type categories
*
* $id int require
* $tax string require eg.: 'product_category'
* $before string optional
* $after string optional
*
* return str
*/
function get_terms_string($id, $tax, $before = null, $after = null) {
$arr = get_the_terms($id, $tax);
$str = '';
$str .= $before;
if( is_array( $arr ) ) {
foreach ($arr as $key => $value) {
$str .= "<a href='" . get_term_link($value->term_id) . "'>" . $value->name . "</a>";
if (count($arr) != $key + 1) {
$str .= "، ";
}
}
}
$str .= $after;
return $str;
}
function iott_get_field( $key , $post_id = 0 ){
global $post;
$post_id = (int)$post_id;
if( $post_id == 0 && $post ){
$post_id = get_the_ID();
}
return get_post_meta( $post_id , $key , true );
}
function iott_the_field( $key , $post_id = 0 ){
echo iott_get_field( $key , $post_id );
}
add_action( 'pre_get_posts', 'iott_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 iott_per_page_query( $query ) {
$taxonomy = is_tax() ? get_queried_object()->taxonomy:"";
$is_taxonomy = in_array( $taxonomy , array( 'product_category' , 'event_cat' , 'chart_cat' , 'video_cat' , 'infographic_cat' ) );
if ( $query->is_main_query() && ! $query->is_feed() && ! is_admin() && $is_taxonomy ) {
$query->set( 'posts_per_page', '12' ); //Change this number to anything you like.
}
$post_type = $query->get('post_type');
$is_post_type = in_array( $post_type , array( 'product' , 'sed_events' , 'chart' , 'iott_video' , 'sed_infographic' ) );
if ( $query->is_main_query() && ! $query->is_feed() && ! is_admin() && $is_post_type && is_post_type_archive() ) {
$query->set( 'posts_per_page', '12' ); //Change this number to anything you like.
}
}
/*
* Sort posts in a custom post-type
*/
function iott_custom_posttype_sort($query) {
$post_type = $query->get('post_type'); //var_dump( $query );
$taxonomy = is_tax() ? get_queried_object()->taxonomy:"";
$is_post_type = in_array( $post_type , array( 'product' , 'sed_events' , 'chart' , 'iott_video' , 'sed_infographic' ) );
$is_taxonomy = in_array( $taxonomy , array( 'product_category' , 'event_cat' , 'chart_cat' , 'video_cat' , 'infographic_cat' ) );
if ( ( $is_post_type || $is_taxonomy ) && $query->is_main_query() && !is_admin() ) {
if( isset( $_GET['orderby'] ) && !empty( $_GET['orderby'] ) ) {
$order_by = $_GET['orderby'];
switch ( $order_by ) {
case 'date_asc':
$query->set('orderby', 'date');
$query->set('order', 'ASC');
break;
case 'data_desc':
$query->set('orderby', 'date');
$query->set('order', 'DESC');
break;
case 'title_asc':
$query->set('orderby', 'title');
$query->set('order', 'ASC');
break;
case 'title_desc':
$query->set('orderby', 'title');
$query->set('order', 'DESC');
break;
default:
break;
}
}
if( isset( $_GET['postperpage'] ) && !empty( $_GET['postperpage'] ) ) {
$per_page = (int)$_GET['postperpage'];
$query->set('posts_per_page', $per_page);
}
}
}
add_action('pre_get_posts', 'iott_custom_posttype_sort');
function iott_register_widgets() {
if( class_exists('NS_Featured_Posts') ){
unregister_widget( 'NSFP_Featured_Post_Widget' );
require_once( get_stylesheet_directory(). '/widgets/featured-post.php' );
register_widget( 'Sed_Featured_Post_Widget' );
}
}
add_action( 'widgets_init', 'iott_register_widgets' );
function the_sponsored_image( $attachment_id ){
$img = get_sed_attachment_image_html( $attachment_id , "full");
if ( ! $img ) {
$img = array();
$img['thumbnail'] = '<img class="sed-image-placeholder sed-image" src="' . sed_placeholder_img_src() . '" />';
}
echo $img['thumbnail'];
}
function iott_register_theme_fields( $fields ){
$fields['video_field_attr'] = array(
'type' => 'video',
'label' => __('Featured Video Field (MP4)', 'site-editor'),
'description' => __('the Video OGV Upload option allows you to upload a .OGV format of your video file. .OGV files are optional. You can choose a video with this format from the library by clicking on the button in this section.','site-editor'),
"js_params" => array(
"subtypes" => array( "mp4" )
),
'transport' => 'postMessage' ,
'setting_id' => 'iott_featured_video_src',
'default' => '',
"panel" => "general_settings" ,
);
return $fields;
}
add_filter( "sed_theme_options_fields_filter" , 'iott_register_theme_fields' , 10000 );
function iott_admin_enqueue_style_fix( $hook ) {
if ( !is_site_editor() ) {
return;
}
wp_dequeue_style('wp-jquery-ui-dialog');
}
add_action( 'admin_enqueue_scripts', 'iott_admin_enqueue_style_fix' , 10000000 );
add_action( 'in_admin_header', 'iott_admin_enqueue_style_fix' , 10000000 );
add_action( 'media_buttons', 'iott_admin_enqueue_style_fix' , 10000000 );