Repository navigation
Expand file tree
/
Copy pathvirtual-page.php
More file actions
115 lines (91 loc) · 2.79 KB
/
Copy pathvirtual-page.php
File metadata and controls
115 lines (91 loc) · 2.79 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
114
115
<?php
/**
* A class for creating virtual pages for WordPress.
*
* Based on a class "cooked up" by Ohad Raz.
* https://coderwall.com/p/fwea7g/create-wordpress-virtual-page-on-the-fly
*
* @package GoogleCalendarEventWorker
* @author Janne Kahkonen <jannekahkonen@gmail.com>
* @author Ohad Raz
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
class GCEventWorkerVirtualPage
{
/**
* The constructor.
*
* @param array $args
*
*/
function __construct($args)
{
add_filter('the_posts', array($this,'virtual_page'));
$this->args = $args;
$this->slug = $args['slug'];
}
function remove_link()
{
return false;
}
/**
* TODO
*
* @param TODO
*
*/
function my_the_content_filter($content)
{
//echo $content . '[MAP HERE]';
echo $content;
add_filter( 'previous_post_link', array($this,'remove_link' ));
add_filter( 'next_post_link', array($this,'remove_link' ));
wp_enqueue_script('search-form',
plugin_dir_url( __FILE__ ) . 'js/temp.js',
array('jquery'));
//echo $content . get_post_type( get_the_ID() ) . get_the_ID();
}
/**
* A function that catches the request and returns the page as if it was retrieved from the database
*
* @param array $posts
*
* @return array
*
*/
function virtual_page($posts)
{
global $wp, $wp_query;
$page_slug = $this->slug;
// Check if user is requesting our virtual page.
if (count($posts) == 0 && (strtolower($wp->request) == $page_slug))
{
// Create a virtual post.
$post = new stdClass;
$post->post_name = $page_slug;
$post->guid = get_bloginfo('wpurl' . '/' . $page_slug);
// Just needs to be a number (negatives are fine).
$post->ID = time();
$post->post_status = 'static';
$post->comment_status = 'closed';
$post->ping_status = 'closed';
$post->comment_count = 0;
$post->post_type = "page";
$post = (object) array_merge((array) $post, (array) $this->args);
//$posts = NULL;
$posts[] = $post;
$wp_query->is_page = true;
$wp_query->is_singular = true;
$wp_query->is_home = false;
$wp_query->is_archive = false;
$wp_query->is_category = false;
unset($wp_query->query['error']);
$wp_query->query_vars['error']= "";
$wp_query->is_404 = false;
add_filter('the_content', array($this, 'my_the_content_filter'));
}
return $posts;
}
} //end class
/* End of File */