1
|
|
|
<?php |
|
|
|
|
2
|
|
|
namespace lsx_health_plan\classes; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Contains the downloads functions post type |
6
|
|
|
* |
7
|
|
|
* @package lsx-health-plan |
8
|
|
|
*/ |
9
|
|
|
class Download_Monitor { |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Holds class instance |
13
|
|
|
* |
14
|
|
|
* @since 1.0.0 |
15
|
|
|
* |
16
|
|
|
* @var object \lsx_health_plan\classes\Download_Monitor() |
17
|
|
|
*/ |
18
|
|
|
protected static $instance = null; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Holds post_type slug used as an index |
22
|
|
|
* |
23
|
|
|
* @since 1.0.0 |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
public $slug = 'download'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Constructor |
31
|
|
|
*/ |
32
|
|
|
public function __construct() { |
|
|
|
|
33
|
|
|
add_action( 'cmb2_admin_init', array( $this, 'downloads_post_type_metaboxes' ), 5 ); |
34
|
|
|
add_action( 'cmb2_admin_init', array( $this, 'download_connections' ), 5 ); |
35
|
|
|
add_filter( 'lsx_health_plan_connections', array( $this, 'enable_connections' ), 10, 1 ); |
36
|
|
|
} |
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Return an instance of this class. |
40
|
|
|
* |
41
|
|
|
* @since 1.0.0 |
42
|
|
|
* |
43
|
|
|
* @return object \lsx_health_plan\classes\Download_Monitor() A single instance of this class. |
44
|
|
|
*/ |
45
|
|
|
public static function get_instance() { |
46
|
|
|
// If the single instance hasn't been set, set it now. |
47
|
|
|
if ( null === self::$instance ) { |
|
|
|
|
48
|
|
|
self::$instance = new self(); |
49
|
|
|
} |
|
|
|
|
50
|
|
|
return self::$instance; |
51
|
|
|
} |
|
|
|
|
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Enables the Bi Directional relationships |
55
|
|
|
* |
56
|
|
|
* @param array $connections |
|
|
|
|
57
|
|
|
* @return void |
|
|
|
|
58
|
|
|
*/ |
59
|
|
|
public function enable_connections( $connections = array() ) { |
60
|
|
|
$connections['dlm_download']['connected_pages'] = 'connected_downloads'; |
|
|
|
|
61
|
|
|
$connections['dlm_download']['connected_workouts'] = 'connected_downloads'; |
|
|
|
|
62
|
|
|
$connections['dlm_download']['connected_meals'] = 'connected_downloads'; |
|
|
|
|
63
|
|
|
$connections['dlm_download']['connected_recipes'] = 'connected_downloads'; |
|
|
|
|
64
|
|
|
|
65
|
|
|
//Post Type Connections |
|
|
|
|
66
|
|
|
$connections['workout']['connected_downloads'] = 'connected_workouts'; |
67
|
|
|
$connections['meal']['connected_downloads'] = 'connected_meals'; |
68
|
|
|
$connections['recipe']['connected_downloads'] = 'connected_recipes'; |
69
|
|
|
$connections['page']['connected_downloads'] = 'connected_pages'; |
70
|
|
|
return $connections; |
71
|
|
|
} |
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Define the metabox and field configurations. |
75
|
|
|
*/ |
76
|
|
|
public function downloads_post_type_metaboxes() { |
77
|
|
|
$cmb = new_cmb2_box( array( |
|
|
|
|
78
|
|
|
'id' => $this->slug . '_connections_metabox', |
79
|
|
|
'title' => __( 'Connections', 'lsx-health-plan' ), |
80
|
|
|
'object_types' => array( 'dlm_download' ), // Post type |
|
|
|
|
81
|
|
|
'context' => 'normal', |
82
|
|
|
'priority' => 'high', |
83
|
|
|
'show_names' => true, |
84
|
|
|
) ); |
|
|
|
|
85
|
|
|
$cmb->add_field( array( |
|
|
|
|
86
|
|
|
'name' => __( 'Pages', 'lsx-health-plan' ), |
87
|
|
|
'id' => 'connected_pages', |
88
|
|
|
'type' => 'post_search_ajax', |
89
|
|
|
// Optional : |
|
|
|
|
90
|
|
|
'limit' => 10, // Limit selection to X items only (default 1) |
|
|
|
|
91
|
|
|
'sortable' => true, // Allow selected items to be sortable (default false) |
|
|
|
|
92
|
|
|
'query_args' => array( |
93
|
|
|
'post_type' => array( 'page' ), |
94
|
|
|
'post_status' => array( 'publish' ), |
95
|
|
|
'posts_per_page' => -1, |
96
|
|
|
), |
97
|
|
|
) ); |
|
|
|
|
98
|
|
|
$cmb->add_field( array( |
|
|
|
|
99
|
|
|
'name' => __( 'Workouts', 'lsx-health-plan' ), |
100
|
|
|
'id' => 'connected_workouts', |
101
|
|
|
'type' => 'post_search_ajax', |
102
|
|
|
// Optional : |
|
|
|
|
103
|
|
|
'limit' => 10, // Limit selection to X items only (default 1) |
|
|
|
|
104
|
|
|
'sortable' => true, // Allow selected items to be sortable (default false) |
|
|
|
|
105
|
|
|
'query_args' => array( |
106
|
|
|
'post_type' => array( 'workout' ), |
107
|
|
|
'post_status' => array( 'publish' ), |
108
|
|
|
'posts_per_page' => -1, |
109
|
|
|
), |
110
|
|
|
) ); |
|
|
|
|
111
|
|
|
$cmb->add_field( array( |
|
|
|
|
112
|
|
|
'name' => __( 'Meals', 'lsx-health-plan' ), |
113
|
|
|
'id' => 'connected_meals', |
114
|
|
|
'type' => 'post_search_ajax', |
115
|
|
|
// Optional : |
|
|
|
|
116
|
|
|
'limit' => 10, // Limit selection to X items only (default 1) |
|
|
|
|
117
|
|
|
'sortable' => true, // Allow selected items to be sortable (default false) |
|
|
|
|
118
|
|
|
'query_args' => array( |
119
|
|
|
'post_type' => array( 'meal' ), |
120
|
|
|
'post_status' => array( 'publish' ), |
121
|
|
|
'posts_per_page' => -1, |
122
|
|
|
), |
123
|
|
|
) ); |
|
|
|
|
124
|
|
|
$cmb->add_field( array( |
|
|
|
|
125
|
|
|
'name' => __( 'Recipe', 'lsx-health-plan' ), |
126
|
|
|
'id' => 'connected_recipes', |
127
|
|
|
'type' => 'post_search_ajax', |
128
|
|
|
// Optional : |
|
|
|
|
129
|
|
|
'limit' => 10, // Limit selection to X items only (default 1) |
|
|
|
|
130
|
|
|
'sortable' => true, // Allow selected items to be sortable (default false) |
|
|
|
|
131
|
|
|
'query_args' => array( |
132
|
|
|
'post_type' => array( 'recipe' ), |
133
|
|
|
'post_status' => array( 'publish' ), |
134
|
|
|
'posts_per_page' => -1, |
135
|
|
|
), |
136
|
|
|
) ); |
|
|
|
|
137
|
|
|
} |
|
|
|
|
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Registers the workout connections on the plan post type. |
141
|
|
|
* |
142
|
|
|
* @return void |
143
|
|
|
*/ |
144
|
|
|
public function download_connections() { |
145
|
|
|
$cmb = new_cmb2_box( array( |
|
|
|
|
146
|
|
|
'id' => $this->slug . '_metabox', |
147
|
|
|
'title' => __( 'Downloads', 'lsx-health-plan' ), |
148
|
|
|
'object_types' => array( 'workout', 'meal', 'recipe' ), // Post type |
|
|
|
|
149
|
|
|
'context' => 'normal', |
150
|
|
|
'priority' => 'high', |
151
|
|
|
'show_names' => true, |
152
|
|
|
) ); |
|
|
|
|
153
|
|
|
$cmb->add_field( array( |
|
|
|
|
154
|
|
|
'name' => __( 'Downloads', 'lsx-health-plan' ), |
155
|
|
|
'desc' => __( "Add the pdf's connected to this day plan, using the field provided.", 'lsx-health-plan' ), |
156
|
|
|
'id' => 'connected_downloads', |
157
|
|
|
'type' => 'post_search_ajax', |
158
|
|
|
// Optional |
|
|
|
|
159
|
|
|
'limit' => 15, // Limit selection to X items only (default 1) |
|
|
|
|
160
|
|
|
'sortable' => true, // Allow selected items to be sortable (default false) |
|
|
|
|
161
|
|
|
'query_args' => array( |
162
|
|
|
'post_type' => array( 'dlm_download' ), |
163
|
|
|
'post_status' => array( 'publish' ), |
164
|
|
|
'posts_per_page' => -1, |
165
|
|
|
), |
166
|
|
|
) ); |
|
|
|
|
167
|
|
|
} |
|
|
|
|
168
|
|
|
} |
169
|
|
|
|