Actions
1 year ago
Connectors
1 year ago
Traits
1 year ago
Cmbird_Acf.php
1 year ago
Cors.php
1 year ago
Template.php
1 year ago
index.php
1 year ago
Cors.php
49 lines
| 1 | <?php |
| 2 | |
| 3 | namespace CommerceBird\Admin; |
| 4 | |
| 5 | /* |
| 6 | |-------------------------------------------------------------------------- |
| 7 | | If this file is called directly, abort. |
| 8 | |-------------------------------------------------------------------------- |
| 9 | */ |
| 10 | |
| 11 | use CommerceBird\Admin\Traits\Singleton; |
| 12 | |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit; |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Class Cors |
| 19 | * |
| 20 | * @package Enable\Cors |
| 21 | */ |
| 22 | final class Cors { |
| 23 | use Singleton; |
| 24 | |
| 25 | public function __construct() { |
| 26 | |
| 27 | $option = (bool) get_option( 'cmbird_zoho_cors_status', 0 ); |
| 28 | if ( ! $option ) { |
| 29 | return; |
| 30 | } |
| 31 | $this->headers(); |
| 32 | add_filter( 'rest_pre_serve_request', array( $this, 'headers' ) ); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * It sets headers for Cross-Origin Resource Sharing (CORS) based on options set in the |
| 37 | * plugin's settings. |
| 38 | * |
| 39 | * @return void If the `` variable is empty, the function will return nothing (void). |
| 40 | */ |
| 41 | public function headers(): void { |
| 42 | |
| 43 | header( 'Access-Control-Allow-Origin: *', true ); |
| 44 | header( 'Access-Control-Allow-Methods: *', true ); |
| 45 | header( 'Access-Control-Allow-Headers: *', true ); |
| 46 | header( 'Access-Control-Allow-Credentials: true', true ); |
| 47 | } |
| 48 | } |
| 49 |