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

/wp-content/themes/twentyfifteen/functions.php

https://gitlab.com/math4youbyusgroupillinois/WordPress
PHP | 331 lines | 144 code | 43 blank | 144 comment | 29 complexity | 91567c7d8859d2bdd1f432db060e16bd MD5 | raw file
  1. <?php
  2. /**
  3. * Twenty Fifteen functions and definitions
  4. *
  5. * Set up the theme and provides some helper functions, which are used in the
  6. * theme as custom template tags. Others are attached to action and filter
  7. * hooks in WordPress to change core functionality.
  8. *
  9. * When using a child theme you can override certain functions (those wrapped
  10. * in a function_exists() call) by defining them first in your child theme's
  11. * functions.php file. The child theme's functions.php file is included before
  12. * the parent theme's file, so the child theme functions would be used.
  13. *
  14. * @link https://codex.wordpress.org/Theme_Development
  15. * @link https://codex.wordpress.org/Child_Themes
  16. *
  17. * Functions that are not pluggable (not wrapped in function_exists()) are
  18. * instead attached to a filter or action hook.
  19. *
  20. * For more information on hooks, actions, and filters,
  21. * {@link https://codex.wordpress.org/Plugin_API}
  22. *
  23. * @package WordPress
  24. * @subpackage Twenty_Fifteen
  25. * @since Twenty Fifteen 1.0
  26. */
  27. /**
  28. * Set the content width based on the theme's design and stylesheet.
  29. *
  30. * @since Twenty Fifteen 1.0
  31. */
  32. if ( ! isset( $content_width ) ) {
  33. $content_width = 660;
  34. }
  35. /**
  36. * Twenty Fifteen only works in WordPress 4.1 or later.
  37. */
  38. if ( version_compare( $GLOBALS['wp_version'], '4.1-alpha', '<' ) ) {
  39. require get_template_directory() . '/inc/back-compat.php';
  40. }
  41. if ( ! function_exists( 'twentyfifteen_setup' ) ) :
  42. /**
  43. * Sets up theme defaults and registers support for various WordPress features.
  44. *
  45. * Note that this function is hooked into the after_setup_theme hook, which
  46. * runs before the init hook. The init hook is too late for some features, such
  47. * as indicating support for post thumbnails.
  48. *
  49. * @since Twenty Fifteen 1.0
  50. */
  51. function twentyfifteen_setup() {
  52. /*
  53. * Make theme available for translation.
  54. * Translations can be filed in the /languages/ directory.
  55. * If you're building a theme based on twentyfifteen, use a find and replace
  56. * to change 'twentyfifteen' to the name of your theme in all the template files
  57. */
  58. load_theme_textdomain( 'twentyfifteen', get_template_directory() . '/languages' );
  59. // Add default posts and comments RSS feed links to head.
  60. add_theme_support( 'automatic-feed-links' );
  61. /*
  62. * Let WordPress manage the document title.
  63. * By adding theme support, we declare that this theme does not use a
  64. * hard-coded <title> tag in the document head, and expect WordPress to
  65. * provide it for us.
  66. */
  67. add_theme_support( 'title-tag' );
  68. /*
  69. * Enable support for Post Thumbnails on posts and pages.
  70. *
  71. * See: https://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
  72. */
  73. add_theme_support( 'post-thumbnails' );
  74. set_post_thumbnail_size( 825, 510, true );
  75. // This theme uses wp_nav_menu() in two locations.
  76. register_nav_menus( array(
  77. 'primary' => __( 'Primary Menu', 'twentyfifteen' ),
  78. 'social' => __( 'Social Links Menu', 'twentyfifteen' ),
  79. ) );
  80. /*
  81. * Switch default core markup for search form, comment form, and comments
  82. * to output valid HTML5.
  83. */
  84. add_theme_support( 'html5', array(
  85. 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
  86. ) );
  87. /*
  88. * Enable support for Post Formats.
  89. *
  90. * See: https://codex.wordpress.org/Post_Formats
  91. */
  92. add_theme_support( 'post-formats', array(
  93. 'aside', 'image', 'video', 'quote', 'link', 'gallery', 'status', 'audio', 'chat'
  94. ) );
  95. $color_scheme = twentyfifteen_get_color_scheme();
  96. $default_color = trim( $color_scheme[0], '#' );
  97. // Setup the WordPress core custom background feature.
  98. add_theme_support( 'custom-background', apply_filters( 'twentyfifteen_custom_background_args', array(
  99. 'default-color' => $default_color,
  100. 'default-attachment' => 'fixed',
  101. ) ) );
  102. /*
  103. * This theme styles the visual editor to resemble the theme style,
  104. * specifically font, colors, icons, and column width.
  105. */
  106. add_editor_style( array( 'css/editor-style.css', 'genericons/genericons.css', twentyfifteen_fonts_url() ) );
  107. }
  108. endif; // twentyfifteen_setup
  109. add_action( 'after_setup_theme', 'twentyfifteen_setup' );
  110. /**
  111. * Register widget area.
  112. *
  113. * @since Twenty Fifteen 1.0
  114. *
  115. * @link https://codex.wordpress.org/Function_Reference/register_sidebar
  116. */
  117. function twentyfifteen_widgets_init() {
  118. register_sidebar( array(
  119. 'name' => __( 'Widget Area', 'twentyfifteen' ),
  120. 'id' => 'sidebar-1',
  121. 'description' => __( 'Add widgets here to appear in your sidebar.', 'twentyfifteen' ),
  122. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  123. 'after_widget' => '</aside>',
  124. 'before_title' => '<h2 class="widget-title">',
  125. 'after_title' => '</h2>',
  126. ) );
  127. }
  128. add_action( 'widgets_init', 'twentyfifteen_widgets_init' );
  129. if ( ! function_exists( 'twentyfifteen_fonts_url' ) ) :
  130. /**
  131. * Register Google fonts for Twenty Fifteen.
  132. *
  133. * @since Twenty Fifteen 1.0
  134. *
  135. * @return string Google fonts URL for the theme.
  136. */
  137. function twentyfifteen_fonts_url() {
  138. $fonts_url = '';
  139. $fonts = array();
  140. $subsets = 'latin,latin-ext';
  141. /* translators: If there are characters in your language that are not supported by Noto Sans, translate this to 'off'. Do not translate into your own language. */
  142. if ( 'off' !== _x( 'on', 'Noto Sans font: on or off', 'twentyfifteen' ) ) {
  143. $fonts[] = 'Noto Sans:400italic,700italic,400,700';
  144. }
  145. /* translators: If there are characters in your language that are not supported by Noto Serif, translate this to 'off'. Do not translate into your own language. */
  146. if ( 'off' !== _x( 'on', 'Noto Serif font: on or off', 'twentyfifteen' ) ) {
  147. $fonts[] = 'Noto Serif:400italic,700italic,400,700';
  148. }
  149. /* translators: If there are characters in your language that are not supported by Inconsolata, translate this to 'off'. Do not translate into your own language. */
  150. if ( 'off' !== _x( 'on', 'Inconsolata font: on or off', 'twentyfifteen' ) ) {
  151. $fonts[] = 'Inconsolata:400,700';
  152. }
  153. /* translators: To add an additional character subset specific to your language, translate this to 'greek', 'cyrillic', 'devanagari' or 'vietnamese'. Do not translate into your own language. */
  154. $subset = _x( 'no-subset', 'Add new subset (greek, cyrillic, devanagari, vietnamese)', 'twentyfifteen' );
  155. if ( 'cyrillic' == $subset ) {
  156. $subsets .= ',cyrillic,cyrillic-ext';
  157. } elseif ( 'greek' == $subset ) {
  158. $subsets .= ',greek,greek-ext';
  159. } elseif ( 'devanagari' == $subset ) {
  160. $subsets .= ',devanagari';
  161. } elseif ( 'vietnamese' == $subset ) {
  162. $subsets .= ',vietnamese';
  163. }
  164. if ( $fonts ) {
  165. $fonts_url = add_query_arg( array(
  166. 'family' => urlencode( implode( '|', $fonts ) ),
  167. 'subset' => urlencode( $subsets ),
  168. ), '//fonts.googleapis.com/css' );
  169. }
  170. return $fonts_url;
  171. }
  172. endif;
  173. /**
  174. * Enqueue scripts and styles.
  175. *
  176. * @since Twenty Fifteen 1.0
  177. */
  178. function twentyfifteen_scripts() {
  179. // Add custom fonts, used in the main stylesheet.
  180. wp_enqueue_style( 'twentyfifteen-fonts', twentyfifteen_fonts_url(), array(), null );
  181. // Add Genericons, used in the main stylesheet.
  182. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.2' );
  183. // Load our main stylesheet.
  184. wp_enqueue_style( 'twentyfifteen-style', get_stylesheet_uri() );
  185. // Load the Internet Explorer specific stylesheet.
  186. wp_enqueue_style( 'twentyfifteen-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentyfifteen-style' ), '20141010' );
  187. wp_style_add_data( 'twentyfifteen-ie', 'conditional', 'lt IE 9' );
  188. // Load the Internet Explorer 7 specific stylesheet.
  189. wp_enqueue_style( 'twentyfifteen-ie7', get_template_directory_uri() . '/css/ie7.css', array( 'twentyfifteen-style' ), '20141010' );
  190. wp_style_add_data( 'twentyfifteen-ie7', 'conditional', 'lt IE 8' );
  191. wp_enqueue_script( 'twentyfifteen-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20141010', true );
  192. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  193. wp_enqueue_script( 'comment-reply' );
  194. }
  195. if ( is_singular() && wp_attachment_is_image() ) {
  196. wp_enqueue_script( 'twentyfifteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20141010' );
  197. }
  198. wp_enqueue_script( 'twentyfifteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20141212', true );
  199. wp_localize_script( 'twentyfifteen-script', 'screenReaderText', array(
  200. 'expand' => '<span class="screen-reader-text">' . __( 'expand child menu', 'twentyfifteen' ) . '</span>',
  201. 'collapse' => '<span class="screen-reader-text">' . __( 'collapse child menu', 'twentyfifteen' ) . '</span>',
  202. ) );
  203. }
  204. add_action( 'wp_enqueue_scripts', 'twentyfifteen_scripts' );
  205. /**
  206. * Add featured image as background image to post navigation elements.
  207. *
  208. * @since Twenty Fifteen 1.0
  209. *
  210. * @see wp_add_inline_style()
  211. */
  212. function twentyfifteen_post_nav_background() {
  213. if ( ! is_single() ) {
  214. return;
  215. }
  216. $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
  217. $next = get_adjacent_post( false, '', false );
  218. $css = '';
  219. if ( is_attachment() && 'attachment' == $previous->post_type ) {
  220. return;
  221. }
  222. if ( $previous && has_post_thumbnail( $previous->ID ) ) {
  223. $prevthumb = wp_get_attachment_image_src( get_post_thumbnail_id( $previous->ID ), 'post-thumbnail' );
  224. $css .= '
  225. .post-navigation .nav-previous { background-image: url(' . esc_url( $prevthumb[0] ) . '); }
  226. .post-navigation .nav-previous .post-title, .post-navigation .nav-previous a:hover .post-title, .post-navigation .nav-previous .meta-nav { color: #fff; }
  227. .post-navigation .nav-previous a:before { background-color: rgba(0, 0, 0, 0.4); }
  228. ';
  229. }
  230. if ( $next && has_post_thumbnail( $next->ID ) ) {
  231. $nextthumb = wp_get_attachment_image_src( get_post_thumbnail_id( $next->ID ), 'post-thumbnail' );
  232. $css .= '
  233. .post-navigation .nav-next { background-image: url(' . esc_url( $nextthumb[0] ) . '); }
  234. .post-navigation .nav-next .post-title, .post-navigation .nav-next a:hover .post-title, .post-navigation .nav-next .meta-nav { color: #fff; }
  235. .post-navigation .nav-next a:before { background-color: rgba(0, 0, 0, 0.4); }
  236. ';
  237. }
  238. wp_add_inline_style( 'twentyfifteen-style', $css );
  239. }
  240. add_action( 'wp_enqueue_scripts', 'twentyfifteen_post_nav_background' );
  241. /**
  242. * Display descriptions in main navigation.
  243. *
  244. * @since Twenty Fifteen 1.0
  245. *
  246. * @param string $item_output The menu item output.
  247. * @param WP_Post $item Menu item object.
  248. * @param int $depth Depth of the menu.
  249. * @param array $args wp_nav_menu() arguments.
  250. * @return string Menu item with possible description.
  251. */
  252. function twentyfifteen_nav_description( $item_output, $item, $depth, $args ) {
  253. if ( 'primary' == $args->theme_location && $item->description ) {
  254. $item_output = str_replace( $args->link_after . '</a>', '<div class="menu-item-description">' . $item->description . '</div>' . $args->link_after . '</a>', $item_output );
  255. }
  256. return $item_output;
  257. }
  258. add_filter( 'walker_nav_menu_start_el', 'twentyfifteen_nav_description', 10, 4 );
  259. /**
  260. * Add a `screen-reader-text` class to the search form's submit button.
  261. *
  262. * @since Twenty Fifteen 1.0
  263. *
  264. * @param string $html Search form HTML.
  265. * @return string Modified search form HTML.
  266. */
  267. function twentyfifteen_search_form_modify( $html ) {
  268. return str_replace( 'class="search-submit"', 'class="search-submit screen-reader-text"', $html );
  269. }
  270. add_filter( 'get_search_form', 'twentyfifteen_search_form_modify' );
  271. /**
  272. * Implement the Custom Header feature.
  273. *
  274. * @since Twenty Fifteen 1.0
  275. */
  276. require get_template_directory() . '/inc/custom-header.php';
  277. /**
  278. * Custom template tags for this theme.
  279. *
  280. * @since Twenty Fifteen 1.0
  281. */
  282. require get_template_directory() . '/inc/template-tags.php';
  283. /**
  284. * Customizer additions.
  285. *
  286. * @since Twenty Fifteen 1.0
  287. */
  288. require get_template_directory() . '/inc/customizer.php';