View difference between Paste ID: r3kyPJ9W and tKY1kN9D
SHOW: | | - or go back to the newest paste.
1
<?php
2
/**
3
 * mx functions and definitions
4
 *
5
 * @since MX 4.0
6
 */
7
 
8
 
9
/**
10
 * All MX common functions.
11
 * Don't remove it.
12
 *
13
 * @since MX 1.0
14
 */
15
 function register_my_menu() {
16
  register_nav_menu('bottom-menu',__( 'Bottom Menu' ));
17
}
18
add_action( 'init', 'register_my_menu' );
19
20
require_once("inc/mx-functions.php");
21
22
/**
23
 * Sets up theme custom options, post, update notifier.
24
 * Don't remove it.
25
 *
26
 * @since MX 1.0
27
 */
28
include_once("inc/penguin-config.php");
29
/**
30
 * Get all MX options value
31
 */
32
global $mx_options;
33
$mx_options = get_option("mx_options");
34
35
if (class_exists( 'woocommerce' )) {
36
	require_once('woocommerce/woocommerce-config.php');
37
}
38
39
add_action('wp_ajax_nopriv_post-like', 'penguin_post_like');
40
add_action('wp_ajax_post-like', 'penguin_post_like');
41
42
/**
43
 * Set the content width based on the theme's design and stylesheet.
44
 */
45
if ( ! isset( $content_width ) ) {
46
	$content_width = 788;
47
}
48
49
/**
50
 * Sets up theme defaults and registers support for various WordPress features.
51
 *
52
 * Note that this function is hooked into the after_setup_theme hook, which runs
53
 * before the init hook. The init hook is too late for some features, such as indicating
54
 * support post thumbnails.
55
 *
56
 * @uses load_theme_textdomain() For translation/localization support.
57
 * @uses add_theme_support() To add support for post thumbnails, automatic feed links and post formats.
58
 * @uses register_nav_menus() To add support for navigation menus.
59
 * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
60
 *
61
 * @since MX 1.0
62
 */
63
function mx_setup() {
64
65
	// Load the Themes' Translations through domain
66
	load_theme_textdomain( 'MX', get_template_directory() . '/languages' );
67
	
68
	// Add default posts and comments RSS feed links to head
69
	add_theme_support( 'automatic-feed-links' );
70
	
71
	// This theme uses wp_nav_menu() in one location.
72
	register_nav_menu( 'mx_menu', __( 'MX Main Menus', 'MX' ) );
73
	register_nav_menu( 'mx_topbar_menu', __( 'MX Topbar Menus', 'MX' ) );
74
	register_nav_menu( 'mx_bottom_menu', __( 'MX Bottom Menus', 'MX' ) );
75
76
	// Add support for a variety of post formats
77
	add_theme_support( 'post-formats', array( 'gallery', 'video', 'audio' ,'image' , 'quote' ) );
78
	
79
	// This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images
80
	add_theme_support( 'post-thumbnails' );
81
	
82
	// Add Woocommerce Support
83
	add_theme_support( 'woocommerce' );
84
	
85
	// We'll be using post thumbnails for custom header images on posts and pages.
86
	// We want them to be the size of the header image that we just defined
87
	// Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
88
	set_post_thumbnail_size( 788, 445, true );
89
	
90
	//mx theme image size
91
	add_image_size( 'mx-l-thumbs' , 750 , 423 , true);
92
	add_image_size( 'mx-m-thumbs' , 555 , 313 , true);
93
	add_image_size( 'mx-s-thumbs' , 450 , 254 , true);
94
	add_image_size( 'mx-square-thumbs' , 750 , 750 , true);
95
	add_image_size( 'mx-nocrop-thumbs' , 750 , 1500 , false);
96
	
97
}
98
add_action( 'after_setup_theme', 'mx_setup' );
99
100
/**
101
 * Sets up theme defaults styles and scripts.
102
 *
103
 * @since MX 1.0
104
 */
