Project

General

Profile

Support #9175 » functions.php

Diane Krauthamer, 2018-02-08 10:21 PM

 
1
<?php
2
/**
3
 * ColorMag functions and definitions
4
 *
5
 * This file contains all the functions and it's defination that particularly can't be
6
 * in other files.
7
 *
8
 * @package    ThemeGrill
9
 * @subpackage ColorMag
10
 * @since      ColorMag 1.0
11
 */
12

    
13
/****************************************************************************************/
14

    
15
add_action( 'wp_enqueue_scripts', 'colormag_scripts_styles_method' );
16
/**
17
 * Register jquery scripts
18
 */
19
function colormag_scripts_styles_method() {
20
	/**
21
	 * Using google font
22
	 */
23
	wp_enqueue_style( 'colormag_google_fonts', '//fonts.googleapis.com/css?family=Open+Sans:400,600' );
24

    
25
	/**
26
	 * Loads our main stylesheet.
27
	 */
28
	wp_enqueue_style( 'colormag_style', get_stylesheet_uri() );
29

    
30
	/**
31
	 * Adds JavaScript to pages with the comment form to support
32
	 * sites with threaded comments (when in use).
33
	 */
34
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
35
		wp_enqueue_script( 'comment-reply' );
36
	}
37

    
38
	/**
39
	 * Register bxSlider js file for slider.
40
	 */
41
	wp_register_script( 'colormag-bxslider', COLORMAG_JS_URL . '/jquery.bxslider.min.js', array( 'jquery' ), '4.2.10', true );
42

    
43
	/**
44
	 * Enqueue Slider setup js file.
45
	 */
46
	wp_enqueue_script( 'colormag_slider', COLORMAG_JS_URL . '/colormag-slider-setting.js', array( 'colormag-bxslider' ), false, true );
47

    
48
	wp_enqueue_script( 'colormag-navigation', COLORMAG_JS_URL . '/navigation.js', array( 'jquery' ), false, true );
49
	wp_enqueue_script( 'colormag-custom', COLORMAG_JS_URL . '/colormag-custom.js', array( 'jquery' ) );
50

    
51
	wp_enqueue_style( 'colormag-fontawesome', get_template_directory_uri() . '/fontawesome/css/font-awesome.css', array(), '4.2.1' );
52

    
53
	if ( get_theme_mod( 'colormag_breaking_news', 0 ) == 1 ) {
54
		wp_enqueue_script( 'colormag-news-ticker', COLORMAG_JS_URL . '/news-ticker/jquery.newsTicker.min.js', array( 'jquery' ), '1.0.0', true );
55

    
56
		wp_enqueue_script( 'colormag-news-ticker-setting', COLORMAG_JS_URL . '/news-ticker/ticker-setting.js', array( 'colormag-news-ticker' ), '20150304', true );
57
	}
58

    
59
	if ( get_theme_mod( 'colormag_primary_sticky_menu', 0 ) == 1 ) {
60
		wp_enqueue_script( 'colormag-sticky-menu', COLORMAG_JS_URL . '/sticky/jquery.sticky.js', array( 'jquery' ), '20150309', true );
61

    
62
		wp_enqueue_script( 'colormag-sticky-menu-setting', COLORMAG_JS_URL . '/sticky/sticky-setting.js', array( 'colormag-sticky-menu' ), '20150309', true );
63
	}
64

    
65
	if ( get_theme_mod( 'colormag_featured_image_popup', 0 ) == 1 ) {
66
		wp_enqueue_script( 'colormag-featured-image-popup', COLORMAG_JS_URL . '/magnific-popup/jquery.magnific-popup.min.js', array( 'jquery' ), '20150310', true );
67
		wp_enqueue_style( 'colormag-featured-image-popup-css', COLORMAG_JS_URL . '/magnific-popup/magnific-popup.css', array(), '20150310' );
68
		wp_enqueue_script( 'colormag-featured-image-popup-setting', COLORMAG_JS_URL . '/magnific-popup/image-popup-setting.js', array( 'jquery' ), '20150310', true );
69
	}
70

    
71
	wp_enqueue_script( 'colormag-fitvids', COLORMAG_JS_URL . '/fitvids/jquery.fitvids.js', array( 'jquery' ), '20150311', true );
72

    
73
	wp_enqueue_script( 'colormag-fitvids-setting', COLORMAG_JS_URL . '/fitvids/fitvids-setting.js', array( 'colormag-fitvids' ), '20150311', true );
74

    
75
	if ( get_post_format() || is_archive() || is_search() ) {
76
		wp_enqueue_script( 'colormag-postformat-setting', COLORMAG_JS_URL . '/post-format.js', array( 'jquery' ), '20150422', true );
77
	}
78

    
79
	wp_enqueue_script( 'html5', COLORMAG_JS_URL . '/html5shiv.min.js', true );
80
	wp_script_add_data( 'html5', 'conditional', 'lte IE 8' );
81

    
82
}
83

    
84
add_action( 'admin_enqueue_scripts', 'colormag_image_uploader' );
85
function colormag_image_uploader() {
86
	wp_enqueue_media();
87
	wp_enqueue_script( 'colormag-widget-image-upload', COLORMAG_JS_URL . '/image-uploader.js', false, '20150309', true );
88
}
89

    
90
/****************************************************************************************/
91

    
92
add_filter( 'excerpt_length', 'colormag_excerpt_length' );
93
/**
94
 * Sets the post excerpt length to 40 words.
95
 *
96
 * function tied to the excerpt_length filter hook.
97
 *
98
 * @uses filter excerpt_length
99
 */
