File: //wordpress/plugins/wp-cloud-client/1.1.9/src/Integration/DiviHelper.php
<?php
declare(strict_types=1);
namespace VPlugins\WPCloudClient\Integration;
final class DiviHelper {
/**
* Check whether the Divi theme is active.
*
* @return bool True if Divi is the active theme or a parent theme.
*/
public static function isActive(): bool {
$theme = wp_get_theme();
while ( $theme ) {
if ( $theme->get( 'Name' ) === 'Divi' || $theme->get_template() === 'Divi' ) {
return true;
}
$parent = $theme->parent();
if ( ! $parent || $parent === $theme ) {
break;
}
$theme = $parent;
}
return false;
}
/**
* Sync a business profile into Divi theme options.
*
* @param array $profile The business profile data to sync.
* @return array<string, string>|null The written options or null if inactive.
*/
public static function syncProfile( array $profile ): ?array {
if ( empty( $profile ) || ! self::isActive() ) {
return null;
}
if ( ! function_exists( 'et_update_option' ) ) {
return null;
}
$options = [];
$options['divi_facebook_url'] = $profile['facebook_url'] ?? '';
$options['divi_instagram_url'] = $profile['instagram_url'] ?? '';
$options['divi_rss_url'] = $profile['rss_url'] ?? '';
$options['divi_twitter_url'] = $profile['twitter_url'] ?? '';
if ( empty( $profile['contact_email'] ) ) {
$options['header_email'] = get_option( 'admin_email', '' );
} else {
$options['header_email'] = $profile['contact_email'];
}
if ( ! empty( $profile['toll_free_number'] ) ) {
$options['phone_number'] = $profile['toll_free_number'];
} elseif ( ! empty( $profile['work_number'] ) && is_array( $profile['work_number'] ) ) {
$options['phone_number'] = $profile['work_number'][0];
} elseif ( ! empty( $profile['cell_number'] ) ) {
$options['phone_number'] = $profile['cell_number'];
} else {
$options['phone_number'] = '';
}
foreach ( $options as $name => $value ) {
et_update_option( $name, $value );
}
return $options;
}
}