Completed
Push — master ( a2ad7e...08fe5e )
by SILENT
02:17
created

functions.php (2 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Strip functions and definitions
4
 *
5
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
6
 *
7
 * @package WordPress
8
 * @subpackage Strip
9
 */
10
11
	// Set the content width based on the theme's design and stylesheet.
12
if ( ! isset( $content_width ) ) {
13
		$content_width = 1920;
14
} /* pixels */
15
16
if ( ! function_exists( 'strip_setup' ) ) :
17
	/**
18
	 * Sets up theme defaults and registers support for various WordPress features.
19
	 *
20
	 * Note that this function is hooked into the after_setup_theme hook, which runs
21
	 * before the init hook. The init hook is too late for some features, such as indicating
22
	 * support post thumbnails.
23
	 */
24
	function strip_setup() {
25
		/**
26
* Remove some default WordPress dashboard widgets
27
* an example custom dashboard widget
28
* adding custom login css
29
* changing text in footer of admin
30
*/
31
		require_once( 'assets/admin.php' );
32
		/**
33
* Make theme available for translation
34
* Translations can be filed in the /languages/ directory
35
* If you're building a theme based on strip, use a find and replace
36
* to change 'strip' to the name of your theme in all the template files
37
*/
38
		load_theme_textdomain( 'strip', get_template_directory() . '/languages' );
39
40
		// Add default posts and comments RSS feed links to head.
41
		add_theme_support( 'automatic-feed-links' );
42
43
		/**
44
* Enable support for title-tag. Allows themes to add document title tag to HTML <head> (since version 4.1.).
45
*/
46
		add_theme_support( 'title-tag' );
47
48
		/**
49
* Enable support for custom logo.
50
*
51
* @since strip 1.0
52
*/
53
		add_theme_support( 'custom-logo', array(
54
			'height'      => 156,
55
			'width'       => 312,
56
			'flex-height' => true,
57
			'flex-width'  => true,
58
			)
59
		);
60
61
		/**
62
* Enable support for Post Thumbnails on posts and pages
63
*
64
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
65
*/
66
		add_theme_support( 'post-thumbnails' );
67
		add_image_size( 'strip-featured-image', 1920, 960, true );
68
		add_image_size( 'strip-large', 1920, 960, true ); // cropped.
69
		add_image_size( 'strip-medium', 624, 312, true ); // cropped.
70
		add_image_size( 'strip-thumbnail', 312, 156, true ); // cropped.
71
72
		/**
73
		 * Remove paragraph tags around images.
74
		 *
75
		 * @param array $content filter p tags.
76
		 * @return $content
77
		 * @link https://css-tricks.com/snippets/wordpress/remove-paragraph-tags-from-around-images/
78
		 * @see http://codex.wordpress.org/Function_Reference/wpautop gets the same result but removes line blocks: remove_filter( 'the_content', 'wpautop' );
79
		 */
80
		function filter_ptags_on_images( $content ) {
81
			return preg_replace( '/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content );
82
		}
83
		add_filter( 'the_content', 'filter_ptags_on_images' );
84
85
		/**
86
	 	* This theme uses wp_nav_menu() in one location.
87
	 	*/
88
		register_nav_menus(array(
89
			'primary' => __( 'Primary Menu', 'strip' ),
90
		));
91
92
		/*
93
		* Switch default core markup for search form, comment form, and comments
94
		* to output valid HTML5.
95
		*/
96
		add_theme_support( 'html5', array(
97
			'search-form',
98
			'comment-form',
99
			'comment-list',
100
			'gallery',
101
			'caption',
102
			'widgets',
103
		) );
104
105
		/**
106
	 * Enable support for Post Formats
107
	 */
108
		add_theme_support( 'post-formats', array(
109
			'image',
110
			'video',
111
			'quote',
112
			'link',
113
			'gallery',
114
			'audio',
115
			'chat',
116
		) );
117
118
		// Setup the WordPress core custom background feature.
119
		add_theme_support('custom-background', apply_filters('strip_custom_background_args', array(
120
			'default-color' => 'ffffff',
121
			'default-image' => '',
122
		) ) );
123
	}
124
125
	/**
126
	 * Clean wp_head, remove queries.
127
	 *
128
	 * @since    1.1.3
129
	 * @link: http://cubiq.org/clean-up-and-optimize-wordpress-for-your-next-theme
130
	 */
131
	function strip_cleanup() {
132
			remove_action( 'wp_head', 'wp_generator' );					// WP Version.
133
			remove_action( 'wp_head', 'wlwmanifest_link' );
134
			remove_action( 'wp_head', 'rsd_link' );
135
			remove_action( 'wp_head', 'rel_canonical', 10, 0 );
136
			remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
137
138
			remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );// Parent rel link.
139
			remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );	// Start post rel link.
140
			remove_action( 'wp_head', 'index_rel_link' );
141
142
			remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); // Adjacent post rel link.
