Changeset 13754 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/blocks.php
- Timestamp:
- 05/29/2024 02:01:38 AM (23 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/blocks.php
r12291 r13754 8 8 use Sensei_Reports_Overview_Service_Courses; 9 9 use function WordPressdotorg\Locales\get_locale_name_from_code; 10 use function WPOrg_Learn\{get_build_path, get_build_url, get_ views_path};10 use function WPOrg_Learn\{get_build_path, get_build_url, get_js_path, get_views_path}; 11 11 use function WPOrg_Learn\Form\render_workshop_application_form; 12 12 use function WPOrg_Learn\Post_Meta\get_workshop_duration; … … 15 15 16 16 /** 17 * Views. 18 */ 19 require_once get_views_path() . 'block-course-status.php'; 20 require_once get_views_path() . 'block-learning-duration.php'; 21 require_once get_views_path() . 'block-lesson-count.php'; 22 23 /** 17 24 * Actions and filters. 18 25 */ 19 26 add_action( 'init', __NAMESPACE__ . '\register_types' ); 20 27 add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_block_style_assets' ); 28 add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_course_grid_assets' ); 21 29 add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_block_style_assets' ); 22 30 … … 27 35 */ 28 36 function register_types() { 37 register_course_data(); 38 register_course_status(); 39 register_learning_duration(); 40 register_lesson_count(); 29 41 register_lesson_plan_actions(); 30 42 register_lesson_plan_details(); 31 register_course_data();32 43 register_workshop_details(); 33 44 register_workshop_application_form(); … … 438 449 ); 439 450 } 451 452 /** 453 * Enqueue course grid assets. 454 * 455 * @throws Error If the build files are not found. 456 */ 457 function enqueue_course_grid_assets() { 458 $script_asset_path = get_build_path() . 'course-grid.asset.php'; 459 if ( ! is_readable( $script_asset_path ) ) { 460 throw new Error( 461 'You need to run `npm start` or `npm run build` for the "wporg-learn/course-grid" block first.' 462 ); 463 } 464 465 $script_asset = require $script_asset_path; 466 wp_enqueue_script( 467 'wporg-learn-course-grid', 468 get_build_url() . 'course-grid.js', 469 $script_asset['dependencies'], 470 $script_asset['version'], 471 true 472 ); 473 } 474 475 /** 476 * Register the learning duration block. 477 */ 478 function register_learning_duration() { 479 register_block_type( 480 get_js_path() . 'learning-duration/', 481 array( 482 'render_callback' => function( $attributes, $content, $block ) { 483 return \WPOrg_Learn\View\Blocks\Learning_Duration\render( $attributes, $content, $block ); 484 }, 485 ) 486 ); 487 } 488 489 /** 490 * Register the lesson count block. 491 */ 492 function register_lesson_count() { 493 register_block_type( 494 get_js_path() . 'lesson-count/', 495 array( 496 'render_callback' => function( $attributes, $content, $block ) { 497 return \WPOrg_Learn\View\Blocks\Lesson_Count\render( $attributes, $content, $block ); 498 }, 499 ) 500 ); 501 } 502 503 /** 504 * Register the course status block. 505 */ 506 function register_course_status() { 507 register_block_type( 508 get_js_path() . 'course-status/', 509 array( 510 'render_callback' => function( $attributes, $content, $block ) { 511 return \WPOrg_Learn\View\Blocks\Course_Status\render( $attributes, $content, $block ); 512 }, 513 ) 514 ); 515 } 516
Note: See TracChangeset
for help on using the changeset viewer.