Making WordPress.org

Changeset 10458


Ignore:
Timestamp:
11/20/2020 12:07:27 AM (6 years ago)
Author:
coreymckrill
Message:

WordPress.org Learn: Sync with GitHub

https://github.com/WordPress/learn/compare/a6529c2090ca8a1dcc9e36e27460f6cbb84e02ef...2c9bbc5fc4eefb1f1a367f7bb8afcd3da6ef32b0

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
1 added
3 edited

Legend:

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

    r10376 r10458  
    1515 */
    1616add_action( 'init', __NAMESPACE__ . '\register' );
     17add_action( 'add_meta_boxes', __NAMESPACE__ . '\add_lesson_plan_metaboxes' );
    1718add_action( 'add_meta_boxes', __NAMESPACE__ . '\add_workshop_metaboxes' );
    18 add_action( 'save_post_wporg_workshop', __NAMESPACE__ . '\save_workshop_metabox_fields', 10, 2 );
     19add_action( 'save_post_lesson-plan', __NAMESPACE__ . '\save_lesson_plan_metabox_fields' );
     20add_action( 'save_post_wporg_workshop', __NAMESPACE__ . '\save_workshop_metabox_fields' );
    1921
    2022/**
     
    2224 */
    2325function register() {
     26        register_lesson_plan_meta();
    2427        register_workshop_meta();
     28}
     29
     30/**
     31 * Register post meta keys for lesson plans.
     32 */
     33function register_lesson_plan_meta() {
     34        $post_type = 'lesson-plan';
     35
     36        register_post_meta(
     37                $post_type,
     38                'slides_view_url',
     39                array(
     40                        'description'       => __( 'A URL for viewing lesson plan slides.', 'wporg_learn' ),
     41                        'type'              => 'string',
     42                        'single'            => true,
     43                        'default'           => '',
     44                        'sanitize_callback' => 'esc_url_raw',
     45                        'show_in_rest'      => true,
     46                )
     47        );
     48
     49        register_post_meta(
     50                $post_type,
     51                'slides_download_url',
     52                array(
     53                        'description'       => __( 'A URL for downloading lesson plan slides.', 'wporg_learn' ),
     54                        'type'              => 'string',
     55                        'single'            => true,
     56                        'default'           => '',
     57                        'sanitize_callback' => 'esc_url_raw',
     58                        'show_in_rest'      => true,
     59                )
     60        );
    2561}
    2662
     
    189225
    190226/**
     227 * Add meta boxes to the Edit Lesson Plan screen.
     228 *
     229 * Todo these should be replaced with block editor panels.
     230 */
     231function add_lesson_plan_metaboxes() {
     232        add_meta_box(
     233                'lesson-plan-slides',
     234                __( 'Slides', 'wporg_learn' ),
     235                __NAMESPACE__ . '\render_metabox_lesson_plan_slides',
     236                'lesson-plan',
     237                'side'
     238        );
     239}
     240
     241/**
     242 * Render the Lesson Plan Slides metabox.
     243 *
     244 * @param WP_Post $post
     245 */
     246function render_metabox_lesson_plan_slides( WP_Post $post ) {
     247        // The $post var is used in the include file.
     248        require get_views_path() . 'metabox-lesson-plan-slides.php';
     249}
     250
     251/**
     252 * Update the post meta values from the meta box fields when the post is saved.
     253 *
     254 * @param int $post_id
     255 */
     256function save_lesson_plan_metabox_fields( $post_id ) {
     257        if ( wp_is_post_revision( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) {
     258                return;
     259        }
     260
     261        // This nonce field is rendered in the Lesson Plan Slides metabox.
     262        $nonce = filter_input( INPUT_POST, 'lesson-plan-metabox-nonce' );
     263        if ( ! wp_verify_nonce( $nonce, 'lesson-plan-metaboxes' ) ) {
     264                return;
     265        }
     266
     267        $view_url = filter_input( INPUT_POST, 'slides-view-url', FILTER_VALIDATE_URL ) ?: '';
     268        update_post_meta( $post_id, 'slides_view_url', $view_url );
     269
     270        $download_url = filter_input( INPUT_POST, 'slides-download-url', FILTER_VALIDATE_URL ) ?: '';
     271        update_post_meta( $post_id, 'slides_download_url', $download_url );
     272}
     273
     274/**
    191275 * Add meta boxes to the Edit Workshop screen.
    192276 *
     
    261345 * Update the post meta values from the meta box fields when the post is saved.
    262346 *
    263  * @param int     $post_id
    264  * @param WP_Post $post
    265  */
    266 function save_workshop_metabox_fields( $post_id, WP_Post $post ) {
     347 * @param int $post_id
     348 */
     349function save_workshop_metabox_fields( $post_id ) {
    267350        if ( wp_is_post_revision( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) {
    268351                return;
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/functions.php

    r10422 r10458  
    202202function wporg_post_type_is_lesson() {
    203203        return get_post_type() == 'lesson-plan';
    204 }
    205 
    206 /**
    207  * Returns the custom field view_lesson_plan_slides_url, if it doesn't exists returns false
    208  *
    209  * @return string|bool
    210  */
    211 function wporg_get_slides_url() {
    212         return get_post_meta( get_the_ID(), 'view_lesson_plan_slides_url', true );
    213 }
    214 
    215 /**
    216  * Returns the custom field download_lesson_plan_slides_url, if it doesn't exists returns false
    217  *
    218  * @return string|bool
    219  */
    220 function wporg_get_download_slides_url() {
    221         return get_post_meta( get_the_ID(), 'download_lesson_plan_slides_url', true );
    222204}
    223205
     
    622604        return $siblings[ $index ] ?? false;
    623605}
     606
     607/**
     608 * Robots "noindex" rules for specific parts of the Learn site.
     609 *
     610 * @param bool $noindex
     611 *
     612 * @return bool
     613 */
     614function wporg_learn_noindex( $noindex ) {
     615        if ( is_singular( 'quiz' ) ) {
     616                $noindex = true;
     617        }
     618
     619        return $noindex;
     620}
     621add_filter( 'wporg_noindex_request', 'wporg_learn_noindex' );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/template-parts/content-single.php

    r10192 r10458  
    88 */
    99
    10 $slides_url   = wporg_get_slides_url();
    11 $download_url = wporg_get_download_slides_url();
    1210?>
    1311
     
    4442
    4543                                        <ul class="lp-links">
    46 
    47                                         <?php if ( $slides_url ) : ?>
    48                                                 <li>
    49                                                         <a href="<?php echo esc_url( $slides_url ); ?>" target="_blank"><span class="dashicons dashicons-admin-page"></span> <?php esc_html_e( 'View Lesson Plan Slides', 'wporg-learn' ); ?></a>
    50                                                 </li>
    51                                         <?php endif; ?>
    52 
    53                                         <?php if ( $download_url ) : ?>
    54                                                 <li>
    55                                                         <a href="<?php echo esc_url( $download_url ); ?>"><span class="dashicons dashicons-download"></span> <?php esc_html_e( 'Download Lesson Slides', 'wporg-learn' ); ?></a>
    56                                                 </li>
    57                                         <?php endif; ?>
    58                        
     44                                                <?php if ( $post->slides_view_url ) : ?>
     45                                                        <li>
     46                                                                <a href="<?php echo esc_attr( $post->slides_view_url ); ?>" target="_blank">
     47                                                                        <span class="dashicons dashicons-admin-page"></span>
     48                                                                        <?php esc_html_e( 'View Lesson Plan Slides', 'wporg-learn' ); ?>
     49                                                                </a>
     50                                                        </li>
     51                                                <?php endif; ?>
     52                                                <?php if ( $post->slides_download_url ) : ?>
     53                                                        <li>
     54                                                                <a href="<?php echo esc_attr( $post->slides_download_url ); ?>">
     55                                                                        <span class="dashicons dashicons-download"></span>
     56                                                                        <?php esc_html_e( 'Download Lesson Slides', 'wporg-learn' ); ?>
     57                                                                </a>
     58                                                        </li>
     59                                                <?php endif; ?>
    5960                                                <!-- <li>
    60                                                         <a href="#" target="_blank"><span class="dashicons dashicons-admin-post"></span> <?php esc_html_e( 'Print Lesson Plan', 'wporg-learn' ); ?></a>
     61                                                        <a href="#" target="_blank">
     62                                                                <span class="dashicons dashicons-admin-post"></span>
     63                                                                <?php esc_html_e( 'Print Lesson Plan', 'wporg-learn' ); ?>
     64                                                        </a>
    6165                                                </li> -->
    6266                                        </ul>
Note: See TracChangeset for help on using the changeset viewer.