<?php

// Register Custom Post Type Services
function create_services_cpt()
{

    $labels = array(
        'name' => _x('Meditest Services', 'Post Type General Name', 'meditest-extra'),
        'singular_name' => _x('Services', 'Post Type Singular Name', 'meditest-extra'),
        'menu_name' => _x('Meditest Services', 'Admin Menu text', 'meditest-extra'),
        'name_admin_bar' => _x('Services', 'Add New on Toolbar', 'meditest-extra'),
        'archives' => __('Services Archives', 'meditest-extra'),
        'attributes' => __('Services Attributes', 'meditest-extra'),
        'parent_item_colon' => __('Parent Services:', 'meditest-extra'),
        'all_items' => __('All Services', 'meditest-extra'),
        'add_new_item' => __('Add New Services', 'meditest-extra'),
        'add_new' => __('Add New', 'meditest-extra'),
        'new_item' => __('New Services', 'meditest-extra'),
        'edit_item' => __('Edit Services', 'meditest-extra'),
        'update_item' => __('Update Services', 'meditest-extra'),
        'view_item' => __('View Services', 'meditest-extra'),
        'view_items' => __('View Services', 'meditest-extra'),
        'search_items' => __('Search Services', 'meditest-extra'),
        'not_found' => __('Not found', 'meditest-extra'),
        'not_found_in_trash' => __('Not found in Trash', 'meditest-extra'),
        'featured_image' => __('Featured Image', 'meditest-extra'),
        'set_featured_image' => __('Set featured image', 'meditest-extra'),
        'remove_featured_image' => __('Remove featured image', 'meditest-extra'),
        'use_featured_image' => __('Use as featured image', 'meditest-extra'),
        'insert_into_item' => __('Insert into Services', 'meditest-extra'),
        'uploaded_to_this_item' => __('Uploaded to this Services', 'meditest-extra'),
        'items_list' => __('Services list', 'meditest-extra'),
        'items_list_navigation' => __('Services list navigation', 'meditest-extra'),
        'filter_items_list' => __('Filter Services list', 'meditest-extra'),
    );
    $args = array(
        'label' => __('Services', 'meditest-extra'),
        'description' => __('Services Post Type', 'meditest-extra'),
        'labels' => $labels,
        'menu_icon' => 'dashicons-buddicons-topics',
        'supports' => array('title', 'editor'),
        'taxonomies' => array(),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'menu_position' => 25,
        'show_in_admin_bar' => true,
        'show_in_nav_menus' => true,
        'can_export' => true,
        'has_archive' => false,
        'hierarchical' => false,
        'exclude_from_search' => false,
        'show_in_rest' => false,
        'publicly_queryable' => true,
        'capability_type' => 'post',
    );
    register_post_type('services', $args);
}
add_action('init', 'create_services_cpt', 0);





