-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-frontend.php
More file actions
56 lines (50 loc) · 1.46 KB
/
class-frontend.php
File metadata and controls
56 lines (50 loc) · 1.46 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
<?php
namespace B0334315817D4E03A27BEED307E417C8\Webinars_Made_Easy;
class Frontend {
private $webinar;
public function __construct( $webinar_instance ) {
$this->webinar = $webinar_instance;
add_filter( 'template_include', array( $this, 'on_template_include' ) );
add_shortcode( 'webinars', array( $this, 'list_webinars' ) );
}
/**
*/
public function on_template_include( $template_path ) {
$type_slug = $this->webinar->get_post_type();
if ( $type_slug == get_post_type() ) {
if ( is_single() ) {
$webinar_template = 'single-' . $type_slug . '.php';
if ( $theme_file = locate_template( array( $webinar_template ) ) ) {
$template_path = $theme_file;
} else {
$template_path = plugin_dir_path( __FILE__ ) . '/templates/' . $webinar_template;
}
}
}
return $template_path;
}
/**
* Lists all of the webinars from a given time period (future, past)
*/
function list_webinars( $atts ) {
extract( shortcode_atts( array(
'from_period' => 'future'
), $atts ) );
$webinar_query = new \WP_Query( array( 'post_type' => $this->webinar->get_post_type() ) );
?>
<ul>
<?php if ( $webinar_query->have_posts() ) :
while ( $webinar_query->have_posts() ) : ?>
<li>
<?php $webinar_query->the_post();
echo get_the_title(); ?>
</li>
<?php endwhile;
wp_reset_postdata();
else :
/* TODO: What happens to the table if there really aren't any webinars? */
echo '<li>No Webinars</li>'; ?>
</ul>
<?php endif;
}
}