File: /var/www/hcv/wp-content/plugins/hockeycoach-site-plugin/cpt.php
<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}
add_action( 'init', function() {
    register_taxonomy( 'free_drill_categories', 'free_drill', array(
        'labels' => array(
            'name'          => __('Categories', 'tokic_theme'),
            'singular_name' => __('Category', 'tokic_theme'),
            'add_new_item'  => __('Add New Category', 'tokic_theme'),
            'edit_item'     => __('Edit Category', 'tokic_theme'),
            'new_item'      => __('New Category', 'tokic_theme'),
            'view_item'     => __('View Category', 'tokic_theme'),
            'view_items'    => __('View Categories', 'tokic_theme'),
            'search_items'  => __('Search Category', 'tokic_theme'),
            'not_found'     => __('No Categories found', 'tokic_theme'),
            'all_items'     => __('All Categories', 'tokic_theme')
        ),
        'rewrite' => array('slug' => 'category'),
        'hierarchical' => false,
    ));
    
    register_taxonomy( 'free_drill_age', 'free_drill', array(
        'labels' => array(
            'name'          => __('Ages', 'tokic_theme'),
            'singular_name' => __('Age', 'tokic_theme'),
            'add_new_item'  => __('Add New Age', 'tokic_theme'),
            'edit_item'     => __('Edit Age', 'tokic_theme'),
            'new_item'      => __('New Age', 'tokic_theme'),
            'view_item'     => __('View Age', 'tokic_theme'),
            'view_items'    => __('View Ages', 'tokic_theme'),
            'search_items'  => __('Search Age', 'tokic_theme'),
            'not_found'     => __('No Ages found', 'tokic_theme'),
            'all_items'     => __('All Ages', 'tokic_theme')
        ),
        'rewrite' => array('slug' => 'age'),
        'hierarchical' => false,
    ));
    register_post_type('free_drill',
        array(
            'labels' => array(
                'name' => __('Free drills', 'free_drill'),
                'singular_name' => __('Free drill', 'free_drill'),
            ),
            'public' => true,
            'show_in_menu' => true,
            'supports' => array( 'title'  ),
            'has_archive' => true,
            'rewrite' => array('slug' =>  'drills'),
        ));
    register_post_type('testimonial',
        array(
            'labels' => array(
                'name' => __('Testimonials', 'testimonials'),
                'singular_name' => __('Testimonial', 'testimonial'),
            ),
            'public' => true,
            'show_in_menu' => true,
            'supports' => array('title', 'editor'),
            'has_archive' => true,
            'rewrite' => array('slug' =>  'testimonials'),
            'menu_icon' => 'dashicons-editor-quote',
        ));
        
    register_post_type('tutorial',
    array(
        'labels' => array(
            'name' => __('Tutorials', 'tutorial'),
            'singular_name' => __('Tutorial', 'tutorial'),
        ),
        'public' => true,
        'show_in_menu' => true,
        'supports' => array( 'title', 'editor' ),
        'has_archive' => true,
        'rewrite' => array('slug' =>  'tutorials'),
        'menu_icon' => 'dashicons-welcome-learn-more',
    ));
});
add_filter( 'manage_free_drill_posts_columns', 'set_custom_edit_free_drills_columns');
function set_custom_edit_free_drills_columns($columns) {
	$temp = $columns['date'];
    unset( $columns['date'] );
    $columns['category'] = 'Category';
    $columns['age'] = 'Age';
    $columns['date'] = $temp;
    return $columns;
}
add_action( 'manage_free_drill_posts_custom_column' , 'custom_free_drills_column', 10, 2 );
function custom_free_drills_column(  $column, $post_id ) {
    if ( $column == 'category' ) {
        $terms = get_the_terms( $post_id, 'free_drill_categories' );
        if ($terms) {
            $term = array_pop($terms);
            echo $term->name;
        } else {
            echo 'no-category';
        }
    } else if ( $column == 'age' ) {
        $terms = get_the_terms( $post_id, 'free_drill_age' );
        if ($terms) {
            $term = array_pop($terms);
            echo $term->name;} else {
            echo 'no-age';
        }
    } 
}
function add_single_query_arg($key,  $list_of_args, $arg): string
{
    if($list_of_args){
        $args_array = explode(',', $list_of_args);
    }else{
        $args_array = [];
    }
    if (!in_array($arg, $args_array)) {
        array_push($args_array, $arg);
    }
    return add_query_arg($key, implode(',', $args_array), get_pagenum_link(false, false));
}
function remove_single_query_arg($key,  $list_of_args, $arg): string
{
    if($list_of_args){
        $args_array = explode(',', $list_of_args);
        if (($name = array_search($arg, $args_array)) !== false) {
            unset($args_array[$name]);
        }
    }else{
        $args_array = [];
    }
    if(count($args_array) == 0){
        return remove_query_arg($key);
    }
    return add_query_arg($key, implode(',', $args_array), get_pagenum_link(false, false));
}
?>