← Back
Editing: functions.php
<?php $GLOBALS['TIL'] = str_replace(['_RU', '_UZ', '_US'], '', get_locale()); $per_product = 23; // Disable WordPress image compression add_filter( 'jpeg_quality', function( $arg ) { return 100; }); function get_qoute_url() { if(pll_current_language()=='ru'){ return '/quote-page-ru'; } else{ return '/'.pll_current_language().'/quote-page-'.pll_current_language(); } } // Easy access for ACF of footer, header and contacts function get_contact_field($field) { return get_field($field, 49); } function get_header_field($field) { return get_field($field, 57); } function get_footer_field($field) { return get_field($field, 59); } if ( ! function_exists( 'wp_bootstrap_starter_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 wp_bootstrap_starter_setup() { /* * Make theme available for translation. * Translations can be filed in the /languages/ directory. * If you're building a theme based on WP Bootstrap Starter, use a find and replace * to change 'wp-bootstrap-starter' to the name of your theme in all the template files. */ load_theme_textdomain( 'wp-bootstrap-starter', get_template_directory() . '/languages' ); // 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( 'primary' => esc_html__( 'Primary', 'wp-bootstrap-starter' ), ) ); /* * Switch default core markup for search form, comment form, and comments * to output valid HTML5. */ add_theme_support( 'html5', array( 'comment-form', 'comment-list', 'caption', ) ); // Set up the WordPress core custom background feature. add_theme_support( 'custom-background', apply_filters( 'wp_bootstrap_starter_custom_background_args', array( 'default-color' => 'ffffff', 'default-image' => '', ) ) ); // Add theme support for selective refresh for widgets. add_theme_support( 'customize-selective-refresh-widgets' ); function wp_boostrap_starter_add_editor_styles() { add_editor_style( 'custom-editor-style.css' ); } add_action( 'admin_init', 'wp_boostrap_starter_add_editor_styles' ); } endif; add_action( 'after_setup_theme', 'wp_bootstrap_starter_setup' ); /** * Add Welcome message to dashboard */ function wp_bootstrap_starter_reminder(){ $theme_page_url = 'https://afterimagedesigns.com/wp-bootstrap-starter/?dashboard=1'; if(!get_option( 'triggered_welcomet')){ $message = sprintf(__( 'Welcome to WP Bootstrap Starter Theme! Before diving in to your new theme, please visit the <a style="color: #fff; font-weight: bold;" href="%1$s" target="_blank">theme\'s</a> page for access to dozens of tips and in-depth tutorials.', 'wp-bootstrap-starter' ), esc_url( $theme_page_url ) ); printf( '<div class="notice is-dismissible" style="background-color: #6C2EB9; color: #fff; border-left: none;"> <p>%1$s</p> </div>', $message ); add_option( 'triggered_welcomet', '1', '', 'yes' ); } } add_action( 'admin_notices', 'wp_bootstrap_starter_reminder' ); /** * Set the content width in pixels, based on the theme's design and stylesheet. * * Priority 0 to make it available to lower priority callbacks. * * @global int $content_width */ function wp_bootstrap_starter_content_width() { $GLOBALS['content_width'] = apply_filters( 'wp_bootstrap_starter_content_width', 1170 ); } add_action( 'after_setup_theme', 'wp_bootstrap_starter_content_width', 0 ); /** * Register widget area. * * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar */ function wp_bootstrap_starter_widgets_init() { register_sidebar( array( 'name' => esc_html__( 'Sidebar', 'wp-bootstrap-starter' ), 'id' => 'sidebar-1', 'description' => esc_html__( 'Add widgets here.', 'wp-bootstrap-starter' ), 'before_widget' => '<section id="%1$s" class="widget %2$s">', 'after_widget' => '</section>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', ) ); register_sidebar( array( 'name' => esc_html__( 'Footer 1', 'wp-bootstrap-starter' ), 'id' => 'footer-1', 'description' => esc_html__( 'Add widgets here.', 'wp-bootstrap-starter' ), 'before_widget' => '<section id="%1$s" class="widget %2$s">', 'after_widget' => '</section>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', ) ); register_sidebar( array( 'name' => esc_html__( 'Footer 2', 'wp-bootstrap-starter' ), 'id' => 'footer-2', 'description' => esc_html__( 'Add widgets here.', 'wp-bootstrap-starter' ), 'before_widget' => '<section id="%1$s" class="widget %2$s">', 'after_widget' => '</section>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', ) ); register_sidebar( array( 'name' => esc_html__( 'Footer 3', 'wp-bootstrap-starter' ), 'id' => 'footer-3', 'description' => esc_html__( 'Add widgets here.', 'wp-bootstrap-starter' ), 'before_widget' => '<section id="%1$s" class="widget %2$s">', 'after_widget' => '</section>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', ) ); } add_action( 'widgets_init', 'wp_bootstrap_starter_widgets_init' ); /** * Enqueue scripts and styles. */ function wp_bootstrap_starter_scripts() { // load bootstrap css $form_styles_header = [ "1" => "bootstrap/bootstrap.min.css", "2" => "css/bww7w.css", "3" => "css/navbar.css", "4" => "css/bww7v.css", "5" => "asda-barvent.css" ]; foreach ($form_styles_header as $no=>$form_style) { wp_enqueue_style('wp-barvent-'.$no, get_template_directory_uri() . "/inc/assets/".$form_style."?v=".time()); } // load bootstrap css // style.css in coren themes // wp_enqueue_style( 'wp-bootstrap-starter-style', get_stylesheet_uri() ); if(get_theme_mod( 'theme_option_setting' ) && get_theme_mod( 'theme_option_setting' ) !== 'default') { wp_enqueue_style( 'wp-bootstrap-starter-'.get_theme_mod( 'theme_option_setting' ), get_template_directory_uri() . '/inc/assets/css/presets/theme-option/'.get_theme_mod( 'theme_option_setting' ).'.css', false, '' ); } if(get_theme_mod( 'preset_style_setting' ) === 'poppins-lora') { wp_enqueue_style( 'wp-bootstrap-starter-poppins-lora-font', 'https://fonts.googleapis.com/css?family=Lora:400,400i,700,700i|Poppins:300,400,500,600,700' ); } if(get_theme_mod( 'preset_style_setting' ) === 'montserrat-merriweather') { wp_enqueue_style( 'wp-bootstrap-starter-montserrat-merriweather-font', 'https://fonts.googleapis.com/css?family=Merriweather:300,400,400i,700,900|Montserrat:300,400,400i,500,700,800' ); } if(get_theme_mod( 'preset_style_setting' ) === 'poppins-poppins') { wp_enqueue_style( 'wp-bootstrap-starter-poppins-font', 'https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700' ); } if(get_theme_mod( 'preset_style_setting' ) === 'roboto-roboto') { wp_enqueue_style( 'wp-bootstrap-starter-roboto-font', 'https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,500,500i,700,700i,900,900i' ); } if(get_theme_mod( 'preset_style_setting' ) === 'arbutusslab-opensans') { wp_enqueue_style( 'wp-bootstrap-starter-arbutusslab-opensans-font', 'https://fonts.googleapis.com/css?family=Arbutus+Slab|Open+Sans:300,300i,400,400i,600,600i,700,800' ); } if(get_theme_mod( 'preset_style_setting' ) === 'oswald-muli') { wp_enqueue_style( 'wp-bootstrap-starter-oswald-muli-font', 'https://fonts.googleapis.com/css?family=Muli:300,400,600,700,800|Oswald:300,400,500,600,700' ); } if(get_theme_mod( 'preset_style_setting' ) === 'montserrat-opensans') { wp_enqueue_style( 'wp-bootstrap-starter-montserrat-opensans-font', 'https://fonts.googleapis.com/css?family=Montserrat|Open+Sans:300,300i,400,400i,600,600i,700,800' ); } if(get_theme_mod( 'preset_style_setting' ) === 'robotoslab-roboto') { wp_enqueue_style( 'wp-bootstrap-starter-robotoslab-roboto', 'https://fonts.googleapis.com/css?family=Roboto+Slab:100,300,400,700|Roboto:300,300i,400,400i,500,700,700i' ); } if(get_theme_mod( 'preset_style_setting' ) && get_theme_mod( 'preset_style_setting' ) !== 'default') { wp_enqueue_style( 'wp-bootstrap-starter-'.get_theme_mod( 'preset_style_setting' ), get_template_directory_uri() . '/inc/assets/css/presets/typography/'.get_theme_mod( 'preset_style_setting' ).'.css', false, '' ); } //Color Scheme /*if(get_theme_mod( 'preset_color_scheme_setting' ) && get_theme_mod( 'preset_color_scheme_setting' ) !== 'default') { wp_enqueue_style( 'wp-bootstrap-starter-'.get_theme_mod( 'preset_color_scheme_setting' ), get_template_directory_uri() . '/inc/assets/css/presets/color-scheme/'.get_theme_mod( 'preset_color_scheme_setting' ).'.css', false, '' ); }else { wp_enqueue_style( 'wp-bootstrap-starter-default', get_template_directory_uri() . '/inc/assets/css/presets/color-scheme/blue.css', false, '' ); }*/ // Javascript codes file $form_js_footer = [ "1" => "js/bootstrap.bundle.js", "2" => "js/headroom.min.js?ver=5.1.10", "3" => "js/waypoints.min.js?ver=5.6", "4" => "js/jquery.smartmenus.min.js?ver=5.1.10", "5" => "js/main.min.js?ver=5.1.10", "6" => "js/lightgallery-all.min.js", "7" => "js/lazyload.min.js", "8" => "js/hoverontouch.js" ]; foreach ($form_js_footer as $no=>$form_js) { wp_enqueue_script('barvent-'.$no, get_template_directory_uri() . "/inc/assets/".$form_js, array(), '', true); } } add_action( 'wp_enqueue_scripts', 'wp_bootstrap_starter_scripts' ); /** * Add Preload for CDN scripts and stylesheet */ function wp_bootstrap_starter_preload( $hints, $relation_type ){ if ( 'preconnect' === $relation_type && get_theme_mod( 'cdn_assets_setting' ) === 'yes' ) { $hints[] = [ 'href' => 'https://cdn.jsdelivr.net/', 'crossorigin' => 'anonymous', ]; $hints[] = [ 'href' => 'https://use.fontawesome.com/', 'crossorigin' => 'anonymous', ]; } return $hints; } add_filter( 'wp_resource_hints', 'wp_bootstrap_starter_preload', 10, 2 ); function wp_bootstrap_starter_password_form() { global $post; $label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID ); $o = '<form action="' . esc_url( home_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post"> <div class="d-block mb-3">' . __( "To view this protected post, enter the password below:", "wp-bootstrap-starter" ) . '</div> <div class="form-group form-inline"><label for="' . $label . '" class="mr-2">' . __( "Password:", "wp-bootstrap-starter" ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" maxlength="20" class="form-control mr-2" /> <input type="submit" name="Submit" value="' . esc_attr__( "Submit", "wp-bootstrap-starter" ) . '" class="btn btn-primary"/></div> </form>'; return $o; } add_filter( 'the_password_form', 'wp_bootstrap_starter_password_form' ); /** * Implement the Custom Header feature. */ require get_template_directory() . '/inc/custom-header.php'; /** * Custom template tags for this theme. */ require get_template_directory() . '/inc/template-tags.php'; /** * Custom functions that act independently of the theme templates. */ require get_template_directory() . '/inc/extras.php'; /** * Customizer additions. */ require get_template_directory() . '/inc/customizer.php'; /** * Load plugin compatibility file. */ require get_template_directory() . '/inc/plugin-compatibility/plugin-compatibility.php'; /** * Load custom WordPress nav walker. */ if ( ! class_exists( 'wp_bootstrap_navwalker' )) { require_once(get_template_directory() . '/inc/wp_bootstrap_navwalker.php'); } /** * Coding write by Morgan - 17.11.2022 */ /* Disable WordPress Admin Bar for all users */ add_filter( 'show_admin_bar', '__return_false' ); /*Run i18n langs package*/ $folder_vendor = 'i18n-langs/vendor/philipp15b/php-i18n'; require get_template_directory() . '/i18n-langs/vendor/autoload.php'; require_once get_template_directory() . '/'.$folder_vendor.'/i18n.class.php'; $i18n = new i18n(get_template_directory() . '/i18n-langs/lang/{LANGUAGE}.yml', get_template_directory() . '/i18n-langs/langcache', 'ru'); $i18n->setForcedLang($GLOBALS['TIL']); $i18n->init(); /*end i18n langs pack*/ // close comments add_action( 'wp_enqueue_scripts', 'remove_comments_multiple_categories' ); function remove_comments_multiple_categories() { add_filter('comments_open', '__return_false', 20, 2); add_filter('pings_open', '__return_false', 20, 2); } add_filter( 'edit_post_link', '__return_false' ); /** * Part translate */ add_filter('gettext', 'translate_strings'); add_filter('ngettext', 'translate_strings'); function translate_strings($translated) { $str_translate_checkout = [ 'Posted on', 'Home' ]; $str_response_checkout = [ L::posted, L::home ]; $translated = str_replace($str_translate_checkout, $str_response_checkout, $translated); return $translated; } /*My custom pagination in numbers*/ function the_custom_pagination($args = [], $class = 'pagination') { if ($GLOBALS['wp_query']->max_num_pages <= 1) return; $args = wp_parse_args( $args, [ 'mid_size' => 2, 'prev_next' => false, 'prev_text' => __(L::next, 'wp-bootstrap-starter'), 'next_text' => __(L::prev, 'wp-bootstrap-starter'), 'screen_reader_text' => __('Posts navigation', 'wp-bootstrap-starter'), ]); $links = paginate_links($args); $next_link = get_previous_posts_link($args['next_text']); $prev_link = get_next_posts_link($args['prev_text']); $template = apply_filters( 'the_navigation_markup_template', ' <div class="col-md-12 col-sm-12 col-xs-12"> <div class="blog-pagination"> <ul class="pagination"> <li id="prev">%5$s</li> %4$s <li id="next">%3$s</li> </div> </div>', $args, $class); ?> <style> .blog-pagination { margin-top: 20px; margin-bottom: 20px; display: flex; justify-content: center; } .pagination .page-numbers { font-size: 18px; padding: 10px 20px; border: 1px solid #ddd; border-radius: 5px; margin: 0 5px; display: flex; align-items: center; } .pagination li:first-child { margin: unset; } .pagination .current { background-color: #ddd; } ul li#prev a, ul li#next a { margin: unset; font-size: 18px; padding: 10px 20px; border: 1px solid #ddd; border-radius: 5px; /*margin: 0 5px;*/ display: flex; align-items: center; } </style> <?php echo sprintf($template, $class, $args['screen_reader_text'], $prev_link, $links, $next_link); } function the_custom_pagination2($query, $class = 'pagination'){ $args= [ 'total' => $query->max_num_pages, 'mid_size' => 2, 'prev_next' => false, 'prev_text' => __(L::next, 'wp-bootstrap-starter'), 'next_text' => __(L::prev, 'wp-bootstrap-starter'), 'screen_reader_text' => __('Posts navigation', 'wp-bootstrap-starter'), ]; $links = paginate_links($args); $next_link = get_previous_posts_link($args['next_text']); $prev_link = get_next_posts_link($args['prev_text'], $query->max_num_pages); $template = apply_filters( 'the_navigation_markup_template', ' <div class="col-md-12 col-sm-12 col-xs-12"> <div class="blog-pagination"> <ul class="pagination"> <li id="prev">%5$s</li> %4$s <li id="next">%3$s</li> </div> </div>', $args, $class); ?> <style> .blog-pagination { margin-top: 20px; margin-bottom: 20px; display: flex; justify-content: center; } .pagination .page-numbers { font-size: 18px; padding: 10px 20px; border: 1px solid #ddd; border-radius: 5px; margin: 0 5px; display: flex; align-items: center; } .pagination li:first-child { margin: unset; } .pagination .current { background-color: #ddd; } ul li#prev a, ul li#next a { margin: unset; font-size: 18px; padding: 10px 20px; border: 1px solid #ddd; border-radius: 5px; /*margin: 0 5px;*/ display: flex; align-items: center; } </style> <?php echo sprintf($template, $class, $args['screen_reader_text'], $prev_link, $links, $next_link); } /** * Conditionally Override Yoast SEO Breadcrumb Trail * http://plugins.svn.wordpress.org/wordpress-seo/trunk/frontend/class-breadcrumbs.php * ----------------------------------------------------------------------------------- */ add_filter( 'wpseo_breadcrumb_links', 'wpse_100012_override_yoast_breadcrumb_trail' ); function wpse_100012_override_yoast_breadcrumb_trail( $links ) { global $post; // sayt haritasida pageni category bilan bog'lab chiqarish if (in_category(52)) $id = 84; if (in_category(54)) $id = 105; if (in_category(48)) $id = 80; if (in_category(50)) $id = 109; if (in_category(56)) $id = 95; if (in_category(58)) $id = 101; if (in_category(60)) $id = 97; if (in_category(62)) $id = 103; if (in_category(148)) $id = 93; if (in_category(150)) $id = 107; if ( isset($id) ) { $breadcrumb[] = array( 'url' => get_permalink($id), 'text' => get_the_title($id), ); array_splice($links, 1, -2, $breadcrumb); } // news breadcumbs if (in_category(38)) $cat_id = 38; if (in_category(40)) $cat_id = 40; // news breadcumbs template-1 if (in_category(131)) $cat_id = 38; if (in_category(133)) $cat_id = 40; if (isset($cat_id)) { $breadcrumb[] = array( 'url' => get_category_link($cat_id), 'text' => get_cat_name($cat_id), ); array_splice($links, 1, -2, $breadcrumb); } return $links; } add_action('wpcf7_before_send_mail', 'dynamic_addcc'); function dynamic_addcc($WPCF7_ContactForm) { $currentformInstance = WPCF7_ContactForm::get_current(); $contactformsubmition = WPCF7_Submission::get_instance(); if ($contactformsubmition) { $data = $contactformsubmition->get_posted_data(); if (empty($data)) return; $mail = $currentformInstance->prop('mail'); //$mail['additional_headers'] = ''; //override additional headers $email = $_POST['brand'] == "barvent" ? "info@barvent.uz" : "info@asda.uz"; $mail['recipient'] = $email; // Save the email body $currentformInstance->set_properties(array( "mail" => $mail )); // return current cf7 instance return $currentformInstance; } } /** Add image url * to category post */ function my_category_module() { // this action is deprecated //add_action('edit_category_form_fields', 'add_image_cat'); // Add these actions for edit and add add_action('edited_category', 'save_image'); add_action('create_category', 'save_image'); add_action('category_edit_form_fields', 'edit_image_cat'); } add_action('init', 'my_category_module'); function edit_image_cat($tag) { $category_images = get_option('category_images'); $category_image = ''; if (is_array($category_images) && array_key_exists($tag->term_id, $category_images)) { $category_image = $category_images[$tag->term_id]; } ?> <tr> <th scope="row" valign="top"><label for="auteur_revue_image">Image</label></th> <td> <?php if ($category_image != "") { ?> <img style="width: 300px;" src="<?php echo $category_image; ?>" alt="" title="" /> <?php } ?> <br /> <!-- Add this html here --> <input type="text" class="regular-text" id="custom_category_image" name="category_image" value="<?php echo $category_image; ?>"> <button class="set_category_image button">Set Image url</button> <!-- <input type="text" name="category_image" id="category_image" value="<?php echo $category_image; ?>"/><br /> <span>This field allows you to add a picture to illustrate the category. Upload the image from the media tab WordPress and paste its URL here.</span> --> </td> </tr> <?php } function save_image($term_id) { if (isset($_POST['category_image'])) { //load existing category featured option $category_images = get_option('category_images'); //set featured post ID to proper category ID in options array $category_images[$term_id] = $_POST['category_image']; //save the option array update_option('category_images', $category_images); } } // Enquey media elements add_action('admin_enqueue_scripts', function () { if (is_admin()) wp_enqueue_media(); }); // Add JS using admin_footer or enque thorugh hooks add_action('admin_footer', 'my_footer_scripts'); function my_footer_scripts() { ?> <script> jQuery(document).ready(function() { if (jQuery('.set_category_image').length > 0) { if (typeof wp !== 'undefined' && wp.media && wp.media.editor) { jQuery('.set_category_image').on('click', function(e) { e.preventDefault(); var button = jQuery(this); var url_input = jQuery("#custom_category_image"); wp.media.editor.send.attachment = function(props, attachment) { url_input.val(attachment.url); }; wp.media.editor.open(button); return false; }); } } }); </script> <?php } add_filter( 'single_template', function ($single_template) { global $post; if ( in_category( [148,150] ) ) { $single_template = dirname( __FILE__ ) . '/single-sredstva.php'; } return $single_template; }, 10, 3 ); //carousel img add size add_image_size('carousel-img', 270); // for desktop devices add_image_size('carousel-img-mobile', 376); // for mobile devices
Save File
Cancel