100
function colormag_excerpt_length( $length ) {
101
	return 20;
102
}
103

    
104
add_filter( 'excerpt_more', 'colormag_continue_reading' );
105
/**
106
 * Returns a "Continue Reading" link for excerpts
107
 */
108
function colormag_continue_reading() {
109
	return '';
110
}
111

    
112
/****************************************************************************************/
113

    
114
/**
115
 * Removing the default style of wordpress gallery
116
 */
117
add_filter( 'use_default_gallery_style', '__return_false' );
118

    
119
/**
120
 * Filtering the size to be full from thumbnail to be used in WordPress gallery as a default size
121
 */
122
function colormag_gallery_atts( $out, $pairs, $atts ) {
123
	$atts = shortcode_atts( array(
124
		'size' => 'colormag-featured-image',
125
	), $atts );
126

    
127
	$out[ 'size' ] = $atts[ 'size' ];
128

    
129
	return $out;
130

    
131
}
132

    
133
add_filter( 'shortcode_atts_gallery', 'colormag_gallery_atts', 10, 3 );
134

    
135
/****************************************************************************************/
136

    
137
add_filter( 'body_class', 'colormag_body_class' );
138
/**
139
 * Filter the body_class
140
 *
141
 * Throwing different body class for the different layouts in the body tag
142
 */
143
function colormag_body_class( $classes ) {
144
	global $post;
145

    
146
	if ( $post ) {
147
		$layout_meta = get_post_meta( $post->ID, 'colormag_page_layout', true );
148
	}
149

    
150
	if ( is_home() ) {
151
		$queried_id  = get_option( 'page_for_posts' );
152
		$layout_meta = get_post_meta( $queried_id, 'colormag_page_layout', true );
153
	}
154
	if ( empty( $layout_meta ) || is_archive() || is_search() ) {
155
		$layout_meta = 'default_layout';
156
	}
157
	$colormag_default_layout = get_theme_mod( 'colormag_default_layout', 'right_sidebar' );
158

    
159
	$colormag_default_page_layout = get_theme_mod( 'colormag_default_page_layout', 'right_sidebar' );
160
	$colormag_default_post_layout = get_theme_mod( 'colormag_default_single_posts_layout', 'right_sidebar' );
161

    
162
	if ( $layout_meta == 'default_layout' ) {
163
		if ( is_page() ) {
164
			if ( $colormag_default_page_layout == 'right_sidebar' ) {
165
				$classes[] = '';
166
			} else if ( $colormag_default_page_layout == 'left_sidebar' ) {
167
				$classes[] = 'left-sidebar';
168
			} else if ( $colormag_default_page_layout == 'no_sidebar_full_width' ) {
169
				$classes[] = 'no-sidebar-full-width';
170
			} else if ( $colormag_default_page_layout == 'no_sidebar_content_centered' ) {
171
				$classes[] = 'no-sidebar';
172
			}
173
		} else if ( is_single() ) {
174
			if ( $colormag_default_post_layout == 'right_sidebar' ) {
175
				$classes[] = '';
176
			} else if ( $colormag_default_post_layout == 'left_sidebar' ) {
177
				$classes[] = 'left-sidebar';
178
			} else if ( $colormag_default_post_layout == 'no_sidebar_full_width' ) {
179
				$classes[] = 'no-sidebar-full-width';
180
			} else if ( $colormag_default_post_layout == 'no_sidebar_content_centered' ) {
181
				$classes[] = 'no-sidebar';
182
			}
183
		} else if ( $colormag_default_layout == 'right_sidebar' ) {
184
			$classes[] = '';
185
		} else if ( $colormag_default_layout == 'left_sidebar' ) {
186
			$classes[] = 'left-sidebar';
187
		} else if ( $colormag_default_layout == 'no_sidebar_full_width' ) {
188
			$classes[] = 'no-sidebar-full-width';
189
		} else if ( $colormag_default_layout == 'no_sidebar_content_centered' ) {
190
			$classes[] = 'no-sidebar';
191
		}
192
	} else if ( $layout_meta == 'right_sidebar' ) {
193
		$classes[] = '';
194
	} else if ( $layout_meta == 'left_sidebar' ) {
195
		$classes[] = 'left-sidebar';
196
	} else if ( $layout_meta == 'no_sidebar_full_width' ) {
197
		$classes[] = 'no-sidebar-full-width';
198
	} else if ( $layout_meta == 'no_sidebar_content_centered' ) {
199
		$classes[] = 'no-sidebar';
200
	}
201

    
202
	if ( get_theme_mod( 'colormag_site_layout', 'wide_layout' ) == 'wide_layout' ) {
203
		$classes[] = 'wide';
204
	} else if ( get_theme_mod( 'colormag_site_layout', 'wide_layout' ) == 'boxed_layout' ) {
205
		$classes[] = '';
206
	}
207

    
208
	if ( get_theme_mod( 'colormag_responsive_menu', 0 ) == 1 ) {
209
		$classes[] = 'better-responsive-menu';
210
	}
211

    
212
	return $classes;
213
}
214

    
215
/****************************************************************************************/
216

    
217
if ( ! function_exists( 'colormag_sidebar_select' ) ) :
218
	/**
219
	 * Function to select the sidebar
220
	 */
