PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/Avada/functions.php

https://gitlab.com/webkod3r/tripolis
PHP | 579 lines | 366 code | 116 blank | 97 comment | 101 complexity | 9b15a3ce626f1b8e1194f4e7e851f6e0 MD5 | raw file
  1. <?php
  2. /**
  3. * Autoloader
  4. *
  5. * Automatically load files when their classes are required.
  6. */
  7. spl_autoload_register( 'avada_register_classes' );
  8. function avada_register_classes( $class_name ) {
  9. if ( class_exists( $class_name ) ) {
  10. return;
  11. }
  12. if ( 'TGM_Plugin_Activation' == $class_name ) {
  13. return;
  14. }
  15. $class_path = get_template_directory() . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'class-' . strtolower( str_replace( '_', '-', $class_name ) ) . '.php';
  16. if ( file_exists( $class_path ) ) {
  17. include $class_path;
  18. }
  19. }
  20. /**
  21. * Must-use Plugins
  22. */
  23. include_once get_template_directory() . '/framework/plugins/multiple_sidebars.php';
  24. require_once get_template_directory() . '/framework/plugins/post-link-plus.php';
  25. require_once get_template_directory() . '/framework/plugins/multiple-featured-images/multiple-featured-images.php';
  26. /*
  27. * Include the Options Framework
  28. */
  29. require_once( get_template_directory() . '/framework/admin/index.php' );
  30. /**
  31. * Instantiate the Avada class
  32. * Make sure the class is properly set-up.
  33. * The Avada class is a singular object so we can directly access the one true Avada object using this function.
  34. */
  35. function Avada() {
  36. // Instantiate the class
  37. $avada = Avada::get_instance();
  38. // Properly add the settings
  39. $avada->settings = new Avada_Settings();
  40. $avada->mfi = new Avada_Multiple_Featured_Images();
  41. return $avada;
  42. }
  43. $avada = Avada();
  44. global $social_icons;
  45. $social_icons = $avada->social_icons;
  46. /*
  47. * Include the TGM configuration
  48. */
  49. require_once( get_template_directory() . '/includes/class-tgm-plugin-activation.php' );
  50. require_once( get_template_directory() . '/includes/avada-tgm.php' );
  51. /**
  52. * The main Avada class
  53. */
  54. require_once( get_template_directory() . '/includes/class-avada.php' );
  55. /*
  56. * Include deprecated functions
  57. */
  58. require_once( get_template_directory() . '/includes/deprecated.php' );
  59. /*
  60. * Include compatibility tweaks
  61. */
  62. require_once( get_template_directory() . '/includes/avada-compatibility.php' );
  63. /**
  64. * Metaboxes
  65. */
  66. include_once get_template_directory() . '/framework/metaboxes/metaboxes.php' ;
  67. /**
  68. * Initialize the mega menu framework
  69. */
  70. require_once( get_template_directory() . '/framework/plugins/megamenu/mega-menu-framework.php' );
  71. /**
  72. * Load the Fusion Framework main object to have all functions of it available for later usage
  73. */
  74. require_once( 'framework/fusion-framework.php' );
  75. /**
  76. * Custom Functions
  77. */
  78. get_template_part( 'framework/custom_functions' );
  79. require_once( 'includes/avada-functions.php' );
  80. /**
  81. * WPML Config
  82. */
  83. if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
  84. include_once get_template_directory() . '/framework/plugins/wpml.php';
  85. }
  86. /**
  87. * Include the importer
  88. */
  89. include get_template_directory() . '/framework/plugins/importer/importer.php';
  90. /**
  91. * Woo Config
  92. */
  93. if ( class_exists( 'WooCommerce' ) ) {
  94. include_once( get_template_directory() . '/includes/woo-config.php' );
  95. }
  96. /**
  97. * The dynamic CSS
  98. */
  99. require_once get_template_directory() . '/includes/dynamic_css.php';
  100. $image = new Fusion_Image_Resizer();
  101. //define('WOOCOMMERCE_USE_CSS', false);
  102. /**
  103. * Avada Header Template
  104. */
  105. get_template_part( 'templates/header' );
  106. // Content Width
  107. if ( ! isset( $content_width ) ) {
  108. $content_width = '669';
  109. }
  110. /**
  111. * Font-Awesome icon handler.
  112. * Adds compatibility with order versions of FA icon names.
  113. */
  114. function avada_font_awesome_name_handler( $icon ) {
  115. $old_icons = Avada_Data::old_icons();
  116. if ( 'icon-' == substr( $icon, 0, 5 ) || 'fa=' != substr( $icon, 0, 3 ) ) {
  117. // Replace old prefix with new one
  118. $icon = str_replace( 'icon-', 'fa-', $icon );
  119. if ( array_key_exists( str_replace( 'fa-', '', $icon ), $old_icons ) ) {
  120. $fa_icon = 'fa-' . $old_icons[str_replace( 'fa-', '', $icon )];
  121. } else {
  122. $fa_icon = ( 'fa-' != substr( $icon, 0, 3 ) ) ? 'fa-' . $icon : $icon;
  123. }
  124. } else {
  125. $fa_icon = ( 'fa-' != substr( $icon, 0, 3 ) ) ? 'fa-' . $icon : $icon;
  126. }
  127. return $fa_icon;
  128. }
  129. add_filter( 'get_archives_link', 'avada_cat_count_span' );
  130. add_filter( 'wp_list_categories', 'avada_cat_count_span' );
  131. function avada_cat_count_span( $links ) {
  132. $get_count = preg_match_all( '#\((.*?)\)#', $links, $matches );
  133. if ( $matches ) {
  134. $i = 0;
  135. foreach( $matches[0] as $val ) {
  136. $links = str_replace( '</a> ' . $val, ' ' . $val . '</a>', $links );
  137. $links = str_replace( '</a>&nbsp;' . $val, ' ' . $val . '</a>', $links );
  138. $i++;
  139. }
  140. }
  141. return $links;
  142. }
  143. remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
  144. if ( ! is_admin() ) {
  145. add_filter( 'pre_get_posts', 'avada_SearchFilter' );
  146. function avada_SearchFilter( $query ) {
  147. if ( is_search() && $query->is_search ) {
  148. if ( isset( $_GET ) && 1 < count( $_GET ) ) {
  149. return $query;
  150. }
  151. if ( 'Only Posts' == Avada()->settings->get( 'search_content' ) ) {
  152. $query->set('post_type', 'post');
  153. } elseif ( 'Only Pages' == Avada()->settings->get( 'search_content' ) ) {
  154. $query->set('post_type', 'page');
  155. }
  156. }
  157. return $query;
  158. }
  159. }
  160. function is_events_archive() {
  161. if ( class_exists( 'Tribe__Events__Main' ) ) {
  162. return ( tribe_is_month() || tribe_is_day() || tribe_is_past() || tribe_is_upcoming() || ( class_exists( 'Tribe__Events__Pro__Main' ) && ( tribe_is_week() || tribe_is_photo() || tribe_is_map() ) ) ) ? true : false;
  163. } else {
  164. return false;
  165. }
  166. }
  167. /**
  168. * Adding the Open Graph in the Language Attributes
  169. */
  170. function avada_add_opengraph_doctype( $output ) {
  171. return Avada()->head->add_opengraph_doctype( $output );
  172. }
  173. function fusion_insert_og_meta() {
  174. Avada()->head->insert_og_meta();
  175. }
  176. if ( ! Avada()->settings->get( 'status_opengraph' ) ) {
  177. add_filter( 'language_attributes', 'avada_add_opengraph_doctype' );
  178. add_action( 'wp_head', 'fusion_insert_og_meta', 5 );
  179. }
  180. function modify_contact_methods( $profile_fields ) {
  181. // Add new fields
  182. $profile_fields['author_facebook'] = 'Facebook ';
  183. $profile_fields['author_twitter'] = 'Twitter';
  184. $profile_fields['author_linkedin'] = 'LinkedIn';
  185. $profile_fields['author_dribble'] = 'Dribble';
  186. $profile_fields['author_gplus'] = 'Google+';
  187. $profile_fields['author_custom'] = 'Custom Message';
  188. return $profile_fields;
  189. }
  190. add_filter( 'user_contactmethods', 'modify_contact_methods' );
  191. /* Change admin css */
  192. function avada_custom_admin_styles() {
  193. echo '<style type="text/css">.widget input { border-color: #DFDFDF !important; }</style>';
  194. }
  195. add_action( 'admin_head', 'avada_custom_admin_styles' );
  196. function avada_admin_notice() {
  197. $url = admin_url( 'themes.php?page=optionsframework#of-option-advanced' );
  198. $page = '';
  199. if ( array_key_exists( 'page', $_GET ) ) {
  200. $page = $_GET['page'];
  201. }
  202. if ( array_key_exists( 'imported', $_GET ) && isset( $_GET['imported'] ) && 'success' == $_GET['imported'] ) {
  203. echo '<div id="setting-error-settings_updated" class="updated settings-error"><p>' . __( 'Sucessfully imported demo data!', 'Avada' ) . '</p></div>';
  204. }
  205. }
  206. add_action( 'admin_notices', 'avada_admin_notice' );
  207. function avada_nag_ignore() {
  208. global $current_user;
  209. $user_id = $current_user->ID;
  210. /* If user clicks to ignore the notice, add that to their user meta */
  211. if ( isset( $_GET['fusion_richedit_nag_ignore'] ) && '0' == $_GET['fusion_richedit_nag_ignore'] ) {
  212. add_user_meta( $user_id, 'fusion_richedit_nag_ignore', 'true', true );
  213. //$referer = esc_url($_SERVER["HTTP_REFERER"]);
  214. //wp_redirect($referer);
  215. }
  216. /* If user clicks to ignore the notice, add that to their user meta */
  217. if ( isset( $_GET['avada_uber_nag_ignore'] ) && '0' == $_GET['avada_uber_nag_ignore'] ) {
  218. update_option( 'avada_ubermenu_notice', true );
  219. update_option( 'avada_ubermenu_notice_hidden', true );
  220. $referer = esc_url( $_SERVER["HTTP_REFERER"] );
  221. wp_redirect( $referer );
  222. }
  223. }
  224. add_action( 'admin_init', 'avada_nag_ignore' );
  225. if ( function_exists( 'rev_slider_shortcode' ) ) {
  226. add_action( 'admin_init', 'avada_disable_revslider_notice' );
  227. add_action( 'admin_init', 'avada_revslider_styles' );
  228. }
  229. /* Disable revslider notice */
  230. function avada_disable_revslider_notice() {
  231. update_option( 'revslider-valid-notice', 'false' );
  232. }
  233. /* Add revslider styles */
  234. function avada_revslider_styles() {
  235. global $wpdb, $revSliderVersion;
  236. $plugin_version = $revSliderVersion;
  237. $table_name = $wpdb->prefix . 'revslider_css';
  238. if ( $wpdb->get_var( "SHOW TABLES LIKE '$table_name'" ) == $table_name && function_exists( 'rev_slider_shortcode' ) && $plugin_version != get_option('avada_revslider_version' ) ) {
  239. $old_styles = array( '.avada_huge_white_text', '.avada_huge_black_text', '.avada_big_black_text', '.avada_big_white_text', '.avada_big_black_text_center', '.avada_med_green_text', '.avada_small_gray_text', '.avada_small_white_text', '.avada_block_black', '.avada_block_green', '.avada_block_white', '.avada_block_white_trans' );
  240. foreach( $old_styles as $handle ) {
  241. $wpdb->delete( $table_name, array( 'handle' => '.tp-caption' . $handle ) );
  242. }
  243. $styles = array(
  244. '.tp-caption.avada_huge_white_text' => '{"position":"absolute","color":"#ffffff","font-size":"130px","line-height":"45px","font-family":"museoslab500regular"}',
  245. '.tp-caption.avada_huge_black_text' => '{"position":"absolute","color":"#000000","font-size":"130px","line-height":"45px","font-family":"museoslab500regular"}',
  246. '.tp-caption.avada_big_black_text' => '{"position":"absolute","color":"#333333","font-size":"42px","line-height":"45px","font-family":"museoslab500regular"}',
  247. '.tp-caption.avada_big_white_text' => '{"position":"absolute","color":"#fff","font-size":"42px","line-height":"45px","font-family":"museoslab500regular"}',
  248. '.tp-caption.avada_big_black_text_center' => '{"position":"absolute","color":"#333333","font-size":"38px","line-height":"45px","font-family":"museoslab500regular","text-align":"center"}',
  249. '.tp-caption.avada_med_green_text' => '{"position":"absolute","color":"#A0CE4E","font-size":"24px","line-height":"24px","font-family":"PTSansRegular, Arial, Helvetica, sans-serif"}',
  250. '.tp-caption.avada_small_gray_text' => '{"position":"absolute","color":"#747474","font-size":"13px","line-height":"20px","font-family":"PTSansRegular, Arial, Helvetica, sans-serif"}',
  251. '.tp-caption.avada_small_white_text' => '{"position":"absolute","color":"#fff","font-size":"13px","line-height":"20px","font-family":"PTSansRegular, Arial, Helvetica, sans-serif","text-shadow":"0px 2px 5px rgba(0, 0, 0, 0.5)","font-weight":"700"}',
  252. '.tp-caption.avada_block_black' => '{"position":"absolute","color":"#A0CE4E","text-shadow":"none","font-size":"22px","line-height":"34px","padding":["1px", "10px", "0px", "10px"],"margin":"0px","border-width":"0px","border-style":"none","background-color":"#000","font-family":"PTSansRegular, Arial, Helvetica, sans-serif"}',
  253. '.tp-caption.avada_block_green' => '{"position":"absolute","color":"#000","text-shadow":"none","font-size":"22px","line-height":"34px","padding":["1px", "10px", "0px", "10px"],"margin":"0px","border-width":"0px","border-style":"none","background-color":"#A0CE4E","font-family":"PTSansRegular, Arial, Helvetica, sans-serif"}',
  254. '.tp-caption.avada_block_white' => '{"position":"absolute","color":"#fff","text-shadow":"none","font-size":"22px","line-height":"34px","padding":["1px", "10px", "0px", "10px"],"margin":"0px","border-width":"0px","border-style":"none","background-color":"#000","font-family":"PTSansRegular, Arial, Helvetica, sans-serif"}',
  255. '.tp-caption.avada_block_white_trans' => '{"position":"absolute","color":"#fff","text-shadow":"none","font-size":"22px","line-height":"34px","padding":["1px", "10px", "0px", "10px"],"margin":"0px","border-width":"0px","border-style":"none","background-color":"rgba(0, 0, 0, 0.6)","font-family":"PTSansRegular, Arial, Helvetica, sans-serif"}',
  256. );
  257. foreach( $styles as $handle => $params ) {
  258. $test = $wpdb->get_var( $wpdb->prepare( 'SELECT handle FROM ' . $table_name . ' WHERE handle = %s', $handle ) );
  259. if ( $test != $handle ) {
  260. $wpdb->replace(
  261. $table_name,
  262. array(
  263. 'handle' => $handle,
  264. 'params' => $params,
  265. 'settings' => '{"hover":"false","type":"text","version":"custom","translated":"5"}',
  266. ),
  267. array(
  268. '%s',
  269. '%s',
  270. '%s',
  271. )
  272. );
  273. }
  274. }
  275. update_option( 'avada_revslider_version', $plugin_version );
  276. }
  277. }
  278. //////////////////////////////////////////////////////////////////
  279. // Woo Products Shortcode Recode
  280. //////////////////////////////////////////////////////////////////
  281. function avada_woo_product( $atts, $content = null ) {
  282. global $woocommerce_loop;
  283. if ( empty( $atts ) ) {
  284. return;
  285. }
  286. $args = array(
  287. 'post_type' => 'product',
  288. 'posts_per_page' => 1,
  289. 'no_found_rows' => 1,
  290. 'post_status' => 'publish',
  291. 'meta_query' => array(
  292. array(
  293. 'key' => '_visibility',
  294. 'value' => array('catalog', 'visible'),
  295. 'compare' => 'IN'
  296. )
  297. ),
  298. 'columns' => 1
  299. );
  300. if ( isset( $atts['sku'] ) ) {
  301. $args['meta_query'][] = array(
  302. 'key' => '_sku',
  303. 'value' => $atts['sku'],
  304. 'compare' => '='
  305. );
  306. }
  307. if ( isset( $atts['id'] ) ) {
  308. $args['p'] = $atts['id'];
  309. }
  310. ob_start();
  311. if ( isset( $columns ) ) {
  312. $woocommerce_loop['columns'] = $columns;
  313. }
  314. $products = new WP_Query( $args );
  315. if ( $products->have_posts() ) : ?>
  316. <?php woocommerce_product_loop_start(); ?>
  317. <?php while ( $products->have_posts() ) : $products->the_post(); ?>
  318. <?php woocommerce_get_template_part( 'content', 'product' ); ?>
  319. <?php endwhile; // end of the loop. ?>
  320. <?php woocommerce_product_loop_end(); ?>
  321. <?php endif;
  322. wp_reset_postdata();
  323. return '<div class="woocommerce">' . ob_get_clean() . '</div>';
  324. }
  325. add_action( 'wp_loaded', 'remove_product_shortcode' );
  326. function remove_product_shortcode() {
  327. if ( class_exists( 'WooCommerce' ) ) {
  328. // First remove the shortcode
  329. remove_shortcode( 'product' );
  330. // Then recode it
  331. add_shortcode( 'product', 'avada_woo_product' );
  332. }
  333. }
  334. // Support email login on my account dropdown
  335. if( isset( $_POST['fusion_woo_login_box'] ) && $_POST['fusion_woo_login_box'] == 'true' ) {
  336. add_filter( 'authenticate', 'avada_email_login_auth', 10, 3 );
  337. }
  338. function avada_email_login_auth( $user, $username, $password ) {
  339. if ( is_a( $user, 'WP_User' ) ) {
  340. return $user;
  341. }
  342. if ( !empty( $username ) ) {
  343. $username = str_replace( '&', '&amp;', stripslashes( $username ) );
  344. $user = get_user_by( 'email', $username );
  345. if ( isset( $user, $user->user_login, $user->user_status ) && 0 == (int) $user->user_status ) {
  346. $username = $user->user_login;
  347. }
  348. }
  349. return wp_authenticate_username_password( null, $username, $password );
  350. }
  351. // No redirect on woo my account dropdown login when it fails
  352. if( isset( $_POST['fusion_woo_login_box'] ) && $_POST['fusion_woo_login_box'] == 'true' ) {
  353. add_action( 'init', 'avada_load_login_redirect_support' );
  354. }
  355. function avada_load_login_redirect_support() {
  356. if ( class_exists( 'WooCommerce' ) ) {
  357. // When on the my account page, do nothing
  358. if ( ! empty( $_POST['login'] ) && ! empty( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'woocommerce-login' ) ) {
  359. return;
  360. }
  361. add_action( 'login_redirect', 'avada_login_fail', 10, 3 );
  362. }
  363. }
  364. // Avada Login Fail Test
  365. function avada_login_fail( $url = '', $raw_url = '', $user = '' ) {
  366. if ( ! is_account_page() ) {
  367. if ( isset( $_SERVER ) && isset( $_SERVER['HTTP_REFERER'] ) && $_SERVER['HTTP_REFERER'] ) {
  368. $referer_array = parse_url( $_SERVER['HTTP_REFERER'] );
  369. $referer = '//' . $referer_array['host'] . $referer_array['path'];
  370. // If there's a valid referrer, and it's not the default log-in screen
  371. if ( ! empty( $referer ) && ! strstr( $referer, 'wp-login' ) && ! strstr( $referer, 'wp-admin' ) ) {
  372. if ( is_wp_error( $user ) ) {
  373. // Let's append some information (login=failed) to the URL for the theme to use
  374. wp_redirect( add_query_arg( array( 'login' => 'failed' ), $referer ) );
  375. } else {
  376. wp_redirect( $referer );
  377. }
  378. exit;
  379. } else {
  380. return $url;
  381. }
  382. } else {
  383. return $url;
  384. }
  385. }
  386. }
  387. /**
  388. * Show a shop page description on product archives
  389. */
  390. function woocommerce_product_archive_description() {
  391. if ( is_post_type_archive( 'product' ) && 0 == get_query_var( 'paged' ) ) {
  392. $shop_page = get_post( woocommerce_get_page_id( 'shop' ) );
  393. if ( $shop_page ) {
  394. $description = apply_filters( 'the_content', $shop_page->post_content );
  395. if ( $description ) {
  396. echo '<div class="post-content">' . $description . '</div>';
  397. }
  398. }
  399. }
  400. }
  401. /**
  402. * Layerslider API
  403. */
  404. function avada_layerslider_ready() {
  405. if ( class_exists('LS_Sources') ) {
  406. LS_Sources::addSkins( get_template_directory().'/includes/ls-skins' );
  407. }
  408. if ( defined( 'LS_PLUGIN_BASE' ) ) {
  409. remove_action( 'after_plugin_row_' . LS_PLUGIN_BASE, 'layerslider_plugins_purchase_notice', 10, 3 );
  410. }
  411. }
  412. add_action( 'layerslider_ready', 'avada_layerslider_ready' );
  413. /**
  414. * Custom Excerpt function for Sermon Manager
  415. */
  416. function avada_get_sermon_content( $archive = false ) {
  417. global $post;
  418. $sermon_content = '';
  419. ob_start();
  420. ?>
  421. <p>
  422. <?php
  423. _e( 'Date: ', 'Avada' );
  424. wpfc_sermon_date( get_option( 'date_format' ), '<span class="sermon_date">', '</span> ' ); echo the_terms( $post->ID, 'wpfc_service_type', ' <span class="service_type">(', ' ', ')</span>');
  425. ?></p><p><?php
  426. wpfc_sermon_meta( 'bible_passage', '<span class="bible_passage">' . __( 'Bible Text: ', 'Avada' ), '</span> | ' );
  427. echo the_terms( $post->ID, 'wpfc_preacher', '<span class="preacher_name">', ', ', '</span>');
  428. echo the_terms( $post->ID, 'wpfc_sermon_series', '<p><span class="sermon_series">' .__( 'Series: ', 'Aavada' ), ' ', '</span></p>' );
  429. ?>
  430. </p>
  431. <?php
  432. if ( $archive ) {
  433. $sermonoptions = get_option( 'wpfc_options' );
  434. if ( isset( $sermonoptions['archive_player'] ) == '1' ) { ?>
  435. <div class="wpfc_sermon cf">
  436. <?php wpfc_sermon_files(); ?>
  437. </div>
  438. <?php }
  439. } ?>
  440. <?php if ( ! $archive ) { ?>
  441. <?php wpfc_sermon_files(); ?>
  442. <?php wpfc_sermon_description(); ?>
  443. <?php wpfc_sermon_attachments(); ?>
  444. <?php echo the_terms( $post->ID, 'wpfc_sermon_topics', '<p class="sermon_topics">'.__( 'Topics: ', 'sermon-manager'), ',', '', '</p>' ); ?>
  445. <?php }
  446. $sermon_content = ob_get_clean();
  447. if ( $archive ) {
  448. $description = '';
  449. ob_start();
  450. wpfc_sermon_description();
  451. $description .= ob_get_clean();
  452. $excerpt_length = fusion_get_theme_option( 'excerpt_length_blog' );
  453. $sermon_content .= Avada()->blog->get_content_stripped_and_excerpted( $excerpt_length, $description );
  454. }
  455. return $sermon_content;
  456. }
  457. // WIP, please ignore below:
  458. add_theme_support( 'fusion-builder-demos' );
  459. if ( get_option( 'avada_imported_demo' ) == 'true' ) {
  460. flush_rewrite_rules();
  461. update_option( 'avada_imported_demo', 'false' );
  462. }
  463. // Omit closing PHP tag to avoid "Headers already sent" issues.