Making WordPress.org


Ignore:
Timestamp:
09/10/2021 10:25:05 PM (4 years ago)
Author:
coreymckrill
Message:

WordPress.org Learn: Sync with GitHub

https://github.com/WordPress/learn/compare/13104703090bd3b7f59cb7794a3a0ede50f4dfe8...b786efa59c12a5bb4c987f84ba5fc56e9c776c8f

File:
1 edited

Legend:

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

    r10926 r11225  
    66use WP_Post;
    77use function WordPressdotorg\Locales\{ get_locales_with_english_names };
    8 use function WPOrg_Learn\get_views_path;
     8use function WPOrg_Learn\{ get_build_path, get_build_url, get_views_path };
    99use function WPOrg_Learn\Form\get_workshop_application_field_schema;
    1010
     
    1919add_action( 'save_post_lesson-plan', __NAMESPACE__ . '\save_lesson_plan_metabox_fields' );
    2020add_action( 'save_post_wporg_workshop', __NAMESPACE__ . '\save_workshop_metabox_fields' );
     21add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_editor_assets' );
    2122
    2223/**
     
    2627    register_lesson_plan_meta();
    2728    register_workshop_meta();
     29    register_misc_meta();
    2830}
    2931
     
    139141        )
    140142    );
     143}
     144
     145/**
     146 * Register other post meta keys.
     147 *
     148 * For multiple post types, for example.
     149 */
     150function register_misc_meta() {
     151    // Expiration field.
     152    $post_types = array( 'lesson-plan', 'wporg_workshop', 'course', 'lesson' );
     153    foreach ( $post_types as $post_type ) {
     154        register_post_meta(
     155            $post_type,
     156            'expiration_date',
     157            array(
     158                'description'       => __( 'The date when the content of the post may be obsolete.', 'wporg_learn' ),
     159                'type'              => 'string',
     160                'single'            => true,
     161                'sanitize_callback' => function( $value ) {
     162                    return filter_var( $value, FILTER_SANITIZE_STRING );
     163                },
     164                'show_in_rest'      => true,
     165            )
     166        );
     167    }
    141168}
    142169
     
    431458    }
    432459}
     460
     461/**
     462 * Enqueue scripts for the block editor.
     463 */
     464function enqueue_editor_assets() {
     465    global $typenow;
     466
     467    $post_types_with_expiration = array( 'lesson-plan', 'wporg_workshop', 'course', 'lesson' );
     468    if ( in_array( $typenow, $post_types_with_expiration, true ) ) {
     469        $script_asset_path = get_build_path() . 'expiration-date.asset.php';
     470        if ( ! file_exists( $script_asset_path ) ) {
     471            wp_die( 'You need to run `yarn start` or `yarn build` to build the required assets.' );
     472        }
     473
     474        $script_asset = require( $script_asset_path );
     475        wp_enqueue_script(
     476            'wporg-learn-expiration-date',
     477            get_build_url() . 'expiration-date.js',
     478            $script_asset['dependencies'],
     479            $script_asset['version'],
     480            true
     481        );
     482
     483        wp_set_script_translations( 'wporg-learn-expiration-date', 'wporg-learn' );
     484    }
     485}
Note: See TracChangeset for help on using the changeset viewer.