143
144
			add_filter( 'the_generator', '__return_false' );
145
146
			remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
147
			remove_action( 'wp_print_styles', 'print_emoji_styles' );
148
	}
149
	/**
150
	 * Cleanup head remove rss version
151
	 *
152
	 * @since    1.1.3
153
	 */
154
	function strip_remove_rss_version() {
155
		return '';
156
	}
157
	/**
158
	 * Cleanup head remove X-Pingback
159
	 *
160
	 * @param array $headers remove x pingback.
161
	 * @since    1.1.3
162
	 */
163
	function strip_remove_x_pingback( $headers ) {
164
		unset( $headers['X-Pingback'] );
165
		return $headers;
166
	}
167
168
	/**
169
	 * Cleanup head remove inline CSS comments
170
	 *
171
	 * @since    1.1.3
172
	 */
173
	function strip_remove_comments_inline_styles() {
174
		global $wp_widget_factory;
175
		if ( has_filter( 'wp_head', 'wp_widget_recent_comments_style' ) ) {
176
			remove_filter( 'wp_head', 'wp_widget_recent_comments_style' );
177
		}
178
179
		remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
180
	}
181
182
183
	/**
184
	* This theme styles the visual editor to resemble the theme style,
185
	* specifically font, colors, icons, and column width.
186
	*/
187
	add_editor_style( array( '/assets/css/editor-style.css', '/assets/fonts/fenix.css' ) );
188
189
	// Indicate widget sidebars can use selective refresh in the Customizer.
190
	// See https://make.wordpress.org/core/2016/03/22/implementing-selective-refresh-support-for-widgets/ for detail.
191
	add_theme_support( 'customize-selective-refresh-widgets' );
192
endif; // strip_setup.
193
add_action( 'after_setup_theme', 'strip_setup' );
194
195
/**
196
 * Register widgetized area and update sidebar with default widgets
197
 */
198
function strip_widgets_init() {
199
	register_sidebar(array(
200
		'name'          => __( 'Main Sidebar', 'strip' ),
201
		'id'            => 'sidebar',
202
		'description'   => __( 'The main body widget area', 'strip' ),
203
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
204
		'after_widget'	=> '</aside>',
205
		'before_title'	=> '<h2 class="widget-title">',
206
		'after_title'   => '</h2>',
207
	));
208
209
	// First footer widget area, located in the footer. Empty by default.
210
	register_sidebar( array(
211
		'name'          => __( 'First Footer Widget', 'strip' ),
212
		'id'            => 'first-footer-widget',
213
		'description'   => __( 'The first footer widget', 'strip' ),
214
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
215
		'after_widget'	=> '</aside>',
216
		'before_title'	=> '<h3 class="widget-title">',
217
		'after_title'   => '</h3>',
218
	));
219
220
	// Second Footer Widget Area, located in the footer. Empty by default.
221
	register_sidebar(array(
222
		'name'          => __( 'Second Footer Widget', 'strip' ),
223
		'id'            => 'second-footer-widget',
224
		'description'   => __( 'The second footer widget', 'strip' ),
225
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
226
		'after_widget'	=> '</aside>',
227
		'before_title'	=> '<h3 class="widget-title">',
228
		'after_title'   => '</h3>',
229
	));
230
231
	// Third Footer Widget Area, located in the footer. Empty by default.
232
	register_sidebar(array(
233
		'name'          => __( 'Third Footer Widget', 'strip' ),
234
		'id'            => 'third-footer-widget',
235
		'description'   => __( 'The third footer widget', 'strip' ),
236
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
237
		'after_widget'	=> '</aside>',
238
		'before_title'	=> '<h3 class="widget-title">',
239
		'after_title'   => '</h3>',
240
	));
241
242
	// Fourth Footer Widget Area, located in the footer. Empty by default.
243
	register_sidebar(array(
244
		'name'           => __( 'Fourth Footer Widget', 'strip' ),
245
		'id'             => 'fourth-footer-widget',
246
		'description'    => __( 'The fourth footer widget', 'strip' ),
247
		'before_widget'  => '<aside id="%1$s" class="widget %2$s">',
248
		'after_widget'	 => '</aside>',
249
		'before_title'	 => '<h3 class="widget-title">',
250
		'after_title'    => '</h3>',
251
	));
252
253
}
254
add_action( 'widgets_init', 'strip_widgets_init' );
255
256
/**
257
 * Handles JavaScript detection.
258
 *
259
 * Adds a `js` class to the root `<html>` element when JavaScript is detected.
260
 *
261
 * @since Strip 1.0
262
 */
