| 1 |
<?php |
| 2 |
/** |
| 3 |
* Booking related hooks |
| 4 |
* |
| 5 |
* @package Timetics |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Timetics\Core\Appointments; |
| 9 |
|
| 10 |
use Timetics\Utils\Singleton; |
| 11 |
|
| 12 |
class Hooks { |
| 13 |
use Singleton; |
| 14 |
|
| 15 |
/** |
| 16 |
* Initialize |
| 17 |
* |
| 18 |
* @return void |
| 19 |
*/ |
| 20 |
public function init() { |
| 21 |
add_filter( 'template_include', [ $this, 'custom_single_post_template' ] ); |
| 22 |
add_action( 'init', [ $this, 'register_appointment' ] ); |
| 23 |
add_action( 'init', [ $this, 'register_appointment_taxonomy' ] ); |
| 24 |
// add_filter( 'get_term', [ $this, 'prepare_term' ], 10, 2 ); |
| 25 |
|
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Include custom template for single appointment |
| 30 |
* |
| 31 |
* @param string $template |
| 32 |
* |
| 33 |
* @return string |
| 34 |
*/ |
| 35 |
public function custom_single_post_template( $template ) { |
| 36 |
|
| 37 |
|
| 38 |
// Check if it's a single post |
| 39 |
if ( is_single() ) { |
| 40 |
global $post; // Add this line to access the global $post variable |
| 41 |
|
| 42 |
// Check if the post type is 'timetics-appointment' |
| 43 |
if ('timetics-appointment' !== $post->post_type) { |
| 44 |
return $template; |
| 45 |
} |
| 46 |
// Load a custom template file |
| 47 |
$custom_template = TIMETICS_PLUGIN_DIR . '/templates/meeting/custom-single-post-template.php'; |
| 48 |
|
| 49 |
if ( file_exists( $custom_template ) ) { |
| 50 |
return $custom_template; |
| 51 |
} |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
// Check if it's an archive |
| 56 |
|
| 57 |
if (is_archive() && is_tax('timetics-meeting-category')) { |
| 58 |
|
| 59 |
// Check if the post type is 'timetics-appointment' |
| 60 |
$custom_template = TIMETICS_PLUGIN_DIR . '/templates/meeting/category-template.php'; |
| 61 |
|
| 62 |
// If a custom template exists, use it; otherwise, use the default template |
| 63 |
if (file_exists($custom_template)) { |
| 64 |
return $custom_template; |
| 65 |
} |
| 66 |
|
| 67 |
} |
| 68 |
|
| 69 |
// Return the original template if no custom template is found |
| 70 |
return $template; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Register custom post type for appointment |
| 75 |
* |
| 76 |
* @return void |
| 77 |
*/ |
| 78 |
public function register_appointment() { |
| 79 |
$labels = array( |
| 80 |
'name' => __( 'Timetics Appointments', 'timetics' ), |
| 81 |
'singular_name' => __( 'Timetics Appointment', 'timetics' ), |
| 82 |
'menu_name' => __( 'Timetics Appointments', 'timetics' ), |
| 83 |
'add_new' => __( 'Add New', 'timetics' ), |
| 84 |
'add_new_item' => __( 'Add New Timetics Appointment', 'timetics'), |
| 85 |
'edit' => __( 'Edit', 'timetics' ), |
| 86 |
'edit_item' => __( 'Edit Timetics Appointment', 'timetics' ), |
| 87 |
'new_item' => __( 'New Timetics Appointment', 'timetics' ), |
| 88 |
'view' => __( 'View', 'timetics' ), |
| 89 |
'view_item' => __( 'View Timetics Appointment', 'timetics' ), |
| 90 |
'search_items' => __( 'Search Timetics Appointments', 'timetics' ), |
| 91 |
'not_found' => __( 'No timetics appointments found', 'timetics' ), |
| 92 |
'not_found_in_trash' => __( 'No timetics appointments found in trash', 'timetics' ), |
| 93 |
'parent' => __( 'Parent Timetics Appointment', 'timetics' ), |
| 94 |
); |
| 95 |
|
| 96 |
$args = array( |
| 97 |
'labels' => $labels, |
| 98 |
'public' => true, |
| 99 |
'publicly_queryable' => true, |
| 100 |
'show_ui' => true, |
| 101 |
'show_in_menu' => false, |
| 102 |
'query_var' => true, |
| 103 |
'rewrite' => array( 'slug' => 'timetics-appointment' ), |
| 104 |
'capability_type' => 'post', |
| 105 |
'has_archive' => true, |
| 106 |
'hierarchical' => false, |
| 107 |
'menu_position' => null, |
| 108 |
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt' ), |
| 109 |
); |
| 110 |
|
| 111 |
register_post_type( 'timetics-appointment', $args ); |
| 112 |
} |
| 113 |
|
| 114 |
public function register_appointment_taxonomy() { |
| 115 |
$labels = array( |
| 116 |
'name' => __( 'Appointment categories', 'timetics' ), |
| 117 |
'singular_name' => __( 'Appointment category', 'timetics' ), |
| 118 |
'menu_name' => __( 'Appointment category', 'timetics' ), |
| 119 |
'all_items' => __( 'Appointment categories', 'timetics' ), |
| 120 |
'parent_item' => __( 'Parent Genre', 'timetics' ), |
| 121 |
'parent_item_colon' => __( 'Parent Genre:', 'timetics' ), |
| 122 |
'new_item_name' => __( 'New Genre Name', 'timetics' ), |
| 123 |
'add_new_item' => __( 'Add New Genre', 'timetics' ), |
| 124 |
'edit_item' => __( 'Edit Genre', 'timetics' ), |
| 125 |
'update_item' => __( 'Update Genre', 'timetics' ), |
| 126 |
'view_item' => __( 'View Genre', 'timetics' ), |
| 127 |
'separate_items_with_commas' => __( 'Separate genres with commas', 'timetics' ), |
| 128 |
'add_or_remove_items' => __( 'Add or remove genres', 'timetics' ), |
| 129 |
'choose_from_most_used' => __( 'Choose from the most used genres', 'timetics' ), |
| 130 |
'popular_items' => __( 'Popular Genres', 'timetics' ), |
| 131 |
'search_items' => __( 'Search Genres', 'timetics' ), |
| 132 |
'not_found' => __( 'Genre Not Found', 'timetics' ), |
| 133 |
'no_terms' => __( 'No genres', 'timetics' ), |
| 134 |
'items_list' => __( 'Genres list', 'timetics' ), |
| 135 |
'items_list_navigation' => __( 'Genres list navigation', 'timetics' ), |
| 136 |
); |
| 137 |
|
| 138 |
$args = array( |
| 139 |
'labels' => $labels, |
| 140 |
'hierarchical' => true, |
| 141 |
'public' => true, |
| 142 |
'show_ui' => false, |
| 143 |
'show_admin_column' => true, |
| 144 |
'show_in_nav_menus' => true, |
| 145 |
'show_tagcloud' => true, |
| 146 |
); |
| 147 |
|
| 148 |
register_taxonomy( 'timetics-meeting-category', array( 'book' ), $args ); // |
| 149 |
} |
| 150 |
|
| 151 |
public function prepare_term( $term, $taxonomy ) { |
| 152 |
if ( 'timetics-meeting-category' !== $taxonomy ) { |
| 153 |
return $term; |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
return $term; |
| 158 |
} |
| 159 |
} |
| 160 |
|