%PDF- %PDF-
Direktori : /proc/1857783/root/var/www/tif-dev/wp-content/themes/inkfactory/ |
Current File : //proc/1857783/root/var/www/tif-dev/wp-content/themes/inkfactory/functions.php |
<?php /** * Inkfactory functions and definitions * * @link https://developer.wordpress.org/themes/basics/theme-functions/ * * @package Inkfactory */ if (!defined('_S_VERSION')) { // Replace the version number of the theme on each release. define('_S_VERSION', '1.0.0'); } if (!function_exists('inkfactory_setup')) : /** * Sets up theme defaults and registers support for various WordPress features. * * Note that this function is hooked into the after_setup_theme hook, which * runs before the init hook. The init hook is too late for some features, such * as indicating support for post thumbnails. */ function inkfactory_setup() { // Add default posts and comments RSS feed links to head. add_theme_support('automatic-feed-links'); /* * Let WordPress manage the document title. * By adding theme support, we declare that this theme does not use a * hard-coded <title> tag in the document head, and expect WordPress to * provide it for us. */ add_theme_support('title-tag'); /* * Enable support for Post Thumbnails on posts and pages. * * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/ */ add_theme_support('post-thumbnails'); // This theme uses wp_nav_menu() in one location. register_nav_menus( array( 'menu-1' => esc_html__('Primary', 'Inkfactory'), ) ); /* * Switch default core markup for search form, comment form, and comments * to output valid HTML5. */ add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'style', 'script', ) ); // Add theme support for selective refresh for widgets. add_theme_support('customize-selective-refresh-widgets'); /** * Add support for core custom logo. * * @link https://codex.wordpress.org/Theme_Logo */ add_theme_support( 'custom-logo', array( 'height' => 250, 'width' => 250, 'flex-width' => true, 'flex-height' => true, ) ); add_theme_support( 'align-wide' ); if( function_exists('acf_add_options_page') ) { acf_add_options_page(array( 'page_title' => 'Theme settings', 'icon_url' => 'dashicons-admin-settings' )); } if( function_exists('acf_add_options_sub_page') ) { acf_add_options_sub_page(array( 'page_title' => 'Artists settings', 'menu_title' => 'Artists settings', 'parent_slug' => 'edit.php?post_type=artists', )); acf_add_options_sub_page(array( 'page_title' => 'Barbers settings', 'menu_title' => 'Barbers settings', 'parent_slug' => 'edit.php?post_type=barbers', )); acf_add_options_sub_page(array( 'page_title' => 'Piercers settings', 'menu_title' => 'Piercers settings', 'parent_slug' => 'edit.php?post_type=piercers', )); acf_add_options_sub_page(array( 'page_title' => 'Tattoos settings', 'menu_title' => 'Tattoos settings', 'parent_slug' => 'edit.php?post_type=tattoos', )); acf_add_options_sub_page(array( 'page_title' => 'Tattoo styles settings', 'menu_title' => 'Tattoo styles settings', 'parent_slug' => 'edit.php?post_type=tattoo-styles', )); } } endif; add_action('after_setup_theme', 'inkfactory_setup'); add_action('after_setup_theme', 'theme_register_nav_menu'); function theme_register_nav_menu() { register_nav_menu('header_menu', 'Header menu'); register_nav_menu('hero-menu', 'Hero menu'); register_nav_menu('footer_row_1', 'Footer column 1'); register_nav_menu('footer_row_2', 'Footer column 2'); register_nav_menu('footer_row_3', 'Footer column 3'); } /** * Enqueue scripts and styles. */ function inkfactory_scripts() { // jquery wp_enqueue_script('jquery', get_template_directory_uri() . '/assets/libs/jquery/jquery.min.js', array(), null, true); wp_enqueue_script('jquery.mask', get_template_directory_uri() . '/assets/libs/jquery-mask/jquery.mask.min.js', array('jquery'), _S_VERSION, true); //magnific-popup wp_enqueue_style('magnific-popup', get_template_directory_uri() . '/assets/libs/magnific-popup/magnific-popup.css', array(), _S_VERSION); wp_enqueue_script('magnific-popup', get_template_directory_uri() . '/assets/libs/magnific-popup/jquery.magnific-popup.min.js', array('jquery'), _S_VERSION, true); // Swiper wp_enqueue_style('swiper', get_template_directory_uri() . '/assets/libs/swiper/swiper.min.css', array(), _S_VERSION); wp_enqueue_script('swiper', get_template_directory_uri() . '/assets/libs/swiper/swiper.min.js', array('jquery'), _S_VERSION); wp_enqueue_style('bootstrap-grid', get_template_directory_uri() . '/assets/libs/bootstrap-grid/bootstrap-grid.min.css', array(), _S_VERSION); wp_enqueue_style('main', get_template_directory_uri() . '/assets/css/main.css', array(), time()); wp_enqueue_style('inkfactory-style', get_stylesheet_uri(), array(), _S_VERSION); // tippy wp_enqueue_script('popperjs', 'https://unpkg.com/@popperjs/core@2', array('jquery'), _S_VERSION); wp_enqueue_script('tippy', 'https://unpkg.com/tippy.js@6', array('jquery'), _S_VERSION); // Scripts wp_enqueue_script('main', get_template_directory_uri() . '/assets/js/main.js', array('jquery'), time()); } add_action('wp_enqueue_scripts', 'inkfactory_scripts'); add_filter('excerpt_more', function ($more) { return '...'; }); /* Disable the Admin Bar. */ // add_filter('show_admin_bar', '__return_false'); /** * Pagination */ function wp_custom_pagination($args = array()) { $defaults = array( 'range' => 4, 'custom_query' => FALSE, 'previous_string' => '', 'next_string' => '', 'before_output' => '<div class="pagination"><div class="pagination__wrapp">', 'after_output' => '</div></div>' ); $args = wp_parse_args( $args, apply_filters('wp_bootstrap_pagination_defaults', $defaults) ); $args['range'] = (int) $args['range'] - 1; if (!$args['custom_query']) $args['custom_query'] = @$GLOBALS['wp_query']; $count = (int) $args['custom_query']->max_num_pages; $page = intval(get_query_var('paged')); $ceil = ceil($args['range'] / 2); if ($count <= 1) return FALSE; if (!$page) $page = 1; if ($count > $args['range']) { if ($page <= $args['range']) { $min = 1; $max = $args['range'] + 1; } elseif ($page >= ($count - $ceil)) { $min = $count - $args['range']; $max = $count; } elseif ($page >= $args['range'] && $page < ($count - $ceil)) { $min = $page - $ceil; $max = $page + $ceil; } } else { $min = 1; $max = $count; } $echo = ''; $previous = intval($page) - 1; $previous = esc_attr(get_pagenum_link($previous)); $firstpage = esc_attr(get_pagenum_link(1)); // if ( $firstpage && (1 != $page) ) // $echo .= '<a class="pagination__item" href="' . $firstpage . '">' . __( 'First', 'text-domain' ) . '</a>'; if ($previous && (1 != $page)) { $echo .= '<a class="pagination__arrow pagination__item" href="' . $previous . '" title="' . __('previous', 'text-domain') . '">' . $args['previous_string'] . '</a>'; } else { $echo .= ''; } if (!empty($min) && !empty($max)) { for ($i = $min; $i <= $max; $i++) { if ($page == $i) { $echo .= '<span class="pagination__item active">' . str_pad((int)$i, 1, '0', STR_PAD_LEFT) . '</span>'; } else { $echo .= sprintf('<a href="%s" class="pagination__item">%2d</a>', esc_attr(get_pagenum_link($i)), $i); } } } $next = intval($page) + 1; $next = esc_attr(get_pagenum_link($next)); // $lastpage = esc_attr( get_pagenum_link($count) ); // if ( $lastpage ) { // $echo .= '<li class="pagination__item"><a class="pagination__link" href="' . $lastpage . '">...</a></li>'; // } if ($next && ($count != $page)) { $echo .= '<a class="pagination__arrow pagination__item" href="' . $next . '" title="' . __('next', 'text-domain') . '">' . $args['next_string'] . '</a>'; } else { $echo .= ''; } if (isset($echo)) echo $args['before_output'] . $echo . $args['after_output']; } if(false === get_option("medium_crop")) { add_option("medium_crop", "1"); } else { update_option("medium_crop", "1"); } /** * Change posts per page by post type */ function change_posts_per_page( $query ) { if ( is_admin() || ! $query->is_main_query() ) { return; } if ( is_post_type_archive( 'tattoos' ) || is_post_type_archive( 'artists' ) || is_post_type_archive( 'barbers' ) || is_post_type_archive( 'piercers' )) { $query->set( 'posts_per_page', -1 ); } if ( is_search() ) { $query->set( 'posts_per_page', -1 ); } } add_filter( 'pre_get_posts', 'change_posts_per_page' ); add_filter( 'walker_nav_menu_start_el', 'cfw_add_arrow',10,4); function cfw_add_arrow( $output, $item, $depth, $args ){ //Only add class to 'top level' if('header_menu' == $args->theme_location && $depth === 0 ){ if (in_array("menu-item-has-children", $item->classes)) { $output .='<span class="menu-arrow"></span>'; } } return $output; } /** * This function modifies the main WordPress query to include an array of * post types instead of the default 'post' post type. * * @param object $query The main WordPress query. */ // function tg_include_custom_post_types_in_search_results( $query ) { // if ( $query->is_main_query() && $query->is_search() && ! is_admin() ) { // $query->set( 'post_type', array( 'post', 'barbers', 'piercers', 'artists' ) ); // } // } // add_action( 'pre_get_posts', 'tg_include_custom_post_types_in_search_results' );