263
function strip_javascript_detection() {
264
	echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n";
265
}
266
add_action( 'wp_head', 'strip_javascript_detection', 0 );
267
268
/**
269
 * Enqueue_styles for custom fonts.
270
 */
271
function strip_scripts() {
272
	// add custom font here if any.
273
	wp_enqueue_style( 'fenix', get_template_directory_uri() . '/assets/fonts/fenix.css', array(), null );
274
275
	wp_enqueue_style( 'inconsolata', get_template_directory_uri() . '/assets/fonts/inconsolata.css', array(), null );
276
277
	// Theme stylesheet.
278
	wp_enqueue_style( 'strip-style', get_stylesheet_uri() );
279
280
	// Load the Internet Explorer specific stylesheet. Conditional stylesheet — tested and works with IE9 on Windows7.
281
	wp_enqueue_style( 'strip-ie', get_template_directory_uri() . 'assets/css/ie.css', array( 'strip-style' ), '20160305' );
282
	wp_style_add_data( 'strip-ie', 'conditional', 'lt IE 10' );
283
284
	if ( has_nav_menu( 'primary' ) ) {
285
		wp_enqueue_script( 'strip-navigation', get_template_directory_uri() . '/assets/js/min/navigation-min.js', array(), '1.0', true );
286
	}
287
288
	// Load the html5 shiv.
289
	wp_enqueue_script( 'strip-html5', get_template_directory_uri() . '/assets/js/min/html5-min.js', array(), '3.7.3' );
290
	wp_script_add_data( 'strip-html5', 'conditional', 'lt IE 9' );
291
292
	wp_enqueue_script( 'strip-skip-link-focus-fix', get_template_directory_uri() . '/assets/js/min/skip-link-focus-fix-min.js', array(), '1.0', true );
293
294
	// toggle comments js.
295
	wp_enqueue_script( 'strip-toggle-comments', get_template_directory_uri() . '/assets/js/min/toggle-comments-min.js', array( 'jquery' ), '1.2', true );
296
297
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
298
		wp_enqueue_script( 'comment-reply' );
299
300
		if ( is_single() && wp_attachment_is_image() ) {
301
			wp_enqueue_script( 'strip-keyboard-image-navigation', get_template_directory_uri() . '/assets/js/min/keyboard-image-navigation-min.js', array( 'jquery' ), '20160412', true );
302
		}
303
	}
304
}
305
306
add_action( 'wp_enqueue_scripts', 'strip_scripts' );
307
308
/**
309
 * Implement the Custom Header feature.
310
 */
311
require get_template_directory() . '/inc/custom-header.php';
312
313
/**
314
 * Custom template tags for this theme.
315
 */
316
require get_template_directory() . '/inc/template-tags.php';
317
318
/**
319
 * Custom functions that act independently of the theme templates.
320
 */
321
require get_template_directory() . '/inc/extras.php';
322
323
/**
324
 * Customizer additions.
325
 */
326
require get_template_directory() . '/inc/customizer.php';
327
328
/**
329
 * Load Jetpack compatibility file.
330
 */
331
require get_template_directory() . '/inc/jetpack.php';
332
333
add_action( 'wp_enqueue_scripts', 'enqueue_royal_sliders' );
334
/**
335
 * Register RoyalSLider
336
 */
337
function enqueue_royal_sliders() {
338
	if ( function_exists( 'register_new_royalslider_files' ) ) {
339
		// you could try this: if ( is_single() && is_archive() ) { but you don't really need it.
340
			register_new_royalslider_files( 1 ); // place register_new_royalslider_files function here, 1 is your slider's configuration number
341
		// add } if use is_single etc.
342
	}
343
}
344
345
/**
346
 * Get the first image from each post and resize it.
347
 *
348
 * @return string $first_img.
349
 * @link https://css-tricks.com/snippets/wordpress/get-the-first-image-from-a-post/
350
 * @link https://gist.github.com/SilentComics/0a7ea47942eb759dbb48eac2b7be1bbc/
351
 */
