setup_init(); $this->setup_hook(); } } /** * Setup Classes */ private function setup_init() { self::$slug_default = self::$settings; } /** * Setup Hooks */ private function setup_hook() { add_action( 'init', array( $this, 'post_type' ), 9 ); add_action( 'admin_init', array( $this, 'init_dashboard' ) ); add_action( 'in_admin_header', array( $this, 'render_header_dashboard' ) ); add_action( 'admin_menu', array( $this, 'parent_menu' ) ); add_action( 'admin_menu', array( $this, 'child_menu' ) ); add_action( 'admin_footer', array( $this, 'admin_footer' ) ); add_action( 'admin_footer', array( $this, 'print_script_template' ) ); add_filter( 'admin_footer_text', array( $this, 'thankyou_text' ), 99 ); add_filter( 'elementor/settings/controls/checkbox_list_cpt/post_type_objects', array( $this, 'hide_jkit_cpt_from_elementor' ) ); } /** * Get class instance * * @return Dashboard */ public static function instance() { if ( null === static::$instance ) { static::$instance = new static(); } return static::$instance; } /** * Initialize Dashboard */ public function init_dashboard() { if ( is_admin() ) { add_action( 'admin_enqueue_scripts', array( $this, 'load_style' ) ); } if ( isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], array( self::$dashboard, 'jkit-settings', 'jkit-user-data', 'jkit-elements', 'jkit-404' ), true ) ) { add_action( 'admin_enqueue_scripts', array( $this, 'load_asset' ) ); } global $pagenow; $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; if ( $pagenow == 'admin.php' && $page && self::$dashboard === $page ) { wp_safe_redirect( menu_page_url( self::$settings, false ) ); exit; } if ( $pagenow == 'admin.php' && $page && self::$templates === $page ) { wp_safe_redirect( menu_page_url( self::$jkit_header, false ) ); exit; } if ( is_admin() && isset( $_REQUEST['page'] ) && strpos( $_REQUEST['page'], 'jkit' ) !== false ) { add_action( 'in_admin_header', array( $this, 'disable_plugins_notices_jkit_dashboard' ) ); add_filter( 'elementor/admin-top-bar/is-active', '__return_false' ); } } /** * Load style */ public function load_style() { wp_enqueue_style( 'jkit-dashboard', JEG_ELEMENTOR_KIT_URL . '/assets/css/admin/dashboard.css', null, JEG_ELEMENTOR_KIT_VERSION ); } /** * Load scripts */ public function load_asset() { wp_enqueue_style( 'notiflix', JEG_ELEMENTOR_KIT_URL . '/assets/js/notiflix/notiflix.min.css', null, '3.2.5' ); wp_enqueue_script( 'notiflix', JEG_ELEMENTOR_KIT_URL . '/assets/js/notiflix/notiflix.min.js', array(), '3.2.5', true ); wp_register_script( 'jkit-dashboard', JEG_ELEMENTOR_KIT_URL . '/assets/js/dashboard/dashboard.js', array( 'underscore', 'jquery', 'jquery-ui-draggable', 'jquery-ui-sortable', 'notiflix' ), JEG_ELEMENTOR_KIT_VERSION, true ); wp_add_inline_script( 'jkit-dashboard', $this->ajax_url() ); wp_localize_script( 'jkit-dashboard', 'jkit_dashboard_localize', $this->localize_array() ); wp_enqueue_script( 'jkit-dashboard' ); } /** * Type List * * @return array */ public static function post_type_list() { return array( self::$jkit_header => array( 'label' => esc_html__( 'JKIT - Header ', 'jeg-elementor-kit' ), ), self::$jkit_footer => array( 'label' => esc_html__( 'JKIT - Footer ', 'jeg-elementor-kit' ), ), self::$jkit_template => array( 'label' => esc_html__( 'JKIT - Template ', 'jeg-elementor-kit' ), ), ); } /** * Post Type */ public function post_type() { foreach ( self::post_type_list() as $post_type => $data ) { register_post_type( $post_type, array( 'label' => $data['label'], 'public' => true, 'show_ui' => false, 'capability_type' => 'post', 'hierarchical' => false, 'show_in_nav_menus' => false, 'supports' => array( 'title', 'revisions', 'page-attributes', 'elementor' ), 'map_meta_cap' => true, 'rewrite' => array( 'slug' => $post_type, 'with_front' => false, ), ) ); } } /** * Admin Menu * * @return array */ public function get_admin_menu() { $menu[] = array( 'title' => esc_html__( 'Settings', 'jeg-elementor-kit' ), 'menu' => esc_html__( 'Settings', 'jeg-elementor-kit' ), 'slug' => self::$settings, 'action' => array( &$this, 'settings' ), 'priority' => 56, 'icon' => 'fa-cogs', ); $menu[] = array( 'title' => esc_html__( 'User Data', 'jeg-elementor-kit' ), 'menu' => esc_html__( 'User Data', 'jeg-elementor-kit' ), 'slug' => self::$user_data, 'action' => array( &$this, 'user_data' ), 'priority' => 57, 'icon' => 'fa-regular fa-circle-user', ); $menu[] = array( 'title' => esc_html__( 'Elements', 'jeg-elementor-kit' ), 'menu' => esc_html__( 'Elements', 'jeg-elementor-kit' ), 'slug' => 'jkit-elements', 'action' => array( &$this, 'elements' ), 'priority' => 58, 'icon' => 'fa-solid fa-bars-progress', ); $menu[] = array( 'title' => esc_html__( 'Templates', 'jeg-elementor-kit' ), 'menu' => esc_html__( 'Templates', 'jeg-elementor-kit' ), 'slug' => self::$templates, 'action' => array( &$this, 'manage_template' ), 'priority' => 59, 'icon' => 'fa-regular fa-file-lines', 'class' => 'have-jkit-child-menu', ); $menu[] = array( 'title' => esc_html__( 'Header', 'jeg-elementor-kit' ), 'menu' => esc_html__( 'Header', 'jeg-elementor-kit' ), 'slug' => self::$jkit_header, 'action' => array( $this, 'header_template' ), 'parent' => self::$templates, 'priority' => 60, 'class' => 'jkit-child-menu first', ); $menu[] = array( 'title' => esc_html__( 'Footer', 'jeg-elementor-kit' ), 'menu' => esc_html__( 'Footer', 'jeg-elementor-kit' ), 'slug' => self::$jkit_footer, 'action' => array( $this, 'footer_template' ), 'parent' => self::$templates, 'priority' => 61, 'class' => 'jkit-child-menu', ); $menu[] = array( 'title' => esc_html__( 'Not Found 404', 'jeg-elementor-kit' ), 'menu' => esc_html__( 'Not Found 404', 'jeg-elementor-kit' ), 'slug' => 'jkit-404', 'action' => array( $this, 'not_found_template' ), 'parent' => self::$templates, 'priority' => 62, 'class' => 'jkit-child-menu last', ); $menu[] = array( 'title' => esc_html__( 'Need Help?', 'jeg-elementor-kit' ), 'menu' => esc_html__( 'Need Help?', 'jeg-elementor-kit' ), 'slug' => 'support-forum', 'priority' => 63, 'icon' => 'fa-solid fa-life-ring', 'external_link' => 'https://wordpress.org/support/plugin/jeg-elementor-kit/#new-topic-0', 'class' => 'jkit-support-menu', ); return apply_filters( 'jkit_admin_menu', $menu ); } /** * Parent Menu * * @return void */ public function parent_menu() { $args = array( 'page_title' => esc_html__( 'Jeg Elementor Kit', 'jeg-elementor-kit' ), 'menu_title' => esc_html__( 'Jeg Elementor Kit', 'jeg-elementor-kit' ), 'capability' => 'edit_theme_options', 'menu_slug' => self::$slug_default, 'function' => null, 'icon_url' => JEG_ELEMENTOR_KIT_URL . '/assets/img/admin/icon.svg', 'position' => 76, ); $args = apply_filters( 'jkit_parent_menu', $args ); add_menu_page( $args['page_title'], $args['menu_title'], $args['capability'], $args['menu_slug'], $args['function'], $args['icon_url'], $args['position'] ); } /** * Child Menu */ public function child_menu() { $self = $this; $menus = $this->get_admin_menu(); $position = array_column( $menus, 'priority' ); array_multisort( $position, SORT_ASC, $menus ); foreach ( $menus as $key => $menu ) { add_submenu_page( self::$slug_default, $menu['title'], $menu['menu'], 'edit_theme_options', $menu['slug'], function () use ( $self, $menu ) { $self->render_header(); if ( isset( $menu['action'] ) ) { call_user_func( $menu['action'] ); } // $self->render_sidebar(); } ); $this->add_child_menu_class( $key, $menu ); } } /** * Add Class Selector to Child Menu * * @param int $key Menu offset. * @param array $menu List of menu. */ private function add_child_menu_class( $key, $menu ) { global $submenu; if ( isset( $menu['class'] ) ) { // @codingStandardsIgnoreStart $submenu[ self::$slug_default ][ $key ][4] = $menu['class']; // @codingStandardsIgnoreEnd } if ( isset( $menu['external_link'] ) ) { // replace the slug with external url // @codingStandardsIgnoreStart $submenu[ self::$slug_default ][ $key ][2] = $menu['external_link']; // @codingStandardsIgnoreEnd } } /** * Header Dashboard */ public function render_header() { jkit_get_template_part( $this->template_slug, 'header' ); } /** * Footer Dashboard */ public function render_sidebar() { jkit_get_template_part( $this->template_slug, 'sidebar' ); } /** * Dashboard */ public function dashboard() {} /** * Dashboard Content */ public function dashboard_content() { jkit_get_template_part( $this->template_slug, 'content' ); } /** * User Data */ public function settings() { jkit_get_template_part( $this->template_slug, 'settings' ); } /** * User Data */ public function user_data() { jkit_get_template_part( $this->template_slug, 'user-data' ); } /** * Header */ public function header_template() { new Header_Dashboard_Template(); } /** * Footer */ public function footer_template() { new Footer_Dashboard_Template(); } /** * 404 Template */ public function not_found_template() { jkit_get_template_part( $this->template_slug, 'notfound' ); } /** * Manage Template */ public function manage_template() {} /** * Elements */ public function elements() { jkit_get_template_part( $this->template_slug, 'elements' ); } /** * Add ajax URL */ public function ajax_url() { if ( is_admin() ) { $ajax_url = add_query_arg( array( $this->endpoint => 'jkit_user_data' ), esc_url( home_url( '/' ) ) ); return 'var jkit_ajax_url = "' . esc_url( $ajax_url ) . '", jkit_nonce = "' . jkit_create_global_nonce( 'dashboard' ) . '";'; } return null; } /** * Get URL to Elementor Builder * * @param int $post_id Post ID. * * @return string */ public static function editor_url( $post_id ) { $the_id = ( strlen( $post_id ) > 0 ? $post_id : get_the_ID() ); $parameter = array( 'post' => $the_id, 'action' => 'elementor', ); return admin_url( 'post.php' ) . '?' . build_query( $parameter ); } /** * Localize Script */ public function localize_array() { return array( 'something_wrong' => esc_html__( 'Something went wrong', 'jeg-elementor-kit' ), 'save_failed' => esc_html__( 'Save Failed', 'jeg-elementor-kit' ), ); } /** * Admin footer */ public function admin_footer() { ?>
%1$s, thank you for using Jeg Elementor Kit v%4$s. Please take a second to leave us a ★★★★★ rating. We\'d really appreciate your support!', 'jeg-elementor-kit' ), wp_get_current_user()->display_name, 'https://wordpress.org/plugins/jeg-elementor-kit/', 'https://wordpress.org/support/plugin/jeg-elementor-kit/reviews/#new-post', JEG_ELEMENTOR_KIT_VERSION ); } return $text; } /** * Header Dashboard Template */ public function render_header_dashboard() { if ( is_admin() && isset( $_REQUEST['page'] ) && strpos( $_REQUEST['page'], 'jkit' ) !== false ) { ?>
<?php echo JEG_ELEMENTOR_KIT_NAME; ?>

$callbacks ) { foreach ( $callbacks as $name => $details ) { if ( is_array( $details['function'] ) && is_object( $details['function'][0] ) ) { if ( strrpos( \get_class( $details['function'][0] ), 'Jeg\\Elementor_Kit' ) === false ) { $wp_filter['admin_notices']->remove_filter( 'admin_notices', $details['function'], $weight ); } } } } } /** * Filters the list of post type objects used by Elementor. * * @since 2.6.2 * * @param array $post_types_objects List of post type objects used by Elementor. */ public function hide_jkit_cpt_from_elementor( $post_types_objects ) { foreach ( $post_types_objects as $type ) { if ( array_key_exists( $type->name, $this->post_type_list() ) ) { unset( $post_types_objects[ $type->name ] ); } } return $post_types_objects; } }