Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 46.51 KB | None | 0 0
  1. <?php
  2. /**
  3. * Functions.php => This is where the magic happens.
  4. *
  5. * IMPORTANT: DO NOT USE AN ILLEGAL COPY OF THIS THEME !!!
  6. * IMPORTANT: DO NOT EVER EDIT THIS FILE !!!!
  7. * IMPORTANT: DO NOT EVER COPY AND PASTE ANYTHING FROM THIS FILE TO YOUR CHILD THEME !!!
  8. * IMPORTANT: DO NOT COPY AND PASTE THIS FILE INTO YOUR CHILD THEME !!!
  9. * IMPORTANT: DO USE HOOKS, FILTERS & TEMPLATE PARTS TO ALTER THIS THEME
  10. *
  11. * Total is a very powerful theme and virtually anything can be customized
  12. * via a child theme. If you need any help altering a function, just let us know!
  13. * Customizations aren't included with your purchase but if it's a simple task we can assist :)
  14. *
  15. * Theme Docs : http://wpexplorer-themes.com/total/docs/
  16. * Using Hooks : http://wpexplorer-themes.com/total/docs/action-hooks/
  17. * Filters Reference : http://www.wpexplorer.com/docs/total-wordpress-theme-filters/
  18. * Theme Support : http://wpexplorer-themes.com/support/ (valid purchase required)
  19. *
  20. * @package Total WordPress Theme
  21. * @subpackage Templates
  22. * @version 3.6.0
  23. */
  24.  
  25. // Exit if accessed directly
  26. if ( ! defined( 'ABSPATH' ) ) {
  27. exit;
  28. }
  29.  
  30. // Core Constants
  31. define( 'TOTAL_THEME_ACTIVE', true );
  32. define( 'WPEX_THEME_VERSION', '3.6.0' );
  33. define( 'WPEX_VC_SUPPORTED_VERSION', '4.12.1' );
  34.  
  35. define( 'WPEX_THEME_DIR', get_template_directory() );
  36. define( 'WPEX_THEME_URI', get_template_directory_uri() );
  37.  
  38. // Start up class
  39. class WPEX_Theme_Setup {
  40.  
  41. /**
  42. * Main Theme Class Constructor
  43. *
  44. * Loads all necessary classes, functions, hooks, configuration files and actions for the theme.
  45. * Everything starts here.
  46. *
  47. * @since 1.6.0
  48. *
  49. */
  50. public function __construct() {
  51.  
  52. // Perform actions after updating => Run before anything else
  53. require_once( WPEX_THEME_DIR .'/framework/updates/after-update.php' );
  54.  
  55. // Define globals
  56. global $wpex_theme, $wpex_theme_mods;
  57.  
  58. // Gets all theme mods and stores them in an easily accessable global var to limit DB requests
  59. $wpex_theme_mods = get_theme_mods();
  60.  
  61. // Functions used to retrieve theme mods.
  62. // Loaded early so it can be used on all hooks.
  63. // Requires $wpex_theme_mods global var to be defined first => look up!
  64. require_once( WPEX_THEME_DIR .'/framework/get_mods.php' );
  65.  
  66. // Include conditional functions early so we can use them anywhere
  67. require_once( WPEX_THEME_DIR .'/framework/conditionals.php' );
  68.  
  69. // Include global object class early so it can be used anywhere needed.
  70. // This is important because when inserting VC modules we must re-run the class object at times
  71. require_once( WPEX_THEME_DIR .'/framework/classes/global-object.php' );
  72.  
  73. // Define constants
  74. add_action( 'after_setup_theme', array( 'WPEX_Theme_Setup', 'constants' ), 0 );
  75.  
  76. // Load all core theme function files
  77. // Load Before classes and addons so we can make use of them
  78. add_action( 'after_setup_theme', array( 'WPEX_Theme_Setup', 'include_functions' ), 1 );
  79.  
  80. // Load all the theme addons - must run on this hook!!!
  81. add_action( 'after_setup_theme', array( 'WPEX_Theme_Setup', 'addons' ), 2 );
  82.  
  83. // Load configuration classes (post types & 3rd party plugins)
  84. // Must load first so it can use hooks defined in the classes
  85. add_action( 'after_setup_theme', array( 'WPEX_Theme_Setup', 'configs' ), 3 );
  86.  
  87. // Load framework classes
  88. add_action( 'after_setup_theme', array( 'WPEX_Theme_Setup', 'classes' ), 4 );
  89.  
  90. // Setup theme => add_theme_support, register_nav_menus, load_theme_textdomain, etc
  91. // Must run on 10 priority or else child theme locale will be overritten
  92. add_action( 'after_setup_theme', array( 'WPEX_Theme_Setup', 'theme_setup' ), 10 );
  93.  
  94. // Defines hooks and adds theme actions
  95. // Moved to after_setup_theme hook in v3.6.0 so it can be accessed earlier if needed
  96. // to remove actions
  97. add_action( 'after_setup_theme', array( 'WPEX_Theme_Setup', 'hooks_actions' ), 10 );
  98.  
  99. // Populate the global object
  100. // Must be done early on to prevent issues with plugins altering templates
  101. // But must run after WP has loaded so conditionals work
  102. add_action( 'template_redirect', array( 'WPEX_Theme_Setup', 'global_object' ), 0 );
  103.  
  104. // Run after switch theme
  105. add_action( 'after_switch_theme', array( 'WPEX_Theme_Setup', 'after_switch_theme' ) );
  106.  
  107. // Load custom widgets
  108. add_action( 'widgets_init', array( 'WPEX_Theme_Setup', 'custom_widgets' ), 10 );
  109.  
  110. // Register sidebar widget areas
  111. add_action( 'widgets_init', array( 'WPEX_Theme_Setup', 'register_sidebars' ) );
  112.  
  113. // Register footer widgets
  114. add_action( 'widgets_init', array( 'WPEX_Theme_Setup', 'footer_widgets' ), 40 );
  115.  
  116. /** Admin only actions **/
  117. if ( is_admin() ) {
  118.  
  119. // Load scripts in the WP admin
  120. add_action( 'admin_enqueue_scripts', array( 'WPEX_Theme_Setup', 'admin_font_awesome' ) );
  121.  
  122. // Outputs custom CSS for the admin
  123. add_action( 'admin_head', array( 'WPEX_Theme_Setup', 'admin_inline_css' ) );
  124.  
  125. // Add new social profile fields to the user dashboard
  126. add_filter( 'user_contactmethods', array( 'WPEX_Theme_Setup', 'add_user_social_fields' ) );
  127.  
  128. // Remove wpex_term_data when a term is removed
  129. add_action( 'delete_term', array( 'WPEX_Theme_Setup', 'delete_term' ), 5 );
  130.  
  131. /** Non Admin actions **/
  132. } else {
  133.  
  134. // Load theme CSS
  135. add_action( 'wp_enqueue_scripts', array( 'WPEX_Theme_Setup', 'theme_css' ) );
  136.  
  137. // Browser dependent CSS
  138. add_action( 'wp_enqueue_scripts', array( 'WPEX_Theme_Setup', 'browser_dependent_css' ), 40 );
  139.  
  140. // Load RTL CSS right before responsive
  141. add_action( 'wp_enqueue_scripts', array( 'WPEX_Theme_Setup', 'rtl_css' ), 98 );
  142.  
  143. // Load responsive CSS - must be added last
  144. add_action( 'wp_enqueue_scripts', array( 'WPEX_Theme_Setup', 'responsive_css' ), 99 );
  145.  
  146. // Load theme js => High priority so after js_composer
  147. add_action( 'wp_enqueue_scripts', array( 'WPEX_Theme_Setup', 'theme_js' ) );
  148.  
  149. // Exclude categories from the blog page
  150. add_action( 'pre_get_posts', array( 'WPEX_Theme_Setup', 'pre_get_posts' ) );
  151.  
  152. // Redirect posts with custom links
  153. add_filter( 'template_redirect', array( 'WPEX_Theme_Setup', 'redirect_custom_links' ) );
  154.  
  155. // Add meta viewport tag to header
  156. add_action( 'wp_head', array( 'WPEX_Theme_Setup', 'meta_viewport' ), 1 );
  157.  
  158. // Add theme meta generator
  159. add_action( 'wp_head', array( 'WPEX_Theme_Setup', 'theme_meta_generator' ), 1 );
  160.  
  161. // Add an X-UA-Compatible header
  162. add_filter( 'wp_headers', array( 'WPEX_Theme_Setup', 'x_ua_compatible_headers' ) );
  163.  
  164. // Outputs custom CSS to the head
  165. add_action( 'wp_head', array( 'WPEX_Theme_Setup', 'custom_css' ), 9999 );
  166.  
  167. // Alter tagcloud widget to display all tags with 1em font size
  168. add_filter( 'widget_tag_cloud_args', array( 'WPEX_Theme_Setup', 'widget_tag_cloud_args' ) );
  169.  
  170. // Alter WP categories widget to display count inside a span
  171. add_filter( 'wp_list_categories', array( 'WPEX_Theme_Setup', 'wp_list_categories_args' ) );
  172.  
  173. // Add a responsive wrapper to the WordPress oembed output
  174. add_filter( 'embed_oembed_html', array( 'WPEX_Theme_Setup', 'oembed_html' ), 99, 4 );
  175.  
  176. // Allow for the use of shortcodes in the WordPress excerpt
  177. add_filter( 'the_excerpt', 'shortcode_unautop' );
  178. add_filter( 'the_excerpt', 'do_shortcode' );
  179.  
  180. // Make sure the wp_get_attachment_url() function returns correct page request (HTTP or HTTPS)
  181. add_filter( 'wp_get_attachment_url', array( 'WPEX_Theme_Setup', 'honor_ssl_for_attachments' ) );
  182.  
  183. // Tweak the default password protection output form
  184. add_filter( 'the_password_form', array( 'WPEX_Theme_Setup', 'custom_password_protected_form' ) );
  185.  
  186. // Exclude posts with custom links from the next and previous post links
  187. add_filter( 'get_previous_post_join', array( 'WPEX_Theme_Setup', 'prev_next_join' ) );
  188. add_filter( 'get_next_post_join', array( 'WPEX_Theme_Setup', 'prev_next_join' ) );
  189. add_filter( 'get_previous_post_where', array( 'WPEX_Theme_Setup', 'prev_next_where' ) );
  190. add_filter( 'get_next_post_where', array( 'WPEX_Theme_Setup', 'prev_next_where' ) );
  191.  
  192. // Remove emoji scripts
  193. if ( wpex_get_mod( 'remove_emoji_scripts_enable', true ) ) {
  194. remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
  195. remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
  196. remove_action( 'wp_print_styles', 'print_emoji_styles' );
  197. remove_action( 'admin_print_styles', 'print_emoji_styles' );
  198. }
  199.  
  200. // Adds classes the post class
  201. add_filter( 'post_class', array( 'WPEX_Theme_Setup', 'post_class' ) );
  202.  
  203. // Add schema markup to the authors post link
  204. add_filter( 'the_author_posts_link', array( 'WPEX_Theme_Setup', 'the_author_posts_link' ) );
  205.  
  206. // Move Comment textarea form field back to bottom
  207. add_filter( 'comment_form_fields', array( 'WPEX_Theme_Setup', 'move_comment_form_fields' ) );
  208.  
  209. // Disable WP responsive images if retina is enabled
  210. if ( wpex_is_retina_enabled() ) {
  211. add_filter( 'wp_calculate_image_srcset', '__return_false' );
  212. }
  213.  
  214. // Disable canonical redirect on the homepage when using pagination via VC modules
  215. add_filter( 'redirect_canonical', array( 'WPEX_Theme_Setup', 'home_pagination_fix' ) );
  216.  
  217. // Filter kses protocols
  218. add_filter( 'kses_allowed_protocols' , array( 'WPEX_Theme_Setup', 'kses_allowed_protocols' ) );
  219.  
  220. // Filter comment link for smooth scrolling
  221. add_filter( 'get_comments_link', array( 'WPEX_Theme_Setup', 'get_comments_link' ), 10, 2 );
  222. add_filter( 'respond_link', array( 'WPEX_Theme_Setup', 'get_comments_link' ), 10, 2 );
  223.  
  224. // Allow shortcodes in menus
  225. add_filter( 'wp_nav_menu_items', 'do_shortcode' );
  226.  
  227. } // Non admin functions
  228.  
  229. } // End constructor
  230.  
  231. /**
  232. * Defines the constants for use within the theme.
  233. *
  234. * @since 2.0.0
  235. */
  236. public static function constants() {
  237.  
  238. // Theme branding
  239. define( 'WPEX_THEME_BRANDING', wpex_get_mod( 'theme_branding', 'Total' ) );
  240.  
  241. // Theme Panel slug
  242. define( 'WPEX_THEME_PANEL_SLUG', 'wpex-panel' );
  243. define( 'WPEX_ADMIN_PANEL_HOOK_PREFIX', 'theme-panel_page_'. WPEX_THEME_PANEL_SLUG );
  244.  
  245. // Framework Paths
  246. define( 'WPEX_FRAMEWORK_DIR', WPEX_THEME_DIR .'/framework/' );
  247. define( 'WPEX_FRAMEWORK_DIR_URI', WPEX_THEME_URI .'/framework/' );
  248.  
  249. // Classes directory
  250. define( 'WPEX_ClASSES_DIR', WPEX_FRAMEWORK_DIR .'classes/' );
  251.  
  252. // Check if plugins are active
  253. define( 'WPEX_VC_ACTIVE', class_exists( 'Vc_Manager' ) );
  254. define( 'WPEX_BBPRESS_ACTIVE', class_exists( 'bbPress' ) );
  255. define( 'WPEX_WOOCOMMERCE_ACTIVE', class_exists( 'WooCommerce' ) );
  256. define( 'WPEX_WPML_ACTIVE', class_exists( 'SitePress' ) );
  257.  
  258. // Active post types
  259. define( 'WPEX_PORTFOLIO_IS_ACTIVE', wpex_get_mod( 'portfolio_enable', true ) );
  260. define( 'WPEX_STAFF_IS_ACTIVE', wpex_get_mod( 'staff_enable', true ) );
  261. define( 'WPEX_TESTIMONIALS_IS_ACTIVE', wpex_get_mod( 'testimonials_enable', true ) );
  262.  
  263. }
  264.  
  265. /**
  266. * Defines all theme hooks and runs all needed actions for theme hooks.
  267. *
  268. * @since 2.0.0
  269. */
  270. public static function hooks_actions() {
  271.  
  272. // Register hooks (needed in admin for Custom Actions panel)
  273. require_once( WPEX_FRAMEWORK_DIR .'hooks/hooks.php' );
  274.  
  275. // Front-end stuff
  276. if ( ! is_admin() ) {
  277. require_once( WPEX_FRAMEWORK_DIR .'hooks/actions.php' );
  278. require_once( WPEX_FRAMEWORK_DIR .'hooks/partials.php' );
  279. }
  280.  
  281. }
  282.  
  283. /**
  284. * Framework functions
  285. * Load before Classes & Addons so we can use them
  286. *
  287. * @since 2.0.0
  288. */
  289. public static function include_functions() {
  290.  
  291. // Needed in front-end and back-end
  292. require_once( WPEX_FRAMEWORK_DIR .'deprecated.php' );
  293. require_once( WPEX_FRAMEWORK_DIR .'core-functions.php' );
  294. require_once( WPEX_FRAMEWORK_DIR .'arrays.php' );
  295. require_once( WPEX_FRAMEWORK_DIR .'shortcodes/shortcodes.php' );
  296. require_once( WPEX_FRAMEWORK_DIR .'helper-functions/fonts.php' );
  297. require_once( WPEX_FRAMEWORK_DIR .'helper-functions/overlays.php' );
  298.  
  299. // Admin only functions
  300. if ( is_admin() ) {
  301. require_once( WPEX_FRAMEWORK_DIR .'disable-wp-update-check.php' );
  302. }
  303.  
  304. // Front-end functions only
  305. else {
  306. require_once( WPEX_FRAMEWORK_DIR .'body-classes.php' );
  307. require_once( WPEX_FRAMEWORK_DIR .'helper-functions/header.php' );
  308. require_once( WPEX_FRAMEWORK_DIR .'helper-functions/menu.php' );
  309. require_once( WPEX_FRAMEWORK_DIR .'helper-functions/title.php' );
  310. require_once( WPEX_FRAMEWORK_DIR .'helper-functions/page-header.php' );
  311. require_once( WPEX_FRAMEWORK_DIR .'helper-functions/excerpts.php' );
  312. require_once( WPEX_FRAMEWORK_DIR .'helper-functions/pagination.php' );
  313. require_once( WPEX_FRAMEWORK_DIR .'helper-functions/blog.php' );
  314. require_once( WPEX_FRAMEWORK_DIR .'helper-functions/instagram-feed.php' );
  315. }
  316.  
  317. }
  318.  
  319. /**
  320. * Include Theme Panel class which loads various add-on functions
  321. *
  322. * @since 2.0.0
  323. */
  324. public static function addons() {
  325. require_once( WPEX_FRAMEWORK_DIR .'addons/theme-panel.php' );
  326. }
  327.  
  328. /**
  329. * Configs for post types and 3rd party plugins.
  330. *
  331. * @since 2.0.0
  332. */
  333. public static function configs() {
  334.  
  335. // Portfolio
  336. if ( WPEX_PORTFOLIO_IS_ACTIVE ) {
  337. require_once( WPEX_FRAMEWORK_DIR .'portfolio/portfolio-config.php' );
  338. }
  339.  
  340. // Staff
  341. if ( WPEX_STAFF_IS_ACTIVE ) {
  342. require_once( WPEX_FRAMEWORK_DIR .'staff/staff-config.php' );
  343. }
  344.  
  345. // Testimonias
  346. if ( WPEX_TESTIMONIALS_IS_ACTIVE ) {
  347. require_once( WPEX_FRAMEWORK_DIR .'testimonials/testimonials-config.php' );
  348. }
  349.  
  350. // WooCommerce
  351. if ( WPEX_WOOCOMMERCE_ACTIVE ) {
  352. require_once( WPEX_FRAMEWORK_DIR .'woocommerce/woocommerce-config.php' );
  353. }
  354.  
  355. // Visual Composer
  356. if ( WPEX_VC_ACTIVE ) {
  357. require_once( WPEX_FRAMEWORK_DIR .'visual-composer/vc-config.php' );
  358. }
  359.  
  360. // The Events Calendar
  361. if ( class_exists( 'Tribe__Events__Main' ) ) {
  362. require_once( WPEX_FRAMEWORK_DIR .'tribe-events/tribe-events-config.php' );
  363. }
  364.  
  365. // WPML
  366. if ( WPEX_WPML_ACTIVE ) {
  367. require_once( WPEX_FRAMEWORK_DIR .'3rd-party/wpml.php' );
  368. }
  369.  
  370. // Polylang
  371. if ( class_exists( 'Polylang' ) ) {
  372. require_once( WPEX_FRAMEWORK_DIR .'3rd-party/polylang.php' );
  373. }
  374.  
  375. // bbPress
  376. if ( WPEX_BBPRESS_ACTIVE ) {
  377. require_once( WPEX_FRAMEWORK_DIR .'bbpress/bbpress-config.php' );
  378. }
  379.  
  380. // Sensei
  381. if ( function_exists( 'Sensei' ) ) {
  382. require_once( WPEX_FRAMEWORK_DIR .'3rd-party/sensei.php' );
  383. }
  384.  
  385. // Yoast SEO
  386. if ( defined( 'WPSEO_VERSION' ) ) {
  387. require_once( WPEX_FRAMEWORK_DIR .'3rd-party/yoast.php' );
  388. }
  389.  
  390. // Contact From 7
  391. if ( defined( 'WPCF7_VERSION' ) ) {
  392. require_once( WPEX_FRAMEWORK_DIR .'3rd-party/contact-form-7.php' );
  393. }
  394.  
  395. // Revolution
  396. if ( class_exists( 'RevSlider' ) ) {
  397. require_once( WPEX_FRAMEWORK_DIR .'3rd-party/revslider.php' );
  398. }
  399.  
  400. // LayerSlider
  401. if ( class_exists( 'LS_Sliders' ) ) {
  402. require_once( WPEX_FRAMEWORK_DIR .'3rd-party/layerslider.php' );
  403. }
  404.  
  405. // JetPack
  406. if ( class_exists( 'Jetpack' ) ) {
  407. require_once( WPEX_FRAMEWORK_DIR .'3rd-party/jetpack.php' );
  408. }
  409.  
  410. // Gravity Forms
  411. if ( class_exists( 'RGForms' ) ) {
  412. require_once( WPEX_FRAMEWORK_DIR .'3rd-party/gravity-forms.php' );
  413. }
  414.  
  415. // Post types UI
  416. if ( function_exists( 'cptui_init' ) ) {
  417. require_once( WPEX_FRAMEWORK_DIR .'cpt-ui/types.php' );
  418. }
  419.  
  420. }
  421.  
  422. /**
  423. * Framework Classes
  424. *
  425. * @since 2.0.0
  426. */
  427. public static function classes() {
  428.  
  429. // Sanitize input
  430. require_once( WPEX_ClASSES_DIR .'sanitize-data.php' );
  431.  
  432. // iLightbox
  433. require_once( WPEX_ClASSES_DIR .'ilightbox.php' );
  434.  
  435. // Image Resize
  436. require_once( WPEX_ClASSES_DIR .'image-resize.php' );
  437.  
  438. // Gallery metabox
  439. require_once( WPEX_ClASSES_DIR .'gallery-metabox.php' );
  440.  
  441. // Term colors - @todo
  442. //require_once( WPEX_ClASSES_DIR .'term-colors.php' );
  443.  
  444. // Post Series
  445. if ( wpex_get_mod( 'post_series_enable', true ) ) {
  446. require_once( WPEX_ClASSES_DIR .'post-series.php' );
  447. }
  448.  
  449. // Custom WP header
  450. if ( wpex_get_mod( 'header_image_enable' ) ) {
  451. require_once( WPEX_ClASSES_DIR .'custom-header.php' );
  452. }
  453.  
  454. // Term meta
  455. require_once( WPEX_ClASSES_DIR .'term-meta.php' );
  456.  
  457. // Term thumbnails
  458. if ( wpex_get_mod( 'term_thumbnails_enable', true ) ) {
  459. require_once( WPEX_ClASSES_DIR .'term-thumbnails.php' );
  460. }
  461.  
  462. // Remove post type slugs
  463. if ( wpex_get_mod( 'remove_posttype_slugs' ) ) {
  464. require_once( WPEX_ClASSES_DIR .'remove-post-type-slugs.php' );
  465. }
  466.  
  467. // Image sizes panel
  468. if ( wpex_get_mod( 'image_sizes_enable', true ) ) {
  469. require_once( WPEX_ClASSES_DIR .'image-sizes.php' );
  470. }
  471.  
  472. // Admin only classes
  473. if ( is_admin() ) {
  474.  
  475. // Recommend plugins
  476. if ( wpex_recommended_plugins() && wpex_get_mod( 'recommend_plugins_enable', true ) ) {
  477. require_once( WPEX_ClASSES_DIR .'class-tgm-plugin-activation.php' );
  478. require_once( WPEX_FRAMEWORK_DIR .'3rd-party/tgm-plugin-activation.php' );
  479. }
  480.  
  481. // Plugins updater
  482. // Won't work with multisite because of how themes work.
  483. require_once( WPEX_ClASSES_DIR .'plugins-updater.php' );
  484.  
  485. // Category meta
  486. require_once( WPEX_ClASSES_DIR .'category-meta.php' );
  487.  
  488. // Metabox => Page Settings
  489. require_once( WPEX_ClASSES_DIR .'post-metabox.php' );
  490.  
  491. // Custom attachment fields
  492. require_once( WPEX_ClASSES_DIR .'attachment-fields.php' );
  493.  
  494. }
  495.  
  496. // Front-end classes
  497. else {
  498.  
  499. // Accent color
  500. require_once( WPEX_ClASSES_DIR .'accent-color.php' );
  501.  
  502. // Border color
  503. require_once( WPEX_ClASSES_DIR .'border-colors.php' );
  504.  
  505. // Site backgrounds
  506. require_once( WPEX_ClASSES_DIR .'site-backgrounds.php' );
  507.  
  508. // Advanced styling
  509. require_once( WPEX_ClASSES_DIR .'advanced-styling.php' );
  510.  
  511. // Breadcrumbs class
  512. require_once( WPEX_ClASSES_DIR .'breadcrumbs.php' );
  513.  
  514. }
  515.  
  516. // Disable Google Services
  517. if ( wpex_disable_google_services() ) {
  518. require_once( WPEX_ClASSES_DIR .'disable-google-services.php' );
  519. }
  520.  
  521. // Customizer must load last to take advantage of all functions before it
  522. require_once( WPEX_FRAMEWORK_DIR .'customizer/customizer.php' );
  523.  
  524. }
  525.  
  526. /**
  527. * Include all custom widget classes
  528. *
  529. * @since 2.0.0
  530. */
  531. public static function custom_widgets() {
  532.  
  533. // Get array of custom widgets
  534. $widgets = wpex_custom_widgets_list();
  535.  
  536. // Loop through array and register the custom widgets
  537. if ( $widgets && is_array( $widgets ) ) {
  538. foreach ( $widgets as $widget ) {
  539. $file = WPEX_ClASSES_DIR .'widgets/' . $widget .'.php';
  540. if ( file_exists ( $file ) ) {
  541. require_once( $file );
  542. }
  543. }
  544. }
  545.  
  546. }
  547.  
  548. /**
  549. * Populate the $wpex_theme global object.
  550. *
  551. * This helps speed things up by calling core functions only once and saving them in memory.
  552. *
  553. * @since 2.0.0
  554. */
  555. public static function global_object() {
  556. global $wpex_theme;
  557. $wpex_theme = new WPEX_Global_Theme_Object();
  558. $wpex_theme = $wpex_theme->generate_obj();
  559. }
  560.  
  561. /**
  562. * Adds basic theme support functions and registers the nav menus
  563. *
  564. * @since 1.6.0
  565. */
  566. public static function theme_setup() {
  567.  
  568. // Load text domain
  569. load_theme_textdomain( 'total', WPEX_THEME_DIR .'/languages' );
  570.  
  571. // Get globals
  572. global $content_width;
  573.  
  574. // Set content width based on theme's default design
  575. if ( ! isset( $content_width ) ) {
  576. $content_width = 980;
  577. }
  578.  
  579. // Register theme navigation menus
  580. register_nav_menus( array(
  581. 'topbar_menu' => esc_html__( 'Top Bar', 'total' ),
  582. 'main_menu' => esc_html__( 'Main', 'total' ),
  583. 'mobile_menu_alt' => esc_html__( 'Mobile Menu Alternative', 'total' ),
  584. 'mobile_menu' => esc_html__( 'Mobile Icons', 'total' ),
  585. 'footer_menu' => esc_html__( 'Footer', 'total' ),
  586. ) );
  587.  
  588. // Declare theme support
  589. add_theme_support( 'post-formats', array( 'video', 'gallery', 'audio', 'quote', 'link' ) );
  590. add_theme_support( 'automatic-feed-links' );
  591. add_theme_support( 'post-thumbnails' );
  592. add_theme_support( 'html5' );
  593. add_theme_support( 'woocommerce' );
  594. add_theme_support( 'title-tag' );
  595. add_theme_support( 'customize-selective-refresh-widgets' );
  596.  
  597. // Enable excerpts for pages.
  598. add_post_type_support( 'page', 'excerpt' );
  599.  
  600. // Add styles to the WP editor
  601. add_editor_style( 'assets/css/editor-style.css' );
  602.  
  603. }
  604.  
  605. /**
  606. * Functions called after theme switch
  607. *
  608. * @since 1.6.0
  609. */
  610. public static function after_switch_theme() {
  611. flush_rewrite_rules();
  612. delete_metadata( 'user', null, 'tgmpa_dismissed_notice_wpex_theme', null, true );
  613. }
  614.  
  615. /**
  616. * Adds the meta tag to the site header
  617. *
  618. * @since 1.6.0
  619. */
  620. public static function meta_viewport() {
  621.  
  622. // Responsive viewport viewport
  623. if ( wpex_global_obj( 'responsive' ) ) {
  624. $viewport = '<meta name="viewport" content="width=device-width, initial-scale=1">';
  625. }
  626.  
  627. // Non responsive meta viewport
  628. else {
  629. $width = intval( wpex_get_mod( 'main_container_width', '980' ) );
  630. $width = $width ? $width: '980';
  631. $viewport = '<meta name="viewport" content="width='. $width .'" />';
  632. }
  633.  
  634. // Apply filters to the meta viewport for child theme tweaking
  635. echo apply_filters( 'wpex_meta_viewport', $viewport );
  636.  
  637. }
  638.  
  639. /**
  640. * Adds meta generator for
  641. *
  642. * @since 3.1.0
  643. */
  644. public static function theme_meta_generator() {
  645. echo "\r\n";
  646. echo '<meta name="generator" content="Total WordPress Theme '. WPEX_THEME_VERSION .'" />';
  647. echo "\r\n";
  648. }
  649.  
  650. /**
  651. * Load font awesome in backend
  652. *
  653. * @since 3.6.0
  654. */
  655. public static function admin_font_awesome( $hook ) {
  656.  
  657. // Array of places to load font awesome
  658. $hooks = array(
  659. 'edit.php',
  660. 'post.php',
  661. 'post-new.php',
  662. 'widgets.php',
  663. );
  664.  
  665. // Only needed on these admin screens
  666. if ( ! in_array( $hook, $hooks ) ) {
  667. return;
  668. }
  669.  
  670. // Load font awesome script for VC icons and other
  671. wp_enqueue_style( 'font-awesome', wpex_asset_url( 'lib/font-awesome/css/font-awesome.min.css' ), array(), '4.6.3' );
  672.  
  673. }
  674.  
  675. /**
  676. * Returns all CSS needed for the front-end
  677. *
  678. * @since 1.6.0
  679. */
  680. public static function theme_css() {
  681.  
  682. // Remove other font awesome scripts
  683. wp_deregister_style( 'font-awesome' );
  684. wp_deregister_style( 'fontawesome' );
  685.  
  686. // Register hover-css
  687. wp_register_style( 'wpex-hover-animations', wpex_asset_url( 'lib/hover-css/hover-css.min.css' ), array(), '2.0.1' );
  688.  
  689. // Main Style.css File
  690. wp_enqueue_style(
  691. 'wpex-style', // !! IMPORTANT ** Do NOT edit 'wpex-style' *** !!!
  692. get_stylesheet_uri(),
  693. array(),
  694. WPEX_THEME_VERSION
  695. );
  696.  
  697. }
  698.  
  699. /**
  700. * Loads RTL stylesheet
  701. *
  702. * @since 1.6.0
  703. */
  704. public static function rtl_css() {
  705. if ( is_RTL() ) {
  706. wp_enqueue_style( 'wpex-rtl', wpex_asset_url( 'css/wpex-rtl.css' ), array(), WPEX_THEME_VERSION );
  707. }
  708. }
  709.  
  710. /**
  711. * Loads responsive css very last after all styles.
  712. *
  713. * @since 1.6.0
  714. */
  715. public static function responsive_css() {
  716. if ( wpex_global_obj( 'responsive' ) ) {
  717. wp_enqueue_style( 'wpex-responsive', wpex_asset_url( 'css/wpex-responsive.css' ), array(), WPEX_THEME_VERSION );
  718. }
  719. }
  720.  
  721. /**
  722. * Returns all js needed for the front-end
  723. *
  724. * @since 1.6.0
  725. */
  726. public static function theme_js() {
  727.  
  728. // First lets make sure html5 shiv is on the site
  729. wp_enqueue_script( 'wpex-html5shiv', wpex_asset_url( 'js/dynamic/html5.js' ), array(), WPEX_THEME_VERSION, false );
  730. wp_script_add_data( 'wpex-html5shiv', 'conditional', 'lt IE 9' );
  731.  
  732. // Get localized array
  733. $localize_array = WPEX_Theme_Setup::localize_array();
  734.  
  735. // Comment reply
  736. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  737. wp_enqueue_script( 'comment-reply' );
  738. }
  739.  
  740. // Load minified js
  741. if ( wpex_get_mod( 'minify_js_enable', true ) ) {
  742. wp_enqueue_script( 'wpex-core', wpex_asset_url( 'js/total-min.js' ), array( 'jquery' ), WPEX_THEME_VERSION, true );
  743. }
  744.  
  745. // Load all non-minified js
  746. else {
  747.  
  748. // Touch events
  749. wp_enqueue_script( 'tocca', wpex_asset_url( 'js/core/Tocca.min.js' ), array( 'jquery' ), '1.0.0', true );
  750.  
  751. // Easing
  752. wp_enqueue_script( 'easing', wpex_asset_url( 'js/core/jquery.easing.js' ), array( 'jquery' ), '1.3.2', true );
  753.  
  754. // Superfish used for menu dropdowns
  755. wp_enqueue_script( 'wpex-superfish', wpex_asset_url( 'js/core/superfish.js' ), array( 'jquery' ), WPEX_THEME_VERSION, true );
  756. wp_enqueue_script( 'wpex-supersubs', wpex_asset_url( 'js/core/supersubs.js' ), array( 'jquery' ), WPEX_THEME_VERSION, true );
  757. wp_enqueue_script( 'wpex-hoverintent', wpex_asset_url( 'js/core/hoverintent.js' ), array( 'jquery' ), WPEX_THEME_VERSION, true );
  758.  
  759. // Tooltips
  760. wp_enqueue_script( 'wpex-tipsy', wpex_asset_url( 'js/core/tipsy.js' ), array( 'jquery' ), WPEX_THEME_VERSION, true );
  761.  
  762. // Typed
  763. wp_enqueue_script( 'wpex-typed', wpex_asset_url( 'js/core/typed.js' ), array( 'jquery' ), WPEX_THEME_VERSION, true );
  764.  
  765. // Checks if images are loaded within an element
  766. wp_enqueue_script( 'wpex-images-loaded', wpex_asset_url( 'js/core/images-loaded.js' ), array( 'jquery' ), WPEX_THEME_VERSION, true );
  767.  
  768. // Main masonry script
  769. wp_enqueue_script( 'wpex-isotope', wpex_asset_url( 'js/core/isotope.js' ), array( 'jquery' ), '2.2.2', true );
  770.  
  771. // Leaner modal used for search/woo modals: @todo: Replace with CSS+light js
  772. wp_enqueue_script( 'wpex-leanner-modal', wpex_asset_url( 'js/core/leanner-modal.js' ), array( 'jquery' ), WPEX_THEME_VERSION, true );
  773.  
  774. // Slider Pro
  775. wp_enqueue_script( 'wpex-sliderpro', wpex_asset_url( 'js/core/jquery.sliderPro.js' ), array( 'jquery' ), '1.3', true );
  776. wp_enqueue_script( 'wpex-sliderpro-customthumbnails', wpex_asset_url( 'js/core/jquery.sliderProCustomThumbnails.js' ), array( 'jquery', 'wpex-sliderpro' ), false, true );
  777.  
  778. // Touch Swipe - do we need it?
  779. wp_enqueue_script( 'wpex-touch-swipe', wpex_asset_url( 'js/core/touch-swipe.js' ), array( 'jquery' ), WPEX_THEME_VERSION, true );
  780.  
  781. // Carousels
  782. wp_enqueue_script( 'wpex-owl-carousel', wpex_asset_url( 'js/core/owl.carousel.js' ), array( 'jquery' ), WPEX_THEME_VERSION, true );
  783.  
  784. // Used for milestones
  785. wp_enqueue_script( 'wpex-countUp', wpex_asset_url( 'js/core/countUp-jquery.js' ), array( 'jquery' ), WPEX_THEME_VERSION, true );
  786. wp_enqueue_script( 'wpex-appear', wpex_asset_url( 'js/core/appear.js' ), array( 'jquery' ), WPEX_THEME_VERSION, true );
  787.  
  788. // Mobile menu
  789. wp_enqueue_script( 'wpex-sidr', wpex_asset_url( 'js/core/sidr.js' ), array( 'jquery' ), WPEX_THEME_VERSION, true );
  790.  
  791. // Custom Selects
  792. wp_enqueue_script( 'wpex-custom-select', wpex_asset_url( 'js/core/jquery.customSelect.js' ), array( 'jquery' ), WPEX_THEME_VERSION, true );
  793.  
  794. // Equal Heights
  795. wp_enqueue_script( 'wpex-equal-heights', wpex_asset_url( 'js/core/jquery.wpexEqualHeights.js' ), array( 'jquery' ), WPEX_THEME_VERSION, true );
  796.  
  797. // Mousewheel
  798. wp_enqueue_script( 'wpex-mousewheel', wpex_asset_url( 'js/core/jquery.mousewheel.js' ), array( 'jquery' ), WPEX_THEME_VERSION, true );
  799.  
  800. // Parallax bgs
  801. wp_enqueue_script( 'wpex-scrolly', wpex_asset_url( 'js/core/scrolly.js' ), array( 'jquery' ), WPEX_THEME_VERSION, true );
  802.  
  803. // iLightbox
  804. wp_enqueue_script( 'wpex-ilightbox', wpex_asset_url( 'js/core/ilightbox.js' ), array( 'jquery' ), WPEX_THEME_VERSION, true );
  805.  
  806. // Core global functions
  807. wp_enqueue_script( 'wpex-core', wpex_asset_url( 'js/functions.js' ), array( 'jquery' ), WPEX_THEME_VERSION, true );
  808.  
  809. }
  810.  
  811. // Localize core js
  812. wp_localize_script( 'wpex-core', 'wpexLocalize', $localize_array );
  813.  
  814. // Retina.js
  815. if ( wpex_is_retina_enabled() ) {
  816. wp_enqueue_script( 'wpex-retina', wpex_asset_url( 'js/dynamic/retina.js' ), array( 'jquery' ), '0.0.2', true );
  817. wp_localize_script( 'wpex-retina', 'wpexRetina', array(
  818. 'mode' => wpex_get_mod( 'retina_mode', 1 )
  819. ) );
  820. }
  821.  
  822. }
  823.  
  824. /**
  825. * Functions.js localize array
  826. * IMPORTANT: Must be ** static function ** so we can get array in VC inline_js class
  827. *
  828. * @since 3.0.0
  829. */
  830. public static function localize_array() {
  831.  
  832. // Get Header Style and Mobile meny style
  833. $header_style = wpex_global_obj( 'header_style' );
  834. $mm_style = wpex_global_obj( 'mobile_menu_style' );
  835. $mm_toggle_style = wpex_global_obj( 'mobile_menu_toggle_style' );
  836. $mm_breakpoint = intval( wpex_get_mod( 'mobile_menu_breakpoint' ) );
  837.  
  838. // Create array
  839. $array = array(
  840. 'isRTL' => is_rtl(),
  841. 'mainLayout' => wpex_global_obj( 'main_layout' ),
  842. 'menuSearchStyle' => wpex_global_obj( 'menu_search_style' ),
  843. 'siteHeaderStyle' => $header_style,
  844. 'megaMenuJS' => true,
  845. 'superfishDelay' => 600,
  846. 'superfishSpeed' => 'fast',
  847. 'superfishSpeedOut' => 'fast',
  848. 'hasMobileMenu' => wpex_global_obj( 'has_mobile_menu' ),
  849. 'mobileMenuBreakpoint' => $mm_breakpoint ? $mm_breakpoint : '960',
  850. 'mobileMenuStyle' => $mm_style,
  851. 'mobileMenuToggleStyle' => $mm_toggle_style,
  852. 'localScrollUpdateHash' => false,
  853. 'localScrollSpeed' => 1000,
  854. 'localScrollEasing' => 'easeInOutExpo',
  855. 'scrollTopSpeed' => 1000,
  856. 'scrollTopOffset' => 100,
  857. 'carouselSpeed' => 150,
  858. 'customSelects' => '.woocommerce-ordering .orderby, #dropdown_product_cat, .widget_categories select, .widget_archive select, #bbp_stick_topic_select, #bbp_topic_status_select, #bbp_destination_topic, .single-product .variations_form .variations select',
  859. 'overlaysMobileSupport' => true,
  860. );
  861.  
  862. /**** Header params ****/
  863. if ( 'disabled' != $header_style ) {
  864.  
  865. // Sticky Header
  866. if ( wpex_global_obj( 'has_fixed_header' ) ) {
  867. $array['hasStickyHeader'] = true;
  868. if ( $logo = wpex_global_obj( 'fixed_header_logo' ) ) {
  869. $array['stickyheaderCustomLogo'] = esc_url( $logo );
  870. if ( $logo = wpex_global_obj( 'fixed_header_logo_retina' ) ) {
  871. $array['stickyheaderCustomLogoRetina'] = esc_url( $logo );
  872. }
  873. }
  874. $array['stickyHeaderStyle'] = wpex_global_obj( 'fixed_header_style' );
  875. $array['hasStickyMobileHeader'] = wpex_get_mod( 'fixed_header_mobile' );
  876. $array['overlayHeaderStickyTop'] = 0;
  877. $array['stickyHeaderBreakPoint'] = 960;
  878.  
  879. // Shrink sticky header > used for local-scroll offset
  880. if ( wpex_global_obj( 'shrink_fixed_header' ) ) {
  881. $height = intval( wpex_get_mod( 'fixed_header_shrink_end_height' ) );
  882. $height = $height ? $height + 20 : 70;
  883. $array['shrinkHeaderHeight'] = $height;
  884. }
  885.  
  886. }
  887.  
  888. // Sticky Navbar
  889. if ( 'two' == $header_style || 'three' == $header_style || 'four' == $header_style ) {
  890. $enabled = wpex_get_mod( 'fixed_header_menu', true );
  891. $array['hasStickyNavbar'] = $enabled;
  892. if ( $enabled ) {
  893. $array['hasStickyNavbarMobile'] = wpex_get_mod( 'fixed_header_menu_mobile' );
  894. $array['stickyNavbarBreakPoint'] = 960;
  895. }
  896. }
  897.  
  898. // Header five
  899. if ( 'five' == $header_style ) {
  900. $array['headerFiveSplitOffset'] = 1;
  901. }
  902.  
  903. // WooCart
  904. if ( WPEX_WOOCOMMERCE_ACTIVE ) {
  905. $array['wooCartStyle'] = wpex_global_obj( 'menu_cart_style' );
  906. }
  907.  
  908. } // End header params
  909.  
  910. // Toggle mobile menu position
  911. if ( 'toggle' == $mm_style ) {
  912. $array['animateMobileToggle'] = true;
  913. if ( wpex_get_mod( 'fixed_header_mobile' ) ) {
  914. $mobileToggleMenuPosition = 'absolute'; // Must be absolute for sticky header
  915. } elseif ( 'fixedTopNav' != $mm_toggle_style && ( wpex_global_obj( 'has_overlay_header' ) ) ) {
  916. if ( 'navbar' == $mm_toggle_style ) {
  917. $mobileToggleMenuPosition = 'afterself';
  918. } else {
  919. $mobileToggleMenuPosition = 'absolute';
  920. }
  921. } elseif ( 'outer_wrap_before' == wpex_get_mod( 'mobile_menu_navbar_position' ) && 'navbar' == $mm_toggle_style ) {
  922. $mobileToggleMenuPosition = 'afterself';
  923. } else {
  924. $mobileToggleMenuPosition = 'afterheader';
  925. }
  926. $array['mobileToggleMenuPosition'] = $mobileToggleMenuPosition;
  927. }
  928.  
  929. // Sidr settings
  930. if ( 'sidr' == $mm_style ) {
  931. $sidr_side = wpex_get_mod( 'mobile_menu_sidr_direction' );
  932. $sidr_side = $sidr_side ? $sidr_side : 'left'; // Fallback is crucial
  933. $array['sidrSource'] = wpex_global_obj( 'sidr_menu_source' );
  934. $array['sidrDisplace'] = wpex_get_mod( 'mobile_menu_sidr_displace', true ) ? true : false;
  935. $array['sidrSide'] = $sidr_side;
  936. $array['sidrBodyNoScroll'] = false;
  937. $array['sidrSpeed'] = 300;
  938. $array['sidrDropdownTarget'] = 'arrow';
  939. }
  940.  
  941. // Sticky topBar
  942. if ( apply_filters( 'wpex_has_sticky_topbar', wpex_get_mod( 'top_bar_sticky' ) ) ) {
  943. $array['stickyTopBarBreakPoint'] = 960;
  944. $array['hasStickyTopBarMobile'] = true;
  945. }
  946.  
  947. // Full screen mobile menu style
  948. if ( 'full_screen' == $mm_style ) {
  949. $array['fullScreenMobileMenuStyle'] = wpex_get_mod( 'full_screen_mobile_menu_style', 'white' );
  950. }
  951.  
  952. // Contact form 7 preloader
  953. if ( defined( 'WPCF7_VERSION' ) ) {
  954. $array['altercf7Prealoader'] = true;
  955. }
  956.  
  957. // Apply filters and return array - sanitization done by wp_localize_script
  958. return apply_filters( 'wpex_localize_array', $array );
  959. }
  960.  
  961. /**
  962. * Add headers for IE to override IE's Compatibility View Settings
  963. *
  964. * @since 2.1.0
  965. */
  966. public static function x_ua_compatible_headers( $headers ) {
  967. $headers['X-UA-Compatible'] = 'IE=edge';
  968. return $headers;
  969. }
  970.  
  971. /**
  972. * Load browser dependent stylesheets
  973. *
  974. * @since 1.6.0
  975. */
  976. public static function browser_dependent_css() {
  977.  
  978. // IE8 Stylesheet
  979. wp_enqueue_style( 'wpex-ie8',
  980. apply_filters( 'wpex_ie8_stylesheet', wpex_asset_url( 'css/wpex-ie8.css' ) ),
  981. false,
  982. WPEX_THEME_VERSION
  983. );
  984. wp_style_add_data( 'wpex-ie8', 'conditional', 'IE 8' );
  985.  
  986. // IE9 Stylesheet
  987. wp_enqueue_style( 'wpex-ie9',
  988. apply_filters( 'wpex_ie9_stylesheet', wpex_asset_url( 'css/wpex-ie9.css' ) ),
  989. false,
  990. WPEX_THEME_VERSION
  991. );
  992. wp_style_add_data( 'wpex-ie9', 'conditional', 'IE 9' );
  993.  
  994. }
  995.  
  996. /**
  997. * Registers the theme sidebars (widget areas)
  998. *
  999. * @since 1.6.0
  1000. */
  1001. public static function register_sidebars() {
  1002.  
  1003. // Define sidebars array
  1004. $sidebars = array(
  1005. 'sidebar' => esc_html__( 'Main Sidebar', 'total' ),
  1006. );
  1007.  
  1008. // Pages Sidebar
  1009. if ( wpex_get_mod( 'pages_custom_sidebar', true ) ) {
  1010. $sidebars['pages_sidebar'] = esc_html__( 'Pages Sidebar', 'total' );
  1011. }
  1012.  
  1013. // Search Results Sidebar
  1014. if ( wpex_get_mod( 'search_custom_sidebar', true ) ) {
  1015. $sidebars['search_sidebar'] = esc_html__( 'Search Results Sidebar', 'total' );
  1016. }
  1017.  
  1018. // Apply filters - makes it easier to register new sidebars
  1019. $sidebars = apply_filters( 'wpex_register_sidebars_array', $sidebars );
  1020.  
  1021. // Register sidebars
  1022. if ( $sidebars ) {
  1023.  
  1024. // Sidebar tags
  1025. $tag = wpex_get_mod( 'sidebar_headings', 'div' );
  1026. $tag = $tag ? $tag : 'div';
  1027.  
  1028. // Loop through sidebars and register them
  1029. foreach ( $sidebars as $id => $name ) {
  1030. register_sidebar( array(
  1031. 'name' => $name,
  1032. 'id' => $id,
  1033. 'before_widget' => '<div id="%1$s" class="sidebar-box widget %2$s clr">',
  1034. 'after_widget' => '</div>',
  1035. 'before_title' => '<'. $tag .' class="widget-title">',
  1036. 'after_title' => '</'. $tag .'>',
  1037. ) );
  1038. }
  1039.  
  1040. }
  1041.  
  1042. }
  1043.  
  1044. /**
  1045. * Registers footer widgets
  1046. *
  1047. * @since 3.6.0
  1048. */
  1049. public static function footer_widgets() {
  1050.  
  1051. // Check if footer widgets are enabled
  1052. $footer_widgets = apply_filters( 'wpex_register_footer_sidebars', wpex_get_mod( 'footer_widgets', true ) );
  1053.  
  1054. // return if no widgets
  1055. if ( ! $footer_widgets ) {
  1056. return;
  1057. }
  1058.  
  1059. // Footer tag
  1060. $tag = wpex_get_mod( 'footer_headings', 'div' );
  1061. $tag = $tag ? $tag : 'div';
  1062.  
  1063. // Footer widget columns
  1064. $footer_columns = wpex_get_mod( 'footer_widgets_columns', '4' );
  1065.  
  1066. // Footer 1
  1067. register_sidebar( array(
  1068. 'name' => esc_html__( 'Footer Column 1', 'total' ),
  1069. 'id' => 'footer_one',
  1070. 'before_widget' => '<div id="%1$s" class="footer-widget widget %2$s clr">',
  1071. 'after_widget' => '</div>',
  1072. 'before_title' => '<'. $tag .' class="widget-title">',
  1073. 'after_title' => '</'. $tag .'>',
  1074. ) );
  1075.  
  1076. // Footer 2
  1077. if ( $footer_columns > '1' ) {
  1078. register_sidebar( array(
  1079. 'name' => esc_html__( 'Footer Column 2', 'total' ),
  1080. 'id' => 'footer_two',
  1081. 'before_widget' => '<div id="%1$s" class="footer-widget widget %2$s clr">',
  1082. 'after_widget' => '</div>',
  1083. 'before_title' => '<'. $tag .' class="widget-title">',
  1084. 'after_title' => '</'. $tag .'>'
  1085. ) );
  1086. }
  1087.  
  1088. // Footer 3
  1089. if ( $footer_columns > '2' ) {
  1090. register_sidebar( array(
  1091. 'name' => esc_html__( 'Footer Column 3', 'total' ),
  1092. 'id' => 'footer_three',
  1093. 'before_widget' => '<div id="%1$s" class="footer-widget widget %2$s clr">',
  1094. 'after_widget' => '</div>',
  1095. 'before_title' => '<'. $tag .' class="widget-title">',
  1096. 'after_title' => '</'. $tag .'>',
  1097. ) );
  1098. }
  1099.  
  1100. // Footer 4
  1101. if ( $footer_columns > '3' ) {
  1102. register_sidebar( array(
  1103. 'name' => esc_html__( 'Footer Column 4', 'total' ),
  1104. 'id' => 'footer_four',
  1105. 'before_widget' => '<div id="%1$s" class="footer-widget widget %2$s clr">',
  1106. 'after_widget' => '</div>',
  1107. 'before_title' => '<'. $tag .' class="widget-title">',
  1108. 'after_title' => '</'. $tag .'>',
  1109. ) );
  1110. }
  1111.  
  1112. // Footer 5
  1113. if ( $footer_columns > '4' ) {
  1114. register_sidebar( array(
  1115. 'name' => esc_html__( 'Footer Column 5', 'total' ),
  1116. 'id' => 'footer_five',
  1117. 'before_widget' => '<div id="%1$s" class="footer-widget widget %2$s clr">',
  1118. 'after_widget' => '</div>',
  1119. 'before_title' => '<'. $tag .' class="widget-title">',
  1120. 'after_title' => '</'. $tag .'>',
  1121. ) );
  1122. }
  1123.  
  1124. }
  1125.  
  1126. /**
  1127. * All theme functions hook into the wpex_head_css filter for this function.
  1128. * This way all dynamic CSS is minified and outputted in one location in the site header.
  1129. *
  1130. * @since 1.6.0
  1131. */
  1132. public static function custom_css( $output = NULL ) {
  1133.  
  1134. // Add filter for adding custom css via other functions
  1135. $output = apply_filters( 'wpex_head_css', $output );
  1136.  
  1137. // Minify and output CSS in the wp_head
  1138. if ( ! empty( $output ) ) {
  1139. echo '<style type="text/css" data-type="wpex-css">'. wp_strip_all_tags( wpex_minify_css( $output ) ) .'</style>';
  1140. }
  1141.  
  1142. }
  1143.  
  1144. /**
  1145. * Adds inline CSS for the admin
  1146. *
  1147. * @since 1.6.0
  1148. */
  1149. public static function admin_inline_css() {
  1150. echo '<style>div#setting-error-tgmpa{display:block;}</style>';
  1151. }
  1152.  
  1153. /**
  1154. * Alters the default WordPress tag cloud widget arguments.
  1155. * Makes sure all font sizes for the cloud widget are set to 1em.
  1156. *
  1157. * @since 1.6.0
  1158. */
  1159. public static function widget_tag_cloud_args( $args ) {
  1160. $args['largest'] = '0.923';
  1161. $args['smallest'] = '0.923';
  1162. $args['unit'] = 'em';
  1163. return $args;
  1164. }
  1165.  
  1166. /**
  1167. * Alter wp list categories arguments.
  1168. * Adds a span around the counter for easier styling.
  1169. *
  1170. * @since 1.6.0
  1171. */
  1172. public static function wp_list_categories_args( $links ) {
  1173. $links = str_replace( '</a> (', '</a> <span class="cat-count-span">(', $links );
  1174. $links = str_replace( ')', ')</span>', $links );
  1175. return $links;
  1176. }
  1177.  
  1178. /**
  1179. * This function runs before the main query.
  1180. *
  1181. * @since 1.6.0
  1182. */
  1183. public static function pre_get_posts( $query ) {
  1184.  
  1185. // Only alter main query
  1186. if ( ! $query->is_main_query() ) {
  1187. return;
  1188. }
  1189.  
  1190. // Search pagination
  1191. if ( is_search() ) {
  1192. $query->set( 'posts_per_page', wpex_get_mod( 'search_posts_per_page', '10' ) );
  1193. return;
  1194. }
  1195.  
  1196. // Exclude categories from the main blog
  1197. if ( ( is_home() || is_page_template( 'templates/blog.php' ) ) && $cats = wpex_blog_exclude_categories() ) {
  1198. $query->set( 'category__not_in', $cats );
  1199. return;
  1200. }
  1201.  
  1202. // Category pagination
  1203. if ( $query->is_category() ) {
  1204. $terms = get_terms( 'category' );
  1205. if ( ! empty( $terms ) ) {
  1206. foreach ( $terms as $term ) {
  1207. if ( is_category( $term->slug ) ) {
  1208. $term_id = $term->term_id;
  1209. $term_data = get_option( "category_$term_id" );
  1210. if ( $term_data ) {
  1211. if ( ! empty( $term_data['wpex_term_posts_per_page'] ) ) {
  1212. $query->set( 'posts_per_page', $term_data['wpex_term_posts_per_page'] );
  1213. return;
  1214. }
  1215. }
  1216. }
  1217. }
  1218. }
  1219. }
  1220.  
  1221. }
  1222.  
  1223. /**
  1224. * Add new user fields / user meta
  1225. *
  1226. * @since 1.6.0
  1227. */
  1228. public static function add_user_social_fields( $contactmethods ) {
  1229.  
  1230. $branding = wpex_get_theme_branding();
  1231. $branding = $branding ? $branding .' - ' : '';
  1232.  
  1233. if ( ! isset( $contactmethods['wpex_twitter'] ) ) {
  1234. $contactmethods['wpex_twitter'] = $branding .'Twitter';
  1235. }
  1236.  
  1237. if ( ! isset( $contactmethods['wpex_facebook'] ) ) {
  1238. $contactmethods['wpex_facebook'] = $branding .'Facebook';
  1239. }
  1240.  
  1241. if ( ! isset( $contactmethods['wpex_googleplus'] ) ) {
  1242. $contactmethods['wpex_googleplus'] = $branding .'Google+';
  1243. }
  1244.  
  1245. if ( ! isset( $contactmethods['wpex_linkedin'] ) ) {
  1246. $contactmethods['wpex_linkedin'] = $branding .'LinkedIn';
  1247. }
  1248.  
  1249. if ( ! isset( $contactmethods['wpex_pinterest'] ) ) {
  1250. $contactmethods['wpex_pinterest'] = $branding .'Pinterest';
  1251. }
  1252.  
  1253. if ( ! isset( $contactmethods['wpex_instagram'] ) ) {
  1254. $contactmethods['wpex_instagram'] = $branding .'Instagram';
  1255. }
  1256.  
  1257. return $contactmethods;
  1258.  
  1259. }
  1260.  
  1261. /**
  1262. * Alters the default oembed output.
  1263. * Adds special classes for responsive oembeds via CSS.
  1264. *
  1265. * @since 1.6.0
  1266. */
  1267. public static function oembed_html( $cache, $url, $attr, $post_ID ) {
  1268.  
  1269. // Remove frameborder
  1270. $cache = str_replace( 'frameborder="0"', '', $cache );
  1271.  
  1272. // Supported video embeds
  1273. $hosts = apply_filters( 'wpex_oembed_responsive_hosts', array(
  1274. 'vimeo.com',
  1275. 'youtube.com',
  1276. 'blip.tv',
  1277. 'money.cnn.com',
  1278. 'dailymotion.com',
  1279. 'flickr.com',
  1280. 'hulu.com',
  1281. 'kickstarter.com',
  1282. 'vine.co',
  1283. 'soundcloud.com',
  1284. ) );
  1285.  
  1286. // Supports responsive
  1287. $supports_responsive = false;
  1288.  
  1289. // Check if responsive wrap should be added
  1290. foreach( $hosts as $host ) {
  1291. if ( strpos( $url, $host ) !== false ) {
  1292. $supports_responsive = true;
  1293. break; // no need to loop further
  1294. }
  1295. }
  1296.  
  1297. // Output code
  1298. if ( $supports_responsive ) {
  1299. return '<p class="responsive-video-wrap wpex-clr">' . $cache . '</p>';
  1300. } else {
  1301. return '<div class="wpex-oembed-wrap wpex-clr">' . $cache . '</div>';
  1302. }
  1303.  
  1304. }
  1305.  
  1306. /**
  1307. * The wp_get_attachment_url() function doesn't distinguish whether a page request arrives via HTTP or HTTPS.
  1308. * Using wp_get_attachment_url filter, we can fix this to avoid the dreaded mixed content browser warning
  1309. *
  1310. * @since 1.6.0
  1311. */
  1312. public static function honor_ssl_for_attachments( $url ) {
  1313. $http = site_url( FALSE, 'http' );
  1314. $https = site_url( FALSE, 'https' );
  1315. $isSecure = false;
  1316. if ( ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ) {
  1317. $isSecure = true;
  1318. }
  1319. if ( $isSecure ) {
  1320. return str_replace( $http, $https, $url );
  1321. } else {
  1322. return $url;
  1323. }
  1324. }
  1325.  
  1326. /**
  1327. * Alters the default WordPress password protected form so it's easier to style
  1328. *
  1329. * @since 2.0.0
  1330. */
  1331. public static function custom_password_protected_form() {
  1332. ob_start();
  1333. include( locate_template( 'partials/password-protection-form.php' ) );
  1334. return ob_get_clean();
  1335. }
  1336.  
  1337.  
  1338. /**
  1339. * Modify JOIN in the next/prev function
  1340. *
  1341. * @since 2.0.0
  1342. */
  1343. public static function prev_next_join( $join ) {
  1344. global $wpdb;
  1345. $join .= " LEFT JOIN $wpdb->postmeta AS m ON ( p.ID = m.post_id AND m.meta_key = 'wpex_post_link' )";
  1346. return $join;
  1347. }
  1348.  
  1349. /**
  1350. * Modify WHERE in the next/prev function
  1351. *
  1352. * @since 2.0.0
  1353. */
  1354. public static function prev_next_where( $where ) {
  1355. $where .= " AND ( (m.meta_key = 'wpex_post_link' AND CAST(m.meta_value AS CHAR) = '' ) OR m.meta_id IS NULL ) ";
  1356. return $where;
  1357. }
  1358.  
  1359. /**
  1360. * Redirect posts using custom links
  1361. *
  1362. * @since 2.0.0
  1363. */
  1364. public static function redirect_custom_links() {
  1365. if ( ! wpex_vc_is_inline()
  1366. && is_singular()
  1367. && $custom_link = wpex_get_custom_permalink()
  1368. ) {
  1369. wp_redirect( $custom_link, 301 );
  1370. }
  1371. }
  1372.  
  1373. /**
  1374. * When a term is deleted, delete its data.
  1375. *
  1376. * @since 2.1.0
  1377. */
  1378. public static function delete_term( $term_id ) {
  1379.  
  1380. // If term id is defined
  1381. if ( $term_id = absint( $term_id ) ) {
  1382.  
  1383. // Get terms data
  1384. $term_data = get_option( 'wpex_term_data' );
  1385.  
  1386. // Remove key with term data
  1387. if ( $term_data && isset( $term_data[$term_id] ) ) {
  1388. unset( $term_data[$term_id] );
  1389. update_option( 'wpex_term_data', $term_data );
  1390. }
  1391.  
  1392. }
  1393.  
  1394. }
  1395.  
  1396. /**
  1397. * Adds extra classes to the post_class() output
  1398. *
  1399. * @since 3.0.0
  1400. */
  1401. public static function post_class( $classes ) {
  1402.  
  1403. // Get post type
  1404. $type = get_post_type();
  1405.  
  1406. // Not needed here
  1407. if ( 'forum' == $type || 'topic' == $type ) {
  1408. return $classes;
  1409. }
  1410.  
  1411. // Add entry class
  1412. $classes[] = 'entry';
  1413.  
  1414. // Add has media class (requires wpex media metabox)
  1415. $check_gallery = ( 'post' == $type && wpex_get_mod( 'blog_entry_gallery_output', true ) ) ? true : false;
  1416. if ( wpex_post_has_media( get_the_ID(), $check_gallery ) ) {
  1417. $classes[] = 'has-media';
  1418. } else {
  1419. $classes[] = 'no-media';
  1420. }
  1421.  
  1422. // Return classes
  1423. return $classes;
  1424.  
  1425. }
  1426.  
  1427. /**
  1428. * Add schema markup to the authors post link
  1429. *
  1430. * @since 3.0.0
  1431. */
  1432. public static function the_author_posts_link( $link ) {
  1433.  
  1434. // Add schema markup
  1435. $schema = wpex_get_schema_markup( 'author_link' );
  1436. if ( $schema ) {
  1437. $link = str_replace( 'rel="author"', 'rel="author"'. $schema, $link );
  1438. }
  1439.  
  1440. // Return link
  1441. return $link;
  1442.  
  1443. }
  1444.  
  1445. /**
  1446. * Move Comment form field back to bottom which was altered in WP 4.4
  1447. *
  1448. * @since 3.3.0
  1449. */
  1450. public static function move_comment_form_fields( $fields ) {
  1451. $comment_field = $fields['comment'];
  1452. unset( $fields['comment'] );
  1453. $fields['comment'] = $comment_field;
  1454. return $fields;
  1455. }
  1456.  
  1457. /**
  1458. * Disable canonical redirect on the homepage when using pagination via VC modules
  1459. * or when using the blog template on the homepage
  1460. *
  1461. * @since 3.3.3
  1462. */
  1463. public static function home_pagination_fix( $redirect_url ) {
  1464. if ( is_paged() && is_singular() ) {
  1465. $redirect_url = false;
  1466. }
  1467. return $redirect_url;
  1468. }
  1469.  
  1470. /**
  1471. * Filters the kses_allowed_protocols for sanitization like esc_url to allow
  1472. * specific protocols such as skype calls
  1473. *
  1474. * @since 3.5.0
  1475. */
  1476. public static function kses_allowed_protocols( $protocols ) {
  1477. $protocols[] = 'skype';
  1478. return $protocols;
  1479. }
  1480.  
  1481. /**
  1482. * Filters the comments_link for smoother local scrolling and to
  1483. * fix issues with fixed/sticky elements
  1484. *
  1485. * @since 3.5.0
  1486. */
  1487. public static function get_comments_link( $comments_link, $post_id ) {
  1488. $hash = get_comments_number( $post_id ) ? '#view_comments' : '#comments_reply';
  1489. $comments_link = get_permalink( $post_id ) . $hash;
  1490. return $comments_link;
  1491. }
  1492.  
  1493. }
  1494. new WPEX_Theme_Setup;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement