Making WordPress.org


Ignore:
Timestamp:
07/03/2024 10:55:23 PM (2 years ago)
Author:
adamwood
Message:

Learn: Sync with git WordPress/learn@e0208b2

File:
1 edited

Legend:

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

    r13862 r13873  
    2828 */
    2929function register() {
     30        register_lesson_meta();
    3031        register_lesson_plan_meta();
    3132        register_workshop_meta();
    3233        register_misc_meta();
     34}
     35
     36/**
     37 * Register post meta keys for lessons.
     38 */
     39function register_lesson_meta() {
     40        register_post_meta(
     41                'lesson',
     42                '_lesson_featured',
     43                array(
     44                        'description'       => __( 'Whether the lesson is featured.', 'wporg-learn' ),
     45                        'type'              => 'string',
     46                        'single'            => true,
     47                        'sanitize_callback' => 'sanitize_text_field',
     48                        'show_in_rest'      => true,
     49                        'auth_callback'     => function( $allowed, $meta_key, $post_id ) {
     50                                return current_user_can( 'edit_post', $post_id );
     51                        },
     52                ),
     53        );
    3354}
    3455
    … …  
    614635        enqueue_expiration_date_assets();
    615636        enqueue_language_meta_assets();
     637        enqueue_lesson_featured_meta_assets();
    616638        enqueue_duration_meta_assets();
    617639}
    … …  
    671693
    672694/**
     695 * Enqueue scripts for the featured lesson meta block.
     696 */
     697function enqueue_lesson_featured_meta_assets() {
     698        global $typenow;
     699
     700        if ( 'lesson' === $typenow ) {
     701                $script_asset_path = get_build_path() . 'lesson-featured-meta.asset.php';
     702                if ( ! file_exists( $script_asset_path ) ) {
     703                        wp_die( 'You need to run `yarn start` or `yarn build` to build the required assets.' );
     704                }
     705
     706                $script_asset = require( $script_asset_path );
     707                wp_enqueue_script(
     708                        'wporg-learn-lesson-featured-meta',
     709                        get_build_url() . 'lesson-featured-meta.js',
     710                        $script_asset['dependencies'],
     711                        $script_asset['version'],
     712                        true
     713                );
     714
     715                wp_set_script_translations( 'wporg-learn-lesson-featured-meta', 'wporg-learn' );
     716        }
     717}
     718
     719/**
    673720 * Enqueue scripts for the duration meta block.
    674721 */
Note: See TracChangeset for help on using the changeset viewer.