plugin_name = $plugin_name; $this->version = $version; $this->post_type = $post_type; // Register the post type add_action('init', array($this, 'register')); // Admin set post columns add_filter('manage_edit-' . $this->post_type . '_columns', array($this, 'set_columns')) ; // Set messages add_filter('post_updated_messages', array($this, 'wpvr_post_updated_messages') ); // Admin edit post columns add_filter('manage_' . $this->post_type . '_posts_custom_column', array($this, 'edit_columns')); add_filter('admin_body_class',array($this, 'add_body_class')); add_filter('admin_head',array($this, 'add_javascript_in_wpvr_admin_page')); // add_action('admin_footer',array($this, 'add_new_tour_modal')); } /** * Adds a modal for creating a new tour. * * This function checks if the current screen is the post type edit screen and * if so, it displays a modal for creating a new tour. The modal includes options * for selecting the tour type, entering the tour name, and submitting the form. * * @return void */ public function add_new_tour_modal() { $current_screen = get_current_screen(); if(!empty($current_screen->post_type) && $current_screen->post_type == $this->post_type && $current_screen->base == 'edit'){ $radio_icon = ''; ?>

post_type) && $current_screen->post_type == $this->post_type && $current_screen->base == 'edit'){ ?> post_type) && $current_screen->post_type == $this->post_type && $current_screen->base == 'post' && $current_screen->action == 'add') { // $tour_title = $_GET['tour_title']; ?> post_type) && $current_screen->post_type == $this->post_type && $current_screen->base == 'edit'){ return 'wpvr-tour-list'; } } /** * Register the custom post type * * @since 8.0.0 */ public function register() { $labels = array( 'name' => __('Tours', $this->plugin_name), 'singular_name' => __('Tours', $this->plugin_name), 'add_new' => __('Add New Tour', $this->plugin_name), 'add_new_item' => __('Add New Tour', $this->plugin_name), 'edit_item' => __('Edit Tour', $this->plugin_name), 'new_item' => __('New Tour', $this->plugin_name), 'view_item' => __('View Tour', $this->plugin_name), 'search_items' => __('Search WP VR Tour', $this->plugin_name), 'not_found' => __('No WP VR Tour found', $this->plugin_name), 'not_found_in_trash'=> __('No WP VR Tour found in Trash', $this->plugin_name), 'parent_item_colon' => '', 'all_items' => __('All Tours', $this->plugin_name), 'menu_name' => __('WP VR', $this->plugin_name), ); $args = array( 'labels' => $labels, 'public' => false, 'show_ui' => true, 'show_in_menu' => false, 'menu_position' => 100, 'supports' => array( 'title' ), 'menu_icon' => plugins_url(). '/wpvr/images/icon.png', 'capabilities' => array( 'edit_post' => 'edit_wpvr_tour', 'edit_posts' => 'edit_wpvr_tours', 'edit_others_posts' => 'edit_other_wpvr_tours', 'publish_posts' => 'publish_wpvr_tours', 'read_post' => 'read_wpvr_tour', 'read_private_posts' => 'read_private_wpvr_tours', 'delete_post' => 'delete_wpvr_tour' ), 'map_meta_cap' => true, ); /** * Documentation : https://codex.wordpress.org/Function_Reference/register_post_type */ register_post_type($this->post_type, $args); } public function copy_shortcode_html() { $copy = ' Copied '; return $copy; } /** * @param $columns * @return mixed * * Choose the columns you want in * the admin table for this post * @since 8.0.0 */ public function set_columns($columns) { // Set/unset post type table columns $columns = array( 'cb' => '', 'title' => __('Title', $this->plugin_name), 'thumbnail' => __('Thumbnail', $this->plugin_name), 'shortcode' => __('Shortcodes', $this->plugin_name), 'type' => __('Type', $this->plugin_name), 'author' => __('Author', $this->plugin_name), 'date' => __('Date', $this->plugin_name) ); return $columns; } /** * @param $column * @param $post_id * * Edit the contents of each column in * the admin table for this post * @since 8.0.0 */ public function edit_columns($column) { // Post type table column content $post = get_post(); $postdata = get_post_meta($post->ID, 'panodata', true); $image_tour_icon = ''; $video_tour_icon = ''; $streetview_icon = ''; switch ($column) { case 'shortcode': echo '
[wpvr id="' . $post->ID . '"] ' . $this->copy_shortcode_html() . '
'; break; case 'thumbnail': $scene_image = !empty($postdata['preview']) ? $postdata['preview'] : $this->get_scene_image($postdata); if ($scene_image) { echo 'thumbnail'; }else { echo ''; } break; case 'type': if (isset($postdata['streetviewdata'])) { echo ''. $streetview_icon .'Street View'; } elseif (isset($postdata['vidid'])) { echo ''. $video_tour_icon .'360 Video'; } else { echo ''. $image_tour_icon .' 360 Image'; } break; default: break; } } private function get_scene_image($postdata) { if (!empty($postdata['panodata']['scene-list'][1]['scene-type']) && $postdata['panodata']['scene-list'][1]['scene-type'] === 'equirectangular') { $image_src = $postdata['panodata']['scene-list'][1]['scene-attachment-url'] ?? ''; $attachment_id = attachment_url_to_postid($image_src); if ($attachment_id) { return wp_get_attachment_image_url($attachment_id, 'thumbnail'); } } $image_src_face = $postdata['panodata']['scene-list'][1]['scene-attachment-url-face0'] ?? '';; $attachment_id_face = attachment_url_to_postid($image_src_face); if ($attachment_id_face) { return wp_get_attachment_image_url($attachment_id_face, 'thumbnail'); } } /** * Sets the messages for the custom post type * * @since 8.0.0 */ public function wpvr_post_updated_messages($messages) { $messages[$this->post_type][1] = __('WP VR item updated.', $this->plugin_name); $messages[$this->post_type][4] = __('WP VR item updated.', $this->plugin_name); return $messages; } }