|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
namespace lsx_health_plan\classes; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Contains the video post type |
|
6
|
|
|
* |
|
7
|
|
|
* @package lsx-health-plan |
|
8
|
|
|
*/ |
|
9
|
|
|
class Video { |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Holds class instance |
|
13
|
|
|
* |
|
14
|
|
|
* @since 1.0.0 |
|
15
|
|
|
* |
|
16
|
|
|
* @var object \lsx_health_plan\classes\Video() |
|
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 = 'video'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Constructor |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct() { |
|
|
|
|
|
|
33
|
|
|
add_action( 'init', array( $this, 'register_post_type' ) ); |
|
34
|
|
|
add_action( 'admin_menu', array( $this, 'register_menus' ) ); |
|
35
|
|
|
add_filter( 'lsx_health_plan_single_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
36
|
|
|
add_filter( 'lsx_health_plan_connections', array( $this, 'enable_connections' ), 10, 1 ); |
|
37
|
|
|
add_action( 'cmb2_admin_init', array( $this, 'details_metaboxes' ) ); |
|
38
|
|
|
} |
|
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Return an instance of this class. |
|
42
|
|
|
* |
|
43
|
|
|
* @since 1.0.0 |
|
44
|
|
|
* |
|
45
|
|
|
* @return object \lsx_health_plan\classes\Video() A single instance of this class. |
|
46
|
|
|
*/ |
|
47
|
|
|
public static function get_instance() { |
|
48
|
|
|
// If the single instance hasn't been set, set it now. |
|
49
|
|
|
if ( null === self::$instance ) { |
|
|
|
|
|
|
50
|
|
|
self::$instance = new self(); |
|
51
|
|
|
} |
|
|
|
|
|
|
52
|
|
|
return self::$instance; |
|
53
|
|
|
} |
|
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Register the post type. |
|
56
|
|
|
*/ |
|
57
|
|
|
public function register_post_type() { |
|
58
|
|
|
$labels = array( |
|
59
|
|
|
'name' => esc_html__( 'Videos', 'lsx-health-plan' ), |
|
60
|
|
|
'singular_name' => esc_html__( 'Video', 'lsx-health-plan' ), |
|
61
|
|
|
'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ), |
|
62
|
|
|
'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
63
|
|
|
'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
64
|
|
|
'new_item' => esc_html__( 'New', 'lsx-health-plan' ), |
|
65
|
|
|
'all_items' => esc_html__( 'All Videos', 'lsx-health-plan' ), |
|
66
|
|
|
'view_item' => esc_html__( 'View', 'lsx-health-plan' ), |
|
67
|
|
|
'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
68
|
|
|
'not_found' => esc_html__( 'None found', 'lsx-health-plan' ), |
|
69
|
|
|
'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ), |
|
70
|
|
|
'parent_item_colon' => '', |
|
71
|
|
|
'menu_name' => esc_html__( 'Videos', 'lsx-health-plan' ), |
|
72
|
|
|
); |
|
73
|
|
|
$args = array( |
|
74
|
|
|
'labels' => $labels, |
|
75
|
|
|
'public' => true, |
|
76
|
|
|
'publicly_queryable' => true, |
|
77
|
|
|
'show_ui' => true, |
|
78
|
|
|
'show_in_menu' => false, |
|
79
|
|
|
'show_in_rest' => true, |
|
80
|
|
|
'menu_icon' => 'dashicons-format-video', |
|
81
|
|
|
'query_var' => true, |
|
82
|
|
|
'rewrite' => false, |
|
83
|
|
|
'capability_type' => 'post', |
|
84
|
|
|
'has_archive' => false, |
|
85
|
|
|
'hierarchical' => false, |
|
86
|
|
|
'menu_position' => null, |
|
87
|
|
|
'supports' => array( |
|
88
|
|
|
'title', |
|
89
|
|
|
'editor', |
|
90
|
|
|
'custom-fields', |
|
91
|
|
|
), |
|
92
|
|
|
); |
|
93
|
|
|
register_post_type( 'video', $args ); |
|
94
|
|
|
} |
|
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Registers the Recipes under the Meals Post type menu. |
|
98
|
|
|
* |
|
99
|
|
|
* @return void |
|
100
|
|
|
*/ |
|
101
|
|
|
public function register_menus() { |
|
102
|
|
|
add_submenu_page( 'edit.php?post_type=workout', esc_html__( 'Videos', 'lsx-health-plan' ), esc_html__( 'Videos', 'lsx-health-plan' ), 'edit_posts', 'edit.php?post_type=video' ); |
|
103
|
|
|
} |
|
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Adds the post type to the different arrays. |
|
107
|
|
|
* |
|
108
|
|
|
* @param array $post_types |
|
|
|
|
|
|
109
|
|
|
* @return array |
|
110
|
|
|
*/ |
|
111
|
|
|
public function enable_post_type( $post_types = array() ) { |
|
112
|
|
|
$post_types[] = $this->slug; |
|
113
|
|
|
return $post_types; |
|
114
|
|
|
} |
|
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Enables the Bi Directional relationships |
|
118
|
|
|
* |
|
119
|
|
|
* @param array $connections |
|
|
|
|
|
|
120
|
|
|
* @return void |
|
|
|
|
|
|
121
|
|
|
*/ |
|
122
|
|
|
public function enable_connections( $connections = array() ) { |
|
123
|
|
|
$connections['video']['connected_plans'] = 'connected_videos'; |
|
124
|
|
|
$connections['plan']['connected_videos'] = 'connected_plans'; |
|
125
|
|
|
$connections['video']['connected_workouts'] = 'connected_videos'; |
|
126
|
|
|
$connections['plan']['connected_videos'] = 'connected_workouts'; |
|
127
|
|
|
return $connections; |
|
128
|
|
|
} |
|
|
|
|
|
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Define the metabox and field configurations. |
|
132
|
|
|
*/ |
|
133
|
|
|
public function details_metaboxes() { |
|
134
|
|
|
$cmb = new_cmb2_box( array( |
|
|
|
|
|
|
135
|
|
|
'id' => $this->slug . '_details_metabox', |
|
136
|
|
|
'title' => __( 'Video Details', 'lsx-health-plan' ), |
|
137
|
|
|
'object_types' => array( $this->slug ), // Post type |
|
|
|
|
|
|
138
|
|
|
'context' => 'normal', |
|
139
|
|
|
'priority' => 'high', |
|
140
|
|
|
'show_names' => true, |
|
141
|
|
|
) ); |
|
|
|
|
|
|
142
|
|
|
$cmb->add_field( array( |
|
|
|
|
|
|
143
|
|
|
'name' => __( 'Featured Video', 'lsx-health-plan' ), |
|
144
|
|
|
'desc' => __( 'Enable the checkbox to feature this video, featured videos display in any page that has the video shortcode: [lsx_health_plan_featured_videos_block]', 'lsx-health-plan' ), |
|
145
|
|
|
'id' => $this->slug . '_featured_video', |
|
146
|
|
|
'type' => 'checkbox', |
|
147
|
|
|
'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
148
|
|
|
) ); |
|
|
|
|
|
|
149
|
|
|
$cmb->add_field( array( |
|
|
|
|
|
|
150
|
|
|
'name' => __( 'Youtube Source', 'lsx-health-plan' ), |
|
151
|
|
|
'desc' => __( 'Drop in the url for your video from YouTube in this field, i.e: "https://www.youtube.com/watch?v=9xwazD5SyVg"', 'lsx-health-plan' ), |
|
152
|
|
|
'id' => $this->slug . '_youtube_source', |
|
153
|
|
|
'type' => 'oembed', |
|
154
|
|
|
'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
155
|
|
|
) ); |
|
|
|
|
|
|
156
|
|
|
$cmb->add_field( array( |
|
|
|
|
|
|
157
|
|
|
'name' => __( 'Giphy Source', 'lsx-health-plan' ), |
|
158
|
|
|
'desc' => __( 'Drop in the iFrame embed code from Giphy in this field, i.e: <iframe src="https://giphy.com/embed/3o7527Rn1HxXWqgxuo" width="480" height="270" frameborder="0" class="giphy-embed" allowfullscreen></iframe>', 'lsx-health-plan' ), |
|
159
|
|
|
'id' => $this->slug . '_giphy_source', |
|
160
|
|
|
'type' => 'textarea_code', |
|
161
|
|
|
'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
162
|
|
|
) ); |
|
|
|
|
|
|
163
|
|
|
} |
|
|
|
|
|
|
164
|
|
|
|
|
165
|
|
|
// /** |
|
|
|
|
|
|
166
|
|
|
// * Registers the workout connections on the workout post type. |
|
|
|
|
|
|
167
|
|
|
// * |
|
|
|
|
|
|
168
|
|
|
// * @return void |
|
|
|
|
|
|
169
|
|
|
// */ |
|
|
|
|
|
|
170
|
|
|
// public function videos_connections() { |
|
171
|
|
|
// $cmb = new_cmb2_box( array( |
|
|
|
|
|
|
172
|
|
|
// 'id' => $this->slug . '_videos_connections_metabox', |
|
|
|
|
|
|
173
|
|
|
// 'title' => __( 'Videos', 'lsx-health-plan' ), |
|
|
|
|
|
|
174
|
|
|
// 'desc' => __( 'Start typing to search for your workouts', 'lsx-health-plan' ), |
|
|
|
|
|
|
175
|
|
|
// 'object_types' => array( 'workout' ), // Post type |
|
|
|
|
|
|
176
|
|
|
// 'context' => 'normal', |
|
|
|
|
|
|
177
|
|
|
// 'priority' => 'high', |
|
|
|
|
|
|
178
|
|
|
// 'show_names' => false, |
|
|
|
|
|
|
179
|
|
|
// ) ); |
|
|
|
|
|
|
180
|
|
|
// $cmb->add_field( array( |
|
|
|
|
|
|
181
|
|
|
// 'name' => __( 'Videos', 'lsx-health-plan' ), |
|
|
|
|
|
|
182
|
|
|
// 'id' => 'connected_videos', |
|
|
|
|
|
|
183
|
|
|
// 'type' => 'post_search_ajax', |
|
|
|
|
|
|
184
|
|
|
// // Optional : |
|
|
|
|
|
|
185
|
|
|
// 'limit' => 15, // Limit selection to X items only (default 1) |
|
|
|
|
|
|
186
|
|
|
// 'sortable' => true, // Allow selected items to be sortable (default false) |
|
|
|
|
|
|
187
|
|
|
// 'query_args' => array( |
|
|
|
|
|
|
188
|
|
|
// 'post_type' => array( 'video' ), |
|
|
|
|
|
|
189
|
|
|
// 'post_status' => array( 'publish' ), |
|
|
|
|
|
|
190
|
|
|
// 'posts_per_page' => -1, |
|
|
|
|
|
|
191
|
|
|
// ), |
|
|
|
|
|
|
192
|
|
|
// ) ); |
|
|
|
|
|
|
193
|
|
|
// } |
|
194
|
|
|
|
|
195
|
|
|
} |
|
196
|
|
|
|