function meditest_footer_builder()
{

    $labels = array(
        'name' => _x('Meditest Footer Builder', 'Post Type General Name', 'meditest-extra'),
        'singular_name' => _x('Meditest Footer', 'Post Type Singular Name', 'meditest-extra'),
        'menu_name' => _x('Meditest Footer Builder', 'Admin Menu text', 'meditest-extra'),
        'name_admin_bar' => _x('Meditest Footer', 'Add New on Toolbar', 'meditest-extra'),
        'archives' => __('Meditest Footer Archives', 'meditest-extra'),
        'attributes' => __('Meditest Footer Attributes', 'meditest-extra'),
        'parent_item_colon' => __('Parent Meditest Footer:', 'meditest-extra'),
        'all_items' => __('All Footers', 'meditest-extra'),
        'add_new_item' => __('Add New Meditest Footer', 'meditest-extra'),
        'add_new' => __('Add New', 'meditest-extra'),
        'new_item' => __('New Meditest Footer', 'meditest-extra'),
        'edit_item' => __('Edit Meditest Footer', 'meditest-extra'),
        'update_item' => __('Update Meditest Footer', 'meditest-extra'),
        'view_item' => __('View Meditest Footer', 'meditest-extra'),
        'view_items' => __('View Meditest Footers', 'meditest-extra'),
        'search_items' => __('Search Meditest Footer', 'meditest-extra'),
        'not_found' => __('Not found', 'meditest-extra'),
        'not_found_in_trash' => __('Not found in Trash', 'meditest-extra'),
        'featured_image' => __('Featured Image', 'meditest-extra'),
        'set_featured_image' => __('Set featured image', 'meditest-extra'),
        'remove_featured_image' => __('Remove featured image', 'meditest-extra'),
        'use_featured_image' => __('Use as featured image', 'meditest-extra'),
        'insert_into_item' => __('Insert into Meditest Footer', 'meditest-extra'),
        'uploaded_to_this_item' => __('Uploaded to this Meditest Footer', 'meditest-extra'),
        'items_list' => __('Meditest Footers list', 'meditest-extra'),
        'items_list_navigation' => __('Meditest Footers list navigation', 'meditest-extra'),
        'filter_items_list' => __('Filter Meditest Footers list', 'meditest-extra'),
    );

    $args = array(
        'label' => __('Meditest Footer', 'meditest-extra'),
        'description' => __('', 'meditest-extra'),
        'labels' => $labels,
        'menu_icon' => 'dashicons-table-row-before',
        'supports' => array('title', 'editor'),
        'taxonomies' => array(),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'menu_position' => 25,
        'show_in_admin_bar' => true,
        'show_in_nav_menus' => false,
        'can_export' => true,
        'has_archive' => true,
        'hierarchical' => false,
        'exclude_from_search' => false,
        'show_in_rest' => false,
        'publicly_queryable' => true,
        'capability_type' => 'post',
        'rewrite' => false,
    );
    register_post_type('meditest_footer', $args);
}
add_action('init', 'meditest_footer_builder', 0);


// Custom Search form function for custom-search-form widget
function meditest_modify_search_query($query)
{
    if ($query->is_search) {
        $query->set('post_type', array('post', 'doctorsprofile', 'services'));
    }
    return $query;
}
add_filter('pre_get_posts', 'meditest_modify_search_query');


/** Add Contact Methods in the User Profile **/
function meditest_user_contact_methods($user_contact)
{
    $user_contact['facebook']   = esc_html__('Facebook Profile Link', 'meditest');
    $user_contact['twitter']    = esc_html__('Twitter Profile', 'meditest');
    $user_contact['instagram']  = esc_html__('Instagram', 'meditest');
    $user_contact['pinterest']  = esc_html__('Pinterest', 'meditest');
    $user_contact['youtube']    = esc_html__('Youtube Profile', 'meditest');

    return $user_contact;
};
add_filter('user_contactmethods', 'meditest_user_contact_methods');

// Support SVG File Upload
function meditest_enable_svg_upload($upload_mimes)
{
    $upload_mimes['svg'] = 'image/svg+xml';
    $upload_mimes['svgz'] = 'image/svg+xml';
    return $upload_mimes;
}
add_filter('upload_mimes', 'meditest_enable_svg_upload', 10, 1);

