AlkantarClanX12
| Current Path : /www/capitalgmcbuickregina_830/public/wp-content/plugins/leadbox/cli/ |
| Current File : /www/capitalgmcbuickregina_830/public/wp-content/plugins/leadbox/cli/lead-intake-target-command.php |
<?php if (!defined('ABSPATH')) exit;
/**
* LBT-1468 — WP-CLI command to read/set the lead-intake routing target.
*
* wp leadbox lead-intake-target get
* wp leadbox lead-intake-target set <legacy|leadbox_os|both>
*
* Registered in Leadbox.php under `if (defined('WP_CLI') && WP_CLI)`.
*/
final class LB_CLI_Lead_Intake_Target_Command
{
/**
* Shows the effective lead-intake target, the stored option, and whether the
* LEADBOX_LEAD_INTAKE_TARGET constant is overriding it.
*
* ## EXAMPLES
*
* wp leadbox lead-intake-target get
*
* @when after_wp_load
*/
public function get($args, $assoc_args)
{
$settings = get_option('leadbox-settings');
$stored = (is_array($settings) && isset($settings['lead_intake_target']) && $settings['lead_intake_target'] !== '')
? $settings['lead_intake_target']
: '(unset — defaults to legacy)';
$effective = LB_API_Settings::getInstance()->getLeadIntakeTarget();
WP_CLI::log('Effective target : ' . $effective);
WP_CLI::log('Stored option : ' . $stored);
if (defined('LEADBOX_LEAD_INTAKE_TARGET')) {
WP_CLI::log('Constant override: LEADBOX_LEAD_INTAKE_TARGET = ' . strtolower((string) LEADBOX_LEAD_INTAKE_TARGET));
WP_CLI::warning('The constant overrides the stored option; the effective target is driven by wp-config.php.');
} else {
WP_CLI::log('Constant override: (not defined)');
}
}
/**
* Sets the stored lead-intake target option.
*
* ## OPTIONS
*
* <target>
* : Where Ninja Forms leads are routed.
* ---
* options:
* - legacy
* - leadbox_os
* - both
* ---
*
* ## EXAMPLES
*
* # Enter dual-write mode for parity monitoring
* wp leadbox lead-intake-target set both
*
* # Cut fully over to Leadbox Platform
* wp leadbox lead-intake-target set leadbox_os
*
* @when after_wp_load
*/
public function set($args, $assoc_args)
{
$target = isset($args[0]) ? strtolower(trim($args[0])) : '';
$valid = LB_API_Settings::LEAD_INTAKE_TARGETS;
if (!in_array($target, $valid, true)) {
WP_CLI::error(sprintf(
"Invalid target '%s'. Valid values: %s.",
$target,
implode(', ', $valid)
));
}
$settings = get_option('leadbox-settings');
if (!is_array($settings)) {
$settings = array();
}
$settings['lead_intake_target'] = $target;
update_option('leadbox-settings', $settings);
WP_CLI::success(sprintf("lead_intake_target set to '%s'.", $target));
if (defined('LEADBOX_LEAD_INTAKE_TARGET')) {
WP_CLI::warning(sprintf(
"LEADBOX_LEAD_INTAKE_TARGET is defined ('%s') in wp-config.php and OVERRIDES this option. " .
"The effective target will not change until the constant is removed.",
strtolower((string) LEADBOX_LEAD_INTAKE_TARGET)
));
}
}
}