File "functions.php"
Full Path: /var/www/bvnghean.vn/wp-content/themes/bvnghean/functions.php
File size: 7.67 KB
MIME-type: text/x-php
Charset: utf-8
<?php
date_default_timezone_set("Asia/Ho_Chi_Minh");
function my_frontend_script(){
wp_enqueue_style( 'roboto', 'https://fonts.googleapis.com/css2?family=Roboto',false,'2.0','all');
wp_enqueue_style( 'jquery-ui', 'https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css',false,'2.0','all');
wp_enqueue_style( 'lineawesome', get_template_directory_uri() . '/css/lineawesome/line-awesome.min.css',false,'2.0','all');
wp_enqueue_style( 'bxslider', 'https://cdn.jsdelivr.net/bxslider/4.2.12/jquery.bxslider.css',false,'2.0','all');
wp_enqueue_style( 'layout', get_template_directory_uri() . '/css/layout.css',false,time(),'all');
wp_enqueue_style( 'stylesheet', get_template_directory_uri() . '/css/stylesheet.css',false,time(),'all');
wp_enqueue_style( 'responsive', get_template_directory_uri() . '/css/responsive.css',false,time(),'all');
wp_enqueue_script( 'jquery', get_template_directory_uri() . '/js/jquery-1.10.2.js', array ( 'jquery' ), '2.0', true);
wp_enqueue_script( 'jquery-ui', 'https://code.jquery.com/ui/1.12.1/jquery-ui.js', null, '2.0', true);
wp_enqueue_script( 'bxslider', 'https://cdn.jsdelivr.net/bxslider/4.2.12/jquery.bxslider.min.js', null, '2.0', true);
wp_enqueue_script( 'main', get_template_directory_uri() . '/js/main.js', null , '2.1', true);
}
add_action( 'wp_enqueue_scripts', 'my_frontend_script' );
add_theme_support( 'post-thumbnails' );
if (function_exists('register_nav_menus')) {
register_nav_menus (
array(
'main_nav' => 'Menu header',
)
);
}
foreach(glob(get_template_directory() . "/ajax/*.php") as $file){
include_once($file);
}
function get_gioitinh($data){
if($data == 'nam'){ return 'Nam'; }
else if($data == 'nu'){ return 'Nữ'; }
else{ return $data; }
}
function get_igioitinh($data){
if($data == 'nam'){ return '<i class="la la-male color-main"></i> Nam'; }
else if($data == 'nu'){ return '<i class="la la-female color-second"></i> Nữ'; }
else{ return $data; }
}
function get_trangthai($data){
if($data == true){
return '<span class="color-main"><i class="la la-door-closed"></i> Đã xử lý</span>';
}else{
return '<span class="color-second"><i class="la la-door-open"></i> Chưa xử lý</span>';
}
}
//Sidebar
register_sidebar(array(
'name' => 'Sidebar Category',
'id' => 'sidebar-category',
'description' => 'Sidebar Category',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<div class="the-title"><span>',
'after_title' => '</span></div>'
));
// Posttype - Booking
function post_type_booking() {
$args = array(
'labels' => array(
'name' => 'Đặt lịch khám',
'singular_name' => 'Đặt lịch khám'
),
'description' => 'Đặt lịch khám bệnh online',
'supports' => array(
'title'
),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => false,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-bell',
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post'
);
register_post_type( 'booking' , $args );
}
add_action( 'init', 'post_type_booking' );
// Posttype - Hien tang
function post_type_hien() {
$args = array(
'labels' => array(
'name' => 'Hiến tạng',
'singular_name' => 'Hiến tạng'
),
'description' => 'Đăng ký Hiến tạng',
'supports' => array(
'title',
'thumbnail'
),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => false,
'show_in_admin_bar' => true,
'menu_position' => 6,
'menu_icon' => 'dashicons-remove',
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post'
);
register_post_type( 'hientang' , $args );
}
add_action( 'init', 'post_type_hien' );
// Posttype - Nhận tạng
function post_type_nhan() {
$args = array(
'labels' => array(
'name' => 'Nhận tạng',
'singular_name' => 'Nhận tạng'
),
'description' => 'Đăng ký nhận tạng',
'supports' => array(
'title',
'thumbnail'
),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => false,
'show_in_admin_bar' => true,
'menu_position' => 7,
'menu_icon' => 'dashicons-plus-alt',
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post'
);
register_post_type( 'nhantang' , $args );
}
add_action( 'init', 'post_type_nhan' );
// Add column
function booking_columns($columns) {
$columns['dien_thoai'] = 'Số điện thoại';
$columns['status'] = 'Trạng thái';
return $columns;
}
add_filter( 'manage_booking_posts_columns', 'booking_columns' );
// Display Column
function custom_booking_column( $column, $post_id ) {
switch ( $column ) {
case 'dien_thoai' :
echo get_field( "dien_thoai", $post_id );
break;
case 'status' :
$status = get_field( "status", $post_id );
if($status == true) echo '<span style="color:#0d9c4a">Đã xử lý</span>';
else if($status == false) echo '<span style="color:#e10786">Chưa xử lý</span>';
break;
}
}
add_action( 'manage_booking_posts_custom_column' , 'custom_booking_column', 10, 2 );
//Pagination
function pagination($custom_query = null, $paged = null) {
global $wp_query;
if($custom_query) $main_query = $custom_query;
else $main_query = $wp_query;
$paged = ($paged) ? $paged : get_query_var('paged');
$big = 999999999;
$total = isset($main_query->max_num_pages)?$main_query->max_num_pages:'';
if($total > 1) echo '<div class="pagenavi">';
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, $paged ),
'total' => $total,
'mid_size' => '10', // Số trang hiển thị khi có nhiều trang trước khi hiển thị ...
'prev_text' => __('Prev','devvn'),
'next_text' => __('Next','devvn'),
) );
if($total > 1) echo '</div>';
}
function get_image_src($id, $size){
global $post;
if($size == '') $size="thumbnail";
$src = wp_get_attachment_image_src($id,$size, true)[0];
if(strpos($src, 'default.png') !== false){
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
if(isset($matches[1][0]))
$first_img = $matches[1][0];
if(empty($first_img)){
//$src = wp_get_attachment_image_src(13998,$size, true)[0];
$src = get_template_directory_uri().'/imgs/placeholder.jpg';
}else{
$src = $first_img;
}
}
return $src;
}
include 'include/widgets.php';
include 'include/shortcodes.php';
if( function_exists('acf_add_options_page') ) {
acf_add_options_page();
}
if(!function_exists('highlight')){
function highlight($text){
$keys = implode('|', explode(' ', get_search_query()));
$text = preg_replace('/(' . $keys .')/iu', '\0', $text);
echo $text;
}
}
function bvnghean_login_redirect( $url, $request, $user ) {
if ($user && is_object($user) && is_a($user, 'ttgheptang')) {
$url = "https://bvnghean.vn/gheptang";
}
return $url;
}
add_filter( 'login_redirect', 'bvnghean_login_redirect', 10, 3 );
?>