| 1 |
<?php |
| 2 |
/** |
| 3 |
* Register Custom Endpoint |
| 4 |
* |
| 5 |
* @package Timetics |
| 6 |
*/ |
| 7 |
namespace Timetics\Base; |
| 8 |
|
| 9 |
defined( 'ABSPATH' ) || exit; |
| 10 |
|
| 11 |
use Timetics\Utils\Singleton; |
| 12 |
|
| 13 |
class Custom_Endpoint { |
| 14 |
use Singleton; |
| 15 |
|
| 16 |
/** |
| 17 |
* Initialize |
| 18 |
* |
| 19 |
* @return void |
| 20 |
*/ |
| 21 |
public function init() { |
| 22 |
add_action( 'init', [$this, 'register'] ); |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Register all custom endpoints |
| 27 |
* |
| 28 |
* @return void |
| 29 |
*/ |
| 30 |
public function register() { |
| 31 |
$endpoints = $this->get_endpoints(); |
| 32 |
|
| 33 |
foreach ( $endpoints as $endpoint ) { |
| 34 |
add_rewrite_endpoint( $endpoint, EP_ALL ); |
| 35 |
} |
| 36 |
|
| 37 |
// Flush rewrite rules after register all custom endpoints. |
| 38 |
flush_rewrite_rules( true ); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Get all endpoints |
| 43 |
* |
| 44 |
* @return array |
| 45 |
*/ |
| 46 |
public function get_endpoints() { |
| 47 |
/** |
| 48 |
* All endpoints that have to be register |
| 49 |
*/ |
| 50 |
return [ |
| 51 |
'timetics-integration', |
| 52 |
]; |
| 53 |
} |
| 54 |
}; |
| 55 |
|