| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /** |
|---|
| 4 | * Square functions and definitions. |
|---|
| 5 | * |
|---|
| 6 | * @package Square |
|---|
| 7 | */ |
|---|
| 8 | if (!defined('SQUARE_VERSION')) { |
|---|
| 9 | $square_get_theme = wp_get_theme(); |
|---|
| 10 | $square_version = $square_get_theme->Version; |
|---|
| 11 | define('SQUARE_VERSION', $square_version); |
|---|
| 12 | } |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | if (!function_exists('square_setup')): |
|---|
| 16 | |
|---|
| 17 | //Sets up theme defaults and registers support for various WordPress features. |
|---|
| 18 | function square_setup() { |
|---|
| 19 | // Make theme available for translation. |
|---|
| 20 | load_theme_textdomain('square', get_template_directory() . '/languages'); |
|---|
| 21 | |
|---|
| 22 | // Add default posts and comments RSS feed links to head. |
|---|
| 23 | add_theme_support('automatic-feed-links'); |
|---|
| 24 | |
|---|
| 25 | //Let WordPress manage the document title. |
|---|
| 26 | add_theme_support('title-tag'); |
|---|
| 27 | |
|---|
| 28 | //Support for woocommerce |
|---|
| 29 | add_theme_support('woocommerce'); |
|---|
| 30 | add_theme_support('wc-product-gallery-zoom'); |
|---|
| 31 | add_theme_support('wc-product-gallery-lightbox'); |
|---|
| 32 | add_theme_support('wc-product-gallery-slider'); |
|---|
| 33 | |
|---|
| 34 | //Enable support for Post Thumbnails on posts and pages. |
|---|
| 35 | add_theme_support('post-thumbnails'); |
|---|
| 36 | add_image_size('square-about-thumb', 400, 420, true); |
|---|
| 37 | add_image_size('square-blog-thumb', 800, 420, true); |
|---|
| 38 | |
|---|
| 39 | // This theme uses wp_nav_menu() in one location. |
|---|
| 40 | register_nav_menus(array( |
|---|
| 41 | 'primary' => esc_html__('Primary Menu', 'square'), |
|---|
| 42 | )); |
|---|
| 43 | |
|---|
| 44 | /* |
|---|
| 45 | * Switch default core markup for search form, comment form, and comments |
|---|
| 46 | * to output valid HTML5. |
|---|
| 47 | */ |
|---|
| 48 | add_theme_support('html5', array( |
|---|
| 49 | 'comment-form', |
|---|
| 50 | 'comment-list', |
|---|
| 51 | 'gallery', |
|---|
| 52 | 'caption', |
|---|
| 53 | 'style', |
|---|
| 54 | 'script', |
|---|
| 55 | 'navigation-widgets' |
|---|
| 56 | )); |
|---|
| 57 | |
|---|
| 58 | // Set up the WordPress core custom background feature. |
|---|
| 59 | add_theme_support('custom-background', apply_filters('square_custom_background_args', array( |
|---|
| 60 | 'default-color' => 'ffffff', |
|---|
| 61 | 'default-image' => '', |
|---|
| 62 | ))); |
|---|
| 63 | |
|---|
| 64 | add_theme_support('custom-logo', array( |
|---|
| 65 | 'height' => 60, |
|---|
| 66 | 'width' => 300, |
|---|
| 67 | 'flex-height' => true, |
|---|
| 68 | 'flex-width' => true, |
|---|
| 69 | 'header-text' => array('.sq-site-title', '.sq-site-description'), |
|---|
| 70 | )); |
|---|
| 71 | |
|---|
| 72 | // Add theme support for selective refresh for widgets. |
|---|
| 73 | add_theme_support('customize-selective-refresh-widgets'); |
|---|
| 74 | |
|---|
| 75 | // Add support for responsive embedded content. |
|---|
| 76 | add_theme_support('responsive-embeds'); |
|---|
| 77 | |
|---|
| 78 | // Add support editor style. |
|---|
| 79 | add_theme_support('editor-styles'); |
|---|
| 80 | |
|---|
| 81 | // Add support for Block Styles. |
|---|
| 82 | add_theme_support('wp-block-styles'); |
|---|
| 83 | |
|---|
| 84 | /* |
|---|
| 85 | * This theme styles the visual editor to resemble the theme style, |
|---|
| 86 | * specifically font, colors, icons, and column width. |
|---|
| 87 | */ |
|---|
| 88 | add_editor_style(array('css/editor-style.css')); |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | endif; // square_setup |
|---|
| 92 | add_action('after_setup_theme', 'square_setup'); |
|---|
| 93 | |
|---|
| 94 | function square_content_width() { |
|---|
| 95 | $GLOBALS['content_width'] = apply_filters('square_content_width', 800); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | add_action('after_setup_theme', 'square_content_width', 0); |
|---|
| 99 | |
|---|
| 100 | //Enables the Excerpt meta box in Page edit screen. |
|---|
| 101 | function square_add_excerpt_support_for_pages() { |
|---|
| 102 | add_post_type_support('page', 'excerpt'); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | add_action('init', 'square_add_excerpt_support_for_pages'); |
|---|
| 106 | |
|---|
| 107 | //If Custom Logo is uploaded, remove the backward compatibility for header image |
|---|
| 108 | function square_remove_header_image() { |
|---|
| 109 | $custom_logo_enabled = get_theme_mod('square_custom_logo_enabled', false); |
|---|
| 110 | if (!$custom_logo_enabled && has_custom_logo()) { |
|---|
| 111 | set_theme_mod('square_custom_logo_enabled', true); |
|---|
| 112 | set_theme_mod('header_image', ''); |
|---|
| 113 | } |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | add_action('init', 'square_remove_header_image'); |
|---|
| 117 | |
|---|
| 118 | //Register widget area. |
|---|
| 119 | function square_widgets_init() { |
|---|
| 120 | register_sidebar(array( |
|---|
| 121 | 'name' => esc_html__('Right Sidebar', 'square'), |
|---|
| 122 | 'id' => 'square-right-sidebar', |
|---|
| 123 | 'description' => '', |
|---|
| 124 | 'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
|---|
| 125 | 'after_widget' => '</aside>', |
|---|
| 126 | 'before_title' => '<h4 class="widget-title">', |
|---|
| 127 | 'after_title' => '</h4>', |
|---|
| 128 | )); |
|---|
| 129 | |
|---|
| 130 | register_sidebar(array( |
|---|
| 131 | 'name' => esc_html__('Left Sidebar', 'square'), |
|---|
| 132 | 'id' => 'square-left-sidebar', |
|---|
| 133 | 'description' => '', |
|---|
| 134 | 'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
|---|
| 135 | 'after_widget' => '</aside>', |
|---|
| 136 | 'before_title' => '<h4 class="widget-title">', |
|---|
| 137 | 'after_title' => '</h4>', |
|---|
| 138 | )); |
|---|
| 139 | |
|---|
| 140 | register_sidebar(array( |
|---|
| 141 | 'name' => esc_html__('Shop Sidebar', 'square'), |
|---|
| 142 | 'id' => 'square-shop-sidebar', |
|---|
| 143 | 'description' => '', |
|---|
| 144 | 'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
|---|
| 145 | 'after_widget' => '</aside>', |
|---|
| 146 | 'before_title' => '<h4 class="widget-title">', |
|---|
| 147 | 'after_title' => '</h4>', |
|---|
| 148 | )); |
|---|
| 149 | |
|---|
| 150 | register_sidebar(array( |
|---|
| 151 | 'name' => esc_html__('Footer 1', 'square'), |
|---|
| 152 | 'id' => 'square-footer1', |
|---|
| 153 | 'description' => '', |
|---|
| 154 | 'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
|---|
| 155 | 'after_widget' => '</aside>', |
|---|
| 156 | 'before_title' => '<h5 class="widget-title">', |
|---|
| 157 | 'after_title' => '</h5>', |
|---|
| 158 | )); |
|---|
| 159 | |
|---|
| 160 | register_sidebar(array( |
|---|
| 161 | 'name' => esc_html__('Footer 2', 'square'), |
|---|
| 162 | 'id' => 'square-footer2', |
|---|
| 163 | 'description' => '', |
|---|
| 164 | 'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
|---|
| 165 | 'after_widget' => '</aside>', |
|---|
| 166 | 'before_title' => '<h5 class="widget-title">', |
|---|
| 167 | 'after_title' => '</h5>', |
|---|
| 168 | )); |
|---|
| 169 | |
|---|
| 170 | register_sidebar(array( |
|---|
| 171 | 'name' => esc_html__('Footer 3', 'square'), |
|---|
| 172 | 'id' => 'square-footer3', |
|---|
| 173 | 'description' => '', |
|---|
| 174 | 'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
|---|
| 175 | 'after_widget' => '</aside>', |
|---|
| 176 | 'before_title' => '<h5 class="widget-title">', |
|---|
| 177 | 'after_title' => '</h5>', |
|---|
| 178 | )); |
|---|
| 179 | |
|---|
| 180 | register_sidebar(array( |
|---|
| 181 | 'name' => esc_html__('Footer 4', 'square'), |
|---|
| 182 | 'id' => 'square-footer4', |
|---|
| 183 | 'description' => '', |
|---|
| 184 | 'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
|---|
| 185 | 'after_widget' => '</aside>', |
|---|
| 186 | 'before_title' => '<h5 class="widget-title">', |
|---|
| 187 | 'after_title' => '</h5>', |
|---|
| 188 | )); |
|---|
| 189 | |
|---|
| 190 | register_sidebar(array( |
|---|
| 191 | 'name' => esc_html__('About Footer', 'square'), |
|---|
| 192 | 'id' => 'square-about-footer', |
|---|
| 193 | 'description' => '', |
|---|
| 194 | 'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
|---|
| 195 | 'after_widget' => '</aside>', |
|---|
| 196 | 'before_title' => '<h5 class="widget-title">', |
|---|
| 197 | 'after_title' => '</h5>', |
|---|
| 198 | )); |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | add_action('widgets_init', 'square_widgets_init'); |
|---|
| 202 | |
|---|
| 203 | if (!function_exists('square_fonts_url')): |
|---|
| 204 | |
|---|
| 205 | /** |
|---|
| 206 | * Register Google fonts for Square. |
|---|
| 207 | * |
|---|
| 208 | * @since Square 1.0 |
|---|
| 209 | * |
|---|
| 210 | * @return string Google fonts URL for the theme. |
|---|
| 211 | */ |
|---|
| 212 | function square_fonts_url() { |
|---|
| 213 | $fonts_url = ''; |
|---|
| 214 | $fonts = $customizer_font_family = array(); |
|---|
| 215 | $subsets = 'latin,latin-ext'; |
|---|
| 216 | $all_fonts = square_all_fonts(); |
|---|
| 217 | $google_fonts = square_google_fonts(); |
|---|
| 218 | |
|---|
| 219 | $customizer_fonts = apply_filters('square_customizer_fonts', array( |
|---|
| 220 | 'square_body_family' => 'Open Sans', |
|---|
| 221 | 'square_menu_family' => 'Roboto Condensed', |
|---|
| 222 | 'square_h_family' => 'Roboto Condensed' |
|---|
| 223 | )); |
|---|
| 224 | |
|---|
| 225 | foreach ($customizer_fonts as $key => $value) { |
|---|
| 226 | $font = get_theme_mod($key, $value); |
|---|
| 227 | if (array_key_exists($font, $google_fonts)) { |
|---|
| 228 | $customizer_font_family[] = $font; |
|---|
| 229 | } |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | if ($customizer_font_family) { |
|---|
| 233 | $customizer_font_family = array_unique($customizer_font_family); |
|---|
| 234 | foreach ($customizer_font_family as $font_family) { |
|---|
| 235 | if (isset($all_fonts[$font_family]['variants'])) { |
|---|
| 236 | $variants_array = $all_fonts[$font_family]['variants']; |
|---|
| 237 | $variants_keys = array_keys($variants_array); |
|---|
| 238 | $variants = implode(',', $variants_keys); |
|---|
| 239 | |
|---|
| 240 | $fonts[] = $font_family . ':' . str_replace('italic', 'i', $variants); |
|---|
| 241 | } |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | if ($fonts) { |
|---|
| 245 | $fonts_url = add_query_arg(array( |
|---|
| 246 | 'family' => urlencode(implode('|', $fonts)), |
|---|
| 247 | 'subset' => urlencode($subsets), |
|---|
| 248 | 'display' => 'swap', |
|---|
| 249 | ), 'https://fonts.googleapis.com/css'); |
|---|
| 250 | } |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | return $fonts_url; |
|---|
| 254 | } |
|---|
| 255 | |
|---|
| 256 | endif; |
|---|
| 257 | |
|---|
| 258 | /** |
|---|
| 259 | * Enqueue scripts and styles. |
|---|
| 260 | */ |
|---|
| 261 | function square_scripts() { |
|---|
| 262 | wp_enqueue_script('modernizr', get_template_directory_uri() . '/js/modernizr.js', array(), SQUARE_VERSION, true); |
|---|
| 263 | wp_enqueue_script('owl-carousel', get_template_directory_uri() . '/js/owl.carousel.js', array('jquery'), SQUARE_VERSION, true); |
|---|
| 264 | wp_enqueue_script('jquery-superfish', get_template_directory_uri() . '/js/jquery.superfish.js', array('jquery'), SQUARE_VERSION, true); |
|---|
| 265 | |
|---|
| 266 | if (is_page_template('templates/home-template.php') || is_front_page()) { |
|---|
| 267 | wp_enqueue_script('square-draggabilly', get_template_directory_uri() . '/js/draggabilly.pkgd.min.js', array('jquery'), SQUARE_VERSION, true); |
|---|
| 268 | wp_enqueue_script('square-elastiStack', get_template_directory_uri() . '/js/elastiStack.js', array('jquery'), SQUARE_VERSION, true); |
|---|
| 269 | } |
|---|
| 270 | |
|---|
| 271 | wp_enqueue_script('square-custom', get_template_directory_uri() . '/js/square-custom.js', array('jquery'), SQUARE_VERSION, true); |
|---|
| 272 | wp_localize_script('square-custom', 'square_localize', array( |
|---|
| 273 | 'is_rtl' => is_rtl() ? 'true' : 'false' |
|---|
| 274 | )); |
|---|
| 275 | |
|---|
| 276 | wp_enqueue_style('animate', get_template_directory_uri() . '/css/animate.css', array(), SQUARE_VERSION); |
|---|
| 277 | wp_enqueue_style('font-awesome-v4-shims', get_template_directory_uri() . '/css/v4-shims.css', array(), SQUARE_VERSION); |
|---|
| 278 | wp_enqueue_style('font-awesome-6.3.0', get_template_directory_uri() . '/css/font-awesome-6.3.0.css', array(), SQUARE_VERSION); |
|---|
| 279 | wp_enqueue_style('owl-carousel', get_template_directory_uri() . '/css/owl.carousel.css', array(), SQUARE_VERSION); |
|---|
| 280 | wp_enqueue_style('square-style', get_stylesheet_uri(), array(), SQUARE_VERSION); |
|---|
| 281 | wp_style_add_data('square-style', 'rtl', 'replace'); |
|---|
| 282 | wp_add_inline_style('square-style', square_dymanic_styles()); |
|---|
| 283 | wp_enqueue_style('wp-block-library'); |
|---|
| 284 | |
|---|
| 285 | $fonts_url = square_fonts_url(); |
|---|
| 286 | $load_font_locally = get_theme_mod('square_load_google_font_locally', false); |
|---|
| 287 | if ($fonts_url && $load_font_locally) { |
|---|
| 288 | require_once get_theme_file_path('inc/wptt-webfont-loader.php'); |
|---|
| 289 | $fonts_url = wptt_get_webfont_url($fonts_url); |
|---|
| 290 | } |
|---|
| 291 | |
|---|
| 292 | // Load Fonts if necessary. |
|---|
| 293 | if ($fonts_url) { |
|---|
| 294 | wp_enqueue_style('square-fonts', $fonts_url, array(), NULL); |
|---|
| 295 | } |
|---|
| 296 | |
|---|
| 297 | if (is_singular() && comments_open() && get_option('thread_comments')) { |
|---|
| 298 | wp_enqueue_script('comment-reply'); |
|---|
| 299 | } |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | add_action('wp_enqueue_scripts', 'square_scripts'); |
|---|
| 303 | |
|---|
| 304 | add_action('wp_print_scripts', function () { |
|---|
| 305 | if (!is_admin()) { |
|---|
| 306 | return; |
|---|
| 307 | } |
|---|
| 308 | if (function_exists('get_current_screen') && get_current_screen() && get_current_screen()->is_block_editor() && get_current_screen()->base === 'post') { |
|---|
| 309 | echo '<style id="square-admin-css-vars">'; |
|---|
| 310 | echo square_dymanic_styles(); |
|---|
| 311 | echo '</style>'; |
|---|
| 312 | } |
|---|
| 313 | }); |
|---|
| 314 | |
|---|
| 315 | /** |
|---|
| 316 | * Enqueue admin style |
|---|
| 317 | */ |
|---|
| 318 | function square_admin_scripts() { |
|---|
| 319 | wp_enqueue_media(); |
|---|
| 320 | wp_enqueue_style('square-admin-style', get_template_directory_uri() . '/inc/css/admin-style.css', array(), SQUARE_VERSION); |
|---|
| 321 | wp_enqueue_script('square-admin-scripts', get_template_directory_uri() . '/inc/js/admin-scripts.js', array('jquery'), SQUARE_VERSION, true); |
|---|
| 322 | |
|---|
| 323 | $fonts_url = square_fonts_url(); |
|---|
| 324 | |
|---|
| 325 | // Load Fonts if necessary. |
|---|
| 326 | if ($fonts_url && function_exists('get_current_screen') && get_current_screen() && get_current_screen()->is_block_editor() && get_current_screen()->base === 'post') { |
|---|
| 327 | wp_enqueue_style('square-fonts', $fonts_url, array(), NULL); |
|---|
| 328 | } |
|---|
| 329 | } |
|---|
| 330 | |
|---|
| 331 | add_action('admin_enqueue_scripts', 'square_admin_scripts'); |
|---|
| 332 | add_action('elementor/editor/before_enqueue_scripts', 'square_admin_scripts'); |
|---|
| 333 | |
|---|
| 334 | if (!function_exists('wp_body_open')) { |
|---|
| 335 | |
|---|
| 336 | function wp_body_open() { |
|---|
| 337 | do_action('wp_body_open'); |
|---|
| 338 | } |
|---|
| 339 | |
|---|
| 340 | } |
|---|
| 341 | |
|---|
| 342 | add_filter('template_include', 'square_frontpage_template', 9999); |
|---|
| 343 | |
|---|
| 344 | function square_frontpage_template($template) { |
|---|
| 345 | if (is_front_page()) { |
|---|
| 346 | $enable_frontpage = get_theme_mod('square_enable_frontpage', false); |
|---|
| 347 | if ($enable_frontpage) { |
|---|
| 348 | $new_template = locate_template(array('templates/home-template.php')); |
|---|
| 349 | if ('' != $new_template) { |
|---|
| 350 | return $new_template; |
|---|
| 351 | } |
|---|
| 352 | } |
|---|
| 353 | } |
|---|
| 354 | return $template; |
|---|
| 355 | } |
|---|
| 356 | |
|---|
| 357 | /** |
|---|
| 358 | * Custom template tags for this theme. |
|---|
| 359 | */ |
|---|
| 360 | require get_template_directory() . '/inc/template-tags.php'; |
|---|
| 361 | |
|---|
| 362 | /** |
|---|
| 363 | * Custom functions that act independently of the theme templates. |
|---|
| 364 | */ |
|---|
| 365 | require get_template_directory() . '/inc/square-functions.php'; |
|---|
| 366 | |
|---|
| 367 | /** |
|---|
| 368 | * Customizer additions. |
|---|
| 369 | */ |
|---|
| 370 | require get_template_directory() . '/inc/customizer/customizer.php'; |
|---|
| 371 | |
|---|
| 372 | /** |
|---|
| 373 | * Load Woocommerce additions |
|---|
| 374 | */ |
|---|
| 375 | require get_template_directory() . '/inc/woo-functions.php'; |
|---|
| 376 | |
|---|
| 377 | /** |
|---|
| 378 | * Load Custom Metabox |
|---|
| 379 | */ |
|---|
| 380 | require get_template_directory() . '/inc/square-metabox.php'; |
|---|
| 381 | |
|---|
| 382 | /** |
|---|
| 383 | * Welcome Page. |
|---|
| 384 | */ |
|---|
| 385 | require get_template_directory() . '/welcome/welcome.php'; |
|---|
| 386 | |
|---|
| 387 | /** |
|---|
| 388 | * Dynamic Styles additions. |
|---|
| 389 | */ |
|---|
| 390 | require get_template_directory() . '/inc/style.php'; |
|---|
| 391 | /** |
|---|
| 392 | * Widgets additions. |
|---|
| 393 | */ |
|---|
| 394 | require get_template_directory() . '/inc/widgets/widget-fields.php'; |
|---|
| 395 | require get_template_directory() . '/inc/widgets/widget-contact-info.php'; |
|---|
| 396 | require get_template_directory() . '/inc/widgets/widget-personal-info.php'; |
|---|
| 397 | require get_template_directory() . '/inc/widgets/widget-latest-post.php'; |
|---|