352
function get_first_image() {
353
	global $post;
354
	$first_img = '';
355
	preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', do_shortcode( $post->post_content, 'gallery' ), $matches );
356
	  $first_img = isset( $matches[1][0] ) ? $matches[1][0] : null;
357
358
	if ( empty( $first_img ) ) {
359
			return get_template_directory_uri() . '/assets/images/empty.png'; // path to default image.
360
	}
361
362
		// Now we have the $first_img but we want the thumbnail of that image.
363
		$explode = explode( '.', $first_img );
364
		$count = count( $explode );
365
		$size = '-624x312'; // Panel ratio (2:1) 312x156 for lighther page, 624x312 for retina; use add_image_size() and Force Regenerate Thumbnails plugin when changing sizes.
366
		$explode[ $count -2 ] = $explode[ $count -2 ] . '' . $size;
367
		$thumb_img = implode( '.', $explode );
368
		return $thumb_img;
369
}
370
	add_filter( 'get_first_image', 'thumbnail' );
371
372
/**
373
 * Register Custom Post Type for comics
374
 */
375
function comic_post_type() {
376
377
	$labels = array(
378
		'name'                       => _x( 'Comics', 'Post Type General Name', 'strip' ),
379
		'singular_name'              => _x( 'Comic', 'Post Type Singular Name', 'strip' ),
380
		'menu_name'                  => _x( 'Comics', 'admin menu', 'strip' ),
381
		'name_admin_bar'             => _x( 'Comic', 'add new on admin bar', 'strip' ),
382
		'parent_item_colon'	         => __( 'Parent Comic:', 'strip' ),
383
		'all_items'                  => __( 'All Comics', 'strip' ),
384
		'add_new_item'               => __( 'Add New Comic', 'strip' ),
385
		'add_new'                    => __( 'Add New Comic', 'strip' ),
386
		'new_item'                   => __( 'New Comic', 'strip' ),
387
		'edit_item'                  => __( 'Edit Comic', 'strip' ),
388
		'update_item'                => __( 'Update Comic', 'strip' ),
389
		'view_item'                  => __( 'View Comic', 'strip' ),
390
		'search_items'               => __( 'Search Item', 'strip' ),
391
		'not_found'                  => __( 'No Comics found', 'strip' ),
392
		'not_found_in_trash'         => __( 'No Comics found in Trash', 'strip' ),
393
		'items_list'                 => __( 'Comics list', 'strip' ),
394
		'items_list_navigation'      => __( 'Comics list navigation', 'strip' ),
395
		'filter_items_list'          => __( 'Filter Comics list', 'strip' ),
396
	);
397
398
	$supports = array(
399
	'title',
400
	'editor',
401
	'excerpt',
402
	'trackbacks',
403
	'custom-fields',
404
	'comments',
405
	'revisions',
406
	'thumbnail',
407
	'author',
408
	'archive',
409
	);
410
411
	$args = array(
412
		'label'                      => __( 'Comic', 'strip' ),
413
		'description'                => __( 'Publish Comics and Webcomics', 'strip' ),
414
		'labels'                     => $labels,
415
		'supports'                   => $supports,
416
		'taxonomies'                 => array( 'story', 'story_term', 'draft' ),
417
		'hierarchical'               => true,
418
		'public'                     => true,
419
		'show_ui'                    => true,
420
		'show_in_menu'               => true,
421
		'menu_position'              => 20,
422
		'menu_icon'                  => 'dashicons-book-alt',
423
		'show_in_admin_bar'	         => true,
424
		'show_in_nav_menus'	         => true,
425
		'can_export'                 => true,
426
		'has_archive'                => true,
427
		'feeds'                      => true,
428
		'exclude_from_search'        => false,
429
		'rewrite'                    => array( 'slug' => 'stories', 'with_front' => true ),
430
		'publicly_queryable'	       => true,
431
		'capability_type'            => 'post',
432
	);
433
	register_post_type( 'comic', $args );
434
}
435
436
// Hook into the 'init' action.
437
add_action( 'init', 'comic_post_type', 0 ); // End of register_cpt_comic().
438
439
	/**
440
	 * Register Custom Taxonomy 'story'
441
	 */
