-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
391 lines (284 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
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
<?php
//
// Recommended way to include parent theme styles.
// (Please see http://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme)
//
function negar_enqueue_styles() {
wp_enqueue_style( 'negar-parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'negar-style',
get_stylesheet_directory_uri() . '/style.css',
array('parent-style')
);
/**
* Theme Front end main js
*/
wp_enqueue_script( "negar-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', 'negar_enqueue_styles' , 0 );
add_action( 'after_setup_theme', 'sed_negar_theme_setup' );
function sed_negar_theme_setup() {
load_child_theme_textdomain( 'negar', get_stylesheet_directory() . '/languages' );
remove_filter( 'excerpt_more', 'twentyseventeen_excerpt_more' );
/**
* Short Description (excerpt).
*/
add_filter( 'negar_short_description', 'wptexturize' );
add_filter( 'negar_short_description', 'convert_smilies' );
add_filter( 'negar_short_description', 'convert_chars' );
add_filter( 'negar_short_description', 'wpautop' );
add_filter( 'negar_short_description', 'shortcode_unautop' );
add_filter( 'negar_short_description', 'prepend_attachment' );
add_filter( 'negar_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 negar_excerpt_more( $link ) {
if ( is_admin() ) {
return $link;
}
return ' … ';
}
add_filter( 'excerpt_more', 'negar_excerpt_more' );
function negar_excerpt_length( $length ) {
return 650;
}
add_filter( 'excerpt_length', 'negar_excerpt_length', 999 );
/**
* Add Site Editor Modules
*
* @param $modules
* @return mixed
*/
function sed_negar_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/negar-products/negar-products.php";
$modules[$module_name] = $sed_pb_modules->get_module_data(get_stylesheet_directory() . '/site-editor/modules/negar-products/negar-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_negar_add_modules" );
function negar_register_theme_fields( $fields ){
/*$fields['products_archive_description'] = array(
'type' => 'textarea',
'label' => __('Product Archive Description', 'site-editor'),
//'description' => '',
'transport' => 'postMessage' ,
'setting_id' => 'negar_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' => 'negar_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' => 'negar_english_site_url',
'default' => 'http://eng.tanin.com',
"panel" => "general_settings",
);
}
$fields[ 'intro_logo' ] = array(
'setting_id' => 'negar_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" , 'negar_register_theme_fields' , 10000 );
add_action( 'pre_get_posts', 'negar_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 negar_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( 'press_media' ) );
if ( $query->is_main_query() && ! $query->is_feed() && ! is_admin() && $is_post_type && is_post_type_archive() ) {
$query->set( 'posts_per_page', '2' ); //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 negar_add_google_font( $google_fonts ){
$google_fonts["David Libre"] = "David Libre";
return $google_fonts;
}
//add_filter( 'sed_google_fonts_filter' , 'negar_add_google_font' );
function negar_check_exist_parent_term( $term , $list ){
if( !$term->parent ){
return false;
}
if( in_array( $term->parent , $list ) ){
return $term->parent;
}
return negar_check_exist_parent_term( get_term( $term->parent ) , $list );
}
add_shortcode( 'negar_header_group_icon', 'negar_add_header_group_icon' );
function negar_add_header_group_icon( $atts = null ){
ob_start();
?>
<div class="row negar-header-group-icons">
<div class="col-xs-4">
<div class="negar-header-icon user">
<a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>"><?php echo __("My Account" , "negar");?></a>
</div>
</div>
<div class="col-xs-4">
<div class="negar-header-icon ncart">
<?php echo do_shortcode( '[sed_woo_cart_icon]' );?>
</div>
<div class="negar-header-icon ncart responsive-cart">
<?php
global $woocommerce;
$cart_url = $woocommerce->cart->get_cart_url();
?>
<a class="cart-contents" href="<?php echo esc_attr( esc_url( $cart_url ) );?>" title="View your shopping cart">
</a>
</div>
</div>
<div class="col-xs-4">
<div class="negar-header-icon wishlist">
<a href="<?php echo esc_url( YITH_WCWL()->get_wishlist_url() ); ?>"><?php echo __("Wishlist" , "negar");?></a>
</div>
</div>
</div>
<?php
return ob_get_clean();
}
function negar_comment($comment, $args, $depth) {
$tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
?>
<<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $args['has_children'] ? 'parent' : '', $comment ); ?>>
<article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
<footer class="comment-meta">
<div class="comment-author vcard">
<?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
<?php
/* translators: %s: comment author link */
printf( __( '%s <span class="says">says:</span>' ),
sprintf( '<b class="fn">%s</b>', get_comment_author_link( $comment ) )
);
?>
</div><!-- .comment-author -->
<div class="comment-metadata">
<a class="comment-time" href="<?php echo esc_url( get_comment_link( $comment, $args ) ); ?>">
<time datetime="<?php comment_time( 'c' ); ?>">
<?php
/* translators: 1: comment date, 2: comment time */
printf( __( '%1$s at %2$s' ), get_comment_date( '', $comment ), get_comment_time() );
?>
</time>
</a>
<?php
comment_reply_link( array_merge( $args, array(
'add_below' => 'div-comment',
'depth' => $depth,
'max_depth' => $args['max_depth'],
'before' => '<div class="reply">',
'after' => '</div>'
) ) );
?>
<?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
</div><!-- .comment-metadata -->
<?php if ( '0' == $comment->comment_approved ) : ?>
<p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></p>
<?php endif; ?>
</footer><!-- .comment-meta -->
<div class="comment-content">
<?php comment_text(); ?>
</div><!-- .comment-content -->
</article><!-- .comment-body -->
<?php
}
/**
* Get an attachment ID given a URL.
*
* @param string $url
*
* @return int Attachment ID on success, 0 on failure
*/
function negar_get_attachment_id_by_url( $url ) {
$attachment_id = 0;
$dir = wp_upload_dir();
if ( false !== strpos( $url, $dir['baseurl'] . '/' ) ) { // Is URL in uploads directory?
$file = basename( $url );
$query_args = array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'fields' => 'ids',
'meta_query' => array(
array(
'value' => $file,
'compare' => 'LIKE',
'key' => '_wp_attachment_metadata',
),
)
);
$query = new WP_Query( $query_args );
if ( $query->have_posts() ) {
foreach ( $query->posts as $post_id ) {
$meta = wp_get_attachment_metadata( $post_id );
$original_file = basename( $meta['file'] );
$cropped_image_files = wp_list_pluck( $meta['sizes'], 'file' );
if ( $original_file === $file || in_array( $file, $cropped_image_files ) ) {
$attachment_id = $post_id;
break;
}
}
}
}
return $attachment_id;
}
/**
* Site Editor Shop WooCommerce
*/
require dirname(__FILE__) . '/inc/woocommerce.php';