| Server IP : 194.61.116.167 / Your IP : 216.73.217.84 Web Server : Apache/2 System : Linux nimbus2000.evosiber.com 5.14.0-503.11.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 12 09:26:13 EST 2024 x86_64 User : evoplastik ( 1130) PHP Version : 8.1.34 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/evoplastik/public_html/wp-content/plugins/elementor/core/experiments/ |
Upload File : |
<?php
namespace Elementor\Core\Experiments;
use Elementor\Core\Experiments\Manager as Experiments_Manager;
use Elementor\Plugin;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Wp_Cli extends \WP_CLI_Command {
/**
* Activate an Experiment
*
* ## EXAMPLES
*
* 1. wp elementor experiments activate container
* - This will activate the Container experiment.
*
* @param array $args
* @param array|null $assoc_args - Arguments from WP CLI command.
*/
public function activate( $args, $assoc_args ) {
if ( empty( $args[0] ) ) {
\WP_CLI::error( 'Please specify an experiment.' );
}
$is_network = $this->is_network( $assoc_args );
// Activate experiment callback.
$activate = function ( $site = '', $id = null ) use ( $args, $is_network ) {
$success = 'Experiment activated successfully';
$error = 'Cannot activate experiment';
if ( $is_network ) {
$success .= " for site {$site}";
$error .= " for site {$site}";
}
$experiments_manager = Plugin::instance()->experiments;
$option = $experiments_manager->get_feature_option_key( $args[0] );
update_option( $option, Experiments_Manager::STATE_ACTIVE );
try {
\WP_CLI::success( $success );
} catch ( \Exception $e ) {
\WP_CLI::error( $error );
}
};
if ( $is_network ) {
$this->foreach_sites( $activate );
} else {
$activate();
}
}
/**
* Deactivate an Experiment
*
* ## EXAMPLES
*
* 1. wp elementor experiments deactivate container
* - This will deactivate the Container experiment.
*
* @param array $args
* @param array|null $assoc_args - Arguments from WP CLI command.
*/
public function deactivate( $args, $assoc_args ) {
if ( empty( $args[0] ) ) {
\WP_CLI::error( 'Please specify an experiment.' );
}
$is_network = $this->is_network( $assoc_args );
// Activate experiment callback.
$activate = function ( $site = '' ) use ( $args, $is_network ) {
$success = 'Experiment deactivated successfully';
$error = 'Cannot deactivate experiment';
if ( $is_network ) {
$success .= " for site {$site}";
$error .= " for site {$site}";
}
$experiments_manager = Plugin::instance()->experiments;
$option = $experiments_manager->get_feature_option_key( $args[0] );
update_option( $option, Experiments_Manager::STATE_INACTIVE );
try {
\WP_CLI::success( $success );
} catch ( \Exception $e ) {
\WP_CLI::error( $error );
}
};
if ( $is_network ) {
$this->foreach_sites( $activate );
} else {
$activate();
}
}
/**
* Determine if the current website is a multisite.
*
* @param array|null $assoc_args - Arguments from WP CLI command.
*
* @return bool
*/
private function is_network( $assoc_args ) {
return ! empty( $assoc_args['network'] ) && is_multisite();
}
/**
* Iterate over network sites and execute a callback.
*
* @param callable $callback - Callback to execute. Gets the site name & id as parameters.
*
* @return void
*/
private function foreach_sites( callable $callback ) {
/** @var \WP_Site[] $sites */
$sites = get_sites();
foreach ( $sites as $keys => $site ) {
// Cast $blog as an array instead of object
$blog_id = $site->blog_id;
switch_to_blog( $blog_id );
$callback( get_option( 'home' ), $blog_id );
restore_current_blog();
}
}
}