functions.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <?php
  2. /**
  3. * Publication functions and definitions
  4. *
  5. * @package Publication
  6. */
  7. /**
  8. * Publication only works in WordPress 4.1 or later.
  9. */
  10. if ( version_compare( $GLOBALS['wp_version'], '4.1-alpha', '<' ) ) {
  11. require get_template_directory() . '/inc/back-compat.php';
  12. }
  13. if ( ! function_exists( 'publication_setup' ) ) :
  14. /**
  15. * Sets up theme defaults and registers support for various WordPress features.
  16. *
  17. * Note that this function is hooked into the after_setup_theme hook, which
  18. * runs before the init hook. The init hook is too late for some features, such
  19. * as indicating support for post thumbnails.
  20. */
  21. function publication_setup() {
  22. /*
  23. * Make theme available for translation.
  24. * Translations can be filed in the /languages/ directory.
  25. * If you're building a theme based on Publication, use a find and replace
  26. * to change 'publication' to the name of your theme in all the template files
  27. */
  28. load_theme_textdomain( 'publication', get_template_directory() . '/languages' );
  29. // Add default posts and comments RSS feed links to head.
  30. add_theme_support( 'automatic-feed-links' );
  31. /*
  32. * Let WordPress manage the document title.
  33. * By adding theme support, we declare that this theme does not use a
  34. * hard-coded <title> tag in the document head, and expect WordPress to
  35. * provide it for us.
  36. */
  37. add_theme_support( 'title-tag' );
  38. // Add support for responsive embeds.
  39. add_theme_support( 'responsive-embeds' );
  40. /**
  41. * Gutenberg wide and full images support
  42. */
  43. add_theme_support( 'align-wide' );
  44. // Add custom colors to Gutenberg
  45. add_theme_support(
  46. 'editor-color-palette', array(
  47. array(
  48. 'name' => esc_html__( 'Black', 'publication' ),
  49. 'slug' => 'black',
  50. 'color' => '#222',
  51. ),
  52. array(
  53. 'name' => esc_html__( 'Dark Gray', 'publication' ),
  54. 'slug' => 'dark-gray',
  55. 'color' => '#474f53',
  56. ),
  57. array(
  58. 'name' => esc_html__( 'Medium Gray', 'publication' ),
  59. 'slug' => 'medium-gray',
  60. 'color' => '#a5a29d',
  61. ),
  62. array(
  63. 'name' => esc_html__( 'Light Gray', 'publication' ),
  64. 'slug' => 'light-gray',
  65. 'color' => '#eeece8',
  66. ),
  67. array(
  68. 'name' => esc_html__( 'White', 'publication' ),
  69. 'slug' => 'white',
  70. 'color' => '#ffffff',
  71. ),
  72. array(
  73. 'name' => esc_html__( 'Orange', 'publication' ),
  74. 'slug' => 'orange',
  75. 'color' => '#ef7d0b',
  76. ),
  77. array(
  78. 'name' => esc_html__( 'Dark Orange', 'publication' ),
  79. 'slug' => 'dark-orange',
  80. 'color' => '#9c8012',
  81. ),
  82. )
  83. );
  84. /*
  85. * Enable support for Post Thumbnails on posts and pages.
  86. *
  87. * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
  88. */
  89. add_theme_support( 'post-thumbnails' );
  90. set_post_thumbnail_size( 144, 144, true );
  91. add_image_size( 'publication-hero', 2000, 1500, true );
  92. add_image_size( 'publication-navigation', 1055, 132, true );
  93. // This theme uses wp_nav_menu() in two locations.
  94. register_nav_menus( array(
  95. 'primary' => esc_html__( 'Primary Menu', 'publication' ),
  96. 'social' => esc_html__( 'Social Menu', 'publication' ),
  97. ) );
  98. /*
  99. * Switch default core markup for search form, comment form, and comments
  100. * to output valid HTML5.
  101. */
  102. add_theme_support( 'html5', array(
  103. 'search-form',
  104. 'comment-form',
  105. 'comment-list',
  106. 'gallery',
  107. 'caption',
  108. ) );
  109. // Set up the WordPress core custom background feature.
  110. add_theme_support( 'custom-background', apply_filters( 'publication_custom_background_args', array(
  111. 'default-color' => 'ffffff',
  112. 'default-image' => '',
  113. ) ) );
  114. }
  115. endif; // publication_setup
  116. add_action( 'after_setup_theme', 'publication_setup' );
  117. /**
  118. * Set the content width in pixels, based on the theme's design and stylesheet.
  119. *
  120. * Priority 0 to make it available to lower priority callbacks.
  121. *
  122. * @global int $content_width
  123. */
  124. function publication_content_width() {
  125. $GLOBALS['content_width'] = apply_filters( 'publication_content_width', 672 );
  126. }
  127. add_action( 'after_setup_theme', 'publication_content_width', 0 );
  128. /**
  129. * Register widget area.
  130. *
  131. * @link http://codex.wordpress.org/Function_Reference/register_sidebar
  132. */
  133. function publication_widgets_init() {
  134. register_sidebar( array(
  135. 'name' => esc_html__( 'Sidebar One', 'publication' ),
  136. 'id' => 'sidebar-1',
  137. 'description' => '',
  138. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  139. 'after_widget' => '</aside>',
  140. 'before_title' => '<h2 class="widget-title">',
  141. 'after_title' => '</h2>',
  142. ) );
  143. register_sidebar( array(
  144. 'name' => esc_html__( 'Sidebar Two', 'publication' ),
  145. 'id' => 'sidebar-2',
  146. 'description' => '',
  147. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  148. 'after_widget' => '</aside>',
  149. 'before_title' => '<h2 class="widget-title">',
  150. 'after_title' => '</h2>',
  151. ) );
  152. }
  153. add_action( 'widgets_init', 'publication_widgets_init' );
  154. /**
  155. * Register Lato and Neuton fonts.
  156. *
  157. * @return string
  158. */
  159. function publication_lato_neuton_fonts_url() {
  160. $fonts_url = '';
  161. /* translators: If there are characters in your language that are not supported
  162. * by Lato, translate this to 'off'. Do not translate into your own language.
  163. */
  164. $lato = _x( 'on', 'Lato font: on or off', 'publication' );
  165. /* translators: If there are characters in your language that are not supported
  166. * by Neuton, translate this to 'off'. Do not translate into your own language.
  167. */
  168. $neuton = _x( 'on', 'Neuton font: on or off', 'publication' );
  169. if ( 'off' !== $lato || 'off' !== $neuton ) {
  170. $font_families = array();
  171. if ( 'off' !== $lato ) {
  172. $font_families[] = 'Lato:400,700,400italic,700italic';
  173. }
  174. if ( 'off' !== $neuton ) {
  175. $font_families[] = 'Neuton:400,700,400italic,700italic';
  176. }
  177. $query_args = array(
  178. 'family' => urlencode( implode( '|', $font_families ) ),
  179. 'subset' => urlencode( 'latin,latin-ext' ), // add extra subset
  180. );
  181. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  182. }
  183. return $fonts_url;
  184. }
  185. /**
  186. * Register Oswald and Inconsolata fonts.
  187. *
  188. * @return string
  189. */
  190. function publication_oswald_inconsolata_fonts_url() {
  191. $fonts_url = '';
  192. /* translators: If there are characters in your language that are not supported
  193. * by Oswald, translate this to 'off'. Do not translate into your own language.
  194. */
  195. $oswald = _x( 'on', 'Oswald font: on or off', 'publication' );
  196. /* translators: If there are characters in your language that are not supported
  197. * by Inconsolata, translate this to 'off'. Do not translate into your own language.
  198. */
  199. $inconsolata = _x( 'on', 'Inconsolata font: on or off', 'publication' );
  200. if ( 'off' !== $oswald || 'off' !== $inconsolata ) {
  201. $font_families = array();
  202. if ( 'off' !== $oswald ) {
  203. $font_families[] = 'Oswald:300,400,700';
  204. }
  205. if ( 'off' !== $inconsolata ) {
  206. $font_families[] = 'Inconsolata:400,700';
  207. }
  208. $query_args = array(
  209. 'family' => urlencode( implode( '|', $font_families ) ),
  210. 'subset' => urlencode( 'latin,latin-ext' ), // add extra subset
  211. );
  212. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  213. }
  214. return $fonts_url;
  215. }
  216. /**
  217. * Enqueue scripts and styles.
  218. */
  219. function publication_scripts() {
  220. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/fonts/genericons/genericons.css', array(), '3.3.1' );
  221. wp_enqueue_style( 'publication-menucon', get_template_directory_uri() . '/fonts/menucon/menucon.css', array(), '20150609' );
  222. wp_enqueue_style( 'publication-lato-neuton', publication_lato_neuton_fonts_url() );
  223. wp_enqueue_style( 'publication-oswald-inconsolata', publication_oswald_inconsolata_fonts_url() );
  224. wp_enqueue_style( 'publication-style', get_stylesheet_uri() );
  225. // Gutenberg styles
  226. wp_enqueue_style( 'publication-blocks', get_template_directory_uri() . '/blocks.css' );
  227. wp_enqueue_script( 'publication-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20150715', true );
  228. wp_enqueue_script( 'publication-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ), '20150529', true );
  229. wp_enqueue_script( 'publication-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
  230. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  231. wp_enqueue_script( 'comment-reply' );
  232. }
  233. wp_localize_script( 'publication-script', 'screenReaderText', array(
  234. 'expand' => '<span class="screen-reader-text">' . __( 'expand child menu', 'publication' ) . '</span>',
  235. 'collapse' => '<span class="screen-reader-text">' . __( 'collapse child menu', 'publication' ) . '</span>',
  236. ) );
  237. }
  238. add_action( 'wp_enqueue_scripts', 'publication_scripts' );
  239. /**
  240. * Gutenberg Editor Styles
  241. */
  242. function publication_editor_styles() {
  243. wp_enqueue_style( 'publication-editor-block-style', get_template_directory_uri() . '/editor-blocks.css');
  244. wp_enqueue_style( 'publication-lato-neuton', publication_lato_neuton_fonts_url() );
  245. wp_enqueue_style( 'publication-oswald-inconsolata', publication_oswald_inconsolata_fonts_url() );
  246. }
  247. add_action( 'enqueue_block_editor_assets', 'publication_editor_styles' );
  248. /**
  249. * Custom template tags for this theme.
  250. */
  251. require get_template_directory() . '/inc/template-tags.php';
  252. /**
  253. * Custom functions that act independently of the theme templates.
  254. */
  255. require get_template_directory() . '/inc/extras.php';
  256. /**
  257. * Customizer additions.
  258. */
  259. require get_template_directory() . '/inc/customizer.php';
  260. /**
  261. * Load Jetpack compatibility file.
  262. */
  263. require get_template_directory() . '/inc/jetpack.php';