functions.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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-global-header-menu' => __('UIU Global Header Menu'),
  151. 'uiu-departmental-header-menu' => __('UIU Departmental Header Menu'),
  152. 'uiu-global-footer-menu' => __('UIU Global 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. // function fetch_conference_data($params)
  220. // {
  221. // $auth_token = get_field('auth_token', 'option');
  222. // $client_id = get_field('client_id', 'option');
  223. // $conference_api = get_field('conference_api', 'option');
  224. // $curl = curl_init();
  225. // curl_setopt_array($curl, array(
  226. // CURLOPT_URL => $conference_api,
  227. // CURLOPT_RETURNTRANSFER => true,
  228. // CURLOPT_ENCODING => '',
  229. // CURLOPT_MAXREDIRS => 10,
  230. // CURLOPT_TIMEOUT => 0,
  231. // CURLOPT_FOLLOWLOCATION => true,
  232. // CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  233. // CURLOPT_CUSTOMREQUEST => 'POST',
  234. // CURLOPT_POSTFIELDS => '{
  235. // "auth_token" : "' . $auth_token . '",
  236. // "user_login_id" : "' . $client_id . '",
  237. // "employee_id" : ' . isset($params["author"]) ? " " : " " . ',
  238. // "fromYear" : ' . $params["fromYear"] ?? " " . ',
  239. // "toYear" : ' . $params["toYear"] . ',
  240. // "page" : ' . $params["page"] . ',
  241. // "limit" : ' . $params["limit"] . '
  242. // }',
  243. // CURLOPT_HTTPHEADER => array(
  244. // 'Content-Type: application/json'
  245. // ),
  246. // ));
  247. // $response = curl_exec($curl);
  248. // curl_close($curl);
  249. // $response = json_decode($response, true);
  250. // return $response;
  251. // }
  252. // function uiu_conference_route_menu_with_params(WP_REST_Request $request)
  253. // {
  254. // // $arg = $request->get_param('limit');
  255. // $params = $request->get_params();
  256. // // var_dump($params);
  257. // return fetch_conference_data($params);
  258. // }
  259. // add_action("rest_api_init", function () {
  260. // register_rest_route("uiu_api", "/conference", [
  261. // "methods" => "GET",
  262. // "callback" => "uiu_conference_route_menu_with_params",
  263. // ]);
  264. // });
  265. /**
  266. * Make theme option page field value available via REST API
  267. */
  268. function theme_options_route_menu_global_header()
  269. {
  270. return get_field('global_menu_rich_contents', 'option');
  271. }
  272. add_action("rest_api_init", function () {
  273. register_rest_route("options/menu", "/global-header", [
  274. "methods" => "GET",
  275. "callback" => "theme_options_route_menu_global_header",
  276. ]);
  277. });
  278. function theme_options_route_menu_departmental_header()
  279. {
  280. return get_field('departmental_menu_rich_contents', 'option');
  281. }
  282. add_action("rest_api_init", function () {
  283. register_rest_route("options/menu", "/departmental-header", [
  284. "methods" => "GET",
  285. "callback" => "theme_options_route_menu_departmental_header",
  286. ]);
  287. });
  288. add_action('rest_api_init', function () {
  289. header("Access-Control-Allow-Origin: *");
  290. });
  291. /**
  292. * Custom Walker class to add extra element to sub-menu ul.
  293. */
  294. class Custom_Walker_Nav_Menu extends Walker_Nav_Menu
  295. {
  296. public function start_lvl(&$output, $depth = 0, $args = array())
  297. {
  298. // Add your extra element here.
  299. parent::start_lvl($output, $depth, $args);
  300. $output .= '<div class="container"><div class="sub-menu-feature">
  301. <img class="menu_feature_image" src="../wp-content/themes/uiu-cse/img/menu-background.jpg" alt="">
  302. <div class="heading-text menu_title">
  303. Research
  304. </div>
  305. <div class="text menu_description">
  306. We collect personal information from you so we can provide investment services to you.
  307. </div>
  308. </div><div class="sub-menu-link-container">';
  309. }
  310. public function end_lvl(&$output, $depth = 0, $args = array())
  311. {
  312. // Add your extra element here.
  313. $output .= '</div></div>';
  314. parent::end_lvl($output, $depth, $args);
  315. }
  316. }
  317. function custom_menu_walker($args)
  318. {
  319. return array_merge($args, array(
  320. 'walker' => new Custom_Walker_Nav_Menu(),
  321. ));
  322. }
  323. add_filter('wp_nav_menu_args', 'custom_menu_walker');
  324. /**
  325. * Insert_extra_element_to_submenu
  326. */
  327. // function insert_extra_element_to_submenu($matches)
  328. // {
  329. // $sub_menu_ul = $matches[0];
  330. // $extra_element = '<div class="extra-item col-breaker">
  331. // <img class="menu_feature_image" src="../wp-content/themes/uiu-cse/img/menu-background.jpg" alt="">
  332. // <div class="heading-text menu_title">
  333. // Research
  334. // </div>
  335. // <div class="text menu_description">
  336. // We collect personal information from you so we can provide investment services to you.
  337. // </div>
  338. // </div>';
  339. // $sub_menu_ul .= $extra_element;
  340. // return $sub_menu_ul;
  341. // }
  342. // function custom_add_extra_element_to_submenu($nav_menu, $args)
  343. // {
  344. // // Find all sub-menu ul elements and add the extra element after each one.
  345. // $nav_menu = preg_replace_callback('/(<ul\s*class="sub-menu[^"]*">)/', 'insert_extra_element_to_submenu', $nav_menu);
  346. // return $nav_menu;
  347. // }
  348. // add_filter('wp_nav_menu', 'custom_add_extra_element_to_submenu', 10, 2);