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