: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
public function support_user_remove_roles() {
// Divi Support :: Standard
remove_role( 'et_support' );
// Divi Support :: Elevated
remove_role( 'et_support_elevated' );
* Set the ET Support User's role
public function support_user_set_role( $role = '' ) {
// Get the Divi Support User object
$support_user = new WP_User( $this->support_user_account_name );
$support_user->set_role( 'et_support' );
case 'et_support_elevated':
$support_user->set_role( 'et_support_elevated' );
$support_user->set_role( '' );
* Ensure the `unfiltered_html` capability is added to the ET Support roles in Multisite
* @param array $caps An array of capabilities.
* @param string $cap The capability being requested.
* @param int $user_id The current user's ID.
* @return array Modified array of user capabilities.
function support_user_map_meta_cap( $caps, $cap, $user_id ) {
if ( ! $this->is_support_user( $user_id ) ) {
// This user is in an ET Support user role, so add the capability
if ( 'unfiltered_html' === $cap ) {
$caps = array( 'unfiltered_html' );
* Remove KSES filters on ET Support User's content
function support_user_kses_remove_filters() {
if ( $this->is_support_user() ) {
* Clear "Delete Account" cron hook
public function support_user_clear_delete_cron() {
wp_clear_scheduled_hook( $this->support_user_cron_name );
* Delete the support account if it's expired or the expiration date is not set
public function support_user_cron_maybe_delete_account() {
if ( ! username_exists( $this->support_user_account_name ) ) {
if ( isset( $this->support_user_options['date_created'] ) ) {
$this->support_user_maybe_delete_expired_account();
// if the expiration date isn't set, delete the account anyway
$this->support_user_delete_account();
* Schedule account removal check
public function support_user_init_cron_delete_account() {
$this->support_user_clear_delete_cron();
wp_schedule_event( time(), 'hourly', $this->support_user_cron_name );
public function support_user_get_options() {
$this->support_user_options = get_option( $this->support_user_options_name );
* @param integer $length Token Length
* @param bool $include_symbols Whether to include special characters (or just stick to alphanumeric)
* @return string $token Generated token
public function support_user_generate_token( $length = 17, $include_symbols = true ) {
$alphanum = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$token = substr( str_shuffle( $include_symbols ? $alphanum . $symbols : $alphanum ), 0, $length );
* Generate password from token
* @param string $token Token
* @return string|WP_Error Generated password if successful, WP Error object otherwise
public function support_user_generate_password( $token ) {
/** @see ET_Core_SupportCenter::maybe_set_site_id() */
$site_id = get_option( 'et_support_site_id' );
if ( empty( $site_id ) ) {
// Site ID must be a string
if ( ! is_string( $site_id ) ) {
$et_license = $this->get_et_license();
'site_id' => esc_attr( $site_id ),
'username' => esc_attr( $et_license['username'] ),
'api_key' => esc_attr( $et_license['api_key'] ),
'site_url' => esc_url( home_url( '/' ) ),
'login_url' => 'https://www.elegantthemes.com/members-area/admin/token/'
. '?url=' . urlencode( wp_login_url() )
. '&token=' . urlencode( $token . '|' . $site_id ),
$support_user_options = array(
'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
$request = wp_remote_post(
'https://www.elegantthemes.com/api/token.php',
// Early exit if we don't get a good HTTP response from the API server
if ( 200 !== intval( wp_remote_retrieve_response_code( $request ) ) ) {
'Elegant Themes API Error: HTTP error in API response',
// Early exit and pass along WP_Error report if the server response is an error
if ( is_wp_error( $request ) ) {
'Elegant Themes API Error: WordPress Error in API response',
// Otherwise the response is good - let's load it and continue
$response = unserialize( wp_remote_retrieve_body( $request ) );
// If the API returns an error, we will return and log the accompanying message
$response_is_error = array_key_exists( 'error', $response );
$response_has_error_message = array_key_exists( 'message', $response );
if ( $response_is_error && $response_has_error_message ) {
'Elegant Themes API Error: ' . $response['message'],
// If we get an "Incorrect Token" response, delete the generated Site ID from database
$response_is_token_error = array_key_exists( 'incorrect_token', $response );
if ( $response_is_token_error && ! empty( $response['incorrect_token'] ) ) {
delete_option( 'et_support_site_id' );
'Elegant Themes API Error: Incorrect Token. Please, try again.',
// If we get a normal-looking response, but it doesn't contain the salt we need
if ( empty( $response['salt'] ) ) {
'Elegant Themes API Error: The API response was missing required data.',
// We have the salt; let's clean it and make sure we can use it
$salt = sanitize_text_field( $response['salt'] );
'Elegant Themes API Error: The API responded, but the response was empty.',
// Generate the password using the token we were initially passed & the salt from the API
$password = hash( 'sha256', $token . $salt );
* Delete the account if it's expired
public function support_user_maybe_delete_expired_account() {
if ( empty( $this->support_user_options['date_created'] ) ) {
$expiration_date_unix = strtotime( $this->support_user_expiration_time, $this->support_user_options['date_created'] );
// Delete the user account if the expiration date is in the past
if ( time() >= $expiration_date_unix ) {
$this->support_user_delete_account();
* Delete support account and the plugin options ( token, expiration date )
* @return string | WP_Error Confirmation message on success, WP_Error on failure
public function support_user_delete_account() {
if ( defined( 'DOING_CRON' ) ) {
require_once( ABSPATH . 'wp-admin/includes/user.php' );
if ( ! username_exists( $this->support_user_account_name ) ) {
return new WP_Error( 'get_user_data', esc_html__( 'Support account doesn\'t exist.', 'et-core' ) );
$support_account_data = get_user_by( 'login', $this->support_user_account_name );
if ( $support_account_data ) {
$support_account_id = $support_account_data->ID;
( is_multisite() && ! wpmu_delete_user( $support_account_id ) )
|| ( ! is_multisite() && ! wp_delete_user( $support_account_id ) )
return new WP_Error( 'delete_user', esc_html__( 'Support account hasn\'t been removed. Try to regenerate token again.', 'et-core' ) );
delete_option( $this->support_user_options_name );
return new WP_Error( 'get_user_data', esc_html__( 'Cannot get the support account data. Try to regenerate token again.', 'et-core' ) );
$this->support_user_remove_roles();
$this->support_user_remove_site_id();
$this->support_user_clear_delete_cron();
// update options variable
$this->support_user_get_options();
new WP_Error( 'get_user_data', esc_html__( 'Token has been deleted successfully.', 'et-core' ) );
return esc_html__( 'Token has been deleted successfully. ', 'et-core' );
* Maybe delete support account and the plugin options when switching themes
* If a theme change is one of:
* - [Divi/Extra] > [Divi/Extra] child theme
* - [Divi/Extra] child theme > [Divi/Extra] child theme
* - [Divi/Extra] child theme > [Divi/Extra]
* ...then we won't change the state of the Remote Access toggle.
* @return string | WP_Error Confirmation message on success, WP_Error on failure
public function maybe_deactivate_on_theme_switch() {
// Don't do anything if the user isn't logged in
if ( ! is_user_logged_in() ) {
// Don't do anything if the parent theme's name matches the parent of this Support Center instance
if ( get_option( 'template' ) === $this->parent_nicename ) {
// Leaving Divi/Extra environment; deactivate Support Center
$this->support_user_delete_account();
$this->unlist_support_center();
$this->support_center_capabilities_teardown();
* Is this user the ET Support User?
* @param int|null $user_id Pass a User ID to check. We'll get the current user's ID otherwise.
* @return bool Returns whether this user is the ET Support User.
function is_support_user( $user_id = null ) {
$user_id = $user_id ? (int) $user_id : get_current_user_id();
$user = get_userdata( $user_id );
// Gather this user's associated role(s)
$user_roles = (array) $user->roles;
$user_is_support = false;
// First, check the username
if ( ! $this->support_user_account_name === $user->user_login ) {
// Determine whether this user has the ET Support User role
if ( in_array( 'et_support', $user_roles ) ) {
if ( in_array( 'et_support_elevated', $user_roles ) ) {
* Delete support account and the plugin options ( token, expiration date )
public function unlist_support_center() {
delete_option( 'et_support_center_installed' );
public function support_user_remove_site_id() {
$site_id = get_option( 'et_support_site_id' );
if ( empty( $site_id ) ) {
// Site ID must be a string
if ( ! is_string( $site_id ) ) {
$et_license = $this->get_et_license();
'action' => 'remove_site_id',
'site_id' => esc_attr( $site_id ),
'username' => esc_attr( $et_license['username'] ),
'api_key' => esc_attr( $et_license['api_key'] ),
'site_url' => esc_url( home_url( '/' ) ),
$request = wp_remote_post( 'https://www.elegantthemes.com/api/token.php', $settings );
if ( is_wp_error( $request ) ) {
wp_remote_post( 'https://cdn.elegantthemes.com/api/token.php', $settings );
function support_user_update_via_ajax() {
et_core_security_check( 'manage_options', 'support_center', 'nonce' );
$support_update = sanitize_text_field( $_POST['support_update'] );
if ( 'activate' === $support_update ) {
$maybe_create_user = $this->support_user_maybe_create_user();
// Only activate if we have a User ID and Password
if ( ! is_wp_error( $maybe_create_user ) ) {
$this->support_user_set_role( 'et_support' );
$account_settings = get_option( $this->support_user_options_name );
$site_id = get_option( 'et_support_site_id' );
$response['expiry'] = strtotime(
$this->support_user_options['date_created']
) . $this->support_user_expiration_time
if ( ! empty( $site_id ) && is_string( $site_id ) ) {
$response['token'] = $account_settings['token'] . '|' . $site_id;
$response['message'] = esc_html__(
'ET Support User role has been activated.',