/functions.php

  1. <?php 
  2.  
  3. /***** Fetch Theme Data & Options *****/ 
  4.  
  5. $mh_magazine_lite_data = wp_get_theme('mh-magazine-lite'); 
  6. $mh_magazine_lite_version = $mh_magazine_lite_data['Version']; 
  7. $mh_magazine_lite_options = get_option('mh_magazine_lite_options'); 
  8.  
  9. /***** Custom Hooks *****/ 
  10.  
  11. function mh_before_header() { 
  12. do_action('mh_before_header'); 
  13. function mh_after_header() { 
  14. do_action('mh_after_header'); 
  15. function mh_before_page_content() { 
  16. do_action('mh_before_page_content'); 
  17. function mh_before_post_content() { 
  18. do_action('mh_before_post_content'); 
  19. function mh_after_post_content() { 
  20. do_action('mh_after_post_content'); 
  21. function mh_post_header() { 
  22. do_action('mh_post_header'); 
  23. function mh_before_footer() { 
  24. do_action('mh_before_footer'); 
  25. function mh_after_footer() { 
  26. do_action('mh_after_footer'); 
  27. function mh_before_container_close() { 
  28. do_action('mh_before_container_close'); 
  29.  
  30. /***** Enable Shortcodes inside Widgets *****/ 
  31.  
  32. add_filter('widget_text', 'do_shortcode'); 
  33.  
  34. /***** Theme Setup *****/ 
  35.  
  36. if (!function_exists('mh_magazine_lite_setup')) { 
  37. function mh_magazine_lite_setup() { 
  38. load_theme_textdomain('mh-magazine-lite', get_template_directory() . '/languages'); 
  39. add_filter('use_default_gallery_style', '__return_false'); 
  40. add_theme_support('title-tag'); 
  41. add_theme_support('automatic-feed-links'); 
  42. add_theme_support('html5', array('comment-list', 'comment-form', 'search-form', 'gallery', 'caption')); 
  43. add_theme_support('post-thumbnails'); 
  44. add_theme_support('custom-background', array('default-color' => 'f7f7f7')); 
  45. add_theme_support('custom-header', array('default-image' => '', 'default-text-color' => '000', 'width' => 1080, 'height' => 250, 'flex-width' => true, 'flex-height' => true)); 
  46. add_theme_support('custom-logo', array('width' => 300, 'height' => 100, 'flex-width' => true, 'flex-height' => true)); 
  47. add_theme_support('customize-selective-refresh-widgets'); 
  48. register_nav_menu('main_nav', esc_html__('Main Navigation', 'mh-magazine-lite')); 
  49. add_editor_style(); 
  50. add_action('after_setup_theme', 'mh_magazine_lite_setup'); 
  51.  
  52. /***** Add Custom Image Sizes *****/ 
  53.  
  54. if (!function_exists('mh_magazine_lite_image_sizes')) { 
  55. function mh_magazine_lite_image_sizes() { 
  56. add_image_size('mh-magazine-lite-slider', 1030, 438, true); 
  57. add_image_size('mh-magazine-lite-content', 678, 381, true); 
  58. add_image_size('mh-magazine-lite-large', 678, 509, true); 
  59. add_image_size('mh-magazine-lite-medium', 326, 245, true); 
  60. add_image_size('mh-magazine-lite-small', 80, 60, true); 
  61. add_action('after_setup_theme', 'mh_magazine_lite_image_sizes'); 
  62.  
  63. /***** Set Content Width *****/ 
  64.  
  65. if (!function_exists('mh_magazine_lite_content_width')) { 
  66. function mh_magazine_lite_content_width() { 
  67. global $content_width; 
  68. if (!isset($content_width)) { 
  69. $content_width = 678; 
  70. add_action('template_redirect', 'mh_magazine_lite_content_width'); 
  71.  
  72. /***** Load CSS & JavaScript *****/ 
  73.  
  74. if (!function_exists('mh_magazine_lite_scripts')) { 
  75. function mh_magazine_lite_scripts() { 
  76. global $mh_magazine_lite_version; 
  77. wp_enqueue_style('mh-google-fonts', 'https://fonts.googleapis.com/css?family=Open+Sans:400, 400italic, 700, 600', array(), null); 
  78. wp_enqueue_style('mh-magazine-lite', get_stylesheet_uri(), false, $mh_magazine_lite_version); 
  79. wp_enqueue_style('mh-font-awesome', get_template_directory_uri() . '/includes/font-awesome.min.css', array(), null); 
  80. wp_enqueue_script('mh-scripts', get_template_directory_uri() . '/js/scripts.js', array('jquery'), $mh_magazine_lite_version); 
  81. if (is_singular() && comments_open() && get_option('thread_comments') == 1) { 
  82. wp_enqueue_script('comment-reply'); 
  83. add_action('wp_enqueue_scripts', 'mh_magazine_lite_scripts'); 
  84.  
  85. if (!function_exists('mh_magazine_lite_admin_scripts')) { 
  86. function mh_magazine_lite_admin_scripts($hook) { 
  87. if ('appearance_page_magazine' === $hook || 'widgets.php' === $hook) { 
  88. wp_enqueue_style('mh-admin', get_template_directory_uri() . '/admin/admin.css'); 
  89. add_action('admin_enqueue_scripts', 'mh_magazine_lite_admin_scripts'); 
  90.  
  91. /***** Register Widget Areas / Sidebars *****/ 
  92.  
  93. if (!function_exists('mh_magazine_lite_widgets_init')) { 
  94. function mh_magazine_lite_widgets_init() { 
  95. register_sidebar(array('name' => esc_html__('Sidebar', 'mh-magazine-lite'), 'id' => 'sidebar', 'description' => esc_html__('Widget area (sidebar left/right) on single posts, pages and archives.', 'mh-magazine-lite'), 'before_widget' => '<div id="%1$s" class="mh-widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h4 class="mh-widget-title"><span class="mh-widget-title-inner">', 'after_title' => '</span></h4>')); 
  96. register_sidebar(array('name' => sprintf(esc_html_x('Home %d - Full Width', 'widget area name', 'mh-magazine-lite'), 1), 'id' => 'home-1', 'description' => esc_html__('Widget area on homepage.', 'mh-magazine-lite'), 'before_widget' => '<div id="%1$s" class="mh-widget mh-home-1 mh-home-wide %2$s">', 'after_widget' => '</div>', 'before_title' => '<h4 class="mh-widget-title"><span class="mh-widget-title-inner">', 'after_title' => '</span></h4>')); 
  97. register_sidebar(array('name' => sprintf(esc_html_x('Home %d - 2/3 Width', 'widget area name', 'mh-magazine-lite'), 2), 'id' => 'home-2', 'description' => esc_html__('Widget area on homepage.', 'mh-magazine-lite'), 'before_widget' => '<div id="%1$s" class="mh-widget mh-home-2 mh-widget-col-2 %2$s">', 'after_widget' => '</div>', 'before_title' => '<h4 class="mh-widget-title"><span class="mh-widget-title-inner">', 'after_title' => '</span></h4>')); 
  98. register_sidebar(array('name' => sprintf(esc_html_x('Home %d - 1/3 Width', 'widget area name', 'mh-magazine-lite'), 3), 'id' => 'home-3', 'description' => esc_html__('Widget area on homepage.', 'mh-magazine-lite'), 'before_widget' => '<div id="%1$s" class="mh-widget mh-home-3 %2$s">', 'after_widget' => '</div>', 'before_title' => '<h4 class="mh-widget-title"><span class="mh-widget-title-inner">', 'after_title' => '</span></h4>')); 
  99. register_sidebar(array('name' => sprintf(esc_html_x('Home %d - 1/3 Width', 'widget area name', 'mh-magazine-lite'), 4), 'id' => 'home-4', 'description' => esc_html__('Widget area on homepage.', 'mh-magazine-lite'), 'before_widget' => '<div id="%1$s" class="mh-widget mh-home-4 %2$s">', 'after_widget' => '</div>', 'before_title' => '<h4 class="mh-widget-title"><span class="mh-widget-title-inner">', 'after_title' => '</span></h4>')); 
  100. register_sidebar(array('name' => sprintf(esc_html_x('Home %d - 2/3 Width', 'widget area name', 'mh-magazine-lite'), 5), 'id' => 'home-5', 'description' => esc_html__('Widget area on homepage.', 'mh-magazine-lite'), 'before_widget' => '<div id="%1$s" class="mh-widget mh-home-5 mh-widget-col-2 %2$s">', 'after_widget' => '</div>', 'before_title' => '<h4 class="mh-widget-title"><span class="mh-widget-title-inner">', 'after_title' => '</span></h4>')); 
  101. register_sidebar(array('name' => sprintf(esc_html_x('Home %d - 1/3 Width', 'widget area name', 'mh-magazine-lite'), 6), 'id' => 'home-6', 'description' => esc_html__('Widget area on homepage.', 'mh-magazine-lite'), 'before_widget' => '<div id="%1$s" class="mh-widget mh-home-6 %2$s">', 'after_widget' => '</div>', 'before_title' => '<h4 class="mh-widget-title"><span class="mh-widget-title-inner">', 'after_title' => '</span></h4>')); 
  102. register_sidebar(array('name' => sprintf(esc_html_x('Posts %d - Advertisement', 'widget area name', 'mh-magazine-lite'), 1), 'id' => 'posts-1', 'description' => esc_html__('Widget area above single post content.', 'mh-magazine-lite'), 'before_widget' => '<div id="%1$s" class="mh-widget mh-posts-1 %2$s">', 'after_widget' => '</div>', 'before_title' => '<h4 class="mh-widget-title"><span class="mh-widget-title-inner">', 'after_title' => '</span></h4>')); 
  103. register_sidebar(array('name' => sprintf(esc_html_x('Posts %d - Advertisement', 'widget area name', 'mh-magazine-lite'), 2), 'id' => 'posts-2', 'description' => esc_html__('Widget area below single post content.', 'mh-magazine-lite'), 'before_widget' => '<div id="%1$s" class="mh-widget mh-posts-2 %2$s">', 'after_widget' => '</div>', 'before_title' => '<h4 class="mh-widget-title"><span class="mh-widget-title-inner">', 'after_title' => '</span></h4>')); 
  104. register_sidebar(array('name' => sprintf(esc_html_x('Footer %d - 1/4 Width', 'widget area name', 'mh-magazine-lite'), 1), 'id' => 'footer-1', 'description' => esc_html__('Widget area in footer.', 'mh-magazine-lite'), 'before_widget' => '<div id="%1$s" class="mh-footer-widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h6 class="mh-widget-title mh-footer-widget-title"><span class="mh-widget-title-inner mh-footer-widget-title-inner">', 'after_title' => '</span></h6>')); 
  105. register_sidebar(array('name' => sprintf(esc_html_x('Footer %d - 1/4 Width', 'widget area name', 'mh-magazine-lite'), 2), 'id' => 'footer-2', 'description' => esc_html__('Widget area in footer.', 'mh-magazine-lite'), 'before_widget' => '<div id="%1$s" class="mh-footer-widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h6 class="mh-widget-title mh-footer-widget-title"><span class="mh-widget-title-inner mh-footer-widget-title-inner">', 'after_title' => '</span></h6>')); 
  106. register_sidebar(array('name' => sprintf(esc_html_x('Footer %d - 1/4 Width', 'widget area name', 'mh-magazine-lite'), 3), 'id' => 'footer-3', 'description' => esc_html__('Widget area in footer.', 'mh-magazine-lite'), 'before_widget' => '<div id="%1$s" class="mh-footer-widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h6 class="mh-widget-title mh-footer-widget-title"><span class="mh-widget-title-inner mh-footer-widget-title-inner">', 'after_title' => '</span></h6>')); 
  107. register_sidebar(array('name' => sprintf(esc_html_x('Footer %d - 1/4 Width', 'widget area name', 'mh-magazine-lite'), 4), 'id' => 'footer-4', 'description' => esc_html__('Widget area in footer.', 'mh-magazine-lite'), 'before_widget' => '<div id="%1$s" class="mh-footer-widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h6 class="mh-widget-title mh-footer-widget-title"><span class="mh-widget-title-inner mh-footer-widget-title-inner">', 'after_title' => '</span></h6>')); 
  108. add_action('widgets_init', 'mh_magazine_lite_widgets_init'); 
  109.  
  110. /***** Include Several Functions *****/ 
  111.  
  112. if (is_admin()) { 
  113. require_once('admin/admin.php'); 
  114.  
  115. require_once('includes/mh-customizer.php'); 
  116. require_once('includes/mh-widgets.php'); 
  117. require_once('includes/mh-custom-functions.php'); 
  118. require_once('includes/mh-compatibility.php'); 
  119.  
  120. /***** Add Support for WooCommerce *****/ 
  121.  
  122. include_once(ABSPATH . 'wp-admin/includes/plugin.php'); 
  123.  
  124. if (is_plugin_active('woocommerce/woocommerce.php')) { 
  125. require_once('woocommerce/mh-custom-woocommerce.php'); 
  126.  
  127. ?> 
.