<?php
/*
Plugin Name: Safelayout Elegant Icons
Plugin URI: https://safelayout.com
Description: Beautiful SVG icons.
Requires at least: 6.5
Requires PHP: 7.0
Version: 1.4.6
Author: Safelayout
Text Domain: safelayout-elegant-icons
Domain Path: /languages
License: GPLv2
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Elementor tested up to: 4.1.1
Elementor Pro tested up to: 4.1.0
*/

defined( 'ABSPATH' ) || exit; // Exit if accessed directly.

if ( ! class_exists( 'Safelayout_elegant_icons' ) && ! class_exists( 'Safelayout_elegant_icons_pro' ) ) {

	// Define the constant used in this plugin
	define( 'SAFELAYOUT_ICONS_VERSION', '1.4.6');
	define( 'SAFELAYOUT_ICONS_PATH', plugin_dir_path( __FILE__ ) );
	define( 'SAFELAYOUT_ICONS_URL', plugin_dir_url( __FILE__ ) );
	define( 'SAFELAYOUT_ICONS_NAME', plugin_basename( __FILE__ ) );

	class Safelayout_elegant_icons {
		protected $options_page_hook = null;
		protected $icons_list_key = false;
		protected $social_enqueue_key = false;

		public function __construct() {
			add_action( 'init', array( $this, 'load_textdomain' ) );
			add_action( 'activated_plugin', array( $this, 'activated_plugin' ) );
			add_filter( 'plugin_action_links_' . SAFELAYOUT_ICONS_NAME, array( $this, 'plugin_action_links' ) );
			add_filter( 'wp_kses_allowed_html', array( $this, 'allowed_html' ), 99, 2 );
			add_filter( 'safecss_filter_attr_allow_css', array( $this, 'attr_allow_css' ), 99, 2 );
			add_filter( 'safe_style_css', array( $this, 'allowed_css' ), 10, 1 );

			add_action( 'init', array( $this, 'register_block' ) );
			add_action( 'init', array( $this, 'register_patterns' ), 8 );
			add_action( 'init', array( $this, 'shortcodes_init' ) );
			add_filter( 'render_block_safelayout/safelayout-social-share', array( $this, 'render_share_block' ), 10, 3 );
			add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
			add_action( 'enqueue_block_editor_assets', array( $this, 'load_packs' ), 1 );
			add_action( 'enqueue_block_editor_assets', array( $this, 'set_translations' ), PHP_INT_MAX );
			add_filter( 'block_categories_all', array( $this, 'safelayout_blocks_categories_add' ), 10, 2 );

			add_filter( 'tiny_mce_before_init', array( $this, 'new_mce_options' ), PHP_INT_MAX );
			add_filter( 'no_texturize_tags', array( $this, 'mce_no_texturize_tags' ) );
			add_filter( 'the_content', array( $this, 'mce_the_content' ), PHP_INT_MAX );
			add_filter( 'wp_enqueue_scripts', array( $this, 'enqueue_mce' ), PHP_INT_MAX );
			add_filter( 'mce_external_plugins', array( $this, 'mce_plugins' ), PHP_INT_MAX );
			add_filter( 'mce_buttons', array( $this, 'mce_buttons' ), PHP_INT_MAX );

			add_action( 'elementor/widgets/register', array( $this, 'register_widgets' ) );
			add_action( 'elementor/controls/register', array( $this, 'register_controls' ) );
			add_action( 'elementor/editor/before_enqueue_scripts', array( $this, 'elementor_enqueue' ) );
			add_action( 'wp_enqueue_scripts', array( $this, 'register_elementor_front' ) );
			add_action( 'wp_enqueue_scripts', array( $this, 'deregister_elementor_script' ), PHP_INT_MAX );
			add_action( 'elementor/preview/enqueue_styles', array( $this, 'elementor_preview_enqueue' ) );
			add_action( 'elementor/editor/after_enqueue_scripts', array( $this, 'after_elementor_enqueue' ) );
			add_action( 'elementor/editor/footer', array( $this, 'print_template_views' ) );

			add_action( 'load-nav-menus.php', array( $this, 'nav_menus_enqueue' ) );
			add_action( 'admin_footer-nav-menus.php', array( $this, 'nav_menus_page_footer' ) );
			add_action( 'wp_nav_menu_item_custom_fields', array( $this, 'nav_menu_add_fields' ), 10, 4 );
			add_action( 'wp_update_nav_menu_item', array( $this, 'nav_menu_update' ), 10, 2 );
			add_filter( 'wp_nav_menu_args', array( $this, 'add_menu_item_filter' ) );
			add_filter( 'wp_nav_menu', array( $this, 'remove_menu_item_filter' ) );

			add_filter( 'litespeed_optimize_css_excludes', array( $this, 'litespeed_css_excludes' ) );
			add_filter( 'litespeed_optimize_js_excludes', array( $this, 'litespeed_js_excludes' ) );
			add_filter( 'litespeed_optm_js_defer_exc', array( $this, 'litespeed_js_excludes' ) );
			add_filter( 'litespeed_optm_gm_js_exc', array( $this, 'litespeed_js_excludes' ) );
			add_filter( 'sgo_js_minify_exclude', array( $this, 'sgo_javascript_exclude' ) );
			add_filter( 'sgo_js_async_exclude', array( $this, 'sgo_javascript_exclude' ) );
			add_filter( 'sgo_javascript_combine_exclude', array( $this, 'sgo_javascript_exclude' ) );
			add_filter( 'sgo_css_combine_exclude', array( $this, 'sgo_css_exclude' ) );
			add_filter( 'sgo_css_minify_exclude', array( $this, 'sgo_css_exclude' ) );
			add_filter( 'wp-optimize-minify-default-exclusions', array( $this, 'wp_optimize_javascript_exclude' ) );
			add_filter( 'autoptimize_filter_js_exclude', array( $this, 'autoptimize_javascript_exclude' ) );
			add_filter( 'autoptimize_filter_css_exclude', array( $this, 'autoptimize_css_exclude' ) );
			add_filter( 'get_rocket_option_remove_unused_css_safelist', array( $this, 'rocket_remove_unused_css_safelist' ) );
			add_filter( 'get_rocket_option_exclude_js', array( $this, 'rocket_exclude_js' ) );
			add_filter( 'get_rocket_option_delay_js_exclusions', array( $this, 'rocket_exclude_js' ) );
			add_filter( 'get_rocket_option_exclude_defer_js', array( $this, 'rocket_exclude_js' ) );

			if ( is_admin() ) {
				add_action( 'admin_menu', array( $this, 'admin_menu' ) );
				add_action( 'admin_init', array( $this, 'add_settings_fields' ) );
				add_action( 'admin_init', array( $this, 'add_rate_reminder' ) );
				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts_for_feedback' ) );
				add_action( 'admin_footer-plugins.php', array( $this, 'add_code_for_feedback' ) );
				add_action( 'wp_ajax_slei_icons_feedback', array( $this, 'icons_feedback_ajax_handler' ) );
				add_filter( 'http_request_host_is_external', array( $this, 'allow_icons_feedback_host' ), 10, 3 );
				add_filter( 'register_block_type_args', array( $this, 'add_icon_blocks_to_core_blocks' ), 10, 2 );
			}
		}

		// exclude css WP Rocket
		public function rocket_remove_unused_css_safelist( $excluded ) {
			$list = [
				'safelayout-menu-css-(.*)',
				'safelayout-icon-text-css-(.*)',
				'safelayout-icon-box-block-(.*)-css',
				'safelayout-icon-box-block-effect-(.*)',
				'safelayout-elegant-icons/build/icon/style-index.css',
				'safelayout-elegant-icons/build/icon-box/style-index.css',
			];
			foreach( $list as $li ) {
				if( ! in_array( $li, $excluded ) ) {
					array_push( $excluded, $li );
				}
			}
			return $excluded;
		}

		// exclude js WP Rocket
		public function rocket_exclude_js( $excluded ) {
			$list = [ 'safelayout-share-script.js', ];
			foreach( $list as $li ) {
				if( ! in_array( $li, $excluded ) ) {
					array_push( $excluded, $li );
				}
			}
			return $excluded;
		}

		// exclude js autoptimize
		public function autoptimize_javascript_exclude( $excluded ) {
			if( is_string( $excluded ) ) {
				$excluded .= ', safelayout-share-script.js';
			}
			return $excluded;
		}

		// exclude js autoptimize
		public function autoptimize_css_exclude( $excluded ) {
			if( is_string( $excluded ) ) {
				$excluded .= ', safelayout-elegant-icons/build/icon/style-index.css';
				$excluded .= ', safelayout-elegant-icons/build/icon-box/style-index.css';
			}
			return $excluded;
		}

		// exclude js wp optimize
		public function wp_optimize_javascript_exclude( $excluded ) {
			$excluded[] = 'safelayout-share-script.js';
			$excluded[] = 'safelayout-elegant-icons/build/icon/style-index.css';
			$excluded[] = 'safelayout-elegant-icons/build/icon-box/style-index.css';
			return $excluded;
		}

		// exclude css, LiteSpeed Cache
		public function litespeed_css_excludes( $excludes ) {
			$excludes[] = 'safelayout-elegant-icons/build/icon/style-index.css';
			$excludes[] = 'safelayout-elegant-icons/build/icon-box/style-index.css';
			return $excludes;
		}

		// exclude js, LiteSpeed Cache
		public function litespeed_js_excludes( $excludes ) {
			$excludes[] = 'safelayout-share-script.js';
			return $excludes;
		}

		// exclude js, Siteground SG Optimize
		public function sgo_javascript_exclude( $excluded ) {
			$excluded[] = 'safelayout-safelayout-social-share-view-script';
			return $excluded;
		}

		// exclude css, Siteground SG Optimize
		public function sgo_css_exclude( $excluded ) {
			$excluded[] = 'safelayout-safelayout-icon-list-style';
			$excluded[] = 'safelayout-safelayout-social-profiles-style';
			$excluded[] = 'safelayout-safelayout-social-share-style';
			$excluded[] = 'safelayout-safelayout-icon-box-style';
			$excluded[] = 'safelayout-safelayout-icon-style';
			return $excluded;
		}

		// set social share hooks
		public function pre_get_posts( $query ) {
			if ( $query->is_main_query() ) {
				$options = $this->get_social_share_options();
				if ( '' != $options['enable_social'] && ! ( wp_is_mobile() && $options['hide_on_mobile'] ) ) {
					add_action( 'the_content', array( $this, 'add_social' ) );
					add_action( 'the_excerpt', array( $this, 'add_social' ) );
					add_action( 'woocommerce_share', array( $this, 'woocommerce_share' ) );
					add_action( 'woocommerce_after_single_product', array( $this, 'woocommerce_after_single_product' ) );
				}
			}
		}

		// show social share after product summary
		public function woocommerce_share() {
			$this->show_social_woocommerce( 'summary' );
		}

		// show social share after product content
		public function woocommerce_after_single_product() {
			$this->show_social_woocommerce( 'content' );
		}

		// echo social share for woocommerce product
		public function show_social_woocommerce( $arg ) {
			$options = $this->get_social_share_options();
			if ( $options['display_on_woo'] && $options['display_on_woo_place'] == $arg ) {
				echo do_shortcode( $this->get_social_share_code() );
				if ( ! $this->social_enqueue_key ) {
					$this->social_enqueue_key = true;
					$this->enqueue_social_style();
				}
			}
		}

		// get social share options
		public function get_social_share_options() {
			$default = array(
				'version'					=> SAFELAYOUT_ICONS_VERSION,
				'enable_social'				=> '',
				's_title'					=> '',
				's_attributes'				=> htmlspecialchars_decode( '%7B%22blockId%22%3A%2255410f6a-76f5-354d-b8cd-8cdedb735330%22%2C%22slbbShowText%22%3Afalse%2C%22slbbFont%22%3A%22Default%22%2C%22slbbBold%22%3Afalse%2C%22slbbItalic%22%3Afalse%2C%22slbbUpercase%22%3Afalse%2C%22slbbNewTab%22%3Atrue%2C%22slbbFloat%22%3Afalse%2C%22slbbFloatPos%22%3A%22center%20left%22%2C%22slbbJust%22%3A%22left%22%2C%22slbbOrient%22%3A%22row%22%2C%22slbbWrap%22%3Atrue%2C%22rotateBg%22%3A0%2C%22hasBg%22%3Atrue%2C%22bgShape%22%3A%22rect%22%2C%22bgShapeVal%22%3A%22%22%2C%22size%22%3A%2240px%22%2C%22slbbGap%22%3A20%2C%22hasShadow%22%3Afalse%2C%22shadow%22%3A%22drop-shadow(2px%202px%201px%20%23000)%22%2C%22svgFilter%22%3A%22none%22%2C%22bgStrokeColor%22%3A%22%23000%22%2C%22bgStrokeWidth%22%3A0%2C%22hasBgShadow%22%3Afalse%2C%22bgShadow%22%3A%22drop-shadow(0px%203px%202px%20%23000)%22%2C%22hasBaseShadow%22%3Afalse%2C%22baseShadowWidth%22%3A70%2C%22baseShadowHeight%22%3A12%2C%22baseShadowTop%22%3A96%2C%22padding%22%3A8%2C%22bgRadius%22%3A10%2C%22effect%22%3A%22No%20Effect%22%2C%22slbbAnim%22%3A%22No%20Animation%22%2C%22blockMargin%22%3A%7B%22top%22%3A%2210px%22%2C%22bottom%22%3A%2210px%22%7D%2C%22blockPadding%22%3A%7B%7D%2C%22classes%22%3A%22%22%2C%22slbbPopup%22%3Atrue%2C%22slbbIcons%22%3A%5B%7B%22socialName%22%3A%22Facebook%22%2C%22iconName%22%3A%22705_facebook%22%2C%22paths%22%3A%5B%7B%22d%22%3A%22M12%202C6.5%202%202%206.5%202%2012c0%205%203.7%209.1%208.4%209.9v-7H7.9V12h2.5V9.8c0-2.5%201.5-3.9%203.8-3.9%201.1%200%202.2.2%202.2.2v2.5h-1.3c-1.2%200-1.6.8-1.6%201.6V12h2.8l-.4%202.9h-2.3v7C18.3%2021.1%2022%2017%2022%2012c0-5.5-4.5-10-10-10z%22%7D%5D%2C%22color%22%3A%22%23fff%22%2C%22bgColor%22%3A%22%230866ff%22%2C%22linkUrl%22%3A%22https%3A%2F%2Fwww.facebook.com%2Fsharer%2Fsharer.php%3Fu%3D%5Bslei_social_url%5D%26title%3D%5Bslei_social_title%5D%22%2C%22linkRel%22%3A%22%22%7D%2C%7B%22socialName%22%3A%22X%22%2C%22iconName%22%3A%22705_x%22%2C%22paths%22%3A%5B%7B%22d%22%3A%22M16.613%204.75h2.46l-5.374%206.143L20.021%2019.25h-4.951l-3.876-5.069-4.436%205.069h-2.462l5.749-6.569L3.979%204.75h5.076l3.505%204.634L16.612%204.75Zm-.863%2013.028h1.363L8.314%206.145H6.851l8.899%2011.632Z%22%7D%5D%2C%22color%22%3A%22%23fff%22%2C%22bgColor%22%3A%22%23000%22%2C%22linkUrl%22%3A%22https%3A%2F%2Fx.com%2Fintent%2Ftweet%3Ftext%3D%5Bslei_social_title%5D%20%5Bslei_social_url%5D%22%2C%22linkRel%22%3A%22%22%7D%2C%7B%22socialName%22%3A%22LinkedIn%22%2C%22iconName%22%3A%22705_linkedin%22%2C%22paths%22%3A%5B%7B%22d%22%3A%22M19.379%203.375H4.621C3.933%203.375%203.375%203.933%203.375%204.621v14.758C3.375%2020.067%203.933%2020.625%204.621%2020.625h14.758c.688%200%201.246-.558%201.246-1.246V4.621C20.625%203.933%2020.067%203.375%2019.379%203.375zM8.492%2018.074H5.931v-8.232h2.561V18.074zM7.212%208.717c-.821%200-1.484-.665-1.484-1.483%200-.819.662-1.484%201.484-1.484.818%200%201.483.665%201.483%201.484C8.695%208.053%208.031%208.717%207.212%208.717zM18.075%2018.074h-2.558v-4.003c0-.955-.016-2.183-1.329-2.183-1.331%200-1.534%201.041-1.534%202.114v4.072h-2.556v-8.232h2.452v1.125h.035c.341-.647%201.176-1.329%202.421-1.329%202.59%200%203.07%201.705%203.07%203.921V18.074z%22%7D%5D%2C%22color%22%3A%22%23fff%22%2C%22bgColor%22%3A%22%230d66c2%22%2C%22linkUrl%22%3A%22https%3A%2F%2Fwww.linkedin.com%2FshareArticle%3Fmini%3Dtrue%26url%3D%5Bslei_social_url%5D%26title%3D%5Bslei_social_title%5D%22%2C%22linkRel%22%3A%22%22%7D%5D%2C%22key%22%3A10%7D' ),
				's_code'					=> addslashes( '<div class="safelayout-ei-icon-block safelayout-ei-social-share-block share-in-popup" style="margin-top: 10px; margin-bottom: 10px; display: flex; flex-wrap: wrap; justify-content: left; gap: 20px;"><a href="https://www.facebook.com/sharer/sharer.php?u=[slei_social_url]&amp;title=[slei_social_title]" target="_blank" aria-label="Facebook" title="Facebook" style="height: 40px; width: 40px;"><svg viewBox="0 0 96 96" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><defs></defs><g><rect x="4" y="4" width="88" height="88" rx="8.8" fill="#0866ff" stroke="#000" stroke-width="0"></rect></g></svg><svg viewBox="0 0 96 96" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" style="height: calc(110% - 19px); width: calc(110% - 19px);"><defs></defs><symbol viewBox="0 0 24 24" id="path55410f6a-76f5-354d-b8cd-8cdedb7353300"><path vector-effect="non-scaling-stroke" fill="#fff" stroke="#000" stroke-width="0" d="M12 2C6.5 2 2 6.5 2 12c0 5 3.7 9.1 8.4 9.9v-7H7.9V12h2.5V9.8c0-2.5 1.5-3.9 3.8-3.9 1.1 0 2.2.2 2.2.2v2.5h-1.3c-1.2 0-1.6.8-1.6 1.6V12h2.8l-.4 2.9h-2.3v7C18.3 21.1 22 17 22 12c0-5.5-4.5-10-10-10z"></path></symbol><use href="#path55410f6a-76f5-354d-b8cd-8cdedb7353300"></use></svg></a><a href="https://x.com/intent/tweet?text=[slei_social_title] [slei_social_url]" target="_blank" aria-label="X" title="X" style="height: 40px; width: 40px;"><svg viewBox="0 0 96 96" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><defs></defs><g><rect x="4" y="4" width="88" height="88" rx="8.8" fill="#000" stroke="#000" stroke-width="0"></rect></g></svg><svg viewBox="0 0 96 96" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" style="height: calc(110% - 19px); width: calc(110% - 19px);"><defs></defs><symbol viewBox="0 0 24 24" id="path55410f6a-76f5-354d-b8cd-8cdedb7353301"><path vector-effect="non-scaling-stroke" fill="#fff" stroke="#000" stroke-width="0" d="M16.613 4.75h2.46l-5.374 6.143L20.021 19.25h-4.951l-3.876-5.069-4.436 5.069h-2.462l5.749-6.569L3.979 4.75h5.076l3.505 4.634L16.612 4.75Zm-.863 13.028h1.363L8.314 6.145H6.851l8.899 11.632Z"></path></symbol><use href="#path55410f6a-76f5-354d-b8cd-8cdedb7353301"></use></svg></a><a href="https://www.linkedin.com/shareArticle?mini=true&amp;url=[slei_social_url]&amp;title=[slei_social_title]" target="_blank" aria-label="LinkedIn" title="LinkedIn" style="height: 40px; width: 40px;"><svg viewBox="0 0 96 96" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><defs></defs><g><rect x="4" y="4" width="88" height="88" rx="8.8" fill="#0d66c2" stroke="#000" stroke-width="0"></rect></g></svg><svg viewBox="0 0 96 96" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" style="height: calc(110% - 19px); width: calc(110% - 19px);"><defs></defs><symbol viewBox="0 0 24 24" id="path55410f6a-76f5-354d-b8cd-8cdedb7353302"><path vector-effect="non-scaling-stroke" fill="#fff" stroke="#000" stroke-width="0" d="M19.379 3.375H4.621C3.933 3.375 3.375 3.933 3.375 4.621v14.758C3.375 20.067 3.933 20.625 4.621 20.625h14.758c.688 0 1.246-.558 1.246-1.246V4.621C20.625 3.933 20.067 3.375 19.379 3.375zM8.492 18.074H5.931v-8.232h2.561V18.074zM7.212 8.717c-.821 0-1.484-.665-1.484-1.483 0-.819.662-1.484 1.484-1.484.818 0 1.483.665 1.483 1.484C8.695 8.053 8.031 8.717 7.212 8.717zM18.075 18.074h-2.558v-4.003c0-.955-.016-2.183-1.329-2.183-1.331 0-1.534 1.041-1.534 2.114v4.072h-2.556v-8.232h2.452v1.125h.035c.341-.647 1.176-1.329 2.421-1.329 2.59 0 3.07 1.705 3.07 3.921V18.074z"></path></symbol><use href="#path55410f6a-76f5-354d-b8cd-8cdedb7353302"></use></svg></a></div>' ),
				'hide_on_mobile'			=> false,
				'special_on_mobile'			=> false,
				's_title_mobile'			=> '',
				's_attributes_mobile'		=> htmlspecialchars_decode( '%7B%22blockId%22%3A%22a3305dde-15da-d0dc-f79c-4b70d03c058d%22%2C%22slbbShowText%22%3Afalse%2C%22slbbFont%22%3A%22Default%22%2C%22slbbBold%22%3Afalse%2C%22slbbItalic%22%3Afalse%2C%22slbbUpercase%22%3Afalse%2C%22slbbNewTab%22%3Atrue%2C%22slbbFloat%22%3Afalse%2C%22slbbFloatPos%22%3A%22center%20left%22%2C%22slbbJust%22%3A%22left%22%2C%22slbbOrient%22%3A%22row%22%2C%22slbbWrap%22%3Atrue%2C%22rotateBg%22%3A0%2C%22hasBg%22%3Atrue%2C%22bgShape%22%3A%22rect%22%2C%22bgShapeVal%22%3A%22%22%2C%22size%22%3A%2240px%22%2C%22slbbGap%22%3A20%2C%22hasShadow%22%3Afalse%2C%22shadow%22%3A%22drop-shadow(2px%202px%201px%20%23000)%22%2C%22svgFilter%22%3A%22none%22%2C%22bgStrokeColor%22%3A%22%23000%22%2C%22bgStrokeWidth%22%3A0%2C%22hasBgShadow%22%3Afalse%2C%22bgShadow%22%3A%22drop-shadow(0px%203px%202px%20%23000)%22%2C%22hasBaseShadow%22%3Afalse%2C%22baseShadowWidth%22%3A70%2C%22baseShadowHeight%22%3A12%2C%22baseShadowTop%22%3A96%2C%22padding%22%3A8%2C%22bgRadius%22%3A50%2C%22effect%22%3A%22No%20Effect%22%2C%22slbbAnim%22%3A%22No%20Animation%22%2C%22blockMargin%22%3A%7B%22top%22%3A%2210px%22%2C%22bottom%22%3A%2210px%22%7D%2C%22blockPadding%22%3A%7B%7D%2C%22classes%22%3A%22%22%2C%22slbbPopup%22%3Atrue%2C%22slbbIcons%22%3A%5B%7B%22socialName%22%3A%22Facebook%22%2C%22iconName%22%3A%22705_facebook%22%2C%22paths%22%3A%5B%7B%22d%22%3A%22M12%202C6.5%202%202%206.5%202%2012c0%205%203.7%209.1%208.4%209.9v-7H7.9V12h2.5V9.8c0-2.5%201.5-3.9%203.8-3.9%201.1%200%202.2.2%202.2.2v2.5h-1.3c-1.2%200-1.6.8-1.6%201.6V12h2.8l-.4%202.9h-2.3v7C18.3%2021.1%2022%2017%2022%2012c0-5.5-4.5-10-10-10z%22%7D%5D%2C%22color%22%3A%22%23fff%22%2C%22bgColor%22%3A%22%230866ff%22%2C%22linkUrl%22%3A%22https%3A%2F%2Fwww.facebook.com%2Fsharer%2Fsharer.php%3Fu%3D%5Bslei_social_url%5D%26title%3D%5Bslei_social_title%5D%22%2C%22linkRel%22%3A%22%22%7D%2C%7B%22socialName%22%3A%22X%22%2C%22iconName%22%3A%22705_x%22%2C%22paths%22%3A%5B%7B%22d%22%3A%22M16.613%204.75h2.46l-5.374%206.143L20.021%2019.25h-4.951l-3.876-5.069-4.436%205.069h-2.462l5.749-6.569L3.979%204.75h5.076l3.505%204.634L16.612%204.75Zm-.863%2013.028h1.363L8.314%206.145H6.851l8.899%2011.632Z%22%7D%5D%2C%22color%22%3A%22%23fff%22%2C%22bgColor%22%3A%22%23000%22%2C%22linkUrl%22%3A%22https%3A%2F%2Fx.com%2Fintent%2Ftweet%3Ftext%3D%5Bslei_social_title%5D%20%5Bslei_social_url%5D%22%2C%22linkRel%22%3A%22%22%7D%2C%7B%22socialName%22%3A%22LinkedIn%22%2C%22iconName%22%3A%22705_linkedin%22%2C%22paths%22%3A%5B%7B%22d%22%3A%22M19.379%203.375H4.621C3.933%203.375%203.375%203.933%203.375%204.621v14.758C3.375%2020.067%203.933%2020.625%204.621%2020.625h14.758c.688%200%201.246-.558%201.246-1.246V4.621C20.625%203.933%2020.067%203.375%2019.379%203.375zM8.492%2018.074H5.931v-8.232h2.561V18.074zM7.212%208.717c-.821%200-1.484-.665-1.484-1.483%200-.819.662-1.484%201.484-1.484.818%200%201.483.665%201.483%201.484C8.695%208.053%208.031%208.717%207.212%208.717zM18.075%2018.074h-2.558v-4.003c0-.955-.016-2.183-1.329-2.183-1.331%200-1.534%201.041-1.534%202.114v4.072h-2.556v-8.232h2.452v1.125h.035c.341-.647%201.176-1.329%202.421-1.329%202.59%200%203.07%201.705%203.07%203.921V18.074z%22%7D%5D%2C%22color%22%3A%22%23fff%22%2C%22bgColor%22%3A%22%230d66c2%22%2C%22linkUrl%22%3A%22https%3A%2F%2Fwww.linkedin.com%2FshareArticle%3Fmini%3Dtrue%26url%3D%5Bslei_social_url%5D%26title%3D%5Bslei_social_title%5D%22%2C%22linkRel%22%3A%22%22%7D%5D%2C%22key%22%3A29%7D' ),
				's_code_mobile'				=> addslashes( '<div class="safelayout-ei-icon-block safelayout-ei-social-share-block share-in-popup" style="margin-top: 10px; margin-bottom: 10px; display: flex; flex-wrap: wrap; justify-content: left; gap: 20px;"><a href="https://www.facebook.com/sharer/sharer.php?u=[slei_social_url]&amp;title=[slei_social_title]" target="_blank" aria-label="Facebook" title="Facebook" style="height: 40px; width: 40px;"><svg viewBox="0 0 96 96" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><defs></defs><g><rect x="4" y="4" width="88" height="88" rx="44" fill="#0866ff" stroke="#000" stroke-width="0"></rect></g></svg><svg viewBox="0 0 96 96" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" style="height: calc(110% - 19px); width: calc(110% - 19px);"><defs></defs><symbol viewBox="0 0 24 24" id="patha3305dde-15da-d0dc-f79c-4b70d03c058d0"><path vector-effect="non-scaling-stroke" fill="#fff" stroke="#000" stroke-width="0" d="M12 2C6.5 2 2 6.5 2 12c0 5 3.7 9.1 8.4 9.9v-7H7.9V12h2.5V9.8c0-2.5 1.5-3.9 3.8-3.9 1.1 0 2.2.2 2.2.2v2.5h-1.3c-1.2 0-1.6.8-1.6 1.6V12h2.8l-.4 2.9h-2.3v7C18.3 21.1 22 17 22 12c0-5.5-4.5-10-10-10z"></path></symbol><use href="#patha3305dde-15da-d0dc-f79c-4b70d03c058d0"></use></svg></a><a href="https://x.com/intent/tweet?text=[slei_social_title] [slei_social_url]" target="_blank" aria-label="X" title="X" style="height: 40px; width: 40px;"><svg viewBox="0 0 96 96" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><defs></defs><g><rect x="4" y="4" width="88" height="88" rx="44" fill="#000" stroke="#000" stroke-width="0"></rect></g></svg><svg viewBox="0 0 96 96" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" style="height: calc(110% - 19px); width: calc(110% - 19px);"><defs></defs><symbol viewBox="0 0 24 24" id="patha3305dde-15da-d0dc-f79c-4b70d03c058d1"><path vector-effect="non-scaling-stroke" fill="#fff" stroke="#000" stroke-width="0" d="M16.613 4.75h2.46l-5.374 6.143L20.021 19.25h-4.951l-3.876-5.069-4.436 5.069h-2.462l5.749-6.569L3.979 4.75h5.076l3.505 4.634L16.612 4.75Zm-.863 13.028h1.363L8.314 6.145H6.851l8.899 11.632Z"></path></symbol><use href="#patha3305dde-15da-d0dc-f79c-4b70d03c058d1"></use></svg></a><a href="https://www.linkedin.com/shareArticle?mini=true&amp;url=[slei_social_url]&amp;title=[slei_social_title]" target="_blank" aria-label="LinkedIn" title="LinkedIn" style="height: 40px; width: 40px;"><svg viewBox="0 0 96 96" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><defs></defs><g><rect x="4" y="4" width="88" height="88" rx="44" fill="#0d66c2" stroke="#000" stroke-width="0"></rect></g></svg><svg viewBox="0 0 96 96" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" style="height: calc(110% - 19px); width: calc(110% - 19px);"><defs></defs><symbol viewBox="0 0 24 24" id="patha3305dde-15da-d0dc-f79c-4b70d03c058d2"><path vector-effect="non-scaling-stroke" fill="#fff" stroke="#000" stroke-width="0" d="M19.379 3.375H4.621C3.933 3.375 3.375 3.933 3.375 4.621v14.758C3.375 20.067 3.933 20.625 4.621 20.625h14.758c.688 0 1.246-.558 1.246-1.246V4.621C20.625 3.933 20.067 3.375 19.379 3.375zM8.492 18.074H5.931v-8.232h2.561V18.074zM7.212 8.717c-.821 0-1.484-.665-1.484-1.483 0-.819.662-1.484 1.484-1.484.818 0 1.483.665 1.483 1.484C8.695 8.053 8.031 8.717 7.212 8.717zM18.075 18.074h-2.558v-4.003c0-.955-.016-2.183-1.329-2.183-1.331 0-1.534 1.041-1.534 2.114v4.072h-2.556v-8.232h2.452v1.125h.035c.341-.647 1.176-1.329 2.421-1.329 2.59 0 3.07 1.705 3.07 3.921V18.074z"></path></symbol><use href="#patha3305dde-15da-d0dc-f79c-4b70d03c058d2"></use></svg></a></div>' ),
				'exclude_IDs'				=> '',
				'exclude_IDs_value'			=> '',
				'display_on_post'			=> true,
				'display_on_post_place'		=> 'bottom',
				'display_on_page'			=> true,
				'display_on_page_place'		=> 'bottom',
				'display_on_front'			=> true,
				'display_on_front_place'	=> 'bottom',
				'display_on_search'			=> true,
				'display_on_search_place'	=> 'bottom',
				'display_on_archive'		=> true,
				'display_on_archive_place'	=> 'bottom',
				'display_on_woo'			=> true,
				'display_on_woo_place'		=> 'summary',
			);
			$options = wp_parse_args(
				get_option( 'safelayout_icons_social_options', array() ),
				$default
			);
			return $options;
		}

		// add social share to posts and pages
		public function add_social( $content ) {
			global $wp_current_filter;
			
			// Don't add to get_the_excerpt because it's too early and strips tags (adding to the_excerpt is allowed).
			if ( in_array( 'get_the_excerpt', (array) $wp_current_filter ) ) {
				return $content;
			}
			$options = $this->get_social_share_options();
			$show = false;
			$place = '';
			if ( $options['display_on_post'] && is_singular('post') ) {
				$show = true;
				$place = $options['display_on_post_place'];
			}
			if ( $options['display_on_page'] && is_singular('page') ) {
				$show = true;
				$place = $options['display_on_page_place'];
			}
			if ( $options['display_on_front'] && is_home() ) {
				$show = true;
				$place = $options['display_on_front_place'];
			}
			if ( $options['display_on_search'] && is_search() ) {
				$show = true;
				$place = $options['display_on_search_place'];
			}
			if ( $options['display_on_archive'] && is_archive() ) {
				$show = true;
				$place = $options['display_on_archive_place'];
			}

			//exclude
			if ( $options['exclude_IDs'] && $show ) {
				$id = get_the_ID();
				if ( $id != 0 ) {
					$show = ! $this->check_specific_posts( $options['exclude_IDs_value'], $id );
				}
			}

			if ( $show && ( $place == 'top' || $place == 'both' ) ) {
				$content = do_shortcode( $this->get_social_share_code() ) . $content;
			}
			if ( $show && ( $place == 'bottom' || $place == 'both' ) ) {
				$content = $content . do_shortcode( $this->get_social_share_code() );
			}
			if ( ! $this->social_enqueue_key && $show ) {
				$this->social_enqueue_key = true;
				$this->enqueue_social_style();
			}
			return $content;
		}

		// Add social share block js file for frontend
		public function enqueue_social_style() {
			$this->enqueue_icon_style();
			wp_enqueue_script(
				'safelayout-safelayout-social-share-view-script',
				SAFELAYOUT_ICONS_URL . 'build/social-share/safelayout-share-script.js',
				array(),
				SAFELAYOUT_ICONS_VERSION,
				array(
					'in_footer' => true,
				)
			);
		}

		// Return true if id is in specific_posts options
		public function check_specific_posts( $ids, $id ) {
			$ids = explode( ',', $ids );
			$ids = array_map('trim', $ids);
			return in_array( $id, $ids );
		}

		// get social share HTML code
		public function get_social_share_code() {
			$options = $this->get_social_share_options();
			$allowed_html = Safelayout_elegant_icons::allowed_html( array(), 'post' );
			$mobile = wp_is_mobile() && $options['special_on_mobile'];
			$code = $mobile ? stripslashes( $options['s_code_mobile'] ) : stripslashes( $options['s_code'] );
			$title = $mobile ? $options['s_title_mobile'] :  $options['s_title'];
			if ( $title != '' ) {
				$float = '';
				$temp1;
				$result = preg_match( '/position\s*:\s*fixed[^"]*/i', $code, $temp1 );
				if ( $result ) {
					$float = 'style="' . $temp1[0] . '" ';
					$code = preg_replace( '/position\s*:\s*fixed[^"]*/i', '', $code, 1 );
				}
				$code = '<div ' . $float . 'class="safelayout-elegant-icons-social"><div class="sl-ei-social-head">' . $title . '</div>' . $code . '</div>';
			}

			return wp_kses( $code, $allowed_html );
		}

		// social share shortcodes
		public function shortcodes_init() {
			add_shortcode( 'slei_social_title', array( $this, 'social_shortcode_title' ) );
			add_shortcode( 'slei_social_url', array( $this, 'social_shortcode_url' ) );
		}

		// social share shortcodes slei_social_title
		public function social_shortcode_title( $atts ) {
			return esc_attr( $this->get_title() );
		}

		// social share shortcodes slei_social_url
		public function social_shortcode_url( $atts ) {
			return esc_url( $this->get_url() );
		}

		// get the URL
		public function get_url() {
			if ( in_the_loop() ) {
				return get_the_permalink();
			} else {
				global $wp;
				return add_query_arg( $wp->query_vars, home_url( $wp->request ) );
			}
		}

		// get the title
		public function get_title() {
			if ( in_the_loop() ) {
				return get_the_title();
			} else {
				return wp_get_document_title();
			}
		}

		// render social share block 
		public function render_share_block( $block_content, $block, $instance ) {
			return do_shortcode( $block_content );
		}

		// enqueue assets to menu editor
		public function nav_menus_enqueue() {
			add_action( 'admin_enqueue_scripts', array( $this, 'nav_menu_enqueue_assets' ) );
		}

		// enqueue assets to menu editor
		public function nav_menu_enqueue_assets() {
			$this->load_packs();
			$this->load_mce_assets();
			wp_enqueue_script(
				'safelayout-menu-script',
				SAFELAYOUT_ICONS_URL . 'assets/js/menu.js',
				array(),
				SAFELAYOUT_ICONS_VERSION,
				true
			);
			wp_enqueue_style(
				'safelayout-elegant-icons-style-admin',
				SAFELAYOUT_ICONS_URL . 'assets/css/safelayout-elegant-icons-admin.min.css',
				array(),
				SAFELAYOUT_ICONS_VERSION
			);
		}

		// add html code to menu editor
		public function nav_menus_page_footer() {
			?>
				<div id="sl-ei-menu-modal">
					<div class="sl-ei-menu-window">
						<div class="sl-ei-menu-header"><?php esc_html_e( 'Edit Icon (Safelayout)', 'safelayout-elegant-icons' ); ?></div>
						<div id="sl-ei-menu-body" menu-helper-id="not set yet">
						</div>
						<div class="sl-ei-menu-footer">
							<a id="sl-ei-menu-submit" class="button"><?php esc_html_e( 'OK', 'safelayout-elegant-icons' ); ?></a>
							<a id="sl-ei-menu-cancel" class="button"><?php esc_html_e( 'Cancel', 'safelayout-elegant-icons' ); ?></a> 
						</div>
					</div>
				</div>
			<?php
		}

		// add fields to menu editor
		public function nav_menu_add_fields( $item_id, $item, $depth, $args ) {
			$menu_icon = stripslashes( get_post_meta( $item_id, 'safelayout_menu_icon', true ) );
			$allowed_html = Safelayout_elegant_icons::allowed_html( array(), 'post' );
			wp_nonce_field( 'safelayout_menu_meta_nonce', 'safelayout_menu_meta_nonce_name' );
			$msg = $menu_icon ? __( 'Edit Icon', 'safelayout-elegant-icons' ) : __( 'Insert Icon', 'safelayout-elegant-icons' );
			?>
				<div class="sl-ei-menu-field-container" id="sl-ei-menu-<?php echo esc_html( $item_id ) ?>">
					<span class="sl-ei-menu-field-container-title"><?php esc_html_e( 'Icon (Safelayout)', 'safelayout-elegant-icons' ); ?></span>
					<div class="sl-ei-menu-icon-container"><?php echo wp_kses( $menu_icon, $allowed_html ); ?></div>
					<a class="button sl-ei-menu-insert"><?php echo esc_html( $msg ); ?></a>
					<a class="button sl-ei-menu-remove"><?php esc_html_e( 'Remove Icon', 'safelayout-elegant-icons' ); ?></a> 
					<input class="sl-ei-menu-code" type="hidden" name="safelayout-menu-code[<?php echo esc_html( $item_id ); ?>]" value="<?php echo htmlspecialchars( wp_kses( $menu_icon, $allowed_html ) ); ?>">
				</div>
			<?php
		}

		// update menu metadata
		public function nav_menu_update( $menu_id, $menu_item_db_id ) {
			if ( ! isset( $_POST['safelayout_menu_meta_nonce_name'] ) ||
				 ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['safelayout_menu_meta_nonce_name'] ) ), 'safelayout_menu_meta_nonce' ) ) {
				return;
			}
			if( isset( $_POST['safelayout-menu-code'][$menu_item_db_id] ) ) {
				$sanitary_values = addslashes( wp_kses(
					htmlspecialchars_decode( $_POST['safelayout-menu-code'][$menu_item_db_id] ),
					Safelayout_elegant_icons::allowed_html( array(), 'post' )
					) );
				update_post_meta( $menu_item_db_id, 'safelayout_menu_icon', $sanitary_values );
			} else {
				delete_post_meta( $menu_item_db_id, 'safelayout_menu_icon' );
			}
		}

		// add filter to change menu title
		public function add_menu_item_filter( $args ) {
			add_filter( 'the_title', array( $this, 'insert_icon' ), PHP_INT_MAX, 2 );
			add_filter( 'megamenu_the_title', array( $this, 'insert_icon' ), PHP_INT_MAX, 2 );
			return $args;
		}

		// remove filter from menu title
		public function remove_menu_item_filter( $nav_menu ) {
			remove_filter( 'the_title', array( $this, 'insert_icon' ), PHP_INT_MAX, 2 );
			remove_filter( 'megamenu_the_title', array( $this, 'insert_icon' ), PHP_INT_MAX, 2 );
			return $nav_menu;
		}

		// insert icon in title
		public function insert_icon( $title, $id ) {
			$menu_icon = stripslashes( get_post_meta( $id, 'safelayout_menu_icon', true ) );

			if( $menu_icon ) {
				$temp0;
				$result = preg_match( '/iconpos[^=]*=[^\"]*"\K[^\"]*/i', $menu_icon, $temp0 );
				if ( $result ) {
					$allowed_html = Safelayout_elegant_icons::allowed_html( array(), 'post' );
					$temp1;
					$temp2 = '';
					$result = preg_match( '/icongap[^=]*=[^\"]*"\K[^\"]*/i', $menu_icon, $temp1 );
					if ( $result ) {
						$temp2 = '<span style="margin-left:' . $temp1[0] . 'px;"></span>';
					}
					if ( $temp0[0] == 'before' ) {
						$title = wp_kses( $menu_icon, $allowed_html ) . wp_kses( $temp2, $allowed_html ) . $title;
					} else {
						$title = $title . wp_kses( $temp2, $allowed_html ) . wp_kses( $menu_icon, $allowed_html );
					}
				}
			}
			return $title;
		}

		// Register elementor widget front js & css file
		public function register_elementor_front() {
			wp_register_style(
				'safelayout-safelayout-icon-style',
				SAFELAYOUT_ICONS_URL . 'build/icon/style-index.css',
				array(),
				SAFELAYOUT_ICONS_VERSION,
			);
			wp_register_style(
				'safelayout-safelayout-icon-box-style',
				SAFELAYOUT_ICONS_URL . 'build/icon-box/style-index.css',
				array(),
				SAFELAYOUT_ICONS_VERSION,
			);
			wp_register_script(
				'safelayout-safelayout-social-share-view-script',
				SAFELAYOUT_ICONS_URL . 'build/social-share/safelayout-share-script.js',
				array(),
				SAFELAYOUT_ICONS_VERSION,
				array(
					'in_footer' => true,
				)
			);
		}

		// deregister script.js from elementor editor
		public function deregister_elementor_script() {
			if ( array_key_exists( 'elementor-preview', $_GET ) ) {
				wp_deregister_script( 'safelayout-safelayout-social-share-view-script' );
			}
		}

		// Register elementor widget
		public function register_widgets( $widgets_manager ) {
			require_once SAFELAYOUT_ICONS_PATH . 'elementor/class-safelayout-icons-elementor-widget.php';
			$widgets_manager->register( new \Safelayout_icons_elementor_widget() );
			require_once SAFELAYOUT_ICONS_PATH . 'elementor/class-safelayout-iconlist-elementor-widget.php';
			$widgets_manager->register( new \Safelayout_iconlist_elementor_widget() );
			require_once SAFELAYOUT_ICONS_PATH . 'elementor/class-safelayout-iconbox-elementor-widget.php';
			$widgets_manager->register( new \Safelayout_iconbox_elementor_widget() );
			require_once SAFELAYOUT_ICONS_PATH . 'elementor/class-safelayout-socialprofiles-elementor-widget.php';
			$widgets_manager->register( new \Safelayout_socialprofiles_elementor_widget() );
			require_once SAFELAYOUT_ICONS_PATH . 'elementor/class-safelayout-socialshare-elementor-widget.php';
			$widgets_manager->register( new \Safelayout_socialshare_elementor_widget() );
		}

		// Register elementor control
		public function register_controls( $controls_manager ) {
			require_once SAFELAYOUT_ICONS_PATH . 'elementor/class-safelayout-icons-elementor-control.php';
			$controls_manager->register( new \Safelayout_icons_elementor_control() );
			require_once SAFELAYOUT_ICONS_PATH . 'elementor/class-safelayout-iconlist-elementor-control.php';
			$controls_manager->register( new \Safelayout_iconlist_elementor_control() );
			require_once SAFELAYOUT_ICONS_PATH . 'elementor/class-safelayout-iconbox-elementor-control.php';
			$controls_manager->register( new \Safelayout_iconbox_elementor_control() );
			require_once SAFELAYOUT_ICONS_PATH . 'elementor/class-safelayout-boxbutton-elementor-control.php';
			$controls_manager->register( new \Safelayout_boxbutton_elementor_control() );
			require_once SAFELAYOUT_ICONS_PATH . 'elementor/class-safelayout-ribbon-elementor-control.php';
			$controls_manager->register( new \Safelayout_ribbon_elementor_control() );
			require_once SAFELAYOUT_ICONS_PATH . 'elementor/class-safelayout-boxhead-elementor-control.php';
			$controls_manager->register( new \Safelayout_boxhead_elementor_control() );
			require_once SAFELAYOUT_ICONS_PATH . 'elementor/class-safelayout-boxtext-elementor-control.php';
			$controls_manager->register( new \Safelayout_boxtext_elementor_control() );
			require_once SAFELAYOUT_ICONS_PATH . 'elementor/class-safelayout-socialprofiles-elementor-control.php';
			$controls_manager->register( new \Safelayout_socialprofiles_elementor_control() );
			require_once SAFELAYOUT_ICONS_PATH . 'elementor/class-safelayout-socialshare-elementor-control.php';
			$controls_manager->register( new \Safelayout_socialshare_elementor_control() );
		}

		// Add js & css file for elementor editor
		public function elementor_enqueue() {
			$this->load_packs();
			$this->load_mce_assets();
			$this->load_iconbox_assets();
			$this->load_ribbon_assets();
			$this->load_boxbutton_assets();
			$this->load_social_assets();
			$this->load_iconlist_assets();
		}

		// Add js & css file for elementor template
		public function after_elementor_enqueue() {
			wp_enqueue_style(
				'safelayout-elementor-template-style',
				SAFELAYOUT_ICONS_URL . 'elementor/templates/template.css',
				array( 'elementor-editor', ),
				SAFELAYOUT_ICONS_VERSION,
			);

			wp_enqueue_script(
				'safelayout-elementor-template-script',
				SAFELAYOUT_ICONS_URL . 'elementor/templates/template.js',
				array( 'elementor-editor', 'jquery-hover-intent', ),
				SAFELAYOUT_ICONS_VERSION,
				true
			);

			wp_enqueue_script(
				'safelayout-elegant-icons-template-array',
				SAFELAYOUT_ICONS_URL . 'elementor/templates/template-data.js',
				array(),
				SAFELAYOUT_ICONS_VERSION,
				true
			);

			$temp = 'SLEIBaseUrl = "' . SAFELAYOUT_ICONS_URL . '";';
			wp_add_inline_script(
				'safelayout-elegant-icons-template-array',
				$temp,
				'before'
			);
		}

		// Add elementor template data
		public function print_template_views() {
			include_once ( SAFELAYOUT_ICONS_PATH . 'elementor/templates/template.php' );
		}

		// Add js & css file for elementor editor
		public function elementor_preview_enqueue() {
			wp_enqueue_style( 'safelayout-safelayout-icon-box-editor-style' );
		}

		// Add js & css file for icon box edit
		public function load_iconbox_assets() {
			$asset = include SAFELAYOUT_ICONS_PATH . 'build/icon-box/index.asset.php';
			wp_enqueue_script(
				'safelayout-safelayout-icon-box-editor-script',
				SAFELAYOUT_ICONS_URL . 'build/icon-box/index.js',
				$asset['dependencies'],
				$asset['version'],
				array(
					'in_footer' => true,
				)
			);
			wp_enqueue_style(
				'safelayout-safelayout-icon-box-editor-style',
				SAFELAYOUT_ICONS_URL . 'build/icon-box/index.css',
				array_filter(
					$asset['dependencies'],
					function ( $style ) {
						return wp_style_is( $style, 'registered' );
					}
				),
				$asset['version'],
			);
			wp_enqueue_style(
				'safelayout-safelayout-icon-box-style',
				SAFELAYOUT_ICONS_URL . 'build/icon-box/style-index.css',
				array(),
				$asset['version'],
			);
			foreach ( $asset['dependencies'] as $dep ) {
				wp_enqueue_style( $dep );
			}
		}

		// Add js & css file for box ribbon edit
		public function load_ribbon_assets() {
			$asset = include SAFELAYOUT_ICONS_PATH . 'build/box-ribbon/index.asset.php';
			wp_enqueue_script(
				'safelayout-safelayout-box-ribbon-editor-script',
				SAFELAYOUT_ICONS_URL . 'build/box-ribbon/index.js',
				$asset['dependencies'],
				$asset['version'],
				array(
					'in_footer' => true,
				)
			);
			foreach ( $asset['dependencies'] as $dep ) {
				wp_enqueue_style( $dep );
			}
		}

		// Add js & css file for box button edit
		public function load_boxbutton_assets() {
			$asset = include SAFELAYOUT_ICONS_PATH . 'build/box-button/index.asset.php';
			wp_enqueue_script(
				'safelayout-safelayout-box-button-editor-script',
				SAFELAYOUT_ICONS_URL . 'build/box-button/index.js',
				$asset['dependencies'],
				$asset['version'],
				array(
					'in_footer' => true,
				)
			);
			foreach ( $asset['dependencies'] as $dep ) {
				wp_enqueue_style( $dep );
			}
		}

		// Add js & css file for social
		public function load_social_assets() {
			$asset = include SAFELAYOUT_ICONS_PATH . 'build/social-profiles/index.asset.php';
			wp_enqueue_script(
				'safelayout-safelayout-social-profiles-editor-script',
				SAFELAYOUT_ICONS_URL . 'build/social-profiles/index.js',
				$asset['dependencies'],
				$asset['version'],
				array(
					'in_footer' => true,
				)
			);
			foreach ( $asset['dependencies'] as $dep ) {
				wp_enqueue_style( $dep );
			}
		}

		// Add js & css file for iconlist
		public function load_iconlist_assets() {
			$asset = include SAFELAYOUT_ICONS_PATH . 'build/icon-list/index.asset.php';
			wp_enqueue_script(
				'safelayout-safelayout-icon-list-editor-script',
				SAFELAYOUT_ICONS_URL . 'build/icon-list/index.js',
				$asset['dependencies'],
				$asset['version'],
				array(
					'in_footer' => true,
				)
			);
			foreach ( $asset['dependencies'] as $dep ) {
				wp_enqueue_style( $dep );
			}
		}

		// Load plugin textdomain
		public function load_textdomain() {
			load_plugin_textdomain( 'safelayout-elegant-icons', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
		}

		// Add svg to tinymce
		public function new_mce_options( $init ) {
			$ext = 'span[*],div[*],svg[*],a[*],circle[*],clippath[*],defs[*],ellipse[*],feblend[*],fecolormatrix[*],fecomponenttransfer[*],fecomposite[*],feconvolvematrix[*],fediffuselighting[*],fedisplacementmap[*],fedistantlight[*],feflood[*],fefunca[*],fefuncb[*],fefuncg[*],fefuncr[*],fegaussianblur[*],feimage[*],femerge[*],femergenode[*],femorphology[*],feoffset[*],fepointlight[*],fespecularlighting[*],fespotlight[*],fetile[*],feturbulence[*],filter[*],g[*],mask[*],path[*],pattern[*],polygon[*],polyline[*],radialgradient[*],rect[*],stop[*],lineargradient[*],style[*],symbol[*],use[*],br[*],sl-bb-custom1359[*]';

			if ( isset( $init['extended_valid_elements'] ) ) { 
				$init['extended_valid_elements'] .= ',' . $ext;
			} else {
				$init['extended_valid_elements'] = $ext;
			}

			$s = SAFELAYOUT_ICONS_URL . 'build/icon/';
			if ( isset( $init['content_css'] ) ) { 
				$init['content_css'] .= ',' . $s . 'style-index.css';
			} else {
				$init['content_css'] = $s . 'style-index.css';
			}
			$this->load_packs();
			$this->load_mce_assets();
			return $init;
		}

		// Loade assets for tinymce
		public function load_mce_assets() {
			$asset = include SAFELAYOUT_ICONS_PATH . 'build/mce/index.asset.php';
	
			wp_enqueue_script(
				'safelayout-safelayout-mce-editor-script',
				SAFELAYOUT_ICONS_URL . 'build/mce/index.js',
				$asset['dependencies'],
				$asset['version'],
				array(
					'in_footer' => true,
				)
			);

			wp_enqueue_style(
				'safelayout-safelayout-icon-editor-style',
				SAFELAYOUT_ICONS_URL . 'build/icon/index.css',
				array_filter(
					$asset['dependencies'],
					function ( $style ) {
						return wp_style_is( $style, 'registered' );
					}
				),
				$asset['version'],
			);
	
			wp_enqueue_style(
				'safelayout-safelayout-icon-style',
				SAFELAYOUT_ICONS_URL . 'build/icon/style-index.css',
				array(),
				$asset['version'],
			);
			foreach ( $asset['dependencies'] as $dep ) {
				wp_enqueue_style( $dep );
			}
		}

		// Prevent tags from texturize
		public function mce_no_texturize_tags( $tags ) {
			$tags[] = 'sl-bb-custom1359';
			return $tags;
		}

		// Replace custom tag with style tag
		public function mce_the_content( $content ) {
			return str_replace( 'sl-bb-custom1359', 'style', $content );
		}

		// Add js & css file for frontend mce
		public function enqueue_mce() {
			$wp_post = get_post();

			if ( $wp_post instanceof WP_Post ) {
				$n0 = 'safelayout-ei-icon-block';
				$n1 = 'data-safelayout-mce-icon';
				if ( mb_strpos( (string) $wp_post->post_content, $n0 ) !== false || mb_strpos( (string) $wp_post->post_content, $n1 ) !== false ) {
					$this->enqueue_icon_style();
				}
			}
		}

		// Add icon block css file for frontend
		public function enqueue_icon_style() {
			wp_enqueue_style(
				'safelayout-safelayout-icon-style',
				SAFELAYOUT_ICONS_URL . 'build/icon/style-index.css',
				array(),
				SAFELAYOUT_ICONS_VERSION,
			);
		}

		// Add js plugin file to tinymce
		public function mce_plugins( $plugins ) {
			$plugins['safelayout_icons'] = SAFELAYOUT_ICONS_URL . 'assets/js/plugin.js';
			return $plugins;
		}

		// Add a toolbar button to tinymce
		public function mce_buttons( $toolbarButtons ) {
			$toolbarButtons[] = 'safelayout_icons';
			return $toolbarButtons;
		}

		// activated plugin
		public function activated_plugin( $plugin ) {
			if( $plugin == plugin_basename( __FILE__ ) ) {
				$rate = $this->get_rate_data();
			}
		}

		// Add settings link on plugin page
		public function plugin_action_links( $links ) {
			$settings_link = array(
				'<a href="' . admin_url( 'options-general.php?page=safelayout-elegant-icons' ) . '">' . esc_html__( 'Settings', 'safelayout-elegant-icons' ) . '</a>',
			);
			$links = array_merge( $links, $settings_link );
			return $links;
		}

		// Register icons block
		public function register_block() {
			if ( ! function_exists( 'register_block_type' ) ) {
				// Gutenberg is not active.
				return;
			}
			register_block_type( __DIR__ . '/build/box-button' );
			register_block_type( __DIR__ . '/build/box-ribbon' );
			register_block_type( __DIR__ . '/build/container' );
			register_block_type( __DIR__ . '/build/list-item' );
			register_block_type( __DIR__ . '/build/icon' );
			register_block_type( __DIR__ . '/build/icon-box' );
			register_block_type( __DIR__ . '/build/icon-list' );
			register_block_type( __DIR__ . '/build/social-profiles' );
			register_block_type( __DIR__ . '/build/social-share' );
		}

		// Register patterns
		public function register_patterns() {
			$block_pattern_categories = array(
				'safelayout'   => array( 'label' => __( 'Safelayout', 'safelayout-elegant-icons' ) ),
				'icons-icon-boxes' => array( 'label' => __( 'Icons and Icon Boxes', 'safelayout-elegant-icons' ) ),
				'social-icons' => array( 'label' => __( 'Social Icons', 'safelayout-elegant-icons' ) ),
				'text-boxes'  => array( 'label' => __( 'Text Boxes', 'safelayout-elegant-icons' ) ),
				'icon-lists' => array( 'label' => __( 'Icon Lists', 'safelayout-elegant-icons' ) ),
			);
		
			foreach ( $block_pattern_categories as $name => $properties ) {
				if ( ! \WP_Block_Pattern_Categories_Registry::get_instance()->is_registered( $name ) ) {
					register_block_pattern_category( $name, $properties );
				}
			}
	
			$block_patterns = array(
				array(
					'slug' => 'features-01',
					'file' => 'pattern001',
				),
				array(
					'slug' => 'features-02',
					'file' => 'pattern002',
				),
				array(
					'slug' => 'features-03',
					'file' => 'pattern003',
				),
				array(
					'slug' => 'features-04',
					'file' => 'pattern004',
				),
				array(
					'slug' => 'simple-icon-box-01',
					'file' => 'pattern005',
				),
				array(
					'slug' => 'simple-icon-box-02',
					'file' => 'pattern006',
				),
				array(
					'slug' => 'icon-box-with-button-01',
					'file' => 'pattern007',
				),
				array(
					'slug' => 'icon-box-with-button-02',
					'file' => 'pattern008',
				),
				array(
					'slug' => 'icon-box-with-button-03',
					'file' => 'pattern009',
				),
				array(
					'slug' => 'dark-text-box-with-horizontal-ribbon',
					'file' => 'pattern010',
				),
				array(
					'slug' => 'light-text-box-with-horizontal-ribbon',
					'file' => 'pattern011',
				),
				array(
					'slug' => 'dark-text-box-with-vertical-ribbon',
					'file' => 'pattern012',
				),
				array(
					'slug' => 'light-text-box-with-vertical-ribbon',
					'file' => 'pattern013',
				),
				array(
					'slug' => 'dark-text-box',
					'file' => 'pattern014',
				),
				array(
					'slug' => 'light-text-box',
					'file' => 'pattern015',
				),
				array(
					'slug' => 'social-icons-01',
					'file' => 'pattern016',
				),
				array(
					'slug' => 'social-icons-02',
					'file' => 'pattern017',
				),
				array(
					'slug' => 'social-icons-03',
					'file' => 'pattern018',
				),
				array(
					'slug' => 'social-icons-04',
					'file' => 'pattern019',
				),
				array(
					'slug' => 'social-icons-05',
					'file' => 'pattern020',
				),
				array(
					'slug' => 'icon-list-01',
					'file' => 'pattern021',
				),
				array(
					'slug' => 'icon-list-02',
					'file' => 'pattern022',
				),
				array(
					'slug' => 'icon-list-03',
					'file' => 'pattern023',
				),
				array(
					'slug' => 'icon-list-04',
					'file' => 'pattern024',
				),
				array(
					'slug' => 'icon-list-05',
					'file' => 'pattern025',
				),
			);
	
			foreach ( $block_patterns as $block_pattern ) {
				$pattern_file = SAFELAYOUT_ICONS_PATH . 'assets/patterns/' . $block_pattern['file'] . '.php';
		
				register_block_pattern(
					'safelayout/' . $block_pattern['slug'],
					require $pattern_file
				);
			}
		}
	
		// Add block category
		public function safelayout_blocks_categories_add( $block_categories, $editor_context ) {
			$key = false;
			foreach ( $block_categories as $block_cat ) {
				if ( $block_cat['slug'] === 'blocks-safelayout-category' ) {
					$key = true;
					break;
				}
			}
			if ( ! $key ) {
				array_unshift(
					$block_categories,
					array(
						'slug'  => 'blocks-safelayout-category',
						'title' => __( 'Blocks By Safelayout', 'safelayout-elegant-icons' ),
						'icon'  => null,
					)
				);
			}
			return $block_categories;
		}

		// Return rate reminder data
		public function get_rate_data() {
			$rate = get_option( 'safelayout_icons_options_rate' );
			if ( ! $rate ) {
				$rate = array(
					'time'	=> time(),
					'later'	=> time(),
				);
				update_option( 'safelayout_icons_options_rate', $rate );
			}
			return $rate;
		}

		// Return icons upgrade data
		public function get_upgrade_data() {
			$upgrade = get_option( 'safelayout_icons_options_upgrade' );
			if ( ! $upgrade ) {
				$upgrade = time();
				update_option( 'safelayout_icons_options_upgrade', $upgrade );
			}
			return $upgrade;
		}

		// Add rate reminder
		public function add_rate_reminder() {
			if ( is_super_admin() ) {
				$rate = $this->get_rate_data();
				$upgrade = $this->get_upgrade_data();
				if ( $upgrade < strtotime( '-12 day' ) ) {
					add_action( 'admin_notices', array( $this, 'show_upgrade_message' ), 0 );
					add_action( 'wp_ajax_slei_icons_upgrade', array( $this, 'icons_upgrade_ajax_handler' ) );
					add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts_for_rate_reminder' ) );
				} else if ( $upgrade < strtotime( '-1 day' ) && $rate['later'] != 0 && $rate['later'] < strtotime( '-4 day' ) ) {
					add_action( 'admin_notices', array( $this, 'show_rate_reminder' ), 0 );
					add_action( 'wp_ajax_slei_icons_rate_reminder', array( $this, 'icons_rate_reminder_ajax_handler' ) );
					add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts_for_rate_reminder' ) );
				}
			}
		}

		// ajax handlers for rate reminder
		public function icons_rate_reminder_ajax_handler() {
			check_ajax_referer( 'slei_icons_ajax' );
			$type = sanitize_text_field( wp_unslash( $_POST['type'] ) );
			$rate = $this->get_rate_data();
			if ( $type === 'sl-ei-rate-later' ) {
				$rate['later'] = time();
			} else {
				$rate['later'] = 0;
			}
			update_option( 'safelayout_icons_options_rate', $rate );

			wp_die();
		}

		// Show rate reminder
		public function show_rate_reminder() {
			global $current_user;
			?>
			<div id="sl-ei-rate-reminder" class="notice notice-success is-dismissible">
				<img alt="safelayout elegant icons" src="<?php echo esc_url( SAFELAYOUT_ICONS_URL . 'assets/image/icon-128x128.png' ); ?>">
				<div class="sl-ei-msg-container">
					<p>
						<?php
						printf(
							/* translators: 1: current user name, 2: Safelayout Elegant Icons, 3: give it a 5-star rating on WordPress.org, 4: We really appreciate your support! */
							esc_html__(
								'Howdy, %1$s! Thank you for using %2$s! Could you please do us a BIG favor and %3$s? Just to help us spread the word and boost our motivation.%4$s',
								'safelayout-elegant-icons'
							),
							'<strong>' . esc_html( $current_user->display_name ) . '</strong>',
							'<strong>' . esc_html__( 'Safelayout Elegant Icons', 'safelayout-elegant-icons' ) . '</strong>',
							'<strong>' . esc_html__( 'give it a 5-star rating on WordPress.org', 'safelayout-elegant-icons' ) . '</strong>',
							'<br>' . esc_html__( 'We really appreciate your support!', 'safelayout-elegant-icons' ) . '<strong> -Safelayout-</strong>'
						);
						?>
					</p>
					<div class="sl-ei-rate-reminder-footer">
						<a id="sl-ei-rate-ok" class="button" href="https://wordpress.org/support/plugin/safelayout-elegant-icons/reviews/?filter=5" target="_blank">
							<?php esc_html_e( 'Yes, I will help ★★★★★', 'safelayout-elegant-icons' ); ?>
						</a>
						<a id="sl-ei-rate-later" class="button"><span class="dashicons dashicons-calendar"></span><?php esc_html_e( 'Remind me later', 'safelayout-elegant-icons' ); ?></a>
						<a id="sl-ei-rate-already" class="button"><span class="dashicons dashicons-smiley"></span><?php esc_html_e( 'I already did', 'safelayout-elegant-icons' ); ?></a>
					</div>
				</div>
			</div>
			<?php
		}

		// ajax handlers for upgrade message
		public function icons_upgrade_ajax_handler() {
			check_ajax_referer( 'slei_icons_ajax' );
			update_option( 'safelayout_icons_options_upgrade', time() );
			wp_die();
		}

		// Show upgrade message
		public function show_upgrade_message() {
			global $current_user;
			?>
			<div id="sl-ei-upgrade-reminder" class="notice notice-success">
				<div class="sl-ei-msg-container" style="width: initial;">
					<img alt="safelayout elegant icons" src="<?php echo esc_url( SAFELAYOUT_ICONS_URL . 'assets/image/safelayout-elegant-icons-pro-note.png?ver=' . SAFELAYOUT_ICONS_VERSION ); ?>"  style="max-width: 100%;height:auto;">
					<p>
						<?php
						printf(
							/* translators: 1: current user name, 2: Safelayout Elegant Icons, 3: upgrading to the PRO version, 4: support the developer, 5: We really appreciate your support! */
							esc_html__(
								'Howdy, %1$s! Thank you for using %2$s! Please consider %3$s, get full features and %4$s.%5$s',
								'safelayout-elegant-icons'
							),
							'<strong>' . esc_html( $current_user->display_name ) . '</strong>',
							'<strong>' . esc_html__( 'Safelayout Elegant Icons', 'safelayout-elegant-icons' ) . '</strong>',
							'<strong>' . esc_html__( 'upgrading to the PRO version', 'safelayout-elegant-icons' ) . '</strong>',
							'<strong>' . esc_html__( 'support the developer', 'safelayout-elegant-icons' ) . '</strong>',
							'<br>' . esc_html__( 'We really appreciate your support!', 'safelayout-elegant-icons' ) . '<strong> -Safelayout-</strong>'
						);
						?>
					</p>
					<div class="sl-ei-upgrade-reminder-footer">
						<a id="sl-ei-upgrade" class="button" href="https://safelayout.com/safelayout-elegant-icons-pro" target="_blank">
							<span class="dashicons dashicons-smiley"></span><?php esc_html_e( 'Upgrade to Pro', 'safelayout-elegant-icons' ); ?>
						</a>
						<a id="sl-ei-upgrade-later" class="button">
							<span class="dashicons dashicons-no-alt"></span><?php esc_html_e( 'No Thanks', 'safelayout-elegant-icons' ); ?>
						</a> 
					</div>
				</div>
			</div>
			<?php
		}

		// allow feedback host
		public function allow_icons_feedback_host( $allow, $host, $url ) {
			return ( false !== strpos( $host, 'safelayout' ) ) ? true : $allow;
		}

		// Add css and js file for rate reminder
		public function enqueue_scripts_for_rate_reminder( $hook ) {
			$this->enqueue_scripts_for_feedback_and_rate();
		}

		// Add css and js file for feedback
		public function enqueue_scripts_for_feedback( $hook ) {
			if ( $hook != 'plugins.php' ) {
				return;
			}
			$this->enqueue_scripts_for_feedback_and_rate();
		}

		// Add css and js file for feedback & rate reminder
		public function enqueue_scripts_for_feedback_and_rate() {
			wp_enqueue_script(
				'safelayout-elegant-icons-script-admin-feedback',
				SAFELAYOUT_ICONS_URL . 'assets/js/safelayout-elegant-icons-admin-feedback.min.js',
				array( 'jquery' ),
				SAFELAYOUT_ICONS_VERSION,
				true
			);
			$temp_obj = array(
				'ajax_url'	=> admin_url( 'admin-ajax.php' ),
				'nonce'		=> wp_create_nonce( 'slei_icons_ajax' ),
			);
			wp_localize_script( 'safelayout-elegant-icons-script-admin-feedback', 'sleiIconsAjax', $temp_obj );
			wp_enqueue_style(
				'safelayout-elegant-icons-style-admin-feedback',
				SAFELAYOUT_ICONS_URL . 'assets/css/safelayout-elegant-icons-admin-feedback.min.css',
				array(),
				SAFELAYOUT_ICONS_VERSION
			);
		}

		// ajax handlers for feedback
		public function icons_feedback_ajax_handler() {
			check_ajax_referer( 'slei_icons_ajax' );
			$type = sanitize_text_field( wp_unslash( $_POST['type'] ) );
			$text = sanitize_text_field( wp_unslash( $_POST['text'] ) );
			$apiUrl = 'https://safelayout.com/feedback/feedback.php';
			$rate = $this->get_rate_data();

			$data = array (
				'php'		=> phpversion(),
				'wordpress'	=> get_bloginfo( 'version' ),
				'version'	=> SAFELAYOUT_ICONS_VERSION,
				'time'		=> $rate['time'],
				'type'		=> $type,
				'text'		=> $text,
				'plugin'	=> 'icons',
			);
			$arg = array (
				'body'			=> $data,
				'timeout'		=> 30,
				'sslverify'		=> false,
				'httpversion'	=> 1.1,
			);

			$ret = wp_safe_remote_post( $apiUrl, $arg );
			if ( is_wp_error( $ret ) ) {
				$apiUrl = 'http://' . substr( $apiUrl, 8 );
				$ret = wp_remote_post( $apiUrl, $arg );
			}
			var_dump( $ret );

			wp_die();
		}

		// Add html code for feedback
		public function add_code_for_feedback( $hook ) {
			$msg1 = __( 'Please share your feedback, so we can fix issues and add the features you want.', 'safelayout-elegant-icons' );
			$msg2 = __( 'Feel free to write to us in your native language.', 'safelayout-elegant-icons' );
			$msg3 = __( 'Please share your feedback...', 'safelayout-elegant-icons' );
			switch ( substr( get_locale(), 0, 2 ) ) {
				case 'fa':
					$msg1 = 'لطفا نظرات خود را با ما به اشتراک بگذارید، تا بتوانیم مشکلات را برطرف کرده و ویژگی‌های مورد نظر شما را اضافه کنیم.';
					$msg2 = 'در صورت تمایل می‌توانید به زبان مادری خود برای ما بنویسید.';
					$msg3 = 'لطفا نظرات خود را به اشتراک بگذارید...';
					break;
				case 'ja':
					$msg1 = '問題の解決やご要望に応じた機能の追加のため、ぜひフィードバックをお寄せください。';
					$msg2 = 'お気軽に母国語でお問い合わせください。';
					$msg3 = 'フィードバックをお寄せください。';
					break;
				case 'it':
					$msg1 = 'Condividi il tuo feedback, così potremo risolvere i problemi e aggiungere le funzionalità che desideri.';
					$msg2 = 'Sentiti libero di scriverci nella tua lingua madre.';
					$msg3 = 'Condividi il tuo feedback...';
					break;
				case 'fr':
					$msg1 = "N'hésitez pas à nous faire part de vos commentaires afin que nous puissions corriger les problèmes et ajouter les fonctionnalités que vous souhaitez.";
					$msg2 = 'Vous pouvez nous écrire dans votre langue maternelle.';
					$msg3 = "N'hésitez pas à nous faire part de vos commentaires…";
					break;
				case 'es':
					$msg1 = 'Comparte tus comentarios para que podamos solucionar los problemas y añadir las funciones que deseas.';
					$msg2 = 'No dudes en escribirnos en tu idioma.';
					$msg3 = 'Comparte tus comentarios...';
					break;
				case 'ru':
					$msg1 = 'Пожалуйста, поделитесь своим мнением, чтобы мы могли исправить ошибки и добавить нужные вам функции.';
					$msg2 = 'Вы можете написать нам на своем родном языке.';
					$msg3 = 'Пожалуйста, поделитесь своим мнением...';
					break;
				case 'uk':
					$msg1 = 'Будь ласка, поділіться своїм відгуком, щоб ми могли виправити проблеми та додати потрібні вам функції.';
					$msg2 = 'Не соромтеся писати нам рідною мовою.';
					$msg3 = 'Будь ласка, поділіться своїм відгуком...';
					break;
			}
			?>
			<div id="sl-ei-feedback-modal">
				<div class="sl-ei-feedback-window">
					<div class="sl-ei-feedback-header"><?php esc_html_e( 'Quick Feedback', 'safelayout-elegant-icons' ); ?></div>
					<div class="sl-ei-feedback-body">
						<div class="sl-ei-feedback-title">
							<?php echo esc_html( $msg1 ); ?>
							<span class="dashicons dashicons-smiley"></span>
						</div>
						<div class="sl-ei-feedback-item">
							<span><?php echo esc_html( $msg2 ); ?></span>
							<textarea rows="6" id="sl-ei-feedback-text" placeholder="<?php echo esc_html( $msg3 ); ?>"></textarea>
						</div>
					</div>
					<div class="sl-ei-feedback-footer">
						<a id="sl-ei-feedback-submit" class="button"><?php esc_html_e( 'Submit & Deactivate', 'safelayout-elegant-icons' ); ?></a>
						<a id="sl-ei-feedback-skip" class="button"><?php esc_html_e( 'Skip & Deactivate', 'safelayout-elegant-icons' ); ?></a> 
					</div>
					<div id="sl-ei-feedback-loader"><div id="sl-ei-dots-rate" class="sl-ei-spin-rate"><div><span></span><span></span><span></span><span></span></div>
					<div id="sl-ei-feedback-loader-msg"><?php esc_html_e( 'Wait ...', 'safelayout-elegant-icons' ); ?></div></div></div>
					<div id="sl-ei-feedback-loader-msg-tr"><?php esc_html_e( 'Redirecting ...', 'safelayout-elegant-icons' ); ?></div>
				</div>
			</div>
			<?php
		}

		// Load icons packs
		public function load_packs() {
			$packs = $this->get_packs();
			$first = '';
			foreach ( $packs['icons'] as $icon ) {
				if ( $icon['active'] === 'yes' ) {
					$path = SAFELAYOUT_ICONS_URL . 'packs/' . $icon['file_name'] . '.js';
					if ( $first === '' ) {
						$first = $icon['file_name'];
					}
					wp_enqueue_script(
						'safelayout-pack-' . $icon['file_name'] . '-script',
						$path,
						array(),
						SAFELAYOUT_ICONS_VERSION,
						false
					);
				}
			}

			wp_enqueue_script(
				'safelayout-pack-social-icons-script',
				SAFELAYOUT_ICONS_URL . 'packs/social-icons.js',
				array(),
				SAFELAYOUT_ICONS_VERSION,
				false
			);

			if ( ! $this->icons_list_key ) {
				$this->icons_list_key = true;
				$temp = "SLEImceIcons = {};if (!(typeof SLEIiconArray !== 'undefined' && SLEIiconArray)) {SLEIiconArray = []}";
				wp_add_inline_script(
					'safelayout-pack-' . $first . '-script',
					$temp,
					'before'
				);
			}
		}

		// Set translations
		public function set_translations() {
			wp_set_script_translations(
				'safelayout-safelayout-icon-editor-script',
				'safelayout-elegant-icons',
				SAFELAYOUT_ICONS_PATH . 'languages'
			);
		}

		// Add an admin menu for plugin
		public function admin_menu() {
			$this->options_page_hook = add_options_page(
				esc_html__( 'Safelayout Elegant Icons Options', 'safelayout-elegant-icons' ),
				esc_html__( 'Safelayout Icons', 'safelayout-elegant-icons' ),
				'manage_options',
				'safelayout-elegant-icons',
				array( $this, 'admin_menu_page' )
			);
		}

		// Admin menu page
		public function admin_menu_page() {
			$packs = $this->get_packs();
			$s_options = $this->get_social_share_options();
			$allowed_html = Safelayout_elegant_icons::allowed_html( array(), 'post' );

			$active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : 'general';
			$general_class = 'nav-tab' . ( $active_tab == 'general' ? ' nav-tab-active' : '' );
			$social_class = 'nav-tab' . ( $active_tab == 'social' ? ' nav-tab-active' : '' );
			?>
			<div class="wrap">
				<h2><?php esc_html_e( 'Safelayout Elegant Icons Options', 'safelayout-elegant-icons' ); ?></h2>
				<?php settings_errors( 'safelayout-elegant-icons' ); ?>

				<h2 class="nav-tab-wrapper">
					<a href="?page=safelayout-elegant-icons&tab=general" class="<?php echo esc_attr( $general_class ); ?>"><?php esc_html_e( 'General', 'safelayout-elegant-icons' ); ?></a>
					<a href="?page=safelayout-elegant-icons&tab=social" class="<?php echo esc_attr( $social_class ); ?>"><?php esc_html_e( 'Social Share', 'safelayout-elegant-icons' ); ?></a>
				</h2>
				<div id="sl-ei-packs-settings">
					<form method="post" action="options.php">
						<?php if( $active_tab == "general" ): ?>
							<?php settings_fields( 'safelayout_icons_packs_group_1' ); ?>
							<input type="hidden" name="safelayout-elegant-icons-validate-key" value="true">
							<div>
								<table class="sl-ei-packs-table">
									<caption><?php esc_html_e( 'Safelayout Elegant Icons Installed Packs', 'safelayout-elegant-icons' ); ?></caption>
									<thead>
										<tr>
											<th><?php esc_html_e( 'No.', 'safelayout-elegant-icons' ); ?></th>
											<th><?php esc_html_e( 'Pack Name', 'safelayout-elegant-icons' ); ?></th>
											<th><?php esc_html_e( 'Pack Status', 'safelayout-elegant-icons' ); ?></th>
										</tr>
									</thead>
									<tbody>
										<?php 
											foreach ( $packs['icons'] as $index => $pack ) {
												echo '<tr><td>' . esc_html( $index + 1 ) . '</td><td>' . esc_html( $pack['name'] ) .
													'</td><td><input type="checkbox" name="safelayout_icons_packs[safelayout-' .
													esc_html( $pack['file_name'] ) . ']" value="yes" ' .
													checked( esc_attr( $pack['active'] ), 'yes', false ) . ' id="safelayout-' .
													esc_html( $pack['file_name'] ) . '"><label for="safelayout-' . esc_html( $pack['file_name'] ) .
													'">' . esc_html__( 'Active', 'safelayout-elegant-icons' ) . '</label></td></tr>';
											}
										?>
									</tbody>
								</table>
							</div>
							<div style="height: 50px;">
								<?php submit_button( esc_html__( 'Save Changes', 'safelayout-elegant-icons' ), 'primary', 'submit', false ); ?>
							</div>
						<?php elseif( $active_tab == "social" ): ?>
							<?php settings_fields( 'safelayout_icons_packs_group_2' ); ?>
							<h3><?php esc_html_e( 'Safelayout Social Share Options', 'safelayout-elegant-icons' ); ?></h3>
							<input type="hidden" name="safelayout_icons_social_options[validate-key]" value="true">
							<div>
								<table class="form-table" role="presentation">
									<tbody>
										<tr>
											<th scope="row"><?php esc_html_e( 'Enable Social', 'safelayout-elegant-icons' ); ?></th>
											<td>
												<input type="checkbox" name="safelayout_icons_social_options[enable_social]" id="enable_social" value="enable"<?php if ( 'enable' == $s_options['enable_social'] ) echo ' checked="checked"'; ?> >
												<label for="enable_social"><strong><?php esc_html_e( 'Enable Social Share Icons.', 'safelayout-elegant-icons' ); ?></strong></label>
											</td>
										</tr>
										<tr>
											<th scope="row"><?php esc_html_e( 'Social share title', 'safelayout-elegant-icons' ); ?></th>
											<td>
												<input type="text" style="width: 500px" name="safelayout_icons_social_options[s_title]" id="s_title" value="<?php echo esc_attr( $s_options['s_title'] ); ?>" placeholder="<?php esc_html_e( 'Share:', 'safelayout-elegant-icons' ); ?>" >
											</td>
										</tr>
										<tr>
											<th scope="row"><?php esc_html_e( 'Social share icons', 'safelayout-elegant-icons' ); ?></th>
											<td>
												<div class="sl-ei-social-icon-container"><?php echo wp_kses( stripslashes( str_replace( '<a', '<div', str_replace( '</a', '</div', $s_options['s_code'] ) ) ), $allowed_html ); ?></div>
												<br><button class="button" id="sl-ei-social-edit" disabled><?php esc_html_e( 'Edit social icons', 'safelayout-elegant-icons' ); ?></button>
												<input class="sl-ei-social-attributes" type="hidden" name="safelayout_icons_social_options[s_attributes]" value="<?php echo htmlspecialchars( wp_kses( $s_options['s_attributes'], $allowed_html ) ); ?>">
												<input class="sl-ei-social-code" type="hidden" name="safelayout_icons_social_options[s_code]" value="<?php echo htmlspecialchars( wp_kses( stripslashes( $s_options['s_code'] ), $allowed_html ) ); ?>">
											</td>
										</tr>
										<tr>
											<th scope="row"><?php esc_html_e( 'Hide on mobile', 'safelayout-elegant-icons' ); ?></th>
											<td>
												<input type="checkbox" name="safelayout_icons_social_options[hide_on_mobile]" id="hide_on_mobile" value="enable"<?php if ( $s_options['hide_on_mobile'] ) echo ' checked="checked"'; ?> >
												<label for="hide_on_mobile"><?php esc_html_e( 'Hide Social Share Icons on mobile.', 'safelayout-elegant-icons' ); ?></label><br><br>
											</td>
										</tr>
										<tr>
											<th scope="row"><?php esc_html_e( 'Mobile Social share', 'safelayout-elegant-icons' ); ?></th>
											<td>
												<input type="checkbox" name="safelayout_icons_social_options[special_on_mobile]" id="special_on_mobile" value="enable"<?php if ( $s_options['special_on_mobile'] ) echo ' checked="checked"'; ?> >
												<label for="special_on_mobile"><?php esc_html_e( 'Special Social Share Icons for mobile.', 'safelayout-elegant-icons' ); ?></label><br><br>
												<div id="sl-ei-social-icon-box" style="display: none;">
													<label for="s_title_mobile"><?php esc_html_e( 'Social share title for mobile: ', 'safelayout-elegant-icons' ); ?></label>
													<input type="text" style="width: 500px" name="safelayout_icons_social_options[s_title_mobile]" id="s_title_mobile" value="<?php echo esc_attr( $s_options['s_title_mobile'] ); ?>" placeholder="<?php esc_html_e( 'Share:', 'safelayout-elegant-icons' ); ?>" ><br><br>
													<div class="sl-ei-social-icon-container"><?php echo wp_kses( stripslashes( str_replace( '<a', '<div', str_replace( '</a', '</div', $s_options['s_code_mobile'] ) ) ), $allowed_html ); ?></div>
													<br><button class="button" id="sl-ei-social-edit-mobile" disabled><?php esc_html_e( 'Edit mobile social icons', 'safelayout-elegant-icons' ); ?></button>
													<input class="sl-ei-social-attributes" type="hidden" name="safelayout_icons_social_options[s_attributes_mobile]" value="<?php echo htmlspecialchars( wp_kses( $s_options['s_attributes_mobile'], $allowed_html ) ); ?>">
													<input class="sl-ei-social-code" type="hidden" name="safelayout_icons_social_options[s_code_mobile]" value="<?php echo htmlspecialchars( wp_kses( stripslashes( $s_options['s_code_mobile'] ), $allowed_html ) ); ?>">
												<div>
											</td>
										</tr>
										<tr>
											<th scope="row"><?php esc_html_e( 'Display on', 'safelayout-elegant-icons' ); ?></th>
											<td>
												<input type="checkbox" name="safelayout_icons_social_options[display_on_post]" id="display_on_post" value="enable"<?php if ( $s_options['display_on_post'] ) echo ' checked="checked"'; ?> >
												<label for="display_on_post"><?php
													esc_html_e( 'Display in posts at the ', 'safelayout-elegant-icons' );
													$this->print_social_placement( 'display_on_post_place', $s_options['display_on_post_place'] );
												?></label><br><br>
												<input type="checkbox" name="safelayout_icons_social_options[display_on_page]" id="display_on_page" value="enable"<?php if ( $s_options['display_on_page'] ) echo ' checked="checked"'; ?> >
												<label for="display_on_page"><?php
													esc_html_e( 'Display in pages at the ', 'safelayout-elegant-icons' );
													$this->print_social_placement( 'display_on_page_place', $s_options['display_on_page_place'] );
												?></label><br><br>
												<input type="checkbox" name="safelayout_icons_social_options[display_on_front]" id="display_on_front" value="enable"<?php if ( $s_options['display_on_front'] ) echo ' checked="checked"'; ?> >
												<label for="display_on_front"><?php
													esc_html_e( 'Display in posts on the front page at the ', 'safelayout-elegant-icons' );
													$this->print_social_placement( 'display_on_front_place', $s_options['display_on_front_place'] );
												?></label><br><br>
												<input type="checkbox" name="safelayout_icons_social_options[display_on_search]" id="display_on_search" value="enable"<?php if ( $s_options['display_on_search'] ) echo ' checked="checked"'; ?> >
												<label for="display_on_search"><?php
													esc_html_e( 'Display in posts on search pages at the ', 'safelayout-elegant-icons' );
													$this->print_social_placement( 'display_on_search_place', $s_options['display_on_search_place'] );
												?></label><br><br>
												<input type="checkbox" name="safelayout_icons_social_options[display_on_archive]" id="display_on_archive" value="enable"<?php if ( $s_options['display_on_archive'] ) echo ' checked="checked"'; ?> >
												<label for="display_on_archive"><?php
													esc_html_e( 'Display in posts on archive pages at the ', 'safelayout-elegant-icons' );
													$this->print_social_placement( 'display_on_archive_place', $s_options['display_on_archive_place'] );
												?></label><br><br>
												<input type="checkbox" name="safelayout_icons_social_options[display_on_woo]" id="display_on_woo" value="enable"<?php if ( $s_options['display_on_woo'] ) echo ' checked="checked"'; ?> >
												<label for="display_on_woo"><?php
													esc_html_e( 'Display on Woocommerce product pages after product', 'safelayout-elegant-icons' );
													$this->print_social_placement_woo( 'display_on_woo_place', $s_options['display_on_woo_place'] );
												?></label><br><br>
											</td>
										</tr>
										<tr>
											<th scope="row"><?php esc_html_e( 'Exclude page/post', 'safelayout-elegant-icons' ); ?></th>
											<td>
												<input type="checkbox" name="safelayout_icons_social_options[exclude_IDs]" id="exclude_IDs" value="enable"<?php if ( $s_options['exclude_IDs'] ) echo ' checked="checked"'; ?> >
												<label for="exclude_IDs"><?php esc_html_e( 'Exclude specific posts/pages ( Select from the list ).', 'safelayout-elegant-icons' ); ?></label><br>
				 								<input type="hidden" id="exclude_IDs_value" name="safelayout_icons_social_options[exclude_IDs_value]" value="<?php echo esc_attr( $s_options['exclude_IDs_value'] ); ?>" >
												<div class="sl-ei-exclude-social-select" id="exclude_IDs_select">
												<?php 
													$pages = $this->get_page_list();
													$count = 0;
													foreach ( $pages as $page ) {
														$key = $this->check_list( esc_attr( $s_options['exclude_IDs_value'] ), esc_html( $page[0] ) );
														echo '<input class="sl-ei-exclude-list-id" type="checkbox" id="specific_exclude_id_list_' . esc_html( $count ) .
															'" value="' . esc_html( $page[0] ) . '" ' . checked( esc_attr( $key ), true, false ) .
															' /><label' . ( $key ? ' class="sl-ei-list-selected"' : '' ) . ' for="specific_exclude_id_list_' .
															esc_html( $count++ ) . '" title="' . esc_html( $page[1] ) . '">' . esc_html( $page[1] ) . '</label><br />';
													}
												?>
												</div>
											</td>
										</tr>
									</tbody>
								</table>
							</div>
							<div style="height: 50px;margin-top:40px">
								<?php submit_button( esc_html__( 'Save Changes', 'safelayout-elegant-icons' ), 'primary', 'submit_btn', false ); ?>
								<span style="margin: 15px;"></span>
								<?php submit_button( esc_html__( 'Restore Defaults', 'safelayout-elegant-icons' ), 'delete', 'delete_btn', false ); ?>
							</div>
						<?php endif; ?>
					</form>
					<div id="sl-ei-social-modal">
						<div class="sl-ei-social-window">
							<div class="sl-ei-social-header"><?php esc_html_e( 'Edit Social Share (Safelayout)', 'safelayout-elegant-icons' ); ?></div>
							<div id="sl-ei-social-body" social-helper-id="not set yet">
							</div>
							<div class="sl-ei-social-footer">
								<a id="sl-ei-social-submit" class="button"><?php esc_html_e( 'OK', 'safelayout-elegant-icons' ); ?></a>
								<a id="sl-ei-social-cancel" class="button"><?php esc_html_e( 'Cancel', 'safelayout-elegant-icons' ); ?></a> 
							</div>
						</div>
					</div>
				</div>
			</div>
			<?php
		}

		// Return list of all posts and pages
		public function get_page_list() {
			$arr = [];
			$pages = get_pages( array( 'number' => 200 ) );
			if ( is_array( $pages ) ) {
				foreach ($pages as $page) {
					$arr[] = [$page->ID , __( '[Page]', 'safelayout-elegant-icons' ) . ' ' . $page->post_title ];
				}
			}

			$posts = get_posts( array( 'numberposts' => 100 ) );
			if ( is_array($posts) && !empty($posts) && gettype($posts[0]) === 'object') {
				foreach ($posts as $post) {
					$arr[] = [$post->ID , __( '[Post]', 'safelayout-elegant-icons' ) . ' ' . $post->post_title ];
				}
			}

			return $arr;
		}

		// Return true if val is in list
		public function check_list( $list, $val ) {
			if ( trim($list) === '' ) {
				return false;
			}
			$arr = explode( ',', $list );
			$arr = array_map('trim', $arr);
			return in_array( $val, $arr );
		}

		// print social placement html code
		public function print_social_placement( $id, $val ) {
			echo '<select id="' . esc_html( $id ) . '" name="safelayout_icons_social_options[' . esc_html( $id ) . ']">' .
				 '<option value="bottom"' . ( 'bottom' == esc_html( $val ) ? ' selected="selected"' : '' ) . ' >bottom</option>' .
				 '<option value="top"' . ( 'top' == esc_html( $val ) ? ' selected="selected"' : '' ) . ' >top</option>' .
				 '<option value="both"' . ( 'both' == esc_html( $val ) ? ' selected="selected"' : '' ) . ' >top and bottom</option></select>';
		}

		// print social placement html code for Woocommerce
		public function print_social_placement_woo( $id, $val ) {
			echo ' <select id="' . esc_html( $id ) . '" name="safelayout_icons_social_options[' . esc_html( $id ) . ']">' .
				 '<option value="summary"' . ( 'summary' == esc_html( $val ) ? ' selected="selected"' : '' ) . ' >summary</option>' .
				 '<option value="content"' . ( 'content' == esc_html( $val ) ? ' selected="selected"' : '' ) . ' >content</option></select>';
		}

		// Add settings fields
		public function add_settings_fields() {
			register_setting(
				'safelayout_icons_packs_group_1',
				'safelayout_icons_packs',
				array( $this, 'option_sanitize' )
			);
			register_setting(
				'safelayout_icons_packs_group_2',
				'safelayout_icons_social_options',
				array( $this, 'option_sanitize_social' )
			);
		}

		// Add js & css file for settings page
		public function enqueue_scripts( $hook ) {
			if ( ! $hook || $hook != $this->options_page_hook ) {
				return;
			}
			wp_enqueue_style(
				'safelayout-elegant-icons-style-admin',
				SAFELAYOUT_ICONS_URL . 'assets/css/safelayout-elegant-icons-admin.min.css',
				array(),
				SAFELAYOUT_ICONS_VERSION
			);
			wp_enqueue_script(
				'safelayout-elegant-icons-script-admin',
				SAFELAYOUT_ICONS_URL . 'assets/js/safelayout-elegant-icons-admin.min.js',
				array( 'jquery' ),
				SAFELAYOUT_ICONS_VERSION,
				true
			);
			$this->load_packs();
			$this->load_mce_assets();
			$this->load_social_assets();
		}

		// Sanitize options
		public function option_sanitize_social( $input ) {
			$allowed_html = Safelayout_elegant_icons::allowed_html( array(), 'post' );
			$options = $this->get_social_share_options();
			
			//purge cache
			$this->purge_cache();

			$sanitary_values = array();
			
			$sanitary_values['version'] = SAFELAYOUT_ICONS_VERSION;
			// Restore Defaults
			if ( isset( $_POST["delete_btn"] ) ) {
				return $sanitary_values;
			}

			if ( isset( $input['enable_social'] ) ) {
				$sanitary_values['enable_social'] = sanitize_text_field( $input['enable_social'] );
			} else {
				$options['enable_social'] = '';
				return $options;

			}

			if ( isset( $input['s_title'] ) ) {
				$sanitary_values['s_title'] = wp_kses( $input['s_title'], $allowed_html );
			}

			if ( isset( $input['s_attributes'] ) ) {
				$sanitary_values['s_attributes'] = wp_kses( htmlspecialchars_decode( $input['s_attributes'] ), $allowed_html );
			}

			if ( isset( $input['s_code'] ) ) {
				$sanitary_values['s_code'] = addslashes( wp_kses( htmlspecialchars_decode( $input['s_code'] ), $allowed_html ) );
			}

			if ( isset( $input['hide_on_mobile'] ) ) {
				$sanitary_values['hide_on_mobile'] = true;
			} else {
				$sanitary_values['hide_on_mobile'] = false;
			}

			if ( isset( $input['special_on_mobile'] ) ) {
				$sanitary_values['special_on_mobile'] = true;
			} else {
				$sanitary_values['special_on_mobile'] = false;
			}

			if ( isset( $input['s_title_mobile'] ) ) {
				$sanitary_values['s_title_mobile'] = wp_kses( $input['s_title_mobile'], $allowed_html );
			}

			if ( isset( $input['s_attributes_mobile'] ) ) {
				$sanitary_values['s_attributes_mobile'] = wp_kses( htmlspecialchars_decode( $input['s_attributes_mobile'] ), $allowed_html );
			}

			if ( isset( $input['s_code_mobile'] ) ) {
				$sanitary_values['s_code_mobile'] = addslashes( wp_kses( htmlspecialchars_decode( $input['s_code_mobile'] ), $allowed_html ) );
			}

			if ( isset( $input['exclude_IDs'] ) ) {
				$sanitary_values['exclude_IDs'] = true;
			} else {
				$sanitary_values['exclude_IDs'] = false;
			}

			if ( isset( $input['exclude_IDs_value'] ) ) {
				$sanitary_values['exclude_IDs_value'] = sanitize_text_field( $input['exclude_IDs_value'] );
			}

			if ( isset( $input['display_on_post'] ) ) {
				$sanitary_values['display_on_post'] = true;
			} else {
				$sanitary_values['display_on_post'] = false;
			}

			if ( isset( $input['display_on_post_place'] ) ) {
				$sanitary_values['display_on_post_place'] = sanitize_text_field( $input['display_on_post_place'] );
			}

			if ( isset( $input['display_on_page'] ) ) {
				$sanitary_values['display_on_page'] = true;
			} else {
				$sanitary_values['display_on_page'] = false;
			}

			if ( isset( $input['display_on_page_place'] ) ) {
				$sanitary_values['display_on_page_place'] = sanitize_text_field( $input['display_on_page_place'] );
			}

			if ( isset( $input['display_on_front'] ) ) {
				$sanitary_values['display_on_front'] = true;
			} else {
				$sanitary_values['display_on_front'] = false;
			}

			if ( isset( $input['display_on_front_place'] ) ) {
				$sanitary_values['display_on_front_place'] = sanitize_text_field( $input['display_on_front_place'] );
			}

			if ( isset( $input['display_on_search'] ) ) {
				$sanitary_values['display_on_search'] = true;
			} else {
				$sanitary_values['display_on_search'] = false;
			}

			if ( isset( $input['display_on_search_place'] ) ) {
				$sanitary_values['display_on_search_place'] = sanitize_text_field( $input['display_on_search_place'] );
			}

			if ( isset( $input['display_on_archive'] ) ) {
				$sanitary_values['display_on_archive'] = true;
			} else {
				$sanitary_values['display_on_archive'] = false;
			}

			if ( isset( $input['display_on_archive_place'] ) ) {
				$sanitary_values['display_on_archive_place'] = sanitize_text_field( $input['display_on_archive_place'] );
			}

			if ( isset( $input['display_on_woo'] ) ) {
				$sanitary_values['display_on_woo'] = true;
			} else {
				$sanitary_values['display_on_woo'] = false;
			}

			if ( isset( $input['display_on_woo_place'] ) ) {
				$sanitary_values['display_on_woo_place'] = sanitize_text_field( $input['display_on_woo_place'] );
			}

			return $sanitary_values;
		}

		// Sanitize options
		public function option_sanitize( $input ) {
			if ( ! isset( $_POST["safelayout-elegant-icons-validate-key"] ) ) {
				return $input;
			}
			$packs = $this->get_packs();
			$packs['version'] = SAFELAYOUT_ICONS_VERSION;
			$key = false;
			
			foreach ( $packs['icons'] as $index => $pack ) {
				$id = 'safelayout-' . esc_html( $pack['file_name'] );
				if ( isset( $input[ $id ] ) ) {
					$packs['icons'][$index]['active'] = 'yes';
					$key = true;
				} else {
					$packs['icons'][$index]['active'] = 'no';
				}
			}
			if ( $key ) {
				return $packs;
			} else {
				return $this->get_packs();
			}
		}

		// Return default packs
		public function get_default_packs() {
			$default = array(
				'version'	=> SAFELAYOUT_ICONS_VERSION,
				'icons'		=> [
					array( 'name' => 'Themeisle',					'active' => 'yes', 'file_name' => 'themeisle-icons' ),
					array( 'name' => 'Wordpress Dashicons',			'active' => 'yes', 'file_name' => 'wordpress-dashicons-icons' ),
					array( 'name' => 'Wordpress',					'active' => 'yes', 'file_name' => 'wordpress-icons' ),
				],
			);
			return $default;
		}

		// Return packs
		public function get_packs() {
			$packs = get_option( 'safelayout_icons_packs' );
			if ( ! $packs ) {
				$packs = $this->get_default_packs();
				update_option( 'safelayout_icons_packs', $packs );
			}
			return $packs;
		}

		//purge cache
		public static function purge_cache() {
			if ( function_exists( 'w3tc_pgcache_flush' ) ) { // W3 Total Cache
				w3tc_pgcache_flush();
			} else if ( function_exists( 'wp_cache_clean_cache' ) ) { // WP Super Cache
				global $file_prefix, $supercachedir;
				if ( empty( $supercachedir ) && function_exists( 'get_supercache_dir' ) ) {
					$supercachedir = get_supercache_dir();
				}
				wp_cache_clean_cache( $file_prefix );
			} else if ( class_exists( 'WpeCommon' ) ) { // WPEngine Cache
				//be extra careful, just in case 3rd party changes things on us
				if ( method_exists( 'WpeCommon', 'purge_memcached' ) ) {
					WpeCommon::purge_memcached();
				}
				if ( method_exists( 'WpeCommon', 'clear_maxcdn_cache' ) ) {
					WpeCommon::clear_maxcdn_cache();
				}
				if ( method_exists( 'WpeCommon', 'purge_varnish_cache' ) ) {
					WpeCommon::purge_varnish_cache();   
				}
			} else if ( method_exists( 'WpFastestCache', 'deleteCache' ) && !empty( $wp_fastest_cache ) ) { // WP Fastest Cache
				$wp_fastest_cache->deleteCache( true );
			} else if ( class_exists( 'WP_Optimize' ) && defined( 'WPO_PLUGIN_MAIN_PATH' ) ) { // WP Optimize Cache
				if ( !class_exists('WP_Optimize_Cache_Commands') ) {
					include_once(WPO_PLUGIN_MAIN_PATH . 'cache/class-cache-commands.php');
				}

				if ( class_exists( 'WP_Optimize_Cache_Commands' ) ) {
					$wpoptimize_cache_commands = new WP_Optimize_Cache_Commands();
					$wpoptimize_cache_commands->purge_page_cache();
				}
			} else if ( class_exists( 'Breeze_Admin' ) ) { // Breeze Cache
				do_action('breeze_clear_all_cache');
			} else if ( defined( 'LSCWP_V' ) ) { // LiteSpeed Cache
				do_action( 'litespeed_purge_all' );
			} else if ( function_exists( 'sg_cachepress_purge_cache' ) ) { // SiteGround SuperCacher
				sg_cachepress_purge_cache();
			} else if ( class_exists( 'autoptimizeCache' ) ) { // Autoptimize
				if ( method_exists( 'autoptimizeCache', 'clearall' ) ) {
					autoptimizeCache::clearall();   
				}
			} else if ( class_exists( 'Cache_Enabler' ) ) { // Cache Enabler
				if ( method_exists( 'Cache_Enabler', 'clear_total_cache' ) ) {
					Cache_Enabler::clear_total_cache();   
				}
			} else if ( function_exists( 'rocket_clean_domain' ) ) { // WP Rocket
				rocket_clean_domain();
				if ( function_exists( 'rocket_clean_minify' ) ) {
					rocket_clean_minify();
				}
			}
		}

		// Add allowed html tags
		public static function allowed_html( $tags, $context ) {
			$my_tags = array();
			if ( 'post' === $context ) {
				$my_tags['div'] = array(
					'class' => true,
					'id' => true,
					'style' => true,
					'sldataicon' => true,
					'aria-label' => true,
					'title' => true,
				);

				$my_tags['ul'] = array(
					'id' => true,
					'style' => true,
					'aria-label' => true,
					'title' => true,
					'class' => true,
				);

				$my_tags['li'] = array(
					'id' => true,
					'style' => true,
					'aria-label' => true,
					'title' => true,
					'class' => true,
				);

				$my_tags['a'] = array(
					'id' => true,
					'style' => true,
					'href' => true,
					'target' => true,
					'rel' => true,
					'aria-label' => true,
					'title' => true,
					'class' => true,
				);

				$my_tags['span'] = array(
					'id' => true,
					'class' => true,
					'style' => true,
					'iconpos' => true,
					'icongap' => true,
					'dataicon' => true,
					'sldataicon' => true,
					'aria-label' => true,
					'title' => true,
				);

				$my_tags['style'] = array(
					'id' => true,
					'type' => true,
					'data-*' => true,
				);

				$my_tags['br'] = array();

				$my_tags['p'] = array(
					'class' => true,
					'style' => true,
				);

				$my_tags['h1'] = array(
					'class' => true,
					'style' => true,
				);

				$my_tags['h2'] = array(
					'class' => true,
					'style' => true,
				);

				$my_tags['h3'] = array(
					'class' => true,
					'style' => true,
				);

				$my_tags['h4'] = array(
					'class' => true,
					'style' => true,
				);

				$my_tags['h5'] = array(
					'class' => true,
					'style' => true,
				);

				$my_tags['h6'] = array(
					'class' => true,
					'style' => true,
				);

				$my_tags['sl-bb-custom1359'] = array(
					'id' => true,
					'type' => true,
					'data-*' => true,
				);

				$my_tags['svg'] = array(
					'id' => true,
					'class' => true,
					'style' => true,
					'viewbox' => true,
					'filter' => true,
					'focusable' => true,
					'xmlns' => true,
					'preserveaspectratio' => true,
					'aria-hidden' => true,
					'data-*' => true,
					'role' => true,
					'height' => true,
					'width' => true,
				);

				$my_tags['defs'] = array(
					'id' => true,
				);

				$my_tags['lineargradient'] = array(
					'id' => true,
					'x1' => true,
					'y1' => true,
					'x2' => true,
					'y2' => true,
				);

				$my_tags['radialgradient'] = array(
					'id' => true,
					'cx' => true,
					'cy' => true,
					'r' => true,
					'fx' => true,
					'fy' => true,
				);

				$my_tags['stop'] = array(
					'stop-color' => true,
					'offset' => true,
					'stop-opacity' => true,
				);

				$my_tags['ellipse'] = array(
					'id' => true,
					'class' => true,
					'style' => true,
					'filter' => true,
					'cx' => true,
					'cy' => true,
					'rx' => true,
					'ry' => true,
					'fill' => true,
				);

				$my_tags['g'] = array(
					'id' => true,
					'class' => true,
					'style' => true,
					'filter' => true,
					'viewbox' => true,
					'fill' => true,
					'stroke' => true,
				);

				$my_tags['rect'] = array(
					'id' => true,
					'class' => true,
					'style' => true,
					'filter' => true,
					'x' => true,
					'y' => true,
					'width' => true,
					'height' => true,
					'rx' => true,
					'fill' => true,
					'stroke' => true,
					'stroke-width' => true,
				);

				$my_tags['path'] = array(
					'id' => true,
					'class' => true,
					'style' => true,
					'filter' => true,
					'd' => true,
					'fill' => true,
					'stroke' => true,
					'stroke-width' => true,
					'vector-effect' => true,
				);

				$my_tags['symbol'] = array(
					'id' => true,
					'class' => true,
					'style' => true,
					'filter' => true,
					'x' => true,
					'y' => true,
					'width' => true,
					'height' => true,
					'viewbox' => true,
				);

				$my_tags['use'] = array(
					'id' => true,
					'class' => true,
					'style' => true,
					'filter' => true,
					'viewbox' => true,
					'href' => true,
					'xlink:href' => true,
				);
			}

			return array_replace_recursive( $tags, $my_tags );
		}

		// Add allowed css style
		public function allowed_css( $styles ) {
			$styles[] = 'transform';
			$styles[] = 'display';
			$styles[] = 'text-shadow';
			$styles[] = 'user-select';
			return $styles;
		}

		//add icon block to core navigation
		public function add_icon_blocks_to_core_blocks( $args, $block_type ) {
			if ( 'core/navigation' === $block_type || 'core/navigation-link' === $block_type) {
				$args['allowed_blocks'] ??= [];
				$args['allowed_blocks'][] = 'safelayout/safelayout-icon';
				$args['allowed_blocks'][] = 'safelayout/safelayout-box-button';
			}
			return $args;
		}

		// Add allowed css for css value contains \ ( & } = or comments
		public function attr_allow_css( $allow_css, $css_test_string ) {
			if ( strpos( $css_test_string, 'filter' ) === false &&
				strpos( $css_test_string, 'text-shadow' ) === false &&
				strpos( $css_test_string, 'box-shadow' ) === false &&
				strpos( $css_test_string, 'background' ) === false &&
				strpos( $css_test_string, 'color' ) === false &&
				strpos( $css_test_string, 'border' ) === false &&
				strpos( $css_test_string, '--sl' ) === false &&
				strpos( $css_test_string, 'transform' ) === false ) {
				return $allow_css;
			} else {
				return true;
			}
		}
	}
	new Safelayout_elegant_icons();
}