-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7925322
commit d0ef3fb
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Zeek\WP_Util; | ||
|
||
use Arrilot\DotEnv\DotEnv; | ||
|
||
class Constants { | ||
|
||
private static $env_vars = [ | ||
'ACF_LITE' => true, | ||
'DISABLE_WP_CRON' => false, | ||
'FILE_MOD_ALLOWED' => false, | ||
'SENTRY_URL' => null, | ||
]; | ||
|
||
public static function init( $dir ) { | ||
/** | ||
* Load dotenv if .env file is present | ||
*/ | ||
if ( file_exists( $dir . '/.env.php' ) ) { | ||
DotEnv::load( $dir . '/.env.php' ); | ||
DotEnv::copyVarsToEnv(); | ||
} | ||
|
||
// Set usable constants | ||
define( 'APP_URL', plugin_dir_url( $dir ) ); | ||
define( 'APP_PATH', dirname( $dir ) . '/' ); | ||
|
||
/** | ||
* Set the proper constant for ACF Lite | ||
* Only load our hardcoded fields if ACF Lite is off | ||
*/ | ||
foreach ( self::$env_vars as $key => $default ) { | ||
self::env_set( $key, $default ); | ||
} | ||
} | ||
|
||
private static function env_set( $key, $default ) { | ||
// Check if we have env value | ||
$env_value = env( $key, $default ); | ||
|
||
if ( ! isset( $env_value ) ) { | ||
return false; | ||
} | ||
|
||
// if not defined | ||
if ( defined( $key ) ) { | ||
return false; | ||
} | ||
|
||
define( $key, $env_value ); | ||
} | ||
} |