221
	function colormag_sidebar_select() {
222
		global $post;
223

    
224
		if ( $post ) {
225
			$layout_meta = get_post_meta( $post->ID, 'colormag_page_layout', true );
226
		}
227

    
228
		if ( is_home() ) {
229
			$queried_id  = get_option( 'page_for_posts' );
230
			$layout_meta = get_post_meta( $queried_id, 'colormag_page_layout', true );
231
		}
232

    
233
		if ( empty( $layout_meta ) || is_archive() || is_search() ) {
234
			$layout_meta = 'default_layout';
235
		}
236
		$colormag_default_layout = get_theme_mod( 'colormag_default_layout', 'right_sidebar' );
237

    
238
		$colormag_default_page_layout = get_theme_mod( 'colormag_default_page_layout', 'right_sidebar' );
239
		$colormag_default_post_layout = get_theme_mod( 'colormag_default_single_posts_layout', 'right_sidebar' );
240

    
241
		if ( $layout_meta == 'default_layout' ) {
242
			if ( is_page() ) {
243
				if ( $colormag_default_page_layout == 'right_sidebar' ) {
244
					get_sidebar();
245
				} else if ( $colormag_default_page_layout == 'left_sidebar' ) {
246
					get_sidebar( 'left' );
247
				}
248
			}
249
			if ( is_single() ) {
250
				if ( $colormag_default_post_layout == 'right_sidebar' ) {
251
					get_sidebar();
252
				} else if ( $colormag_default_post_layout == 'left_sidebar' ) {
253
					get_sidebar( 'left' );
254
				}
255
			} else if ( $colormag_default_layout == 'right_sidebar' ) {
256
				get_sidebar();
257
			} else if ( $colormag_default_layout == 'left_sidebar' ) {
258
				get_sidebar( 'left' );
259
			}
260
		} else if ( $layout_meta == 'right_sidebar' ) {
261
			get_sidebar();
262
		} else if ( $layout_meta == 'left_sidebar' ) {
263
			get_sidebar( 'left' );
264
		}
265
	}
266
endif;
267

    
268
/****************************************************************************************/
269

    
270
if ( ! function_exists( 'colormag_entry_meta' ) ) :
271
	/**
272
	 * Shows meta information of post.
273
	 */
274
	function colormag_entry_meta() {
275
		if ( 'post' == get_post_type() ) :
276
			echo '<div class="below-entry-meta">';
277
			?>
278

    
279
			<?php
280
			$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
281
			if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
282
				$time_string .= '<time class="updated" datetime="%3$s">%4$s</time>';
283
			}
284
			$time_string = sprintf( $time_string,
285
				esc_attr( get_the_date( 'c' ) ),
286
				esc_html( get_the_date() ),
287
				esc_attr( get_the_modified_date( 'c' ) ),
288
				esc_html( get_the_modified_date() )
289
			);
290
			printf( __( '<span class="posted-on"><a href="%1$s" title="%2$s" rel="bookmark"><i class="fa fa-calendar-o"></i> %3$s</a></span>', 'colormag' ),
291
				esc_url( get_permalink() ),
292
				esc_attr( get_the_time() ),
293
				$time_string
294
			); ?>
295

    
296
			<span class="byline"><span class="author vcard"><i class="fa fa-user"></i><a class="url fn n" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" title="<?php echo get_the_author(); ?>"><?php echo coauthors_posts_links(null, null, null, null, false ); ?></a></span></span>
297

    
298
			<?php
299
			if ( ! post_password_required() && comments_open() ) { ?>
300
				<span class="comments"><?php comments_popup_link( __( '<i class="fa fa-comment"></i> 0 Comments', 'colormag' ), __( '<i class="fa fa-comment"></i> 1 Comment', 'colormag' ), __( '<i class="fa fa-comments"></i> % Comments', 'colormag' ) ); ?></span>
301
			<?php }
302
			$tags_list = get_the_tag_list( '<span class="tag-links"><i class="fa fa-tags"></i>', __( ', ', 'colormag' ), '</span>' );
303
			if ( $tags_list ) {
304
				echo $tags_list;
305
			}
306

    
307
			edit_post_link( __( 'Edit', 'colormag' ), '<span class="edit-link"><i class="fa fa-edit"></i>', '</span>' );
308

    
309
			echo '</div>';
310
		endif;
311
	}
312
endif;
313

    
314
/****************************************************************************************/
315

    
316
add_action( 'admin_head', 'colormag_favicon' );
317
add_action( 'wp_head', 'colormag_favicon' );
318
/**
319
 * Favicon for the site
320
 */
321
function colormag_favicon() {
322
	if ( get_theme_mod( 'colormag_favicon_show', '0' ) == '1' ) {
323
		$colormag_favicon        = get_theme_mod( 'colormag_favicon_upload', '' );
324
		$colormag_favicon_output = '';
325
		if ( ! function_exists( 'has_site_icon' ) || ( ! empty( $colormag_favicon ) && ! has_site_icon() ) ) {
326
			$colormag_favicon_output .= '<link rel="shortcut icon" href="' . esc_url( $colormag_favicon ) . '" type="image/x-icon" />';
327
		}
328
		echo $colormag_favicon_output;
329
	}
330
}
331

    
332
/****************************************************************************************/
333

    
334
/**
335
 * Generate darker color
336
 * Source: http://stackoverflow.com/questions/3512311/how-to-generate-lighter-darker-color-with-php
337
 */
