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