functions.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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',
  47. array(
  48. array(
  49. 'name' => esc_html__( 'Black', 'publication' ),
  50. 'slug' => 'black',
  51. 'color' => '#222',
  52. ),
  53. array(
  54. 'name' => esc_html__( 'Dark Gray', 'publication' ),
  55. 'slug' => 'dark-gray',
  56. 'color' => '#474f53',
  57. ),
  58. array(
  59. 'name' => esc_html__( 'Medium Gray', 'publication' ),
  60. 'slug' => 'medium-gray',
  61. 'color' => '#a5a29d',
  62. ),
  63. array(
  64. 'name' => esc_html__( 'Light Gray', 'publication' ),
  65. 'slug' => 'light-gray',
  66. 'color' => '#eeece8',
  67. ),
  68. array(
  69. 'name' => esc_html__( 'White', 'publication' ),
  70. 'slug' => 'white',
  71. 'color' => '#ffffff',
  72. ),
  73. array(
  74. 'name' => esc_html__( 'Orange', 'publication' ),
  75. 'slug' => 'orange',
  76. 'color' => '#ef7d0b',
  77. ),
  78. array(
  79. 'name' => esc_html__( 'Dark Orange', 'publication' ),
  80. 'slug' => 'dark-orange',
  81. 'color' => '#9c8012',
  82. ),
  83. )
  84. );
  85. /*
  86. * Enable support for Post Thumbnails on posts and pages.
  87. *
  88. * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
  89. */
  90. add_theme_support( 'post-thumbnails' );
  91. set_post_thumbnail_size( 144, 144, true );
  92. add_image_size( 'publication-hero', 2000, 1500, true );
  93. add_image_size( 'publication-navigation', 1055, 132, true );
  94. // This theme uses wp_nav_menu() in two locations.
  95. register_nav_menus(
  96. array(
  97. 'primary' => esc_html__( 'Primary Menu', 'publication' ),
  98. 'social' => esc_html__( 'Social Menu', 'publication' ),
  99. )
  100. );
  101. /*
  102. * Switch default core markup for search form, comment form, and comments
  103. * to output valid HTML5.
  104. */
  105. add_theme_support(
  106. 'html5',
  107. array(
  108. 'search-form',
  109. 'comment-form',
  110. 'comment-list',
  111. 'gallery',
  112. 'caption',
  113. )
  114. );
  115. // Set up the WordPress core custom background feature.
  116. add_theme_support(
  117. 'custom-background',
  118. apply_filters(
  119. 'publication_custom_background_args',
  120. array(
  121. 'default-color' => 'ffffff',
  122. 'default-image' => '',
  123. )
  124. )
  125. );
  126. }
  127. endif; // publication_setup
  128. add_action( 'after_setup_theme', 'publication_setup' );
  129. /**
  130. * Set the content width in pixels, based on the theme's design and stylesheet.
  131. *
  132. * Priority 0 to make it available to lower priority callbacks.
  133. *
  134. * @global int $content_width
  135. */
  136. function publication_content_width() {
  137. $GLOBALS['content_width'] = apply_filters( 'publication_content_width', 672 );
  138. }
  139. add_action( 'after_setup_theme', 'publication_content_width', 0 );
  140. /**
  141. * Register widget area.
  142. *
  143. * @link http://codex.wordpress.org/Function_Reference/register_sidebar
  144. */
  145. function publication_widgets_init() {
  146. register_sidebar(
  147. array(
  148. 'name' => esc_html__( 'Sidebar One', 'publication' ),
  149. 'id' => 'sidebar-1',
  150. 'description' => '',
  151. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  152. 'after_widget' => '</aside>',
  153. 'before_title' => '<h2 class="widget-title">',
  154. 'after_title' => '</h2>',
  155. )
  156. );
  157. register_sidebar(
  158. array(
  159. 'name' => esc_html__( 'Sidebar Two', 'publication' ),
  160. 'id' => 'sidebar-2',
  161. 'description' => '',
  162. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  163. 'after_widget' => '</aside>',
  164. 'before_title' => '<h2 class="widget-title">',
  165. 'after_title' => '</h2>',
  166. )
  167. );
  168. }
  169. add_action( 'widgets_init', 'publication_widgets_init' );
  170. /**
  171. * Register Lato and Neuton fonts.
  172. *
  173. * @return string
  174. */
  175. function publication_lato_neuton_fonts_url() {
  176. $fonts_url = '';
  177. /* translators: If there are characters in your language that are not supported
  178. * by Lato, translate this to 'off'. Do not translate into your own language.
  179. */
  180. $lato = _x( 'on', 'Lato font: on or off', 'publication' );
  181. /* translators: If there are characters in your language that are not supported
  182. * by Neuton, translate this to 'off'. Do not translate into your own language.
  183. */
  184. $neuton = _x( 'on', 'Neuton font: on or off', 'publication' );
  185. if ( 'off' !== $lato || 'off' !== $neuton ) {
  186. $font_families = array();
  187. if ( 'off' !== $lato ) {
  188. $font_families[] = 'Lato:400,700,400italic,700italic';
  189. }
  190. if ( 'off' !== $neuton ) {
  191. $font_families[] = 'Neuton:400,700,400italic,700italic';
  192. }
  193. $query_args = array(
  194. 'family' => urlencode( implode( '|', $font_families ) ),
  195. 'subset' => urlencode( 'latin,latin-ext' ), // add extra subset
  196. );
  197. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  198. }
  199. return $fonts_url;
  200. }
  201. /**
  202. * Register Oswald and Inconsolata fonts.
  203. *
  204. * @return string
  205. */
  206. function publication_oswald_inconsolata_fonts_url() {
  207. $fonts_url = '';
  208. /* translators: If there are characters in your language that are not supported
  209. * by Oswald, translate this to 'off'. Do not translate into your own language.
  210. */
  211. $oswald = _x( 'on', 'Oswald font: on or off', 'publication' );
  212. /* translators: If there are characters in your language that are not supported
  213. * by Inconsolata, translate this to 'off'. Do not translate into your own language.
  214. */
  215. $inconsolata = _x( 'on', 'Inconsolata font: on or off', 'publication' );
  216. if ( 'off' !== $oswald || 'off' !== $inconsolata ) {
  217. $font_families = array();
  218. if ( 'off' !== $oswald ) {
  219. $font_families[] = 'Oswald:300,400,700';
  220. }
  221. if ( 'off' !== $inconsolata ) {
  222. $font_families[] = 'Inconsolata:400,700';
  223. }
  224. $query_args = array(
  225. 'family' => urlencode( implode( '|', $font_families ) ),
  226. 'subset' => urlencode( 'latin,latin-ext' ), // add extra subset
  227. );
  228. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  229. }
  230. return $fonts_url;
  231. }
  232. /**
  233. * Enqueue scripts and styles.
  234. */
  235. function publication_scripts() {
  236. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/fonts/genericons/genericons.css', array(), '3.3.1' );
  237. wp_enqueue_style( 'publication-menucon', get_template_directory_uri() . '/fonts/menucon/menucon.css', array(), '20150609' );
  238. wp_enqueue_style( 'publication-lato-neuton', publication_lato_neuton_fonts_url() );
  239. wp_enqueue_style( 'publication-oswald-inconsolata', publication_oswald_inconsolata_fonts_url() );
  240. wp_enqueue_style( 'publication-style', get_stylesheet_uri() );
  241. // Gutenberg styles
  242. wp_enqueue_style( 'publication-blocks', get_template_directory_uri() . '/blocks.css' );
  243. wp_enqueue_script( 'publication-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20150715', true );
  244. wp_enqueue_script( 'publication-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ), '20150529', true );
  245. wp_enqueue_script( 'publication-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
  246. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  247. wp_enqueue_script( 'comment-reply' );
  248. }
  249. wp_localize_script(
  250. 'publication-script',
  251. 'screenReaderText',
  252. array(
  253. 'expand' => '<span class="screen-reader-text">' . __( 'expand child menu', 'publication' ) . '</span>',
  254. 'collapse' => '<span class="screen-reader-text">' . __( 'collapse child menu', 'publication' ) . '</span>',
  255. )
  256. );
  257. }
  258. add_action( 'wp_enqueue_scripts', 'publication_scripts' );
  259. /**
  260. * Gutenberg Editor Styles
  261. */
  262. function publication_editor_styles() {
  263. wp_enqueue_style( 'publication-editor-block-style', get_template_directory_uri() . '/editor-blocks.css' );
  264. wp_enqueue_style( 'publication-lato-neuton', publication_lato_neuton_fonts_url() );
  265. wp_enqueue_style( 'publication-oswald-inconsolata', publication_oswald_inconsolata_fonts_url() );
  266. }
  267. add_action( 'enqueue_block_editor_assets', 'publication_editor_styles' );
  268. /**
  269. * Custom template tags for this theme.
  270. */
  271. require get_template_directory() . '/inc/template-tags.php';
  272. /**
  273. * Custom functions that act independently of the theme templates.
  274. */
  275. require get_template_directory() . '/inc/extras.php';
  276. /**
  277. * Customizer additions.
  278. */
  279. require get_template_directory() . '/inc/customizer.php';
  280. /**
  281. * Load Jetpack compatibility file.
  282. */
  283. require get_template_directory() . '/inc/jetpack.php';