true,
			'context'             => 'epanel',
			'name'                => 'save',
			'nonce'               => wp_create_nonce( 'et_core_portability_export' ),
		);
		$epanel_save_url = add_query_arg( $args, admin_url() );
		wp_localize_script(
			'epanel_functions_init',
			'ePanelSettings',
			[
				'clearpath'       => get_template_directory_uri() . '/epanel/images/empty.png',
				'currentTheme'    => et_core_get_theme_info( 'Name' ),
				'epanel_nonce'    => wp_create_nonce( 'epanel_nonce' ),
				'help_label'      => esc_html__( 'Help', $themename ), // phpcs:disable WordPress.WP.I18n.NonSingularStringLiteralDomain -- Following the standard.
				'et_core_nonces'  => et_core_get_nonces(),
				'epanel_save_url' => $epanel_save_url,
				'allowedCaps'     => array(
					'portability' => et_pb_is_allowed( 'portability' ) ? et_pb_is_allowed( 'et_code_snippets_portability' ) : false,
					'addLibrary'  => et_pb_is_allowed( 'divi_library' ) ? et_pb_is_allowed( 'add_library' ) : false,
					'saveLibrary' => et_pb_is_allowed( 'divi_library' ) ? et_pb_is_allowed( 'save_library' ) : false,
				),
				'i18n'            => [
					// phpcs:disable WordPress.WP.I18n.NonSingularStringLiteralDomain -- Following the standard.
					'Code Snippet' => esc_html__( 'Code Snippet', $themename ),
					'Theme Option' => esc_html__( 'Theme Option', $themename ),
					// phpcs:enable WordPress.WP.I18n.NonSingularStringLiteralDomain
				],
			]
		);
		// Use WP 4.9 CodeMirror Editor for some fields
		if ( function_exists( 'wp_enqueue_code_editor' ) ) {
			wp_enqueue_code_editor(
				array(
					'type' => 'text/css',
				)
			);
			// Required for Javascript mode
			wp_enqueue_script( 'jshint' );
			wp_enqueue_script( 'htmlhint' );
		}
		et_builder_load_library();
		ET_Cloud_App::load_js();
	}
}
/* --------------------------------------------- */
/* Enabling CSSlint for codemirror */
if ( ! function_exists( 'et_epanel_enable_css_lint' ) ) {
	function et_epanel_enable_css_lint( $settings ){
		$modes = array( 'text/css', 'css', 'text/x-scss', 'text/x-less', 'text/x-sass' );
		if ( in_array( $settings['codemirror']['mode'], $modes, true ) ) {
			$settings['codemirror']['lint'] = true;
			$settings['codemirror']['gutters'] = array( 'CodeMirror-lint-markers' );
		}
		return $settings;
	}
	add_filter( 'wp_code_editor_settings', 'et_epanel_enable_css_lint' );
}
/* Adds additional ePanel css */
if ( ! function_exists( 'et_epanel_css_admin' ) ) {
	function et_epanel_css_admin() {
		?>
		
		
		
	id );
		if ( ! wp_style_is( 'et-core-admin', 'enqueued' ) ) {
			wp_enqueue_style( 'et-core-admin-epanel', get_template_directory_uri() . '/core/admin/css/core.css', array(), et_get_theme_version() );
		}
		wp_enqueue_style( 'epanel-style', get_template_directory_uri() . '/epanel/css/panel.css', array(), et_get_theme_version() );
		if ( wp_style_is( 'activecampaign-subscription-forms', 'enqueued' ) ) {
			// activecampaign-subscription-forms style breaks the panel.
			wp_dequeue_style( 'activecampaign-subscription-forms' );
		}
		// ePanel on theme others than Divi might want to add specific styling
		if ( ! apply_filters( 'et_epanel_is_divi', $is_divi ) ) {
			wp_enqueue_style( 'epanel-theme-style', apply_filters( 'et_epanel_style_url', get_template_directory_uri() . '/style-epanel.css'), array( 'epanel-style' ), et_get_theme_version() );
		}
	}
}
if ( ! function_exists( 'et_epanel_hook_scripts' ) ) {
	function et_epanel_hook_scripts() {
		add_action( 'admin_enqueue_scripts', 'et_epanel_admin_scripts' );
	}
}
/* --------------------------------------------- */
/* Save/Reset actions | Adds theme options to WP-Admin menu */
add_action( 'admin_menu', 'et_add_epanel' );
function et_add_epanel() {
	global $themename, $shortname, $options;
	$epanel = basename( __FILE__ );
	if ( isset( $_GET['page'] ) && $_GET['page'] === $epanel && isset( $_POST['action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification -- logic for nonce checks are following
		if (
			( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'epanel_nonce' ) )
			||
			( 'reset' === $_POST['action'] && isset( $_POST['_wpnonce_reset'] ) && wp_verify_nonce( $_POST['_wpnonce_reset'], 'et-nojs-reset_epanel' ) )
		) {
			if ( ! isset( $GLOBALS['et_core_updates'] ) ) {
				et_register_updates_component();
			}
			epanel_save_data( 'js_disabled' ); //saves data when javascript is disabled
		}
	}
	$core_page = add_theme_page( $themename . ' ' . esc_html__( 'Options', $themename ), $themename . ' ' . esc_html__( 'Theme Options', $themename ), 'edit_theme_options', basename( __FILE__ ), 'et_build_epanel' );
	add_action( "admin_print_scripts-{$core_page}", 'et_epanel_admin_js' );
	add_action( "admin_head-{$core_page}", 'et_epanel_css_admin' );
	add_action( "load-{$core_page}", 'et_epanel_hook_scripts' );
}
/* --------------------------------------------- */
/* Displays ePanel */
if ( ! function_exists( 'et_build_epanel' ) ) {
	function et_build_epanel() {
		global $themename, $shortname, $options, $et_disabled_jquery, $epanelMainTabs;
		// load theme settings array
		et_load_core_options();
		$tabs              = array();
		$default_tab_names = array(
			'ad'           => _x( 'Ads', 'site ads placement areas', $themename ),
			'colorization' => _x( 'Colorization', 'site color scheme', $themename ),
			'general'      => _x( 'General', 'general options', $themename ),
			'integration'  => _x( 'Integration', 'integrate third-party code', $themename ),
			'layout'       => _x( 'Layout', 'page/post', $themename ),
			'navigation'   => _x( 'Navigation', 'navigation menu', $themename ),
			'seo'          => _x( 'SEO', 'search engine optimization', $themename ),
			'support'      => _x( 'Support', 'documentation links', $themename ),
			'updates'      => _x( 'Updates', 'theme updates', $themename ),
		);
		/**
		 * Filters the data used to construct ePanel's layout.
		 *
		 * @since 3.2.1
		 *
		 * @param array $options
		 */
		$options = apply_filters( 'et_epanel_layout_data', $options );
		/**
		 * Filters the slugs/ids for ePanel's tabs.
		 *
		 * @deprecated
		 *
		 * @since 1.0
		 * @since 3.2.1 Deprecated
		 *
		 * @param string[] $tab_slugs
		 */
		$epanelMainTabs = apply_filters( 'epanel_page_maintabs', $epanelMainTabs );
		foreach( $epanelMainTabs as $tab_slug ) {
			if ( isset( $default_tab_names[ $tab_slug ] ) ) {
				$tabs[ $tab_slug ] = $default_tab_names[ $tab_slug ];
			}
		}
		/**
		 * Filters ePanel's localized tab names.
		 *
		 * @since 3.2.1
		 *
		 * @param string[] $tabs {
		 *
		 *     @type string $tab_slug Localized tab name.
		 *     ...
		 * }
		 */
		$tabs = apply_filters( 'et_epanel_tab_names', $tabs );
		et_core_nonce_verified_previously();
		if ( isset($_GET['saved']) ) {
			if ( $_GET['saved'] ) echo '
' . esc_html( $themename ) . ' ' . esc_html__( 'settings saved.', $themename ) . '
 ';
		}
		if ( isset($_GET['reset']) ) {
			if ( $_GET['reset'] ) echo '' . esc_html( $themename ) . ' ' . esc_html__( 'settings reset.', $themename ) . '
 ';
		}
	?>
		 
		
		
		
	` in custom CSS would be encoded to `>`) so we have to disable kses filtering
				// while saving epanel options.
				$skip_kses = ! current_user_can( 'unfiltered_html' );
				if ( $skip_kses ) {
					kses_remove_filters();
				}
				$shortname .= 'save_epanel_temp' === $_POST['action'] ? '_' . get_current_user_id() : '';
				foreach ( $options as $value ) {
					$et_option_name   = $et_option_new_value = false;
					$is_builder_field = isset( $value['is_builder_field'] ) && $value['is_builder_field'];
					if ( isset( $value['id'] ) ) {
						$et_option_name = $value['id'];
						if ( isset( $_POST[ $value['id'] ] ) || 'checkbox_list' === $value['type'] ) {
							if ( in_array( $value['type'], array( 'text', 'textlimit', 'password' ) ) ) {
								if( 'password' === $value['type'] && _et_epanel_password_mask() === $_POST[$et_option_name] ) {
									// The password was not modified so no need to update it
									continue;
								}
								if ( isset( $value['validation_type'] ) ) {
									// saves the value as integer
									if ( 'number' === $value['validation_type'] ) {
										$et_option_new_value = intval( stripslashes( $_POST[$value['id']] ) );
									}
									// makes sure the option is a url
									if ( 'url' === $value['validation_type'] ) {
										$et_option_new_value = esc_url_raw( stripslashes( $_POST[ $value['id'] ] ) );
									}
									// option is a date format
									if ( 'date_format' === $value['validation_type'] ) {
										$et_option_new_value = sanitize_option( 'date_format', $_POST[ $value['id'] ] );
									}
									/*
									 * html is not allowed
									 * wp_strip_all_tags can't be used here, because it returns trimmed text, some options need spaces ( e.g 'character to separate BlogName and Post title' option )
									 */
									if ( 'nohtml' === $value['validation_type'] ) {
										$et_option_new_value = stripslashes( wp_filter_nohtml_kses( $_POST[$value['id']] ) );
									}
									if ( 'apikey' === $value['validation_type'] ) {
										$et_option_new_value = stripslashes( sanitize_text_field( $_POST[ $value['id'] ]  ) );
									}
								} else {
									// use html allowed for posts if the validation type isn't provided
									$et_option_new_value = wp_kses_post( stripslashes( $_POST[ $value['id'] ] ) );
								}
							} elseif ( 'select' === $value['type'] ) {
								// select boxes that list pages / categories should save page/category ID ( as integer )
								if ( isset( $value['et_array_for'] ) && in_array( $value['et_array_for'], array( 'pages', 'categories' ) ) ) {
									$et_option_new_value = intval( stripslashes( $_POST[$value['id']] ) );
								} else { // html is not allowed in select boxes
									$et_option_new_value = sanitize_text_field( stripslashes( $_POST[$value['id']] ) );
								}
							} elseif ( in_array( $value['type'], array( 'checkbox', 'checkbox2' ) ) ) {
								// saves 'on' value to the database, if the option is enabled
								$et_option_new_value = 'on';
							} elseif ( 'upload' === $value['type'] ) {
								// makes sure the option is a url
								$et_option_new_value = esc_url_raw( stripslashes( $_POST[ $value['id'] ] ) );
							} elseif ( in_array( $value['type'], array( 'textcolorpopup', 'et_color_palette' ) ) ) {
								// the color value
								$et_option_new_value = sanitize_text_field( stripslashes( $_POST[$value['id']] ) );
							} elseif ( 'textarea' === $value['type'] ) {
								if ( isset( $value['validation_type'] ) ) {
									// html is not allowed
									if ( 'nohtml' === $value['validation_type'] ) {
										if ( $value['id'] === ( $shortname . '_custom_css' ) ) {
											// save custom css into wp custom css option if supported
											// fallback to legacy system otherwise
											if ( function_exists( 'wp_update_custom_css_post' ) ) {
												// Data sent via AJAX is automatically escaped by browser, thus it needs
												// to be unslashed befor being saved into custom CSS post
												wp_update_custom_css_post( wp_unslash( wp_strip_all_tags( $_POST[ $value['id'] ] ) ) );
											} else {
												// don't strip slashes from custom css, it should be possible to use \ for icon fonts
												$et_option_new_value = wp_strip_all_tags( $_POST[ $value['id'] ] );
											}
										} else {
											$et_option_new_value = wp_strip_all_tags( stripslashes( $_POST[ $value['id'] ] ) );
										}
									}
								} else {
									if ( current_user_can( 'edit_theme_options' ) ) {
										$et_option_new_value = stripslashes( $_POST[ $value['id'] ] );
									} else {
										$et_option_new_value = stripslashes( wp_filter_post_kses( addslashes( $_POST[ $value['id'] ] ) ) ); // wp_filter_post_kses() expects slashed value
									}
								}
							} elseif ( 'checkboxes' === $value['type'] ) {
								if ( isset( $value['value_sanitize_function'] ) && 'sanitize_text_field' === $value['value_sanitize_function'] ) {
									// strings
									$et_option_new_value = array_map( 'sanitize_text_field', stripslashes_deep( $_POST[ $value['id'] ] ) );
								} else {
									// saves categories / pages IDs
									$et_option_new_value = array_map( 'intval', stripslashes_deep( $_POST[ $value['id'] ] ) );
								}
							} elseif ( 'different_checkboxes' === $value['type'] ) {
								// saves 'author/date/categories/comments' options
								$et_option_new_value = array_map( 'sanitize_text_field', array_map( 'wp_strip_all_tags', stripslashes_deep( $_POST[$value['id']] ) ) );
							} elseif ( 'checkbox_list' === $value['type'] ) {
								// saves array of: 'value' => 'on' or 'off'
								$raw_checked_options = isset( $_POST[ $value['id'] ] ) ? stripslashes_deep( $_POST[ $value['id'] ] ) : array();
								$checkbox_options    = $value['options'];
								if ( is_callable( $checkbox_options ) ) {
									// @phpcs:ignore Generic.PHP.ForbiddenFunctions.Found
									$checkbox_options = call_user_func( $checkbox_options );
								}
								$allowed_values = array_values( $checkbox_options );
								if ( isset( $value['et_save_values'] ) && $value['et_save_values'] ) {
									$allowed_values = array_keys( $checkbox_options );
								}
								$et_option_new_value = array();
								foreach ( $allowed_values as $allowed_value ) {
									$et_option_new_value[ $allowed_value ] = in_array( $allowed_value, $raw_checked_options ) ? 'on' : 'off';
								}
							}
						} else {
							if ( in_array( $value['type'], array( 'checkbox', 'checkbox2' ) ) ) {
								$et_option_new_value = $is_builder_field ? 'off' : 'false';
							} else if ( 'different_checkboxes' === $value['type'] ) {
								$et_option_new_value = array();
							} else {
								et_delete_option( $value['id'] );
							}
						}
						if ( false !== $et_option_name && false !== $et_option_new_value ) {
							$is_new_global_setting    = false;
							$global_setting_main_name = $global_setting_sub_name = '';
							if ( isset( $value['is_global'] ) && $value['is_global'] ) {
								$is_new_global_setting    = true;
								$global_setting_main_name = isset( $value['main_setting_name'] ) ? sanitize_text_field( $value['main_setting_name'] ) : '';
								$global_setting_sub_name  = isset( $value['sub_setting_name'] ) ? sanitize_text_field( $value['sub_setting_name'] ) : '';
							}
							/**
							 * Fires before updating an ePanel option in the database.
							 *
							 * @param string $et_option_name      The option name/id.
							 * @param string $et_new_option_value The new option value.
							 */
							do_action( 'et_epanel_update_option', $et_option_name, $et_option_new_value );
							if ( 'et_automatic_updates_options' === $global_setting_main_name && 'save_epanel_temp' !== $_POST['action'] ) {
								$updates_options[ $global_setting_sub_name ] = $et_option_new_value;
								update_site_option( $global_setting_main_name, $updates_options );
							} else {
								et_update_option( $et_option_name, $et_option_new_value, $is_new_global_setting, $global_setting_main_name, $global_setting_sub_name );
							}
						}
					}
				}
				if ( $skip_kses ) {
					// Enable kses filters again
					kses_init_filters();
				}
				$redirect_url = add_query_arg( 'saved', 'true', $redirect_url );
				if ( 'js_disabled' === $source ) {
					header( "Location: " . $redirect_url );
				}
				die('1');
			} else if ( 'reset' === $_POST['action'] ) {
				check_admin_referer( 'et-nojs-reset_epanel', '_wpnonce_reset' );
				foreach ($options as $value) {
					if ( isset($value['id']) ) {
						et_delete_option( $value['id'] );
						if ( isset( $value['std'] ) ) {
							et_update_option( $value['id'], $value['std'] );
						}
					}
				}
				// Reset Google Maps API Key
				update_option( 'et_google_api_settings', array() );
				// Resets WordPress custom CSS which is synced with Options Custom CSS as of WP 4.7
				if ( function_exists( 'wp_get_custom_css' ) ) {
					wp_update_custom_css_post('');
					set_theme_mod( 'et_pb_css_synced', 'no' );
				}
				$redirect_url = add_query_arg( 'reset', 'true', $redirect_url );
				header( "Location: " . $redirect_url );
				die('1');
			}
		}
	}
}
function et_epanel_media_upload_scripts() {
	global $themename;
	wp_enqueue_script( 'et_epanel_uploader', get_template_directory_uri().'/epanel/js/custom_uploader.js', array('jquery', 'media-upload', 'thickbox'), et_get_theme_version() );
	wp_enqueue_media();
	wp_localize_script( 'et_epanel_uploader', 'epanel_uploader', array(
		'media_window_title' => esc_html__( 'Choose an Image', $themename ),
	) );
}
function et_epanel_media_upload_styles() {
	wp_enqueue_style( 'thickbox' );
}
global $pagenow;
if ( 'themes.php' === $pagenow && isset( $_GET['page'] ) && ( $_GET['page'] === basename( __FILE__ ) ) ) {
	add_action( 'admin_print_scripts', 'et_epanel_media_upload_scripts' );
	add_action( 'admin_print_styles', 'et_epanel_media_upload_styles' );
}
/**
 * Register ePanel portability.
 *
 * @since To define
 *
 * @return bool Always return true.
 */
function et_epanel_register_portability() {
	global $shortname, $themename, $options;
	// Make sure the Portability is loaded.
	et_core_load_component( 'portability' );
	// Load ePanel options.
	et_load_core_options();
	// Include only ePanel options.
	$include = array();
	foreach ( $options as $option ) {
		if ( isset( $option['id'] ) ) {
			$include[ $option['id'] ] = true;
		}
	}
	// reason: explanation Follwoing the standard and  Not processing form data.
	// phpcs:disable.
	// WordPress.WP.I18n.NonSingularStringLiteralDomain.
	// WordPress.Security.NonceVerification.Recommended.
	// Register the portability.
	et_core_portability_register(
		'epanel',
		array(
			'title'   => esc_html__( 'Import & Export Theme Options', $themename ),
			'name'    => sprintf(
				esc_html__( '%s Theme Options', $themename ),
				$themename
			),
			'type'    => 'options',
			'target'  => "et_{$shortname}",
			'include' => $include,
			'view'    => ( isset( $_GET['page'] ) && "et_{$shortname}_options" === $_GET['page'] ),
		)
	);
	// Register the portability.
	et_core_portability_register(
		'epanel_temp',
		array(
			'title'   => esc_html__( 'Import & Export Theme Options', $themename ),
			'name'    => sprintf(
				esc_html__( '%s Theme Options', $themename ),
				$themename
			),
			'type'    => 'options',
			'target'  => "et_{$shortname}_" . get_current_user_id(),
			'include' => $include,
			'view'    => ( isset( $_GET['page'] ) && "et_{$shortname}_options" === $_GET['page'] ),
		)
	);
	// phpcs:enable
}
add_action( 'admin_init', 'et_epanel_register_portability' );
/**
 * Flush rewrite rules when a change in CPTs with builder enabled is detected.
 *
 * @since ??
 *
 * @param string $et_option_name
 * @param mixed $et_option_new_value
 */
function et_epanel_flush_rewrite_rules_on_post_type_integration( $et_option_name, $et_option_new_value ) {
    if ( 'et_pb_post_type_integration' !== $et_option_name ) {
        return;
    }
    $old = et_get_option( $et_option_name, array() );
    if ( $et_option_new_value !== $old ) {
        flush_rewrite_rules();
    }
}
add_action( 'et_epanel_update_option', 'et_epanel_flush_rewrite_rules_on_post_type_integration', 10, 2 );
if ( ! function_exists( 'et_theme_options_library_admin_enqueue_scripts' ) ) {
	/**
	 * Enqueue Theme Options library scripts on Theme options page.
	 *
	 * @since ??
	 *
	 * @param string $hook_suffix Page hook suffix.
	 * @return void
	 */
	function et_theme_options_library_admin_enqueue_scripts( $hook_suffix ) {
		global $shortname;
		$is_options_page = 'toplevel_page_et_' . $shortname . '_options' === $hook_suffix;
		// Only used on theme options page.
		if ( ! $is_options_page ) {
			return;
		}
		if ( ! class_exists( 'ET_Theme_Options_Library_App' ) ) {
			require_once ET_EPANEL_DIR . '/theme-options-library/theme-options-library-app.php';
		}
		ET_Theme_Options_Library_App::load_js();
	}
	add_action( 'admin_enqueue_scripts', 'et_theme_options_library_admin_enqueue_scripts' );
}