Passed
Push — master ( ba123f...02d6c9 )
by SILENT
02:25
created

functions.php ➔ strip_remove_rss_version()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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( 'stri-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 $strings $content filter_ptags_on_images.
0 ignored issues
show
Documentation introduced by
The doc-type $strings could not be parsed: Unknown type name "$strings" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
76
		 * @link https://css-tricks.com/snippets/wordpress/remove-paragraph-tags-from-around-images/
77
		 * http://codex.wordpress.org/Function_Reference/wpautop gets the same result but also removes line blocks: remove_filter( 'the_content', 'wpautop' );
78
		 */
79
		function filter_ptags_on_images( $content ) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

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