Skip to content

Commit

Permalink
Workshops: Move layout elements from post_content to theme.
Browse files Browse the repository at this point in the history
Having them in `post_content` means that we have to manually update all existing posts every time we change the layout.
  • Loading branch information
iandunn committed Mar 31, 2021
1 parent bfabc32 commit 9005221
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 136 deletions.
15 changes: 15 additions & 0 deletions wp-content/plugins/wporg-learn/inc/post-meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ function register_lesson_plan_meta() {
function register_workshop_meta() {
$post_type = 'wporg_workshop';

register_post_meta(
$post_type,
'video_url',
array(
'description' => __( "The URL of the Workshop's video.", 'wporg_learn' ),
'type' => 'string',
'single' => true,
'sanitize_callback' => 'esc_url_raw',
'show_in_rest' => true,
)
);

register_post_meta(
$post_type,
'duration',
Expand Down Expand Up @@ -376,6 +388,9 @@ function save_workshop_metabox_fields( $post_id ) {
return;
}

$video_url = filter_input( INPUT_POST, 'video-url', FILTER_SANITIZE_URL );
update_post_meta( $post_id, 'video_url', $video_url );

$duration = filter_input( INPUT_POST, 'duration', FILTER_SANITIZE_NUMBER_INT, FILTER_REQUIRE_ARRAY );
if ( isset( $duration['h'], $duration['m'], $duration['s'] ) ) {
$duration = $duration['h'] * HOUR_IN_SECONDS + $duration['m'] * MINUTE_IN_SECONDS + $duration['s'];
Expand Down
108 changes: 31 additions & 77 deletions wp-content/plugins/wporg-learn/inc/post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ function register_workshop() {
'publicly_queryable' => true,
'capability_type' => 'page',
'show_in_rest' => true,
'template_lock' => 'all',
'rewrite' => array( 'slug' => 'workshop' ),
'template' => generate_workshop_template_structure(),
);
Expand All @@ -148,95 +147,50 @@ function register_workshop() {
/**
* Create an array representation of a workshop's content template.
*
* Note that if this template structure changes, the content in views/content-workshop.php
* ⚠️ Note that if this template structure changes, the content in views/content-workshop.php
* will also need to be updated.
*
* @return array
*/
function generate_workshop_template_structure() {
$template = array(
array(
'core/embed',
'core/paragraph',
array(
'className' => 'workshop-page_video',
'providerNameSlug' => 'wordpress-tv',
'placeholder' => __( 'Describe what the workshop is about.', 'wporg-learn' ),
),
),

// Learning outcomes
array(
'core/heading',
array(
'level' => '2',
'content' => __( 'Learning outcomes', 'wporg-learn' ),
),
),
array(
'core/columns',
array( 'className' => 'workshop-page_content' ),
'core/list',
array(
array(
'core/column',
array( 'width' => '66.66%' ),
array(
array(
'core/paragraph',
array(
'placeholder' => __( 'Describe what the workshop is about.', 'wporg-learn' ),
),
),
array(
'core/heading',
array(
'level' => '2',
'content' => __( 'Learning outcomes', 'wporg-learn' ),
),
),
array(
'core/list',
array(
'className' => 'workshop-page_list',
'ordered' => true,
),
),
array(
'core/heading',
array(
'level' => '2',
'content' => __( 'Comprehension questions', 'wporg-learn' ),
),
),
array(
'core/list',
array(
'className' => 'workshop-page_list',
),
),
),
), // End column block.
array(
'core/column',
array(
'className' => 'workshop-page_sidebar',
'width' => '33.333%',
),
array(
array( 'wporg-learn/workshop-details' ),
array(
'core/button',
array(
'className' => 'is-style-secondary-full-width',
'text' => __( 'Join a Group Discussion', 'wporg-learn' ),
'url' => 'https://www.meetup.com/learn-wordpress-discussions/events/',
'borderRadius' => 5,
),
),
array(
'core/paragraph',
array(
'className' => 'terms',
'content' => sprintf(
__( 'You must agree to our <a href="%s">Code of Conduct</a> in order to participate.', 'wporg-learn' ),
'https://learn.wordpress.org/code-of-conduct/'
),
),
),
),
), // End column block.
'className' => 'workshop-page_list',
'ordered' => true,
),
), // End columns block.
array( 'core/separator' ),
),

// Comprehension questions
array(
'core/heading',
array(
'level' => '2',
'content' => __( 'Comprehension questions', 'wporg-learn' ),
),
),
array(
'core/list',
array(
'className' => 'workshop-page_list',
),
),
);

return $template;
Expand Down
80 changes: 24 additions & 56 deletions wp-content/plugins/wporg-learn/views/content-workshop.php
Original file line number Diff line number Diff line change
@@ -1,69 +1,37 @@
<?php

/**
* Content for auto-generated workshop posts.
*
* Note that if the template for the workshop post type changes, this will need to be updated as well.
* ⚠️ Note that if the template for the workshop post type changes, this will need to be updated as well.
*
* phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- The data from this file is being saved to
* the database rather than output; therefore it should be validated rather than escaped. It's validated by
* `validate_workshop_application_form_submission()`, which strips all HTML tags.
*/

/** @var array $blurbs */
?>
<!-- wp:core-embed/wordpress-tv {"className":"workshop-page_video"} /-->

<!-- wp:columns {"className":"workshop-page_content"} -->
<div class="wp-block-columns workshop-page_content">
<!-- wp:column {"width":66.66} -->
<div class="wp-block-column" style="flex-basis:66.66%">
<?php echo $blurbs['description']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>

<!-- wp:heading {"level":"2"} -->
<h2><?php esc_html_e( 'Learning outcomes', 'wporg-learn' ); ?></h2>
<!-- /wp:heading -->

<!-- wp:list {"ordered":true,"className":"workshop-page_list"} -->
<ol class="workshop-page_list">
<?php echo $blurbs['learning-objectives']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</ol>
<!-- /wp:list -->

<!-- wp:heading {"level":"2"} -->
<h2><?php esc_html_e( 'Comprehension questions', 'wporg-learn' ); ?></h2>
<!-- /wp:heading -->
?>

<!-- wp:list {"className":"workshop-page_list"} -->
<ul class="workshop-page_list">
<?php echo $blurbs['comprehension-questions']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</ul>
<!-- /wp:list -->
</div>
<!-- /wp:column -->
<?php echo $blurbs['description']; ?>

<!-- wp:column {"width":33.333,"className":"workshop-page_sidebar"} -->
<div class="wp-block-column workshop-page_sidebar" style="flex-basis:33.333%">
<!-- wp:wporg-learn/workshop-details /-->
<!-- wp:heading {"level":"2"} -->
<h2><?php esc_html_e( 'Learning outcomes', 'wporg-learn' ); ?></h2>
<!-- /wp:heading -->

<!-- wp:button {"borderRadius":5,"className":"is-style-secondary-full-width"} -->
<div class="wp-block-button is-style-secondary-full-width">
<a class="wp-block-button__link" href="https://www.meetup.com/learn-wordpress-discussions/events/" style="border-radius:5px">
<?php esc_html_e( 'Join a Group Discussion', 'wporg-learn' ); ?>
</a>
</div>
<!-- /wp:button -->
<!-- wp:list {"ordered":true,"className":"workshop-page_list"} -->
<ol class="workshop-page_list">
<?php echo $blurbs['learning-objectives']; ?>
</ol>
<!-- /wp:list -->

<!-- wp:paragraph {"className":"terms"} -->
<p class="terms">
<?php
printf(
wp_kses_post( __( 'You must agree to our <a href="%s">Code of Conduct</a> in order to participate.', 'wporg-learn' ) ),
'https://learn.wordpress.org/code-of-conduct/'
);
?>
</p>
<!-- /wp:paragraph -->
</div>
<!-- /wp:column -->
</div>
<!-- /wp:columns -->
<!-- wp:heading {"level":"2"} -->
<h2><?php esc_html_e( 'Comprehension questions', 'wporg-learn' ); ?></h2>
<!-- /wp:heading -->

<!-- wp:separator -->
<hr class="wp-block-separator"/>
<!-- /wp:separator -->
<!-- wp:list {"className":"workshop-page_list"} -->
<ul class="workshop-page_list">
<?php echo $blurbs['comprehension-questions']; ?>
</ul>
<!-- /wp:list -->
15 changes: 15 additions & 0 deletions wp-content/plugins/wporg-learn/views/metabox-workshop-details.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
/** @var array $selected_lessons */
?>

<p>
<label><?php esc_html_e( 'WordPress.tv URL', 'wporg_learn' ); ?></label><br />
<label for="workshop-video-url">
<textarea
id="workshop-video-url"
name="video-url"
class="large-text"
rows="4"
><?php echo esc_url( $post->video_url ); ?></textarea>
</label>
</p>

<p>
<label><?php esc_html_e( 'Duration', 'wporg_learn' ); ?></label><br />
<label for="workshop-duration-hours">
Expand All @@ -20,6 +32,7 @@
class="tiny-text"
type="number"
value="<?php echo absint( $duration_interval->h ); ?>"
min="0"
max="23"
/>
<?php esc_html_e( 'hours', 'wporg_learn' ); ?>
Expand All @@ -31,6 +44,7 @@ class="tiny-text"
class="tiny-text"
type="number"
value="<?php echo absint( $duration_interval->i ); ?>"
min="0"
max="59"
/>
<?php esc_html_e( 'minutes', 'wporg_learn' ); ?>
Expand All @@ -42,6 +56,7 @@ class="tiny-text"
class="tiny-text"
type="number"
value="<?php echo absint( $duration_interval->s ); ?>"
min="0"
max="59"
/>
<?php esc_html_e( 'seconds', 'wporg_learn' ); ?>
Expand Down
16 changes: 15 additions & 1 deletion wp-content/themes/pub/wporg-learn-2020/single-wporg_workshop.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,21 @@
<?php
while ( have_posts() ) {
the_post();
get_template_part( 'template-parts/content', 'workshop-single' );

/*
* Old posts have the layout and presentation of meta data hardcoded into `post_content`, but
* newer posts only store prose there. Meta data, layout, etc is handled in
* `content-workshop-single.php`.
*/
$layout_hardcoded = has_block( 'core/columns' )
&& has_block( 'wporg-learn/workshop-details' )
&& has_block( 'core/separator' );

if ( $layout_hardcoded ) {
get_template_part( 'template-parts/content', 'workshop-single-hardcoded' );
} else {
get_template_part( 'template-parts/content', 'workshop-single' );
}
}
?>
</main><!-- #main -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/*
* This deprecated template is for old posts that have Column/Embed/etc blocks hardcoded into `post_content`.
* See `single-wporg_workshop.php`.
*/

?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<section>
<div class="row align-middle between section-heading section-heading--with-space">
<h1 class="section-heading_title h2"><?php the_title(); ?></h1>
</div>
<hr>
<div class="workshop-page">
<?php the_content(); ?>
<?php if ( is_object_in_term( get_the_ID(), 'wporg_workshop_series' ) ) : ?>
<?php get_template_part( 'template-parts/component', 'series-navigation' ); ?>
<hr class="wp-block-separator" />
<?php endif; ?>
<?php foreach ( wporg_get_workshop_presenters() as $presenter ) : ?>
<section class="row workshop-page_section"">
<div class="col-4">
<?php
get_template_part(
'template-parts/component',
'workshop-presenter',
array(
'presenter' => $presenter,
)
);
?>
</div>
<div class="col-8 workshop-page_biography">
<?php echo wp_kses_data( wpautop( wporg_get_workshop_presenter_bio( $presenter ) ) ); ?>
</div>
</section>
<?php endforeach; ?>
</div>
</section>
</article>

0 comments on commit 9005221

Please sign in to comment.