-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtualtour.php
More file actions
113 lines (98 loc) · 3.8 KB
/
virtualtour.php
File metadata and controls
113 lines (98 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* Plugin Name: Franco Virtual Tour
* Plugin URI: https://github.com/AndersonFranco/franco-virtual-tour
* Description: Street View Gallery.
* Author: Anderson Franco
* Author URI: http://www.francotecnologia.com/
* Version: 1.0.0
* License: GPLv2 or later
*/
class FrancoVirtualTour
{
public function __construct()
{
register_activation_hook(__FILE__, array(get_called_class(), 'pluginActivation'));
add_action('plugins_loaded', array(get_called_class(), 'actions'));
}
public function pluginActivation()
{
self::createPostType();
flush_rewrite_rules();
}
public function actions()
{
add_action('init', array(get_called_class(), 'createPostType'));
add_action('add_meta_boxes', array(get_called_class(), 'addMetaBoxes'));
add_action('save_post', array(get_called_class(), 'savePost'));
add_action('after_switch_theme', array(get_called_class(), 'pluginActivation'));
add_action('wp_enqueue_scripts', array(get_called_class(), 'css'), 98);
add_filter('template_include', array(get_called_class(), 'template'), 1);
add_filter('pre_get_document_title', array(get_called_class(), 'pageTitle'), 100, 1);
add_action('wp_head', array(get_called_class(), 'metaTags'));
}
public function createPostType()
{
register_post_type('franco_virtualtour',
array(
'labels' => array(
'name' => __('Virtual Tours'),
'singular_name' => __('Virtual Tour')
),
'taxonomies' => array('category'),
'public' => true,
'supports' => array('title', 'editor', 'thumbnail'),
'has_archive' => true,
'rewrite' => array('slug' => 'virtualtour'),
)
);
}
public function addMetaBoxes()
{
add_meta_box('meta_box', __('Extras'), array(get_called_class(), 'metaBoxContent'), 'franco_virtualtour', 'normal', 'high');
}
public function metaBoxContent($post)
{
$streetviewUrl = esc_html(get_post_meta($post->ID, 'streetview_url', true));
wp_nonce_field(plugin_basename(__FILE__), 'box_content_nonce');
echo '<label for="streetview_url">Street View Embed URL</label>';
echo '<input type="text" id="streetview_url" name="streetview_url" placeholder="Street View URL" value="' . $streetviewUrl . '" style="width:100%;" />';
}
public function savePost($postId)
{
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if (!wp_verify_nonce($_POST['box_content_nonce'], plugin_basename(__FILE__))) return;
if ('franco_virtualtour' == $_POST['post_type']) {
update_post_meta($postId, 'streetview_url', $_POST['streetview_url']);
}
}
public function css()
{
wp_enqueue_style('virtualtour', plugins_url('virtualtour.css', __FILE__), array(), '1.0', 'all');
}
public function template($templatePath)
{
if (get_post_type() == 'franco_virtualtour') {
if ($themeFile = locate_template(array('streetview-virtualtour.php'))) {
$templatePath = $themeFile;
} else {
$templatePath = plugin_dir_path(__FILE__) . '/streetview-virtualtour.php';
}
}
return $templatePath;
}
public function pageTitle($title)
{
return is_single() ? $title : 'Google Street View - Virtual Tours';
}
public function metaTags()
{
if (is_single()) {
echo '<meta property="og:title" content="' . get_the_title() . '">';
if (has_post_thumbnail()) {
echo '<meta property="og:image" content="' . get_the_post_thumbnail_url() . '">';
}
}
}
}
new FrancoVirtualTour();