338
function colormag_darkcolor( $hex, $steps ) {
339
	// Steps should be between -255 and 255. Negative = darker, positive = lighter
340
	$steps = max( - 255, min( 255, $steps ) );
341

    
342
	// Normalize into a six character long hex string
343
	$hex = str_replace( '#', '', $hex );
344
	if ( strlen( $hex ) == 3 ) {
345
		$hex = str_repeat( substr( $hex, 0, 1 ), 2 ) . str_repeat( substr( $hex, 1, 1 ), 2 ) . str_repeat( substr( $hex, 2, 1 ), 2 );
346
	}
347

    
348
	// Split into three parts: R, G and B
349
	$color_parts = str_split( $hex, 2 );
350
	$return      = '#';
351

    
352
	foreach ( $color_parts as $color ) {
353
		$color  = hexdec( $color ); // Convert to decimal
354
		$color  = max( 0, min( 255, $color + $steps ) ); // Adjust color
355
		$return .= str_pad( dechex( $color ), 2, '0', STR_PAD_LEFT ); // Make two char hex code
356
	}
357

    
358
	return $return;
359
}
360

    
361
/****************************************************************************************/
362

    
363
add_action( 'wp_head', 'colormag_custom_css', 100 );
364
/**
365
 * Hooks the Custom Internal CSS to head section
366
 */
367
function colormag_custom_css() {
368
	$colormag_internal_css = '';
369
	$primary_color         = get_theme_mod( 'colormag_primary_color', '#289dcc' );
370
	$primary_dark          = colormag_darkcolor( $primary_color, - 30 );
371
	if ( $primary_color != '#289dcc' ) {
372
		$colormag_internal_css .= ' .colormag-button,blockquote,button,input[type=reset],input[type=button],input[type=submit],#masthead.colormag-header-clean #site-navigation.main-small-navigation .menu-toggle{background-color:' . $primary_color . '}#site-title a,.next a:hover,.previous a:hover,.social-links i.fa:hover,a,#masthead.colormag-header-clean .social-links li:hover i.fa,#masthead.colormag-header-classic .social-links li:hover i.fa,#masthead.colormag-header-clean .breaking-news .newsticker a:hover,#masthead.colormag-header-classic .breaking-news .newsticker a:hover,#masthead.colormag-header-classic #site-navigation .fa.search-top:hover,#masthead.colormag-header-classic #site-navigation.main-navigation .random-post a:hover .fa-random{color:' . $primary_color . '}.fa.search-top:hover,#masthead.colormag-header-classic #site-navigation.main-small-navigation .menu-toggle{background-color:' . $primary_color . '}#site-navigation{border-top:4px solid ' . $primary_color . '}.home-icon.front_page_on,.main-navigation a:hover,.main-navigation ul li ul li a:hover,.main-navigation ul li ul li:hover>a,.main-navigation ul li.current-menu-ancestor>a,.main-navigation ul li.current-menu-item ul li a:hover,.main-navigation ul li.current-menu-item>a,.main-navigation ul li.current_page_ancestor>a,.main-navigation ul li.current_page_item>a,.main-navigation ul li:hover>a,.main-small-navigation li a:hover,.site-header .menu-toggle:hover,#masthead.colormag-header-classic #site-navigation.main-navigation ul#menu-primary ul.sub-menu li:hover > a, #masthead.colormag-header-classic #site-navigation.main-navigation ul#menu-primary ul.sub-menu li.current-menu-ancestor > a, #masthead.colormag-header-classic #site-navigation.main-navigation ul#menu-primary ul.sub-menu li.current-menu-item > a,#masthead .main-small-navigation li:hover > a, #masthead .main-small-navigation li.current-page-ancestor > a, #masthead .main-small-navigation li.current-menu-ancestor > a, #masthead .main-small-navigation li.current-page-item > a, #masthead .main-small-navigation li.current-menu-item > a{background-color:' . $primary_color . '}.main-small-navigation .current-menu-item>a,.main-small-navigation .current_page_item>a{background:' . $primary_color . '}#masthead.colormag-header-classic #site-navigation.main-navigation ul#menu-primary > li:hover > a, #masthead.colormag-header-classic #site-navigation.main-navigation ul#menu-primary > li.current-menu-item > a, #masthead.colormag-header-classic #site-navigation.main-navigation ul#menu-primary > li.current-menu-ancestor > a,#masthead.colormag-header-classic #site-navigation.main-navigation ul#menu-primary ul.sub-menu li:hover, #masthead.colormag-header-classic #site-navigation.main-navigation ul#menu-primary ul.sub-menu li.current-menu-ancestor, #masthead.colormag-header-classic #site-navigation.main-navigation ul#menu-primary ul.sub-menu li.current-menu-item,#masthead.colormag-header-classic #site-navigation.main-small-navigation .menu-toggle,#masthead.colormag-header-classic #site-navigation .menu-toggle:hover{border-color:' . $primary_color . '}.promo-button-area a:hover{border:2px solid ' . $primary_color . ';background-color:' . $primary_color . '}#content .wp-pagenavi .current,#content .wp-pagenavi a:hover,.format-link .entry-content a,.pagination span{background-color:' . $primary_color . '}.pagination a span:hover{color:' . $primary_color . ';border-color:' . $primary_color . '}#content .comments-area a.comment-edit-link:hover,#content .comments-area a.comment-permalink:hover,#content .comments-area article header cite a:hover,.comments-area .comment-author-link a:hover{color:' . $primary_color . '}.comments-area .comment-author-link span{background-color:' . $primary_color . '}.comment .comment-reply-link:hover,.nav-next a,.nav-previous a{color:' . $primary_color . '}#secondary .widget-title{border-bottom:2px solid ' . $primary_color . '}#secondary .widget-title span{background-color:' . $primary_color . '}.footer-widgets-area .widget-title{border-bottom:2px solid ' . $primary_color . '}.footer-widgets-area .widget-title span,.colormag-footer--classic .footer-widgets-area .widget-title span::before{background-color:' . $primary_color . '}.footer-widgets-area a:hover{color:' . $primary_color . '}.advertisement_above_footer .widget-title{border-bottom:2px solid ' . $primary_color . '}.advertisement_above_footer .widget-title span{background-color:' . $primary_color . '}a#scroll-up i{color:' . $primary_color . '}.page-header .page-title{border-bottom:2px solid ' . $primary_color . '}#content .post .article-content .above-entry-meta .cat-links a,.page-header .page-title span{background-color:' . $primary_color . '}#content .post .article-content .entry-title a:hover,.entry-meta .byline i,.entry-meta .cat-links i,.entry-meta a,.post .entry-title a:hover,.search .entry-title a:hover{color:' . $primary_color . '}.entry-meta .post-format i{background-color:' . $primary_color . '}.entry-meta .comments-link a:hover,.entry-meta .edit-link a:hover,.entry-meta .posted-on a:hover,.entry-meta .tag-links a:hover,.single #content .tags a:hover{color:' . $primary_color . '}.more-link,.no-post-thumbnail{background-color:' . $primary_color . '}.post-box .entry-meta .cat-links a:hover,.post-box .entry-meta .posted-on a:hover,.post.post-box .entry-title a:hover{color:' . $primary_color . '}.widget_featured_slider .slide-content .above-entry-meta .cat-links a{background-color:' . $primary_color . '}.widget_featured_slider .slide-content .below-entry-meta .byline a:hover,.widget_featured_slider .slide-content .below-entry-meta .comments a:hover,.widget_featured_slider .slide-content .below-entry-meta .posted-on a:hover,.widget_featured_slider .slide-content .entry-title a:hover{color:' . $primary_color . '}.widget_highlighted_posts .article-content .above-entry-meta .cat-links a{background-color:' . $primary_color . '}.byline a:hover,.comments a:hover,.edit-link a:hover,.posted-on a:hover,.tag-links a:hover,.widget_highlighted_posts .article-content .below-entry-meta .byline a:hover,.widget_highlighted_posts .article-content .below-entry-meta .comments a:hover,.widget_highlighted_posts .article-content .below-entry-meta .posted-on a:hover,.widget_highlighted_posts .article-content .entry-title a:hover{color:' . $primary_color . '}.widget_featured_posts .article-content .above-entry-meta .cat-links a{background-color:' . $primary_color . '}.widget_featured_posts .article-content .entry-title a:hover{color:' . $primary_color . '}.widget_featured_posts .widget-title{border-bottom:2px solid ' . $primary_color . '}.widget_featured_posts .widget-title span{background-color:' . $primary_color . '}.related-posts-main-title .fa,.single-related-posts .article-content .entry-title a:hover{color:' . $primary_color . '}@media (max-width: 768px) {.better-responsive-menu .sub-toggle{background-color:' . $primary_dark . '}}';
373
	}
374

    
375
	if ( ! empty( $colormag_internal_css ) ) {
376
		echo '<!-- ' . get_bloginfo( 'name' ) . ' Internal Styles -->';
377
		?>
378
		<style type="text/css"><?php echo $colormag_internal_css; ?></style>
379
		<?php
380
	}
381

    
382
	$colormag_custom_css = get_theme_mod( 'colormag_custom_css' );
383
	if ( $colormag_custom_css && ! function_exists( 'wp_update_custom_css_post' ) ) {
384
		echo '<!-- ' . get_bloginfo( 'name' ) . ' Custom Styles -->';
385
		?>
386
		<style type="text/css"><?php echo $colormag_custom_css; ?></style><?php
387
	}
388
}
389

    
390
/**************************************************************************************/
391

    
392
add_filter( 'the_content_more_link', 'colormag_remove_more_jump_link' );
393
/**
394
 * Removing the more link jumping to middle of content
395
 */
