| 1 |
<?php |
| 2 |
/** |
| 3 |
* Initialize REST API Controller |
| 4 |
* |
| 5 |
* @package MasterAddons |
| 6 |
* @subpackage WidgetBuilder |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace MasterAddons\Inc\Admin\WidgetBuilder; |
| 10 |
|
| 11 |
if (!defined('ABSPATH')) { |
| 12 |
exit; |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* Register REST API routes |
| 17 |
*/ |
| 18 |
\add_action('rest_api_init', function() { |
| 19 |
$controller = new REST_Controller(); |
| 20 |
$controller->register_routes(); |
| 21 |
}); |
| 22 |
|
| 23 |
/** |
| 24 |
* Flush rewrite rules on plugin activation or when routes change |
| 25 |
* This ensures REST API endpoints are properly registered |
| 26 |
*/ |
| 27 |
\add_action('admin_init', function() { |
| 28 |
// Check if we need to flush rewrite rules |
| 29 |
$version_option = 'jltma_rest_api_version'; |
| 30 |
$current_version = '1.0.1'; // Increment this when REST routes change |
| 31 |
|
| 32 |
if (get_option($version_option) !== $current_version) { |
| 33 |
flush_rewrite_rules(); |
| 34 |
update_option($version_option, $current_version); |
| 35 |
} |
| 36 |
}); |
| 37 |
|