Changeset 10458
- Timestamp:
- 11/20/2020 12:07:27 AM (4 years ago)
- 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 15 15 */ 16 16 add_action( 'init', __NAMESPACE__ . '\register' ); 17 add_action( 'add_meta_boxes', __NAMESPACE__ . '\add_lesson_plan_metaboxes' ); 17 18 add_action( 'add_meta_boxes', __NAMESPACE__ . '\add_workshop_metaboxes' ); 18 add_action( 'save_post_wporg_workshop', __NAMESPACE__ . '\save_workshop_metabox_fields', 10, 2 ); 19 add_action( 'save_post_lesson-plan', __NAMESPACE__ . '\save_lesson_plan_metabox_fields' ); 20 add_action( 'save_post_wporg_workshop', __NAMESPACE__ . '\save_workshop_metabox_fields' ); 19 21 20 22 /** … … 22 24 */ 23 25 function register() { 26 register_lesson_plan_meta(); 24 27 register_workshop_meta(); 28 } 29 30 /** 31 * Register post meta keys for lesson plans. 32 */ 33 function 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 ); 25 61 } 26 62 … … 189 225 190 226 /** 227 * Add meta boxes to the Edit Lesson Plan screen. 228 * 229 * Todo these should be replaced with block editor panels. 230 */ 231 function 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 */ 246 function 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 */ 256 function 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 /** 191 275 * Add meta boxes to the Edit Workshop screen. 192 276 * … … 261 345 * Update the post meta values from the meta box fields when the post is saved. 262 346 * 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 */ 349 function save_workshop_metabox_fields( $post_id ) { 267 350 if ( wp_is_post_revision( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) { 268 351 return; -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/functions.php
r10422 r10458 202 202 function wporg_post_type_is_lesson() { 203 203 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 false208 *209 * @return string|bool210 */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 false217 *218 * @return string|bool219 */220 function wporg_get_download_slides_url() {221 return get_post_meta( get_the_ID(), 'download_lesson_plan_slides_url', true );222 204 } 223 205 … … 622 604 return $siblings[ $index ] ?? false; 623 605 } 606 607 /** 608 * Robots "noindex" rules for specific parts of the Learn site. 609 * 610 * @param bool $noindex 611 * 612 * @return bool 613 */ 614 function wporg_learn_noindex( $noindex ) { 615 if ( is_singular( 'quiz' ) ) { 616 $noindex = true; 617 } 618 619 return $noindex; 620 } 621 add_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 8 8 */ 9 9 10 $slides_url = wporg_get_slides_url();11 $download_url = wporg_get_download_slides_url();12 10 ?> 13 11 … … 44 42 45 43 <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; ?> 59 60 <!-- <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> 61 65 </li> --> 62 66 </ul>
Note: See TracChangeset
for help on using the changeset viewer.