Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Jakub Kuron Core
- Description: This plugin contains PHP and Javascript custom functions needed by this page to run propertly.
- Author: RISE
- Author URI: riseproject.pl
- Version: 1.0
- */
- // Register custom menus
- function register_custom_nav_menus() {
- register_nav_menus( array(
- 'top-header-menu-left' => __( 'Top Header Menu (Left)', 'twentynineteen' ),
- 'top-header-menu-right' => __( 'Top Header Menu (Right)', 'twentynineteen' )
- ) );
- }
- add_action( 'after_setup_theme', 'register_custom_nav_menus' );
- // Remove theme menus (with priority of 20 because it have to be executed later than theme register menus (default is 10))
- function remove_theme_nav_menus() {
- unregister_nav_menu( 'menu-1' );
- unregister_nav_menu( 'footer' );
- unregister_nav_menu( 'social' );
- }
- add_action( 'after_setup_theme', 'remove_theme_nav_menus', 20 );
- // Register custom footer widgets which will be the footer columns areas
- function register_custom_footer_widget() {
- register_sidebars( 3, array(
- 'name' => __( 'Footer Column %d', 'twentynineteen' ),
- 'before_widget' => '',
- 'after_widget' => '',
- 'before_title' => '<h4>',
- 'after_title' => '</h4>'
- ) );
- }
- add_action( 'widgets_init', 'register_custom_footer_widget', 20 );
- // Remove theme footer widget
- function remove_theme_footer_widget() {
- unregister_sidebar( 'sidebar-1' );
- }
- add_action( 'widgets_init', 'remove_theme_footer_widget', 20 );
- // Load custom scripts file
- function jku_js_load() {
- wp_register_script( 'jakub-kuron-js', plugins_url( 'jakub-kuron-core.js', __FILE__ ), '', '1.0', true);
- wp_enqueue_script( 'jakub-kuron-js' );
- }
- add_action( 'wp_enqueue_scripts', 'jku_js_load' );
- // Create custom post taxonomies - categories
- function create_cpt_categories() {
- $labels = array(
- 'name' => _x( 'Kategorie przepisów', 'taxonomy general name', 'textdomain' ),
- 'singular_name' => _x( 'Kategoria przepisów', 'taxonomy singular name', 'textdomain' ),
- 'search_items' => __( 'Szukaj kategorii', 'textdomain' ),
- 'all_items' => __( 'Wszystkie kategorie', 'textdomain' ),
- 'parent_item' => __( 'Nadrzędna kategoria', 'textdomain' ),
- 'parent_item_colon' => __( 'Nadrzędna kategoria:', 'textdomain' ),
- 'edit_item' => __( 'Edytuj kategorię', 'textdomain' ),
- 'update_item' => __( 'Zaktualizuj kategorię', 'textdomain' ),
- 'add_new_item' => __( 'Dodaj nową kategorię', 'textdomain' ),
- 'new_item_name' => __( 'Dodaj nową nazwę kategorii', 'textdomain' ),
- 'menu_name' => __( 'Kategorie przepisów', 'textdomain' ),
- );
- $args = array(
- 'hierarchical' => true,
- 'labels' => $labels,
- 'show_ui' => true,
- 'public' => true,
- 'has_archive' => true,
- 'show_admin_column' => true,
- 'query_var' => true,
- 'rewrite' => array( 'slug' => 'przepisy', 'with_front' => true ),
- );
- register_taxonomy( 'kategorie-przepisow', array( 'przepisy' ), $args );
- }
- add_action( 'init', 'create_cpt_categories', 0 );
- // Create custom post taxonomies - tags
- function create_cpt_tags() {
- $labels = array(
- 'name' => _x( 'Tagi przepisów', 'taxonomy general name', 'textdomain' ),
- 'singular_name' => _x( 'Tag przepisów', 'taxonomy singular name', 'textdomain' ),
- 'search_items' => __( 'Szukaj tagów', 'textdomain' ),
- 'all_items' => __( 'Wszystkie tagi', 'textdomain' ),
- 'parent_item' => null,
- 'parent_item_colon' => null,
- 'edit_item' => __( 'Edytuj tag', 'textdomain' ),
- 'update_item' => __( 'Zaktualizuj tag', 'textdomain' ),
- 'add_new_item' => __( 'Dodaj nowy tag', 'textdomain' ),
- 'new_item_name' => __( 'Dodaj nową nazwę tagu', 'textdomain' ),
- 'menu_name' => __( 'Tagi przepisów', 'textdomain' ),
- );
- $args = array(
- 'hierarchical' => false,
- 'labels' => $labels,
- 'show_ui' => true,
- 'public' => true,
- 'show_admin_column' => true,
- 'update_count_callback' => '_update_post_term_count',
- 'query_var' => true,
- 'rewrite' => array( 'slug' => 'tagi', 'with_front' => true ),
- );
- register_taxonomy( 'tagi-przepisow', array( 'przepisy' ), $args );
- }
- add_action( 'init', 'create_cpt_tags', 0 );
- // Custom post types copied from the old site
- function create_przepis() {
- register_post_type( 'przepisy',
- array(
- 'labels' => array(
- 'name' => 'Przepisy',
- 'singular_name' => 'Przepis',
- 'add_new' => 'Dodaj nowy',
- 'add_new_item' => 'Dodaj nowy Przepis',
- 'edit' => 'Edytuj',
- 'edit_item' => 'Edytuj Przepis',
- 'new_item' => 'Nowy Przepis',
- 'view' => 'Zobacz',
- 'view_item' => 'Zobacz Przepis',
- 'search_items' => 'Szukaj Przepisów',
- 'not_found' => 'Nie znaleziono',
- 'not_found_in_trash' => 'Nie znaleziono w koszu',
- 'parent' => 'Parent Przepis'
- ),
- 'public' => true,
- 'hierarchical' => true,
- 'show_ui' => true,
- 'has_archive' => true,
- 'menu_position' => 4,
- 'supports' => array( 'title', 'editor', 'thumbnail', 'comments', 'custom-fields' ),
- 'taxonomies' => array( 'kategorie-przepisow', 'tagi-przepisow' ),
- 'rewrite' => array( 'slug' => 'przepisy/%kategorie-przepisow%', 'with_front' => true )
- )
- );
- }
- add_action( 'init', 'create_przepis' );
- function wpa_course_post_link( $post_link, $id = 0 ){
- $post = get_post($id);
- if ( is_object( $post ) ){
- $terms = wp_get_object_terms( $post->ID, 'kategorie-przepisow' );
- if( $terms ){
- return str_replace( '%kategorie-przepisow%' , $terms[0]->slug , $post_link );
- }
- }
- return $post_link;
- }
- add_filter( 'post_type_link', 'wpa_course_post_link', 1, 3 );
- /*
- function create_wideo() {
- register_post_type( 'video',
- array(
- 'labels' => array(
- 'name' => 'Wideo',
- 'singular_name' => 'Wideo',
- 'add_new' => 'Dodaj nowy',
- 'add_new_item' => 'Dodaj nowy Wideo',
- 'edit' => 'Edytuj',
- 'edit_item' => 'Edytuj Wideo',
- 'new_item' => 'Nowy Wideo',
- 'view' => 'Zobacz',
- 'view_item' => 'Zobacz Wideo',
- 'search_items' => 'Szukaj Przepisów',
- 'not_found' => 'Nie znaleziono',
- 'not_found_in_trash' => 'Nie znaleziono w koszu',
- 'parent' => 'Parent Wideo'
- ),
- 'public' => true,
- 'menu_position' => 5,
- 'supports' => array( 'title', 'editor', 'thumbnail', 'comments' ),
- 'taxonomies' => array('category', 'post_tag')
- )
- );
- }
- add_action( 'init', 'create_wideo' );
- // Unregister videos post type
- function kill_video() {
- unregister_post_type( 'video' );
- }
- add_action( 'init', 'kill_video' );
- */
- // Stop wordpress from adding p tags everywhere
- remove_filter( 'the_content', 'wpautop' );
- remove_filter( 'the_excerpt', 'wpautop' );
- // List 1st level post categories executed by the shortcode
- function cpt_categories_cloud_shortcode() {
- // Get the taxonomy's terms
- $terms = get_terms( array(
- 'taxonomy' => 'kategorie-przepisow',
- 'hide_empty' => true,
- 'parent' => 0
- ));
- // Check if any term exists
- if ( !empty( $terms ) && is_array( $terms ) ) {
- $output = '<ul class="jku-categories-cloud-wrapper">';
- foreach ( $terms as $term ) {
- $output .= '<li><a href="' . esc_url(get_term_link( $term )) . '">' . $term->name . '</a></li>';
- }
- $output .= '</ul>';
- }
- return $output;
- }
- add_shortcode( 'cpt-categories-cloud', 'cpt_categories_cloud_shortcode' );
- // List 2nd level post categories executed by the shortcode
- /*
- function cpt_categories_cloud_shortcode_children() {
- // Get the taxonomy's terms
- $terms = get_terms( array(
- 'taxonomy' => 'kategorie-przepisow',
- 'hide_empty' => true,
- 'parent' => 0
- ));
- // Check if any term exists
- if ( !empty( $terms ) && is_array( $terms ) ) {
- $output = '<ul class="jku-categories-cloud-wrapper">';
- foreach ( $terms as $term ) {
- $output .= '<li><a href="' . esc_url(get_term_link( $term )) . '">' . $term->name . '</a></li>';
- }
- $output .= '</ul>';
- }
- return $output;
- }
- add_shortcode( 'cpt-categories-cloud', 'cpt_categories_cloud_shortcode' );
- */
- // List random recipes shortcode
- function list_recipes_shortcode() {
- $args = array(
- 'post_type' => 'przepisy',
- 'orderby' => 'rand',
- 'posts_per_page' => '8',
- 'meta_query' => array(
- array(
- 'key' => '_thumbnail_id',
- 'compare' => 'EXISTS'
- )
- )
- );
- $testimonials = new WP_Query($args);
- $output = '<div class="jku-post-grid-wrapper jku-similar-posts-wrapper">';
- while ($testimonials->have_posts()) : $testimonials->the_post();
- $postid = get_the_ID();
- $output .= '<div class="jku-post-grid-item">';
- if ( has_post_thumbnail() ) {
- $output .= '<a class="jku-image-placeholder" href="' . get_permalink() . '" style="background-image: url(' . get_the_post_thumbnail_url($postid, 'full') . ');">';
- } else {
- $output .= '<a class="jku-image-placeholder" href="' . get_permalink() . '">';
- }
- if ( has_term( 'wideo', 'kategorie-przepisow' ) ) {
- $output .= '<img class="jku-video-post-icon" src="/wp-content/themes/jakub-kuron/svg/jkuron-icon-video0.svg" /></img>';
- }
- $output .= '</a>';
- $output .= '<h5 class="jku-post-grid-categories">';
- $term_list = wp_get_post_terms($postid, 'kategorie-przepisow', array("fields" => "all"));
- foreach($term_list as $term_single) {
- $output .= '<span><a href="' . esc_url(get_term_link( $term_single )) . '">' . $term_single->name . '</a></span>';
- }
- $output .= '</h5>';
- $output .= '<a class="jku-post-grid-title" href="' . get_permalink() . '">';
- $output .= '<h3>' . get_the_title() . '</h3>';
- $output .= '</a>';
- $output .= '</div>';
- endwhile;
- $output .= '</div>';
- wp_reset_postdata();
- return $output;
- }
- add_shortcode( 'list-recipes', 'list_recipes_shortcode' );
- // Enable running shortcodes in widgets
- add_filter( 'widget_text', 'do_shortcode' );
- // Change the except length
- function change_excerpt_length( $length ) {
- return 20;
- }
- add_filter( 'excerpt_length', 'change_excerpt_length', 999 );
- // Change ending of the excerpt
- function change_excerpt_more( $more ) {
- return '..';
- }
- add_filter( 'excerpt_more', 'change_excerpt_more' );
- // List posts shortcode
- function list_posts_shortcode() {
- $args = array(
- 'post_type' => 'post',
- 'orderby' => 'desc',
- 'posts_per_page' => '2',
- 'meta_query' => array(
- array(
- 'key' => '_thumbnail_id',
- 'compare' => 'EXISTS'
- )
- )
- );
- $posts = new WP_Query($args);
- $output = '<div class="jku-post-grid-items-wrapper">';
- while ($posts->have_posts()) : $posts->the_post();
- $output .= '<div class="jku-post-grid-item">';
- if ( has_post_thumbnail() ) {
- $output .= '<a class="jku-post-grid-image" href="' . get_permalink() . '">' . get_the_post_thumbnail() . '</a>';
- }
- $output .= '<h5 class="jku-post-grid-date">' . get_the_date( 'j F Y' ) . '</h5>';
- $output .= '<a class="jku-post-grid-title" href="' . get_permalink() . '"><h3>' . get_the_title() . '</h3></a>';
- $output .= '<p>' . get_the_excerpt() . '</p>';
- $output .= '</div>';
- endwhile;
- $output .= '</div>';
- wp_reset_postdata();
- return $output;
- }
- add_shortcode( 'list-posts', 'list_posts_shortcode' );
- //
- // WooCommerce functions
- //
- // Remove WooCommerce image gallery features
- function remove_zoom_lightbox_theme_support() {
- remove_theme_support( 'wc-product-gallery-zoom' );
- remove_theme_support( 'wc-product-gallery-lightbox' );
- remove_theme_support( 'wc-product-gallery-slider' );
- }
- add_action( 'after_setup_theme', 'remove_zoom_lightbox_theme_support', 100000 );
- // Remove link from single product image
- function remove_product_image_link( $html, $post_id ) {
- return preg_replace( "!<(a|/a).*?>!", '', $html );
- }
- add_filter( 'woocommerce_single_product_image_thumbnail_html', 'remove_product_image_link', 10, 2 );
- // Remove WooCommerce resources from non woocommerce pages
- function remove_woocommerce_scripts() {
- if ( function_exists( 'is_woocommerce' ) ) {
- if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
- remove_action( 'wp_enqueue_scripts', [WC_Frontend_Scripts::class, 'load_scripts'] );
- remove_action( 'wp_print_scripts', [WC_Frontend_Scripts::class, 'localize_printed_scripts'], 5 );
- remove_action( 'wp_print_footer_scripts', [WC_Frontend_Scripts::class, 'localize_printed_scripts'], 5 );
- }
- }
- }
- add_action( 'template_redirect', 'remove_woocommerce_scripts', 100000 );
- // Remove WooCommerce styles
- add_filter( 'woocommerce_enqueue_styles', '__return_false', 100000 );
- // Remove other not required styles
- function remove_other_css() {
- // WooCommerce
- wp_dequeue_style('wc-block-style');
- wp_deregister_style('wc-block-style');
- wp_dequeue_style('woocommerce-inline');
- wp_deregister_style('woocommerce-inline');
- // WP Includes
- wp_dequeue_style('wp-block-library');
- wp_deregister_style('wp-block-library');
- wp_dequeue_style('wp-block-library-theme');
- wp_deregister_style('wp-block-library-theme');
- // Twenty Nineteen print stylesheet
- wp_dequeue_style('twentynineteen-print-style');
- wp_deregister_style('twentynineteen-print-style');
- // Cookie Notice
- wp_dequeue_style('cookie-notice-front');
- wp_deregister_style('cookie-notice-front');
- // Contact Form 7
- wp_dequeue_style('contact-form-7');
- wp_deregister_style('contact-form-7');
- // Post Grid
- wp_dequeue_style('post_grid_style');
- wp_deregister_style('post_grid_style');
- wp_dequeue_style('font-awesome-5');
- wp_deregister_style('font-awesome-5');
- wp_dequeue_style('style.skins');
- wp_deregister_style('style.skins');
- wp_dequeue_style('style.layout');
- wp_deregister_style('style.layout');
- wp_dequeue_style('style.animate');
- wp_deregister_style('style.animate');
- }
- add_action( 'wp_enqueue_scripts','remove_other_css', 100000 );
- // Add custom css to WooCommerce pages
- function register_custom_woo_style() {
- if ( function_exists( 'is_woocommerce' ) ) {
- if ( is_woocommerce() || is_cart() || is_checkout() ) {
- wp_register_style( 'jkuron-woo-styles', '/wp-content/themes/jakub-kuron/woocommerce/style.css' );
- wp_enqueue_style( 'jkuron-woo-styles' );
- }
- }
- }
- add_action( 'wp_enqueue_scripts', 'register_custom_woo_style' );
- // Change posts per page Woo
- function redefine_products_per_page( $per_page ) {
- $per_page = 9;
- return $per_page;
- }
- add_filter( 'loop_shop_per_page', 'redefine_products_per_page', 100000 );
- // Register custom footer widgets which will be the footer columns areas
- function register_woocommerce_sidebar() {
- register_sidebar( array(
- 'name' => __( 'WooCommerce Shop Page Sidebar', 'twentynineteen' ),
- 'id' => 'woocommerce-shop-page-sidebar',
- 'before_widget' => '',
- 'after_widget' => '',
- 'before_title' => '',
- 'after_title' => ''
- ) );
- }
- add_action( 'widgets_init', 'register_woocommerce_sidebar', 20 );
- // Breadcrumbs: Change home label
- function wcc_change_breadcrumb_home_text( $defaults ) {
- $defaults['home'] = 'Jakub Kuroń';
- return $defaults;
- }
- add_filter( 'woocommerce_breadcrumb_defaults', 'wcc_change_breadcrumb_home_text' );
- // Breadcrumbs: Change home link
- function woo_custom_breadrumb_home_url() {
- return '/';
- }
- add_filter( 'woocommerce_breadcrumb_home_url', 'woo_custom_breadrumb_home_url' );
- // Breadcrumbs: Change delimiter
- function wcc_change_breadcrumb_delimiter( $defaults ) {
- $defaults['delimiter'] = ' <span class="jku-separator"></span> ';
- return $defaults;
- }
- add_filter( 'woocommerce_breadcrumb_defaults', 'wcc_change_breadcrumb_delimiter' );
- // WooCommerce - add plus / minus quantity buttons
- function display_quantity_buttons() {
- echo '<div class="jku-quantity-buttons-wrapper"><button type="button" class="plus" >+</button><button type="button" class="minus" >-</button></div>';
- }
- add_action( 'woocommerce_after_add_to_cart_quantity', 'display_quantity_buttons' );
- function add_cart_quantity_plus_minus() {
- if ( ! is_product() ) return;
- ?>
- <script type="text/javascript">
- jQuery(document).ready(function($){
- $('form.cart').on( 'click', 'button.plus, button.minus', function() {
- // Get current quantity values
- var qty = $( this ).closest( 'form.cart' ).find( '.qty' );
- var val = parseFloat(qty.val());
- var max = parseFloat(qty.attr( 'max' ));
- var min = parseFloat(qty.attr( 'min' ));
- var step = parseFloat(qty.attr( 'step' ));
- // Change the value if plus or minus
- if ( $( this ).is( '.plus' ) ) {
- if ( max && ( max <= val ) ) {
- qty.val( max );
- } else {
- qty.val( val + step );
- }
- } else {
- if ( min && ( min >= val ) ) {
- qty.val( min );
- } else if ( val > 1 ) {
- qty.val( val - step );
- }
- }
- });
- });
- </script>
- <?php
- }
- add_action( 'wp_footer', 'add_cart_quantity_plus_minus' );
- // Changing the minimum and maximum quantity for all the WooCommerce products
- function woocommerce_quantity_input_min_callback( $min, $product ) {
- $min = 1;
- return $min;
- }
- add_filter( 'woocommerce_quantity_input_min', 'woocommerce_quantity_input_min_callback', 10, 2 );
- function woocommerce_quantity_input_max_callback( $max, $product ) {
- $max = 99;
- return $max;
- }
- add_filter( 'woocommerce_quantity_input_max', 'woocommerce_quantity_input_max_callback', 10, 2 );
- // Remove opening terms and conditions in the same page. Open in the new tab instead.
- function disable_wc_terms_toggle() {
- wp_add_inline_script( 'wc-checkout', "jQuery( document ).ready( function() { jQuery( document.body ).off( 'click', 'a.woocommerce-terms-and-conditions-link' ); } );" );
- }
- add_action( 'wp_enqueue_scripts', 'disable_wc_terms_toggle', 1000 );
- // Modify image width theme support
- function modify_theme_support() {
- $theme_support = get_theme_support( 'woocommerce' );
- $theme_support = is_array( $theme_support ) ? $theme_support[0] : array();
- $theme_support['single_image_width'] = 660;
- $theme_support['thumbnail_image_width'] = 660;
- remove_theme_support( 'woocommerce' );
- add_theme_support( 'woocommerce', $theme_support );
- }
- add_action( 'after_setup_theme', 'modify_theme_support', 10 );
- ?>
Advertisement
Add Comment
Please, Sign In to add comment