396
function colormag_remove_more_jump_link( $link ) {
397
	$offset = strpos( $link, '#more-' );
398
	if ( $offset ) {
399
		$end = strpos( $link, '"', $offset );
400
	}
401
	if ( $end ) {
402
		$link = substr_replace( $link, '', $offset, $end - $offset );
403
	}
404

    
405
	return $link;
406
}
407

    
408
/**************************************************************************************/
409

    
410
if ( ! function_exists( 'colormag_content_nav' ) ) :
411
	/**
412
	 * Display navigation to next/previous pages when applicable
413
	 */
414
	function colormag_content_nav( $nav_id ) {
415
		global $wp_query, $post;
416

    
417
		// Don't print empty markup on single pages if there's nowhere to navigate.
418
		if ( is_single() ) {
419
			$previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
420
			$next     = get_adjacent_post( false, '', false );
421

    
422
			if ( ! $next && ! $previous ) {
423
				return;
424
			}
425
		}
426

    
427
		// Don't print empty markup in archives if there's only one page.
428
		if ( $wp_query->max_num_pages < 2 && ( is_home() || is_archive() || is_search() ) ) {
429
			return;
430
		}
431

    
432
		$nav_class = ( is_single() ) ? 'post-navigation' : 'paging-navigation';
433

    
434
		?>
435
		<nav role="navigation" id="<?php echo esc_attr( $nav_id ); ?>" class="<?php echo $nav_class; ?>">
436
			<h3 class="screen-reader-text"><?php _e( 'Post navigation', 'colormag' ); ?></h3>
437

    
438
			<?php if ( is_single() ) : // navigation links for single posts ?>
439

    
440
				<?php previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '&larr;', 'Previous post link', 'colormag' ) . '</span> %title' ); ?>
441
				<?php next_post_link( '<div class="nav-next">%link</div>', '%title <span class="meta-nav">' . _x( '&rarr;', 'Next post link', 'colormag' ) . '</span>' ); ?>
442

    
443
			<?php elseif ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) : // navigation links for home, archive, and search pages ?>
