Guest User

Goretti function hueman

a guest
Sep 30th, 2015
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.53 KB | None | 0 0
  1.  
  2. <?php
  3. /* ------------------------------------------------------------------------- *
  4. * Custom functions
  5. /* ------------------------------------------------------------------------- */
  6.  
  7. // Use a child theme instead of placing custom functions here
  8. // http://codex.wordpress.org/Child_Themes
  9.  
  10.  
  11. /* ------------------------------------------------------------------------- *
  12. * OptionTree framework integration: Use in theme mode
  13. /* ------------------------------------------------------------------------- */
  14.  
  15. add_filter( 'ot_show_pages', '__return_false' );
  16. add_filter( 'ot_show_new_layout', '__return_false' );
  17. add_filter( 'ot_theme_mode', '__return_true' );
  18. load_template( get_template_directory() . '/option-tree/ot-loader.php' );
  19.  
  20.  
  21. /* ------------------------------------------------------------------------- *
  22. * Load theme files
  23. /* ------------------------------------------------------------------------- */
  24.  
  25. if ( ! function_exists( 'alx_load' ) ) {
  26.  
  27. function alx_load() {
  28. // Load theme languages
  29. load_theme_textdomain( 'hueman', get_template_directory().'/languages' );
  30.  
  31. // Load theme options and meta boxes
  32. load_template( get_template_directory() . '/functions/theme-options.php' );
  33. load_template( get_template_directory() . '/functions/meta-boxes.php' );
  34.  
  35. // Load custom widgets
  36. load_template( get_template_directory() . '/functions/widgets/alx-tabs.php' );
  37. load_template( get_template_directory() . '/functions/widgets/alx-video.php' );
  38. load_template( get_template_directory() . '/functions/widgets/alx-posts.php' );
  39.  
  40. // Load dynamic styles
  41. load_template( get_template_directory() . '/functions/dynamic-styles.php' );
  42.  
  43. // Load TGM plugin activation
  44. load_template( get_template_directory() . '/functions/class-tgm-plugin-activation.php' );
  45. }
  46.  
  47. }
  48. add_action( 'after_setup_theme', 'alx_load' );
  49.  
  50.  
  51. /* ------------------------------------------------------------------------- *
  52. * Base functionality
  53. /* ------------------------------------------------------------------------- */
  54.  
  55. // Content width
  56. if ( !isset( $content_width ) ) { $content_width = 720; }
  57.  
  58.  
  59. /* Theme setup
  60. /* ------------------------------------ */
  61. if ( ! function_exists( 'alx_setup' ) ) {
  62.  
  63. function alx_setup() {
  64. // Enable title tag
  65. add_theme_support( 'title-tag' );
  66.  
  67. // Enable automatic feed links
  68. add_theme_support( 'automatic-feed-links' );
  69.  
  70. // Enable featured image
  71. add_theme_support( 'post-thumbnails' );
  72.  
  73. // Enable post format support
  74. add_theme_support( 'post-formats', array( 'audio', 'aside', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video' ) );
  75.  
  76. // Declare WooCommerce support
  77. add_theme_support( 'woocommerce' );
  78.  
  79. // Thumbnail sizes
  80. add_image_size( 'thumb-small', 160, 160, true );
  81. add_image_size( 'thumb-standard', 320, 320, true );
  82. add_image_size( 'thumb-medium', 520, 245, true );
  83. add_image_size( 'thumb-large', 720, 340, true );
  84.  
  85. // Custom menu areas
  86. register_nav_menus( array(
  87. 'topbar' => 'Topbar',
  88. 'header' => 'Header',
  89. 'footer' => 'Footer',
  90. ) );
  91. }
  92.  
  93. }
  94. add_action( 'after_setup_theme', 'alx_setup' );
  95.  
  96.  
  97. /* Register sidebars
  98. /* ------------------------------------ */
  99. if ( ! function_exists( 'alx_sidebars' ) ) {
  100.  
  101. function alx_sidebars() {
  102. register_sidebar(array( 'name' => 'Primary','id' => 'primary','description' => "Normal full width sidebar", 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget' => '</div>','before_title' => '<h3>','after_title' => '</h3>'));
  103. register_sidebar(array( 'name' => 'Secondary','id' => 'secondary','description' => "Normal full width sidebar", 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget' => '</div>','before_title' => '<h3>','after_title' => '</h3>'));
  104. if ( ot_get_option('header-ads') == 'on' ) { register_sidebar(array( 'name' => 'Header Ads','id' => 'header-ads', 'description' => "Header ads area", 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget' => '</div>','before_title' => '<h3>','after_title' => '</h3>')); }
  105. if ( ot_get_option('footer-ads') == 'on' ) { register_sidebar(array( 'name' => 'Footer Ads','id' => 'footer-ads', 'description' => "Footer ads area", 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget' => '</div>','before_title' => '<h3>','after_title' => '</h3>')); }
  106. if ( ot_get_option('footer-widgets') >= '1' ) { register_sidebar(array( 'name' => 'Footer 1','id' => 'footer-1', 'description' => "Widgetized footer", 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget' => '</div>','before_title' => '<h3>','after_title' => '</h3>')); }
  107. if ( ot_get_option('footer-widgets') >= '2' ) { register_sidebar(array( 'name' => 'Footer 2','id' => 'footer-2', 'description' => "Widgetized footer", 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget' => '</div>','before_title' => '<h3>','after_title' => '</h3>')); }
  108. if ( ot_get_option('footer-widgets') >= '3' ) { register_sidebar(array( 'name' => 'Footer 3','id' => 'footer-3', 'description' => "Widgetized footer", 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget' => '</div>','before_title' => '<h3>','after_title' => '</h3>')); }
  109. if ( ot_get_option('footer-widgets') >= '4' ) { register_sidebar(array( 'name' => 'Footer 4','id' => 'footer-4', 'description' => "Widgetized footer", 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget' => '</div>','before_title' => '<h3>','after_title' => '</h3>')); }
  110. }
  111.  
  112. }
  113. add_action( 'widgets_init', 'alx_sidebars' );
  114.  
  115.  
  116. /* Enqueue javascript
  117. /* ------------------------------------ */
  118. if ( ! function_exists( 'alx_scripts' ) ) {
  119.  
  120. function alx_scripts() {
  121. wp_enqueue_script( 'flexslider', get_template_directory_uri() . '/js/jquery.flexslider.min.js', array( 'jquery' ),'', false );
  122. wp_enqueue_script( 'scripts', get_template_directory_uri() . '/js/scripts.js', array( 'jquery' ),'', true );
  123. if ( is_singular() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); }
  124. }
  125.  
  126. }
  127. add_action( 'wp_enqueue_scripts', 'alx_scripts' );
  128.  
  129.  
  130. /* Enqueue css
  131. /* ------------------------------------ */
  132. if ( ! function_exists( 'alx_styles' ) ) {
  133.  
  134. function alx_styles() {
  135. wp_enqueue_style( 'style', get_stylesheet_uri() );
  136. if ( ot_get_option('responsive') != 'off' ) { wp_enqueue_style( 'responsive', get_template_directory_uri().'/responsive.css' ); }
  137. wp_enqueue_style( 'font-awesome', get_template_directory_uri().'/fonts/font-awesome.min.css' );
  138. }
  139.  
  140. }
  141. add_action( 'wp_enqueue_scripts', 'alx_styles' );
  142.  
  143.  
  144. /* Register custom sidebars
  145. /* ------------------------------------ */
  146. if ( ! function_exists( 'alx_custom_sidebars' ) ) {
  147.  
  148. function alx_custom_sidebars() {
  149. if ( !ot_get_option('sidebar-areas') =='' ) {
  150.  
  151. $sidebars = ot_get_option('sidebar-areas', array());
  152.  
  153. if ( !empty( $sidebars ) ) {
  154. foreach( $sidebars as $sidebar ) {
  155. if ( isset($sidebar['title']) && !empty($sidebar['title']) && isset($sidebar['id']) && !empty($sidebar['id']) && ($sidebar['id'] !='sidebar-') ) {
  156. register_sidebar(array('name' => ''.$sidebar['title'].'','id' => ''.strtolower($sidebar['id']).'','before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget' => '</div>','before_title' => '<h3>','after_title' => '</h3>'));
  157. }
  158. }
  159. }
  160. }
  161. }
  162.  
  163. }
  164. add_action( 'widgets_init', 'alx_custom_sidebars' );
  165.  
  166.  
  167. /* ------------------------------------------------------------------------- *
  168. * Template functions
  169. /* ------------------------------------------------------------------------- */
  170.  
  171. /* Layout class
  172. /* ------------------------------------ */
  173. if ( ! function_exists( 'alx_layout_class' ) ) {
  174.  
  175. function alx_layout_class() {
  176. // Default layout
  177. $layout = 'col-3cm';
  178. $default = 'col-3cm';
  179.  
  180. // Check for page/post specific layout
  181. if ( is_page() || is_single() ) {
  182. // Reset post data
  183. wp_reset_postdata();
  184. global $post;
  185. // Get meta
  186. $meta = get_post_meta($post->ID,'_layout',true);
  187. // Get if set and not set to inherit
  188. if ( isset($meta) && !empty($meta) && $meta != 'inherit' ) { $layout = $meta; }
  189. // Else check for page-global / single-global
  190. elseif ( is_single() && ( ot_get_option('layout-single') !='inherit' ) ) $layout = ot_get_option('layout-single',''.$default.'');
  191. elseif ( is_page() && ( ot_get_option('layout-page') !='inherit' ) ) $layout = ot_get_option('layout-page',''.$default.'');
  192. // Else get global option
  193. else $layout = ot_get_option('layout-global',''.$default.'');
  194. }
  195.  
  196. // Set layout based on page
  197. elseif ( is_home() && ( ot_get_option('layout-home') !='inherit' ) ) $layout = ot_get_option('layout-home',''.$default.'');
  198. elseif ( is_category() && ( ot_get_option('layout-archive-category') !='inherit' ) ) $layout = ot_get_option('layout-archive-category',''.$default.'');
  199. elseif ( is_archive() && ( ot_get_option('layout-archive') !='inherit' ) ) $layout = ot_get_option('layout-archive',''.$default.'');
  200. elseif ( is_search() && ( ot_get_option('layout-search') !='inherit' ) ) $layout = ot_get_option('layout-search',''.$default.'');
  201. elseif ( is_404() && ( ot_get_option('layout-404') !='inherit' ) ) $layout = ot_get_option('layout-404',''.$default.'');
  202.  
  203. // Global option
  204. else $layout = ot_get_option('layout-global',''.$default.'');
  205.  
  206. // Return layout class
  207. return $layout;
  208. }
  209.  
  210. }
  211.  
  212.  
  213. /* Dynamic sidebar primary
  214. /* ------------------------------------ */
  215. if ( ! function_exists( 'alx_sidebar_primary' ) ) {
  216.  
  217. function alx_sidebar_primary() {
  218. // Default sidebar
  219. $sidebar = 'primary';
  220.  
  221. // Set sidebar based on page
  222. if ( is_home() && ot_get_option('s1-home') ) $sidebar = ot_get_option('s1-home');
  223. if ( is_single() && ot_get_option('s1-single') ) $sidebar = ot_get_option('s1-single');
  224. if ( is_archive() && ot_get_option('s1-archive') ) $sidebar = ot_get_option('s1-archive');
  225. if ( is_category() && ot_get_option('s1-archive-category') ) $sidebar = ot_get_option('s1-archive-category');
  226. if ( is_search() && ot_get_option('s1-search') ) $sidebar = ot_get_option('s1-search');
  227. if ( is_404() && ot_get_option('s1-404') ) $sidebar = ot_get_option('s1-404');
  228. if ( is_page() && ot_get_option('s1-page') ) $sidebar = ot_get_option('s1-page');
  229.  
  230. // Check for page/post specific sidebar
  231. if ( is_page() || is_single() ) {
  232. // Reset post data
  233. wp_reset_postdata();
  234. global $post;
  235. // Get meta
  236. $meta = get_post_meta($post->ID,'_sidebar_primary',true);
  237. if ( $meta ) { $sidebar = $meta; }
  238. }
  239.  
  240. // Return sidebar
  241. return $sidebar;
  242. }
  243.  
  244. }
  245.  
  246.  
  247. /* Dynamic sidebar secondary
  248. /* ------------------------------------ */
  249. if ( ! function_exists( 'alx_sidebar_secondary' ) ) {
  250.  
  251. function alx_sidebar_secondary() {
  252. // Default sidebar
  253. $sidebar = 'secondary';
  254.  
  255. // Set sidebar based on page
  256. if ( is_home() && ot_get_option('s2-home') ) $sidebar = ot_get_option('s2-home');
  257. if ( is_single() && ot_get_option('s2-single') ) $sidebar = ot_get_option('s2-single');
  258. if ( is_archive() && ot_get_option('s2-archive') ) $sidebar = ot_get_option('s2-archive');
  259. if ( is_category() && ot_get_option('s2-archive-category') ) $sidebar = ot_get_option('s2-archive-category');
  260. if ( is_search() && ot_get_option('s2-search') ) $sidebar = ot_get_option('s2-search');
  261. if ( is_404() && ot_get_option('s2-404') ) $sidebar = ot_get_option('s2-404');
  262. if ( is_page() && ot_get_option('s2-page') ) $sidebar = ot_get_option('s2-page');
  263.  
  264. // Check for page/post specific sidebar
  265. if ( is_page() || is_single() ) {
  266. // Reset post data
  267. wp_reset_postdata();
  268. global $post;
  269. // Get meta
  270. $meta = get_post_meta($post->ID,'_sidebar_secondary',true);
  271. if ( $meta ) { $sidebar = $meta; }
  272. }
  273.  
  274. // Return sidebar
  275. return $sidebar;
  276. }
  277.  
  278. }
  279.  
  280.  
  281. /* Social links
  282. /* ------------------------------------ */
  283. if ( ! function_exists( 'alx_social_links' ) ) {
  284.  
  285. function alx_social_links() {
  286. if ( !ot_get_option('social-links') =='' ) {
  287. $links = ot_get_option('social-links', array());
  288. if ( !empty( $links ) ) {
  289. echo '<ul class="social-links">';
  290. foreach( $links as $item ) {
  291.  
  292. // Build each separate html-section only if set
  293. if ( isset($item['title']) && !empty($item['title']) )
  294. { $title = 'title="' .$item['title']. '"'; } else $title = '';
  295. if ( isset($item['social-link']) && !empty($item['social-link']) )
  296. { $link = 'href="' .$item['social-link']. '"'; } else $link = '';
  297. if ( isset($item['social-target']) && !empty($item['social-target']) )
  298. { $target = 'target="' .$item['social-target']. '"'; } else $target = '';
  299. if ( isset($item['social-icon']) && !empty($item['social-icon']) )
  300. { $icon = 'class="fa ' .$item['social-icon']. '"'; } else $icon = '';
  301. if ( isset($item['social-color']) && !empty($item['social-color']) )
  302. { $color = 'style="color: ' .$item['social-color']. ';"'; } else $color = '';
  303.  
  304. // Put them together
  305. if ( isset($item['title']) && !empty($item['title']) && isset($item['social-icon']) && !empty($item['social-icon']) && ($item['social-icon'] !='fa-') ) {
  306. echo '<li><a rel="nofollow" class="social-tooltip" '.$title.' '.$link.' '.$target.'><i '.$icon.' '.$color.'></i></a></li>';
  307. }
  308. }
  309. echo '</ul>';
  310. }
  311. }
  312. }
  313.  
  314. }
  315.  
  316.  
  317. /* Site name/logo
  318. /* ------------------------------------ */
  319. if ( ! function_exists( 'alx_site_title' ) ) {
  320.  
  321. function alx_site_title() {
  322.  
  323. // Text or image?
  324. if ( ot_get_option('custom-logo') ) {
  325. $logo = '<img src="'.ot_get_option('custom-logo').'" alt="'.get_bloginfo('name').'">';
  326. } else {
  327. $logo = get_bloginfo('name');
  328. }
  329.  
  330. $link = '<a href="'.home_url('/').'" rel="home">'.$logo.'</a>';
  331.  
  332. if ( is_front_page() || is_home() ) {
  333. $sitename = '<h1 class="site-title">'.$link.'</h1>'."\n";
  334. } else {
  335. $sitename = '<p class="site-title">'.$link.'</p>'."\n";
  336. }
  337.  
  338. return $sitename;
  339. }
  340.  
  341. }
  342.  
  343.  
  344. /* Page title
  345. /* ------------------------------------ */
  346. if ( ! function_exists( 'alx_page_title' ) ) {
  347.  
  348. function alx_page_title() {
  349. global $post;
  350.  
  351. $heading = get_post_meta($post->ID,'_heading',true);
  352. $subheading = get_post_meta($post->ID,'_subheading',true);
  353. $title = $heading?$heading:the_title();
  354. if($subheading) {
  355. $title = $title.' <span>'.$subheading.'</span>';
  356. }
  357.  
  358. return $title;
  359. }
  360.  
  361. }
  362.  
  363.  
  364. /* Blog title
  365. /* ------------------------------------ */
  366. if ( ! function_exists( 'alx_blog_title' ) ) {
  367.  
  368. function alx_blog_title() {
  369. global $post;
  370. $heading = ot_get_option('blog-heading');
  371. $subheading = ot_get_option('blog-subheading');
  372. if($heading) {
  373. $title = $heading;
  374. } else {
  375. $title = get_bloginfo('name');
  376. }
  377. if($subheading) {
  378. $title = $title.' <span>'.$subheading.'</span>';
  379. }
  380.  
  381. return $title;
  382. }
  383.  
  384. }
  385.  
  386.  
  387. /* Related posts
  388. /* ------------------------------------ */
  389. if ( ! function_exists( 'alx_related_posts' ) ) {
  390.  
  391. function alx_related_posts() {
  392. wp_reset_postdata();
  393. global $post;
  394.  
  395. // Define shared post arguments
  396. $args = array(
  397. 'no_found_rows' => true,
  398. 'update_post_meta_cache' => false,
  399. 'update_post_term_cache' => false,
  400. 'ignore_sticky_posts' => 1,
  401. 'orderby' => 'rand',
  402. 'post__not_in' => array($post->ID),
  403. 'posts_per_page' => 3
  404. );
  405. // Related by categories
  406. if ( ot_get_option('related-posts') == 'categories' ) {
  407.  
  408. $cats = get_post_meta($post->ID, 'related-cat', true);
  409.  
  410. if ( !$cats ) {
  411. $cats = wp_get_post_categories($post->ID, array('fields'=>'ids'));
  412. $args['category__in'] = $cats;
  413. } else {
  414. $args['cat'] = $cats;
  415. }
  416. }
  417. // Related by tags
  418. if ( ot_get_option('related-posts') == 'tags' ) {
  419.  
  420. $tags = get_post_meta($post->ID, 'related-tag', true);
  421.  
  422. if ( !$tags ) {
  423. $tags = wp_get_post_tags($post->ID, array('fields'=>'ids'));
  424. $args['tag__in'] = $tags;
  425. } else {
  426. $args['tag_slug__in'] = explode(',', $tags);
  427. }
  428. if ( !$tags ) { $break = true; }
  429. }
  430.  
  431. $query = !isset($break)?new WP_Query($args):new WP_Query;
  432. return $query;
  433. }
  434.  
  435. }
  436.  
  437.  
  438. /* Get images attached to post
  439. /* ------------------------------------ */
  440. if ( ! function_exists( 'alx_post_images' ) ) {
  441.  
  442. function alx_post_images( $args=array() ) {
  443. global $post;
  444.  
  445. $defaults = array(
  446. 'numberposts' => -1,
  447. 'order' => 'ASC',
  448. 'orderby' => 'menu_order',
  449. 'post_mime_type' => 'image',
  450. 'post_parent' => $post->ID,
  451. 'post_type' => 'attachment',
  452. );
  453.  
  454. $args = wp_parse_args( $args, $defaults );
  455.  
  456. return get_posts( $args );
  457. }
  458.  
  459. }
  460.  
  461.  
  462. /* Get featured post ids
  463. /* ------------------------------------ */
  464. if ( ! function_exists( 'alx_get_featured_post_ids' ) ) {
  465.  
  466. function alx_get_featured_post_ids() {
  467. $args = array(
  468. 'category' => ot_get_option('featured-category'),
  469. 'numberposts' => ot_get_option('featured-posts-count')
  470. );
  471. $posts = get_posts($args);
  472. if ( !$posts ) return false;
  473. foreach ( $posts as $post )
  474. $ids[] = $post->ID;
  475. return $ids;
  476. }
  477.  
  478. }
  479.  
  480.  
  481. /* ------------------------------------------------------------------------- *
  482. * Admin panel functions
  483. /* ------------------------------------------------------------------------- */
  484.  
  485. /* Post formats script
  486. /* ------------------------------------ */
  487. if ( ! function_exists( 'alx_post_formats_script' ) ) {
  488.  
  489. function alx_post_formats_script( $hook ) {
  490. // Only load on posts, pages
  491. if ( !in_array($hook, array('post.php','post-new.php')) )
  492. return;
  493. wp_enqueue_script('post-formats', get_template_directory_uri() . '/functions/js/post-formats.js', array( 'jquery' ));
  494. }
  495.  
  496. }
  497. add_action( 'admin_enqueue_scripts', 'alx_post_formats_script');
  498.  
  499.  
  500. /* ------------------------------------------------------------------------- *
  501. * Filters
  502. /* ------------------------------------------------------------------------- */
  503.  
  504. /* Body class
  505. /* ------------------------------------ */
  506. if ( ! function_exists( 'alx_body_class' ) ) {
  507.  
  508. function alx_body_class( $classes ) {
  509. $classes[] = alx_layout_class();
  510. if ( ot_get_option( 'boxed' ) != 'on' ) { $classes[] = 'full-width'; }
  511. if ( ot_get_option( 'boxed' ) == 'on' ) { $classes[] = 'boxed'; }
  512. if ( has_nav_menu('topbar') ) { $classes[] = 'topbar-enabled'; }
  513. if ( ot_get_option( 'mobile-sidebar-hide' ) == 's1' ) { $classes[] = 'mobile-sidebar-hide-s1'; }
  514. if ( ot_get_option( 'mobile-sidebar-hide' ) == 's2' ) { $classes[] = 'mobile-sidebar-hide-s2'; }
  515. if ( ot_get_option( 'mobile-sidebar-hide' ) == 's1-s2' ) { $classes[] = 'mobile-sidebar-hide'; }
  516. return $classes;
  517. }
  518.  
  519. }
  520. add_filter( 'body_class', 'alx_body_class' );
  521.  
  522.  
  523. /* Custom rss feed
  524. /* ------------------------------------ */
  525. if ( ! function_exists( 'alx_feed_link' ) ) {
  526.  
  527. function alx_feed_link( $output, $feed ) {
  528. // Do not redirect comments feed
  529. if ( strpos( $output, 'comments' ) )
  530. return $output;
  531. // Return feed url
  532. return ot_get_option('rss-feed',$output);
  533. }
  534.  
  535. }
  536. add_filter( 'feed_link', 'alx_feed_link', 10, 2 );
  537.  
  538.  
  539. /* Custom favicon
  540. /* ------------------------------------ */
  541. if ( ! function_exists( 'alx_favicon' ) ) {
  542.  
  543. function alx_favicon() {
  544. if ( ot_get_option('favicon') ) {
  545. echo '<link rel="shortcut icon" href="'.ot_get_option('favicon').'" />'."\n";
  546. }
  547. }
  548.  
  549. }
  550. add_filter( 'wp_head', 'alx_favicon' );
  551.  
  552.  
  553. /* Excerpt ending
  554. /* ------------------------------------ */
  555. if ( ! function_exists( 'alx_excerpt_more' ) ) {
  556.  
  557. function alx_excerpt_more( $more ) {
  558. return '&#46;&#46;&#46;';
  559. }
  560.  
  561. }
  562. add_filter( 'excerpt_more', 'alx_excerpt_more' );
  563.  
  564.  
  565. /* Excerpt length
  566. /* ------------------------------------ */
  567. if ( ! function_exists( 'alx_excerpt_length' ) ) {
  568.  
  569. function alx_excerpt_length( $length ) {
  570. return ot_get_option('excerpt-length',$length);
  571. }
  572.  
  573. }
  574. add_filter( 'excerpt_length', 'alx_excerpt_length', 999 );
  575.  
  576.  
  577. /* Add wmode transparent to media embeds
  578. /* ------------------------------------ */
  579. if ( ! function_exists( 'alx_embed_wmode_transparent' ) ) {
  580.  
  581. function alx_embed_wmode_transparent( $html, $url, $attr ) {
  582. if ( strpos( $html, "<embed src=" ) !== false )
  583. { return str_replace('</param><embed', '</param><param name="wmode" value="opaque"></param><embed wmode="opaque" ', $html); }
  584. elseif ( strpos ( $html, 'feature=oembed' ) !== false )
  585. { return str_replace( 'feature=oembed', 'feature=oembed&wmode=opaque', $html ); }
  586. else
  587. { return $html; }
  588. }
  589.  
  590. }
  591. add_filter( 'embed_oembed_html', 'alx_embed_wmode_transparent', 10, 3 );
  592.  
  593.  
  594. /* Add responsive container to embeds
  595. /* ------------------------------------ */
  596. if ( ! function_exists( 'alx_embed_html' ) ) {
  597.  
  598. function alx_embed_html( $html, $url ) {
  599.  
  600. $pattern = '/^https?:\/\/(www\.)?twitter\.com/';
  601. $is_twitter = preg_match( $pattern, $url );
  602.  
  603. if ( 1 === $is_twitter ) {
  604. return $html;
  605. }
  606.  
  607. return '<div class="video-container">' . $html . '</div>';
  608. }
  609.  
  610. }
  611. add_filter( 'embed_oembed_html', 'alx_embed_html', 10, 3 );
  612.  
  613.  
  614. /* Add responsive container to jetpack embeds
  615. /* ------------------------------------ */
  616. if ( ! function_exists( 'alx_embed_html_jp' ) ) {
  617.  
  618. function alx_embed_html_jp( $html ) {
  619. return '<div class="video-container">' . $html . '</div>';
  620. }
  621.  
  622. }
  623. add_filter( 'video_embed_html', 'alx_embed_html_jp' );
  624.  
  625.  
  626. /* Upscale cropped thumbnails
  627. /* ------------------------------------ */
  628. if ( ! function_exists( 'alx_thumbnail_upscale' ) ) {
  629.  
  630. function alx_thumbnail_upscale( $default, $orig_w, $orig_h, $new_w, $new_h, $crop ){
  631. if ( !$crop ) return null; // let the wordpress default function handle this
  632.  
  633. $aspect_ratio = $orig_w / $orig_h;
  634. $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
  635.  
  636. $crop_w = round($new_w / $size_ratio);
  637. $crop_h = round($new_h / $size_ratio);
  638.  
  639. $s_x = floor( ($orig_w - $crop_w) / 2 );
  640. $s_y = floor( ($orig_h - $crop_h) / 2 );
  641.  
  642. return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
  643. }
  644.  
  645. }
  646. add_filter( 'image_resize_dimensions', 'alx_thumbnail_upscale', 10, 6 );
  647.  
  648.  
  649. /* Add shortcode support to text widget
  650. /* ------------------------------------ */
  651. add_filter( 'widget_text', 'do_shortcode' );
  652.  
  653.  
  654. /* Browser detection body_class() output
  655. /* ------------------------------------ */
  656. if ( ! function_exists( 'alx_browser_body_class' ) ) {
  657.  
  658. function alx_browser_body_class( $classes ) {
  659. global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
  660.  
  661. if($is_lynx) $classes[] = 'lynx';
  662. elseif($is_gecko) $classes[] = 'gecko';
  663. elseif($is_opera) $classes[] = 'opera';
  664. elseif($is_NS4) $classes[] = 'ns4';
  665. elseif($is_safari) $classes[] = 'safari';
  666. elseif($is_chrome) $classes[] = 'chrome';
  667. elseif($is_IE) {
  668. $browser = $_SERVER['HTTP_USER_AGENT'];
  669. $browser = substr( "$browser", 25, 8);
  670. if ($browser == "MSIE 7.0" ) {
  671. $classes[] = 'ie7';
  672. $classes[] = 'ie';
  673. } elseif ($browser == "MSIE 6.0" ) {
  674. $classes[] = 'ie6';
  675. $classes[] = 'ie';
  676. } elseif ($browser == "MSIE 8.0" ) {
  677. $classes[] = 'ie8';
  678. $classes[] = 'ie';
  679. } elseif ($browser == "MSIE 9.0" ) {
  680. $classes[] = 'ie9';
  681. $classes[] = 'ie';
  682. } else {
  683. $classes[] = 'ie';
  684. }
  685. }
  686. else $classes[] = 'unknown';
  687.  
  688. if( $is_iphone ) $classes[] = 'iphone';
  689.  
  690. return $classes;
  691. }
  692.  
  693. }
  694. add_filter( 'body_class', 'alx_browser_body_class' );
  695.  
  696.  
  697. /* ------------------------------------------------------------------------- *
  698. * Actions
  699. /* ------------------------------------------------------------------------- */
  700.  
  701. /* Include or exclude featured articles in loop
  702. /* ------------------------------------ */
  703. if ( ! function_exists( 'alx_pre_get_posts' ) ) {
  704.  
  705. function alx_pre_get_posts( $query ) {
  706. // Are we on main query ?
  707. if ( !$query->is_main_query() ) return;
  708. if ( $query->is_home() ) {
  709.  
  710. // Featured posts enabled
  711. if ( ot_get_option('featured-posts-count') != '0' ) {
  712. // Get featured post ids
  713. $featured_post_ids = alx_get_featured_post_ids();
  714. // Exclude posts
  715. if ( $featured_post_ids && !ot_get_option('featured-posts-include') )
  716. $query->set('post__not_in', $featured_post_ids);
  717. }
  718. }
  719. }
  720.  
  721. }
  722. add_action( 'pre_get_posts', 'alx_pre_get_posts' );
  723.  
  724.  
  725. /* Script for no-js / js class
  726. /* ------------------------------------ */
  727. if ( ! function_exists( 'alx_html_js_class' ) ) {
  728.  
  729. function alx_html_js_class () {
  730. echo '<script>document.documentElement.className = document.documentElement.className.replace("no-js","js");</script>'. "\n";
  731. }
  732.  
  733. }
  734. add_action( 'wp_head', 'alx_html_js_class', 1 );
  735.  
  736.  
  737. /* IE js header
  738. /* ------------------------------------ */
  739. if ( ! function_exists( 'alx_ie_js_header' ) ) {
  740.  
  741. function alx_ie_js_header () {
  742. echo '<!--[if lt IE 9]>'. "\n";
  743. echo '<script src="' . esc_url( get_template_directory_uri() . '/js/ie/html5.js' ) . '"></script>'. "\n";
  744. echo '<script src="' . esc_url( get_template_directory_uri() . '/js/ie/selectivizr.js' ) . '"></script>'. "\n";
  745. echo '<![endif]-->'. "\n";
  746. }
  747.  
  748. }
  749. add_action( 'wp_head', 'alx_ie_js_header' );
  750.  
  751.  
  752. /* IE js footer
  753. /* ------------------------------------ */
  754. if ( ! function_exists( 'alx_ie_js_footer' ) ) {
  755.  
  756. function alx_ie_js_footer () {
  757. echo '<!--[if lt IE 9]>'. "\n";
  758. echo '<script src="' . esc_url( get_template_directory_uri() . '/js/ie/respond.js' ) . '"></script>'. "\n";
  759. echo '<![endif]-->'. "\n";
  760. }
  761.  
  762. }
  763. add_action( 'wp_footer', 'alx_ie_js_footer', 20 );
  764.  
  765.  
  766. /* TGM plugin activation
  767. /* ------------------------------------ */
  768. if ( ! function_exists( 'alx_plugins' ) ) {
  769.  
  770. function alx_plugins() {
  771. if ( ot_get_option('recommended-plugins') != 'off' ) {
  772. // Add the following plugins
  773. $plugins = array(
  774. array(
  775. 'name' => 'Regenerate Thumbnails',
  776. 'slug' => 'regenerate-thumbnails',
  777. 'required' => false,
  778. 'force_activation' => false,
  779. 'force_deactivation'=> false,
  780. ),
  781. array(
  782. 'name' => 'WP-PageNavi',
  783. 'slug' => 'wp-pagenavi',
  784. 'required' => false,
  785. 'force_activation' => false,
  786. 'force_deactivation'=> false,
  787. ),
  788. array(
  789. 'name' => 'Responsive Lightbox',
  790. 'slug' => 'responsive-lightbox',
  791. 'required' => false,
  792. 'force_activation' => false,
  793. 'force_deactivation'=> false,
  794. ),
  795. array(
  796. 'name' => 'Contact Form 7',
  797. 'slug' => 'contact-form-7',
  798. 'required' => false,
  799. 'force_activation' => false,
  800. 'force_deactivation'=> false,
  801. )
  802. );
  803. tgmpa( $plugins );
  804. }
  805. }
  806.  
  807. }
  808. add_action( 'tgmpa_register', 'alx_plugins' );
  809.  
  810.  
  811. /* WooCommerce basic support
  812. /* ------------------------------------ */
  813. function alx_wc_wrapper_start() {
  814. echo '<section class="content">';
  815. echo '<div class="pad">';
  816. }
  817. function alx_wc_wrapper_end() {
  818. echo '</div>';
  819. echo '</section>';
  820. }
  821. remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
  822. remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
  823. add_action('woocommerce_before_main_content', 'alx_wc_wrapper_start', 10);
  824. add_action('woocommerce_after_main_content', 'alx_wc_wrapper_end', 10);
  825.  
  826.  
  827. /* WP-PageNavi support - @devinsays (via GitHub)
  828. /* ------------------------------------ */
  829. function alx_deregister_styles() {
  830. wp_deregister_style( 'wp-pagenavi' );
  831. }
  832. add_action( 'wp_print_styles', 'alx_deregister_styles', 100 );
  833.  
  834. //Add prices to variations
  835. add_filter( 'woocommerce_variation_option_name', 'display_price_in_variation_option_name' );
  836.  
  837. function display_price_in_variation_option_name( $term ) {
  838. global $wpdb, $product;
  839.  
  840. $result = $wpdb->get_col( "SELECT slug FROM {$wpdb->prefix}terms WHERE name = '$term'" );
  841.  
  842. $term_slug = ( !empty( $result ) ) ? $result[0] : $term;
  843.  
  844. $query = "SELECT postmeta.post_id AS product_id
  845. FROM {$wpdb->prefix}postmeta AS postmeta
  846. LEFT JOIN {$wpdb->prefix}posts AS products ON ( products.ID = postmeta.post_id )
  847. WHERE postmeta.meta_key LIKE 'attribute_%'
  848. AND postmeta.meta_value = '$term_slug'
  849. AND products.post_parent = $product->id";
  850.  
  851. $variation_id = $wpdb->get_col( $query );
  852.  
  853. $parent = wp_get_post_parent_id( $variation_id[0] );
  854.  
  855. if ( $parent > 0 ) {
  856. $_product = new WC_Product_Variation( $variation_id[0] );
  857.  
  858. //this is where you can actually customize how the price is displayed
  859. return $term . ' (' . woocommerce_price( $_product->get_price() ) . ')';
  860. }
  861. return $term;
  862.  
  863. }
  864.  
  865. add_filter( 'woocommerce_composited_product_quantity', 'wc_cp_show_zero_min_quantity', 10, 5 );
  866. function wc_cp_show_zero_min_quantity( $value, $min, $max, $product, $component_id ) {
  867. if ( (int) $value === 1 && (int) $min === 0 ) {
  868. $value = 0;
  869. }
  870. return $value;
  871. }
Advertisement
Add Comment
Please, Sign In to add comment