PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/t/glam/functions.php

https://bitbucket.org/matthewselby/wpdev
PHP | 339 lines | 199 code | 87 blank | 53 comment | 12 complexity | 183bc028131a7d382d3962de55a0ddee MD5 | raw file
Possible License(s): Apache-2.0, GPL-2.0, LGPL-3.0, LGPL-2.1, AGPL-1.0, BSD-3-Clause, MIT, GPL-3.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * Glam.
  4. *
  5. * @package Glam
  6. * @link http://restored316designs.com/themes
  7. * @author Lauren Gaige // Restored 316 LLC
  8. * @copyright Copyright (c) 2015, Restored 316 LLC, Released 02/03/2016
  9. * @license GPL-2.0+
  10. */
  11. //* Start the engine
  12. require_once( get_template_directory() . '/lib/init.php' );
  13. //* Add HTML5 markup structure
  14. add_theme_support( 'html5' );
  15. //* Add viewport meta tag for mobile browsers
  16. add_theme_support( 'genesis-responsive-viewport' );
  17. //* Child theme (do not remove)
  18. define( 'CHILD_THEME_NAME', 'Glam' );
  19. define( 'CHILD_THEME_URL', 'http://restored316designs.com' );
  20. define( 'CHILD_THEME_VERSION', '1.0.3' );
  21. //* Add Color Selection to WordPress Theme Customizer
  22. require_once( get_stylesheet_directory() . '/lib/customize.php' );
  23. //* Setup Theme
  24. include_once( get_stylesheet_directory() . '/lib/theme-defaults.php' );
  25. //* Add Widget Spaces
  26. require_once( get_stylesheet_directory() . '/lib/widgets.php' );
  27. //* Install Plugins
  28. require_once( get_stylesheet_directory() . '/lib/plugins/tgm-plugin-activation/register-plugins.php' );
  29. //* Enqueue Responsive Menu, Google fonts, Match Height script, and dashicons
  30. add_action( 'wp_enqueue_scripts', 'glam_google_fonts' );
  31. function glam_google_fonts() {
  32. wp_enqueue_script( 'glam-responsive-menu', get_bloginfo( 'stylesheet_directory' ) . '/js/responsive-menu.js', array( 'jquery' ), '1.0.0' );
  33. wp_enqueue_style( 'google-font', '//fonts.googleapis.com/css?family=Work+Sans:400,200,100,300,500,600,700,800,900|Arapey:400,400italic|Montserrat', array() );
  34. wp_enqueue_script( 'match-height', get_stylesheet_directory_uri() . '/js/jquery.matchHeight-min.js', array( 'jquery' ), '1.0.0', true );
  35. wp_enqueue_script( 'match-height-init', get_stylesheet_directory_uri() . '/js/matchheight-init.js', array( 'match-height' ), '1.0.0', true );
  36. wp_enqueue_style( 'dashicons' );
  37. }
  38. //* Add new image sizes
  39. add_image_size( 'blog-square-featured', 400, 400, TRUE );
  40. add_image_size( 'blog-vertical-featured', 800, 1200, TRUE );
  41. add_image_size( 'sidebar-featured', 125, 125, TRUE );
  42. add_image_size( 'large-featured', 850, 475, TRUE );
  43. //* Add support for custom background
  44. add_theme_support( 'custom-background' );
  45. //* Add support for after entry widget
  46. add_theme_support( 'genesis-after-entry-widget-area' );
  47. //* Add support for custom header
  48. add_theme_support( 'custom-header', array(
  49. 'width' => 900,
  50. 'height' => 400,
  51. 'flex-width' => false,
  52. 'flex-height' => false,
  53. 'header-selector' => '.site-title a',
  54. 'header-text' => false,
  55. ) );
  56. //* Remove the site description
  57. remove_action( 'genesis_site_description', 'genesis_seo_site_description' );
  58. //* Add support for 2-column footer widgets
  59. add_theme_support( 'genesis-footer-widgets', 1 );
  60. //* Unregister layout settings
  61. genesis_unregister_layout( 'content-sidebar-sidebar' );
  62. genesis_unregister_layout( 'sidebar-content-sidebar' );
  63. genesis_unregister_layout( 'sidebar-sidebar-content' );
  64. //* Unregister secondary sidebar
  65. unregister_sidebar( 'sidebar-alt' );
  66. //* Reposition the primary navigation
  67. remove_action( 'genesis_after_header', 'genesis_do_nav' );
  68. add_action( 'genesis_before', 'genesis_do_nav' );
  69. //* Add search form to navigation
  70. add_filter( 'wp_nav_menu_items', 'glam_primary_nav_extras', 10, 2 );
  71. function glam_primary_nav_extras( $menu, $args ) {
  72. //* Change 'primary' to 'secondary' to add extras to the secondary navigation menu
  73. if ( 'primary' !== $args->theme_location ) {
  74. return $menu;
  75. }
  76. ob_start();
  77. get_search_form();
  78. $search = ob_get_clean();
  79. $menu .= '<li class="right search">' . $search . '</li>';
  80. return $menu;
  81. }
  82. //* Customize search form input box text
  83. add_filter( 'genesis_search_text', 'glam_search_text' );
  84. function glam_search_text( $text ) {
  85. return esc_attr( 'Search...' );
  86. }
  87. //* Modify the Genesis content limit read more link
  88. add_filter( 'get_the_content_more_link', 'glam_read_more_link' );
  89. function glam_read_more_link() {
  90. return '... <a class="more-link" href="' . get_permalink() . '">View Post</a>';
  91. }
  92. //* Add widget to secondary navigation
  93. add_filter( 'genesis_nav_items', 'glam_social_icons', 10, 2 );
  94. add_filter( 'wp_nav_menu_items', 'glam_social_icons', 10, 2 );
  95. function glam_social_icons($menu, $args) {
  96. $args = (array)$args;
  97. if ( 'primary' !== $args['theme_location'] )
  98. return $menu;
  99. ob_start();
  100. genesis_widget_area('nav-social-menu');
  101. $social = ob_get_clean();
  102. return $menu . $social;
  103. }
  104. //* Hooks widget area before content
  105. add_action( 'genesis_before_content', 'glam_cta_widget', 2 );
  106. function glam_cta_widget() {
  107. genesis_widget_area( 'cta-widget', array(
  108. 'before' => '<div class="cta-widget widget-area"><div class="wrap">',
  109. 'after' => '</div></div>',
  110. ) );
  111. }
  112. //* Customize the Post Info Function
  113. add_filter( 'genesis_post_info', 'glam_post_info_filter' );
  114. function glam_post_info_filter( $post_info ) {
  115. $post_info = '[post_categories before="in "] on [post_date format="m/d/y"]';
  116. return $post_info;
  117. }
  118. //* Customize the Post Meta function
  119. add_filter( 'genesis_post_meta', 'glam_post_meta_filter' );
  120. function glam_post_meta_filter( $post_meta ) {
  121. $post_meta = '[post_comments zero="Add a Comment" one="1 Comment" more="% Comments"]';
  122. return $post_meta;
  123. }
  124. //* Load Entry Navigation
  125. add_action( 'genesis_after_entry', 'genesis_prev_next_post_nav', 7 );
  126. //* Add support for footer menu
  127. add_theme_support ( 'genesis-menus' , array (
  128. 'primary' => 'Primary Navigation Menu',
  129. 'secondary' => 'Secondary Navigation Menu',
  130. 'footer' => 'Footer Navigation Menu'
  131. ) );
  132. //* Hook menu in footer
  133. add_action( 'genesis_after', 'glam_footer_menu', 13 );
  134. function glam_footer_menu() {
  135. printf( '<nav %s>', genesis_attr( 'nav-footer' ) );
  136. wp_nav_menu( array(
  137. 'theme_location' => 'footer',
  138. 'container' => false,
  139. 'depth' => 1,
  140. 'fallback_cb' => false,
  141. 'menu_class' => 'genesis-nav-menu',
  142. ) );
  143. echo '</nav>';
  144. }
  145. //* Reposition the footer widgets
  146. remove_action( 'genesis_before_footer', 'genesis_footer_widget_areas' );
  147. add_action( 'genesis_after', 'genesis_footer_widget_areas' );
  148. //* Reposition the site footer
  149. remove_action( 'genesis_footer', 'genesis_footer_markup_open', 5 );
  150. remove_action( 'genesis_footer', 'genesis_do_footer' );
  151. remove_action( 'genesis_footer', 'genesis_footer_markup_close', 15 );
  152. add_action( 'genesis_after', 'genesis_footer_markup_open', 11 );
  153. add_action( 'genesis_after', 'genesis_do_footer', 12 );
  154. add_action( 'genesis_after', 'genesis_footer_markup_close', 14 );
  155. //* Setup widget count
  156. function glam_count_widgets( $id ) {
  157. global $sidebars_widgets;
  158. if ( isset( $sidebars_widgets[ $id ] ) ) {
  159. return count( $sidebars_widgets[ $id ] );
  160. }
  161. }
  162. function glam_widget_area_class( $id ) {
  163. $count = glam_count_widgets( $id );
  164. $class = '';
  165. if( $count == 1 || $count < 9 ) {
  166. $classes = array(
  167. 'zero',
  168. 'one',
  169. 'two',
  170. 'three',
  171. 'four',
  172. 'five',
  173. 'six',
  174. 'seven',
  175. 'eight',
  176. );
  177. $class = $classes[ $count ] . '-widget';
  178. $class = $count == 1 ? $class : $class . 's';
  179. return $class;
  180. } else {
  181. $class = 'widget-thirds';
  182. return $class;
  183. }
  184. }
  185. //* Modify the size of the Gravatar in the entry comments
  186. add_filter( 'genesis_comment_list_args', 'glam_comments_gravatar' );
  187. function glam_comments_gravatar( $args ) {
  188. $args['avatar_size'] = 96;
  189. return $args;
  190. }
  191. //* Modify the size of the Gravatar in the author box
  192. add_filter( 'genesis_author_box_gravatar_size', 'glam_author_box_gravatar' );
  193. function glam_author_box_gravatar( $size ) {
  194. return 125;
  195. }
  196. //* Add widget area between and after 3 posts
  197. add_action( 'genesis_after_entry', 'glam_between_posts_area' );
  198. function glam_between_posts_area() {
  199. global $loop_counter;
  200. $loop_counter++;
  201. if( $loop_counter == 4 ) {
  202. if ( is_active_sidebar( 'between-posts-area' ) ) {
  203. echo '<div class="between-posts-area widget-area"><div class="wrap">';
  204. dynamic_sidebar( 'between-posts-area' );
  205. echo '</div></div><!-- end .top -->';
  206. }
  207. $loop_counter = 10;
  208. }
  209. }
  210. //* Remove comment form allowed tags
  211. add_filter( 'comment_form_defaults', 'glam_remove_comment_form_allowed_tags' );
  212. function glam_remove_comment_form_allowed_tags( $defaults ) {
  213. $defaults['comment_notes_after'] = '';
  214. return $defaults;
  215. }
  216. //* Reposition Featured Images
  217. remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
  218. add_action( 'genesis_before_entry', 'genesis_do_post_image', 9 );
  219. //* Customize the credits
  220. add_filter('genesis_footer_creds_text', 'custom_footer_creds_text');
  221. function custom_footer_creds_text() {
  222. echo '<div class="creds"><p>';
  223. echo 'Copyright &copy; ';
  224. echo date('Y');
  225. echo ' &middot; <a target="_blank" href="http://restored316designs.com/themes">glam theme</a> by <a target="_blank" href="http://www.restored316designs.com">Restored 316</a>';
  226. echo '</p></div>';
  227. }
  228. //* Add Theme Support for WooCommerce
  229. add_theme_support( 'genesis-connect-woocommerce' );
  230. //* Remove Related Products
  231. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
  232. //* Remove Add to Cart on Archives
  233. add_action( 'woocommerce_after_shop_loop_item', 'remove_add_to_cart_buttons', 1 );
  234. function remove_add_to_cart_buttons() {
  235. remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
  236. }
  237. //* Change number or products per row to 3
  238. add_filter('loop_shop_columns', 'loop_columns');
  239. if (!function_exists('loop_columns')) {
  240. function loop_columns() {
  241. return 3; // 3 products per row
  242. }
  243. }
  244. //* Display 12 products per page
  245. add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 12;' ), 20 );
  246. //* Add WooCommerce Gallery Options
  247. add_action( 'after_setup_theme', 'glam_woo_gallery' );
  248. function glam_woo_gallery() {
  249. add_theme_support( 'wc-product-gallery-zoom' );
  250. add_theme_support( 'wc-product-gallery-lightbox' );
  251. add_theme_support( 'wc-product-gallery-slider' );
  252. }