orce_print_templates [description] * @param array $vars [description] * @return [type] [description] */ public function listing_form_assets( $force_print_templates = false, $vars = array() ) { jet_engine()->register_jet_plugins_js(); /** * Hook fires also in Elemntor editor for inline create listing in Listing Grid widget. * So be careful with enqueuing additional assets on this hook. * @see https://github.com/Crocoblock/issues-tracker/issues/13481 */ do_action( 'jet-engine/templates/before-listing-assets' ); wp_enqueue_script( 'jet-listings-form', jet_engine()->plugin_url( 'assets/js/admin/listings-popup.js' ), array( 'jquery', 'jet-plugins' ), jet_engine()->get_version(), true ); wp_localize_script( 'jet-listings-form', 'JetListingsSettings', apply_filters( 'jet-engine/templates/localized-settings', array_merge( array( 'hasElementor' => jet_engine()->has_elementor(), 'exclude' => array(), 'defaults' => array(), '_nonce' => wp_create_nonce( $this->nonce_action ), ), $vars ) ) ); wp_enqueue_style( 'jet-listings-form', jet_engine()->plugin_url( 'assets/css/admin/listings.css' ), array(), jet_engine()->get_version() ); if ( $force_print_templates ) { $this->print_listings_popup(); } else { add_action( 'admin_footer', array( $this, 'print_listings_popup' ), 999 ); } } /** * Check if we currently on the Listing Items list page. * * @return boolean */ public function is_listings_edit_page() { $screen = get_current_screen(); if ( $screen && $screen->id === 'edit-' . $this->slug() ) { return true; } elseif ( $screen && $screen->id !== 'edit-' . $this->slug() ) { return false; } // Catch the case when screen is not set yet $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : false; if ( $request_uri && false !== strpos( $request_uri, 'edit.php' ) && ! empty( $_GET['post_type'] ) && $this->slug() === $_GET['post_type'] ) { return true; } else { return false; } } public function get_nonce_action() { return $this->nonce_action; } public function listings_page_assets() { if ( ! $this->is_listings_edit_page() ) { return; } $this->listing_form_assets(); jet_engine()->get_video_help_popup( array( 'popup_title' => __( 'What is Listing Grid?', 'jet-engine' ), 'embed' => 'https://www.youtube.com/embed/JxvtMzwHGIw', ) )->wp_page_popup(); } /** * Returns available listing sources list * * @return [type] [description] */ public function get_listing_item_sources() { return apply_filters( 'jet-engine/templates/listing-sources', array( 'posts' => __( 'Posts', 'jet-engine' ), 'query' => __( 'Query Builder', 'jet-engine' ), 'terms' => __( 'Terms', 'jet-engine' ), 'users' => __( 'Users', 'jet-engine' ), 'repeater' => __( 'Repeater Field', 'jet-engine' ), ) ); } public function get_listing_views() { return apply_filters( 'jet-engine/templates/listing-views', array() ); } /** * Print template type form HTML * * @return void */ public function print_listings_popup() { echo $this->admin_screen->get_listing_popup(); } /** * Templates post type slug * * @return string */ public function slug() { return $this->post_type; } /** * Disable metaboxes from Jet Templates * * @return void */ public function disable_metaboxes() { global $wp_meta_boxes; unset( $wp_meta_boxes[ $this->slug() ]['side']['core']['pageparentdiv'] ); } /** * Register templates post type * * @return void */ public function register_post_type() { $args = array( 'labels' => array( 'name' => esc_html__( 'Listing Items/Components', 'jet-engine' ), 'singular_name' => esc_html__( 'Listing Item/Components', 'jet-engine' ), 'add_new' => esc_html__( 'Add New Listing Item', 'jet-engine' ), 'add_new_item' => esc_html__( 'Add New Item', 'jet-engine' ), 'edit_item' => esc_html__( 'Edit Item', 'jet-engine' ), 'new_item' => esc_html__( 'Add New Item', 'jet-engine' ), 'view_item' => esc_html__( 'View Item', 'jet-engine' ), 'search_items' => esc_html__( 'Search Item', 'jet-engine' ), 'not_found' => esc_html__( 'No Templates Found', 'jet-engine' ), 'not_found_in_trash' => esc_html__( 'No Templates Found In Trash', 'jet-engine' ), 'menu_name' => esc_html__( 'My Library', 'jet-engine' ), ), 'public' => false, 'hierarchical' => false, 'show_ui' => true, 'show_in_menu' => false, 'show_in_nav_menus' => false, 'show_in_rest' => true, 'can_export' => true, 'exclude_from_search' => true, 'capability_type' => 'post', 'rewrite' => false, 'supports' => array( 'title', 'editor', /*'thumbnail',*/ 'author', 'elementor', 'custom-fields' ), ); if ( current_user_can( 'edit_posts' ) ) { $args['public'] = true; } register_post_type( $this->slug(), apply_filters( 'jet-engine/templates/post-type/args', $args ) ); } /** * Menu page */ public function add_templates_page() { $views = $this->get_listing_views(); if ( empty( $views ) ) { return; } add_submenu_page( jet_engine()->admin_page, esc_html__( 'Listings/Components', 'jet-engine' ), esc_html__( 'Listings/Components', 'jet-engine' ), 'edit_pages', 'edit.php?post_type=' . $this->slug() ); } /** * Editor templates. * * @param string $template Current template name. * @return string */ public function set_editor_template( $template ) { $found = false; if ( is_singular( $this->slug() ) ) { $found = true; $template = jet_engine()->plugin_path( 'templates/blank.php' ); } if ( $found ) { do_action( 'jet-engine/post-type/editor-template/found' ); } return $template; } } }