444

    
445
				<?php if ( get_next_posts_link() ) : ?>
446
					<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'colormag' ) ); ?></div>
447
				<?php endif; ?>
448

    
449
				<?php if ( get_previous_posts_link() ) : ?>
450
					<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'colormag' ) ); ?></div>
451
				<?php endif; ?>
452

    
453
			<?php endif; ?>
454

    
455
		</nav><!-- #<?php echo esc_html( $nav_id ); ?> -->
456
		<?php
457
	}
458
endif; // colormag_content_nav
459

    
460
/**************************************************************************************/
461

    
462
add_action( 'colormag_footer_copyright', 'colormag_footer_copyright', 10 );
463
/**
464
 * function to show the footer info, copyright information
465
 */
466
if ( ! function_exists( 'colormag_footer_copyright' ) ) :
467
	function colormag_footer_copyright() {
468
		$site_link = '<a href="' . esc_url( home_url( '/' ) ) . '" title="' . esc_attr( get_bloginfo( 'name', 'display' ) ) . '" ><span>' . get_bloginfo( 'name', 'display' ) . '</span></a>';
469

    
470
		$wp_link = '<a href="https://wordpress.org" target="_blank" title="' . esc_attr__( 'WordPress', 'colormag' ) . '"><span>' . __( 'WordPress', 'colormag' ) . '</span></a>';
471

    
472
		$tg_link = '<a href="https://themegrill.com/themes/colormag" target="_blank" title="' . esc_attr__( 'ThemeGrill', 'colormag' ) . '" rel="designer"><span>' . __( 'ThemeGrill', 'colormag' ) . '</span></a>';
473

    
474
		$default_footer_value = sprintf( __( 'Copyright &copy; %1$s %2$s. All rights reserved.', 'colormag' ), date( 'Y' ), $site_link ) . '<br>' . sprintf( __( 'Theme: %1$s by %2$s.', 'colormag' ), 'ColorMag', $tg_link ) . ' ' . sprintf( __( 'Powered by %s.', 'colormag' ), $wp_link );
475

    
476
		$colormag_footer_copyright = '<div class="copyright">' . $default_footer_value . '</div>';
477
		echo $colormag_footer_copyright;
478
	}
479
endif;
480

    
481
/**************************************************************************************/
482

    
483
/*
484
 * Category Color Options
485
 */
486
if ( ! function_exists( 'colormag_category_color' ) ) :
487
	function colormag_category_color( $wp_category_id ) {
488
		$args     = array(
489
			'orderby'    => 'id',
490
			'hide_empty' => 0,
491
		);
492
		$category = get_categories( $args );
493
		foreach ( $category as $category_list ) {
494
			$color = get_theme_mod( 'colormag_category_color_' . $wp_category_id );
495

    
496
			return $color;
497
		}
498
	}
499
endif;
500

    
501
/**************************************************************************************/
502

    
503
/*
504
 * Breaking News/Latest Posts ticker section in the header
505
 */
506
if ( ! function_exists( 'colormag_breaking_news' ) ) :
507
	function colormag_breaking_news() {
508
		$post_status = 'publish';
509
		if ( get_option( 'fresh_site' ) == 1 ) {
510
			$post_status = array( 'auto-draft', 'publish' );
511
		}
512

    
513
		$get_featured_posts = new WP_Query( array(
514
			'posts_per_page'      => 5,
515
			'post_type'           => 'post',
516
			'ignore_sticky_posts' => true,
517
			'post_status'         => $post_status,
518
		) );
519
		?>
520
		<div class="breaking-news">
521
			<strong class="breaking-news-latest"><?php _e( 'Latest:', 'colormag' ); ?></strong>
522
			<ul class="newsticker">
523
				<?php while ( $get_featured_posts->have_posts() ):$get_featured_posts->the_post(); ?>
524
					<li>
525
						<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
526
					</li>
527
				<?php endwhile; ?>
528
			</ul>
529
		</div>
530
		<?php
531
		// Reset Post Data
532
		wp_reset_query();
533
	}
534
endif;
535

    
536
/**************************************************************************************/
537

    
538
/*
539
 * Display the date in the header
540
 */
541
if ( ! function_exists( 'colormag_date_display' ) ) :
542
	function colormag_date_display() { ?>
543
		<div class="date-in-header">
544
			<?php
545
			if ( get_theme_mod( 'colormag_date_display_type', 'theme_default' ) == 'theme_default' ) {
546
				echo date_i18n( 'l, F j, Y' );
547
			} else if ( get_theme_mod( 'colormag_date_display_type', 'theme_default' ) == 'wordpress_date_setting' ) {
548
				echo date_i18n( get_option( 'date_format' ) );
549
			}
550
			?>
551
		</div>
552
		<?php
553
	}
554
endif;
555

    
556
/**************************************************************************************/
557

    
558
/*
559
 * Random Post in header
560
 */
561
if ( ! function_exists( 'colormag_random_post' ) ) :
562
	function colormag_random_post() {
563
		$get_random_post = new WP_Query( array(
564
			'posts_per_page'      => 1,
565
			'post_type'           => 'post',
566
			'ignore_sticky_posts' => true,
567
			'orderby'             => 'rand',
568
		) );
569
		?>
570
		<div class="random-post">
571
			<?php while ( $get_random_post->have_posts() ):$get_random_post->the_post(); ?>
572
				<a href="<?php the_permalink(); ?>" title="<?php _e( 'View a random post', 'colormag' ); ?>"><i class="fa fa-random"></i></a>
573
			<?php endwhile; ?>
574
		</div>
575
		<?php
576
		// Reset Post Data
577
		wp_reset_query();
578
	}
