| Server IP : 172.67.134.116 / Your IP : 216.73.217.123 Web Server : Apache System : Linux server.rehabsharif.com 5.14.0-611.54.3.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 7 16:31:24 EDT 2026 x86_64 User : nobi37te ( 1003) PHP Version : 8.2.33 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/nobi37te/public_html/wp-content/plugins/enable-cors/src/Helpers/ |
Upload File : |
<?php
namespace Enable\Cors\Helpers;
/*
|--------------------------------------------------------------------------
| If this file is called directly, abort.
|--------------------------------------------------------------------------
*/
if ( ! defined( 'Enable\Cors\SLUG' ) ) {
exit;
}
/**
* Class Headers
*
* @package Enable\Cors
*/
final class Headers {
/**
* Adds headers for Cross-Origin Resource Sharing (CORS) based on the options set.
*
* @param Option $option from DB.
*/
public static function add( Option $option ): void {
// Always set Vary: Origin for proper caching behavior.
header( 'Vary: Origin' );
// Check if the current origin is allowed.
if ( $option->is_current_origin_allowed() ) {
$origin = function_exists( 'get_http_origin' ) ? get_http_origin() : '*';
header( 'Access-Control-Allow-Origin: ' . $origin );
} elseif ( $option->has_wildcard() ) {
header( 'Access-Control-Allow-Origin: *' );
} else {
return; // No CORS allowed, exit early.
}
// Set allowed methods.
if ( $option->has_methods() ) {
$allowed_methods = implode( ', ', $option->get_allowed_methods() );
header( 'Access-Control-Allow-Methods: ' . $allowed_methods );
} else {
header( 'Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE, PATCH' );
}
// Set allowed headers.
if ( $option->has_header() ) {
$allowed_headers = implode( ', ', $option->get_allowed_header() );
header( 'Access-Control-Allow-Headers: ' . $allowed_headers );
} else {
header( 'Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization' ); // Default.
}
// Set credentials policy.
header( 'Access-Control-Allow-Credentials: ' . ( $option->should_allow_credentials() ? 'true' : 'false' ) );
// Handle OPTIONS (preflight) requests properly.
if ( 'OPTIONS' === sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ?? '' ) ) ) {
header( 'HTTP/1.1 204 No Content' ); // Indicate no body response.
exit(); // Stop further execution.
}
}
}