442
function comic_story_taxonomy() {
443
	$labels = array(
444
		'name'                       => _x( 'Comic Story', 'Taxonomy General Name', 'strip' ),
445
		'singular_name'              => _x( 'Comic Story', 'Taxonomy Singular Name', 'strip' ),
446
		'menu_name'                  => __( 'Comic Stories', 'strip' ),
447
		'all_items'                  => __( 'All Comic Stories', 'strip' ),
448
		'parent_item'                => __( 'Parent Story', 'strip' ),
449
		'parent_item_colon'          => __( 'Parent Story:', 'strip' ),
450
		'new_item_name'              => __( 'New Comic Story', 'strip' ),
451
		'add_new_item'               => __( 'Add New Story', 'strip' ),
452
		'edit_item'                  => __( 'Edit Story', 'strip' ),
453
		'update_item'                => __( 'Update Story', 'strip' ),
454
		'view_item'                  => __( 'View Item', 'strip' ),
455
		'separate_items_with_commas' => __( 'Separate stories with commas', 'strip' ),
456
		'add_or_remove_items'        => __( 'Add or Remove Stories', 'strip' ),
457
		'choose_from_most_used'      => __( 'Choose from the most used stories', 'strip' ),
458
		'popular_items'              => __( 'Popular comic stories', 'strip' ),
459
		'search_items'               => __( 'Search Stories', 'strip' ),
460
		'not_found'                  => __( 'No comic Stories found', 'strip' ),
461
		'items_list'                 => __( 'Comic Stories list', 'strip' ),
462
		'items_list_navigation'      => __( 'Comic Stories list navigation', 'strip' ),
463
	);
464
	$args = array(
465
		'labels'                     => $labels,
466
		'label'                      => 'Stories',
467
		'hierarchical'               => true,
468
		'public'                     => true,
469
		'show_ui'                    => true,
470
		'show_admin_column'          => true,
471
		'show_in_nav_menus'          => true,
472
		'show_tagcloud'              => true,
473
		'query_var'	                 => true,
474
		'rewrite'                    => array( 'slug' => 'story' ),
475
	);
476
	register_taxonomy( 'story', array( 'comic' ), $args );
477
	register_taxonomy_for_object_type( 'story', 'comic' );
478
}
479
480
// Hook into the 'init' action.
481
add_action( 'init', 'comic_story_taxonomy', 0 );
482
483
/**
484
 * Function strip rewrite rules.
485
 */
486
function strip_rewrite_rules() {
487
	flush_rewrite_rules();
488
}
489
/* Flush rewrite rules for custom post types. */
490
add_action( 'after_switch_theme', 'strip_rewrite_rules' );
491
492
// Add Print taxonomy, NOT hierarchical (like tags)
493
// Register Custom Taxonomy.
494
	$labels = array(
495
		'name'                       => _x( 'Prints', 'Taxonomy General Name', 'strip' ),
496
		'singular_name'              => _x( 'Print', 'Taxonomy Singular Name', 'strip' ),
497
		'menu_name'                  => __( 'Print', 'strip' ),
498
		'all_items'                  => __( 'All Prints', 'strip' ),
499
		'parent_item'                => __( 'Parent Print', 'strip' ),
500
		'parent_item_colon'          => __( 'Parent Print:', 'strip' ),
501
		'new_item_name'              => __( 'New Print Name', 'strip' ),
502
		'add_new_item'               => __( 'Add New Print', 'strip' ),
503
		'edit_item'                  => __( 'Edit Print', 'strip' ),
504
		'update_item'                => __( 'Update Pring', 'strip' ),
505
		'view_item'                  => __( 'View Print', 'strip' ),
506
		'separate_items_with_commas' => __( 'Separate prints with commas', 'strip' ),
507
		'add_or_remove_items'        => __( 'Add or remove prints', 'strip' ),
508
		'choose_from_most_used'      => __( 'Choose from the most used', 'strip' ),
509
		'popular_items'              => __( 'Popular Prints', 'strip' ),
510
		'search_items'               => __( 'Search Prints', 'strip' ),
511
		'not_found'                  => __( 'Not Found', 'strip' ),
512
		'no_terms'                   => __( 'No prints', 'strip' ),
513
		'items_list'                 => __( 'Prints list', 'strip' ),
514
		'items_list_navigation'      => __( 'Prints list navigation', 'strip' ),
515
	);
