/home/bdqbpbxa/rc-subdomains/optoman-rc.goodface.com.ua/wp-content/themes/optoman/functions.php
<?php
// Require settings and helpers
$theme_uri_arr = explode('/', get_template_directory_uri());
$theme_folder_name = end($theme_uri_arr);
$theme_root_path = get_theme_root() . '/' . $theme_folder_name;
require $theme_root_path . '/functions/settings/acf-settings.php';
require $theme_root_path . '/functions/settings/cf7-settings.php';
require $theme_root_path . '/functions/settings/wp-output-html-settings.php';
require $theme_root_path . '/functions/settings/wysiwyg-editor-settings.php';
require $theme_root_path . '/functions/helpers/helper-functions.php';
require $theme_root_path . '/functions/helpers/helper-shortcodes.php';
require $theme_root_path . '/functions/helpers/helper-woocommerce.php';
require $theme_root_path . '/functions/helpers/helper-calendar.php';
require $theme_root_path . '/functions/helpers/helper-custom-fields.php';
require $theme_root_path . '/functions/helpers/ajax-search.php';
require $theme_root_path . '/functions/helpers/helper-teamtailor.php';
require $theme_root_path . '/functions/helpers/helper-representatives.php';
require $theme_root_path . '/functions/helpers/helper-whitepapers.php';
// Add custom styles to admin panel
function add_custom_admin_styles()
{
wp_enqueue_style('admin-panel-custom-styles', get_template_directory_uri() . '/assets-admin/css/admin-panel.css');
}
add_action('admin_enqueue_scripts', 'add_custom_admin_styles');
// Create option pages
add_action('acf/init', function() {
if (function_exists('acf_add_options_page')) {
acf_add_options_page(array(
'page_title' => 'Global settings',
'menu_title' => 'Global setting',
'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'
// ));
}
});
// Include styles and scripts
function replace_jquery_with_cdn() {
if (!is_admin()) {
// Deregister WordPress default jQuery
wp_deregister_script('jquery');
// Register jQuery from Google CDN
wp_register_script(
'jquery',
'https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js',
[],
'3.6.0',
true
);
// Enqueue the new jQuery
wp_enqueue_script('jquery');
}
}
add_action('wp_enqueue_scripts', 'replace_jquery_with_cdn');
function include_styles_and_scripts()
{
wp_enqueue_style('swiper-css', get_template_directory_uri() . '/assets/js/lib/swiper-bundle.min.css', array(), '1.0.1');
wp_enqueue_style('scroll-animation', get_template_directory_uri() . '/assets/scss/scroll-animation.min.css', array(), true);
wp_enqueue_style('styles-langing', get_template_directory_uri() . '/acf-builder/style.css', array(), '1.0.5');
wp_enqueue_style('styles', get_template_directory_uri() . '/assets/scss/styles.css', array(), '1.0.5');
wp_enqueue_script('fullcalendar-js', get_template_directory_uri() . '/assets/js/lib/fullcalendar.min.js', array('jquery-3.7.1.min.js'), '6.1.8', true);
wp_deregister_script('jquery');
wp_enqueue_script('jquery-3.7.1.min.js', get_template_directory_uri() . '/assets/js/lib/jquery-3.7.1.min.js', array(), '1.0.1', true);
wp_enqueue_script('swiper-js', get_template_directory_uri() . '/assets/js/lib/swiper-bundle.min.js', array(), '1.0.1', true);
wp_enqueue_script('gsap', get_template_directory_uri() . '/assets/js/lib/gsap.min.js', array(), '1.5.1', array('in_footer' => true));
wp_enqueue_script('ScrollTrigger', get_template_directory_uri() . '/assets/js/lib/ScrollTrigger.min.js', array(), '1.5.1', array('in_footer' => true));
wp_enqueue_script('custom-solutions', get_template_directory_uri() . '/assets/js/custom-solutions.js', array('jquery-3.7.1.min.js'), '1.0.1', true);
wp_enqueue_script('animations', get_template_directory_uri() . '/assets/js/animations.js', array('jquery-3.7.1.min.js'), '1.0.1', true);
wp_enqueue_script('custom-calendar-js', get_template_directory_uri() . '/assets/js/custom-calendar.js', array('fullcalendar-js'), '1.0', true);
wp_enqueue_script('script-landing', get_template_directory_uri() . '/acf-builder/scripts.js', array('jquery-3.7.1.min.js'), '1.0.1', true);
wp_enqueue_script('script', get_template_directory_uri() . '/assets/js/script.js', array('jquery-3.7.1.min.js'), '1.0.1', true);
wp_localize_script('custom-calendar-js', 'eventCalendarData', array(
'ajax_url' => admin_url('admin-ajax.php'),
));
wp_enqueue_script('ajax-search', get_template_directory_uri() . '/assets/js/ajax-search.js', array('jquery-3.7.1.min.js'), null, true);
wp_localize_script('ajax-search', 'ajaxSearch', [
'ajax_url' => admin_url('admin-ajax.php'),
'site_url' => home_url('/')
]);
wp_enqueue_script('ajax-js', get_template_directory_uri() . '/assets/js/ajax.js', array('jquery-3.7.1.min.js'), null, true);
wp_localize_script('ajax-js', 'ajaxUrl', [
'ajax_url' => admin_url('admin-ajax.php'),
]);
// Enqueue whitepapers AJAX script only on whitepapers page
if (is_page_template('page-whitepapers.php')) {
wp_enqueue_script('whitepapers-ajax-js', get_template_directory_uri() . '/assets/js/whitepapers-ajax.js', array('jquery-3.7.1.min.js'), '1.0.0', true);
wp_localize_script('whitepapers-ajax-js', 'ajaxUrl', [
'ajax_url' => admin_url('admin-ajax.php'),
]);
}
}
// Додаємо підтримку JSON
function allow_json_upload_for_admins($mime_types)
{
if (current_user_can('manage_options')) {
$mime_types['json'] = 'application/json';
}
return $mime_types;
}
add_filter('upload_mimes', 'allow_json_upload_for_admins');
add_action('wp_enqueue_scripts', 'include_styles_and_scripts');
add_filter('show_admin_bar', '__return_false');
add_action('after_setup_theme', 'remove_admin_bar_for_non_admin');
function remove_admin_bar_for_non_admin()
{
if (!current_user_can('administrator')) {
show_admin_bar(false);
}
}
add_action( 'wp_enqueue_scripts', function() {
if ( ! class_exists( 'WooCommerce' ) ) return;
if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() && ! is_account_page() ) {
wp_dequeue_style( 'woocommerce-general' );
wp_dequeue_style( 'woocommerce-layout' );
wp_dequeue_style( 'woocommerce-smallscreen' );
wp_dequeue_style( 'woocommerce-inline' );
wp_dequeue_script( 'wc-add-to-cart' );
wp_dequeue_script( 'woocommerce' );
wp_dequeue_script( 'wc-cart-fragments' );
}
}, 99 );
/**
* Smart Pagination Function
*/
function smart_pagination($current_page, $total_pages) {
if ($total_pages <= 1) return '';
$html = '<div class="pagination"><ul>';
// Previous button
if ($current_page > 1) {
$html .= '<li class="prev"><a href="javascript:void(0)" data-page="' . ($current_page - 1) . '"><svg width="21" height="20" viewBox="0 0 21 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M16.3346 9.99984H4.66797M4.66797 9.99984L10.5013 15.8332M4.66797 9.99984L10.5013 4.1665" stroke="#365463" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>Previous</a></li>';
} else {
$html .= '<li class="prev disabled"><a href="#"><svg width="21" height="20" viewBox="0 0 21 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M16.3346 9.99984H4.66797M4.66797 9.99984L10.5013 15.8332M4.66797 9.99984L10.5013 4.1665" stroke="#365463" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>Previous</a></li>';
}
// Page numbers
for ($i = 1; $i <= $total_pages; $i++) {
if ($i == $current_page) {
$html .= '<li class="active"><a href="javascript:void(0)" data-page="' . $i . '">' . $i . '</a></li>';
} else {
$html .= '<li><a href="javascript:void(0)" data-page="' . $i . '">' . $i . '</a></li>';
}
}
// Next button
if ($current_page < $total_pages) {
$html .= '<li class="next"><a href="javascript:void(0)" data-page="' . ($current_page + 1) . '">Next<svg width="21" height="20" viewBox="0 0 21 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4.66797 9.99984H16.3346M16.3346 9.99984L10.5013 4.1665M16.3346 9.99984L10.5013 15.8332" stroke="#365463" stroke-width="1.66667" stroke-linecap="round" stroke-linejoin="round"/></svg></a></li>';
} else {
$html .= '<li class="next disabled"><a href="#">Next<svg width="21" height="20" viewBox="0 0 21 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4.66797 9.99984H16.3346M16.3346 9.99984L10.5013 4.1665M16.3346 9.99984L10.5013 15.8332" stroke="#365463" stroke-width="1.66667" stroke-linecap="round" stroke-linejoin="round"/></svg></a></li>';
}
$html .= '</ul></div>';
return $html;
}