Advertisement
Guest User

Functions.php

a guest
Jul 22nd, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.08 KB | None | 0 0
  1. <?php
  2. require get_template_directory() . '/inc/helpers.php';
  3. require get_template_directory() . '/inc/sanitization.php';
  4. require get_template_directory() . '/inc/functions.php';
  5. require get_template_directory() . '/inc/helpers-post-meta.php';
  6. require get_template_directory() . '/inc/customizer.php';
  7. require get_template_directory() . '/inc/customizer-styles.php';
  8.  
  9. add_action( 'after_setup_theme', 'olsen_light_content_width', 0 );
  10. function olsen_light_content_width() {
  11. $GLOBALS['content_width'] = apply_filters( 'olsen_light_content_width', 665 );
  12. }
  13.  
  14. add_action( 'after_setup_theme', 'olsen_light_setup' );
  15. if( !function_exists( 'olsen_light_setup' ) ) :
  16. function olsen_light_setup() {
  17.  
  18. if ( ! defined( 'CI_THEME_NAME' ) ) {
  19. define( 'CI_THEME_NAME', 'olsen-light' );
  20. }
  21.  
  22. load_theme_textdomain( 'olsen-light', get_template_directory() . '/languages' );
  23.  
  24. /*
  25. * Theme supports.
  26. */
  27. add_theme_support( 'automatic-feed-links' );
  28. add_theme_support( 'title-tag' );
  29. add_theme_support( 'post-thumbnails' );
  30. add_theme_support( 'html5', array(
  31. 'search-form',
  32. 'comment-form',
  33. 'comment-list',
  34. 'gallery',
  35. 'caption',
  36. ) );
  37.  
  38. /*
  39. * Image sizes.
  40. */
  41. set_post_thumbnail_size( 665, 435, true );
  42. add_image_size( 'olsen_light_square', 200, 200, true );
  43.  
  44. /*
  45. * Navigation menus.
  46. */
  47. register_nav_menus( array(
  48. 'main_menu' => esc_html__( 'Main Menu', 'olsen-light' ),
  49. 'footer_menu' => esc_html__( 'Footer Menu', 'olsen-light' ),
  50. ) );
  51.  
  52. /*
  53. * Default hooks
  54. */
  55. // Prints the inline JS scripts that are registered for printing, and removes them from the queue.
  56. add_action( 'admin_footer', 'olsen_light_print_inline_js' );
  57. add_action( 'wp_footer', 'olsen_light_print_inline_js' );
  58.  
  59. // Handle the dismissible sample content notice.
  60. add_action( 'admin_notices', 'olsen_light_admin_notice_sample_content' );
  61. add_action( 'wp_ajax_olsen_light_dismiss_sample_content', 'olsen_light_ajax_dismiss_sample_content' );
  62.  
  63. // Wraps post counts in span.ci-count
  64. // Needed for the default widgets, however more appropriate filters don't exist.
  65. add_filter( 'get_archives_link', 'olsen_light_wrap_archive_widget_post_counts_in_span', 10, 2 );
  66. add_filter( 'wp_list_categories', 'olsen_light_wrap_category_widget_post_counts_in_span', 10, 2 );
  67. }
  68. endif;
  69.  
  70.  
  71.  
  72. add_action( 'wp_enqueue_scripts', 'olsen_light_enqueue_scripts' );
  73. function olsen_light_enqueue_scripts() {
  74.  
  75. /*
  76. * Styles
  77. */
  78. $theme = wp_get_theme();
  79.  
  80. $font_url = '';
  81. /* translators: If there are characters in your language that are not supported by Lora and Lato, translate this to 'off'. Do not translate into your own language. */
  82. if ( 'off' !== _x( 'on', 'Lora and Lato fonts: on or off', 'olsen-light' ) ) {
  83. $font_url = add_query_arg( 'family', urlencode( 'Lora:400,700,400italic,700italic|Lato:400,400italic,700,700italic' ), '//fonts.googleapis.com/css' );
  84. }
  85. wp_register_style( 'olsen-light-google-font', esc_url( $font_url ) );
  86.  
  87. wp_register_style( 'olsen-light-base', get_template_directory_uri() . '/css/base.css', array(), $theme->get( 'Version' ) );
  88. wp_register_style( 'font-awesome', get_template_directory_uri() . '/css/font-awesome.css', array(), '4.5.0' );
  89. wp_register_style( 'olsen-light-magnific', get_template_directory_uri() . '/css/magnific.css', array(), '1.0.0' );
  90. wp_register_style( 'olsen-light-slick', get_template_directory_uri() . '/css/slick.css', array(), '1.5.7' );
  91. wp_register_style( 'olsen-light-mmenu', get_template_directory_uri() . '/css/mmenu.css', array(), '5.2.0' );
  92.  
  93. wp_enqueue_style( 'olsen-light-style', get_template_directory_uri() . '/style.css', array(
  94. 'olsen-light-google-font',
  95. 'olsen-light-base',
  96. 'font-awesome',
  97. 'olsen-light-magnific',
  98. 'olsen-light-slick',
  99. 'olsen-light-mmenu'
  100. ), $theme->get( 'Version' ) );
  101.  
  102. if( is_child_theme() ) {
  103. wp_enqueue_style( 'olsen-light-style-child', get_stylesheet_directory_uri() . '/style.css', array(
  104. 'olsen-light-style',
  105. ), $theme->get( 'Version' ) );
  106. }
  107.  
  108. /*
  109. * Scripts
  110. */
  111. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  112. wp_enqueue_script( 'comment-reply' );
  113. }
  114.  
  115. wp_register_script( 'olsen-light-superfish', get_template_directory_uri() . '/js/superfish.js', array( 'jquery' ), '1.7.5', true );
  116. wp_register_script( 'olsen-light-matchHeight', get_template_directory_uri() . '/js/jquery.matchHeight.js', array( 'jquery' ), $theme->get( 'Version' ), true );
  117. wp_register_script( 'olsen-light-slick', get_template_directory_uri() . '/js/slick.js', array( 'jquery' ), '1.5.7', true );
  118. wp_register_script( 'olsen-light-mmenu-offcanvas', get_template_directory_uri() . '/js/jquery.mmenu.offcanvas.js', array( 'jquery' ), '5.2.0', true );
  119. wp_register_script( 'olsen-light-mmenu-navbars', get_template_directory_uri() . '/js/jquery.mmenu.navbars.js', array( 'jquery' ), '5.2.0', true );
  120. wp_register_script( 'olsen-light-mmenu-autoheight', get_template_directory_uri() . '/js/jquery.mmenu.autoheight.js', array( 'jquery' ), '5.2.0', true );
  121. wp_register_script( 'olsen-light-mmenu', get_template_directory_uri() . '/js/jquery.mmenu.oncanvas.js', array( 'jquery', ), '5.2.0', true );
  122. wp_register_script( 'olsen-light-fitVids', get_template_directory_uri() . '/js/jquery.fitvids.js', array( 'jquery' ), '1.1', true );
  123. wp_register_script( 'olsen-light-magnific', get_template_directory_uri() . '/js/jquery.magnific-popup.js', array( 'jquery' ), '1.0.0', true );
  124.  
  125. /*
  126. * Enqueue
  127. */
  128. wp_enqueue_script( 'olsen-light-front-scripts', get_template_directory_uri() . '/js/scripts.js', array(
  129. 'jquery',
  130. 'olsen-light-superfish',
  131. 'olsen-light-matchHeight',
  132. 'olsen-light-slick',
  133. 'olsen-light-mmenu',
  134. 'olsen-light-mmenu-offcanvas',
  135. 'olsen-light-mmenu-navbars',
  136. 'olsen-light-mmenu-autoheight',
  137. 'olsen-light-fitVids',
  138. 'olsen-light-magnific'
  139. ), $theme->get( 'Version' ), true );
  140.  
  141. }
  142.  
  143. add_action( 'admin_enqueue_scripts', 'olsen_light_admin_enqueue_scripts' );
  144. function olsen_light_admin_enqueue_scripts( $hook ) {
  145. $theme = wp_get_theme();
  146.  
  147. /*
  148. * Styles
  149. */
  150.  
  151.  
  152. /*
  153. * Scripts
  154. */
  155. wp_register_script( 'olsen-light-customizer', get_template_directory_uri() . '/js/admin/customizer-scripts.js', array( 'jquery' ), $theme->get( 'Version' ), true );
  156. $params = array(
  157. 'documentation_text' => esc_html__( 'Documentation', 'olsen-light' ),
  158. 'upgrade_text' => esc_html__( 'Upgrade to Pro', 'olsen-light' ),
  159. );
  160. wp_localize_script( 'olsen-light-customizer', 'olsen_light_customizer', $params );
  161.  
  162.  
  163. /*
  164. * Enqueue
  165. */
  166. if ( in_array( $hook, array( 'post.php', 'post-new.php' ) ) ) {
  167. wp_enqueue_media();
  168. wp_enqueue_style( 'olsen-light-post-meta' );
  169. wp_enqueue_script( 'olsen-light-post-meta' );
  170. }
  171.  
  172. if ( in_array( $hook, array( 'profile.php', 'user-edit.php' ) ) ) {
  173. wp_enqueue_media();
  174. wp_enqueue_style( 'olsen-light-post-meta' );
  175. wp_enqueue_script( 'olsen-light-post-meta' );
  176. }
  177.  
  178. if ( in_array( $hook, array( 'widgets.php', 'customize.php' ) ) ) {
  179. wp_enqueue_media();
  180. wp_enqueue_style( 'olsen-light-post-meta' );
  181. wp_enqueue_script( 'olsen-light-post-meta' );
  182. wp_enqueue_script( 'olsen-light-customizer' );
  183. }
  184.  
  185. }
  186.  
  187. add_action( 'customize_controls_print_styles', 'olsen_light_enqueue_customizer_styles' );
  188. function olsen_light_enqueue_customizer_styles() {
  189. $theme = wp_get_theme();
  190.  
  191. wp_register_style( 'olsen-light-customizer-styles', get_template_directory_uri() . '/css/admin/customizer-styles.css', array(), $theme->get( 'Version' ) );
  192. wp_enqueue_style( 'olsen-light-customizer-styles' );
  193. }
  194.  
  195.  
  196. add_action( 'widgets_init', 'olsen_light_widgets_init' );
  197. function olsen_light_widgets_init() {
  198. register_sidebar( array(
  199. 'name' => esc_html_x( 'Blog', 'widget area', 'olsen-light' ),
  200. 'id' => 'blog',
  201. 'description' => esc_html__( 'This is the main sidebar.', 'olsen-light' ),
  202. 'before_widget' => '<aside id="%1$s" class="widget group %2$s">',
  203. 'after_widget' => '</aside>',
  204. 'before_title' => '<h3 class="widget-title">',
  205. 'after_title' => '</h3>',
  206. ) );
  207.  
  208. register_sidebar( array(
  209. 'name' => esc_html_x( 'Pages', 'widget area', 'olsen-light' ),
  210. 'id' => 'page',
  211. 'description' => esc_html__( 'This sidebar appears on your static pages. If empty, the Blog sidebar will be shown instead.', 'olsen-light' ),
  212. 'before_widget' => '<aside id="%1$s" class="widget group %2$s">',
  213. 'after_widget' => '</aside>',
  214. 'before_title' => '<h3 class="widget-title">',
  215. 'after_title' => '</h3>',
  216. ) );
  217.  
  218. register_sidebar( array(
  219. 'name' => esc_html_x( 'Footer Sidebar', 'widget area', 'olsen-light' ),
  220. 'id' => 'footer-widgets',
  221. 'description' => esc_html__( 'Special site-wide sidebar for the WP Instagram Widget plugin.', 'olsen-light' ),
  222. 'before_widget' => '<aside id="%1$s" class="widget group %2$s">',
  223. 'after_widget' => '</aside>',
  224. 'before_title' => '<h3 class="widget-title">',
  225. 'after_title' => '</h3>',
  226. ) );
  227. }
  228.  
  229. add_action( 'widgets_init', 'olsen_light_load_widgets' );
  230. function olsen_light_load_widgets() {
  231. require get_template_directory() . '/inc/widgets/about-me.php';
  232. require get_template_directory() . '/inc/widgets/latest-posts.php';
  233. require get_template_directory() . '/inc/widgets/socials.php';
  234. }
  235.  
  236. add_filter( 'excerpt_length', 'olsen_light_excerpt_length' );
  237. function olsen_light_excerpt_length( $length ) {
  238. return get_theme_mod( 'excerpt_length', 55 );
  239. }
  240.  
  241.  
  242. add_filter( 'previous_posts_link_attributes', 'olsen_light_previous_posts_link_attributes' );
  243. function olsen_light_previous_posts_link_attributes( $attrs ) {
  244. $attrs .= ' class="paging-standard paging-older"';
  245. return $attrs;
  246. }
  247. add_filter( 'next_posts_link_attributes', 'olsen_light_next_posts_link_attributes' );
  248. function olsen_light_next_posts_link_attributes( $attrs ) {
  249. $attrs .= ' class="paging-standard paging-newer"';
  250. return $attrs;
  251. }
  252.  
  253. add_filter( 'wp_page_menu', 'olsen_light_wp_page_menu', 10, 2 );
  254. function olsen_light_wp_page_menu( $menu, $args ) {
  255. preg_match( '#^<div class="(.*?)">(?:.*?)</div>$#', $menu, $matches );
  256. $menu = preg_replace( '#^<div class=".*?">#', '', $menu, 1 );
  257. $menu = preg_replace( '#</div>$#', '', $menu, 1 );
  258. $menu = preg_replace( '#^<ul>#', '<ul class="' . esc_attr( $args['menu_class'] ) . '">', $menu, 1 );
  259. return $menu;
  260. }
  261.  
  262.  
  263. add_filter( 'the_content', 'olsen_light_lightbox_rel', 12 );
  264. add_filter( 'get_comment_text', 'olsen_light_lightbox_rel' );
  265. add_filter( 'wp_get_attachment_link', 'olsen_light_lightbox_rel' );
  266. if ( ! function_exists( 'olsen_light_lightbox_rel' ) ):
  267. function olsen_light_lightbox_rel( $content ) {
  268. global $post;
  269. $pattern = "/<a(.*?)href=('|\")([^>]*).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>(.*?)<\/a>/i";
  270. $replacement = '<a$1href=$2$3.$4$5 data-lightbox="gal[' . $post->ID . ']"$6>$7</a>';
  271. $content = preg_replace( $pattern, $replacement, $content );
  272.  
  273. return $content;
  274. }
  275. endif;
  276.  
  277.  
  278. add_filter( 'wp_link_pages_args', 'olsen_light_wp_link_pages_args' );
  279. function olsen_light_wp_link_pages_args( $params ) {
  280. $params = array_merge( $params, array(
  281. 'before' => '<p class="link-pages">' . esc_html__( 'Pages:', 'olsen-light' ),
  282. 'after' => '</p>',
  283. ) );
  284.  
  285. return $params;
  286. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement