/home/bdqbpbxa/demo-subdomains/ecosphere.goodface.com.ua/wp-content/themes/ecosphere/functions.php
<?php
// Add scripts and styles
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
function theme_name_scripts() {
// CSS files
wp_enqueue_style( 'styles', get_template_directory_uri() . '/assets/css/styles.css', array(), '1.1.0');
wp_enqueue_style( 'adaptive', get_template_directory_uri() . '/assets/css/adaptive.css', array(), '1.1.0');
if (is_page_template('productions.php')) {
wp_enqueue_style( 'OverlayScrollbars', get_template_directory_uri() . '/assets/css/lib/OverlayScrollbars.css', array(), '9.0');
}
if (is_singular('brand') || is_page_template(array('products.php', 'about-us.php', 'productions.php'))) {
wp_enqueue_style( 'swiper-bundle', get_template_directory_uri() . '/assets/css/lib/swiper-bundle.min.css', array(), '9.0');
}
// JS files
wp_deregister_script( 'jquery' );
wp_enqueue_script( 'bodyScrollLock', get_template_directory_uri() . '/assets/js/lib/bodyScrollLock.min.js', array(), '1.0.1', false );
wp_enqueue_script( 'jquery', get_template_directory_uri() . '/assets/js/lib/jquery-3.6.0.min.js', array(), '1.0.1', true );
wp_enqueue_script( 'fakescroll', get_template_directory_uri() . '/assets/js/lib/fakescroll.min.js', array(), '1.0.1', true );
if (is_front_page()) {
wp_enqueue_script( 'mousewheel', get_template_directory_uri() . '/assets/js/lib/jquery.mousewheel.min.js', array(), '1.0.1', true );
wp_enqueue_script( 'touchSwipe', get_template_directory_uri() . '/assets/js/lib/jquery.touchSwipe.min.js', array(), '1.0.1', true );
}
if (is_page_template(['about-us.php', 'productions.php', 'for-distributors.php']) || is_singular('brand')) {
wp_enqueue_script( 'gsap', get_template_directory_uri() . '/assets/js/lib/gsap.min.js', array(), '1.0.1', true );
wp_enqueue_script( 'MotionPathPlugin', get_template_directory_uri() . '/assets/js/lib/MotionPathPlugin.min.js', array(), '1.0.1', true );
}
if (is_page_template('productions.php')) {
wp_enqueue_script( 'overlayScrollbars', get_template_directory_uri() . '/assets/js/lib/jquery.overlayScrollbars.min.js', array(), '1.0.1', true );
}
if (is_singular('brand') || is_page_template(array('products.php', 'about-us.php', 'productions.php'))) {
wp_enqueue_script( 'swiper-bundle', get_template_directory_uri() . '/assets/js/lib/swiper-bundle.min.js', array(), '1.0.1', true );
}
wp_enqueue_script( 'script', get_template_directory_uri() . '/assets/js/script.js', array(), '1.0.1', true );
}
// Include custom styles to the admin panel
add_action( 'admin_enqueue_scripts', 'custom_admin_styles');
function custom_admin_styles() {
wp_enqueue_style('custom-admin-styles', get_template_directory_uri() . '/assets/css/admin-styles.css');
}
// Add option pages
if (function_exists('acf_add_options_page')) {
acf_add_options_page(array(
'page_title' => 'Глобальные настройки',
'menu_title' => 'Глобальные настройки',
'menu_slug' => 'theme-general-settings',
'capability' => 'edit_posts',
'redirect' => false
));
acf_add_options_sub_page(array(
'page_title' => 'English',
'menu_title' => 'English',
'menu_slug' => 'global-settings-en',
'parent_slug' => 'theme-general-settings'
));
acf_add_options_sub_page(array(
'page_title' => 'Українська',
'menu_title' => 'Українська',
'menu_slug' => 'global-settings-uk',
'parent_slug' => 'theme-general-settings'
));
}
// Remove "type" attribute from <script> tag
add_action('after_setup_theme', function() {
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'feed_links', 2);
add_theme_support( 'html5', [ 'script', 'style' ] );
});
function add_cors_http_header(){
header("Access-Control-Allow-Origin: *");
}
add_action('init','add_cors_http_header');
// Add shortcode
add_shortcode('nbsp', 'nbsp');
function nbsp() {
return ' ';
}
// Add ‑ shortcode
add_shortcode('nbds', 'nbds');
function nbds() {
return '‑';
}
// Add ­ shortcode
add_shortcode('shy', 'shy');
function shy() {
return '­';
}
// Add [sup] shortcode
add_shortcode('sup', 'sup');
function sup($atts, $content) {
return "<sup>{$content}</sup>";
}
// Add [current-year] shortcode
add_shortcode('current-year', 'get_current_year');
function get_current_year() {
return date('Y');
}
// Get custom fields by shortcode
add_shortcode('get-custom-field', 'get_custom_field');
function get_custom_field($atts) {
$current_lang = pll_current_language();
$field_name = $atts['name'] . '-' . $current_lang;
$repeat_content = false;
$value = get_field($field_name, 'option');
if (isset($atts['children'])) {
$field_children = explode('/', $atts['children']);
foreach ($field_children as $field) {
$value = $value[$field];
}
}
if (isset($atts['repeater'])) {
$tag = $atts['tag'];
$class = $atts['class'];
foreach ($value as $item) {
$repeat_content .= "<{$tag} class='{$class}'>{$item['value']}</{$tag}>";
}
}
return $repeat_content ? $repeat_content : $value;
}
// Remove CF7 "p" tags and styles
add_filter('wpcf7_autop_or_not', '__return_false');
add_filter('wpcf7_load_css', '__return_false');
// Allow shortcodes in CF7 code
add_filter('wpcf7_form_elements', 'allow_cf7_shortcodes');
function allow_cf7_shortcodes($form) {
$form = do_shortcode($form);
return $form;
}
// Allow shortcodes in custom fields
add_filter('acf/format_value', 'shortcodeFunction', 10, 3);
function shortcodeFunction($value, $post_id, $field) {
$field_type = $field['type'];
if ($field_type == 'text' || $field_type == 'textarea' || $field_type == 'editor') {
$value = do_shortcode($value);
}
return $value;
}
// Remove default wp lazyload
add_filter('wp_lazy_loading_enabled', '__return_false');
// Return link object
function getLink($array) {
$link_type = $array['type'];
$text = $array['title'];
$class = '';
$link = '';
$child = '';
$displayed = false;
if ($link_type == 'object') {
$page_id = $array['object'];
if ($page_id) {
$link = get_the_permalink($page_id);
}
if (!$text) {
$text = get_the_title($page_id);
}
} else if ($link_type == 'link') {
$link = $array['link']['url'];
if (!$text) {
$text = $array['link']['title'];
}
} else if ($link_type == 'file') {
$link = $array['file']['url'];
if (!$text) {
$text = $array['file']['title'];
}
} else if ($link_type == 'dropdown') {
$class = "-has-dropdown";
$child = $array['dropdown'];
$link = '#';
}
if ($link && $text) {
$displayed = true;
}
$link_obj = [
'url' => $link,
'title' => $text,
'class' => $class,
'child' => $child,
'displayed' => $displayed
];
return $link_obj;
}
function getFile($file_array) {
if (!$file_array) {
return;
}
$displayed = true;
$file_id = $file_array['ID'];
$file_item = $file_array['url'];
$file_meta = wp_get_attachment_metadata( $file_id );
if ( isset( $file_meta['filesize'] ) )
$file_size = $file_meta['filesize'];
elseif ( $file = get_attached_file( $file_id ) )
if( file_exists( $file ))
$file_size = filesize( $file );
$file_size_formatted = size_format($file_size);
$file_filtype = wp_check_filetype( $file_item );
$url = $file_array['url'];
if (!$file_size_formatted || !$file_filtype['ext']) {
$displayed = false;
}
return [
'filetype' => $file_filtype['ext'],
'filesize' => $file_size_formatted,
'displayed' => $displayed,
'url' => $url
];
}
// Blog ajax filter
add_action('wp_ajax_modal_ajax', 'modal_ajax_callback');
add_action('wp_ajax_nopriv_modal_ajax', 'modal_ajax_callback');
function modal_ajax_callback() {
get_template_part('template-parts/package-format');
wp_die();
}