l__( '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; } } } ids ); $img_ids = array_map( 'trim', $img_ids ); } if ( empty( $img_ids ) ) { return null; } // Ensure gallery class is included jet_engine_get_gallery(); return Jet_Engine_Img_Gallery::grid( $img_ids, $args ); } /** * Render images gallery as slider. * * @return [type] [description] */ public function img_gallery_slider( $img_ids = null, $args = array() ) { if ( ! $img_ids ) { return null; } if ( ! is_array( $img_ids ) ) { $img_ids = explode( ',', $img_ids ); $img_ids = array_map( 'trim', $img_ids ); } if ( empty( $img_ids ) ) { return null; } // Ensure gallery class is included jet_engine_get_gallery(); add_filter( 'jet-engine/compatibility/popup-package/the_content', array( 'Jet_Engine_Img_Gallery', 'ensure_slider_js' ) ); ob_start(); Jet_Engine_Img_Gallery::slider( $img_ids, $args ); return ob_get_clean(); } /** * Returns image url by ID * * @param int $img_id * @param string $size * @return string */ public function get_img_url( $img_id, $size ) { return wp_get_attachment_image_url( $img_id, $size ); } /** * Returns image alt by ID * * @param int $img_id * @return string */ public function get_img_alt( $img_id ) { if ( ! $img_id ) { return ''; } $alt = get_post_meta( $img_id, '_wp_attachment_image_alt', true ); if ( ! $alt ) { $attachment = get_post( $img_id ); $alt = $attachment->post_excerpt; if ( ! $alt ) { $alt = $attachment->post_title; } } return $alt; } /** * Returns image field by ID * * @param int $img_id * @param string $field * @return string */ public function get_img_field( $img_id = null, $field = 'title' ) { if ( empty( $img_id ) ) { return ''; } $img_post = get_post( $img_id ); if ( ! $img_post ) { return ''; } $fields_map = array( 'title' => 'post_title', 'caption' => 'post_excerpt', 'description' => 'post_content', ); if ( isset( $fields_map[ $field ] ) ) { $field = $fields_map[ $field ]; } if ( ! isset( $img_post->$field ) ) { return ''; } return $img_post->$field; } /** * Returns image caption by ID * * @param int $img_id * @return string */ public function get_img_caption( $img_id ) { return $this->get_img_field( $img_id, 'caption' ); } /** * Returns image title by ID * * @param int $img_id * @return string */ public function get_img_title( $img_id ) { return $this->get_img_field( $img_id, 'title' ); } /** * Returns image description by ID * * @param int $img_id * @return string */ public function get_img_description( $img_id ) { return $this->get_img_field( $img_id, 'description' ); } /** * Returns attachment file URL by attachment ID * @param int $attachment_id * @return string */ public function get_file_url( $attachment_id ) { return wp_get_attachment_url( $attachment_id ); } /** * Returns Post URL by ID * * @param int $post_id * @return string */ public function get_post_url( $post_id ) { return get_permalink( $post_id ); } /** * Returns Post URL by ID * * @param int $post_id * @return string */ public function get_post_title( $post_id ) { return get_the_title( $post_id ); } /** * Returns Post URL by ID * * @param int $post_id * @return string */ public function get_post_link( $post_id ) { return sprintf( '%2$s', $this->get_post_url( $post_id ), $this->get_post_title( $post_id ) ); } } }