SilentComics /
Strip
| 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 | function get_first_image() { |
||
| 293 | $post = get_post(); |
||
| 294 | $first_img = ''; |
||
| 295 | preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', do_shortcode( $post->post_content, 'gallery' ), $matches ); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 296 | $first_img = isset( $matches[1][0] ) ? $matches[1][0] : null; |
||
| 297 | |||
| 298 | if ( empty( $first_img ) ) { |
||
| 299 | return get_template_directory_uri() . '/assets/images/empty.png'; // path to default image. |
||
| 300 | } |
||
| 301 | |||
| 302 | // Now we have the $first_img but we want the thumbnail of that image. |
||
| 303 | $explode = explode( '.', $first_img ); |
||
| 304 | $count = count( $explode ); |
||
| 305 | $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. |
||
| 306 | $explode[ $count -2 ] = $explode[ $count -2 ] . '' . $size; |
||
| 307 | $thumb_img = implode( '.', $explode ); |
||
| 308 | return $thumb_img; |
||
| 309 | } |
||
| 310 | add_filter( 'get_first_image', 'thumbnail' ); |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Register Custom Post Type for comics with REST API support |
||
| 314 | */ |
||
| 315 | function comic_post_type() { |
||
| 316 | |||
| 317 | $labels = array( |
||
| 318 | 'name' => _x( 'Comics', 'Post Type General Name', 'strip' ), |
||
| 319 | 'singular_name' => _x( 'Comic', 'Post Type Singular Name', 'strip' ), |
||
| 320 | 'menu_name' => _x( 'Comics', 'admin menu', 'strip' ), |
||
| 321 | 'name_admin_bar' => _x( 'Comic', 'add new on admin bar', 'strip' ), |
||
| 322 | 'parent_item_colon' => __( 'Parent Comic:', 'strip' ), |
||
| 323 | 'all_items' => __( 'All Comics', 'strip' ), |
||
| 324 | 'add_new_item' => __( 'Add New Comic', 'strip' ), |
||
| 325 | 'add_new' => __( 'Add New Comic', 'strip' ), |
||
| 326 | 'new_item' => __( 'New Comic', 'strip' ), |
||
| 327 | 'edit_item' => __( 'Edit Comic', 'strip' ), |
||
| 328 | 'update_item' => __( 'Update Comic', 'strip' ), |
||
| 329 | 'view_item' => __( 'View Comic', 'strip' ), |
||
| 330 | 'search_items' => __( 'Search Item', 'strip' ), |
||
| 331 | 'not_found' => __( 'No Comics found', 'strip' ), |
||
| 332 | 'not_found_in_trash' => __( 'No Comics found in Trash', 'strip' ), |
||
| 333 | 'items_list' => __( 'Comics list', 'strip' ), |
||
| 334 | 'items_list_navigation' => __( 'Comics list navigation', 'strip' ), |
||
| 335 | 'filter_items_list' => __( 'Filter Comics list', 'strip' ), |
||
| 336 | ); |
||
| 337 | |||
| 338 | $supports = array( |
||
| 339 | 'gutenberg', // see https://github.com/WordPress/gutenberg/issues/2457 |
||
| 340 | 'title', |
||
| 341 | 'editor', |
||
| 342 | 'excerpt', |
||
| 343 | 'trackbacks', |
||
| 344 | 'custom-fields', |
||
| 345 | 'comments', |
||
| 346 | 'revisions', |
||
| 347 | 'thumbnail', |
||
| 348 | 'author', |
||
| 349 | 'archive', |
||
| 350 | ); |
||
| 351 | |||
| 352 | $args = array( |
||
| 353 | 'label' => __( 'Comic', 'strip' ), |
||
| 354 | 'description' => __( 'Publish Comics and Webcomics', 'strip' ), |
||
| 355 | 'labels' => $labels, |
||
| 356 | 'supports' => $supports, |
||
| 357 | 'taxonomies' => array( 'story', 'story_term', 'draft' ), |
||
| 358 | 'hierarchical' => true, |
||
| 359 | 'public' => true, |
||
| 360 | 'show_in_rest' => true, |
||
| 361 | 'rest_base' => 'comics', |
||
| 362 | 'rest_controller_class' => 'WP_REST_Posts_Controller', |
||
| 363 | 'show_ui' => true, |
||
| 364 | 'show_in_menu' => true, |
||
| 365 | 'menu_position' => 20, |
||
| 366 | 'menu_icon' => 'dashicons-book-alt', |
||
| 367 | 'show_in_admin_bar' => true, |
||
| 368 | 'show_in_nav_menus' => true, |
||
| 369 | 'can_export' => true, |
||
| 370 | 'has_archive' => true, |
||
| 371 | 'feeds' => true, |
||
| 372 | 'exclude_from_search' => false, |
||
| 373 | 'rewrite' => array( 'slug' => 'stories', 'with_front' => true ), |
||
| 374 | 'publicly_queryable' => true, |
||
| 375 | 'capability_type' => 'post', |
||
| 376 | ); |
||
| 377 | register_post_type( 'comic', $args ); |
||
| 378 | } |
||
| 379 | |||
| 380 | // Hook into the 'init' action. |
||
| 381 | add_action( 'init', 'comic_post_type', 0 ); // End of register_cpt_comic(). |
||
| 382 | |||
| 383 | /** |
||
| 384 | * Register Custom Taxonomy 'story' with REST API support |
||
| 385 | */ |
||
| 386 | function comic_story_taxonomy() { |
||
| 387 | $labels = array( |
||
| 388 | 'name' => _x( 'Comic Story', 'Taxonomy General Name', 'strip' ), |
||
| 389 | 'singular_name' => _x( 'Comic Story', 'Taxonomy Singular Name', 'strip' ), |
||
| 390 | 'menu_name' => __( 'Comic Stories', 'strip' ), |
||
| 391 | 'all_items' => __( 'All Comic Stories', 'strip' ), |
||
| 392 | 'parent_item' => __( 'Parent Story', 'strip' ), |
||
| 393 | 'parent_item_colon' => __( 'Parent Story:', 'strip' ), |
||
| 394 | 'new_item_name' => __( 'New Comic Story', 'strip' ), |
||
| 395 | 'add_new_item' => __( 'Add New Story', 'strip' ), |
||
| 396 | 'edit_item' => __( 'Edit Story', 'strip' ), |
||
| 397 | 'update_item' => __( 'Update Story', 'strip' ), |
||
| 398 | 'view_item' => __( 'View Item', 'strip' ), |
||
| 399 | 'separate_items_with_commas' => __( 'Separate stories with commas', 'strip' ), |
||
| 400 | 'add_or_remove_items' => __( 'Add or Remove Stories', 'strip' ), |
||
| 401 | 'choose_from_most_used' => __( 'Choose from the most used stories', 'strip' ), |
||
| 402 | 'popular_items' => __( 'Popular comic stories', 'strip' ), |
||
| 403 | 'search_items' => __( 'Search Stories', 'strip' ), |
||
| 404 | 'not_found' => __( 'No comic Stories found', 'strip' ), |
||
| 405 | 'items_list' => __( 'Comic Stories list', 'strip' ), |
||
| 406 | 'items_list_navigation' => __( 'Comic Stories list navigation', 'strip' ), |
||
| 407 | ); |
||
| 408 | $args = array( |
||
| 409 | 'labels' => $labels, |
||
| 410 | 'label' => 'Stories', |
||
| 411 | 'hierarchical' => true, |
||
| 412 | 'public' => true, |
||
| 413 | 'show_ui' => true, |
||
| 414 | 'show_admin_column' => true, |
||
| 415 | 'show_in_nav_menus' => true, |
||
| 416 | 'show_tagcloud' => true, |
||
| 417 | 'query_var' => true, |
||
| 418 | 'rewrite' => array( 'slug' => 'story' ), |
||
| 419 | 'show_in_rest' => true, |
||
| 420 | 'rest_base' => 'genre', |
||
| 421 | 'rest_controller_class' => 'WP_REST_Terms_Controller', |
||
| 422 | ); |
||
| 423 | register_taxonomy( 'story', array( 'comic' ), $args ); |
||
| 424 | register_taxonomy_for_object_type( 'story', 'comic' ); |
||
| 425 | } |
||
| 426 | |||
| 427 | // Hook into the 'init' action. |
||
| 428 | add_action( 'init', 'comic_story_taxonomy', 0 ); |
||
| 429 | |||
| 430 | /** |
||
| 431 | * Function strip rewrite rules. |
||
| 432 | */ |
||
| 433 | function strip_rewrite_rules() { |
||
| 434 | flush_rewrite_rules(); |
||
| 435 | } |
||
| 436 | /* Flush rewrite rules for custom post types. */ |
||
| 437 | add_action( 'after_switch_theme', 'strip_rewrite_rules' ); |
||
| 438 | |||
| 439 | // Add Print taxonomy, NOT hierarchical (like tags) |
||
| 440 | // Register Custom Taxonomy. |
||
| 441 | $labels = array( |
||
| 442 | 'name' => _x( 'Prints', 'Taxonomy General Name', 'strip' ), |
||
| 443 | 'singular_name' => _x( 'Print', 'Taxonomy Singular Name', 'strip' ), |
||
| 444 | 'menu_name' => __( 'Print', 'strip' ), |
||
| 445 | 'all_items' => __( 'All Prints', 'strip' ), |
||
| 446 | 'parent_item' => __( 'Parent Print', 'strip' ), |
||
| 447 | 'parent_item_colon' => __( 'Parent Print:', 'strip' ), |
||
| 448 | 'new_item_name' => __( 'New Print Name', 'strip' ), |
||
| 449 | 'add_new_item' => __( 'Add New Print', 'strip' ), |
||
| 450 | 'edit_item' => __( 'Edit Print', 'strip' ), |
||
| 451 | 'update_item' => __( 'Update Pring', 'strip' ), |
||
| 452 | 'view_item' => __( 'View Print', 'strip' ), |
||
| 453 | 'separate_items_with_commas' => __( 'Separate prints with commas', 'strip' ), |
||
| 454 | 'add_or_remove_items' => __( 'Add or remove prints', 'strip' ), |
||
| 455 | 'choose_from_most_used' => __( 'Choose from the most used', 'strip' ), |
||
| 456 | 'popular_items' => __( 'Popular Prints', 'strip' ), |
||
| 457 | 'search_items' => __( 'Search Prints', 'strip' ), |
||
| 458 | 'not_found' => __( 'Not Found', 'strip' ), |
||
| 459 | 'no_terms' => __( 'No prints', 'strip' ), |
||
| 460 | 'items_list' => __( 'Prints list', 'strip' ), |
||
| 461 | 'items_list_navigation' => __( 'Prints list navigation', 'strip' ), |
||
| 462 | ); |
||
| 463 | |||
| 464 | $args = array( |
||
| 465 | 'labels' => $labels, |
||
| 466 | 'hierarchical' => false, |
||
| 467 | 'public' => true, |
||
| 468 | 'show_ui' => true, |
||
| 469 | 'show_admin_column' => true, |
||
| 470 | 'show_in_nav_menus' => true, |
||
| 471 | 'show_tagcloud' => true, |
||
| 472 | ); |
||
| 473 | register_taxonomy( 'print', array( 'comic' ), $args ); |
||
| 474 | |||
| 475 | /* |
||
| 476 | * WooCommerce Hooks |
||
| 477 | * Layout |
||
| 478 | */ |
||
| 479 | remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 ); |
||
| 480 | remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 ); |
||
| 481 | remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 ); |
||
| 482 | // remove_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 10 ); // removes woo pagination. |
||
| 483 | remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 ); |
||
| 484 | remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 ); |
||
| 485 | |||
| 486 | add_action( 'woocommerce_before_main_content', 'strip_wrapper_start', 10 ); |
||
| 487 | add_action( 'woocommerce_after_main_content', 'strip_wrapper_end', 10 ); |
||
| 488 | |||
| 489 | /** |
||
| 490 | * WooCommerce wrapper |
||
| 491 | */ |
||
| 492 | function strip_wrapper_start() { |
||
| 493 | echo '<section id="content" class="woocommerce-content" role="main"><div class="entry-wrap wrap clear">'; |
||
| 494 | } |
||
| 495 | |||
| 496 | /** |
||
| 497 | * End WooCommerce wrapper |
||
| 498 | */ |
||
| 499 | function strip_wrapper_end() { |
||
| 500 | echo '</section>'; |
||
| 501 | } |
||
| 502 | |||
| 503 | add_action( 'after_setup_theme', 'woocommerce_support' ); |
||
| 504 | /** |
||
| 505 | * Add WooCommerce support |
||
| 506 | * https://docs.woothemes.com/document/third-party-custom-theme-compatibility/* |
||
| 507 | */ |
||
| 508 | function woocommerce_support() { |
||
| 509 | add_theme_support( 'woocommerce' ); |
||
| 510 | } |
||
| 511 | |||
| 512 | /** |
||
| 513 | * Enqueue the theme's own style for WooCommerce. |
||
| 514 | */ |
||
| 515 | function wp_enqueue_woocommerce_style() { |
||
| 516 | |||
| 517 | wp_register_style( 'strip-woocommerce', get_template_directory_uri() . '/assets/css/woocommerce-min.css' ); |
||
| 518 | if ( class_exists( 'woocommerce' ) ) { |
||
| 519 | wp_enqueue_style( 'strip-woocommerce' ); |
||
| 520 | } |
||
| 521 | } |
||
| 522 | |||
| 523 | add_action( 'wp_enqueue_scripts', 'wp_enqueue_woocommerce_style' ); |
||
| 524 | |||
| 525 | /** |
||
| 526 | * Optimize WooCommerce Scripts |
||
| 527 | * Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages. |
||
| 528 | * |
||
| 529 | * @link http://gregrickaby.com/remove-woocommerce-styles-and-scripts/ |
||
| 530 | * @link https://wordimpress.com/how-to-load-woocommerce-scripts-and-styles-only-in-shop/ |
||
| 531 | * @link https://gist.github.com/DevinWalker/7621777 |
||
| 532 | * @link http://dessky.com/blog/disable-woocommerce-scripts-and-styles/ |
||
| 533 | */ |
||
| 534 | add_action( 'wp_enqueue_scripts', 'strip_manage_woocommerce_styles', 99 ); |
||
| 535 | |||
| 536 | /** |
||
| 537 | * Remove some WooCommerce queries. |
||
| 538 | */ |
||
| 539 | function strip_manage_woocommerce_styles() { |
||
| 540 | // remove generator meta tag. |
||
| 541 | remove_action( 'wp_head', array( 'woocommerce', 'generator' ) ); |
||
| 542 | // first check that woo exists to prevent fatal errors. |
||
| 543 | if ( function_exists( 'strip_is_woocommerce_activated' ) ) { |
||
| 544 | // dequeue scripts and styles, unless we're in the store. |
||
| 545 | if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) { |
||
| 546 | wp_dequeue_style( 'woocommerce_frontend_styles' ); |
||
| 547 | wp_dequeue_style( 'woocommerce-general' ); |
||
| 548 | wp_dequeue_style( 'woocommerce-layout' ); |
||
| 549 | wp_dequeue_style( 'woocommerce-smallscreen' ); |
||
| 550 | wp_dequeue_style( 'woocommerce_fancybox_styles' ); |
||
| 551 | wp_dequeue_style( 'woocommerce_chosen_styles' ); |
||
| 552 | wp_dequeue_style( 'woocommerce_prettyPhoto_css' ); |
||
| 553 | wp_dequeue_style( 'select2' ); |
||
| 554 | wp_dequeue_style( 'strip-woocommerce' ); // the theme's CSS overwrite. |
||
| 555 | wp_dequeue_script( 'wc-add-payment-method' ); |
||
| 556 | wp_dequeue_script( 'wc-lost-password' ); |
||
| 557 | wp_dequeue_script( 'wc_price_slider' ); |
||
| 558 | wp_dequeue_script( 'wc-single-product' ); |
||
| 559 | wp_dequeue_script( 'wc-add-to-cart' ); |
||
| 560 | wp_dequeue_script( 'wc-cart-fragments' ); |
||
| 561 | wp_dequeue_script( 'wc-credit-card-form' ); |
||
| 562 | wp_dequeue_script( 'wc-checkout' ); |
||
| 563 | wp_dequeue_script( 'wc-add-to-cart-variation' ); |
||
| 564 | wp_dequeue_script( 'wc-single-product' ); |
||
| 565 | wp_dequeue_script( 'wc-cart' ); |
||
| 566 | wp_dequeue_script( 'wc-chosen' ); |
||
| 567 | wp_dequeue_script( 'woocommerce' ); |
||
| 568 | wp_dequeue_script( 'jquery-cookie' ); |
||
| 569 | wp_dequeue_script( 'prettyPhoto' ); |
||
| 570 | wp_dequeue_script( 'prettyPhoto-init' ); |
||
| 571 | wp_dequeue_script( 'jquery-blockui' ); |
||
| 572 | wp_dequeue_script( 'jquery-placeholder' ); |
||
| 573 | wp_dequeue_script( 'jquery-payment' ); |
||
| 574 | wp_dequeue_script( 'fancybox' ); |
||
| 575 | wp_dequeue_script( 'jqueryui' ); |
||
| 576 | } |
||
| 577 | } |
||
| 578 | } |
||
| 579 | |||
| 580 | add_action( 'pre_get_posts', 'strip_set_posts_per_page' ); |
||
| 581 | /** |
||
| 582 | * Set posts, WooCommerce products & comics number per archive page |
||
| 583 | * Fixes 404 error on pagination due to CTP conflicting with WordPress posts_per_page default |
||
| 584 | * see http://wordpress.stackexchange.com/questions/30757/change-posts-per-page-count/30763#30763 |
||
| 585 | * |
||
| 586 | * @param WP_Query $query strip_set_posts_per_page. |
||
| 587 | * @return $query |
||
| 588 | */ |
||
| 589 | function strip_set_posts_per_page( $query ) { |
||
| 590 | if ( is_post_type_archive( 'product' ) ) { |
||
| 591 | $query->set( 'posts_per_page', 4 ); |
||
| 592 | return $query; |
||
| 593 | } elseif ( is_tax( 'story' ) ) { |
||
| 594 | $query->set( 'posts_per_page', 6 ); |
||
| 595 | } |
||
| 596 | } |
||
| 597 | |||
| 598 | /** |
||
| 599 | * Show comics post types on home page (blog) and feeds. Off by default |
||
| 600 | * |
||
| 601 | * @param string $query strip_add_comics_to_blog. |
||
| 602 | */ |
||
| 603 | // function strip_add_comics_to_blog( $query ) { |
||
| 604 | // if ( is_home() && $query->is_main_query() ) { |
||
| 605 | // $query->set( 'post_type', array( 'post', 'comic' ) ); |
||
| 606 | // return $query; |
||
| 607 | // } |
||
| 608 | // } |
||
| 609 | // add_action( 'pre_get_posts', 'strip_add_comics_to_blog' ); |
||
| 610 | |||
| 611 | /** |
||
| 612 | * Set an automatic default custom taxonomy for comic posts. |
||
| 613 | * When no "story" (taxonomy) is set, comic posts default to “draft”. |
||
| 614 | * |
||
| 615 | * @param string $post_id set_default_object_terms. |
||
| 616 | * @param string $post set_default_object_terms. |
||
| 617 | */ |
||
| 618 | function set_default_object_terms( $post_id, $post ) { |
||
| 619 | if ( 'publish' === $post->post_status && 'comic' === $post->post_type ) { |
||
| 620 | $defaults = array( |
||
| 621 | 'story' => array( 'draft' ), |
||
| 622 | ); |
||
| 623 | $taxonomies = get_object_taxonomies( $post->post_type ); |
||
| 624 | foreach ( (array) $taxonomies as $taxonomy ) { |
||
| 625 | $terms = get_the_terms( $post_id, $taxonomy ); |
||
| 626 | if ( empty( $terms ) && array_key_exists( $taxonomy, $defaults ) ) { |
||
| 627 | wp_set_object_terms( $post_id, $defaults[ $taxonomy ], $taxonomy ); |
||
| 628 | } |
||
| 629 | } |
||
| 630 | } |
||
| 631 | } |
||
| 632 | add_action( 'save_post', 'set_default_object_terms', 0, 2 ); |
||
| 633 | |||
| 634 | /** |
||
| 635 | * Remove jquery migrate $scripts for enhanced performance. |
||
| 636 | * |
||
| 637 | * @param strings $scripts remove_jquery_migrate. |
||
| 638 | */ |
||
| 639 | function remove_jquery_migrate( $scripts ) { |
||
| 640 | if ( is_admin() ) { |
||
| 641 | return; |
||
| 642 | } |
||
| 643 | $scripts->remove( 'jquery' ); |
||
| 644 | $scripts->add( 'jquery', false, array( 'jquery-core' ), '1.10.2' ); |
||
| 645 | } |
||
| 646 | add_action( 'wp_default_scripts', 'remove_jquery_migrate' ); |
||
| 647 | |||
| 648 | /** |
||
| 649 | * Remove login errors notices (security) |
||
| 650 | */ |
||
| 651 | function no_wordpress_errors() { |
||
| 652 | return 'Something is wrong!'; |
||
| 653 | } |
||
| 654 | add_filter( 'login_errors', 'no_wordpress_errors' ); |
||
| 655 |