path(); $path->import('@theme/include/classes/Wpw_Menu_Walker.php'); $path->import('@theme/include/classes/class-tgm-plugin-activation.php'); $path->import('@wpw-config/metaboxes.php'); $path->import('@wpw-config/user.php'); } add_action('wpw_bootstrap', 'anadbry_bootstrap'); /** * Include framework */ include_once get_template_directory() . '/include/lib/wpw-theme-helper/include/classes/Wpw.php'; /** * Define content width */ if (!isset($content_width)) { $content_width = 1920; } /** * Add custom theme support */ function anadbry_after_setup() { load_theme_textdomain( 'anadbry', Wpw::inst()->path()->resolve('@theme/languages') ); add_theme_support('post-thumbnails'); add_theme_support('html5', [ 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', ]); add_theme_support('title-tag'); add_theme_support('automatic-feed-links'); add_theme_support('customize-selective-refresh-widgets'); add_theme_support('woocommerce'); } add_action('after_setup_theme', 'anadbry_after_setup'); /** * Enqueue scripts to theme */ function anadbry_enqueue_scripts() { $custom_js = get_theme_mod('wpw_custom_js'); $custom_js .= apply_filters('wpw_custom_js', $custom_js); // Scripts wp_enqueue_script('anadbry-main-script', Wpw::inst()->path()->resolve_url('@theme-url/assets/js/main.js'), [ 'wp-util', ], false, true); wp_localize_script( 'anadbry-main-script', 'wpwSettings', apply_filters('wpw_settings', []) ); wp_localize_script('anadbry-main-script', 'wpwUrls', [ 'js' => Wpw::inst()->path()->resolve_url('@theme-url/assets/js'), 'ajax' => admin_url('admin-ajax.php'), ]); if (is_singular()) { wp_enqueue_script('comment-reply', '', [], false, true); } $custom_js = trim($custom_js); if (!empty($custom_js)) { wp_add_inline_script('anadbry-main-script', $custom_js); } } add_action('wp_enqueue_scripts', 'anadbry_enqueue_scripts', 50); /** * Enqueue styles to theme */ function anadbry_enqueue_styles() { $wpw = Wpw::inst(); $path = $wpw->path(); $custom_css = get_theme_mod('wpw_custom_css'); // Styles wp_enqueue_style('main-style', $path->resolve_url('@theme-url/assets/css/main.css')); $dynamic_style = apply_filters('wpw_external_styles', ''); $cache_timeout = intval(get_theme_mod('wpw_styles_cache_time')); if (empty($cache_timeout)) { $cache_timeout = -1; } if ($cache_timeout > -1) { $cache = $wpw->db_cache(); $cached_styles = $cache->get('wpw_theme_styles'); if ($cached_styles) { $dynamic_style = $cached_styles; } else { $cache_timeout = intval(get_theme_mod('wpw_styles_cache_time')); $dynamic_style .= $wpw ->resource() ->render('@theme/assets/css/dynamic-styles/load-styles.php'); $dynamic_style = $wpw->helpers()->minify($dynamic_style); $dynamic_style = preg_replace('/background-image: url\([\'"#]*\)/si', 'background-image: none', $dynamic_style); $cache->set('wpw_theme_styles', $dynamic_style, $cache_timeout); } } else { $dynamic_style .= $wpw ->resource() ->render('@theme/assets/css/dynamic-styles/load-styles.php'); $dynamic_style = preg_replace('/background-image: url\([\'"#]*\)/si', 'background-image: none', $dynamic_style); $dynamic_style = $wpw->helpers()->minify($dynamic_style); } if (!$wpw->helpers()->default_styling()) { wp_add_inline_style('main-style', $dynamic_style); } if (!empty($custom_css)) { wp_add_inline_style('main-style', $custom_css); } } add_action('wp_enqueue_scripts', 'anadbry_enqueue_styles'); /** * Add styles and scripts to admin pages */ function anadbry_admin_enqueue() { $path = Wpw::inst()->path(); // Styles $base_url = $path->resolve_url('@theme-url/assets/css'); wp_enqueue_style('font-awesome', $base_url . '/font-awesome.min.css'); wp_enqueue_style('wpw-admin-styles', $base_url . '/admin.css'); add_editor_style($base_url . '/editor.css'); } add_action('admin_enqueue_scripts', 'anadbry_admin_enqueue'); add_action('customize_controls_enqueue_scripts', 'anadbry_admin_enqueue'); /** * Add menu settings page to admin panel */ function anadbry_register_menus() { register_nav_menu('primary', esc_html__('Primary menu', 'anadbry')); } add_action('after_setup_theme', 'anadbry_register_menus'); /** * Register sidebars */ function anadbry_register_sidebar() { $wpw = Wpw::inst(); $formatter = $wpw->formatter(); $opt = $formatter->parse_mod('wpw_widgets_element'); $opt = !empty($opt['wpw_widgets']) ? $formatter->parse($opt['wpw_widgets']) : []; $sidebars = $formatter->parse_mod('wpw_widget_containers'); $sidebars = array_merge([ 'primary' => [ 'title' => esc_html__('Primary', 'anadbry'), 'class_name' => 'primary', ], ], $sidebars); $bg_block = $wpw->resource()->render('@theme/templates/components/default-bg.php'); foreach ($sidebars as $sidebar) { $widget_styling = !empty($sidebar['widget_styling']) ? $sidebar['widget_styling'] : ''; $wrapper_class = $title_class = ''; if (!empty($widget_styling)) { foreach ($opt as $_style) { $class_name = !empty($_style['class_name']) ? $_style['class_name'] : ''; if ($class_name == $widget_styling) { $wrapper_class .= !empty($_style['widget_list_style']) ? ' ' . $_style['widget_list_style'] : ''; $wrapper_class .= !empty($_style['widget_link_style']) ? ' ' . $_style['widget_link_style'] : ''; } } } $title = !empty($sidebar['title']) ? $sidebar['title'] : ''; $id = !empty($sidebar['class_name']) ? $sidebar['class_name'] : ''; $wrapper_class .= !empty($sidebar['widget_class']) ? ' ' . $sidebar['widget_class'] : ''; $wrapper_class .= ' ' . $widget_styling; $title_class .= !empty($sidebar['widget_title_class']) ? ' ' . $sidebar['widget_title_class'] : ''; register_sidebar([ 'name' => $title, 'id' => 'wpw-sidebar-' . $id, 'class' => 'wpw-sidebar', 'before_widget' => '
' . $bg_block, 'after_widget' => '
', 'before_title' => '
' . $bg_block . '
', 'after_title' => '
', ]); } } add_action('widgets_init', 'anadbry_register_sidebar'); /** * Include plugins to theme */ function anadbry_require_plugins() { $plugins = [ [ 'name' => esc_html__('Contact Form 7', 'anadbry'), 'slug' => 'contact-form-7', 'required' => true, ], [ 'name' => esc_html__('MailChimp for WordPress', 'anadbry'), 'slug' => 'mailchimp-for-wp', 'required' => true, ], [ 'name' => esc_html__('WooCommerce', 'anadbry'), 'slug' => 'woocommerce', 'required' => true, ], [ 'name' => esc_html__('WpWay Custom Elements', 'anadbry'), 'slug' => 'customizer-elements', 'required' => true, 'version' => '1.0', 'source' => esc_url('https://validate.wpway.com/static/customizer-elements-1.0.zip'), ], [ 'name' => esc_html__('WpWay Importer', 'anadbry'), 'slug' => 'customizer-importer', 'required' => true, 'version' => '1.0', 'source' => esc_url('https://validate.wpway.com/static/customizer-importer-1.0.zip'), ], [ 'name' => esc_html__('WpWay Global Styling', 'anadbry'), 'slug' => 'customizer-global', 'required' => true, 'version' => '1.0', 'source' => esc_url('https://validate.wpway.com/static/customizer-global-1.0.zip'), ], [ 'name' => esc_html__('WpWay Iconography', 'anadbry'), 'slug' => 'customizer-icons', 'required' => true, 'version' => '1.0', 'source' => esc_url('https://validate.wpway.com/static/customizer-icons-1.0.zip'), ], [ 'name' => esc_html__('WpWay Layout', 'anadbry'), 'slug' => 'customizer-layout', 'required' => true, 'version' => '1.0', 'source' => esc_url('https://validate.wpway.com/static/customizer-layout-1.0.zip'), ], [ 'name' => esc_html__('WpWay Navigation', 'anadbry'), 'slug' => 'customizer-navigation', 'required' => true, 'version' => '1.0', 'source' => esc_url('https://validate.wpway.com/static/customizer-navigation-1.0.zip'), ], [ 'name' => esc_html__('WpWay Typography', 'anadbry'), 'slug' => 'customizer-typography', 'required' => true, 'version' => '1.0', 'source' => esc_url('https://validate.wpway.com/static/customizer-typography-1.0.zip'), ], [ 'name' => esc_html__('WpWay Visual Composer Components', 'anadbry'), 'slug' => 'vc-components', 'required' => true, 'version' => '1.0', 'source' => esc_url('https://validate.wpway.com/static/vc-components-1.0.zip'), ], [ 'name' => esc_html__('Visual Composer', 'anadbry'), 'slug' => 'js_composer', 'required' => true, 'source' => get_template_directory() . '/plugins/js_composer.zip', ], ]; $config = [ 'id' => 'wpw-tgmpa', 'default_path' => '', 'menu' => 'wpw-tgmpa-install-plugins', 'parent_slug' => 'themes.php', 'capability' => 'edit_theme_options', 'has_notices' => true, 'dismissable' => true, 'dismiss_msg' => '', 'is_automatic' => true, ]; tgmpa($plugins, $config); } add_action('tgmpa_register', 'anadbry_require_plugins'); /** * Remove plugin styles */ function anadbry_deregister_styles() { wp_deregister_style('contact-form-7'); wp_deregister_style('wp-pagenavi'); wp_deregister_style('imgareaselect'); } add_action('wp_print_styles', 'anadbry_deregister_styles', 100); add_filter('woocommerce_enqueue_styles', '__return_false'); /** * Change preloader for gform * @return string * @internal param $image_src * @internal param $form */ function anadbry_gform_spinner_url() { return Wpw::inst() ->path() ->resolve_url('@theme-url/assets/img/svg/loader.svg'); } add_filter('gform_ajax_spinner_url', 'anadbry_gform_spinner_url', 10, 2); /** * Control comment state from customizer */ function anadbry_customize_comment() { if (get_theme_mod('wpw_blog_enable_comments', true)) { update_option('default_comment_status', 'open'); } else { update_option('default_comment_status', 'close'); } } add_action('init', 'anadbry_customize_comment'); /** * Add custom classes for body * * @param $classes * @return array * @internal param Wpw $ith * @internal param $post_type */ function anadbry_body_class_filter($classes) { $ith = Wpw::inst(); $post_type = get_post_type(); $body_class = []; $metabox = $ith->metabox(); if (is_singular('product')) { $single_sidebar_position = null; $comments = null; $single_sidebar_position = get_theme_mod('wpw_product_sidebar_pos'); $single_sidebar_position = !empty($single_sidebar_position) ? $single_sidebar_position : 'none'; $body_class[] = 'single-sidebar-' . $single_sidebar_position; $body_class[] = 'wpw-sidebar-' . $single_sidebar_position; } elseif (is_post_type_archive('product') || is_tax('product_cat') || is_tax('product_tag')) { $single_sidebar_position = get_theme_mod('wpw_shop_sidebar_pos'); $single_sidebar_position = !empty($single_sidebar_position) ? $single_sidebar_position : 'none'; $body_class[] = 'portfolio-sidebar-' . $single_sidebar_position; $body_class[] = 'wpw-sidebar-' . $single_sidebar_position; } elseif (is_single()) { $single_sidebar_position = null; $comments = null; if ($post_type === 'portfolio') { $single_sidebar_position = get_theme_mod('wpw_portfolio_single_sidebar_pos'); $comments = get_theme_mod('wpw_portfolio_comments', true); } else { $single_sidebar_position = get_theme_mod('wpw_blog_sidebar_pos'); $comments = get_theme_mod('wpw_blog_enable_comments', true); } $single_sidebar_position = !empty($single_sidebar_position) ? $single_sidebar_position : 'right'; $comments = $comments ? 'on' : 'off'; $body_class[] = 'single-sidebar-' . $single_sidebar_position; $body_class[] = 'wpw-sidebar-' . $single_sidebar_position; $body_class[] = 'comments-' . $comments; } elseif (is_post_type_archive('portfolio') || is_tax('portfolio_categories')) { $single_sidebar_position = get_theme_mod('wpw_portfolio_archive_sidebar_pos'); $single_sidebar_position = !empty($single_sidebar_position) ? $single_sidebar_position : 'right'; $body_class[] = 'portfolio-sidebar-' . $single_sidebar_position; $body_class[] = 'wpw-sidebar-' . $single_sidebar_position; } elseif (!is_single() && !is_page()) { $list_sidebar_position = get_theme_mod('wpw_list_sidebar_pos'); $list_sidebar_position = !empty($list_sidebar_position) ? $list_sidebar_position : 'right'; $body_class[] = 'archive-sidebar-' . $list_sidebar_position; $body_class[] = 'wpw-sidebar-' . $list_sidebar_position; } elseif (is_page()) { $page_sidebar_position = $metabox->get(get_the_ID(), 'sidebar_pos'); if (empty($page_sidebar_position)) { $page_sidebar_position = get_theme_mod('wpw_page_sidebar_pos'); $page_sidebar_position = !empty($page_sidebar_position) ? $page_sidebar_position : 'none'; } $body_class[] = 'page-sidebar-' . $page_sidebar_position; $body_class[] = 'wpw-sidebar-' . $page_sidebar_position; } $post_format = $metabox->get(get_the_ID(), 'post_format'); if (!empty($post_format)) { $body_class[] = 'wpw-post-format-' . $post_format; } // scroll $config = get_theme_mod('wpw_scroll_element'); $config = !empty($config) ? json_decode(urldecode($config), true) : []; if (isset($config['enable_scroll']) && $config['enable_scroll']) { $body_class[] = 'wpw-custom-scroll'; // position $position = (isset($config['position']) && !empty($config['position']) && in_array($config['position'], ['right', 'left'])) ? $config['position'] : 'right'; $body_class[] = 'wpw-custom-scroll_position_' . $position; // animation $show = (isset($config['show']) && !empty($config['show']) && in_array($config['show'], [ 'always-animation', 'on-scroll', 'always', ])) ? $config['show'] : 'always-animation'; $body_class[] = 'wpw-custom-scroll_show_' . $show; } // preloader $config = get_theme_mod('wpw_preloader_element'); $config = !empty($config) ? json_decode(urldecode($config), true) : []; if (isset($config['enable_preloader']) && $config['enable_preloader']) { $body_class[] = 'wpw-custom-preloader'; $body_class[] = 'loading'; } return array_merge($classes, $body_class); } add_filter('body_class', 'anadbry_body_class_filter'); /** * Replace comment form fields * * @param $fields * @return mixed */ function anadbry_change_comment_form($fields) { $comment_field = $fields['comment']; unset($fields['comment']); $fields['comment'] = $comment_field; return $fields; } add_filter('comment_form_fields', 'anadbry_change_comment_form');