1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Add Calendar Meta Box |
4
|
|
|
* |
5
|
|
|
* @package SimpleCalendar/Admin |
6
|
|
|
*/ |
7
|
|
|
namespace SimpleCalendar\Admin\Metaboxes; |
8
|
|
|
|
9
|
|
|
use SimpleCalendar\Abstracts\Meta_Box; |
10
|
|
|
|
11
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
12
|
|
|
exit; |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Attach a calendar to a post. |
17
|
|
|
* |
18
|
|
|
* Meta box for attaching calendars to WordPress posts. |
19
|
|
|
* |
20
|
|
|
* @since 3.0.0 |
21
|
|
|
*/ |
22
|
|
|
class Attach_Calendar implements Meta_Box { |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Output the meta box markup. |
26
|
|
|
* |
27
|
|
|
* @since 3.0.0 |
28
|
|
|
* |
29
|
|
|
* @param \WP_Post $post |
30
|
|
|
*/ |
31
|
|
|
public static function html( $post ) { |
32
|
|
|
|
33
|
|
|
// @see Meta_Boxes::save_meta_boxes() |
|
|
|
|
34
|
|
|
wp_nonce_field( 'simcal_save_data', 'simcal_meta_nonce' ); |
35
|
|
|
|
36
|
|
|
$calendars = simcal_get_calendars(); |
37
|
|
|
|
38
|
|
|
simcal_print_field( array( |
39
|
|
|
'type' => 'select', |
40
|
|
|
'id' => '_simcal_attach_calendar_id', |
41
|
|
|
'name' => '_simcal_attach_calendar_id', |
42
|
|
|
'enhanced' => count( $calendars ) > 15 ? 'enhanced' : '', |
43
|
|
|
'allow_void' => 'allow_void', |
44
|
|
|
'value' => absint( get_post_meta( $post->ID, '_simcal_attach_calendar_id', true ) ), |
45
|
|
|
'options' => $calendars, |
46
|
|
|
'attributes' => array( |
47
|
|
|
'data-allowclear' => 'true', |
48
|
|
|
) |
49
|
|
|
) ); |
50
|
|
|
|
51
|
|
|
$position = get_post_meta( $post->ID, '_simcal_attach_calendar_position', true ); |
52
|
|
|
|
53
|
|
|
simcal_print_field( array( |
54
|
|
|
'type' => 'radio', |
55
|
|
|
'id' => '_simcal_attach_calendar_position', |
56
|
|
|
'name' => '_simcal_attach_calendar_position', |
57
|
|
|
'value' => $position ? $position : 'after', |
58
|
|
|
'options' => array( |
59
|
|
|
'after' => __( 'After Content', 'google-calendar-events' ), |
60
|
|
|
'before' => __( 'Before Content', 'google-calendar-events' ), |
61
|
|
|
), |
62
|
|
|
) ); |
63
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Validate and save the meta box fields. |
68
|
|
|
* |
69
|
|
|
* @since 3.0.0 |
70
|
|
|
* |
71
|
|
|
* @param int $post_id |
72
|
|
|
* @param \WP_Post $post |
73
|
|
|
*/ |
74
|
|
|
public static function save( $post_id, $post ) { |
|
|
|
|
75
|
|
|
|
76
|
|
|
$id = isset( $_POST['_simcal_attach_calendar_id'] ) ? absint( $_POST['_simcal_attach_calendar_id'] ) : ''; |
77
|
|
|
update_post_meta( $post_id, '_simcal_attach_calendar_id', $id ); |
78
|
|
|
|
79
|
|
|
$position = isset( $_POST['_simcal_attach_calendar_position'] ) ? sanitize_title( $_POST['_simcal_attach_calendar_position'] ) : 'after'; |
80
|
|
|
update_post_meta( $post_id, '_simcal_attach_calendar_position', $position ); |
81
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.