105
function mx_init_styles_scripts() {
106
	global $google_load_fonts,$mx_options;
107
	
108
	//get template directory url
109
	$dir = get_template_directory_uri();
110
	
111
	//get theme version
112
	$theme_data = wp_get_theme();
113
	$ver = $theme_data['Version'];
114
	
115
	/* bootstrap & fontawesome css files */
116
	if(mx_get_options_key('bootstrap-fontawesome-cdn') == "on"){
117
		wp_enqueue_style( 'bootstrap', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css' , array() , $ver );
118
		wp_enqueue_style( 'fontawesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css' , array() , $ver );
119
	}else{
120
		wp_enqueue_style( 'bootstrap', $dir . '/bootstrap/css/bootstrap.min.css' , array() , $ver );
121
		wp_enqueue_style( 'fontawesome', $dir . '/fontawesome/css/font-awesome.min.css' , array() , $ver );	
122
	}
123
	wp_enqueue_style( 'flexslider_style', $dir . '/js/flexslider/flexslider.css' , array() , $ver );
124
	wp_enqueue_style( 'fancyBox_style', $dir . '/js/fancyBox/jquery.fancybox.css' , array() , $ver );
125
	wp_enqueue_style( 'fancyBox_helper_style', $dir . '/js/fancyBox/helpers/jquery.fancybox-thumbs.css' , array() , $ver );
126
	wp_enqueue_style( 'animate', $dir . '/css/animate.min.css' , array() , $ver );
127
	if (class_exists( 'woocommerce' )) { 
128
		wp_enqueue_style( 'woocommerce_style', $dir . '/woocommerce/assets/css/woocommerce-'. mx_get_theme_skin() .'.css' , array() , $ver ); 
129
	}
130
	wp_enqueue_style( 'mx_skin', $dir . '/css/' . mx_get_theme_skin() . '.css'  , array() , $ver );
131
	wp_enqueue_style( 'mx_style', get_stylesheet_uri()  , array() , $ver );
132
	wp_enqueue_style( 'mx_responsive_style', $dir . '/css/responsive.css'  , array() , $ver );
133
	
134
	//Custom
135
	$mx_options_update = get_option('mx_options_update');
136
	if(isset($mx_options_update['version'])){
137
		$uploads = wp_upload_dir();
138
		if (file_exists($uploads['basedir'] . '/mx/mx-styles.css')) {
139
			$custom_css = $uploads['baseurl'] . '/mx/mx-styles.css';
140
			wp_enqueue_style( 'custom_style', $custom_css  , array() , $mx_options_update['version'] );
141
		}
142
	}
143
	
144
	//Font
145
	mx_get_custom_font();
146
	if($google_load_fonts != null && $google_load_fonts != ""){
147
		$subsets = mx_get_options_key('google-font-subset') != "" ? '&subset='.mx_get_options_key('google-font-subset') : "";
148
		wp_enqueue_style( 'custom-font', '//fonts.googleapis.com/css?family='.$google_load_fonts.$subsets);
149
	}
150
	
151
	//Javascripts
152
	wp_enqueue_script('jquery');
153
	if ( is_singular() && comments_open() ) { wp_enqueue_script( 'comment-reply' );	}
154
	if(mx_get_options_key('bootstrap-fontawesome-cdn') == "on"){
155
		wp_enqueue_script( 'bootstrap' , '//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js' , array('jquery') , $ver , true);
156
	}else{
157
		wp_enqueue_script( 'bootstrap' , $dir . '/bootstrap/js/bootstrap.min.js' , array('jquery') , $ver , true);
158
	}
159
	wp_enqueue_script( 'isotope' , $dir . '/js/isotope.pkgd.min.js' , array('jquery') , $ver , true);
160
	wp_enqueue_script( 'fancyBox_mousewheel' , $dir . '/js/fancyBox/jquery.mousewheel-3.0.6.pack.js' , array('jquery') , $ver , true);
161
	wp_enqueue_script( 'fancyBox_js' , $dir . '/js/fancyBox/jquery.fancybox.pack.js' , array('jquery') , $ver , true);
162
	wp_enqueue_script( 'fancyBox_helpers_js' , $dir . '/js/fancyBox/helpers/jquery.fancybox-thumbs.js' , array('jquery') , $ver , true);
163
	wp_enqueue_script( 'flexslider_js' , $dir . '/js/flexslider/jquery.flexslider-min.js' , array('jquery') , $ver , true);
164
	wp_enqueue_script( 'mx_script' , $dir . '/js/jquery.theme.js' , array('jquery') , $ver , true);
165
	
166
	if (class_exists( 'woocommerce' )) {
167
		wc_enqueue_js( "$('a.zoom').fancybox({helpers: {thumbs: {width: 80,height	: 80}}});$('body').mxpreview();" );
168
	}
169
	
170
	if(mx_get_options_key('blog-viewlike-enable') == "on" || mx_get_options_key('portfolio-viewlike-enable') == "on"){
171
		
172
		wp_enqueue_script( 'like_post' , $dir . '/js/jquery.likepost.js' , array('jquery') , $ver , true);
173
		
174
		wp_localize_script('like_post', 'ajax_var', array(
175
			'url' => admin_url('admin-ajax.php'),
176
			'nonce' => wp_create_nonce('ajax-nonce')
177
		));
178
	}
179
}
180
add_action('wp_enqueue_scripts', 'mx_init_styles_scripts');
181
182
/**
183
 * Sets up custom title
184
 *
185
 * @since MX 1.0
186
 */
187
function mx_wp_title( $title, $sep ) {
188
	global $paged, $page;
189
190
	if ( is_feed() ){return $title;	}
191
192
	// Add the site name.
193
	$title .= get_bloginfo( 'name' );
194
195
	// Add the site description for the home/front page.
196
	$site_description = get_bloginfo( 'description', 'display' );
197
	if ( $site_description && ( is_home() || is_front_page() ) ){
198
		$title = "$title $sep $site_description";
199
	}
200
201
	// Add a page number if necessary.
202
	if ( $paged >= 2 || $page >= 2 ){
203
		$title = "$title $sep " . sprintf( __( 'Page %s', 'MX' ), max( $paged, $page ) );
204
	}
205
206
	return $title;
207
}
208
add_filter( 'wp_title', 'mx_wp_title', 10, 2 );
209
210
/**
211
 * Sets up custom theme styles
212
 *
213
 * @since MX 1.0
214
 */
215
function mx_custom_styles(){
216
	global $mx_page_custom_scripts;
217
	// get page custom css
218
	mx_get_page_custom_options_css();
219
220
	// get option custom css style
221
	if(mx_get_options_key('custom-enable-css') == "on" && mx_get_options_key('custom-css-content') != ""){
222
		?>
223
        <style id="mx-custom-css" type="text/css">
224
			<?php echo mx_get_options_key('custom-css-content'); ?>
225
			@media only screen and (-Webkit-min-device-pixel-ratio: 1.5),
226
			only screen and (-moz-min-device-pixel-ratio: 1.5),
227
			only screen and (-o-min-device-pixel-ratio: 3/2),
228
			only screen and (min-device-pixel-ratio: 1.5) {
229
			<?php echo mx_get_options_key('custom-css-retina-content'); ?>
230
			}
231
		</style>
232
        <?php 
233
	}
234
	
235
	// get page custom scripts
236
	$mx_page_custom_scripts = mx_get_page_custom_options_scripts();
237
	
238
	// get gogole analytics
239
	echo intval(mx_get_options_key('google_analytics-position')) == 0 ? mx_get_options_key('google_analytics-content') : "";
240
}
241
add_action( 'wp_head', 'mx_custom_styles' );
242
243
/**
244
 * Sets up footer custom theme styles
245
 *
246
 * @since MX 1.0
247
 */
248
function mx_wp_footer_scripts(){
249
	global $mx_map_id,$mx_page_custom_scripts;
250
	//get template directory url
251
	$dir = get_template_directory_uri();
252
253
	if(isset($mx_map_id) && intval($mx_map_id > 0)){
254
		/* google map */
255
		wp_enqueue_script( 'googleapis', '//maps.googleapis.com/maps/api/js?v=3&amp;sensor=false');
256
		wp_enqueue_script( 'map-infobox', $dir . '/js/infobox.js');
257
	}
258
	if((mx_get_options_key('custom-enable-scripts') == "on" && mx_get_options_key('custom-scripts-content') != "") || (isset($mx_page_custom_scripts) && $mx_page_custom_scripts != '')){
259
?>
260
	<script type="text/javascript">
261
    <?php 
262
		if(mx_get_options_key('custom-enable-scripts') == "on" && mx_get_options_key('custom-scripts-content') != ""){
263
			echo mx_get_options_key('custom-scripts-content'); 
264
		}
265
		if(isset($mx_page_custom_scripts) && $mx_page_custom_scripts != ''){
266
			echo $mx_page_custom_scripts;
267
		}
268
	?>
269
    </script>
270
<?php 
271
	}
272
	
273
	echo intval(mx_get_options_key('google_analytics-position')) == 1 ? mx_get_options_key('google_analytics-content') : "";
274
}
275
add_action( 'wp_footer', 'mx_wp_footer_scripts' );
276
277
/**
278
 * Add shortcode
279
 *
280
 * @since MX 1.0
281
 */
282
 
283
// Use shortcodes in text widgets.
284
add_filter('widget_text', 'do_shortcode');
285
include("inc/shortcodes.php");
286
287
/**
288
 * Register our sidebars and widgetized areas. Also register the default Epherma widget.
289
 *
290
 * @since MX 1.0
291
 */
292
function mx_widgets_init() {
293
	
294
	register_sidebar( array(
295
		'name' => __( 'Global Sidebar', 'MX' ),
296
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
297
		'after_widget' => '</div>',
298
		'before_title' => '<h4 class="widget-title">',
299
		'after_title' => '</h4><div class="line"></div><div class="clear"></div>'
300
	));
301
	
302
	register_sidebar( array(
303
		'id'	=>'sidebar-footer-1',
304
		'name' => __( 'Footer 1', 'MX' ),
305
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
306
		'after_widget' => '</div>',
307
		'before_title' => '<h4 class="widget-title">',
308
		'after_title' => '</h4>'
309
	));
310
	
311
	register_sidebar( array(
312
		'id'	=>'sidebar-footer-2',
313
		'name' => __( 'Footer 2', 'MX' ),
314
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
315
		'after_widget' => '</div>',
316
		'before_title' => '<h4 class="widget-title">',
317
		'after_title' => '</h4>'
318
	));
319
	
320
	register_sidebar( array(
321
		'id'	=>'sidebar-footer-3',
322
		'name' => __( 'Footer 3', 'MX' ),
323
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
324
		'after_widget' => '</div>',
325
		'before_title' => '<h4 class="widget-title">',
326
		'after_title' => '</h4>'
327
	));
328
	
329
	register_sidebar( array(
330
		'id'	=>'sidebar-footer-4',
331
		'name' => __( 'Footer 4', 'MX' ),
332
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
333
		'after_widget' => '</div>',
334
		'before_title' => '<h4 class="widget-title">',
335
		'after_title' => '</h4>'
336
	));
337
	
338
	register_sidebar( array(
339
		'id'	=>'shop',
340
		'name' => __( 'Woocommerce Shop', 'MX' ),
341
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
342
		'after_widget' => '</div>',
343
		'before_title' => '<h4 class="widget-title">',
344
		'after_title' => '</h4><div class="line"></div><div class="clear"></div>'
345
	));
346
347
}
348
add_action( 'widgets_init', 'mx_widgets_init' );
349
include_once("inc/custom-widgets.php");
350
351
/**
352
 * Redesign login page
353
 */
354
function mx_login_logo() { 
355
	global $mx_options;
356
?>
357
    <style type="text/css">
358
        body.login div#login h1 a {
359
			width:<?php echo mx_get_options_key('logo-image-width'); ?>px;
360
			height:<?php echo mx_get_options_key('logo-image-height'); ?>px;
361
			background-image:url(<?php echo mx_get_options_key('logo-image') == "" ?  get_template_directory_uri()."/img/logo.png" : mx_get_options_key('logo-image'); ?>);
362
    		background-size: <?php echo mx_get_options_key('logo-image-width'); ?>px <?php echo mx_get_options_key('logo-image-height'); ?>px;
363
        }
364
		@media only screen and (-Webkit-min-device-pixel-ratio: 1.5),
365
		only screen and (-moz-min-device-pixel-ratio: 1.5),
366
		only screen and (-o-min-device-pixel-ratio: 3/2),
367
		only screen and (min-device-pixel-ratio: 1.5) {
368
		body.login div#login h1 a {
369
			background-image: url(<?php echo mx_get_options_key('logo-retina-image') == "" ?  get_template_directory_uri()."/img/[email protected]" : mx_get_options_key('logo-retina-image'); ?>);
370
        }
371
		}
