PluginProbe
WP Courses LMS – Online Courses Builder, eLearning Courses, Courses Solution, Education Courses / trunk
WP Courses LMS – Online Courses Builder, eLearning Courses, Courses Solution, Education Courses vtrunk
3.2.30 trunk 3.1.40 3.1.41 3.1.42 3.1.43 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.17 3.2.18 3.2.19 3.2.2 3.2.20 3.2.21 3.2.22 3.2.23 3.2.24 3.2.25 All 36 releases
wp-courses / init / cp-types.php

cp-types.php in WP Courses LMS – Online Courses Builder, eLearning Courses, Courses Solution, Education Courses trunk, at init/cp-types.php

384 lines 15.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Register Custom Post Type Course
3 function wpc_register_course_cp()
4 {
5
6 $labels = array(
7 'name' => _x('Courses', 'post type general name'),
8 'singular_name' => _x('Course', 'post type singular name'),
9 'add_new' => _x('Add New', 'Course'),
10 'add_new_item' => __('Add New Course'),
11 'edit_item' => __('Edit Course'),
12 'new_item' => __('New Course'),
13 'all_items' => __('All Courses'),
14 'view_item' => __('View Course'),
15 'search_items' => __('Search Courses'),
16 'not_found' => __('No courses found'),
17 'not_found_in_trash' => __('No courses found in Trash'),
18 'parent_item_colon' => '',
19 'menu_name' => __('Courses', 'wp-courses'),
20 );
21 $args = array(
22 'labels' => $labels,
23 'show_in_admin_bar' => true,
24 'menu_icon' => null,
25 'show_in_nav_menus' => false,
26 'publicly_queryable' => true,
27 'query_var' => true,
28 'can_export' => true,
29 'rewrite' => true,
30 'show_in_menu' => '',
31 'description' => __('Enter a Course Description Here', 'wp-courses'),
32 'public' => true,
33 'show_ui' => true,
34 'hierarchical' => false,
35 'supports' => array('title', 'editor', 'excerpt', 'page-attributes', 'thumbnail', 'custom-fields'),
36 'has_archive' => true,
37 'show_in_rest' => true,
38 );
39
40 register_post_type('course', $args);
41 flush_rewrite_rules(false);
42 }
43 add_action('init', 'wpc_register_course_cp');
44
45 //Custom Messages for Custom Post Type Course
46 function wpc_course_messages($messages)
47 {
48 global $post;
49 $post_ID = get_the_id();
50 $messages['course'] = array(
51 0 => '',
52 1 => sprintf(__('Course updated. <a href="%s">View Course</a>'), esc_url(get_permalink($post_ID))),
53 2 => __('Custom field updated.'),
54 3 => __('Custom field deleted.'),
55 4 => __('Course updated.'),
56 5 => isset($_GET['revision']) ? sprintf(__('Course restored to revision from %s'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
57 6 => sprintf(__('Course published. <a href="%s">View Course</a>'), esc_url(get_permalink($post_ID))),
58 7 => __('Course saved.'),
59 8 => sprintf(__('Course submitted. <a target="_blank" href="%s">Preview Course</a>'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))),
60 9 => sprintf(__('Course scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Course</a>'), date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)), esc_url(get_permalink($post_ID))),
61 10 => sprintf(__('Course draft updated. <a target="_blank" href="%s">Preview Course</a>'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))),
62 );
63 return $messages;
64 }
65 add_filter('post_updated_messages', 'wpc_course_messages');
66
67 // Register Custom Post Type Lesson
68 function wpc_register_lesson_cp()
69 {
70 $labels = array(
71 'name' => _x('Lessons', 'post type general name'),
72 'singular_name' => _x('Lesson', 'post type singular name'),
73 'add_new' => _x('Add New', 'Lesson'),
74 'add_new_item' => __('Add New Lesson'),
75 'edit_item' => __('Edit Lesson'),
76 'new_item' => __('New Lesson'),
77 'all_items' => __('All Lessons'),
78 'view_item' => __('View Lesson'),
79 'search_items' => __('Search Lessons'),
80 'not_found' => __('No lessons found'),
81 'not_found_in_trash' => __('No lessons found in Trash'),
82 'parent_item_colon' => '',
83 'menu_name' => __('Lessons', 'wp-courses'),
84 );
85 $args = array(
86 'show_in_admin_bar' => true,
87 'menu_icon' => null,
88 'show_in_nav_menus' => false,
89 'publicly_queryable' => true,
90 'exclude_from_search' => true,
91 'has_archive' => false,
92 'query_var' => true,
93 'can_export' => true,
94 'rewrite' => true,
95 'show_in_menu' => '',
96 'has_archive' => true,
97 'hierarchical' => true,
98 'public' => true,
99 'show_ui' => true,
100 'show_in_rest' => true,
101 'labels' => $labels,
102 'description' => __('Enter a lesson description here', 'wp-courses'),
103 'supports' => array('title', 'editor', 'excerpt', 'comments', 'revisions', 'author', 'custom-fields', 'page-attributes'),
104 );
105
106 register_post_type('lesson', $args);
107 flush_rewrite_rules(false);
108 }
109 add_action('init', 'wpc_register_lesson_cp');
110
111 //Custom Messages for Custom Post Type Lesson
112 function wpc_lesson_messages_cp($messages)
113 {
114 global $post;
115 $post_ID = get_the_id();
116 $messages['lesson'] = array(
117 0 => '',
118 1 => sprintf(__('Lesson updated. <a href="%s">View Lesson</a>'), esc_url(get_permalink($post_ID))),
119 2 => __('Custom field updated.'),
120 3 => __('Custom field deleted.'),
121 4 => __('Lesson updated.'),
122 5 => isset($_GET['revision']) ? sprintf(__('Lesson restored to revision from %s'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
123 6 => sprintf(__('Lesson published. <a href="%s">View Lesson</a>'), esc_url(get_permalink($post_ID))),
124 7 => __('Lesson saved.'),
125 8 => sprintf(__('Lesson submitted. <a target="_blank" href="%s">Preview Lesson</a>'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))),
126 9 => sprintf(__('Lesson scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Lesson</a>'), date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)), esc_url(get_permalink($post_ID))),
127 10 => sprintf(__('Lesson draft updated. <a target="_blank" href="%s">Preview Lesson</a>'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))),
128 );
129 return $messages;
130 }
131 add_filter('post_updated_messages', 'wpc_lesson_messages_cp');
132
133 // Register Custom Post Type Module
134 function wpc_register_module_cp()
135 {
136
137 $labels = array(
138 'name' => _x('Modules', 'post type general name'),
139 'singular_name' => _x('Module', 'post type singular name'),
140 'add_new' => _x('Add New', 'Module'),
141 'add_new_item' => __('Add New Module'),
142 'edit_item' => __('Edit Module'),
143 'new_item' => __('New Module'),
144 'all_items' => __('All Modules'),
145 'view_item' => __('View Module'),
146 'search_items' => __('Search Modules'),
147 'not_found' => __('No modules found'),
148 'not_found_in_trash' => __('No modules found in Trash'),
149 'parent_item_colon' => '',
150 'menu_name' => __('Modules', 'wp-courses'),
151 );
152
153 $args = array(
154 'show_in_admin_bar' => false,
155 'menu_icon' => null,
156 'show_in_nav_menus' => false,
157 'publicly_queryable' => true,
158 'exclude_from_search' => true,
159 'has_archive' => false,
160 'query_var' => true,
161 'can_export' => true,
162 'rewrite' => true,
163 'show_in_menu' => '',
164 'has_archive' => true,
165 'hierarchical' => false,
166 'public' => true,
167 'show_ui' => true,
168 'show_in_rest' => true,
169 'labels' => $labels,
170 'description' => __('Enter a module description here', 'wp-courses'),
171 'supports' => array('title'),
172 );
173
174 register_post_type('wpc-module', $args);
175 flush_rewrite_rules(false);
176 }
177 add_action('init', 'wpc_register_module_cp');
178 //Custom Messages for Custom Post Type Module
179 function wpc_module_messages_cp($messages)
180 {
181 global $post;
182 $post_ID = get_the_id();
183 $messages['wpc-module'] = array(
184 0 => '',
185 1 => sprintf(__('Module updated. <a href="%s">View Module</a>'), esc_url(get_permalink($post_ID))),
186 2 => __('Custom field updated.'),
187 3 => __('Custom field deleted.'),
188 4 => __('Module updated.'),
189 5 => isset($_GET['revision']) ? sprintf(__('Module restored to revision from %s'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
190 6 => sprintf(__('Module published. <a href="%s">View Module</a>'), esc_url(get_permalink($post_ID))),
191 7 => __('Module saved.'),
192 8 => sprintf(__('Module submitted. <a target="_blank" href="%s">Preview Module</a>'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))),
193 9 => sprintf(__('Module scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Module</a>'), date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)), esc_url(get_permalink($post_ID))),
194 10 => sprintf(__('Module draft updated. <a target="_blank" href="%s">Preview Module</a>'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))),
195 );
196 return $messages;
197 }
198 add_filter('post_updated_messages', 'wpc_module_messages_cp');
199
200 // Register Custom Post Type Teacher
201 function wpc_register_teacher_cp()
202 {
203 $labels = array(
204 'name' => _x('Teachers', 'post type general name'),
205 'singular_name' => _x('Teacher', 'post type singular name'),
206 'add_new' => _x('Add New', 'Teacher'),
207 'add_new_item' => __('Add New Teacher'),
208 'edit_item' => __('Edit Teacher'),
209 'new_item' => __('New Teacher'),
210 'all_items' => __('All Teachers'),
211 'view_item' => __('View Teacher'),
212 'search_items' => __('Search Teachers'),
213 'not_found' => __('No teachers found'),
214 'not_found_in_trash' => __('No teachers found in Trash'),
215 'parent_item_colon' => '',
216 'menu_name' => __('Teachers', 'wp-courses'),
217 );
218 $args = array(
219 'show_in_admin_bar' => true,
220 'menu_icon' => null,
221 'show_in_nav_menus' => false,
222 'publicly_queryable' => true,
223 'exclude_from_search' => true,
224 'query_var' => true,
225 'can_export' => true,
226 'rewrite' => true,
227 'show_in_menu' => '',
228 'has_archive' => true,
229 'hierarchical' => false,
230 'public' => true,
231 'show_ui' => true,
232 'show_in_rest' => true,
233 'labels' => $labels,
234 'description' => __('Enter a Teacher Description Here', 'wp-courses'),
235 'supports' => array('title', 'editor', 'excerpt', 'page-attributes', 'thumbnail'),
236 );
237
238 register_post_type('teacher', $args);
239 flush_rewrite_rules(false);
240 }
241 add_action('init', 'wpc_register_teacher_cp');
242 //Custom Messages for Custom Post Type Teacher
243 function wpc_teacher_messages($messages)
244 {
245 $permalink = get_permalink(get_the_ID());
246 $messages['course'] = array(
247 0 => '',
248 1 => sprintf(__('Teacher updated. <a href="%s">View Teacher</a>'), esc_url($permalink)),
249 2 => __('Custom field updated.'),
250 3 => __('Custom field deleted.'),
251 4 => __('Teacher updated.'),
252 5 => isset($_GET['revision']) ? sprintf(__('Teacher restored to revision from %s'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
253 6 => sprintf(__('Teacher published. <a href="%s">View Teacher</a>'), esc_url($permalink)),
254 7 => __('Teacher saved.'),
255 8 => sprintf(__('Teacher submitted. <a target="_blank" href="%s">Preview Teacher</a>'), esc_url(add_query_arg('preview', 'true', $permalink))),
256 9 => sprintf(__('Teacher scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Teacher</a>'), date_i18n(__('M j, Y @ G:i'), strtotime(get_the_ID())), esc_url($permalink)),
257 10 => sprintf(__('Teacher draft updated. <a target="_blank" href="%s">Preview Teacher</a>'), esc_url(add_query_arg('preview', 'true', $permalink))),
258 );
259 return $messages;
260 }
261 add_filter('post_updated_messages', 'wpc_teacher_messages');
262
263 // Register Custom Post Type wpc-quiz
264 function wpcq_register_quiz_cp()
265 {
266 $labels = array(
267 'name' => _x('Quizzes', 'post type general name'),
268 'singular_name' => _x('Quiz', 'post type singular name'),
269 'add_new' => _x('Add New', 'Quiz'),
270 'add_new_item' => __('Add New Quiz'),
271 'edit_item' => __('Edit Quiz'),
272 'new_item' => __('New Quiz'),
273 'all_items' => __('All Quizzes'),
274 'view_item' => __('View Quiz'),
275 'search_items' => __('Search Quizzes'),
276 'not_found' => __('No quizzes found'),
277 'not_found_in_trash' => __('No quizzes found in Trash'),
278 'parent_item_colon' => '',
279 'menu_name' => 'Quizzes'
280 );
281 $args = array(
282 'labels' => $labels,
283 'show_in_admin_bar' => true,
284 'menu_icon' => null,
285 'show_in_nav_menus' => false,
286 'publicly_queryable' => true,
287 'exclude_from_search' => true,
288 'has_archive' => true,
289 'query_var' => true,
290 'can_export' => true,
291 'rewrite' => true,
292 'show_in_menu' => '',
293 'description' => 'Enter a Quiz Description Here',
294 'public' => true,
295 'show_ui' => true,
296 'hierarchical' => false,
297 'supports' => array('title'),
298 'hierarchical' => false,
299 );
300 register_post_type('wpc-quiz', $args);
301 flush_rewrite_rules(false);
302 }
303 add_action('init', 'wpcq_register_quiz_cp');
304
305 // Remove View-links or add own View-links on wp-admin/edit.php pages
306 function wpc_remove_or_add_view_link($actions, $post)
307 {
308 $post_type = $post->post_type;
309
310 if (is_admin()) {
311 if ($post_type === 'teacher' || $post_type === 'wpc-email' || $post_type === 'wpc-badge' || $post_type === 'wpc-certificate') {
312 unset($actions['view']);
313 }
314 }
315
316 if (is_admin() && !wp_doing_ajax()) {
317 $courses_shortcode_url = wpc_get_main_shortcode_page_url();
318 $post_ID = $post->ID;
319 $permalink = '';
320
321 if ($post_type == 'course') {
322 if ($courses_shortcode_url) {
323 $permalink = $courses_shortcode_url;
324 } else {
325 $permalink = 'admin.php?page=wpc_shortcode_note';
326 }
327 } else if ($post_type == 'lesson') {
328 if ($courses_shortcode_url) {
329 $course_ids = wpc_get_connected_course_ids($post_ID);
330 $course_id = $course_ids[0];
331
332 if ($course_id !== '-1') {
333 $params = array(
334 'view' => 'single-lesson',
335 'course_id' => $course_id,
336 'lesson_id' => $post_ID,
337 'page' => 'null',
338 'category' => 'null',
339 'orderby' => 'null',
340 'search' => 'null',
341 );
342 $courses_hash = wpc_get_courses_hash($params);
343 $permalink = $courses_shortcode_url . $courses_hash;
344 } else {
345 $permalink = 'admin.php?page=wpc_shortcode_note';
346 }
347 } else {
348 $permalink = 'admin.php?page=wpc_shortcode_note';
349 }
350 } else if ($post_type == 'wpc-quiz') {
351 if ($courses_shortcode_url) {
352 $course_ids = wpc_get_connected_course_ids($post_ID, 'quiz-to-course');
353 $course_id = $course_ids[0];
354
355 if ($course_id !== '-1') {
356 $params = array(
357 'view' => 'single-quiz',
358 'course_id' => $course_id,
359 'lesson_id' => $post_ID,
360 'search' => 'null'
361 );
362 $courses_hash = wpc_get_courses_hash($params);
363 $permalink = $courses_shortcode_url . $courses_hash;
364 } else {
365 $permalink = 'admin.php?page=wpc_shortcode_note';
366 }
367 } else {
368 $permalink = 'admin.php?page=wpc_shortcode_note';
369 }
370 }
371
372 if ($permalink) {
373 $actions['wp_courses_view'] = sprintf(
374 '<a href="%s" class="wp-courses-view">%s</a>',
375 $permalink,
376 'View WP Courses');
377 }
378 }
379
380 return $actions;
381 }
382 add_filter('page_row_actions', 'wpc_remove_or_add_view_link', 10, 2);
383 add_filter('post_row_actions', 'wpc_remove_or_add_view_link', 10, 2);
384