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