Making WordPress.org


Ignore:
Timestamp:
05/29/2024 02:01:38 AM (2 years ago)
Author:
adamwood
Message:

Learn: Sync with git WordPress/learn@9535e1c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/blocks.php

    r12291 r13754  
    88use Sensei_Reports_Overview_Service_Courses;
    99use function WordPressdotorg\Locales\get_locale_name_from_code;
    10 use function WPOrg_Learn\{get_build_path, get_build_url, get_views_path};
     10use function WPOrg_Learn\{get_build_path, get_build_url, get_js_path, get_views_path};
    1111use function WPOrg_Learn\Form\render_workshop_application_form;
    1212use function WPOrg_Learn\Post_Meta\get_workshop_duration;
    … …  
    1515
    1616/**
     17 * Views.
     18 */
     19require_once get_views_path() . 'block-course-status.php';
     20require_once get_views_path() . 'block-learning-duration.php';
     21require_once get_views_path() . 'block-lesson-count.php';
     22
     23/**
    1724 * Actions and filters.
    1825 */
    1926add_action( 'init', __NAMESPACE__ . '\register_types' );
    2027add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_block_style_assets' );
     28add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_course_grid_assets' );
    2129add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_block_style_assets' );
    2230
    … …  
    2735 */
    2836function register_types() {
     37        register_course_data();
     38        register_course_status();
     39        register_learning_duration();
     40        register_lesson_count();
    2941        register_lesson_plan_actions();
    3042        register_lesson_plan_details();
    31         register_course_data();
    3243        register_workshop_details();
    3344        register_workshop_application_form();
    … …  
    438449        );
    439450}
     451
     452/**
     453 * Enqueue course grid assets.
     454 *
     455 * @throws Error If the build files are not found.
     456 */
     457function 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 */
     478function 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 */
     492function 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 */
     506function 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.