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