| 1 |
<?php |
| 2 |
|
| 3 |
namespace Booktics\Appointment; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 6 |
|
| 7 |
use Booktics\Contracts\Hookable_Service_Contract; |
| 8 |
|
| 9 |
class Appointment_Hooks implements Hookable_Service_Contract { |
| 10 |
|
| 11 |
/** |
| 12 |
* Register the appointment hooks. |
| 13 |
* |
| 14 |
* @return void |
| 15 |
*/ |
| 16 |
public function register() { |
| 17 |
add_filter( 'booktics_appointment_args', array( |
| 18 |
$this, |
| 19 |
'booktics_appointment_args' |
| 20 |
) ); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Filter appointment arguments based on the current user's role. |
| 25 |
* |
| 26 |
* @param array $args The appointment arguments. |
| 27 |
* |
| 28 |
* @return array The filtered appointment arguments. |
| 29 |
*/ |
| 30 |
public function booktics_appointment_args( $args ) { |
| 31 |
$current_user = wp_get_current_user(); |
| 32 |
$roles = $current_user->roles; |
| 33 |
|
| 34 |
if ( in_array( 'administrator', $roles, true ) ) { |
| 35 |
return $args; |
| 36 |
} |
| 37 |
|
| 38 |
if ( in_array( 'booktics_team_member', $roles, true ) ) { |
| 39 |
if ( ! isset( $args['meta_query'] ) ) { |
| 40 |
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Meta query is necessary for filtering team members by meta fields |
| 41 |
$args['meta_query'] = []; |
| 42 |
} |
| 43 |
$args['meta_query'][] = array( |
| 44 |
'key' => 'team_member_id', |
| 45 |
'value' => $current_user->ID, |
| 46 |
'compare' => '=', |
| 47 |
); |
| 48 |
} |
| 49 |
|
| 50 |
return $args; |
| 51 |
} |
| 52 |
} |