372
    </style>
373
<?php }
374
add_action( 'login_enqueue_scripts', 'mx_login_logo' );
375
376
function mx_login_logo_url() {
377
    return home_url();
378
}
379
add_filter( 'login_headerurl', 'mx_login_logo_url' );
380
381
function mx_login_logo_url_title() {
382
    return get_bloginfo('title');
383
}
384
add_filter( 'login_headertitle', 'mx_login_logo_url_title' );
385
386
?>
387
388
<?php
389
function lidget_popup_link() {
390
?>
391
<script type="text/javascript">
392
    jQuery(window).load(function() {
393
        var width = "680", /* Enter popup window width here */
394
            height = "480", /* Enter popup window height here */
395
            menuItem = "menu-item-140", /* Enter menu item ID */
396
            target = "#"+menuItem+" a",
397
            hrefVal = jQuery(target).attr("href")
398
        ;
399
        jQuery(target).attr({
400
            "href" : "#",
401
            "onclick" : "window.open('"+hrefVal+"','','width="+width+",height="+height+",scrollbars=no,resizable=no,location=no,menubar=no,toolbar=no')"
402
        });
403
    });
404
</script>
405
<?php
406
}
407
add_action('wp_head', 'lidget_popup_link');
408
409
function lidget_call_jquery() {
410
    wp_enqueue_script('jquery');
411
}
412
add_action('wp_enqueue_scripts', 'lidget_call_jquery');
413
?>