-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathTeamProfiles.php
229 lines (193 loc) · 6.4 KB
/
TeamProfiles.php
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
/**
* Team profiles
*
* Create a "Meet our team" page in WordPress using
* custom post types, taxonomies, and Advanced Custom
* Fields
*/
if ( !class_exists('TeamProfiles') ):
class TeamProfiles
{
/**
* Initialize & hook into WP
*/
public function __construct() {
add_action( 'init', array($this, 'register_post_type'), 0 );
add_action( 'init', array($this, 'register_taxonomy'), 0 );
add_action( 'wp_enqueue_scripts', array($this, 'load_styles'), 101 );
add_action( 'admin_notices', array($this, 'admin_notice') );
add_action( 'after_setup_theme', array($this, 'after_setup_theme') );
}
/**
* Dependencies check
*
* Check to make sure we have the required plugin(s)
* installed.
*/
public function dependencies_check() {
return ( is_plugin_active('advanced-custom-fields/acf.php') ) ? true : false;
}
/**
* Load CSS for template-team.php
*/
public function load_styles() {
if ( is_page_template('template-team.php') )
wp_enqueue_style( 'team-template', get_stylesheet_directory_uri() . '/assets/css/team.css' );
}
/**
* Theme setup
*
* Create a custom thumbnail size for our team avatars
*/
public function after_setup_theme() {
add_image_size('team-thumb', 100, 100, true); // 100px x 100px with hard crop enabled
}
/**
* Dependencies notifications
*
* Required plugin isn't installed, notify user
*/
public function admin_notice() {
// Check for required plugins
if ( $this->dependencies_check() )
return;
// Display message
$install_link = admin_url('plugin-install.php?tab=search&type=term&s=Advanced+Custom+Fields&plugin-search-input=Search+Plugins');
$html = '<div class="error"><p>';
$html .= '<strong>Team Profiles</strong> needs the <a href="http://www.advancedcustomfields.com/" target="_blank">Advanced Custom Fields</a> plugin to work. Please <a href="' . $install_link . '">install it now</a>.';
$html .= '</p></div>';
echo $html;
}
/**
* Register post type
*/
public function register_post_type() {
// Labels
$labels = array(
'name' => _x("Team", "post type general name"),
'singular_name' => _x("Team", "post type singular name"),
'menu_name' => 'Team Profiles',
'add_new' => _x("Add New", "team item"),
'add_new_item' => __("Add New Profile"),
'edit_item' => __("Edit Profile"),
'new_item' => __("New Profile"),
'view_item' => __("View Profile"),
'search_items' => __("Search Profiles"),
'not_found' => __("No Profiles Found"),
'not_found_in_trash' => __("No Profiles Found in Trash"),
'parent_item_colon' => ''
);
// Register post type
register_post_type('team' , array(
'labels' => $labels,
'public' => true,
'has_archive' => false,
'menu_icon' => get_stylesheet_directory_uri() . '/lib/TeamProfiles/team-icon.png',
'rewrite' => false,
'supports' => array('title', 'editor', 'thumbnail')
) );
}
/**
* Register 'department' taxonomy
*/
public function register_taxonomy() {
// Labels
$singular = 'Department';
$plural = 'Departments';
$labels = array(
'name' => _x( $plural, "taxonomy general name"),
'singular_name' => _x( $singular, "taxonomy singular name"),
'search_items' => __("Search $singular"),
'all_items' => __("All $singular"),
'parent_item' => __("Parent $singular"),
'parent_item_colon' => __("Parent $singular:"),
'edit_item' => __("Edit $singular"),
'update_item' => __("Update $singular"),
'add_new_item' => __("Add New $singular"),
'new_item_name' => __("New $singular Name"),
);
// Register and attach to 'team' post type
register_taxonomy( strtolower($singular), 'team', array(
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'hierarchical' => true,
'query_var' => true,
'rewrite' => false,
'labels' => $labels
) );
}
/**
* Display the cached HTML
*/
static function display() {
global $post;
// Caching, re-run query if not found or expired
$transient_label = __CLASS__ . "_" . __FUNCTION__; // Transient label will be 'TeamProfiles_display'
if ( false === ( $html = get_transient($transient_label) ) ) {
// Get 'team' posts
$team_posts = get_posts( array(
'post_type' => 'team',
'posts_per_page' => 50, // Unlimited posts
'orderby' => 'title', // Order alphabetically by name
'order' => 'ASC' // Start with 'A'
) );
$html = null;
if ( $team_posts ):
// Gather output
ob_start();
?>
<section class="row profiles">
<div class="intro">
<h2>Meet The Team</h2>
<p class="lead">“Individuals can and do make a difference, but it takes a team<br>to really mess things up.”</p>
</div>
<?php
foreach ( $team_posts as $post ):
setup_postdata($post);
// Resize and CDNize thumbnails using Automattic Photon service
$thumb_src = null;
if ( has_post_thumbnail($post->ID) ) {
$src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'team-thumb' );
$thumb_src = $src[0];
}
?>
<article class="col-sm-6 profile">
<div class="profile-header">
<?php if ( $thumb_src ): ?>
<img src="<?php echo $thumb_src; ?>" alt="<?php the_title(); ?>, <?php the_field('team_position'); ?>" class="img-circle">
<?php endif; ?>
</div>
<div class="profile-content">
<h3><?php the_title(); ?></h3>
<p class="lead position"><?php the_field('team_position'); ?></p>
<?php the_content(); ?>
</div>
<div class="profile-footer">
<a href="tel:<?php the_field('team_phone'); ?>"><i class="icon-mobile-phone"></i></a>
<a href="mailto:<?php echo antispambot( get_field('team_email') ); ?>"><i class="icon-envelope"></i></a>
<?php if ( $twitter = get_field('team_twitter') ): ?>
<a href="<?php echo $twitter; ?>"><i class="icon-twitter"></i></a>
<?php endif; ?>
<?php if ( $linkedin = get_field('team_linkedin') ): ?>
<a href="<?php echo $linkedin; ?>"><i class="icon-linkedin"></i></a>
<?php endif; ?>
</div>
</article><!-- /.profile -->
<?php endforeach; ?>
</section><!-- /.row -->
<?php
// Save output
$html = ob_get_contents();
ob_end_clean();
endif; // end if $team_posts
// Store output in cache
set_transient( $transient_label, $html, DAY_IN_SECONDS );
}
// Output the HTML if it exists
return ( $html ) ? $html : false;
}
}
$TeamProfiles = new TeamProfiles();
endif;