579
endif;
580

    
581
/**************************************************************************************/
582

    
583
/*
584
 * Display the related posts
585
 */
586
if ( ! function_exists( 'colormag_related_posts_function' ) ) {
587

    
588
	function colormag_related_posts_function() {
589
		wp_reset_postdata();
590
		global $post;
591

    
592
		// Define shared post arguments
593
		$args = array(
594
			'no_found_rows'          => true,
595
			'update_post_meta_cache' => false,
596
			'update_post_term_cache' => false,
597
			'ignore_sticky_posts'    => 1,
598
			'orderby'                => 'rand',
599
			'post__not_in'           => array( $post->ID ),
600
			'posts_per_page'         => 3,
601
		);
602
		// Related by categories
603
		if ( get_theme_mod( 'colormag_related_posts', 'categories' ) == 'categories' ) {
604

    
605
			$cats = get_post_meta( $post->ID, 'related-posts', true );
606

    
607
			if ( ! $cats ) {
608
				$cats                   = wp_get_post_categories( $post->ID, array( 'fields' => 'ids' ) );
609
				$args[ 'category__in' ] = $cats;
610
			} else {
611
				$args[ 'cat' ] = $cats;
612
			}
613
		}
614
		// Related by tags
615
		if ( get_theme_mod( 'colormag_related_posts', 'categories' ) == 'tags' ) {
616

    
617
			$tags = get_post_meta( $post->ID, 'related-posts', true );
618

    
619
			if ( ! $tags ) {
620
				$tags              = wp_get_post_tags( $post->ID, array( 'fields' => 'ids' ) );
621
				$args[ 'tag__in' ] = $tags;
622
			} else {
623
				$args[ 'tag_slug__in' ] = explode( ',', $tags );
624
			}
625
			if ( ! $tags ) {
626
				$break = true;
627
			}
628
		}
629

    
630
		$query = ! isset( $break ) ? new WP_Query( $args ) : new WP_Query;
631

    
632
		return $query;
633
	}
634

    
635
}
636

    
637
/**************************************************************************************/
638

    
639
/*
640
 * Category Color for widgets and other
641
 */
642
if ( ! function_exists( 'colormag_colored_category' ) ) :
643
	function colormag_colored_category() {
644
		global $post;
645
		$categories = get_the_category();
646
		$separator  = '&nbsp;';
647
		$output     = '';
648
		if ( $categories ) {
649
			$output .= '<div class="above-entry-meta"><span class="cat-links">';
650
			foreach ( $categories as $category ) {
651
				$color_code = colormag_category_color( get_cat_id( $category->cat_name ) );
652
				if ( ! empty( $color_code ) ) {
653
					$output .= '<a href="' . get_category_link( $category->term_id ) . '" style="background:' . colormag_category_color( get_cat_id( $category->cat_name ) ) . '" rel="category tag">' . $category->cat_name . '</a>' . $separator;
654
				} else {
655
					$output .= '<a href="' . get_category_link( $category->term_id ) . '"  rel="category tag">' . $category->cat_name . '</a>' . $separator;
656
				}
657
			}
658
			$output .= '</span></div>';
659
			echo trim( $output, $separator );
660
		}
661
	}
662
endif;
663

    
664
/**************************************************************************************/
665

    
666
/*
667
 * Creating responsive video for posts/pages
668
 */
669
if ( ! function_exists( 'colormag_responsive_video' ) ) :
670
	function colormag_responsive_video( $html, $url, $attr, $post_ID ) {
671
		return '<div class="fitvids-video">' . $html . '</div>';
672
	}
673

    
674
	add_filter( 'embed_oembed_html', 'colormag_responsive_video', 10, 4 );
675
endif;
676

    
677
/**************************************************************************************/
678

    
679
/*
680
 * Use of the hooks for Category Color in the archive titles
681
 */
682
function colormag_colored_category_title( $title ) {
683
	$color_value        = colormag_category_color( get_cat_id( $title ) );
684
	$color_border_value = colormag_category_color( get_cat_id( $title ) );
685
	if ( ! empty( $color_value ) ) {
686
		return '<h1 class="page-title" style="border-bottom-color: ' . $color_border_value . '">' . '<span style="background-color: ' . $color_value . '">' . $title . '</span></h1>';
687
	} else {
688
		return '<h1 class="page-title"><span>' . $title . '</span></h1>';
689
	}
690
}
691

    
692
function colormag_category_title_function( $category_title ) {
693
	add_filter( 'single_cat_title', 'colormag_colored_category_title' );
694
}
695

    
696
add_action( 'colormag_category_title', 'colormag_category_title_function' );
697

    
698
/**************************************************************************************/
699

    
700
/**
701
 * Making the theme Woocommrece compatible
702
 */
703
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
704
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
705
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 );
706
// Remove WooCommerce default sidebar
707
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
708

    
709
add_filter( 'woocommerce_show_page_title', '__return_false' );
710

    
711
add_action( 'woocommerce_before_main_content', 'colormag_wrapper_start', 10 );
712
add_action( 'woocommerce_after_main_content', 'colormag_wrapper_end', 10 );
713

    
714
function colormag_wrapper_start() {
715
	echo '<div id="primary">';
716
}
717

    
718
function colormag_wrapper_end() {
719
	echo '</div>';
720
	colormag_sidebar_select();
721
}
722

    
723
// Displays the site logo
724
if ( ! function_exists( 'colormag_the_custom_logo' ) ) {
725
	/**
726
	 * Displays the optional custom logo.
727
	 */
728
	function colormag_the_custom_logo() {
729
		if ( function_exists( 'the_custom_logo' ) && ( get_theme_mod( 'colormag_logo', '' ) == '' ) ) {
730
			the_custom_logo();
731
		}
732
	}
733
}
734

    
735
/**
736
 * Function to transfer the favicon added in Customizer Options of theme to Site Icon in Site Identity section
737
 */
