ulgm_define_constants_after
Fires after the ULGM constants have been defined, allowing for late initialization or modification.
add_action( 'ulgm_define_constants_after', $callback, 10, 1 );
Description
Fires after essential plugin constants are defined. Use this action hook to access or modify plugin constants, or to perform actions that depend on their availability before configuration setup is complete.
Usage
add_action( 'ulgm_define_constants_after', 'your_function_name', 10, 1 );
Examples
/**
* Example of how to hook into ulgm_define_constants_after.
* This hook fires after the main plugin constants have been defined.
*
* We'll use this to conditionally define a new constant based on a plugin setting
* or another factor. For this example, let's say we want to define a constant
* for a specific feature flag if a certain option is set in WordPress.
*/
function my_plugin_conditional_constant() {
// Check if a specific WordPress option is enabled.
// Replace 'my_plugin_feature_enabled' with your actual option name.
$is_feature_enabled = get_option( 'my_plugin_feature_enabled', false );
if ( true === $is_feature_enabled ) {
// Define a new constant if the feature is enabled.
// We'll use a prefix to avoid naming collisions.
// Replace 'MY_PLUGIN_FEATURE_ACTIVE' with your desired constant name.
if ( ! defined( 'MY_PLUGIN_FEATURE_ACTIVE' ) ) {
define( 'MY_PLUGIN_FEATURE_ACTIVE', true );
}
// You could also log this action for debugging.
error_log( 'My Plugin: Feature Active constant defined.' );
} else {
// Optionally, you could define a constant for when it's NOT active.
if ( ! defined( 'MY_PLUGIN_FEATURE_INACTIVE' ) ) {
define( 'MY_PLUGIN_FEATURE_INACTIVE', true );
}
error_log( 'My Plugin: Feature Inactive constant defined.' );
}
}
// Add the action. The hook `ulgm_define_constants_after` doesn't pass any arguments,
// so the accepted_args parameter can be 0 (or omitted as it defaults to 1, but 0 is explicit).
add_action( 'ulgm_define_constants_after', 'my_plugin_conditional_constant', 10, 0 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/class-config.php:102
public function configure_plugin_before_boot( $plugin_name, $prefix, $version, $file, $debug ) {
$this->define_constants( $plugin_name, $prefix, $version, $file, $debug );
do_action( 'ulgm_define_constants_after' );
do_action( 'ulgm_config_setup_after' );
}