functions.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <?php
  2. /**
  3. * UIU CSE functions and definitions
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package UIU_CSE
  8. */
  9. if (!defined('_S_VERSION')) {
  10. // Replace the version number of the theme on each release.
  11. define('_S_VERSION', '1.0.0');
  12. }
  13. /**
  14. * Sets up theme defaults and registers support for various WordPress features.
  15. *
  16. * Note that this function is hooked into the after_setup_theme hook, which
  17. * runs before the init hook. The init hook is too late for some features, such
  18. * as indicating support for post thumbnails.
  19. */
  20. function uiu_cse_setup()
  21. {
  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 UIU CSE, use a find and replace
  26. * to change 'uiu-cse' to the name of your theme in all the template files.
  27. */
  28. load_theme_textdomain('uiu-cse', 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. /*
  39. * Enable support for Post Thumbnails on posts and pages.
  40. *
  41. * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
  42. */
  43. add_theme_support('post-thumbnails');
  44. // This theme uses wp_nav_menu() in one location.
  45. register_nav_menus(
  46. array(
  47. 'menu-1' => esc_html__('Primary', 'uiu-cse'),
  48. )
  49. );
  50. /*
  51. * Switch default core markup for search form, comment form, and comments
  52. * to output valid HTML5.
  53. */
  54. add_theme_support(
  55. 'html5',
  56. array(
  57. 'search-form',
  58. 'comment-form',
  59. 'comment-list',
  60. 'gallery',
  61. 'caption',
  62. 'style',
  63. 'script',
  64. )
  65. );
  66. // Set up the WordPress core custom background feature.
  67. add_theme_support(
  68. 'custom-background',
  69. apply_filters(
  70. 'uiu_cse_custom_background_args',
  71. array(
  72. 'default-color' => 'ffffff',
  73. 'default-image' => '',
  74. )
  75. )
  76. );
  77. // Add theme support for selective refresh for widgets.
  78. add_theme_support('customize-selective-refresh-widgets');
  79. /**
  80. * Add support for core custom logo.
  81. *
  82. * @link https://codex.wordpress.org/Theme_Logo
  83. */
  84. add_theme_support(
  85. 'custom-logo',
  86. array(
  87. 'height' => 250,
  88. 'width' => 250,
  89. 'flex-width' => true,
  90. 'flex-height' => true,
  91. )
  92. );
  93. }
  94. add_action('after_setup_theme', 'uiu_cse_setup');
  95. /**
  96. * Set the content width in pixels, based on the theme's design and stylesheet.
  97. *
  98. * Priority 0 to make it available to lower priority callbacks.
  99. *
  100. * @global int $content_width
  101. */
  102. function uiu_cse_content_width()
  103. {
  104. $GLOBALS['content_width'] = apply_filters('uiu_cse_content_width', 640);
  105. }
  106. add_action('after_setup_theme', 'uiu_cse_content_width', 0);
  107. /**
  108. * Register widget area.
  109. *
  110. * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  111. */
  112. function uiu_cse_widgets_init()
  113. {
  114. register_sidebar(
  115. array(
  116. 'name' => esc_html__('Sidebar', 'uiu-cse'),
  117. 'id' => 'sidebar-1',
  118. 'description' => esc_html__('Add widgets here.', 'uiu-cse'),
  119. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  120. 'after_widget' => '</section>',
  121. 'before_title' => '<h2 class="widget-title">',
  122. 'after_title' => '</h2>',
  123. )
  124. );
  125. }
  126. add_action('widgets_init', 'uiu_cse_widgets_init');
  127. /**
  128. * Enqueue scripts and styles.
  129. */
  130. function uiu_cse_scripts()
  131. {
  132. wp_enqueue_style('uiu-cse-style', get_stylesheet_uri(), array(), _S_VERSION);
  133. wp_style_add_data('uiu-cse-style', 'rtl', 'replace');
  134. wp_enqueue_style('uiu-cse-pickr', 'https://cdn.jsdelivr.net/npm/@simonwep/pickr/dist/themes/nano.min.css');
  135. wp_enqueue_style('uiu-cse-google-fonts-material-icon', 'https://fonts.googleapis.com/icon?family=Material+Icons');
  136. wp_enqueue_style('uiu-cse-google-fonts-material-symbols-outlined', 'https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,0,0');
  137. wp_enqueue_style('uiu-cse-google-fonts-material+symbols+sharpt', 'https://fonts.googleapis.com/css2?family=Material+Symbols+Sharp:opsz,wght,FILL,GRAD@48,400,0,0');
  138. wp_enqueue_script('uiu-cse-pickr-js', 'https://cdn.jsdelivr.net/npm/@simonwep/pickr/dist/pickr.min.js', array(), '');
  139. wp_enqueue_script('uiu-cse-settings-js', get_template_directory_uri() . '/js/theme-settings.js', array(), _S_VERSION, true);
  140. wp_enqueue_script('uiu-cse-navigation', get_template_directory_uri() . '/js/navigation.js', array(), _S_VERSION, true);
  141. if (is_singular() && comments_open() && get_option('thread_comments')) {
  142. wp_enqueue_script('comment-reply');
  143. }
  144. }
  145. add_action('wp_enqueue_scripts', 'uiu_cse_scripts');
  146. function uiu_cse_header_menu()
  147. {
  148. register_nav_menus(
  149. array(
  150. 'uiu-header-menu' => __('UIU Header'),
  151. 'cse-header-menu' => __('CSE Header Menu'),
  152. 'uiu-footer-menu' => __('UIU Footer Menu')
  153. )
  154. );
  155. }
  156. add_action('init', 'uiu_cse_header_menu');
  157. /**
  158. * Implement the Custom Header feature.
  159. */
  160. require get_template_directory() . '/inc/custom-header.php';
  161. /**
  162. * Custom template tags for this theme.
  163. */
  164. require get_template_directory() . '/inc/template-tags.php';
  165. /**
  166. * Functions which enhance the theme by hooking into WordPress.
  167. */
  168. require get_template_directory() . '/inc/template-functions.php';
  169. /**
  170. * Customizer additions.
  171. */
  172. require get_template_directory() . '/inc/customizer.php';
  173. /**
  174. * Load Jetpack compatibility file.
  175. */
  176. if (defined('JETPACK__VERSION')) {
  177. require get_template_directory() . '/inc/jetpack.php';
  178. }
  179. /**
  180. * Theme option and custom fields settings
  181. */
  182. // Custom Blocks
  183. include_once(get_stylesheet_directory() . '/inc/custom-blocks.php');
  184. // ACF
  185. include_once(get_template_directory() . '/inc/acf/acf.php');
  186. // ACF Settings
  187. include_once(get_template_directory() . '/inc/acf-settings.php');
  188. // Custom post type
  189. include_once(get_stylesheet_directory() . '/inc/custom-post-type.php');
  190. // Typeahead Settings
  191. // include_once( get_stylesheet_directory() . '/inc/wp-typeahead.php');
  192. // Widgets
  193. // include_once( get_stylesheet_directory() . '/inc/widgets.php' );
  194. // Menus
  195. // include_once( get_stylesheet_directory() . '/inc/menus.php' );
  196. // Theme Settings
  197. include_once(get_stylesheet_directory() . '/inc/theme-settings.php');
  198. // Shortcodes
  199. include_once(get_stylesheet_directory() . '/inc/shortcodes.php');
  200. // Fetch vimeo thumbnail on save - takes video ID as input
  201. function uiu_acf_update_user_id($value, $post_id, $field)
  202. {
  203. // only set a new value if the field is empty
  204. // if ($value == '') {
  205. // get video here
  206. $login_id = get_field('login_id');
  207. // fetch thumb url(s)
  208. $user_meta = file_get_contents("https://api.github.com/users/rousnay");
  209. $user_meta = json_decode($user_meta);
  210. $user_id = $user_meta[0]->id;
  211. // set value
  212. $value = "Rousnay";
  213. return $value;
  214. // } else {
  215. // return $value;
  216. // }
  217. }
  218. add_filter('acf/update_value/name=employeeid', 'uiu_acf_update_user_id', 10, 3);
  219. /**
  220. * Custom Walker class to add extra element to sub-menu ul.
  221. */
  222. class Custom_Walker_Nav_Menu extends Walker_Nav_Menu
  223. {
  224. public function start_lvl(&$output, $depth = 0, $args = array())
  225. {
  226. // Add your extra element here.
  227. $output .= '<div class="container">';
  228. parent::start_lvl($output, $depth, $args);
  229. }
  230. public function end_lvl(&$output, $depth = 0, $args = array())
  231. {
  232. parent::end_lvl($output, $depth, $args);
  233. // Add your extra element here.
  234. $output .= '</div>';
  235. }
  236. }
  237. function custom_menu_walker($args)
  238. {
  239. return array_merge($args, array(
  240. 'walker' => new Custom_Walker_Nav_Menu(),
  241. ));
  242. }
  243. add_filter('wp_nav_menu_args', 'custom_menu_walker');
  244. /**
  245. * Insert_extra_element_to_submenu
  246. */
  247. function insert_extra_element_to_submenu($matches)
  248. {
  249. $sub_menu_ul = $matches[0];
  250. $extra_element = '<div class="extra-item col-breaker">
  251. <img src="../wp-content/themes/uiu-cse/img/menu-background.jpg" alt="">
  252. <div class="heading-text">
  253. Research
  254. </div>
  255. <div class="text">
  256. We collect personal information from you so we can provide investment services to you.
  257. </div>
  258. </div>';
  259. $sub_menu_ul .= $extra_element;
  260. return $sub_menu_ul;
  261. }
  262. function custom_add_extra_element_to_submenu($nav_menu, $args)
  263. {
  264. // Find all sub-menu ul elements and add the extra element after each one.
  265. $nav_menu = preg_replace_callback('/(<ul\s*class="sub-menu[^"]*">)/', 'insert_extra_element_to_submenu', $nav_menu);
  266. return $nav_menu;
  267. }
  268. add_filter('wp_nav_menu', 'custom_add_extra_element_to_submenu', 10, 2);
  269. /**
  270. * Make theme option page field value available via REST API
  271. */
  272. function theme_options_route_menu()
  273. {
  274. return get_field('menu_rich_content', 'option');
  275. }
  276. add_action("rest_api_init", function () {
  277. register_rest_route("options", "/menu", [
  278. "methods" => "GET",
  279. "callback" => "theme_options_route_menu",
  280. ]);
  281. });
  282. add_action('rest_api_init', function () {
  283. header("Access-Control-Allow-Origin: *");
  284. });