LLMS_Meta_Box_Course_Options
Source Source
File: includes/admin/post-types/meta-boxes/class.llms.meta.box.course.options.php
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 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | * @since 3.36.0 Allow some fields to store values with quotes. */ class LLMS_Meta_Box_Course_Options extends LLMS_Admin_Metabox { /** * Configure the metabox settings * * @return void * @since 3.0.0 */ public function configure() { $this ->id = 'lifterlms-course-options' ; $this ->title = __( 'Course Options' , 'lifterlms' ); $this ->screens = 'course' ; $this ->priority = 'high' ; } /** * Setup fields. * * @since 1.0.0 * @since 3.36.0 Allow some fields to store values with quotes. * @since 7.1.3 Fixed condition for unsetting fields when using Gutenberg. * Replaced outdated URLs to WordPress' documentation about the list of sites you can embed from. * @since 7.1.4 Fixed issue that prevented the correct saving of the course length when using the block editor. * @since 7.2.0 Add function exists check for `llms_blocks_is_post_migrated`. * * @return array */ public function get_fields() { global $post ; $course = new LLMS_Course( $this ->post ); $course_tracks_options = get_terms( 'course_track' , 'hide_empty=0' ); $course_tracks = array (); foreach ( ( array ) $course_tracks_options as $term ) { $course_tracks [] = array ( 'key' => $term ->term_id, 'title' => $term ->name, ); } // Setup course difficulty select options. $difficulty_terms = get_terms( 'course_difficulty' , 'hide_empty=0' ); $difficulty_options = array (); foreach ( $difficulty_terms as $term ) { $difficulty_options [] = array ( 'key' => $term ->slug, 'title' => $term ->name, ); } $sales_page_content_type = 'none' ; if ( $post && 'auto-draft' !== $post ->post_status && $post ->post_excerpt ) { $sales_page_content_type = 'content' ; } $fields = array ( array ( 'title' => __( 'Sales Page' , 'lifterlms' ), 'fields' => array ( array ( 'allow_null' => false, 'class' => 'llms-select2' , 'desc' => __( 'Customize the content displayed to visitors and students who are not enrolled in the course.' , 'lifterlms' ), 'desc_class' => 'd-3of4 t-3of4 m-1of2' , 'default' => $sales_page_content_type , 'id' => $this ->prefix . 'sales_page_content_type' , 'is_controller' => true, 'label' => __( 'Sales Page Content' , 'lifterlms' ), 'type' => 'select' , 'value' => llms_get_sales_page_types(), ), array ( 'controller' => '#' . $this ->prefix . 'sales_page_content_type' , 'controller_value' => 'content' , 'desc' => __( 'This content will only be shown to visitors who are not enrolled in this course.' , 'lifterlms' ), 'id' => '' , 'label' => __( 'Sales Page Custom Content' , 'lifterlms' ), 'type' => 'post-excerpt' , ), array ( 'controller' => '#' . $this ->prefix . 'sales_page_content_type' , 'controller_value' => 'page' , 'data_attributes' => array ( 'post-type' => 'page' , 'placeholder' => __( 'Select a page' , 'lifterlms' ), ), 'class' => 'llms-select2-post' , 'id' => $this ->prefix . 'sales_page_content_page_id' , 'type' => 'select' , 'label' => __( 'Select a Page' , 'lifterlms' ), 'value' => $course ->get( 'sales_page_content_page_id' ) ? llms_make_select2_post_array( array ( $course ->get( 'sales_page_content_page_id' ) ) ) : array (), ), array ( 'controller' => '#' . $this ->prefix . 'sales_page_content_type' , 'controller_value' => 'url' , 'type' => 'text' , 'label' => __( 'Sales Page Redirect URL' , 'lifterlms' ), 'id' => $this ->prefix . 'sales_page_content_url' , 'class' => 'input-full' , 'value' => '' , 'desc_class' => 'd-all' , 'group' => 'top' , ), ), ), array ( 'title' => __( 'General' , 'lifterlms' ), 'fields' => array ( array ( 'type' => 'text' , 'label' => __( 'Course Length' , 'lifterlms' ), 'desc' => __( 'Enter a description of the estimated length. IE: 3 days' , 'lifterlms' ), 'id' => $this ->prefix . 'length' , 'class' => 'input-full' , 'value' => '' , 'desc_class' => 'd-all' , 'group' => 'top' , ), array ( 'class' => 'llms-select2' , 'id' => $this ->prefix . 'post_course_difficulty' , 'desc' => sprintf( __( 'Choose a course difficulty level. New difficulties can be added via %1$sCourses -> Difficulties%2$s.' , 'lifterlms' ), '<a href="' . admin_url( 'edit-tags.php?taxonomy=course_difficulty&post_type=course' ) . '">' , '</a>' ), 'desc_class' => 'd-all' , 'group' => 'bottom' , 'label' => __( 'Course Difficulty Category' , 'lifterlms' ), 'selected' => $course ->get_difficulty( 'slug' ), 'type' => 'select' , 'value' => $difficulty_options , ), array ( 'type' => 'text' , 'label' => __( 'Featured Video' , 'lifterlms' ), 'desc' => sprintf( __( 'Paste the url for a Wistia, Vimeo or Youtube video or a hosted video file. For a full list of supported providers see %s.' , 'lifterlms' ), '<a href="https://wordpress.org/documentation/article/embeds/#list-of-sites-you-can-embed-from" target="_blank">WordPress oEmbeds</a>' ), 'id' => $this ->prefix . 'video_embed' , 'class' => 'code input-full' , ), array ( 'desc' => __( 'When enabled, the featured video will be displayed on the course tile in addition to the course page.' , 'lifterlms' ), 'desc_class' => 'd-3of4 t-3of4 m-1of2' , 'id' => $this ->prefix . 'tile_featured_video' , 'label' => __( 'Display Featured Video on Course Tile' , 'lifterlms' ), 'type' => 'checkbox' , 'value' => 'yes' , ), array ( 'type' => 'text' , 'label' => __( 'Featured Audio' , 'lifterlms' ), 'desc' => sprintf( __( 'Paste the url for a SoundCloud or Spotify song or a hosted audio file. For a full list of supported providers see %s.' , 'lifterlms' ), '<a href="https://wordpress.org/documentation/article/embeds/#list-of-sites-you-can-embed-from" target="_blank">WordPress oEmbeds</a>' ), 'id' => $this ->prefix . 'audio_embed' , 'class' => 'code input-full' , ), ), ), array ( 'title' => __( 'Restrictions' , 'lifterlms' ), 'fields' => array ( array ( 'class' => 'input-full' , 'default' => __( 'You must enroll in this course to access course content.' , 'lifterlms' ), 'desc' => __( 'This message will be displayed when non-enrolled visitors attempt to access course content directly without enrolling first' , 'lifterlms' ), 'id' => $this ->prefix . 'content_restricted_message' , 'label' => __( 'Content Restricted Message' , 'lifterlms' ), 'type' => 'text' , ), array ( 'type' => 'checkbox' , 'label' => __( 'Enable Enrollment Period' , 'lifterlms' ), 'desc' => __( 'Set registration start and end dates for this course' , 'lifterlms' ), 'desc_class' => 'd-3of4 t-3of4 m-1of2' , 'id' => $this ->prefix . 'enrollment_period' , 'is_controller' => true, 'value' => 'yes' , ), array ( 'class' => 'llms-datepicker input-full' , 'controller' => '#' . $this ->prefix . 'enrollment_period' , 'controller_value' => 'yes' , 'desc' => __( 'Registration opens on this date.' , 'lifterlms' ), 'desc_class' => 'd-all' , 'id' => $this ->prefix . 'enrollment_start_date' , 'label' => __( 'Enrollment Start Date' , 'lifterlms' ), 'type' => 'date' , ), array ( 'class' => 'llms-datepicker input-full' , 'controller' => '#' . $this ->prefix . 'enrollment_period' , 'controller_value' => 'yes' , 'desc' => __( 'Registration closes on this date.' , 'lifterlms' ), 'desc_class' => 'd-all' , 'id' => $this ->prefix . 'enrollment_end_date' , 'label' => __( 'Enrollment End Date' , 'lifterlms' ), 'type' => 'date' , ), array ( 'class' => 'input-full' , 'controller' => '#' . $this ->prefix . 'enrollment_period' , 'controller_value' => 'yes' , 'default' => sprintf( __( 'Enrollment in this course opens on [lifterlms_course_info id="%d" key="enrollment_start_date"].' , 'lifterlms' ), $this ->post->ID ), 'desc' => sprintf( __( 'This message will be displayed to non-enrolled visitors before the Enrollment Start Date. You may use shortcodes like [lifterlms_course_info id="%d" key="enrollment_start_date"] in this message.' , 'lifterlms' ), $this ->post->ID ), 'id' => $this ->prefix . 'enrollment_opens_message' , 'label' => __( 'Enrollment Opens Message' , 'lifterlms' ), 'type' => 'text' , 'sanitize' => 'shortcode' , ), array ( 'class' => 'input-full' , 'controller' => '#' . $this ->prefix . 'enrollment_period' , 'controller_value' => 'yes' , 'default' => sprintf( __( 'Enrollment in this course closed on [lifterlms_course_info id="%d" key="enrollment_end_date"].' , 'lifterlms' ), $this ->post->ID ), 'desc' => sprintf( __( 'This message will be displayed to non-enrolled visitors once the Enrollment End Date has passed. You may use shortcodes like [lifterlms_course_info id="%d" key="enrollment_end_date"] in this message.' , 'lifterlms' ), $this ->post->ID ), 'id' => $this ->prefix . 'enrollment_closed_message' , 'label' => __( 'Enrollment Closed Message' , 'lifterlms' ), 'type' => 'text' , 'sanitize' => 'shortcode' , ), array ( 'type' => 'checkbox' , 'label' => __( 'Enable Course Time Period' , 'lifterlms' ), 'desc' => __( 'Set start and end dates for this course. Content can only be viewed and completed within the selected range.' , 'lifterlms' ), 'desc_class' => 'd-3of4 t-3of4 m-1of2' , 'id' => $this ->prefix . 'time_period' , 'is_controller' => true, 'value' => 'yes' , ), array ( 'class' => 'llms-datepicker input-full' , 'controller' => '#' . $this ->prefix . 'time_period' , 'controller_value' => 'yes' , 'desc_class' => 'd-all' , 'id' => $this ->prefix . 'start_date' , 'label' => __( 'Course Start Date' , 'lifterlms' ), 'type' => 'date' , ), array ( 'class' => 'llms-datepicker input-full' , 'controller' => '#' . $this ->prefix . 'time_period' , 'controller_value' => 'yes' , 'desc_class' => 'd-all' , 'id' => $this ->prefix . 'end_date' , 'label' => __( 'Course End Date' , 'lifterlms' ), 'type' => 'date' , ), array ( 'class' => 'input-full' , 'controller' => '#' . $this ->prefix . 'time_period' , 'controller_value' => 'yes' , 'default' => sprintf( __( 'This course opens on [lifterlms_course_info id="%d" key="start_date"].' , 'lifterlms' ), $this ->post->ID ), 'desc' => sprintf( __( 'This message will be displayed to non-enrolled visitors before the Course Start Date. You may use shortcodes like [lifterlms_course_info id="%d" key="start_date"] in this message.' , 'lifterlms' ), $this ->post->ID ), 'id' => $this ->prefix . 'course_opens_message' , 'label' => __( 'Course Opens Message' , 'lifterlms' ), 'type' => 'text' , 'sanitize' => 'shortcode' , ), array ( 'class' => 'input-full' , 'controller' => '#' . $this ->prefix . 'time_period' , 'controller_value' => 'yes' , 'default' => sprintf( __( 'This course closed on [lifterlms_course_info id="%d" key="end_date"].' , 'lifterlms' ), $this ->post->ID ), 'desc' => sprintf( __( 'This message will be displayed to non-enrolled visitors once the Course End Date has passed. You may use shortcodes like [lifterlms_course_info id="%d" key="end_date"] in this message.' , 'lifterlms' ), $this ->post->ID ), 'id' => $this ->prefix . 'course_closed_message' , 'label' => __( 'Course Closed Message' , 'lifterlms' ), 'type' => 'text' , 'sanitize' => 'shortcode' , ), array ( 'is_controller' => true, 'type' => 'checkbox' , 'label' => __( 'Enable Prerequisite' , 'lifterlms' ), 'desc' => __( 'Enable to choose a prerequisite course or course track' , 'lifterlms' ), 'id' => $this ->prefix . 'has_prerequisite' , 'class' => '' , 'value' => 'yes' , 'desc_class' => 'd-3of4 t-3of4 m-1of2' , ), array ( 'controller' => '#' . $this ->prefix . 'has_prerequisite' , 'controller_value' => 'yes' , 'data_attributes' => array ( 'post-type' => 'course' , 'allow-clear' => true, 'placeholder' => __( 'Select a course' , 'lifterlms' ), ), 'class' => 'llms-select2-post' , 'desc' => __( 'Select a prerequisite course. Students must have completed the selected course before they can view or complete content in this course.' , 'lifterlms' ), 'id' => $this ->prefix . 'prerequisite' , 'type' => 'select' , 'label' => __( 'Choose Prerequisite Course' , 'lifterlms' ), 'value' => llms_make_select2_post_array( array ( $course ->get( 'prerequisite' ) ) ), ), array ( 'class' => 'llms-select2' , 'controller' => '#' . $this ->prefix . 'has_prerequisite' , 'controller_value' => 'yes' , 'desc' => __( 'Select the prerequisite course track. Students must have completed the select track before they can view or complete content in this course.' , 'lifterlms' ), 'desc_class' => 'd-all' , 'id' => $this ->prefix . 'prerequisite_track' , 'type' => 'select' , 'label' => __( 'Choose Prerequisite Course Track' , 'lifterlms' ), 'value' => $course_tracks , ), array ( 'is_controller' => true, 'type' => 'checkbox' , 'label' => __( 'Enable Course Capacity' , 'lifterlms' ), 'desc' => __( 'Limit the number of users that can enroll in this course.' , 'lifterlms' ), 'id' => $this ->prefix . 'enable_capacity' , 'class' => '' , 'value' => 'yes' , 'desc_class' => 'd-3of4 t-3of4 m-1of2' , ), array ( 'class' => 'input-full' , 'controller' => '#' . $this ->prefix . 'enable_capacity' , 'controller_value' => 'yes' , 'desc_class' => 'd-all' , 'id' => $this ->prefix . 'capacity' , 'type' => 'number' , 'label' => __( 'Course Capacity' , 'lifterlms' ), ), array ( 'class' => 'input-full' , 'controller' => '#' . $this ->prefix . 'enable_capacity' , 'controller_value' => 'yes' , 'default' => __( 'Enrollment has closed because the maximum number of allowed students has been reached.' , 'lifterlms' ), 'desc' => __( 'This message will be displayed to non-enrolled visitors once the Course Capacity has been reached. ' , 'lifterlms' ), 'id' => $this ->prefix . 'capacity_message' , 'label' => __( 'Capacity Reached Message' , 'lifterlms' ), 'type' => 'text' , ), ), ), ); $current_screen = get_current_screen(); $is_gutenberg = is_object ( $current_screen ) && method_exists( $current_screen , 'is_block_editor' ) && $current_screen ->is_block_editor(); /** * Remove length and difficulty fields if * - the course is a new post and the editor is Gutenberg. * or * - the course is migrated to blocks used in the Gutenberg editor. */ if ( ( $is_gutenberg && 'auto-draft' === get_post_status( $this ->post->ID ) ) || function_exists( 'llms_blocks_is_post_migrated' ) && llms_blocks_is_post_migrated( $this ->post->ID ) ) { unset( $fields [1][ 'fields' ][0] ); // length. unset( $fields [1][ 'fields' ][1] ); // difficulty. } return $fields ; } /** * Update course difficulty on save * * @since 3.0.0 * @since 3.26.3 Only save when using the classic editor. * @since 3.35.0 Verify nonces and sanitize ` $_POST ` data. * @since 5.9.0 Stop using deprecated `FILTER_SANITIZE_STRING`. * * @param int $post_id WP Post ID of the course |
Expand full source code Collapse full source code View on GitHub
Methods Methods
- configure — Configure the metabox settings
- get_fields — Setup fields.
- save_before — Update course difficulty on save
Changelog Changelog
Version | Description |
---|---|
3.36.0 | Allow some fields to store values with quotes. |
3.35.0 | Verify nonces and sanitize $_POST data. |
1.0.0 | Introduced. |