738
function colormag_site_icon_migrate() {
739
	if ( get_option( 'colormag_site_icon_transfer' ) ) {
740
		return;
741
	}
742

    
743
	global $wp_version;
744
	$image_url = get_theme_mod( 'colormag_favicon_upload', '' );
745

    
746
	if ( ( $wp_version >= 4.3 ) && ( ! has_site_icon() && ! empty( $image_url ) ) ) {
747
		$customizer_site_icon_id = attachment_url_to_postid( $image_url );
748
		update_option( 'site_icon', $customizer_site_icon_id );
749
		// Set the transfer as complete.
750
		update_option( 'colormag_site_icon_transfer', 1 );
751
		// Delete the old favicon theme_mod option.
752
		remove_theme_mod( 'colormag_favicon_upload' );
753
		remove_theme_mod( 'colormag_favicon_show' );
754
	}
755
}
756

    
757
add_action( 'after_setup_theme', 'colormag_site_icon_migrate' );
758

    
759
/**
760
 * Migrate any existing theme CSS codes added in Customize Options to the core option added in WordPress 4.7
761
 */
762
function colormag_custom_css_migrate() {
763
	if ( function_exists( 'wp_update_custom_css_post' ) ) {
764
		$custom_css = get_theme_mod( 'colormag_custom_css' );
765
		if ( $custom_css ) {
766
			$core_css = wp_get_custom_css(); // Preserve any CSS already added to the core option.
767
			$return   = wp_update_custom_css_post( $core_css . $custom_css );
768
			if ( ! is_wp_error( $return ) ) {
769
				// Remove the old theme_mod, so that the CSS is stored in only one place moving forward.
770
				remove_theme_mod( 'colormag_custom_css' );
771
			}
772
		}
773
	}
774
}
775

    
776
add_action( 'after_setup_theme', 'colormag_custom_css_migrate' );
777

    
778
/**
779
 * Function to transfer the Header Logo added in Customizer Options of theme to Site Logo in Site Identity section
780
 */
781
function colormag_site_logo_migrate() {
782
	if ( function_exists( 'the_custom_logo' ) && ! has_custom_logo( $blog_id = 0 ) ) {
783
		$logo_url = get_theme_mod( 'colormag_logo' );
784

    
785
		if ( $logo_url ) {
786
			$customizer_site_logo_id = attachment_url_to_postid( $logo_url );
787
			set_theme_mod( 'custom_logo', $customizer_site_logo_id );
788

    
789
			// Delete the old Site Logo theme_mod option.
790
			remove_theme_mod( 'colormag_logo' );
791
		}
792
	}
793
}
794

    
795
add_action( 'after_setup_theme', 'colormag_site_logo_migrate' );
796

    
797
/**************************************************************************************/
798

    
799
if ( ! function_exists( 'colormag_comment' ) ) :
800
/**
801
 * Template for comments and pingbacks.
802
 *
803
 * Used as a callback by wp_list_comments() for displaying the comments.
804
 */
805
function colormag_comment( $comment, $args, $depth ) {
806
$GLOBALS[ 'comment' ] = $comment;
807
switch ( $comment->comment_type ) :
808
case 'pingback' :
809
case 'trackback' :
810
// Display trackbacks differently than normal comments.
811
?>
812
<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
813
	<p><?php _e( 'Pingback:', 'colormag' ); ?><?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'colormag' ), '<span class="edit-link">', '</span>' ); ?></p>
814
	<?php
815
	break;
816
	default :
817
	// Proceed with normal comments.
818
	global $post;
819
	?>
820
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
821
	<article id="comment-<?php comment_ID(); ?>" class="comment">
822
		<header class="comment-meta comment-author vcard">
823
			<?php
824
			echo get_avatar( $comment, 74 );
825
			printf( '<div class="comment-author-link"><i class="fa fa-user"></i>%1$s%2$s</div>',
826
				get_comment_author_link(),
827
				// If current post author is also comment author, make it known visually.
828
				( $comment->user_id === $post->post_author ) ? '<span>' . __( 'Post author', 'colormag' ) . '</span>' : ''
829
			);
830
			printf( '<div class="comment-date-time"><i class="fa fa-calendar-o"></i>%1$s</div>',
831
				sprintf( __( '%1$s at %2$s', 'colormag' ), get_comment_date(), get_comment_time() )
832
			);
833
			printf( '<a class="comment-permalink" href="%1$s"><i class="fa fa-link"></i>Permalink</a>', esc_url( get_comment_link( $comment->comment_ID ) ) );
834
			edit_comment_link();
835
			?>
836
		</header><!-- .comment-meta -->
837

    
838
		<?php if ( '0' == $comment->comment_approved ) : ?>
839
			<p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'colormag' ); ?></p>
840
		<?php endif; ?>
841

    
842
		<section class="comment-content comment">
843
			<?php comment_text(); ?>
844
			<?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply', 'colormag' ), 'after' => '', 'depth' => $depth, 'max_depth' => $args[ 'max_depth' ] ) ) ); ?>
845
		</section><!-- .comment-content -->
846

    
847
	</article><!-- #comment-## -->
848
	<?php
849
	break;
850
	endswitch; // end comment_type check
851
	}
852
	endif;
853
	?>
(4-4/16)