PageRenderTime 37ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/ravens-egg-2022/inc/theme-support.php

https://gitlab.com/ravenseyedesign/ravensegg
PHP | 367 lines | 87 code | 51 blank | 229 comment | 5 complexity | 5d6b16aa48f8fda0f67d8b509cd586bb MD5 | raw file
  1. <?php
  2. /**
  3. * Theme support
  4. *
  5. * @package WordPress
  6. * @subpackage Ravens_Egg_2022
  7. * @since 1.0
  8. * @version 1.0
  9. */
  10. namespace ravensegg2022;
  11. if ( ! function_exists( 'ravensegg_setup' ) ) {
  12. /**
  13. * Sets up theme defaults and registers support for various WordPress features.
  14. *
  15. * Note that this function is hooked into the after_setup_theme hook, which
  16. * runs before the init hook. The init hook is too late for some features, such
  17. * as indicating support for post thumbnails.
  18. *
  19. * @return void
  20. * @since Ravens_Egg_2022 1.0
  21. *
  22. */
  23. function ravensegg_setup() {
  24. /*
  25. * Make theme available for translation.
  26. * Translations can be filed in the /languages/ directory.
  27. */
  28. // load_theme_textdomain( 'ravens-egg-2022', 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. * This theme does not use a hard-coded <title> tag in the document head,
  34. * WordPress will provide it for us.
  35. */
  36. add_theme_support( 'title-tag' );
  37. /*
  38. * Enable support for Post Thumbnails on posts and pages.
  39. *
  40. * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
  41. */
  42. add_theme_support( 'post-thumbnails' );
  43. set_post_thumbnail_size( 1920, 1240 );
  44. register_nav_menus(
  45. array(
  46. 'primary' => esc_html__( 'The Main Menu', 'ravens-egg-2022' ), // main nav in header
  47. 'secondary' => __( 'Secondary menu', 'ravens-egg-2022' ),
  48. 'top' => __( 'Top menu', 'ravens-egg-2022' ),
  49. 'footer' => __( 'Footer menu', 'ravens-egg-2022' )
  50. )
  51. );
  52. /*
  53. * Switch default core markup for search form, comment form, and comments
  54. * to output valid HTML5.
  55. */
  56. add_theme_support(
  57. 'html5',
  58. array(
  59. 'comment-form',
  60. 'comment-list',
  61. 'gallery',
  62. 'caption',
  63. 'style',
  64. 'script',
  65. 'navigation-widgets',
  66. )
  67. );
  68. // Add support for responsive embedded content.
  69. add_theme_support( 'responsive-embeds' );
  70. // Add theme support for selective refresh for widgets.
  71. add_theme_support( 'customize-selective-refresh-widgets' );
  72. // Add support for full and wide align images.
  73. add_theme_support( 'align-wide' );
  74. // Add support for editor styles.
  75. add_theme_support( 'editor-styles' );
  76. // Add support for Block Styles. Displays default block styles from editor also on front end.
  77. // add_theme_support( 'wp-block-styles' );
  78. // Custom background color.
  79. // add_theme_support(
  80. // 'custom-background',
  81. // array(
  82. // 'default-color' => 'ffffff',
  83. // )
  84. // );
  85. /*
  86. * Add support for core custom logo.
  87. *
  88. * @link https://codex.wordpress.org/Theme_Logo
  89. */
  90. // $logo_width = 300;
  91. // $logo_height = 100;
  92. //
  93. // add_theme_support(
  94. // 'custom-logo',
  95. // array(
  96. // 'height' => $logo_height,
  97. // 'width' => $logo_width,
  98. // 'flex-width' => true,
  99. // 'flex-height' => true,
  100. // 'unlink-homepage-logo' => true,
  101. // )
  102. // );
  103. /**
  104. * Add post-formats support.
  105. */
  106. // add_theme_support(
  107. // 'post-formats',
  108. // array(
  109. // 'link',
  110. // 'aside',
  111. // 'gallery',
  112. // 'image',
  113. // 'quote',
  114. // 'status',
  115. // 'video',
  116. // 'audio',
  117. // 'chat',
  118. // )
  119. // );
  120. // Editor color palette.
  121. // $teal = '#00637a';
  122. // $aqua = '#77d1e6';
  123. // $warmGrayLight = '#ebe7e0';
  124. // $choco = '#615742';
  125. // $orange = '#f26a13';
  126. //
  127. // add_theme_support(
  128. // 'editor-color-palette',
  129. // array(
  130. // array(
  131. // 'name' => esc_html__( 'Teal', 'ravens-egg-2022' ),
  132. // 'slug' => 'teal',
  133. // 'color' => $teal,
  134. // ),
  135. // array(
  136. // 'name' => esc_html__( 'Aqua', 'ravens-egg-2022' ),
  137. // 'slug' => 'aqua',
  138. // 'color' => $aqua,
  139. // ),
  140. // array(
  141. // 'name' => esc_html__( 'Warm Gray Light', 'ravens-egg-2022' ),
  142. // 'slug' => 'warm-gray-light',
  143. // 'color' => $warmGrayLight,
  144. // ),
  145. // array(
  146. // 'name' => esc_html__( 'Choco', 'ravens-egg-2022' ),
  147. // 'slug' => 'choco',
  148. // 'color' => $choco,
  149. // ),
  150. // array(
  151. // 'name' => esc_html__( 'Orange', 'ravens-egg-2022' ),
  152. // 'slug' => 'orange',
  153. // 'color' => $orange,
  154. // ),
  155. // )
  156. // );
  157. // Disables custom colors
  158. // add_theme_support( 'disable-custom-colors' );
  159. // Disables custom gradients
  160. // add_theme_support( 'disable-custom-gradients' );
  161. // To completely disable gradients, leave preset array empty.
  162. // add_theme_support( 'editor-gradient-presets', array() );
  163. // Adds gradient preset(s).
  164. // add_theme_support( 'editor-gradient-presets', array(
  165. // array(
  166. // 'name' => esc_attr__( 'Gray Wash', 'ravens-egg-2022' ),
  167. // 'gradient' => 'linear-gradient(to right, rgba(128, 128, 128, 1), rgba(192, 192, 192, 1))',
  168. // 'slug' => 'gray-wash',
  169. // )
  170. // ) );
  171. // Add custom editor font sizes.
  172. // add_theme_support( 'editor-font-sizes',
  173. // array(
  174. // array(
  175. // 'name' => esc_html__( 'Small', 'ravens-egg-2022' ),
  176. // 'shortName' => esc_html_x( 'S', 'ravens-egg-2022' ),
  177. // 'size' => 14,
  178. // 'slug' => 'small'
  179. // ),
  180. // array(
  181. // 'name' => esc_html__( 'Normal', 'ravens-egg-2022' ),
  182. // 'shortName' => esc_html_x( 'N', 'ravens-egg-2022' ),
  183. // 'size' => 16,
  184. // 'slug' => 'normal'
  185. // ),
  186. // array(
  187. // 'name' => esc_html__( 'Large', 'ravens-egg-2022' ),
  188. // 'shortName' => esc_html_x( 'M', 'ravens-egg-2022' ),
  189. // 'size' => 20,
  190. // 'slug' => 'medium'
  191. // ),
  192. // array(
  193. // 'name' => esc_html__( 'Larger', 'ravens-egg-2022' ),
  194. // 'shortName' => esc_html_x( 'L', 'ravens-egg-2022' ),
  195. // 'size' => 23,
  196. // 'slug' => 'large'
  197. // ),
  198. // array(
  199. // 'name' => esc_html__( 'Huge', 'ravens-egg-2022' ),
  200. // 'shortName' => esc_html_x( 'XL', 'ravens-egg-2022' ),
  201. // 'size' => 26,
  202. // 'slug' => 'huge'
  203. // )
  204. // ) );
  205. // Disables custom font sizes
  206. // add_theme_support( 'disable-custom-font-sizes' );
  207. // Add support for custom line height controls.
  208. // add_theme_support( 'custom-line-height' );
  209. // Add support for experimental link color control.
  210. // add_theme_support( 'experimental-link-color' );
  211. // Add support for experimental cover block spacing.
  212. // add_theme_support( 'custom-spacing' );
  213. }
  214. }
  215. add_action( 'after_setup_theme', 'ravensegg2022\ravensegg_setup' );
  216. // Add editor styles with cache busting hash.
  217. function add_editor_styles() {
  218. add_editor_style( get_asset_path( 'editor.css' ) );
  219. }
  220. add_action( 'init', 'ravensegg2022\add_editor_styles' );
  221. /**
  222. * Sets active sidebars and widgetized areas.
  223. *
  224. * @return void
  225. */
  226. function register_sidebars() {
  227. $my_sidebars = array(
  228. array(
  229. 'name' => 'Sidebar 1',
  230. 'id' => 'sidebar1',
  231. 'description' => 'The first (primary) sidebar',
  232. ),
  233. array(
  234. 'name' => 'Sidebar 2',
  235. 'id' => 'sidebar2',
  236. 'description' => 'The second (secondary) sidebar',
  237. ),
  238. array(
  239. 'name' => 'Subfooter Widget',
  240. 'id' => 'subfooter',
  241. 'description' => 'Subfooter widget, non-sidebar',
  242. ),
  243. );
  244. $defaults = array(
  245. 'name' => 'Default Sidebar',
  246. 'id' => 'sidebar-default',
  247. 'description' => 'This is the default sidebar',
  248. 'class' => '',
  249. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  250. 'after_widget' => '</div>',
  251. 'before_title' => '<h3 class="widget-title">',
  252. 'after_title' => '</h3>'
  253. );
  254. foreach ( $my_sidebars as $sidebar ) {
  255. $args = wp_parse_args( $sidebar, $defaults );
  256. register_sidebar( $args );
  257. }
  258. }
  259. add_action( 'widgets_init', 'RavensEgg2022\register_sidebars' );
  260. /**
  261. * Disables core update notification emails unless update failed.
  262. *
  263. * @param $send
  264. * @param $type
  265. * @param $core_update
  266. * @param $result
  267. *
  268. * @return false
  269. */
  270. function auto_core_update_send_email( $send, $type, $core_update, $result ) {
  271. if ( ! empty( $type ) && $type == 'success' ) {
  272. // don't send email
  273. return false;
  274. }
  275. // use default settings
  276. return $send;
  277. }
  278. add_filter( 'auto_core_update_send_email', 'ravensegg2022\auto_core_update_send_email', 10, 4 );
  279. // Disables auto-update email notifications for plugins.
  280. add_filter( 'auto_plugin_update_send_email', '__return_false' );
  281. // Disables auto-update email notifications for themes.
  282. add_filter( 'auto_theme_update_send_email', '__return_false' );
  283. /**
  284. * Sets custom thumbnail sizes. Full size is limited by Imsanity plugin to 1920 x 1080.
  285. * Colorbox restrains lightboxed images to 90% of screen width and height
  286. */
  287. //add_image_size( 'xlarge', 1024, 768, false );
  288. // add_image_size( 'slideshow', 1200, 675, true );
  289. //add_image_size( 'ravensegg2022-thumb-300', 300, 100, true );
  290. /**
  291. * Disables full screen editor by default.
  292. */
  293. function disable_editor_fullscreen_by_default() {
  294. $script = "window.onload = function() { const isFullscreenMode = wp.data.select( 'core/edit-post' ).isFeatureActive( 'fullscreenMode' ); if ( isFullscreenMode ) { wp.data.dispatch( 'core/edit-post' ).toggleFeature( 'fullscreenMode' ); } }";
  295. wp_add_inline_script( 'wp-blocks', $script );
  296. }
  297. add_action( 'enqueue_block_editor_assets', 'ravensegg2022\disable_editor_fullscreen_by_default' );
  298. /**
  299. * Display unlimited post types per page and sort by random.
  300. *
  301. * @param $query
  302. */
  303. // function alter_posttype_query( $query ) {
  304. // /* only proceed on the front end */
  305. // if ( is_admin() ) {
  306. // return;
  307. // }
  308. // /* only on the posttype post archive for the main query */
  309. // if ( $query->is_post_type_archive( 'posttype' ) && $query->is_main_query() ) {
  310. // $query->set( 'posts_per_page', - 1 );
  311. // // $query->set( 'orderby', 'post_title' );
  312. // $query->set( 'order', 'ASC' );
  313. // $query->set( 'orderby', 'rand' );
  314. // }
  315. // }
  316. // add_action( 'pre_get_posts', 'ravensegg2022\alter_posttype_query' );