// Post Style One
if (!function_exists('meditest_latest_post_grid_one')) {
    function meditest_latest_post_grid_one($settings, $query)
    { ?>
        <div class="theme-post-grid-design-one grid-loadmore-content news_post_trending_list post-trending-list-wrap post-list-medium-wrap post-list-medium-style post-medium-style-loadmore">

            <div class="row">

                <?php

                while ($query->have_posts()) : $query->the_post(); ?>

                    <div class="<?php echo esc_attr($settings['grid_post_column']); ?>">

                        <div class="post-block-item-one post-block-col-one meditest-post-grid">

                            <div class="news-post-grid-thumbnail post-grid1-thumbnail">
                                <a href="<?php the_permalink(); ?>" class="news-post-grid-thumbnail-wrap">
                                    <img src="<?php echo esc_attr(esc_url(get_the_post_thumbnail_url(null, 'full'))); ?>" alt="<?php the_title_attribute(); ?>">
                                </a>
                            </div>

                            <div class="news-post-grid-content grid-content-inner">

                                <div class="grid-content-meta-uniq">
                                    <div class="custom-meta-date-bx">
                                        <i class="icon-calendar1"></i> <?php echo esc_html(get_the_date('M j, Y')); ?>
                                    </div>
                                    <?php if ($settings['show_comment'] == 'yes') : ?>
                                        <div class="cutom-comment-wrapper">
                                            <?php echo get_comments_number(); ?> <?php echo esc_html('Comment', 'meditest-extra'); ?>
                                        </div>
                                    <?php endif; ?>

                                </div>


                                <h3 class="post-title">
                                    <a href="<?php the_permalink(); ?>"><?php echo esc_html(wp_trim_words(get_the_title(), $settings['post_title_crop'], '')); ?></a>
                                </h3>

                                <?php if ($settings['show_desc'] == 'yes') : ?>
                                    <div class="post-excerpt-box">
                                        <p><?php echo esc_html(wp_trim_words(get_the_excerpt(), $settings['desc_limit'], '')); ?></p>
                                    </div>
                                <?php endif; ?>

                                <div class="post-meta-bottom-list-wrap cols-post-meta-items">
                                    <div class="post-meta-left-wrap cols-meta-left">
                                        <div class="post-meta-left-author">
                                            <?php echo get_avatar(get_the_author_meta('ID'), 40); ?>
                                        </div>

                                        <div class="post-meta-left-content post-grid1-meta">
                                            <h4 class="post-author-name">
                                                <?php echo get_the_author_link(); ?>
                                            </h4>

                                            <?php if ($settings['show_cat'] == 'yes') : ?>
                                                <div class="post-category-box post-block-meta-cat">
                                                    <?php require MEDITEST_THEME_DIR . '/template-parts/cat-alt-template.php'; ?>
                                                </div>
                                            <?php endif; ?>

                                        </div>
                                    </div>

                                    <div class="post-more-link">
                                        <a href="<?php the_permalink(); ?>"><?php echo esc_html('Larn more', 'meditest-extra'); ?> <i class="icon-arrow-right1"></i></a>
                                    </div>

                                </div>
                            </div>

                        </div>



                    </div>

                <?php endwhile; ?>

            </div>
        </div>

    <?php      }
}


// Post Style Tow
if (!function_exists('meditest_latest_post_grid_two')) {
    function meditest_latest_post_grid_two($settings, $query)
    { ?>
        <div class="theme-post-grid-design-one grid-loadmore-content news_post_trending_list post-trending-list-wrap post-list-medium-wrap post-list-medium-style post-medium-style-loadmore">

            <div class="row">

                <?php

                while ($query->have_posts()) : $query->the_post(); ?>

                    <div class="<?php echo esc_attr($settings['grid_post_column']); ?>">

                        <div class="post-block-item-one post-block-col-one meditest-post-grid pg_style_two">

                            <div class="news-post-grid-thumbnail pg_two_img">
                                <a href="<?php the_permalink(); ?>" class="news-post-grid-thumbnail-wrap">
                                    <img src="<?php echo esc_attr(esc_url(get_the_post_thumbnail_url(null, 'full'))); ?>" alt="<?php the_title_attribute(); ?>">
                                </a>
                            </div>

                            <div class="news-post-grid-content grid-content-inner pg_two_content">

                                <div class="grid-content-meta-uniq">
                                    <div class="custom-meta-date-bx">
                                        <i class="icon-calendar1"></i> <?php echo esc_html(get_the_date('d M, Y')); ?>
                                    </div>

                                    <h4 class="post-author-name">
                                        <?php echo esc_html('By', 'meditest-extra') . ' ' . get_the_author_link(); ?>
                                    </h4>

                                </div>


                                <h3 class="post-title">
                                    <a href="<?php the_permalink(); ?>"><?php echo esc_html(wp_trim_words(get_the_title(), $settings['post_title_crop'], '')); ?></a>
                                </h3>




                            </div>

                        </div>



                    </div>

                <?php endwhile; ?>

            </div>
        </div>

    <?php      }
}

