Skip to content

Automattic/jetpack-constants

trunk
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 

Jetpack Constants

A simple constant manager for Jetpack.

Testing constants is hard. Once you define a constant in PHP, it's defined. Constants Manager is an abstraction layer so that unit tests can set constants for tests.

Usage

Retrieve the value of a constant CONSTANT_NAME (returns null if it's not defined):

use Automattic\Jetpack\Constants;

$constant_value = Constants::get_constant( 'CONSTANT_NAME' );

Set the value of a constant CONSTANT_NAME to a particular value:

use Automattic\Jetpack\Constants;

$value = 'some value';
Constants::set_constant( 'CONSTANT_NAME', $value );

Check whether a constant CONSTANT_NAME is defined:

use Automattic\Jetpack\Constants;

$defined = Constants::is_defined( 'CONSTANT_NAME' );

Check whether a constant CONSTANT_NAME is truthy:

use Automattic\Jetpack\Constants;

$is_truthy = Constants::is_true( 'CONSTANT_NAME' );

Delete the CONSTANT_NAME constant:

use Automattic\Jetpack\Constants;

Constants::clear_single_constant( 'CONSTANT_NAME' );

Delete all known constants:

use Automattic\Jetpack\Constants;

Constants::clear_constants();

Using this package in your WordPress plugin

If you plan on using this package in your WordPress plugin, we would recommend that you use Jetpack Autoloader as your autoloader. This will allow for maximum interoperability with other plugins that use this package as well.

Security

Need to report a security vulnerability? Go to https://automattic.com/security/ or directly to our security bug bounty site https://hackerone.com/automattic.

License

jetpack-constants is licensed under GNU General Public License v2 (or later)

About

[READ ONLY] A wrapper for defining constants in a more testable way. This repository is a mirror, for issue tracking and development head to: https://github.com/automattic/jetpack

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Languages