functions.php 11 KB

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