516
517
	$args = array(
518
		'labels'                     => $labels,
519
		'hierarchical'               => false,
520
		'public'                     => true,
521
		'show_ui'                    => true,
522
		'show_admin_column'          => true,
523
		'show_in_nav_menus'          => true,
524
		'show_tagcloud'              => true,
525
	);
526
	register_taxonomy( 'print', array( 'comic' ), $args );
527
528
	/*
529
	* WooCommerce Hooks
530
	* Layout
531
	*/
532
	remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 );
533
	remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
534
	remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
535
	remove_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 10 );
536
	remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
537
	remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
538
539
	add_action( 'woocommerce_before_main_content', 'strip_wrapper_start', 10 );
540
	add_action( 'woocommerce_after_main_content', 'strip_wrapper_end', 10 );
541
542
		 /**
543
		  * WooCommerce wrapper
544
		  */
545
	function strip_wrapper_start() {
546
		echo '<section id="content" class="woocommerce-content" role="main"><div class="entry-wrap wrap clear">';
547
	}
548
549
	/**
550
	 * End WooCommerce wrapper
551
	 */
552
	function strip_wrapper_end() {
553
		echo '</section>';
554
	}
555
556
	add_action( 'after_setup_theme', 'woocommerce_support' );
557
	/**
558
	 * Add WooCommerce support
559
	 * https://docs.woothemes.com/document/third-party-custom-theme-compatibility/*
560
	 */
561
	function woocommerce_support() {
562
		add_theme_support( 'woocommerce' );
563
	}
564
565
	/**
566
	 * Enqueue the theme's own style for WooCommerce.
567
	 */
568
	function wp_enqueue_woocommerce_style() {
569
570
			wp_register_style( 'strip-woocommerce', get_template_directory_uri() . '/assets/css/woocommerce-min.css' );
571
		if ( class_exists( 'woocommerce' ) ) {
572
			wp_enqueue_style( 'strip-woocommerce' );
573
		}
574
	}
575
576
	add_action( 'wp_enqueue_scripts', 'wp_enqueue_woocommerce_style' );
577
578
	/**
579
* Optimize WooCommerce Scripts
580
* Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
581
*
582
* @link http://gregrickaby.com/remove-woocommerce-styles-and-scripts/
583
* @link https://wordimpress.com/how-to-load-woocommerce-scripts-and-styles-only-in-shop/
584
* @link https://gist.github.com/DevinWalker/7621777
585
* @link http://dessky.com/blog/disable-woocommerce-scripts-and-styles/
586
*/
587
	add_action( 'wp_enqueue_scripts', 'strip_manage_woocommerce_styles', 99 );
588
589
	/**
590
	 * Remove some WooCommerce queries.
591
	 */
592
	function strip_manage_woocommerce_styles() {
593
		// remove generator meta tag.
594
		remove_action( 'wp_head', array( 'woocommerce', 'generator' ) ); // this line when used with $GLOBALS['woocommerce'] prompts an error when Woo is deactivated though.
595
		// first check that woo exists to prevent fatal errors.
596
		if ( function_exists( 'strip_is_woocommerce_activated' ) ) {
597
			// dequeue scripts and styles, unless we're in the store.
598
			if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
599
				wp_dequeue_style( 'woocommerce_frontend_styles' );
600
				wp_dequeue_style( 'woocommerce-general' );
601
				wp_dequeue_style( 'woocommerce-layout' );
602
				wp_dequeue_style( 'woocommerce-smallscreen' );
603
				wp_dequeue_style( 'woocommerce_fancybox_styles' );
604
				wp_dequeue_style( 'woocommerce_chosen_styles' );
605
				wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
606
				wp_dequeue_style( 'select2' );
607
				wp_dequeue_style( 'strip-woocommerce' ); // the theme's CSS overwrite.
608
				wp_dequeue_script( 'wc-add-payment-method' );
609
				wp_dequeue_script( 'wc-lost-password' );
610
				wp_dequeue_script( 'wc_price_slider' );
611
				wp_dequeue_script( 'wc-single-product' );
612
				wp_dequeue_script( 'wc-add-to-cart' );
613
				wp_dequeue_script( 'wc-cart-fragments' );
614
				wp_dequeue_script( 'wc-credit-card-form' );
615
				wp_dequeue_script( 'wc-checkout' );
616
				wp_dequeue_script( 'wc-add-to-cart-variation' );
617
				wp_dequeue_script( 'wc-single-product' );
618
				wp_dequeue_script( 'wc-cart' );
619
				wp_dequeue_script( 'wc-chosen' );
620
				wp_dequeue_script( 'woocommerce' );
621
				wp_dequeue_script( 'jquery-cookie' );
622
				wp_dequeue_script( 'prettyPhoto' );
623
				wp_dequeue_script( 'prettyPhoto-init' );
624
				wp_dequeue_script( 'jquery-blockui' );
625
				wp_dequeue_script( 'jquery-placeholder' );
626
				wp_dequeue_script( 'jquery-payment' );
627
				wp_dequeue_script( 'fancybox' );
628
				wp_dequeue_script( 'jqueryui' );
629
			}
630
		}
