PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/functions.php

https://gitlab.com/kerrongordon/strose
PHP | 297 lines | 121 code | 48 blank | 128 comment | 3 complexity | 82ae1c1fdca756d92cc9e5233a2ffdd7 MD5 | raw file
Possible License(s): 0BSD, BSD-3-Clause, BSD-2-Clause, MIT
  1. <?php
  2. /*
  3. Author: Eddie Machado
  4. URL: http://themble.com/bones/
  5. This is where you can drop your custom functions or
  6. just edit things like thumbnail sizes, header images,
  7. sidebars, comments, ect.
  8. */
  9. // LOAD BONES CORE (if you remove this, the theme will break)
  10. require_once( 'library/bones.php' );
  11. // CUSTOMIZE THE WORDPRESS ADMIN (off by default)
  12. // require_once( 'library/admin.php' );
  13. /*********************
  14. LAUNCH BONES
  15. Let's get everything up and running.
  16. *********************/
  17. function bones_ahoy() {
  18. //Allow editor style.
  19. add_editor_style( get_stylesheet_directory_uri() . '/library/css/editor-style.css' );
  20. // let's get language support going, if you need it
  21. load_theme_textdomain( 'strose', get_template_directory() . '/library/translation' );
  22. // USE THIS TEMPLATE TO CREATE CUSTOM POST TYPES EASILY
  23. require_once( 'library/custom-post-type.php' );
  24. // launching operation cleanup
  25. add_action( 'init', 'bones_head_cleanup' );
  26. // A better title
  27. add_filter( 'wp_title', 'rw_title', 10, 3 );
  28. // remove WP version from RSS
  29. add_filter( 'the_generator', 'bones_rss_version' );
  30. // remove pesky injected css for recent comments widget
  31. add_filter( 'wp_head', 'bones_remove_wp_widget_recent_comments_style', 1 );
  32. // clean up comment styles in the head
  33. add_action( 'wp_head', 'bones_remove_recent_comments_style', 1 );
  34. // clean up gallery output in wp
  35. add_filter( 'gallery_style', 'bones_gallery_style' );
  36. // enqueue base scripts and styles
  37. add_action( 'wp_enqueue_scripts', 'bones_scripts_and_styles', 999 );
  38. // ie conditional wrapper
  39. // launching this stuff after theme setup
  40. bones_theme_support();
  41. // adding sidebars to Wordpress (these are created in functions.php)
  42. add_action( 'widgets_init', 'bones_register_sidebars' );
  43. // cleaning up random code around images
  44. add_filter( 'the_content', 'bones_filter_ptags_on_images' );
  45. // cleaning up excerpt
  46. add_filter( 'excerpt_more', 'bones_excerpt_more' );
  47. } /* end bones ahoy */
  48. // let's get this party started
  49. add_action( 'after_setup_theme', 'bones_ahoy' );
  50. /************* OEMBED SIZE OPTIONS *************/
  51. if ( ! isset( $content_width ) ) {
  52. $content_width = 640;
  53. }
  54. /************* THUMBNAIL SIZE OPTIONS *************/
  55. // Thumbnail sizes
  56. add_image_size( 'bones-thumb-600', 600, 150, true );
  57. add_image_size( 'bones-thumb-300', 300, 100, true );
  58. /*
  59. to add more sizes, simply copy a line from above
  60. and change the dimensions & name. As long as you
  61. upload a "featured image" as large as the biggest
  62. set width or height, all the other sizes will be
  63. auto-cropped.
  64. To call a different size, simply change the text
  65. inside the thumbnail function.
  66. For example, to call the 300 x 100 sized image,
  67. we would use the function:
  68. <?php the_post_thumbnail( 'bones-thumb-300' ); ?>
  69. for the 600 x 150 image:
  70. <?php the_post_thumbnail( 'bones-thumb-600' ); ?>
  71. You can change the names and dimensions to whatever
  72. you like. Enjoy!
  73. */
  74. add_filter( 'image_size_names_choose', 'bones_custom_image_sizes' );
  75. function bones_custom_image_sizes( $sizes ) {
  76. return array_merge( $sizes, array(
  77. 'bones-thumb-600' => __('600px by 150px'),
  78. 'bones-thumb-300' => __('300px by 100px'),
  79. ) );
  80. }
  81. /*
  82. The function above adds the ability to use the dropdown menu to select
  83. the new images sizes you have just created from within the media manager
  84. when you add media to your content blocks. If you add more image sizes,
  85. duplicate one of the lines in the array and name it according to your
  86. new image size.
  87. */
  88. /************* THEME CUSTOMIZE *********************/
  89. /*
  90. A good tutorial for creating your own Sections, Controls and Settings:
  91. http://code.tutsplus.com/series/a-guide-to-the-wordpress-theme-customizer--wp-33722
  92. Good articles on modifying the default options:
  93. http://natko.com/changing-default-wordpress-theme-customization-api-sections/
  94. http://code.tutsplus.com/tutorials/digging-into-the-theme-customizer-components--wp-27162
  95. To do:
  96. - Create a js for the postmessage transport method
  97. - Create some sanitize functions to sanitize inputs
  98. - Create some boilerplate Sections, Controls and Settings
  99. */
  100. function bones_theme_customizer($wp_customize) {
  101. // $wp_customize calls go here.
  102. //
  103. // Uncomment the below lines to remove the default customize sections
  104. // $wp_customize->remove_section('title_tagline');
  105. // $wp_customize->remove_section('colors');
  106. // $wp_customize->remove_section('background_image');
  107. // $wp_customize->remove_section('static_front_page');
  108. // $wp_customize->remove_section('nav');
  109. // Uncomment the below lines to remove the default controls
  110. // $wp_customize->remove_control('blogdescription');
  111. // Uncomment the following to change the default section titles
  112. // $wp_customize->get_section('colors')->title = __( 'Theme Colors' );
  113. // $wp_customize->get_section('background_image')->title = __( 'Images' );
  114. }
  115. add_action( 'customize_register', 'bones_theme_customizer' );
  116. /************* ACTIVE SIDEBARS ********************/
  117. // Sidebars & Widgetizes Areas
  118. function bones_register_sidebars() {
  119. register_sidebar(array(
  120. 'id' => 'sidebar1',
  121. 'name' => __( 'Sidebar 1', 'strose' ),
  122. 'description' => __( 'The first (primary) sidebar.', 'strose' ),
  123. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  124. 'after_widget' => '</div>',
  125. 'before_title' => '<h4 class="widgettitle">',
  126. 'after_title' => '</h4>',
  127. ));
  128. register_sidebar(array(
  129. 'id' => 'footerbar',
  130. 'name' => __( 'Footer-bar', 'strose' ),
  131. 'description' => __( 'The footer-bar sidebar.', 'strose' ),
  132. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  133. 'after_widget' => '</div>',
  134. 'before_title' => '<h4 class="">',
  135. 'after_title' => '</h4>',
  136. ));
  137. register_sidebar(array(
  138. 'id' => 'homepagemain',
  139. 'name' => __( 'Home page main content', 'strose' ),
  140. 'description' => __( 'The footer-bar sidebar.', 'strose' ),
  141. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  142. 'after_widget' => '</div>',
  143. 'before_title' => '<h4 class="">',
  144. 'after_title' => '</h4>',
  145. ));
  146. register_sidebar(array(
  147. 'id' => 'homesidebar',
  148. 'name' => __( 'Home page sidebar', 'strose' ),
  149. 'description' => __( 'The footer-bar sidebar.', 'strose' ),
  150. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  151. 'after_widget' => '</div>',
  152. 'before_title' => '<h4 class="">',
  153. 'after_title' => '</h4>',
  154. ));
  155. register_sidebar(array(
  156. 'id' => 'subscriptions',
  157. 'name' => __( 'Home page subscriptions', 'strose' ),
  158. 'description' => __( 'The footer-bar sidebar.', 'strose' ),
  159. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  160. 'after_widget' => '</div>',
  161. 'before_title' => '<h2 class="">&#8220',
  162. 'after_title' => '&#8221</h2>',
  163. ));
  164. /*
  165. to add more sidebars or widgetized areas, just copy
  166. and edit the above sidebar code. In order to call
  167. your new sidebar just use the following code:
  168. Just change the name to whatever your new
  169. sidebar's id is, for example:
  170. register_sidebar(array(
  171. 'id' => 'sidebar2',
  172. 'name' => __( 'Sidebar 2', 'strose' ),
  173. 'description' => __( 'The second (secondary) sidebar.', 'strose' ),
  174. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  175. 'after_widget' => '</div>',
  176. 'before_title' => '<h4 class="widgettitle">',
  177. 'after_title' => '</h4>',
  178. ));
  179. To call the sidebar in your template, you can just copy
  180. the sidebar.php file and rename it to your sidebar's name.
  181. So using the above example, it would be:
  182. sidebar-sidebar2.php
  183. */
  184. } // don't remove this bracket!
  185. /************* COMMENT LAYOUT *********************/
  186. // Comment Layout
  187. function bones_comments( $comment, $args, $depth ) {
  188. $GLOBALS['comment'] = $comment; ?>
  189. <div id="comment-<?php comment_ID(); ?>" <?php comment_class('cf'); ?>>
  190. <article class="cf">
  191. <header class="comment-author vcard">
  192. <?php
  193. /*
  194. this is the new responsive optimized comment image. It used the new HTML5 data-attribute to display comment gravatars on larger screens only. What this means is that on larger posts, mobile sites don't have a ton of requests for comment images. This makes load time incredibly fast! If you'd like to change it back, just replace it with the regular wordpress gravatar call:
  195. echo get_avatar($comment,$size='32',$default='<path_to_url>' );
  196. */
  197. ?>
  198. <?php // custom gravatar call ?>
  199. <?php
  200. // create variable
  201. $bgauthemail = get_comment_author_email();
  202. ?>
  203. <img data-gravatar="http://www.gravatar.com/avatar/<?php echo md5( $bgauthemail ); ?>?s=40" class="load-gravatar avatar avatar-48 photo" height="40" width="40" src="<?php echo get_template_directory_uri(); ?>/library/images/nothing.gif" />
  204. <?php // end custom gravatar call ?>
  205. <?php printf(__( '<cite class="fn">%1$s</cite> %2$s', 'strose' ), get_comment_author_link(), edit_comment_link(__( '(Edit)', 'strose' ),' ','') ) ?>
  206. <time datetime="<?php echo comment_time('Y-m-j'); ?>"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php comment_time(__( 'F jS, Y', 'strose' )); ?> </a></time>
  207. </header>
  208. <?php if ($comment->comment_approved == '0') : ?>
  209. <div class="alert alert-info">
  210. <p><?php _e( 'Your comment is awaiting moderation.', 'strose' ) ?></p>
  211. </div>
  212. <?php endif; ?>
  213. <section class="comment_content cf">
  214. <?php comment_text() ?>
  215. </section>
  216. <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  217. </article>
  218. <?php // </li> is added by WordPress automatically ?>
  219. <?php
  220. } // don't remove this bracket!
  221. /*
  222. This is a modification of a function found in the
  223. twentythirteen theme where we can declare some
  224. external fonts. If you're using Google Fonts, you
  225. can replace these fonts, change it in your scss files
  226. and be up and running in seconds.
  227. */
  228. function bones_fonts() {
  229. wp_enqueue_style('googleFonts', 'http://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic');
  230. wp_enqueue_style('SatisfyFonts', 'http://fonts.googleapis.com/css?family=Satisfy');
  231. }
  232. add_action('wp_enqueue_scripts', 'bones_fonts');
  233. // Enable support for HTML5 markup.
  234. add_theme_support( 'html5', array(
  235. 'comment-list',
  236. 'search-form',
  237. 'comment-form'
  238. ) );
  239. /* DON'T DELETE THIS CLOSING TAG */ ?>