// Post Style Three
if (!function_exists('meditest_latest_post_grid_three')) {
    function meditest_latest_post_grid_three($settings, $query)
    { ?>
        <div class="theme-post-grid-design-one grid-loadmore-content news_post_trending_list post-trending-list-wrap post-list-medium-wrap post-list-medium-style post-medium-style-loadmore">

            <div class="row">

                <?php

                while ($query->have_posts()) : $query->the_post(); ?>

                    <div class="<?php echo esc_attr($settings['grid_post_column']); ?>">

                        <div class="post-block-item-one post-block-col-one meditest-post-grid pg_style_two">

                            <div class="news-post-grid-thumbnail pg_two_img">
                                <a href="<?php the_permalink(); ?>" class="news-post-grid-thumbnail-wrap">
                                    <img src="<?php echo esc_attr(esc_url(get_the_post_thumbnail_url(null, 'full'))); ?>" alt="<?php the_title_attribute(); ?>">
                                </a>
                            </div>

                            <div class="news-post-grid-content grid-content-inner pg_two_content pg_content_three">

                                <div class="grid-content-meta-uniq">
                                    <div class="custom-meta-date-bx">
                                        <i class="icon-calendar1"></i> <?php echo esc_html(get_the_date('d M, Y')); ?>
                                    </div>

                                    <h4 class="post-author-name">
                                        <?php echo esc_html('By', 'meditest-extra') . ' ' . get_the_author_link(); ?>
                                    </h4>

                                </div>


                                <h3 class="post-title">
                                    <a href="<?php the_permalink(); ?>"><?php echo esc_html(wp_trim_words(get_the_title(), $settings['post_title_crop'], '')); ?></a>
                                </h3>




                            </div>

                        </div>



                    </div>

                <?php endwhile; ?>

            </div>
        </div>

    <?php      }
}



// Post Style Four
if (!function_exists('meditest_latest_post_grid_four')) {
    function meditest_latest_post_grid_four($settings, $query)
    { ?>
        <div class="theme-post-grid-design-one grid-loadmore-content news_post_trending_list post-trending-list-wrap post-list-medium-wrap post-list-medium-style post-medium-style-loadmore">

            <div class="row">

                <?php

                while ($query->have_posts()) : $query->the_post(); ?>

                    <div class="<?php echo esc_attr($settings['grid_post_column']); ?>">

                        <div class="post-block-item-one post-block-col-one meditest-post-grid pg_style_four">

                            <div class="news-post-grid-thumbnail">
                                <a href="<?php the_permalink(); ?>" class="news-post-grid-thumbnail-wrap">
                                    <img src="<?php echo esc_attr(esc_url(get_the_post_thumbnail_url(null, 'full'))); ?>" alt="<?php the_title_attribute(); ?>">
                                </a>
                                <div class="date-box-four">
                                    <span><?php echo esc_html(get_the_date('j ')); ?></span>
                                    <span><?php echo esc_html(get_the_date('M')); ?></span>

                                </div>
                            </div>

                            <div class="news-post-grid-content grid-content-inner pg_content_four">

                                <div class="post-category-box post-block-meta-cat">
                                    <?php require MEDITEST_THEME_DIR . '/template-parts/cat-alt-template.php'; ?>
                                </div>

                                <h3 class="post-title">
                                    <a href="<?php the_permalink(); ?>"><?php echo esc_html(wp_trim_words(get_the_title(), $settings['post_title_crop'], '')); ?></a>
                                </h3>

                                <?php if ($settings['show_desc'] == 'yes') : ?>
                                    <div class="post-excerpt-box">
                                        <p><?php echo esc_html(wp_trim_words(get_the_excerpt(), $settings['desc_limit'], '')); ?></p>
                                    </div>
                                <?php endif; ?>



                                <div class="post-more-link-pg-four">
                                    <a href="<?php the_permalink(); ?>"><?php echo esc_html('Read more', 'meditest-extra'); ?> <i class="icon-add1"></i></a>
                                </div>


                            </div>

                        </div>



                    </div>

                <?php endwhile; ?>

            </div>
        </div>

<?php      }
}