631
	}
632
633
	add_action( 'pre_get_posts', 'strip_set_posts_per_page' );
634
	/**
635
	 * Set posts, WooCommerce products & comics number per archive page
636
	 * Fixes 404 error on pagination due to CTP conflicting with WordPress posts_per_page default
637
	 * see http://wordpress.stackexchange.com/questions/30757/change-posts-per-page-count/30763#30763
638
	 *
639
	 * @param WP_Query $query strip_set_posts_per_page.
640
	 * @return $query
641
	 */
642
	function strip_set_posts_per_page( $query ) {
643
		global $wp_the_query;
644
		if ( $wp_the_query-> is_home() && $wp_the_query-> is_search() ) {
645
			$query->set( 'post_type', array( 'post', 'comic', 'posts_per_page', 12 ) );
646
		}
647
		if ( $wp_the_query-> is_post_type_archive( 'product' ) ) {
648
			$query->set( 'posts_per_page', 4 );
649
		} elseif ( ( $query === $wp_the_query ) && ( is_archive() ) && ( is_tax( 'story' ) ) ) {
650
			$query->set( 'posts_per_page', 3 );
651
		}
652
		return;
653
	}
654
655
	add_action( 'pre_get_posts', 'strip_set_posts_per_page' );
656
657
	/**
658
	 * Show comics post types on home page.
659
	 *
660
	 * @param string $query add_comic_post_types_to_query.
661
	 */
662
	function add_comic_post_type_to_query( $query ) {
663
		if ( $query->is_home() && $query->is_main_query() ) {
0 ignored issues
show
The method is_home cannot be called on $query (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
The method is_main_query cannot be called on $query (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
664
			$query->set( 'post_type', array( 'post', 'comic' ) );
665
		}
666
	}
667
	add_action( 'pre_get_posts', 'add_comic_post_type_to_query' );
668
669
	/**
670
	 * Set an automatic default custom taxonomy for comic posts.
671
	 *
672
	 * When no "story" (taxonomy) is set, comic posts default to “draft”.
673
	 *
674
	 * @param	string $post_id set_default_object_terms.
675
	 * @param	string $post set_default_object_terms.
676
	 */
677
	function set_default_object_terms( $post_id, $post ) {
678
		if ( 'publish' === $post->post_status && 'comic' === $post->post_type ) {
679
			$defaults = array(
680
			'story' => array( 'draft' ),
681
			);
682
			$taxonomies = get_object_taxonomies( $post->post_type );
683
			foreach ( (array) $taxonomies as $taxonomy ) {
684
				$terms = get_the_terms( $post_id, $taxonomy );
685
				if ( empty( $terms ) && array_key_exists( $taxonomy, $defaults ) ) {
686
					wp_set_object_terms( $post_id, $defaults[ $taxonomy ], $taxonomy );
687
				}
688
			}
689
		}
690
	}
691
	add_action( 'save_post', 'set_default_object_terms', 0, 2 );
692
693
	/**
694
	 * Remove jquery migrate $scripts for enhanced performance.
695
	 *
696
	 * @param strings $scripts remove_jquery_migrate.
697
	 */
698
	function remove_jquery_migrate( $scripts ) {
699
		if ( is_admin() ) {
700
			return;
701
		}
702
		 $scripts->remove( 'jquery' );
703
		 $scripts->add( 'jquery', false, array( 'jquery-core' ), '1.10.2' );
704
	}
705
		add_action( 'wp_default_scripts', 'remove_jquery_migrate' );
706
707
		/**
708
		 * Remove login errors notices (security)
709
		 */
710
	function no_wordpress_errors() {
711
		return 'Something is wrong!';
712
	}
713
		add_filter( 'login_errors', 'no_wordpress_errors' );
714