/modules/minileven/theme/pub/minileven/functions.php

  1. <?php 
  2. /** 
  3. * Minileven functions and definitions 
  4. * 
  5. * Sets up the theme and provides some helper functions. Some helper functions 
  6. * are used in the theme as custom template tags. Others are attached to action and 
  7. * filter hooks in WordPress to change core functionality. 
  8. * 
  9. * The first function, minileven_setup(), sets up the theme by registering support 
  10. * for various features in WordPress, such as post thumbnails, navigation menus, and the like. 
  11. * 
  12. * @package Minileven 
  13. */ 
  14.  
  15. /** 
  16. * Set the content width based on the theme's design and stylesheet. 
  17. */ 
  18. if ( ! isset( $content_width ) ) 
  19. $content_width = 584; 
  20.  
  21. /** 
  22. * Tell WordPress to run minileven_setup() when the 'after_setup_theme' hook is run. 
  23. */ 
  24. add_action( 'after_setup_theme', 'minileven_setup' ); 
  25.  
  26. if ( ! function_exists( 'minileven_setup' ) ): 
  27. /** 
  28. * Sets up theme defaults and registers support for various WordPress features. 
  29. */ 
  30. function minileven_setup() { 
  31. global $wp_version; 
  32.  
  33. /** 
  34. * Custom template tags for this theme. 
  35. */ 
  36. require( get_template_directory() . '/inc/template-tags.php' ); 
  37.  
  38. /** 
  39. * Custom functions that act independently of the theme templates 
  40. */ 
  41. require( get_template_directory() . '/inc/tweaks.php' ); 
  42.  
  43. /** 
  44. * Implement the Custom Header functions 
  45. */ 
  46. require( get_template_directory() . '/inc/custom-header.php' ); 
  47.  
  48. /** Make Minileven available for translation. 
  49. * Translations can be added to the /languages/ directory. 
  50. * If you're building a theme based on Minileven, use a find and replace 
  51. * to change 'minileven' to the name of your theme in all the template files. 
  52. */ 
  53. /** Don't load a minileven textdomain, as it uses the Jetpack textdomain. 
  54. load_theme_textdomain( 'minileven', get_template_directory() . '/languages' ); 
  55. */ 
  56.  
  57. // Add default posts and comments RSS feed links to <head>. 
  58. add_theme_support( 'automatic-feed-links' ); 
  59.  
  60. // This theme uses wp_nav_menu() in one location. 
  61. register_nav_menu( 'primary', __( 'Primary Menu', 'jetpack' ) ); 
  62.  
  63. // Add support for a variety of post formats 
  64. add_theme_support( 'post-formats', array( 'gallery' ) ); 
  65.  
  66. // Add support for custom backgrounds 
  67. add_theme_support( 'custom-background' ); 
  68.  
  69. // Add support for post thumbnails 
  70. add_theme_support( 'post-thumbnails' ); 
  71. endif; // minileven_setup 
  72.  
  73. /** 
  74. * Enqueue scripts and styles 
  75. */ 
  76. function minileven_scripts() { 
  77. global $post; 
  78.  
  79. wp_enqueue_style( 'style', get_stylesheet_uri() ); 
  80.  
  81. wp_enqueue_script( 'small-menu', get_template_directory_uri() . '/js/small-menu.js', array( 'jquery' ), '20120206', true ); 
  82.  
  83. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { 
  84. wp_enqueue_script( 'comment-reply' ); 
  85. add_action( 'wp_enqueue_scripts', 'minileven_scripts' ); 
  86.  
  87. function minileven_fonts() { 
  88.  
  89. /** translators: If there are characters in your language that are not supported 
  90. by Open Sans, translate this to 'off'. Do not translate into your own language. */ 
  91.  
  92. if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'jetpack' ) ) { 
  93.  
  94. $opensans_subsets = 'latin, latin-ext'; 
  95.  
  96. /** translators: To add an additional Open Sans character subset specific to your language, translate 
  97. this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language. */ 
  98. $opensans_subset = _x( 'no-subset', 'Open Sans font: add new subset (greek, cyrillic, vietnamese)', 'jetpack' ); 
  99.  
  100. if ( 'cyrillic' == $opensans_subset ) 
  101. $opensans_subsets .= ', cyrillic, cyrillic-ext'; 
  102. elseif ( 'greek' == $opensans_subset ) 
  103. $opensans_subsets .= ', greek, greek-ext'; 
  104. elseif ( 'vietnamese' == $opensans_subset ) 
  105. $opensans_subsets .= ', vietnamese'; 
  106.  
  107. $opensans_query_args = array( 
  108. 'family' => 'Open+Sans:200, 200italic, 300, 300italic, 400, 400italic, 600, 600italic, 700, 700italic',  
  109. 'subset' => $opensans_subsets,  
  110. ); 
  111. wp_register_style( 'minileven-open-sans', add_query_arg( $opensans_query_args, "//fonts.googleapis.com/css" ), array(), null ); 
  112. add_action( 'init', 'minileven_fonts' ); 
  113.  
  114. /** 
  115. * Register our sidebars and widgetized areas. 
  116. * @since Minileven 1.0 
  117. */ 
  118. function minileven_widgets_init() { 
  119. register_sidebar( array( 
  120. 'name' => __( 'Main Sidebar', 'jetpack' ),  
  121. 'id' => 'sidebar-1',  
  122. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',  
  123. 'after_widget' => "</aside>",  
  124. 'before_title' => '<h3 class="widget-title">',  
  125. 'after_title' => '</h3>',  
  126. ) ); 
  127. add_action( 'widgets_init', 'minileven_widgets_init' ); 
  128.  
  129. function minileven_posts_per_page() { 
  130. return 5; 
  131. add_filter('pre_option_posts_per_page', 'minileven_posts_per_page'); 
  132.  
  133. /** 
  134. * Determine the currently active theme. 
  135. */ 
  136. function minileven_actual_current_theme() { 
  137. $removed = remove_action( 'option_stylesheet', 'jetpack_mobile_stylesheet' ); 
  138. $stylesheet = get_option( 'stylesheet' ); 
  139. if ( $removed ) 
  140. add_action( 'option_stylesheet', 'jetpack_mobile_stylesheet' ); 
  141.  
  142. return $stylesheet; 
  143.  
  144. /** This function grabs the location of the custom menus from the current theme. If no menu is set in a location 
  145. * it will return a boolean "false". This function helps Minileven know which custom menu to display. */ 
  146. function minileven_get_menu_location() { 
  147. $theme_slug = minileven_actual_current_theme(); 
  148. $mods = get_option( "theme_mods_{$theme_slug}" ); 
  149.  
  150. if ( has_filter( 'jetpack_mobile_theme_menu' ) ) { 
  151.  
  152. /** 
  153. * Filter the menu displayed in the Mobile Theme. 
  154. * 
  155. * @module minileven 
  156. * 
  157. * @since 3.4.0 
  158. * 
  159. * @param int $menu_id ID of the menu to display. 
  160. */ 
  161. return array( 'primary' => apply_filters( 'jetpack_mobile_theme_menu', $menu_id ) ); 
  162.  
  163. if ( isset( $mods['nav_menu_locations'] ) && ! empty( $mods['nav_menu_locations'] ) ) 
  164. return $mods['nav_menu_locations']; 
  165.  
  166. return false; 
  167.  
  168. /** This function grabs the custom background image from the user's current theme so that Minileven can display it. */ 
  169. function minileven_get_background() { 
  170. $theme_slug = minileven_actual_current_theme(); 
  171. $mods = get_option( "theme_mods_$theme_slug" ); 
  172.  
  173. if ( ! empty( $mods ) ) { 
  174. return array( 
  175. 'color' => isset( $mods['background_color'] ) ? $mods['background_color'] : null,  
  176. 'image' => isset( $mods['background_image'] ) ? $mods['background_image'] : null,  
  177. 'repeat' => isset( $mods['background_repeat'] ) ? $mods['background_repeat'] : null,  
  178. 'position' => isset( $mods['background_position_x'] ) ? $mods['background_position_x'] : null,  
  179. 'attachment' => isset( $mods['attachment'] ) ? $mods['attachment'] : null,  
  180. ); 
  181. return false; 
  182.  
  183. /** 
  184. * If the user has set a static front page, show all posts on the front page, instead of a static page. 
  185. */ 
  186. if ( '1' == get_option( 'wp_mobile_static_front_page' ) ) 
  187. add_filter( 'pre_option_page_on_front', '__return_zero' ); 
  188.  
  189. /** 
  190. * Retrieves the IDs for images in a gallery. 
  191. * 
  192. * @uses get_post_galleries() first, if available. Falls back to shortcode parsing,  
  193. * then as last option uses a get_posts() call. 
  194. * 
  195. * @return array List of image IDs from the post gallery. 
  196. */ 
  197. function minileven_get_gallery_images() { 
  198. $images = array(); 
  199.  
  200. if ( function_exists( 'get_post_galleries' ) ) { 
  201. $galleries = get_post_galleries( get_the_ID(), false ); 
  202. if ( isset( $galleries[0]['ids'] ) ) 
  203. $images = explode( ', ', $galleries[0]['ids'] ); 
  204. } else { 
  205. $pattern = get_shortcode_regex(); 
  206. preg_match( "/$pattern/s", get_the_content(), $match ); 
  207. $atts = shortcode_parse_atts( $match[3] ); 
  208. if ( isset( $atts['ids'] ) ) 
  209. $images = explode( ', ', $atts['ids'] ); 
  210.  
  211. if ( ! $images ) { 
  212. $images = get_posts( array( 
  213. 'fields' => 'ids',  
  214. 'numberposts' => 999,  
  215. 'order' => 'ASC',  
  216. 'orderby' => 'menu_order',  
  217. 'post_mime_type' => 'image',  
  218. 'post_parent' => get_the_ID(),  
  219. 'post_type' => 'attachment',  
  220. ) ); 
  221.  
  222. return $images; 
  223.  
  224. /** 
  225. * Allow plugins to filter where Featured Images are displayed. 
  226. * Default has Featured Images disabled on single view and pages. 
  227. * 
  228. * @uses is_search() 
  229. * @uses apply_filters() 
  230. * @return bool 
  231. */ 
  232. function minileven_show_featured_images() { 
  233. $enabled = ( is_home() || is_search() || is_archive() ) ? true : false; 
  234.  
  235. /** 
  236. * Filter where featured images are displayed in the Mobile Theme. 
  237. * 
  238. * By setting $enabled to true or false using functions like is_home() or 
  239. * is_archive(), you can control where featured images are be displayed. 
  240. * 
  241. * @module minileven 
  242. * 
  243. * @since 3.2.0 
  244. * 
  245. * @param bool $enabled True if featured images should be displayed, false if not. 
  246. */ 
  247. return (bool) apply_filters( 'minileven_show_featured_images', $enabled ); 
.