<?php
/**
 * The admin-specific functionality of the plugin.
 *
 * @since      1.0.0
 * @author     Elicus <hello@elicus.com>
 * @copyright  2026 Elicus Technologies Private Limited
 */

// if this file is called directly, abort.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
use Elementor\Settings;
use Elementor\Utils;
if ( ! class_exists( 'WPMOZO_Addons_Lite_For_Elementor_Admin' ) ) {
	class WPMOZO_Addons_Lite_For_Elementor_Admin {

		/**
		 * The unique identifier of this plugin.
		 *
		 * @since    1.0.0
		 * @access   private
		 * @var      string
		 */
		private $plugin_name;

		/**
		 * The current version of the plugin.
		 *
		 * @since    1.0.0
		 * @access   private
		 * @var      string
		 */
		private $plugin_version;

		/**
		 * Plugin Basename.
		 *
		 * @since    1.0.0
		 * @access   private
		 * @var      string
		 */
		private $plugin_basename;

		/**
		 * Plugin Option.
		 *
		 * @since    1.0.0
		 * @access   private
		 * @var      string
		 */
		private $plugin_option;

		/**
		 * Setting page title.
		 *
		 * @since    1.6.1
		 * @access   private
		 * @var      string
		 */
		private $page_title;

		/**
		 * Admin menu title.
		 *
		 * @since    1.6.1
		 * @access   private
		 * @var      string
		 */
		private $menu_title;

		/**
		 * Settings page slug.
		 *
		 * @since    1.6.1
		 * @access   private
		 * @var      string
		 */
		private $menu_slug;

		/**
		 * Plugin option page hook.
		 *
		 * @since    1.0.0
		 * @access   private
		 * @var      string
		 */
		private $hook_suffix;

		/**
		 * Settings Class Object.
		 *
		 * @since    1.6.1
		 * @access   private
		 * @var      Object
		 */
		private $settings;

		/**
		 * Add Class if pro version active.
		 *
		 * @since    1.6.1
		 * @access   private
		 * @var      Object
		 */
		private $proactive;

		/**
		 * Check if divi plus is active.
		 *
		 * @since    1.6.1
		 * @access   public
		 * @var      Object
		 */
		public $diviplus_active;

		/**
		 * Initialize the class and set its properties.
		 *
		 * @since    1.0.0
		 */
		public function __construct( $settings ) {
			$this->page_title      = esc_html__( 'WPMozo Addons Lite for Elementor', 'wpmozo-addons-for-elementor' );
			$this->menu_title      = esc_html__( 'Addons for Elementor', 'wpmozo-addons-for-elementor' );
			$this->menu_slug       = WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_SLUG;
			$this->plugin_name     = WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_SLUG;
			$this->plugin_version  = WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_VERSION;
			$this->plugin_option   = WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_OPTION;
			$this->plugin_basename = WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_BASENAME;
			$this->settings        = $settings;
			if( defined( 'WPMOZO_ADDONS_FOR_ELEMENTOR_VERSION' ) ){
				$this->proactive = 'proactive';
			}
			if( 'Divi' === wp_get_theme()->Name && defined( 'ELICUS_DIVI_PLUS_VERSION' ) ){
				$this->diviplus_active = true;
			}
		}
		/**
		 *
		 * Modifies the "Thank you" text displayed in the admin footer.
		 *
		 * @since 1.9.0
		 * @param string $footer_text.
		 * @return string
		 */
		public function admin_footer_text( $footer_text ) {
			$current_screen = get_current_screen();
			$is_wpmozo_screen = ( $current_screen && false !== strpos( $current_screen->id, 'wpmozo-addons' ) );

			if ( $is_wpmozo_screen ) {
				$footer_text = sprintf(
					/* translators: 1: WPMozo Addons Lite for Elementor, 2: Link to plugin review */
					__( 'Help us grow! If you like our work Rate %1$s %2$s and support us.', 'wpmozo-addons-lite-for-elementor' ),
					'<strong>' . esc_html__( 'WPMozo Addons Lite for Elementor', 'wpmozo-addons-lite-for-elementor' ) . '</strong>',
					'<a href="https://wordpress.org/support/plugin/wpmozo-addons-lite-for-elementor/reviews/#new-post" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a>'
				);
			}

			return $footer_text;
		}


		/**
		 * Register the stylesheets for the admin area.
		 *
		 * @since    1.0.0
		 */
		public function enqueue_styles( $hook_suffix ) {

			wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'assets/css/admin.min.css', array(), $this->plugin_version );

			wp_enqueue_style( $this->plugin_name."-icons", plugin_dir_url( __DIR__ ) . 'assets/css/wpmozoicon/wpmozoicon.min.css', array(), $this->plugin_version );
		}

		/**
		 * Register the JavaScript for the admin area.
		 *
		 * @since    1.0.0
		 */
		public function enqueue_scripts( $hook_suffix ) {
			$nonce = wp_create_nonce( $this->plugin_name . '-admin-nonce' );
			wp_register_script( 'wpmozo-ae-popper', plugins_url( 'assets/js/popper/popper.min.js', plugin_dir_path( __FILE__ ) ), array( 'jquery' ), WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_VERSION, false );

			wp_enqueue_script( 'wpmozo-ae-popper');

			wp_register_script( 'wpmozo-ae-tippy', plugins_url( 'assets/js/tippyBundle/tippy-bundle.min.js', plugin_dir_path( __FILE__ ) ), array( 'jquery' ), WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_VERSION, false );

			wp_enqueue_script( 'wpmozo-ae-tippy');
			wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'assets/js/admin.min.js', array( 'jquery' ), $this->plugin_version, false );


			wp_localize_script(
				$this->plugin_name,
				'wpmozo_ae_lite_admin_ajax_object',
				array(
					'ajaxurl'    => admin_url( 'admin-ajax.php' ),
					'ajax_nonce' => $nonce,
				)
			);
		}

		/**
		 * Register the admin menu for the plugin.
		 *
		 * @since    1.6.1
		 */
		public function admin_menu() {
			$svg_path          = WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_DIR_PATH . 'admin/assets/images/brandicon.svg';
			$this->hook_suffix = add_menu_page($this->page_title, $this->menu_title, 'manage_options', 'wpmozo-addons-for-elementor', array( $this, 'plugin_settings' ), 'data:image/svg+xml;base64,' . base64_encode( file_get_contents( $svg_path ) ), 85 );
		}

		/**
		 * Display settings in the admin area.
		 *
		 * @since    1.6.1
		 */
		public function plugin_settings() {
			?>
				<div class="wpmozo_ae_panel_wrapper <?php echo esc_attr($this->proactive)?>">
					<div class="wpmozo_ae_panel_header">
						<div class="wpmozo_ae_panel_logo">
							<img src="<?php echo esc_url( 'https://wpmozoaddons.com/wp-content/uploads/2023/12/wpmozo-addons-for-elementor-logo.webp' ); ?>" />
						</div>
						<ul class="wpmozo_ae_panel_menu">
							<?php if (!defined('WPMOZO_ADDONS_FOR_ELEMENTOR_VERSION')){ ?>
							<span class="wpmozo_ae_upgrade_to_pro"><a href="https://wpmozoaddons.com/pricing/" target="_blank">Upgrade to Pro</a></span>

							<?php }
							?>
							<li class="wpmozo_ae_panel_menu_item wpmozo_ae_panel_active_menu_item" data-href="#wpmozo_ae_panel_general_section">
								<?php echo esc_html__( 'General', 'wpmozo-addons-lite-for-elementor' ); ?>
									
							</li>
							<?php
						    /**
						     * Allow pro version to add more tabs to the menu.
						     *
						     * @since 1.6.1
						     */
						    echo apply_filters( 'wpmozo_ae_settings_tabs', '' );
						    ?>
						</ul>
					</div>
					<?php if (!defined('WPMOZO_ADDONS_FOR_ELEMENTOR_VERSION')){ ?>
					<div class="wpmozo_ae_banner">
						<a href="https://wpmozo.com/black-friday#wpmz-ae-bf-sale" target="_blank">
							<img src="https://cdn.wpmozoaddons.com/wpmozo-addons-for-elementor/thumbnails/sale-banner/wpmozo-sale-banner.webp">
						</a>
					</div>
					<?php } ?>
					<div class="wpmozo_ae_panel_section_wrapper" >
						<?php include_once plugin_dir_path( __FILE__ ) . 'partials/admin-display.php'; ?>
						<?php
					    /**
					     * Allow Pro version to add more tab sections.
					     *
					     * @since 1.6.1
					     */
					    do_action( 'wpmozo_ae_settings_tab_content' );
					    ?>
						<div class="wpmozo_ae_panel_ajax_processor wpmozo_ae_panel_loader">
							<div class="wpmozo_ae_panel_processor"></div>
						</div>
					</div>
				</div>
			<?php
		}

		/**
		 * Save settings in the database.
		 *
		 * @since    1.6.1
		 */
		public function save_options() {
			$nonce = $this->plugin_name . '-admin-nonce';
			check_ajax_referer( $nonce, 'security', true );
			// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
			$options       = isset( $_POST['options'] ) ? $_POST['options'] : array();
			$plugin_option = get_option( $this->plugin_option, array() );
			if ( is_array( $options ) && ! empty( $options ) ) {
				foreach ( $options as $option ) {
					$name                   = sanitize_text_field( $option['name'] );
					$value                  = sanitize_text_field( $option['value'] );
					$plugin_option[ $name ] = $value;
				}
			}

			update_option( $this->plugin_option, $plugin_option );
			echo 'success';
			exit;
		}

		/**
		 * Displays Settings link on plugin page
		 *
		 * @since    1.6.1
		 */
		public function plugin_action_links( $links ) {
			$links['wpmozo_settings'] = '<a href="' . esc_url( admin_url( 'admin.php?page=wpmozo-addons-for-elementor' ) ) . '">' . esc_html__( 'Settings', 'wpmozo-addons-lite-for-elementor' ) . '</a>';
			
			$upgrade_text = esc_html__( 'Upgrade To Pro', 'wpmozo-addons-lite-for-elementor' );

			$links['wpmozo_upgrade_to_pro'] = sprintf( '<a href="%1$s" target="_blank" class="wpmozo_addons_upgrade">%2$s</a>', 'https://wpmozo.com/product/wpmozo-addons-for-elementor/', $upgrade_text );
			
			return $links;
		}
		/**
		 * Remove Plugin action links.
		 *
		 * Removew upgrade action links from the plugin list table
		 *
		 * @since 2.0.0
		 * @access public
		 *
		 * @param array $links An array of plugin action links.
		 *
		 * @return array An array of plugin action links.
		 */
		public function wpmozo_remove_upgrade_action_links( $links ) {
			unset($links['wpmozo_upgrade_to_pro']);
			return $links;
		}

		/**
		 * Displays custom links in plugin row
		 *
		 * @since    1.6.1
		 */
		public function plugin_row_meta( $links, $plugin_file, $plugin_data, $status ) {
			if ( strpos( $plugin_file, $this->plugin_name . '.php' ) !== false ) {
				$links[] = '<a href="' . esc_url( admin_url( '?page=' . $this->plugin_name ) ) . '">' . esc_html__( 'Settings', 'wpmozo-addons-lite-for-elementor' ) . '</a>';
				$links[] = '<a href="' . esc_url( 'https://documentation.wpmozo.com/' . $this->plugin_name ) . '">' . esc_html__( 'Documentation', 'wpmozo-addons-lite-for-elementor' ) . '</a>';
			}
			return $links;
		}
        /**
    	 * Check if blog categories related widgets are disabled.
    	 *
    	 * @since    1.1.0
    	 */
    	public function wpmozo_is_widget_disabled( $widgets ) {
    		$widgets = explode(',',$widgets);
            $plugin_options = get_option( WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_OPTION );
            if ( isset( $plugin_options['wpmozo_inactive_widgets'] ) ) {
                $all_widgets = explode( ',', $plugin_options['wpmozo_inactive_widgets'] );
                if (
                    count( array_intersect($widgets, $all_widgets) ) === count( $widgets ) 
                ) {
                    return true;
                }
            } else {
                return false;
            }

            return false;
        }
        /**
         * Add image field for category,
         * for add category form.
         * 
         * @since 1.19.0
         */
        public function wpmozo_add_post_category_image_field( $taxonomy ) {
        	// Placeholder image.
        	$placeholder_image = WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_DIR_URL . "admin/assets/images/wpmozo-placeholder-300.png";
        	?>
        	<div class="form-field term-group">
        		<label for="wpmozo_category_thumbnail"><?php esc_html_e( 'Category Image', 'wpmozo-addons-lite-for-elementor' ); ?></label>
        		<div id="wpmozo_category_thumbnail_preview" style="float:left; margin-right:10px;">
        			<img src="<?php echo esc_url( $placeholder_image ); ?>" width="60px" height="60px" />
        		</div>
        		<div style="line-height:60px;">
        			<input type="hidden" id="wpmozo_category_thumbnail" name="wpmozo_category_thumbnail" value="" />
        			<button type="button" class="wpmozo_upload_category_image_button button"><?php esc_html_e( 'Upload/Add image', 'wpmozo-addons-lite-for-elementor' ); ?></button>
        			<button type="button" class="wpmozo_remove_category_image_button button" style="display: none;"><?php esc_html_e( 'Remove image', 'wpmozo-addons-lite-for-elementor' ); ?></button>
        		</div>

        		<?php
        		// Nonce for security — action/field names can be anything unique.
        		wp_nonce_field( 'wpmozo_save_category_image', 'wpmozo_category_image_nonce' ); ?>
        		<div class="clear"></div>
        	</div>
        	<?php
        }

        /**
         * Add image field for category,
         * for edit category form.
         * 
         * @since 1.19.0
         */
        public function wpmozo_edit_post_category_image_field( $term, $taxonomy ) {
        	$image_id  = get_term_meta( $term->term_id, 'wpmozo_category_thumbnail', true );
        	$image_url = $image_id ? wp_get_attachment_thumb_url( $image_id ) : WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_DIR_URL . "admin/assets/images/wpmozo-placeholder-300.png";
        	?>
        	<tr class="form-field term-group-wrap">
        		<th scope="row"><label><?php esc_html_e( 'Category Image', 'wpmozo-addons-lite-for-elementor' ); ?></label></th>
        		<td>
        			<div id="wpmozo_category_thumbnail_preview" style="float:left; margin-right:10px;">
        				<img src="<?php echo esc_url( $image_url ); ?>" width="60px" height="60px" />
        			</div>
        			<div style="line-height:60px;">
        				<input type="hidden" id="wpmozo_category_thumbnail" name="wpmozo_category_thumbnail" value="<?php echo esc_attr( $image_id ); ?>" />
        				<button type="button" class="wpmozo_upload_category_image_button button"><?php esc_html_e( 'Upload/Add image', 'wpmozo-addons-lite-for-elementor' ); ?></button>
        				<button type="button" class="wpmozo_remove_category_image_button button"
        					style="<?php echo ( empty( $image_id ) ) ? 'display: none' : ''; ?>"
        				><?php esc_html_e( 'Remove image', 'wpmozo-addons-lite-for-elementor' ); ?></button>
        			</div>
        			<?php
        			// Nonce for security — action/field names can be anything unique.
        			wp_nonce_field( 'wpmozo_save_category_image', 'wpmozo_category_image_nonce' ); ?>
        			<div class="clear"></div>
        		</td>
        	</tr>
        	<?php
        }

        /**
         * Save post category image.
         * 
         * @since 1.19.0
         */
        public function wpmozo_save_post_category_image( $term_id, $tt_id ) {
        	// Verify nonce — use wp_verify_nonce so function doesn't die (safer in hooks).
        	if (
        		! isset( $_POST['wpmozo_category_image_nonce'] ) ||
        		! wp_verify_nonce(
        			sanitize_text_field( wp_unslash( $_POST['wpmozo_category_image_nonce'] ) ),
        			'wpmozo_save_category_image'
        		)
        	) {
        		return;
        	}

        	// Optional: capability check (extra safety).
        	if ( ! current_user_can( 'manage_categories' ) ) {
        		return;
        	}
        	
        	if ( isset( $_POST['wpmozo_category_thumbnail'] ) ) {
        		update_term_meta( $term_id, 'wpmozo_category_thumbnail', absint( $_POST['wpmozo_category_thumbnail'] ) );
        	}
        }

        /**
         * Category Image column.
         * 
         * @param mixed $columns Columns array.
         * @return array
         * 
         * @since 1.19.0
         */
        public function wpmozo_category_image_columns( $columns ) {
        	$new_columns = array();
        	if ( isset( $columns['cb'] ) ) {
        		$new_columns['cb'] = $columns['cb'];
        		unset( $columns['cb'] );
        	}

        	$new_columns['wpmozo_image'] = __( 'Image', 'woocommerce' );

        	$columns           = array_merge( $new_columns, $columns );
        	$columns['handle'] = '';

        	return $columns;
        }

        /**
         * Category image column value added.
         *
         * @param string $columns Column HTML output.
         * @param string $column Column name.
         * @param int    $id Product ID.
         *
         * @return string
         * 
         * @since 1.19.0
         */
        public function wpmozo_category_image_column( $columns, $column, $id ) {
        	if ( 'wpmozo_image' === $column ) {

        		// Get image url.
        		$image_id  = get_term_meta( $id, 'wpmozo_category_thumbnail', true );
        		$image_url = $image_id ? wp_get_attachment_thumb_url( $image_id ) : WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_DIR_URL . "admin/assets/images/wpmozo-placeholder-300.png";
        		
        		// Final Image.
        		$columns = '<img src="' . esc_url( $image_url ) . '" alt="' . esc_attr__( 'Category Image', 'wpmozo-addons-lite-for-elementor' ) . '" class="wp-post-image" height="48" width="48" />';
        	}
        	return $columns;
        }

        /**
         * Add category upload image.
         * 
         * @since 1.19.0
         */
        public function wpmozo_blog_category_enqueue_scripts( $hook ) {
        	// Load only on category edit/add pages.
        	if ( 'edit-tags.php' !== $hook && 'term.php' !== $hook ) {
        		return;
        	}

        	wp_enqueue_media();
        	wp_enqueue_script( 'jquery' );

        	// Load image upload field script.
        	wp_enqueue_script( 'wpmozo-category-media-upload-script', WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_DIR_URL . "admin/assets/js/category-media-upload.min.js", array('jquery'), WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_VERSION, true );

        	// Localize variables.
        	wp_localize_script( 'wpmozo-category-media-upload-script', 'wpmozoMediaUploadObj', array(
        		'frame_title'        => esc_html__( 'Select or Upload Image', 'wpmozo-addons-lite-for-elementor' ),
        		'upload_button_text' => esc_html__( 'Use this image', 'wpmozo-addons-lite-for-elementor' ),
        		'placeholder_image'  => WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_DIR_URL . "admin/assets/images/wpmozo-placeholder-300.png",
        	) );
        }

		// Team member post type registration.
		/**
		 * Register custom post for team members.
		 *
		 * @since    1.0.0
		 */
		public function wpmozo_register_post_types() {

			if ( ! $this->wpmozo_is_widget_disabled('team-slider,team-grid') ) {
				$team_labels = array(
					'name'                  => esc_html__( 'WPMozo Team Members', 'wpmozo-addons-lite-for-elementor' ),
					'singular_name'         => esc_html__( 'WPMozo Team Member', 'wpmozo-addons-lite-for-elementor' ),
					'menu_name'             => esc_html__( 'WPMozo Team Members', 'wpmozo-addons-lite-for-elementor' ),
					'add_new'               => esc_html__( 'Add New', 'wpmozo-addons-lite-for-elementor' ),
					'add_new_item'          => esc_html__( 'Add New Member', 'wpmozo-addons-lite-for-elementor' ),
					'edit_item'             => esc_html__( 'Edit Member', 'wpmozo-addons-lite-for-elementor' ),
					'new_item'              => esc_html__( 'New Member', 'wpmozo-addons-lite-for-elementor' ),
					'view_item'             => esc_html__( 'View Member', 'wpmozo-addons-lite-for-elementor' ),
					'all_items'             => esc_html__( 'All Members', 'wpmozo-addons-lite-for-elementor' ),
					'search_items'          => esc_html__( 'Search Members', 'wpmozo-addons-lite-for-elementor' ),
					'not_found'             => esc_html__( 'No member found', 'wpmozo-addons-lite-for-elementor' ),
					'not_found_in_trash'    => esc_html__( 'No members found in Trash', 'wpmozo-addons-lite-for-elementor' ),
					'featured_image'        => esc_html__( 'Team Member Image', 'wpmozo-addons-lite-for-elementor' ),
					'set_featured_image'    => esc_html__( 'Set team member image', 'wpmozo-addons-lite-for-elementor' ),
					'remove_featured_image' => esc_html__( 'Remove team member image', 'wpmozo-addons-lite-for-elementor' ),
					'use_featured_image'    => esc_html__( 'Use as team member image', 'wpmozo-addons-lite-for-elementor' ),
					'parent_item_colon'     => esc_html__( 'Parent Member:', 'wpmozo-addons-lite-for-elementor' ),
				);

				$team_args = array(
					'labels'            => $team_labels,
					'description'       => esc_html__( 'WPMozo Team Members Custom Post', 'wpmozo-addons-lite-for-elementor' ),
					'public'            => true,
					'supports'          => array( 'title', 'editor', 'author', 'thumbnail', 'revisions' ),
					'taxonomies'        => array( 'wpmozo-ae-team-member-category' ),
					'hierarchical'      => false,
					'menu_position'     => 20,
					'menu_icon'         => 'data:image/svg+xml;base64,' . base64_encode( file_get_contents( WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_DIR_PATH . 'admin/assets/images/team-member-icon.svg' ) ),
					'show_ui'           => true,
					'show_in_menu'      => true,
					'show_in_nav_menus' => true,
					'show_in_rest'      => true,
					'has_archive'       => true,
					'query_var'         => true,
					'capability_type'   => 'post',
				);
				register_post_type( 'wpmozoae-team-member', $team_args );
			}
			if ( ! $this->wpmozo_is_widget_disabled('testimonial-slider,testimonial-grid') ) {
				$testimonial_labels = array(
					'name'                  => esc_html__( 'WPMozo Testimonials', 'wpmozo-addons-lite-for-elementor' ),
					'singular_name'         => esc_html__( 'WPMozo Testimonial', 'wpmozo-addons-lite-for-elementor' ),
					'menu_name'             => esc_html__( 'WPMozo Testimonials', 'wpmozo-addons-lite-for-elementor' ),
					'add_new'               => esc_html__( 'Add New', 'wpmozo-addons-lite-for-elementor' ),
					'add_new_item'          => esc_html__( 'Add New Testimonial', 'wpmozo-addons-lite-for-elementor' ),
					'edit_item'             => esc_html__( 'Edit Testimonial', 'wpmozo-addons-lite-for-elementor' ),
					'new_item'              => esc_html__( 'New Testimonial', 'wpmozo-addons-lite-for-elementor' ),
					'view_item'             => esc_html__( 'View Testimonial', 'wpmozo-addons-lite-for-elementor' ),
					'all_items'             => esc_html__( 'All Testimonials', 'wpmozo-addons-lite-for-elementor' ),
					'search_items'          => esc_html__( 'Search Testimonials', 'wpmozo-addons-lite-for-elementor' ),
					'not_found'             => esc_html__( 'No testimonial found', 'wpmozo-addons-lite-for-elementor' ),
					'not_found_in_trash'    => esc_html__( 'No testimonial found in Trash', 'wpmozo-addons-lite-for-elementor' ),
					'featured_image'        => esc_html__( 'Testimonial Image', 'wpmozo-addons-lite-for-elementor' ),
					'set_featured_image'    => esc_html__( 'Set testimonial image', 'wpmozo-addons-lite-for-elementor' ),
					'remove_featured_image' => esc_html__( 'Remove testimonial member image', 'wpmozo-addons-lite-for-elementor' ),
					'use_featured_image'    => esc_html__( 'Use as testimonial image', 'wpmozo-addons-lite-for-elementor' ),
					'parent_item_colon'     => esc_html__( 'Parent Testimonial:', 'wpmozo-addons-lite-for-elementor' ),
				);

				$testimonial_args = array(
					'labels'            => $testimonial_labels,
					'description'       => esc_html__( 'WPMozo Testimonial Custom Post', 'wpmozo-addons-lite-for-elementor' ),
					'public'            => true,
					'supports'          => array( 'title', 'editor', 'author', 'thumbnail', 'revisions' ),
					'taxonomies'        => array( 'wpmozo-ae-testimonial-member-category' ),
					'hierarchical'      => false,
					'menu_position'     => 20,
					'menu_icon'         => 'data:image/svg+xml;base64,' . base64_encode( file_get_contents( WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_DIR_PATH . 'admin/assets/images/testimonial-icon.svg' ) ),
					'show_ui'           => true,
					'show_in_menu'      => true,
					'show_in_nav_menus' => true,
					'show_in_rest'      => true,
					'has_archive'       => true,
					'query_var'         => true,
					'capability_type'   => 'post',
				);
				register_post_type( 'wpmozoae-testimonial', $testimonial_args );
			}
			return ;
		}

		/**
		 * Register taxonomies for custom post of team members.
		 *
		 * @since    1.0.0
		 */
		public function wpmozo_register_taxonomies() {
			if ( ! $this->wpmozo_is_widget_disabled('team-slider,team-grid') ) {
				$team_labels = array(
					'name'                       => esc_html_x( 'Categories', 'Taxonomy General Name', 'wpmozo-addons-lite-for-elementor' ),
					'singular_name'              => esc_html_x( 'Category', 'Taxonomy Singular Name', 'wpmozo-addons-lite-for-elementor' ),
					'menu_name'                  => esc_html__( 'Categories', 'wpmozo-addons-lite-for-elementor' ),
					'all_items'                  => esc_html__( 'All Team Member Categories', 'wpmozo-addons-lite-for-elementor' ),
					'parent_item'                => esc_html__( 'Parent Team Member Category', 'wpmozo-addons-lite-for-elementor' ),
					'parent_item_colon'          => esc_html__( 'Parent Team Member Category:', 'wpmozo-addons-lite-for-elementor' ),
					'new_item_name'              => esc_html__( 'New Team Member Category Name', 'wpmozo-addons-lite-for-elementor' ),
					'add_new_item'               => esc_html__( 'Add New Team Member Category', 'wpmozo-addons-lite-for-elementor' ),
					'edit_item'                  => esc_html__( 'Edit Team Member Category', 'wpmozo-addons-lite-for-elementor' ),
					'update_item'                => esc_html__( 'Update Team Member Category', 'wpmozo-addons-lite-for-elementor' ),
					'view_item'                  => esc_html__( 'View Team Member Category', 'wpmozo-addons-lite-for-elementor' ),
					'separate_items_with_commas' => esc_html__( 'Separate categories with commas', 'wpmozo-addons-lite-for-elementor' ),
					'add_or_remove_items'        => esc_html__( 'Add or remove categories', 'wpmozo-addons-lite-for-elementor' ),
					'choose_from_most_used'      => esc_html__( 'Choose from the most used', 'wpmozo-addons-lite-for-elementor' ),
					'popular_items'              => esc_html__( 'Popular Team Member Categories', 'wpmozo-addons-lite-for-elementor' ),
					'search_items'               => esc_html__( 'Search Team Member Categories', 'wpmozo-addons-lite-for-elementor' ),
					'not_found'                  => esc_html__( 'Not Found', 'wpmozo-addons-lite-for-elementor' ),
					'no_terms'                   => esc_html__( 'No Team Member Categories', 'wpmozo-addons-lite-for-elementor' ),
					'items_list'                 => esc_html__( 'Team Member Categories list', 'wpmozo-addons-lite-for-elementor' ),
					'items_list_navigation'      => esc_html__( 'Team Member Categories list navigation', 'wpmozo-addons-lite-for-elementor' ),
				);
				$team_args   = array(
					'labels'            => $team_labels,
					'hierarchical'      => true,
					'public'            => true,
					'show_ui'           => true,
					'show_admin_column' => true,
					'show_in_nav_menus' => true,
					'show_tagcloud'     => true,
				);
				register_taxonomy( 'wpmozo-ae-team-member-category', array( 'wpmozoae-team-member' ), $team_args );
			}
			if ( ! $this->wpmozo_is_widget_disabled('testimonial-slider,testimonial-grid') ) {
				$testimonial_labels = array(
					'name'                       => esc_html_x( 'Categories', 'Taxonomy General Name', 'wpmozo-addons-lite-for-elementor' ),
					'singular_name'              => esc_html_x( 'Category', 'Taxonomy Singular Name', 'wpmozo-addons-lite-for-elementor' ),
					'menu_name'                  => esc_html__( 'Categories', 'wpmozo-addons-lite-for-elementor' ),
					'all_items'                  => esc_html__( 'All Testimonial Categories', 'wpmozo-addons-lite-for-elementor' ),
					'parent_item'                => esc_html__( 'Parent Testimonial Category', 'wpmozo-addons-lite-for-elementor' ),
					'parent_item_colon'          => esc_html__( 'Parent Testimonial Category:', 'wpmozo-addons-lite-for-elementor' ),
					'new_item_name'              => esc_html__( 'New Testimonial Category Name', 'wpmozo-addons-lite-for-elementor' ),
					'add_new_item'               => esc_html__( 'Add New Testimonial Category', 'wpmozo-addons-lite-for-elementor' ),
					'edit_item'                  => esc_html__( 'Edit Testimonial Category', 'wpmozo-addons-lite-for-elementor' ),
					'update_item'                => esc_html__( 'Update Testimonial Category', 'wpmozo-addons-lite-for-elementor' ),
					'view_item'                  => esc_html__( 'View Testimonial Category', 'wpmozo-addons-lite-for-elementor' ),
					'separate_items_with_commas' => esc_html__( 'Separate categories with commas', 'wpmozo-addons-lite-for-elementor' ),
					'add_or_remove_items'        => esc_html__( 'Add or remove categories', 'wpmozo-addons-lite-for-elementor' ),
					'choose_from_most_used'      => esc_html__( 'Choose from the most used', 'wpmozo-addons-lite-for-elementor' ),
					'popular_items'              => esc_html__( 'Popular Testimonial Categories', 'wpmozo-addons-lite-for-elementor' ),
					'search_items'               => esc_html__( 'Search Testimonial Categories', 'wpmozo-addons-lite-for-elementor' ),
					'not_found'                  => esc_html__( 'Not Found', 'wpmozo-addons-lite-for-elementor' ),
					'no_terms'                   => esc_html__( 'No Testimonial Categories', 'wpmozo-addons-lite-for-elementor' ),
					'items_list'                 => esc_html__( 'Testimonial Categories list', 'wpmozo-addons-lite-for-elementor' ),
					'items_list_navigation'      => esc_html__( 'Testimonial Categories list navigation', 'wpmozo-addons-lite-for-elementor' ),
				);
				$testimonial_args   = array(
					'labels'            => $testimonial_labels,
					'hierarchical'      => true,
					'public'            => true,
					'show_ui'           => true,
					'show_admin_column' => true,
					'show_in_nav_menus' => true,
					'show_tagcloud'     => true,
				);
				register_taxonomy( 'wpmozo-ae-testimonial-category', array( 'wpmozoae-testimonial' ), $testimonial_args );
			}
			return ; 
		}

		/**
		 * Add metabox for custom post of team members.
		 *
		 * @since    1.0.0
		 */
		public function wpmozo_ae_team_member_metabox_callback( $post ) {
			$values       = get_post_custom( $post->ID );
			$short_desc   = isset( $values['wpmozo_ae_team_member_short_desc'] ) ? $values['wpmozo_ae_team_member_short_desc'][0] : '';
			$designation  = isset( $values['wpmozo_ae_team_member_designation'] ) ? $values['wpmozo_ae_team_member_designation'][0] : '';
			$website_url  = isset( $values['wpmozo_ae_team_member_website'] ) ? $values['wpmozo_ae_team_member_website'][0] : '';
			$linkedin     = isset( $values['wpmozo_ae_team_member_linkedin'] ) ? $values['wpmozo_ae_team_member_linkedin'][0] : '';
			$facebook     = isset( $values['wpmozo_ae_team_member_facebook'] ) ? $values['wpmozo_ae_team_member_facebook'][0] : '';
			$twitter      = isset( $values['wpmozo_ae_team_member_twitter'] ) ? $values['wpmozo_ae_team_member_twitter'][0] : '';
			$instagram    = isset( $values['wpmozo_ae_team_member_instagram'] ) ? $values['wpmozo_ae_team_member_instagram'][0] : '';
			$youtube      = isset( $values['wpmozo_ae_team_member_youtube'] ) ? $values['wpmozo_ae_team_member_youtube'][0] : '';
			$email        = isset( $values['wpmozo_ae_team_member_email'] ) ? $values['wpmozo_ae_team_member_email'][0] : '';
			$phone        = isset( $values['wpmozo_ae_team_member_phone'] ) ? $values['wpmozo_ae_team_member_phone'][0] : '';
			$skills       = isset( $values['wpmozo_ae_team_member_skills'] ) ? $values['wpmozo_ae_team_member_skills'][0] : '';
			$skills_value = isset( $values['wpmozo_ae_team_member_skills_value'] ) ? $values['wpmozo_ae_team_member_skills_value'][0] : '';

			wp_nonce_field( 'wpmozo_metaboxes_nonce', 'wpmozo_ae_team_member_metabox_nonce' );

			$allowed_html = array(
				'p'      => array(
					'id'    => array(),
					'class' => array(),
				),
				'ul'     => array(
					'id'    => array(),
					'class' => array(),
				),
				'ol'     => array(
					'id'    => array(),
					'class' => array(),
				),
				'li'     => array(
					'id'    => array(),
					'class' => array(),
				),
				'span'   => array(
					'id'    => array(),
					'class' => array(),
				),
				'strong' => array(
					'id'    => array(),
					'class' => array(),
				),
				'b'      => array(
					'id'    => array(),
					'class' => array(),
				),
				'a'      => array(
					'href'  => array(),
					'id'    => array(),
					'class' => array(),
				),
				'br'     => array(
					'id'    => array(),
					'class' => array(),
				),
				'h1'     => array(
					'id'    => array(),
					'class' => array(),
				),
				'h2'     => array(
					'id'    => array(),
					'class' => array(),
				),
				'h3'     => array(
					'id'    => array(),
					'class' => array(),
				),
				'h4'     => array(
					'id'    => array(),
					'class' => array(),
				),
				'h5'     => array(
					'id'    => array(),
					'class' => array(),
				),
				'h6'     => array(
					'id'    => array(),
					'class' => array(),
				),
			);

			?>
			<div class="wpmozo_meta_fields">
				<label for="wpmozo_ae_team_member_short_desc">
					<?php esc_html_e( 'Short Description', 'wpmozo-addons-lite-for-elementor' ); ?>
				</label>
				<textarea type="text" name="wpmozo_ae_team_member_short_desc" class="wpmozo_ae_team_member_short_desc"><?php echo wp_kses( $short_desc, $allowed_html ); ?></textarea>
				<span class="info"><?php echo esc_html__( 'Support for few HTML tags like h1,h2,h3,h4,h5,h6,p,ul,ol,li,span,strong,b,a,br', 'wpmozo-addons-lite-for-elementor' ); ?></span>
			</div>
			<div class="wpmozo_meta_fields">
				<label for="wpmozo_ae_team_member_designation">
					<?php esc_html_e( 'Designation', 'wpmozo-addons-lite-for-elementor' ); ?>
				</label>
				<input type="text" name="wpmozo_ae_team_member_designation" class="wpmozo_ae_team_member_designation" value="<?php echo esc_attr( $designation ); ?>" />
			</div>
			<div class="wpmozo_meta_fields">
				<label for="wpmozo_ae_team_member_email">
					<?php esc_html_e( 'Email Address', 'wpmozo-addons-lite-for-elementor' ); ?>
				</label>
				<input type="email" name="wpmozo_ae_team_member_email" class="wpmozo_ae_team_member_email" value="<?php echo esc_attr( $email ); ?>" />
			</div>
			<div class="wpmozo_meta_fields">
				<label for="wpmozo_ae_team_member_phone">
					<?php esc_html_e( 'Phone Number', 'wpmozo-addons-lite-for-elementor' ); ?>
				</label>
				<input type="tel" name="wpmozo_ae_team_member_phone" class="wpmozo_ae_team_member_phone" value="<?php echo esc_attr( $phone ); ?>" />
			</div>
			<div class="wpmozo_meta_fields">
				<label for="wpmozo_ae_team_member_website">
					<?php esc_html_e( 'Website Url', 'wpmozo-addons-lite-for-elementor' ); ?>
				</label>
				<input type="url" name="wpmozo_ae_team_member_website" class="wpmozo_ae_team_member_website" value="<?php echo esc_attr( $website_url ); ?>" />
			</div>
			<div class="wpmozo_meta_fields">
				<label for="wpmozo_ae_team_member_facebook">
					<?php esc_html_e( 'Facebook Url', 'wpmozo-addons-lite-for-elementor' ); ?>
				</label>
				<input type="url" name="wpmozo_ae_team_member_facebook" class="wpmozo_ae_team_member_facebook" value="<?php echo esc_attr( $facebook ); ?>" />
			</div>
			<div class="wpmozo_meta_fields">
				<label for="wpmozo_ae_team_member_twitter">
					<?php esc_html_e( 'Twitter Url', 'wpmozo-addons-lite-for-elementor' ); ?>
				</label>
				<input type="url" name="wpmozo_ae_team_member_twitter" class="wpmozo_ae_team_member_twitter" value="<?php echo esc_attr( $twitter ); ?>" />
			</div>
			<div class="wpmozo_meta_fields">
				<label for="wpmozo_ae_team_member_linkedin">
					<?php esc_html_e( 'Linkedin Url', 'wpmozo-addons-lite-for-elementor' ); ?>
				</label>
				<input type="url" name="wpmozo_ae_team_member_linkedin" class="wpmozo_ae_team_member_linkedin" value="<?php echo esc_attr( $linkedin ); ?>" />
			</div>
			<div class="wpmozo_meta_fields">
				<label for="wpmozo_ae_team_member_instagram">
					<?php esc_html_e( 'Instagram Url', 'wpmozo-addons-lite-for-elementor' ); ?>
				</label>
				<input type="url" name="wpmozo_ae_team_member_instagram" class="wpmozo_ae_team_member_instagram" value="<?php echo esc_attr( $instagram ); ?>" />
			</div>
			<div class="wpmozo_meta_fields">
				<label for="wpmozo_ae_team_member_youtube">
					<?php esc_html_e( 'Youtube Url', 'wpmozo-addons-lite-for-elementor' ); ?>
				</label>
				<input type="url" name="wpmozo_ae_team_member_youtube" class="wpmozo_ae_team_member_youtube" value="<?php echo esc_attr( $youtube ); ?>" />
			</div>
			<div class="wpmozo_meta_fields">
				<label for="wpmozo_ae_team_member_youtube">
					<?php esc_html_e( 'Skills', 'wpmozo-addons-lite-for-elementor' ); ?>
				</label>
				<div class="wpmozo_repeator_meta_fields">
					<input type="hidden" id="wpmozo_ae_team_member_skills" name="wpmozo_ae_team_member_skills" value="<?php echo esc_attr( $skills ); ?>" required />
					<input type="hidden" id="wpmozo_ae_team_member_skills_value" name="wpmozo_ae_team_member_skills_value" value="<?php echo esc_attr( $skills_value ); ?>" />
					<?php
						$skills       = explode( ',', $skills );
						$skills_value = explode( ',', $skills_value );
					if ( is_array( $skills ) && ! empty( array_filter( $skills ) ) ) {
						if ( count( $skills ) > 1 ) {
							$row_control = '<span class="wpmozo_repeator_meta_field_add_row_control wpmozo_repeator_meta_field_remove_row">-</span>';
						} else {
							$row_control = '';
						}
						$count = count( $skills );
						for ( $i = 0; $i < $count; $i++ ) {
							$skill_value = array_key_exists( $i, $skills_value ) ? absint( $skills_value[ $i ] ) : 100;
							?>
							<div class="wpmozo_repeator_meta_field_row">
								<div class="wpmozo_repeator_meta_field">
									<input type="text" class="wpmozo_ae_team_member_skills" value="<?php echo esc_attr( $skills[ $i ] ); ?>" placeholder="Skill" required />
									<input type="number" class="wpmozo_ae_team_member_skills_value" value="<?php echo esc_attr( $skill_value ); ?>" placeholder="Skill Value Between 0 to 100" step="1" min="0" max="100"/>
								</div>
								<p class="wpmozo_repeator_meta_field_row_controls">
									<?php echo wp_kses_post( $row_control ); ?>
									<?php
									if ( ( count( $skills ) - 1 ) === $i ) {
										?>
										<span class="wpmozo_repeator_meta_field_add_row_control wpmozo_repeator_meta_field_add_row">+</span>
										<?php
									}
									?>
								</p>
							</div>
							<?php
						}
					} else {
						?>
						<div class="wpmozo_repeator_meta_field_row">
							<div class="wpmozo_repeator_meta_field">
								<input type="text" class="wpmozo_ae_team_member_skills" placeholder="Skill" required />
								<input type="number" class="wpmozo_ae_team_member_skills_value" placeholder="Skill Value Between 0 to 100" step="1" min="0" max="100" />
							</div>
							<p class="wpmozo_repeator_meta_field_row_controls">
								<span class="wpmozo_repeator_meta_field_add_row_control wpmozo_repeator_meta_field_add_row">+</span>
							</p>
						</div>
						<?php
					}
					?>
				</div> 
			</div>
			<?php
		}

		/**
		 * Add metabox for custom post of testimonials.
		 *
		 * @since    1.3.0
		 */
		public function wpmozo_ae_testimonial_metabox_callback( $post ) {
	        wp_nonce_field( 'wpmozo_ae_metaboxes_nonce', 'wpmozo_ae_testimonial_metabox_nonce' );
	        $author_name        = get_post_meta( $post->ID, 'wpmozo_ae_testimonial_author_name', true );
	        $author_email       = get_post_meta( $post->ID, 'wpmozo_ae_testimonial_author_email', true );
	        $author_designation = get_post_meta( $post->ID, 'wpmozo_ae_testimonial_author_designation', true );
	        $author_company     = get_post_meta( $post->ID, 'wpmozo_ae_testimonial_author_company', true );
	        $author_company_url = get_post_meta( $post->ID, 'wpmozo_ae_testimonial_author_company_url', true );
	        $author_rating      = get_post_meta( $post->ID, 'wpmozo_ae_testimonial_author_rating', true );
	        $author_rating      = $author_rating ? $author_rating : '5';

	        $ratings = array( '0.5', '1', '1.5', '2', '2.5', '3', '3.5', '4', '4.5', '5' );
	        ?>
			
	        <div class="wpmozo_meta_fields">
	            <label for="wpmozo_ae_testimonial_author_name">
	                <?php esc_html_e( 'Author Name', 'wpmozo-addons-lite-for-elementor' ); ?>
	            </label>
	            <input type="text" id="wpmozo_ae_testimonial_author_name" name="wpmozo_ae_testimonial_author_name" value="<?php echo esc_attr( $author_name ); ?>" />
	        </div>
	        <div class="wpmozo_meta_fields">
	            <label for="wpmozo_ae_testimonial_author_email">
	                <?php esc_html_e( 'Author Email', 'wpmozo-addons-lite-for-elementor' ); ?>
	            </label>
	            <input type="email" id="wpmozo_ae_testimonial_author_email" name="wpmozo_ae_testimonial_author_email" value="<?php echo esc_attr( $author_email ); ?>" />
	        </div>
	        <div class="wpmozo_meta_fields">
	            <label for="wpmozo_ae_testimonial_author_designation">
	                <?php esc_html_e( 'Author Designation', 'wpmozo-addons-lite-for-elementor' ); ?>
	            </label>
	            <input type="text" id="wpmozo_ae_testimonial_author_designation" name="wpmozo_ae_testimonial_author_designation" value="<?php echo esc_attr( $author_designation ); ?>" />
	        </div>
	        <div class="wpmozo_meta_fields">
	            <label for="wpmozo_ae_testimonial_author_company">
	                <?php esc_html_e( 'Author Company', 'wpmozo-addons-lite-for-elementor' ); ?>
	            </label>
	            <input type="text" id="wpmozo_ae_testimonial_author_company" name="wpmozo_ae_testimonial_author_company" value="<?php echo esc_attr( $author_company ); ?>" />
	        </div>
	        <div class="wpmozo_meta_fields">
	            <label for="wpmozo_ae_testimonial_author_company_url">
	                <?php esc_html_e( 'Author Company Url', 'wpmozo-addons-lite-for-elementor' ); ?>
	            </label>
	            <input type="text" id="wpmozo_ae_testimonial_author_company_url" name="wpmozo_ae_testimonial_author_company_url" value="<?php echo esc_attr( $author_company_url ); ?>" />
	        </div>
	        <div class="wpmozo_meta_fields">
	            <label for="wpmozo_ae_testimonial_author_rating">
	                <?php esc_html_e( 'Author Rating', 'wpmozo-addons-lite-for-elementor' ); ?>
	            </label>
	            <select id="wpmozo_ae_testimonial_author_rating" name="wpmozo_ae_testimonial_author_rating">
	                <?php
	                foreach( $ratings as $rating ) {
	                    ?><option value="<?php echo esc_attr( $rating ); ?>" <?php selected( $author_rating, esc_attr( $rating ) ); ?>><?php echo esc_html( $rating ); ?></option><?php
	                }
	                ?>
	            </select>
	        </div>
	        <?php
	    }

		/**
		 * Save data from the meta fields fo custom post for team members.
		 *
		 * @since    1.0.0
		 */
		public function wpmozo_save_team_member_meta_fields( $post_id ) {
			// doing an auto save.
			if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
				return;
			}

			// verify nonce.
			if ( ! isset( $_POST['wpmozo_ae_team_member_metabox_nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['wpmozo_ae_team_member_metabox_nonce'] ) ), 'wpmozo_metaboxes_nonce' ) ) {
				return;
			}

			// if current user can not edit the post.
			if ( ! current_user_can( 'edit_posts', $post_id ) ) {
				return;
			}

			$fields = array(
				'wpmozo_ae_team_member_short_desc',
				'wpmozo_ae_team_member_designation',
				'wpmozo_ae_team_member_website',
				'wpmozo_ae_team_member_linkedin',
				'wpmozo_ae_team_member_facebook',
				'wpmozo_ae_team_member_twitter',
				'wpmozo_ae_team_member_instagram',
				'wpmozo_ae_team_member_youtube',
				'wpmozo_ae_team_member_email',
				'wpmozo_ae_team_member_skills',
				'wpmozo_ae_team_member_skills_value',
				'wpmozo_ae_team_member_phone',
			);

			$allowed_html = array(
				'p'      => array(
					'id'    => array(),
					'class' => array(),
				),
				'ul'     => array(
					'id'    => array(),
					'class' => array(),
				),
				'ol'     => array(
					'id'    => array(),
					'class' => array(),
				),
				'li'     => array(
					'id'    => array(),
					'class' => array(),
				),
				'span'   => array(
					'id'    => array(),
					'class' => array(),
				),
				'strong' => array(
					'id'    => array(),
					'class' => array(),
				),
				'b'      => array(
					'id'    => array(),
					'class' => array(),
				),
				'a'      => array(
					'href'  => array(),
					'id'    => array(),
					'class' => array(),
				),
				'br'     => array(
					'id'    => array(),
					'class' => array(),
				),
				'h1'     => array(
					'id'    => array(),
					'class' => array(),
				),
				'h2'     => array(
					'id'    => array(),
					'class' => array(),
				),
				'h3'     => array(
					'id'    => array(),
					'class' => array(),
				),
				'h4'     => array(
					'id'    => array(),
					'class' => array(),
				),
				'h5'     => array(
					'id'    => array(),
					'class' => array(),
				),
				'h6'     => array(
					'id'    => array(),
					'class' => array(),
				),
			);

			foreach ( $fields as $field ) {
				if ( isset( $_POST[ $field ] ) ) {
					if ( 'wpmozo_ae_team_member_short_desc' === $field ) {
						${$field} = wp_kses( wp_unslash( $_POST[ $field ] ), $allowed_html );
					} else {
						${$field} = sanitize_text_field( wp_unslash( $_POST[ $field ] ) );
					}
					update_post_meta( $post_id, $field, ${$field} );
				}
			}
		}

		/**
		 * Save data from the meta fields fo custom post for team members.
		 *
		 * @since    1.3.0
		 */
		public function wpmozo_save_testimonial_meta_fields( $post_id ) {
	        // doing an auto save.
	        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
	            return;
	        }

	        // verify nonce.
	        if ( ! isset( $_POST['wpmozo_ae_testimonial_metabox_nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['wpmozo_ae_testimonial_metabox_nonce'] ) ), 'wpmozo_ae_metaboxes_nonce' ) ) {
	            return;
	        }

	        // if current user can not edit the post.
	        if ( ! current_user_can( 'edit_posts', $post_id ) ) {
	            return;
	        }

	        $fields = array(
	            'wpmozo_ae_testimonial_author_name',
	            'wpmozo_ae_testimonial_author_email',
	            'wpmozo_ae_testimonial_author_designation',
	            'wpmozo_ae_testimonial_author_company',
	            'wpmozo_ae_testimonial_author_company_url',
	            'wpmozo_ae_testimonial_author_rating',
	        );

	        foreach ( $fields as $field ) {
	            if ( isset( $_POST[ $field ] ) ) {
	                ${$field} = sanitize_text_field( wp_unslash( $_POST[ $field ] ) );
	                update_post_meta( $post_id, $field, ${$field} );
	            }
	        }
	    }

		/**
		 * Callback function to render the meta box.
		 *
		 * @since    1.0.0
		 */
		public function wpmozo_add_team_member_metabox() {
			add_meta_box(
				'wpmozo_ae_team_member_metabox',
				'<img class="wpmozo_ae_meta_image" src="https://wpmozoaddons.com/wp-content/uploads/2023/11/favicon-for-wpmozo-addons-for-elementor.png" />Team Member Information',
				array( $this, 'wpmozo_ae_team_member_metabox_callback' ),
				'wpmozoae-team-member', // Replace 'your_custom_post_type' with the actual name of your custom post type.
				'normal',
				'default'
			);
		}

		/**
		 * Callback function to render the meta box.
		 *
		 * @since    1.3.0
		 */
		public function wpmozo_add_testimonial_metabox() {
			add_meta_box(
				'wpmozo_ae_testimonial_metabox',
				'<img class="wpmozo_ae_meta_image" src="https://wpmozoaddons.com/wp-content/uploads/2023/11/favicon-for-wpmozo-addons-for-elementor.png"/>Testimonial Meta Fields',
				array( $this, 'wpmozo_ae_testimonial_metabox_callback' ),
				'wpmozoae-testimonial', // Replace 'your_custom_post_type' with the actual name of your custom post type.
				'normal',
				'default'
			);
		}

		/**
		 * Runs after WordPress loaded
		 *
		 * @since    1.0.0
		 */
		public function wp_loaded() {
			if ( 'yes' === get_option( 'wpmozo_addons_lite_for_elementor_activated' ) ) {
				delete_option( 'wpmozo_addons_lite_for_elementor_activated' );
			}
			$this->update_active_widgets();
		}

		/**
		 * Runs after WordPress loaded
		 *
		 * @since    1.0.0
		 */
		public function update_active_widgets() {
			$plugin_option 	= get_option( WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_OPTION, array() );
			$widget_version = isset( $plugin_option['wpmozo_addons_lite_for_elementor_version'] ) ? $plugin_option['wpmozo_addons_lite_for_elementor_version'] : '0.0.0';
			if ( version_compare( $widget_version, WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_VERSION, '<' ) ) {
				$all_widgets   = $this->get_all_widgets();
				$plugin_option['wpmozo_addons_lite_for_elementor_version'] = WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_VERSION;
				$plugin_option['wpmozo_lite_widgets'] = implode( ',', $all_widgets );
				if( !isset($plugin_option[ 'wpmozo_inactive_widgets' ] ) ){
					$plugin_option[ 'wpmozo_inactive_widgets' ] = ' '; // To avoid fatal error of array key wpmozo_inactive_widgets not found in pro version.
				}
				update_option( WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_OPTION, $plugin_option );
			}
		}

		/**
		 * Get array of all widgets of the plugin.
		 *
		 * @since    1.0.0
		 */
		private function get_all_widgets() {
			$widgets_path = plugin_dir_path( __DIR__ ) . '/widgets/';
			$widgets      = glob( $widgets_path . '*', GLOB_ONLYDIR );

			if ( ! empty( $widgets ) ) {
				$widgets = array_map( 'basename', $widgets );
				return $widgets;
			}
			return array();
		}
	}
}
