functions.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <?php declare( strict_types = 1 ); ?>
  2. <?php
  3. /**
  4. * Photos functions and definitions
  5. *
  6. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  7. *
  8. * @package photos
  9. */
  10. if ( ! function_exists( 'photos_setup' ) ) :
  11. /**
  12. * Sets up theme defaults and registers support for various WordPress features.
  13. *
  14. * Note that this function is hooked into the after_setup_theme hook, which
  15. * runs before the init hook. The init hook is too late for some features, such
  16. * as indicating support for post thumbnails.
  17. */
  18. function photos_setup() {
  19. /*
  20. * Make theme available for translation.
  21. * Translations can be filed in the /languages/ directory.
  22. * If you're building a theme based on Photos, use a find and replace
  23. * to change 'photos' to the name of your theme in all the template files.
  24. */
  25. load_theme_textdomain( 'photos', get_template_directory() . '/languages' );
  26. // Add default posts and comments RSS feed links to head.
  27. add_theme_support( 'automatic-feed-links' );
  28. /*
  29. * Let WordPress manage the document title.
  30. * By adding theme support, we declare that this theme does not use a
  31. * hard-coded <title> tag in the document head, and expect WordPress to
  32. * provide it for us.
  33. */
  34. add_theme_support( 'title-tag' );
  35. /*
  36. * Enable support for Post Thumbnails on posts and pages.
  37. *
  38. * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
  39. */
  40. add_theme_support( 'post-thumbnails' );
  41. set_post_thumbnail_size( 320, 320, true );
  42. // Home page thumbnails
  43. // Double-sized for retina
  44. add_image_size( 'photos-grid-thumb', 640, 640, true );
  45. add_image_size( 'photos-featured', 2040, 9999, false );
  46. // This theme uses wp_nav_menu() in one location.
  47. register_nav_menu( 'menu-1', esc_html__( 'Primary', 'photos' ) );
  48. /*
  49. * Switch default core markup for search form, comment form, and comments
  50. * to output valid HTML5.
  51. */
  52. add_theme_support(
  53. 'html5',
  54. array(
  55. 'search-form',
  56. 'comment-form',
  57. 'comment-list',
  58. 'gallery',
  59. 'caption',
  60. )
  61. );
  62. // Set up the WordPress core custom background feature.
  63. add_theme_support(
  64. 'custom-background',
  65. apply_filters(
  66. 'photos_custom_background_args',
  67. array(
  68. 'default-color' => 'ffffff',
  69. 'default-image' => '',
  70. )
  71. )
  72. );
  73. // Add theme support for selective refresh for widgets.
  74. add_theme_support( 'customize-selective-refresh-widgets' );
  75. /**
  76. * Add support for core custom logo.
  77. *
  78. * @link https://codex.wordpress.org/Theme_Logo
  79. */
  80. add_theme_support(
  81. 'custom-logo',
  82. array(
  83. 'height' => 360,
  84. 'width' => 720,
  85. 'flex-width' => true,
  86. 'flex-height' => true,
  87. 'header-text' => array(
  88. 'site-title',
  89. 'site-description',
  90. ),
  91. )
  92. );
  93. /* Gutenberg! */
  94. add_theme_support( 'align-wide' );
  95. // Add support for responsive embeds.
  96. add_theme_support( 'responsive-embeds' );
  97. add_theme_support(
  98. 'editor-color-palette',
  99. array(
  100. array(
  101. 'name' => esc_html__( 'red', 'photos' ),
  102. 'slug' => 'red',
  103. 'color' => '#d63031',
  104. ),
  105. array(
  106. 'name' => esc_html__( 'charcoal', 'photos' ),
  107. 'slug' => 'charcoal',
  108. 'color' => '#111',
  109. ),
  110. array(
  111. 'name' => esc_html__( 'very light gray', 'photos' ),
  112. 'slug' => 'very-light-gray',
  113. 'color' => '#f0f0f0',
  114. ),
  115. array(
  116. 'name' => esc_html__( 'very dark gray', 'photos' ),
  117. 'slug' => 'very-dark-gray',
  118. 'color' => '#404040',
  119. ),
  120. array(
  121. 'name' => esc_html__( 'medium gray', 'photos' ),
  122. 'slug' => 'medium-gray',
  123. 'color' => '#606060',
  124. ),
  125. )
  126. );
  127. }
  128. endif;
  129. add_action( 'after_setup_theme', 'photos_setup' );
  130. /**
  131. * Set posts per page on theme switch
  132. */
  133. function photos_setup_options() {
  134. // Set the number of posts to display per page
  135. update_option( 'posts_per_page', 12 );
  136. }
  137. add_action( 'after_switch_theme', 'photos_setup_options' );
  138. /**
  139. * Set the content width in pixels, based on the theme's design and stylesheet.
  140. *
  141. * Priority 0 to make it available to lower priority callbacks.
  142. *
  143. * @global int $content_width
  144. */
  145. function photos_content_width() {
  146. // This variable is intended to be overruled from themes.
  147. // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
  148. // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
  149. $GLOBALS['content_width'] = apply_filters( 'photos_content_width', 640 );
  150. }
  151. add_action( 'after_setup_theme', 'photos_content_width', 0 );
  152. /**
  153. * Register widget area.
  154. *
  155. * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  156. */
  157. function photos_widgets_init() {
  158. register_sidebar(
  159. array(
  160. 'name' => esc_html__( 'Footer', 'photos' ),
  161. 'id' => 'sidebar-1',
  162. 'description' => esc_html__( 'These widgets will be displayed at the bottom of each page.', 'photos' ),
  163. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  164. 'after_widget' => '</section>',
  165. 'before_title' => '<h2 class="widget-title">',
  166. 'after_title' => '</h2>',
  167. )
  168. );
  169. }
  170. add_action( 'widgets_init', 'photos_widgets_init' );
  171. /**
  172. * Enqueue scripts and styles.
  173. */
  174. function photos_scripts() {
  175. // Main stylesheet
  176. wp_enqueue_style( 'photos-style', get_stylesheet_uri() );
  177. // Gutenberg styles
  178. wp_enqueue_style( 'photos-blocks', get_template_directory_uri() . '/blocks.css' );
  179. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  180. wp_enqueue_script( 'comment-reply' );
  181. }
  182. wp_enqueue_script( 'photos-global', get_theme_file_uri( '/js/global.js' ), array( 'jquery' ), '20180724', true );
  183. wp_enqueue_script( 'photos-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
  184. $photos_l10n = array();
  185. wp_enqueue_script( 'photos-navigation', get_theme_file_uri( '/js/navigation.js' ), array( 'jquery' ), '1.0', true );
  186. $photos_l10n['expand'] = esc_attr__( 'Expand child menu', 'photos' );
  187. $photos_l10n['collapse'] = esc_attr__( 'Collapse child menu', 'photos' );
  188. $photos_l10n['icon'] = photos_get_svg(
  189. array(
  190. 'icon' => 'expand',
  191. 'fallback' => true,
  192. )
  193. );
  194. wp_localize_script( 'photos-navigation', 'photosScreenReaderText', $photos_l10n );
  195. }
  196. add_action( 'wp_enqueue_scripts', 'photos_scripts' );
  197. /**
  198. * Gutenberg Editor Styles
  199. */
  200. function photos_editor_styles() {
  201. wp_enqueue_style( 'photos-editor-block-style', get_template_directory_uri() . '/editor-blocks.css' );
  202. }
  203. add_action( 'enqueue_block_editor_assets', 'photos_editor_styles' );
  204. /**
  205. * Custom template tags for this theme.
  206. */
  207. require get_template_directory() . '/inc/template-tags.php';
  208. /**
  209. * Functions which enhance the theme by hooking into WordPress.
  210. */
  211. require get_template_directory() . '/inc/template-functions.php';
  212. /**
  213. * Customizer additions.
  214. */
  215. require get_template_directory() . '/inc/customizer.php';
  216. /**
  217. * Logo Resizer: Bringing logo resizing to the Customizer.
  218. */
  219. require get_template_directory() . '/inc/logo-resizer.php';
  220. /**
  221. * Load Jetpack compatibility file.
  222. */
  223. require get_template_directory() . '/inc/jetpack.php';
  224. /**
  225. * Load Custom Header funtionality.
  226. */
  227. require get_template_directory() . '/inc/custom-header.php';
  228. /**
  229. * SVG icons functions and filters.
  230. */
  231. require get_template_directory() . '/inc/icon-functions.php';