Skip to content

Commit

Permalink
Create Constants.php
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronHolbrook authored Mar 27, 2019
1 parent 7925322 commit d0ef3fb
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/Constants.php
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 );
}
}

0 comments on commit d0ef3fb

Please sign in to comment.