: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
// Fixes the issue with x symbol between width and height values in the filename.
$url = str_replace( '%26%23215%3B', 'x', rawurlencode( $url ) );
$url = rawurldecode( $url );
if ( 0 !== strpos( $url, 'http' ) ) {
$wp_upload_dir = wp_upload_dir( null, false );
$upload_dir = str_replace( site_url( '/' ), '', $wp_upload_dir['baseurl'] );
$url_trimmed = ltrim( $url, '/' );
if ( 0 === strpos( $url_trimmed, $upload_dir ) || 0 === strpos( $url_trimmed, 'wp-content' ) ) {
$url = site_url( $url_trimmed );
$url = $wp_upload_dir['baseurl'] . '/' . $url_trimmed;
// Validate URL format and file extension.
// Example: https://regex101.com/r/dXcpto/1.
if ( ! filter_var( $url, FILTER_VALIDATE_URL ) || ! preg_match( '/^(.+)\.(jpg|jpeg|gif|png)$/', $url ) ) {
if ( ! function_exists( 'et_core_is_uploads_dir_url' ) ) :
* Check if a URL starts with the base upload directory URL.
* @param string $url The URL being looked up.
function et_core_is_uploads_dir_url( $url ) {
$upload_dir = wp_upload_dir( null, false );
return et_()->starts_with( $url, $upload_dir['baseurl'] );
if ( ! function_exists( 'et_get_src_from_img_tag' ) ) :
* Get src attribute value from image tag
* @param string $image The HTML image tag to look up.
* @return string|bool Src attribute value. False on failure.
function et_get_src_from_img_tag( $image ) {
// Parse src attributes using regex.
// Example: https://regex101.com/r/kY6Gdd/1.
if ( preg_match( '/^<img.+src=[\'"](?P<src>.+?)[\'"].*>/', $image, $match ) ) {
if ( isset( $match['src'] ) ) {
// Parse src attributes using DOMDocument when regex is failed.
if ( class_exists( 'DOMDocument' ) && class_exists( 'DOMXPath' ) ) {
$doc = new DOMDocument();
$doc->loadHTML( $image );
$xpath = new DOMXPath( $doc );
return $xpath->evaluate( 'string(//img/@src)' );
if ( ! function_exists( 'et_core_enqueue_js_admin' ) ) :
function et_core_enqueue_js_admin() {
$epanel_jsfolder = ET_CORE_URL . 'admin/js';
et_core_load_main_fonts();
wp_register_script( 'epanel_colorpicker', $epanel_jsfolder . '/colorpicker.js', array(), et_get_theme_version() );
wp_register_script( 'epanel_eye', $epanel_jsfolder . '/eye.js', array(), et_get_theme_version() );
wp_register_script( 'epanel_checkbox', $epanel_jsfolder . '/checkbox.js', array(), et_get_theme_version() );
wp_enqueue_script( 'wp-color-picker' );
wp_enqueue_style( 'wp-color-picker' );
$wp_color_picker_alpha_uri = defined( 'ET_BUILDER_URI' ) ? ET_BUILDER_URI . '/scripts/ext/wp-color-picker-alpha.min.js' : $epanel_jsfolder . '/wp-color-picker-alpha.min.js';
wp_enqueue_script( 'wp-color-picker-alpha', $wp_color_picker_alpha_uri, array(
), et_get_theme_version(), true );
if ( ! wp_script_is( 'epanel_functions_init', 'enqueued' ) ) {
wp_enqueue_script( 'epanel_functions_init', $epanel_jsfolder . '/functions-init.js', array(
), et_get_theme_version() );
wp_localize_script( 'epanel_functions_init', 'ePanelishSettings', array(
'clearpath' => get_template_directory_uri() . '/epanel/images/empty.png',
'epanelish_nonce' => wp_create_nonce( 'epanelish_nonce' ),
'help_label' => esc_html__( 'Help', $themename ),
'et_core_nonces' => et_core_get_nonces(),
// Use WP 4.9 CodeMirror Editor for some fields
if ( function_exists( 'wp_enqueue_code_editor' ) ) {
// Required for Javascript mode
wp_enqueue_script( 'jshint' );
wp_enqueue_script( 'htmlhint' );
* Get ET account information.
function et_core_get_et_account() {
$utils = ET_Core_Data_Utils::instance();
$updates_options = get_site_option( 'et_automatic_updates_options', array() );
'et_username' => $utils->array_get( $updates_options, 'username', '' ),
'et_api_key' => $utils->array_get( $updates_options, 'api_key', '' ),
'status' => get_site_option( 'et_account_status', 'not_active' ),
* Get all meta saved by the builder for a given post.
* @param integer $post_id
function et_core_get_post_builder_meta( $post_id ) {
$raw_meta = get_post_meta( $post_id );
foreach ( $raw_meta as $key => $values ) {
if ( strpos( $key, '_et_pb_' ) !== 0 && strpos( $key, '_et_builder_' ) !== 0 ) {
if ( strpos( $key, '_et_pb_ab_' ) === 0 ) {
// Do not copy A/B meta as it is post-specific.
foreach ( $values as $value ) {
if ( ! function_exists( 'et_core_parse_google_fonts_json' ) ) :
* Parse google fonts json to array.
* @param string $json Google fonts json file content.
* @return array Associative array list of google fonts.
function et_core_parse_google_fonts_json( $fonts_json ) {
if ( ! $fonts_json || ! is_string( $fonts_json ) ) {
$fonts_json_decoded = json_decode( $fonts_json, true );
if ( ! $fonts_json_decoded || empty( $fonts_json_decoded['items'] ) ) {
foreach ( $fonts_json_decoded['items'] as $font_item ) {
if ( ! isset( $font_item['family'], $font_item['variants'], $font_item['subsets'], $font_item['category'] ) ) {
$fonts[ sanitize_text_field( $font_item['family'] ) ] = array(
'styles' => sanitize_text_field( implode( ',', $font_item['variants'] ) ),
'character_set' => sanitize_text_field( implode( ',', $font_item['subsets'] ) ),
'type' => sanitize_text_field( $font_item['category'] ),
if ( ! function_exists( 'et_core_get_saved_google_fonts' ) ) :
* Get saved google fonts list.
* @return array Associative array list of google fonts.
function et_core_get_saved_google_fonts() {
static $saved_google_fonts;
if ( ! is_null( $saved_google_fonts ) ) {
return $saved_google_fonts;
$json_file = ET_CORE_PATH . 'json-data/google-fonts.json';
if ( ! et_()->WPFS()->is_readable( $json_file ) ) {
$saved_google_fonts = et_core_parse_google_fonts_json( et_()->WPFS()->get_contents( $json_file ) );
return $saved_google_fonts;
if ( ! function_exists( 'et_core_get_websafe_fonts' ) ) :
* Get websafe fonts list.
* @return array Associative array list of websafe fonts.
function et_core_get_websafe_fonts() {
'styles' => '300italic,400italic,600italic,700italic,800italic,400,300,600,700,800',
'character_set' => 'cyrillic,greek,latin',
'Times New Roman' => array(
'styles' => '300italic,400italic,600italic,700italic,800italic,400,300,600,700,800',
'character_set' => 'arabic,cyrillic,greek,hebrew,latin',
'styles' => '300italic,400italic,600italic,700italic,800italic,400,300,600,700,800',
'character_set' => 'arabic,cyrillic,greek,hebrew,latin',
'styles' => '300italic,400italic,600italic,700italic,800italic,400,300,600,700,800',
'character_set' => 'cyrillic,latin',
'add_ms_version' => true,
'styles' => '300italic,400italic,600italic,700italic,800italic,400,300,600,700,800',
'character_set' => 'cyrillic,latin',
foreach ( array_keys( $websafe_fonts ) as $font_name ) {
$websafe_fonts[ $font_name ]['standard'] = true;
return apply_filters( 'et_websafe_fonts', $websafe_fonts );
if ( ! function_exists( 'et_maybe_update_hosting_card_status' ) ) :
* Divi Hosting Card :: Update dismiss status via ET API
function et_maybe_update_hosting_card_status() {
$et_account = et_core_get_et_account();
$et_username = et_()->array_get( $et_account, 'et_username', '' );
$et_api_key = et_()->array_get( $et_account, 'et_api_key', '' );
// Exit if ET Username and/or ET API Key is not found
if ( '' === $et_username || '' === $et_api_key ) {
// Remove any WP Cron for Updating Hosting Card Status
wp_unschedule_hook( 'et_maybe_update_hosting_card_status_cron' );
// Prepare settings for API request
'action' => 'disable_hosting_card',
'username' => $et_username,
'api_key' => $et_api_key,
'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
$request = wp_remote_post( 'https://www.elegantthemes.com/api/api.php', $options );
$request_response_code = wp_remote_retrieve_response_code( $request );
$response_body = wp_remote_retrieve_body( $request );
$response = (array) json_decode( $response_body );
// API request has been updated successfully and the User has already disabled the card, or,
// when API request was successful and returns error message
if ( 'disabled' === et_()->array_get( $response, 'status' ) || '' !== et_()->array_get( $response, 'error', '' ) ) {
// Remove any WP Cron for Updating Hosting Card Status
wp_unschedule_hook( 'et_maybe_update_hosting_card_status_cron' );
// Fail-safe :: Schedule WP Cron to try again
// Once something were wrong in API request, or, response has error code
if ( is_wp_error( $request ) || 200 !== $request_response_code ) {
// First API request has failed, which were done already in above, second request
// (via cron) will be made in a minute, then third (via cron) and future (via cron)
// call will be per hour. Once API request is successful, cron will be removed
$timestamp = time() + 1 * MINUTE_IN_SECONDS;
if ( ! wp_next_scheduled( 'et_maybe_update_hosting_card_status_cron' ) ) {
wp_schedule_event( $timestamp, 'hourly', 'et_maybe_update_hosting_card_status_cron' );
// Action for WP Cron: Disable Hosting Card status via ET API
add_action( 'et_maybe_update_hosting_card_status_cron', 'et_maybe_update_hosting_card_status' );