This repository has been archived by the owner on Jul 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zalo-employees-plugin.php
379 lines (340 loc) · 16.8 KB
/
zalo-employees-plugin.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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
<?php
/**
* Plugin Name: Zalo Employees
* Plugin URI:
* Description: Plugin for adding employees
* Version: 0.1
* Author: Tor Raswill
* Author URI: http://tor.raswill.se
* Text Domain: zalo-employees-plugin
*/
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
add_action( 'plugins_loaded', 'zalo_employees_plugin_load_plugin_textdomain' );
function zalo_employees_plugin_load_plugin_textdomain() {
load_plugin_textdomain( 'zalo-employees-plugin', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
}
//* Enqueue Scripts
add_action( 'wp_enqueue_scripts', 'add_employees_styling' );
function add_employees_styling() {
$pluginversion = '0.7.1';
wp_enqueue_style( 'zalo-employees', plugins_url( 'zalo-employees.css', __FILE__ ), array(), $pluginversion, false );
if ( is_singular( 'zalo_employees' ) ) {
//wp_enqueue_script( 'zalo-employees-imagesloaded', plugins_url( 'imagesloaded.js', __FILE__ ), array( 'jquery' ), $pluginversion, false );
wp_enqueue_script( 'zalo-employees-js', plugins_url( 'zalo-employees.js', __FILE__ ), array( 'jquery', 'zalo-imagesloaded', 'BJLL' ), $pluginversion, true );
}
}
add_action( 'init', 'zalo_employees_add_new_image_size' );
function zalo_employees_add_new_image_size() {
add_image_size( 'zalo_employee_front', 600, 400, true ); //mobile
add_image_size( 'zalo_employee_single', 900, 600, true ); //mobile
}
add_action( 'init', 'create_post_type_employees' );
function create_post_type_employees() {
register_post_type( 'zalo_employees',
array(
'supports' => array( 'title', 'editor', 'comments', 'excerpt', 'custom-fields', 'thumbnail' ),
'labels' => array(
'name' => __( 'Employees', 'zalo-employees-plugin' ),
'singular_name' => __( 'Employee', 'zalo-employees-plugin' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'employees'),
'menu_icon' => plugins_url( 'images/icon.png', __FILE__ ),
)
);
}
function get_zalo_employees_template($single_template) {
global $post;
if ($post->post_type == 'zalo_employees') {
$single_template = dirname( __FILE__ ) . '/single-zalo_employees.php';
}
return $single_template;
}
add_filter( 'single_template', 'get_zalo_employees_template' );
/**
* Add the Why I love box
*/
add_action( 'add_meta_boxes_zalo_employees', 'zalo_employees_add_meta_box' );
function zalo_employees_add_meta_box() {
add_meta_box(
'zalo_whyilove',
'Why I love',
'create_zalo_whyilove_nonce_output_box',
'zalo_employees',
'normal',
'high'
);
add_meta_box(
'zalo_title',
'Title',
'create_zalo_title_nonce_output_box',
'zalo_employees',
'side'
);
add_meta_box(
'zalo_contact',
'Contact',
'create_zalo_contact_nonce_output_box',
'zalo_employees',
'side'
);
add_meta_box(
'zalo_skills',
'Skills',
'create_zalo_skills_nonce_output_box',
'zalo_employees',
'side'
);
}
function create_zalo_whyilove_nonce_output_box( $post ) {
$nonce = wp_create_nonce( 'zalo_whyilove_meta_box_nonce' );
echo "<input type='hidden' name='zalo_whyilove_meta_box_nonce' value='$nonce' />";
$value = get_post_meta($post->ID, 'zalo_whyilove_field_box', TRUE );
wp_editor( $value,'zalo_whyilove_field_box', array ('textarea_rows' => 10));
}
function create_zalo_title_nonce_output_box( $post ) {
wp_nonce_field( basename( __FILE__ ), 'title_nonce' );
$zaloemployee_stored_meta = get_post_meta( $post->ID );
?>
<p>
<label for="meta-text" class="prfx-row-title"><?php _e( 'Title', 'zalo-employees-plugin' )?></label>
<input type="text" name="zalo-title-text" id="zalo-title-text" value="<?php if ( isset ( $zaloemployee_stored_meta['zalo-title-text'] ) ) echo $zaloemployee_stored_meta['zalo-title-text'][0]; ?>" />
</p>
<?php
}
function create_zalo_contact_nonce_output_box( $post ) {
wp_nonce_field( basename( __FILE__ ), 'title_nonce' );
$zaloemployee_stored_meta = get_post_meta( $post->ID );
?>
<p>
<label for="meta-text" class="prfx-row-title"><?php _e( 'Phone', 'zalo-employees-plugin' )?></label>
<input type="text" name="zalo-employeephone-text" id="zalo-employeephone-text" value="<?php if ( isset ( $zaloemployee_stored_meta['zalo-employeephone-text'] ) ) echo $zaloemployee_stored_meta['zalo-employeephone-text'][0]; ?>" />
</p>
<p>
<label for="meta-text" class="prfx-row-title"><?php _e( 'Email', 'zalo-employees-plugin' )?></label>
<input type="text" name="zalo-employeemail-text" id="zalo-employeemail-text" value="<?php if ( isset ( $zaloemployee_stored_meta['zalo-employeemail-text'] ) ) echo $zaloemployee_stored_meta['zalo-employeemail-text'][0]; ?>" />
</p>
<p>
<label for="meta-text" class="prfx-row-title"><?php _e( 'LinkedIn', 'zalo-employees-plugin' )?></label>
<input type="text" name="zalo-employeelinkedin-text" id="zalo-employeelinkedin-text" value="<?php if ( isset ( $zaloemployee_stored_meta['zalo-employeelinkedin-text'] ) ) echo $zaloemployee_stored_meta['zalo-employeelinkedin-text'][0]; ?>" />
</p>
<p>
<label for="meta-text" class="prfx-row-title"><?php _e( 'Bungie', 'zalo-employees-plugin' )?></label>
<input type="text" name="zalo-employeebungie-text" id="zalo-employeebungie-text" value="<?php if ( isset ( $zaloemployee_stored_meta['zalo-employeebungie-text'] ) ) echo $zaloemployee_stored_meta['zalo-employeebungie-text'][0]; ?>" />
</p>
<?php
}
function create_zalo_skills_nonce_output_box( $post ) {
wp_nonce_field( basename( __FILE__ ), 'prfx_nonce' );
$zaloemployee_stored_meta = get_post_meta( $post->ID );
?>
<p>
<div class="prfx-row-content">
<label for="zalo-javascript-checkbox">
<input type="checkbox" name="zalo-javascript-checkbox" id="zalo-javascript-checkbox" value="yes" <?php if ( isset ( $zaloemployee_stored_meta['zalo-javascript-checkbox'] ) ) checked( $zaloemployee_stored_meta['zalo-javascript-checkbox'][0], 'yes' ); ?> />
<?php _e( 'Javascript', 'zalo-employees-plugin' )?>
</label><br />
<label for="zalo-html5-checkbox">
<input type="checkbox" name="zalo-html5-checkbox" id="zalo-html5-checkbox" value="yes" <?php if ( isset ( $zaloemployee_stored_meta['zalo-html5-checkbox'] ) ) checked( $zaloemployee_stored_meta['zalo-html5-checkbox'][0], 'yes' ); ?> />
<?php _e( 'HTML5', 'zalo-employees-plugin' )?>
</label><br />
<label for="zalo-css3-checkbox">
<input type="checkbox" name="zalo-css3-checkbox" id="zalo-css3-checkbox" value="yes" <?php if ( isset ( $zaloemployee_stored_meta['zalo-css3-checkbox'] ) ) checked( $zaloemployee_stored_meta['zalo-css3-checkbox'][0], 'yes' ); ?> />
<?php _e( 'CSS3', 'zalo-employees-plugin' )?>
</label><br />
<label for="zalo-visualstudio-checkbox">
<input type="checkbox" name="zalo-visualstudio-checkbox" id="zalo-visualstudio-checkbox" value="yes" <?php if ( isset ( $zaloemployee_stored_meta['zalo-visualstudio-checkbox'] ) ) checked( $zaloemployee_stored_meta['zalo-visualstudio-checkbox'][0], 'yes' ); ?> />
<?php _e( 'Visual Studio', 'zalo-employees-plugin' )?>
</label><br />
<label for="zalo-csharp-checkbox">
<input type="checkbox" name="zalo-csharp-checkbox" id="zalo-csharp-checkbox" value="yes" <?php if ( isset ( $zaloemployee_stored_meta['zalo-csharp-checkbox'] ) ) checked( $zaloemployee_stored_meta['zalo-csharp-checkbox'][0], 'yes' ); ?> />
<?php _e( 'C#', 'zalo-employees-plugin' )?>
</label><br />
<label for="zalo-sharepoint-checkbox">
<input type="checkbox" name="zalo-sharepoint-checkbox" id="zalo-sharepoint-checkbox" value="yes" <?php if ( isset ( $zaloemployee_stored_meta['zalo-sharepoint-checkbox'] ) ) checked( $zaloemployee_stored_meta['zalo-sharepoint-checkbox'][0], 'yes' ); ?> />
<?php _e( 'SharePoint', 'zalo-employees-plugin' )?>
</label><br />
<label for="zalo-azure-checkbox">
<input type="checkbox" name="zalo-azure-checkbox" id="zalo-azure-checkbox" value="yes" <?php if ( isset ( $zaloemployee_stored_meta['zalo-azure-checkbox'] ) ) checked( $zaloemployee_stored_meta['zalo-azure-checkbox'][0], 'yes' ); ?> />
<?php _e( 'Azure', 'zalo-employees-plugin' )?>
</label><br />
<label for="zalo-office-checkbox">
<input type="checkbox" name="zalo-office-checkbox" id="zalo-office-checkbox" value="yes" <?php if ( isset ( $zaloemployee_stored_meta['zalo-office-checkbox'] ) ) checked( $zaloemployee_stored_meta['zalo-office-checkbox'][0], 'yes' ); ?> />
<?php _e( 'Office', 'zalo-employees-plugin' )?>
</label><br />
<label for="zalo-office365-checkbox">
<input type="checkbox" name="zalo-office365-checkbox" id="zalo-office365-checkbox" value="yes" <?php if ( isset ( $zaloemployee_stored_meta['zalo-office365-checkbox'] ) ) checked( $zaloemployee_stored_meta['zalo-office365-checkbox'][0], 'yes' ); ?> />
<?php _e( 'Office365', 'zalo-employees-plugin' )?>
</label><br />
<label for="zalo-powershell-checkbox">
<input type="checkbox" name="zalo-powershell-checkbox" id="zalo-powershell-checkbox" value="yes" <?php if ( isset ( $zaloemployee_stored_meta['zalo-powershell-checkbox'] ) ) checked( $zaloemployee_stored_meta['zalo-powershell-checkbox'][0], 'yes' ); ?> />
<?php _e( 'PowerShell', 'zalo-employees-plugin' )?>
</label><br />
<label for="zalo-scrum-checkbox">
<input type="checkbox" name="zalo-scrum-checkbox" id="zalo-scrum-checkbox" value="yes" <?php if ( isset ( $zaloemployee_stored_meta['zalo-scrum-checkbox'] ) ) checked( $zaloemployee_stored_meta['zalo-scrum-checkbox'][0], 'yes' ); ?> />
<?php _e( 'Scrum', 'zalo-employees-plugin' )?>
</label><br />
</div>
</p>
<?php
}
add_action( 'save_post', 'save_meta_box_content', 10, 2);
function save_meta_box_content( $post_id ) {
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
} else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
}
if ( isset ( $_POST['zalo_whyilove_field_box'] ) && wp_verify_nonce( $_POST[ 'zalo_whyilove_meta_box_nonce' ], 'zalo_whyilove_meta_box_nonce') ) {
update_post_meta( $post_id, 'zalo_whyilove_field_box', $_POST['zalo_whyilove_field_box'] );
} else {
delete_post_meta( $post_id, 'zalo_whyilove_field_box' );
}
// Checks for input and sanitizes/saves if needed
if( isset( $_POST[ 'zalo-title-text' ] ) ) {
update_post_meta( $post_id, 'zalo-title-text', sanitize_text_field( $_POST[ 'zalo-title-text' ] ) );
}
if( isset( $_POST[ 'zalo-employeephone-text' ] ) ) {
update_post_meta( $post_id, 'zalo-employeephone-text', sanitize_text_field( $_POST[ 'zalo-employeephone-text' ] ) );
}
if( isset( $_POST[ 'zalo-employeemail-text' ] ) ) {
update_post_meta( $post_id, 'zalo-employeemail-text', sanitize_text_field( $_POST[ 'zalo-employeemail-text' ] ) );
}
if( isset( $_POST[ 'zalo-employeelinkedin-text' ] ) ) {
update_post_meta( $post_id, 'zalo-employeelinkedin-text', sanitize_text_field( $_POST[ 'zalo-employeelinkedin-text' ] ) );
}
if( isset( $_POST[ 'zalo-employeebungie-text' ] ) ) {
update_post_meta( $post_id, 'zalo-employeebungie-text', sanitize_text_field( $_POST[ 'zalo-employeebungie-text' ] ) );
}
// Checks for input and saves
if( isset( $_POST[ 'zalo-javascript-checkbox' ] ) ) {
update_post_meta( $post_id, 'zalo-javascript-checkbox', 'yes' );
} else {
update_post_meta( $post_id, 'zalo-javascript-checkbox', '' );
}
if( isset( $_POST[ 'zalo-html5-checkbox' ] ) ) {
update_post_meta( $post_id, 'zalo-html5-checkbox', 'yes' );
} else {
update_post_meta( $post_id, 'zalo-html5-checkbox', '' );
}
if( isset( $_POST[ 'zalo-css3-checkbox' ] ) ) {
update_post_meta( $post_id, 'zalo-css3-checkbox', 'yes' );
} else {
update_post_meta( $post_id, 'zalo-css3-checkbox', '' );
}
if( isset( $_POST[ 'zalo-visualstudio-checkbox' ] ) ) {
update_post_meta( $post_id, 'zalo-visualstudio-checkbox', 'yes' );
} else {
update_post_meta( $post_id, 'zalo-visualstudio-checkbox', '' );
}
if( isset( $_POST[ 'zalo-csharp-checkbox' ] ) ) {
update_post_meta( $post_id, 'zalo-csharp-checkbox', 'yes' );
} else {
update_post_meta( $post_id, 'zalo-csharp-checkbox', '' );
}
if( isset( $_POST[ 'zalo-sharepoint-checkbox' ] ) ) {
update_post_meta( $post_id, 'zalo-sharepoint-checkbox', 'yes' );
} else {
update_post_meta( $post_id, 'zalo-sharepoint-checkbox', '' );
}
if( isset( $_POST[ 'zalo-azure-checkbox' ] ) ) {
update_post_meta( $post_id, 'zalo-azure-checkbox', 'yes' );
} else {
update_post_meta( $post_id, 'zalo-azure-checkbox', '' );
}
if( isset( $_POST[ 'zalo-office-checkbox' ] ) ) {
update_post_meta( $post_id, 'zalo-office-checkbox', 'yes' );
} else {
update_post_meta( $post_id, 'zalo-office-checkbox', '' );
}
if( isset( $_POST[ 'zalo-office365-checkbox' ] ) ) {
update_post_meta( $post_id, 'zalo-office365-checkbox', 'yes' );
} else {
update_post_meta( $post_id, 'zalo-office365-checkbox', '' );
}
if( isset( $_POST[ 'zalo-powershell-checkbox' ] ) ) {
update_post_meta( $post_id, 'zalo-powershell-checkbox', 'yes' );
} else {
update_post_meta( $post_id, 'zalo-powershell-checkbox', '' );
}
if( isset( $_POST[ 'zalo-scrum-checkbox' ] ) ) {
update_post_meta( $post_id, 'zalo-scrum-checkbox', 'yes' );
} else {
update_post_meta( $post_id, 'zalo-scrum-checkbox', '' );
}
}
class ZaloEmployeesWidget extends WP_Widget
{
function ZaloEmployeesWidget()
{
$widget_ops = array('classname' => 'zaloemployeeswidget featuredpage', 'description' => __( 'Displays the Zalo employees', 'zalo-employees-plugin' ) );
$this->WP_Widget('ZaloEmployeesWidget', 'Zalo employees widget', $widget_ops);
}
function form($instance)
{
$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
$title = $instance['title'];
echo '<p><label for="' . $this->get_field_id('title') . '">' . __( 'Title', 'zalo-employees-plugin' ) . ': <input class="widefat" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . attribute_escape($title) . '" /></label></p>';
}
function update($new_instance, $old_instance)
{
$instance = $old_instance;
$instance['title'] = $new_instance['title'];
return $instance;
}
function widget($args, $instance)
{
extract($args, EXTR_SKIP);
echo $before_widget;
//$title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
$title = empty($instance['title']) ? '' : $instance['title'];
echo '<div id="zalo-employees" class="zalo-section-target"></div>';
if (!empty($title)) {
echo '<header class="entry-header"><h2 class="entry-title">' . $title . '</h2></header>';
}
$output = '';
//$employee_query = new WP_Query('post_type=zalo_employees&showposts=10&orderby=\'ID\'&order=\'ASC\'');
$employee_query = new WP_Query( array ( 'post_type' => 'zalo_employees', 'orderby' => 'date', 'order' => 'ASC' ) );
if ($employee_query->have_posts()) :
$output .= '<div class="zalo-employees">';
while ($employee_query->have_posts()) : $employee_query->the_post();
$output .= '<a href="' . get_permalink($post->ID) . '">';
$output .= '<div class="employee">';
$employeetitle = genesis_get_custom_field('zalo-title-text'); //genesis_get_custom_field('zalo-title-text')
$placeholder = plugins_url( 'images/placeholder.png', __FILE__ );
$output .= '<div class="employee-image">';
if(has_post_thumbnail()) {
$output .= get_the_post_thumbnail($post->ID,'zalo_employee_front');
} else {
//$output .= '<img width="600" height="400" src="' . $placeholder . '" class="attachment-featured_image wp-post-image" alt="" />';
$img_html = '<img width="600" height="400" src="' . $placeholder . '" class="attachment-featured_image wp-post-image" alt="" />';
$img_html = apply_filters( 'bj_lazy_load_html', $img_html );
$output .= $img_html;
}
$output .= '</div>';
$output .= '<div class="employee-info">';
$output .= '<header class="entry-header"><h4>' . get_the_title() . '</h4></header>';
$output .= '<span class="employee-title">' . $employeetitle . '</span>';
$output .= '</div>';
$output .= '</div>';
$output .= '</a>';
endwhile;
$output .= '</div>';
endif;
wp_reset_postdata();
echo $output;
echo $after_widget;
}
}
add_action( 'widgets_init', create_function('', 'return register_widget("ZaloEmployeesWidget");') );
/* Stop Adding Functions Below this Line */
?>