Making WordPress.org


Ignore:
Timestamp:
09/28/2022 11:18:13 PM (4 years ago)
Author:
adamwood
Message:

Learn: Sync with git WordPress/learn@f49e45d

File:
1 edited

Legend:

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

    r11413 r12096  
    2525 */
    2626function register_types() {
     27    register_lesson_plan_actions();
     28    register_lesson_plan_details();
    2729    register_workshop_details();
    2830    register_workshop_application_form();
     31}
     32
     33/**
     34 * Register Lesson Plan Actions block type and related assets.
     35 *
     36 * @throws Error If the build files are not found.
     37 */
     38function register_lesson_plan_actions() {
     39    $script_asset_path = get_build_path() . 'lesson-plan-actions.asset.php';
     40    if ( ! is_readable( $script_asset_path ) ) {
     41        throw new Error(
     42            'You need to run `npm start` or `npm run build` for the "wporg-learn/lesson-plan-actions" block first.'
     43        );
     44    }
     45
     46    $script_asset = require $script_asset_path;
     47    wp_register_script(
     48        'lesson-plan-actions-editor-script',
     49        get_build_url() . 'lesson-plan-actions.js',
     50        $script_asset['dependencies'],
     51        $script_asset['version'],
     52        true
     53    );
     54
     55    wp_register_style(
     56        'lesson-plan-actions-style',
     57        get_build_url() . 'style-lesson-plan-actions.css',
     58        array(),
     59        filemtime( get_build_path() . 'style-lesson-plan-actions.css' )
     60    );
     61
     62    register_block_type( 'wporg-learn/lesson-plan-actions', array(
     63        'editor_script'   => 'lesson-plan-actions-editor-script',
     64        'style'           => 'lesson-plan-actions-style',
     65        'render_callback' => __NAMESPACE__ . '\lesson_plan_actions_render_callback',
     66    ) );
     67}
     68
     69/**
     70 * Render the block content (html) on the frontend of the site.
     71 *
     72 * @param array  $attributes
     73 * @param string $content
     74 * @return string HTML output used by the block
     75 */
     76function lesson_plan_actions_render_callback( $attributes, $content ) {
     77    if ( get_post_type() !== 'lesson-plan' ) {
     78        return;
     79    }
     80
     81    $post = get_post();
     82
     83    ob_start();
     84    require get_views_path() . 'block-lesson-plan-actions.php';
     85
     86    return ob_get_clean();
     87}
     88
     89/**
     90 * Register Lesson Plan Details block type and related assets.
     91 *
     92 * @throws Error If the build files are not found.
     93 */
     94function register_lesson_plan_details() {
     95    $script_asset_path = get_build_path() . 'lesson-plan-details.asset.php';
     96    if ( ! is_readable( $script_asset_path ) ) {
     97        throw new Error(
     98            'You need to run `npm start` or `npm run build` for the "wporg-learn/lesson-plan-details" block first.'
     99        );
     100    }
     101
     102    $script_asset = require $script_asset_path;
     103    wp_register_script(
     104        'lesson-plan-details-editor-script',
     105        get_build_url() . 'lesson-plan-details.js',
     106        $script_asset['dependencies'],
     107        $script_asset['version'],
     108        true,
     109    );
     110
     111    wp_register_style(
     112        'lesson-plan-details-style',
     113        get_build_url() . 'style-lesson-plan-details.css',
     114        array(),
     115        filemtime( get_build_path() . 'style-lesson-plan-details.css' )
     116    );
     117
     118    register_block_type( 'wporg-learn/lesson-plan-details', array(
     119        'editor_script'   => 'lesson-plan-details-editor-script',
     120        'style'           => 'lesson-plan-details-style',
     121        'render_callback' => __NAMESPACE__ . '\lesson_plan_details_render_callback',
     122    ) );
     123}
     124
     125/**
     126 * Render the block content (html) on the frontend of the site.
     127 *
     128 * @param array  $attributes
     129 * @param string $content
     130 * @return string HTML output used by the block
     131 */
     132function lesson_plan_details_render_callback( $attributes, $content ) {
     133    if ( get_post_type() !== 'lesson-plan' ) {
     134        return;
     135    }
     136
     137    $details = wporg_learn_get_lesson_plan_taxonomy_data( get_the_ID(), 'single' );
     138
     139    ob_start();
     140    require get_views_path() . 'block-lesson-plan-details.php';
     141
     142    return ob_get_clean();
    29143}
    30144
     
    47161        get_build_url() . 'workshop-details.js',
    48162        $script_asset['dependencies'],
    49         $script_asset['version']
     163        $script_asset['version'],
     164        true,
    50165    );
    51166
     
    72187 */
    73188function workshop_details_render_callback( $attributes, $content ) {
     189    if ( get_post_type() !== 'wporg_workshop' ) {
     190        return;
     191    }
     192
    74193    $post      = get_post();
    75194    $topic_ids = wp_get_post_terms( $post->ID, 'topic', array( 'fields' => 'ids' ) );
Note: See TracChangeset for help on using the changeset viewer.