add_action('after_setup_theme', 'bas_setup');
if (!function_exists('bas_setup')) {
// Define the setup function
function bas_setup() {
// Load the theme text domain for translation
load_theme_textdomain('bas', get_template_directory() . '/languages');
// Add default posts and comments RSS feed links to head.
add_theme_support('automatic-feed-links');
// Add support for title tag
add_theme_support('title-tag');
// Enable support for featured images (post thumbnails)
add_theme_support('post-thumbnails');
// Register navigation menus
register_nav_menus(array(
'menu-1' => esc_html__('Primary', 'bas'),
'footer-menu' => esc_html__('Footer', 'bas')
));
// Switch default core markup for search form, comment form, and comments to output valid HTML5.
add_theme_support('html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
));
// Set up the WordPress core custom background feature.
add_theme_support('custom-background', array(
'default-color' => 'ffffff',
'default-image' => '',
));
// Add theme support for selective refresh for widgets.
add_theme_support('customize-selective-refresh-widgets');
// Add theme support for custom logos
add_theme_support('custom-logo', array(
'height' => 250,
'width' => 250,
'flex-width' => true,
'flex-height' => true,
));
// Add custom image size
add_image_size('featured-large', 1400, 780, false);
}
// Hook into the after_setup_theme action to run bas_setup function
add_action('after_setup_theme', 'bas_setup');
}
add_action('after_setup_theme', 'bas_content_width', 0);
function bas_content_width() {
$GLOBALS['content_width'] = apply_filters('bas_content_width', 640);
}
/**
* Register widget area.
*/
add_action('widgets_init', 'bas_widgets_init');
function bas_widgets_init() {
register_sidebar(array(
'name' => esc_html__('Sidebar', 'bas'),
'id' => 'sidebar-1',
'description' => esc_html__('Add widgets here.', 'bas'),
'before_widget' => '',
'before_title' => '
',
));
}
/**
* Enqueue scripts and styles.
*/
add_action('wp_enqueue_scripts', 'bas_scripts');
function bas_scripts() {
global $post;
wp_enqueue_style('bas-style', get_stylesheet_uri());
wp_enqueue_style('bas-bootstrap-style', get_template_directory_uri() . '/dist/css/bootstrap.min.css');
wp_enqueue_style( 'date-range-picker-style', 'https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css');
wp_enqueue_style('bas-fontawesome-style', get_template_directory_uri() . '/dist/css/fontawesome.min.css');
wp_enqueue_style('bas-PxGrotesk-style', get_template_directory_uri() . '/dist/css/PxGrotesk.css');
wp_enqueue_style('bas-Eina02-style', get_template_directory_uri() . '/dist/css/Eina02.css');
wp_enqueue_style('bas-chosen-style', get_stylesheet_directory_uri() . '/dist/css/chosen.css');
wp_enqueue_style('bas-header-footer-style', get_template_directory_uri() . '/dist/css/header-footer.css');
wp_enqueue_style('bas-owl-style', get_template_directory_uri() . '/dist/css/owl.carousel.min.css');
wp_enqueue_style('bas-event-style', get_template_directory_uri() . '/dist/css/event.css');
wp_enqueue_style('bas-general-style', get_template_directory_uri() . '/dist/css/general.css');
wp_enqueue_script('bas-jquery', get_template_directory_uri() . '/dist/js/jquery.min.js');
wp_enqueue_script('bas-popper', get_template_directory_uri() . '/dist/js/popper.min.js');
wp_enqueue_script('bas-bootstrap', get_template_directory_uri() . '/dist/js/bootstrap.min.js', array('bas-jquery'), false, true);
// Datepicker
wp_enqueue_script( 'date-range-moment-js', 'https://cdn.jsdelivr.net/momentjs/latest/moment.min.js', array('bas-jquery'), time(), true );
wp_enqueue_script( 'date-range-picker-js', 'https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js', array('bas-jquery', 'date-range-moment-js'), time(), true );
wp_enqueue_script('bas-chosen-js', get_template_directory_uri() . '/dist/js/chosen.js');
wp_enqueue_script('bas-owl-js', get_template_directory_uri() . '/dist/js/owl.carousel.min.js');
wp_enqueue_script('bas-search-script', get_template_directory_uri() . '/dist/js/bas-search-script.js', array('bas-jquery'), false, true);
wp_localize_script('bas-search-script', 'ajax', array('ajax_url' => admin_url('admin-ajax.php')));
if (is_front_page() || is_home() || is_post_type_archive('event')) {
wp_enqueue_style('event-calender-css', get_template_directory_uri() . '/dist/css/fullcalendar.min.css');
wp_enqueue_script('calender-moment', get_template_directory_uri() . '/dist/js/moment.min.js', array('bas-jquery'), false, true);
wp_enqueue_script('calender-fullcalendar', get_template_directory_uri() . '/dist/js/fullcalendar.min.js', array('bas-jquery'), false, true);
wp_enqueue_script('calender-fullcalendar-all-lang', get_template_directory_uri() . '/dist/js/fullcalendar-all-lang.min.js', array('bas-jquery'), false, true);
wp_enqueue_script('event-calender-custom', get_template_directory_uri() . '/dist/js/custom-calender.js', array('bas-jquery', 'date-range-picker-js'), time(), true);
wp_localize_script('event-calender-custom', 'ajax', array(
'ajax_url' => admin_url('admin-ajax.php'),
'current_year' => isset($_GET['filter-year']) ? $_GET['filter-year'] : '',
'date_filter_btn'=> __('Date', 'bas'),
'is_home' => (is_home() || is_front_page() ) ? true : false,
'archive_event_url' => get_home_url().'/event'
)
);
wp_localize_script('event-calender-custom', 'event_calendar_lang', array('calendar_lang' => ICL_LANGUAGE_CODE));
}
if (is_front_page() || is_home()) {
wp_enqueue_style('bas-owl-theme', get_template_directory_uri() . '/dist/css/owl.theme.default.css');
wp_enqueue_style('bas-home', get_template_directory_uri() . '/dist/css/home.css');
wp_enqueue_script('bas-home-js', get_template_directory_uri() . '/dist/js/bas-home.js', array('jquery'), false, true);
}
if (is_post_type_archive('event')) {
wp_enqueue_style('bas-mCustomScrollbar', get_template_directory_uri() . '/dist/css/jquery.mCustomScrollbar.min.css');
wp_enqueue_style('bas-event', get_stylesheet_directory_uri() . '/dist/css/events-list.css');
wp_enqueue_script('bas-mCustomScrollbar-js', get_template_directory_uri() . '/dist/js/jquery.mCustomScrollbar.concat.min.js');
wp_enqueue_script('bas-events-js', get_template_directory_uri() . '/dist/js/events.js');
wp_enqueue_script('bas-home-js', get_template_directory_uri() . '/dist/js/bas-home.js', array('jquery'), false, true);
wp_localize_script('bas-home-js', 'ajax', array('ajax_url' => admin_url('admin-ajax.php')));
}
if (is_post_type_archive('project') || is_page_template('templates/template-projects.php')) {
wp_enqueue_style('bas-mCustomScrollbar', get_template_directory_uri() . '/dist/css/jquery.mCustomScrollbar.min.css');
wp_enqueue_style('bas-project', get_stylesheet_directory_uri() . '/dist/css/projects-list.css');
wp_enqueue_script('bas-mCustomScrollbar-js', get_template_directory_uri() . '/dist/js/jquery.mCustomScrollbar.concat.min.js');
wp_enqueue_script('bas-projects-js', get_template_directory_uri() . '/dist/js/projects.js');
}
if (is_singular('project')) {
wp_enqueue_style('bas-single-project', get_stylesheet_directory_uri() . '/dist/css/single-project.css');
wp_enqueue_script('bas-single-project-js', get_template_directory_uri() . '/dist/js/single-project.js');
}
if (is_object($post) && (has_shortcode($post->post_content, 'filterPeople') || has_shortcode($post->post_content, 'peopleList') || has_shortcode($post->post_content, 'prevStaff'))) {
wp_enqueue_style('bas-about', get_stylesheet_directory_uri() . '/dist/css/about.css');
wp_register_script('bas-about-script', get_stylesheet_directory_uri() . '/dist/js/about.js');
$params = array('ajaxAdmin' => admin_url('admin-ajax.php'));
wp_localize_script('bas-about-script', 'bas_about_paremters', $params);
wp_enqueue_script('bas-about-script');
}
if (is_search()) {
wp_enqueue_style('bas-search-style', get_template_directory_uri() . '/dist/css/search-results.css');
}
if (is_single()) {
wp_enqueue_style('bas-owl-theme', get_template_directory_uri() . '/dist/css/owl.theme.default.css');
wp_enqueue_style('bas-single', get_stylesheet_directory_uri() . '/dist/css/single.css');
}
if (is_singular() && comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
if (is_post_type_archive('event') || is_post_type_archive('project') || is_page_template('templates/template-projects.php') || is_page_template('templates/template-blog.php') || is_page_template('shortcode-template.php') || has_shortcode($post->post_content, 'filterPeople')) {
wp_enqueue_script('bas-filter-js', get_template_directory_uri() . '/dist/js/filter-actions.js');
}
if (is_page_template('templates/template-blog.php')) {
wp_enqueue_style('bas-mCustomScrollbar', get_template_directory_uri() . '/dist/css/jquery.mCustomScrollbar.min.css');
wp_enqueue_style('bas-posts', get_stylesheet_directory_uri() . '/dist/css/posts-list.css');
wp_enqueue_script('bas-mCustomScrollbar-js', get_template_directory_uri() . '/dist/js/jquery.mCustomScrollbar.concat.min.js');
wp_enqueue_script('bas-news-js', get_template_directory_uri() . '/dist/js/news.js');
}
if (is_object($post) && has_shortcode($post->post_content, 'map')) {
$api_key = get_field('map_api_key', 'option');
wp_enqueue_script('bas-map-js', "//maps.googleapis.com/maps/api/js?key=" . $api_key);
wp_enqueue_script('bas-map-satalite-js', get_template_directory_uri() . '/dist/js/map-satalite.js');
}
if (is_object($post) && has_shortcode($post->post_content, 'reports')) {
wp_enqueue_style('bas-slick-1', "//cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.9/slick.min.css");
wp_enqueue_style('bas-slick-2', "//cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.9/slick-theme.min.css");
wp_enqueue_style('bas-slick-3', get_template_directory_uri() . '/dist/css/organization.css');
wp_enqueue_script('bas-slickjs', "//cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.9/slick.min.js");
wp_register_script('bas-slickjs-action', get_template_directory_uri() . '/dist/js/about_us_organizate.js');
$params = array('ajaxAdmin' => admin_url('admin-ajax.php'));
wp_localize_script('bas-slickjs-action', 'bas_slick_paremters', $params);
wp_enqueue_script('bas-slickjs-action');
}
if (is_object($post) && (has_shortcode($post->post_content, 'reports') || has_shortcode($post->post_content, 'filterPeople') || has_shortcode($post->post_content, 'prevStaff'))) {
wp_enqueue_style('bas-about', get_stylesheet_directory_uri() . '/dist/css/about.css');
}
if (is_object($post) && isset($post->post_content) && has_shortcode($post->post_content, 'video')) {
wp_enqueue_style('video-shortcode-style', get_template_directory_uri() . '/dist/css/videos-list.css');
wp_enqueue_script('video-script', get_template_directory_uri() . '/dist/js/videos.js');
}
if (is_object($post) && isset($post->post_content) && has_shortcode($post->post_content, 'formidable')) {
wp_enqueue_script('video-script', get_template_directory_uri() . '/dist/js/customScriptForms.js');
}
wp_enqueue_script('bas-scripts', get_template_directory_uri() . '/dist/js/scripts.js');
//wp_enqueue_script('custom', get_template_directory_uri() . '/dist/js/custom.js', array('jquery'), '20151215', false );
wp_localize_script('bas-scripts', 'bas', array('sub_menu_text' => __('Select other Page', 'bas'), 'show_more' => __('Read more', 'bas'), 'show_less' => __('Less', 'bas')));
}
add_action('acf/init', 'bas_acf_init');
function bas_acf_init() {
if (function_exists('acf_add_options_page')) {
acf_add_options_page(array(
'page_title' => __('Theme General Settings', 'bas'),
'menu_title' => __('Theme Settings', 'bas'),
'menu_slug' => 'theme-general-settings',
'redirect' => true
));
acf_add_options_sub_page(array(
'page_title' => __('Header & Footer Settings', 'bas'),
'menu_title' => __('Header & Footer', 'bas'),
'menu_slug' => 'header-footer-settings',
'parent_slug' => 'theme-general-settings',
));
acf_add_options_sub_page(array(
'page_title' => __('Homepage', 'bas'),
'menu_title' => __('Homepage', 'bas'),
'menu_slug' => 'home-settings',
'parent_slug' => 'theme-general-settings'
));
acf_add_options_sub_page(array(
'page_title' => __('Contact Us', 'bas'),
'menu_title' => __('Contact Us', 'bas'),
'menu_slug' => 'conatct-us-settings',
'parent_slug' => 'theme-general-settings'
));
acf_add_options_sub_page(array(
'page_title' => __('Dark Page', 'bas'),
'menu_title' => __('Dark Page', 'bas'),
'menu_slug' => 'dark-page-settings',
'parent_slug' => 'theme-general-settings'
));
}
}
include get_template_directory() . '/inc/events-list-functions.php';
include get_template_directory() . '/inc/projects-list-functions.php';
include get_template_directory() . '/inc/filters-query.php';
include get_template_directory() . '/inc/news-list-functions.php';
include get_template_directory() . '/inc/date-functions.php';
include get_template_directory() . '/inc/about-functions.php';
include get_template_directory() . '/inc/about-us-organzation-functions.php';
include get_template_directory() . '/inc/custom-posts.php';
include get_template_directory() . '/inc/video-functions.php';
include get_template_directory() . '/inc/shortcodes/filter-people.php';
include get_template_directory() . '/inc/shortcodes/people-list.php';
include get_template_directory() . '/inc/shortcodes/prev-staff.php';
include get_template_directory() . '/inc/shortcodes/gallery-shortcode.php';
include get_template_directory() . '/inc/shortcodes/document-shortcode.php';
include get_template_directory() . '/inc/shortcodes/accordion-block-shortcode.php';
include get_template_directory() . '/inc/shortcodes/video-shortcode.php';
include get_template_directory() . '/inc/shortcodes/schools-shortcode.php';
include get_template_directory() . '/inc/shortcodes/map-shortcode.php';
include get_template_directory() . '/inc/shortcodes/project-documentation.php';
include get_template_directory() . '/inc/shortcodes/reports.php';
include get_template_directory() . '/inc/ajax/bas-search.php';
include get_template_directory() . '/inc/ajax/calendar-events.php';
add_action('template_redirect', 'redirect_to_news_blog_template');
function redirect_to_news_blog_template() {
global $wp_query;
if ((isset($wp_query) && (bool) $wp_query->is_posts_page) || is_category()) {
include TEMPLATEPATH . '/templates/template-blog.php';
exit;
}
}
// Remove type attribute fro scripts/styles
add_action('wp_loaded', 'output_buffer_start');
function output_buffer_start() {
ob_start("output_callback");
}
//callback function
function output_callback($buffer) {
return preg_replace("%[ ]type=[\'\"]text\/(javascript|css)[\'\"]%", '', $buffer);
}
// autpopulate category products with products that has the selected category
add_action('acf/load_field/name=project_tutors_data', 'bas_load_people_field_choices');
function bas_load_people_field_choices($field) {
global $post;
$type = get_post_type();
$types = array('project');
if (!in_array($type, $types))
return $field;
$peoples = bas_get_peoples();
$field['choices'] = $peoples;
return $field;
}
// list peoples in toturs ACP on project
function bas_get_peoples() {
$available_peoples = get_list_current_people_by_catgory(-1);
$choices = array();
if ($available_peoples && $available_peoples->have_posts()) {
// populate choices
foreach ($available_peoples->posts as $people) {
$choices[$people->ID] = $people->post_title;
}
}
wp_reset_query();
return $choices;
}
//function hook_header() {
// echo "";
//}
//
//add_action('wp_head', 'hook_header');
// get vimeo image by video id
function get_vimeo_image_url($video_id) {
$video_image = '';
if ($video_id) {
$data = wp_remote_get('http://vimeo.com/api/oembed.json?url=https://vimeo.com/' . $video_id);
if (isset($data['body']) && $data['body']) {
$data_body = json_decode($data['body'], true);
$video_image = ($data_body && isset($data_body['thumbnail_url']) && $data_body['thumbnail_url']) ? $data_body['thumbnail_url'] : '';
}
}
return $video_image;
}
// get youtube image by video id
function get_youtube_image_url($video_id) {
$video_image = '';
if ($video_id)
$video_image = 'https://img.youtube.com/vi/' . $video_id . '/mqdefault.jpg';
return $video_image;
}
// get template url by name
function get_page_template_url($template_name = '') {
$url = '';
if ($template_name) {
$page = new WP_Query(array(
'post_type' => 'page',
'post_status' => 'publish',
'posts_per_page' => -1,
'suppress_filters' => false,
'meta_query' => array(
array(
'key' => '_wp_page_template',
'value' => $template_name
)
)
));
if (!empty($page->posts)) {
return get_permalink($page->posts[0]->ID);
}
}
return $url;
}
add_shortcode('get_custom_lang_switcher', 'get_custom_lang_switcher_func');
function get_custom_lang_switcher_func() {
$languages = icl_get_languages('skip_missing=0&orderby=code');
if (!empty($languages)) {
$content = '';
foreach ($languages as $l) {
if ($l['country_flag_url']) {
if ($l["code"] == "en") {
$flag_url = get_template_directory_uri() . "/dist/images/en_lg.png";
} elseif ($l["code"] == "no") {
$flag_url = get_template_directory_uri() . "/dist/images/no_lg.png";
} else {
$flag_url = $l['country_flag_url'];
}
$selected = '';
if ($l['active']) {
$selected = "class='active'";
}
$content .= ' ';
}
}
$content .= '
';
}
return $content;
}
remove_action('wp_head', 'rest_output_link_header', 10);
remove_action('template_redirect', 'rest_output_link_header', 11);
/* Filter to modify search query */
function bas_search_overwrite( $search, $wp_query ) {
// echo "000"; print_r($wp_query);
if ( ! empty( $search ) && ! empty( $wp_query->query_vars['search_terms'] ) ) {
global $wpdb;
$q = $wp_query->query_vars;
$n = ! empty( $q['exact'] ) ? '' : '%';
$search = array();
$term = "";
foreach ( ( array ) $q['search_terms'] as $term ){
$like_var = $n . $wpdb->esc_like( $term ) . $n;
$search['post_title'][] = $wpdb->prepare( "$wpdb->posts.post_title COLLATE UTF8_GENERAL_CI LIKE %s", $like_var );
$search['post_excerpt'][] = $wpdb->prepare( "$wpdb->posts.post_excerpt COLLATE UTF8_GENERAL_CI LIKE %s", $like_var );
$search['post_content'][] = $wpdb->prepare( "$wpdb->posts.post_content COLLATE UTF8_GENERAL_CI LIKE %s", $like_var );
if($wp_query->query['post_type'] == "project"){
$query = $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE ( meta_key='first_name' AND meta_value LIKE '%s' ) or ( meta_key='last_name' AND meta_value LIKE '%s' )", $term ,$term);
$authorID = $wpdb->get_var( $query );
if(!empty($authorID))
$search['author_id'][] = $wpdb->prepare( "$wpdb->posts.post_author IN ($authorID)");
}
}
$search['post_title'] = '( ' .implode( ' AND ', $search['post_title'] ).' )';
$search['post_excerpt'] = '( ' .implode( ' AND ', $search['post_excerpt'] ).' )';
$search['post_content'] = '( ' .implode( ' AND ', $search['post_content'] ).' )';
if(!empty($search['author_id']))
$search['author_id'] = '( ' .implode( ' AND ', $search['author_id'] ).' )';
else
unset($search['author_id']);
// echo "111"; print_r($search); die;
if($wp_query->query['post_type'] == "project"){
$query = $wpdb->prepare("SELECT $wpdb->terms.term_id FROM $wpdb->terms JOIN $wpdb->term_taxonomy ON $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id WHERE name LIKE '%%%s%%' AND $wpdb->term_taxonomy.taxonomy = 'project_tag'", $term);
$termID = $wpdb->get_col( $query );
// echo "222"; print_r($search);
/*if(!empty($termID)){
$search = ' OR ( ' . implode( ' OR ', $search ).' )';
}else{*/
$search = ' AND ( ' . implode( ' OR ', $search ).' )';
//}
}else{
$search = ' AND ( ' . implode( ' OR ', $search ).' )';
}
}
// echo "333"; print_r($search); die("ss");
return $search;
}
add_filter( 'posts_search', 'bas_search_overwrite', 10, 2 );
add_action('wp_ajax_get_permalink_from_id_ajax', 'get_permalink_from_id_ajax');
add_action('wp_ajax_nopriv_get_get_permalink_from_id_ajax', 'get_permalink_from_id_ajax');
function get_permalink_from_id_ajax() {
if ($_POST['post_id']) {
$response = array();
global $post;
$post = get_post($_POST['post_id']);
ob_start();
get_template_part('template-parts/share-on-social', $shared_post_id = $post_id);
$response['shareHTML'] = ob_get_contents();
ob_end_clean();
echo json_encode($response);
}
die();
}
add_action('init', 'mm_dark_page');
function mm_dark_page() {
if (!is_admin()) {
if (function_exists('get_field')) {
$dark_page_active = get_field('dark_page_active', 'option');
if ($dark_page_active) {
$dark_page_text = get_field('dark_page_text', 'option');
add_action('wp_head', function() {
echo '';
}, 0);
echo '';
echo '
';
echo $dark_page_text;
echo '
';
echo '
';
}
}
}
}
/**
* The template for displaying all pages
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages
* and that other 'pages' on your WordPress site may use a
* different template.
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* @package BAS
*/
get_header();
?>
the_title(); ?>
the_content(); ?>
get_footer();