<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[10926] sites/trunk/wordpress.org/public_html/wp-content: WordPress.org Learn: Sync with GitHub</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/10926">10926</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/10926","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>coreymckrill</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-04-26 23:09:28 +0000 (Mon, 26 Apr 2021)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>WordPress.org Learn: Sync with GitHub

https://github.com/WordPress/learn/commit/5133da6d34c524f7b4685400c8359842153fbf17</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporglearnincadminphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/admin.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporglearnincpostmetaphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-meta.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporglearnincposttypephp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-type.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporglearnviewsformworkshopapplicationphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/views/form-workshop-application.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporglearn2020functionsphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/functions.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporglearn2020templatepartscomponentworkshopfiltersphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/template-parts/component-workshop-filters.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporglearnincadminphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/admin.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/admin.php        2021-04-26 21:16:13 UTC (rev 10925)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/admin.php  2021-04-26 23:09:28 UTC (rev 10926)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2,6 +2,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> namespace WPOrg_Learn\Admin;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+use WP_Query;
+use function WordPressdotorg\Locales\get_locale_name_from_code;
+use function WPOrg_Learn\Post_Meta\get_available_workshop_locales;
+
</ins><span class="cx" style="display: block; padding: 0 10px"> defined( 'WPINC' ) || die();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -8,6 +12,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * Actions and filters.
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'admin_notices', __NAMESPACE__ . '\show_term_translation_notice' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+add_filter( 'manage_wporg_workshop_posts_columns', __NAMESPACE__ . '\add_workshop_list_table_columns' );
+add_action( 'manage_wporg_workshop_posts_custom_column', __NAMESPACE__ . '\render_workshop_list_table_columns', 10, 2 );
+add_filter( 'manage_edit-wporg_workshop_sortable_columns', __NAMESPACE__ . '\add_workshop_list_table_sortable_columns' );
+add_action( 'restrict_manage_posts', __NAMESPACE__ . '\add_workshop_list_table_filters', 10, 2 );
+add_action( 'pre_get_posts', __NAMESPACE__ . '\handle_workshop_list_table_filters' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px">  * Show a notice on taxonomy term screens about terms being translatable.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -55,3 +64,146 @@
</span><span class="cx" style="display: block; padding: 0 10px">        </div>
</span><span class="cx" style="display: block; padding: 0 10px">        <?php
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Add additional columns to the post list table for workshops.
+ *
+ * @param array $columns
+ *
+ * @return array
+ */
+function add_workshop_list_table_columns( $columns ) {
+       $columns = array_slice( $columns, 0, -2, true )
+                               + array( 'video_language' => __( 'Language', 'wporg-learn' ) )
+                               + array( 'video_caption_language' => __( 'Captions', 'wporg-learn' ) )
+                               + array_slice( $columns, -2, 2, true );
+
+       return $columns;
+}
+
+/**
+ * Render the cell contents for the additional columns in the post list table for workshops.
+ *
+ * @param string $column_name
+ * @param int    $post_id
+ *
+ * @return void
+ */
+function render_workshop_list_table_columns( $column_name, $post_id ) {
+       $post = get_post( $post_id );
+
+       switch ( $column_name ) {
+               case 'video_language':
+                       printf(
+                               '%s [%s]',
+                               esc_html( get_locale_name_from_code( $post->video_language, 'english' ) ),
+                               esc_html( $post->video_language )
+                       );
+                       break;
+               case 'video_caption_language':
+                       $captions = get_post_meta( $post->ID, 'video_caption_language' );
+
+                       echo esc_html( implode(
+                               ', ',
+                               array_map(
+                                       function( $caption_lang ) {
+                                               return get_locale_name_from_code( $caption_lang, 'english' );
+                                       },
+                                       $captions
+                               )
+                       ) );
+                       break;
+       }
+}
+
+/**
+ * Make additional columns sortable.
+ *
+ * @param array $sortable_columns
+ *
+ * @return array
+ */
+function add_workshop_list_table_sortable_columns( $sortable_columns ) {
+       $sortable_columns['video_language'] = 'video_language';
+
+       return $sortable_columns;
+}
+
+/**
+ * Add filtering controls for the workshops list table.
+ *
+ * @param string $post_type
+ * @param string $which
+ *
+ * @return void
+ */
+function add_workshop_list_table_filters( $post_type, $which ) {
+       if ( 'wporg_workshop' !== $post_type || 'top' !== $which ) {
+               return;
+       }
+
+       $available_locales = get_available_workshop_locales( 'video_language', 'english', false );
+       $language          = filter_input( INPUT_GET, 'language', FILTER_SANITIZE_STRING );
+
+       ?>
+       <label for="filter-by-language" class="screen-reader-text">
+               <?php esc_html_e( 'Filter by language', 'wporg-learn' ); ?>
+       </label>
+       <select id="filter-by-language" name="language">
+               <option value=""<?php selected( ! $language ); ?>><?php esc_html_e( 'Any language', 'wporg-learn' ); ?></option>
+               <?php foreach ( $available_locales as $code => $name ) : ?>
+                       <option value="<?php echo esc_attr( $code ); ?>"<?php selected( $code, $language ); ?>>
+                               <?php
+                               printf(
+                                       '%s [%s]',
+                                       esc_html( $name ),
+                                       esc_html( $code )
+                               );
+                               ?>
+                       </option>
+               <?php endforeach; ?>
+       </select>
+       <?php
+}
+
+/**
+ * Alter the query to include workshop list table filters.
+ *
+ * @param WP_Query $query
+ *
+ * @return void
+ */
+function handle_workshop_list_table_filters( WP_Query $query ) {
+       if ( ! is_admin() ) {
+               return;
+       }
+
+       $current_screen = get_current_screen();
+
+       if ( 'edit-wporg_workshop' === $current_screen->id ) {
+               $language = filter_input( INPUT_GET, 'language', FILTER_SANITIZE_STRING );
+
+               if ( $language ) {
+                       $meta_query = $query->get( 'meta_query', array() );
+
+                       if ( ! empty( $meta_query ) ) {
+                               $meta_query = array(
+                                       'relation' => 'AND',
+                                       $meta_query,
+                               );
+                       }
+
+                       $meta_query[] = array(
+                               'key'   => 'video_language',
+                               'value' => $language,
+                       );
+
+                       $query->set( 'meta_query', $meta_query );
+               }
+
+               if ( 'video_language' === $query->get( 'orderby' ) ) {
+                       $query->set( 'meta_key', 'video_language' );
+                       $query->set( 'orderby', 'meta_value' );
+               }
+       }
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporglearnincpostmetaphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-meta.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-meta.php    2021-04-26 21:16:13 UTC (rev 10925)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-meta.php      2021-04-26 23:09:28 UTC (rev 10926)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -217,22 +217,32 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px">  * Get a list of locales that are associated with at least one workshop.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Optionally only published workshops.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px">  * @param string $meta_key
</span><span class="cx" style="display: block; padding: 0 10px">  * @param string $label_language
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param bool   $published_only
</ins><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @return array
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function get_available_workshop_locales( $meta_key, $label_language = 'english' ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function get_available_workshop_locales( $meta_key, $label_language = 'english', $published_only = true ) {
</ins><span class="cx" style="display: block; padding: 0 10px">         global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        $and_post_status = '';
+       if ( $published_only ) {
+               $and_post_status = "AND posts.post_status = 'publish'";
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         $results = $wpdb->get_col( $wpdb->prepare(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $and_post_status contains no user input.
</ins><span class="cx" style="display: block; padding: 0 10px">                 "
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        SELECT DISTINCT meta_value
-                       FROM $wpdb->postmeta
-                       WHERE meta_key = %s
-                       ORDER BY meta_value ASC
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 SELECT DISTINCT postmeta.meta_value
+                       FROM {$wpdb->postmeta} postmeta
+                               JOIN {$wpdb->posts} posts ON posts.ID = postmeta.post_id $and_post_status
+                       WHERE postmeta.meta_key = %s
</ins><span class="cx" style="display: block; padding: 0 10px">                 ",
</span><span class="cx" style="display: block; padding: 0 10px">                $meta_key
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
</ins><span class="cx" style="display: block; padding: 0 10px">         ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        if ( empty( $results ) ) {
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporglearnincposttypephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-type.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-type.php    2021-04-26 21:16:13 UTC (rev 10925)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-type.php      2021-04-26 23:09:28 UTC (rev 10926)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -10,8 +10,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * Actions and filters.
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'init', __NAMESPACE__ . '\register' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-add_filter( 'manage_wporg_workshop_posts_columns', __NAMESPACE__ . '\add_workshop_list_table_columns' );
-add_action( 'manage_wporg_workshop_posts_custom_column', __NAMESPACE__ . '\render_workshop_list_table_columns', 10, 2 );
</del><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'jetpack_copy_post_post_types', __NAMESPACE__ . '\jetpack_copy_post_post_types' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'jetpack_sitemap_post_types', __NAMESPACE__ . '\jetpack_sitemap_post_types' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'jetpack_page_sitemap_other_urls', __NAMESPACE__ . '\jetpack_page_sitemap_other_urls' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -197,53 +195,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Add additional columns to the post list table for workshops.
- *
- * @param array $columns
- *
- * @return array
- */
-function add_workshop_list_table_columns( $columns ) {
-       $columns = array_slice( $columns, 0, -2, true )
-                               + array( 'video_language' => __( 'Language', 'wporg-learn' ) )
-                               + array( 'video_caption_language' => __( 'Captions', 'wporg-learn' ) )
-                               + array_slice( $columns, -2, 2, true );
-
-       return $columns;
-}
-
-/**
- * Render the cell contents for the additional columns in the post list table for workshops.
- *
- * @param string $column_name
- * @param int    $post_id
- *
- * @return void
- */
-function render_workshop_list_table_columns( $column_name, $post_id ) {
-       $post = get_post( $post_id );
-
-       switch ( $column_name ) {
-               case 'video_language':
-                       echo esc_html( get_locale_name_from_code( $post->video_language, 'english' ) );
-                       break;
-               case 'video_caption_language':
-                       $captions = get_post_meta( $post->ID, 'video_caption_language' );
-
-                       echo esc_html( implode(
-                               ', ',
-                               array_map(
-                                       function( $caption_lang ) {
-                                               return get_locale_name_from_code( $caption_lang, 'english' );
-                                       },
-                                       $captions
-                               )
-                       ) );
-                       break;
-       }
-}
-
-/**
</del><span class="cx" style="display: block; padding: 0 10px">  * Enable Jetpack's Copy Post module for more post types.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @param array $post_types
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporglearnviewsformworkshopapplicationphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/views/form-workshop-application.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/views/form-workshop-application.php  2021-04-26 21:16:13 UTC (rev 10925)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/views/form-workshop-application.php    2021-04-26 23:09:28 UTC (rev 10926)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -244,7 +244,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                <select id="language" name="language" class="do-select2" required>
</span><span class="cx" style="display: block; padding: 0 10px">                                        <?php foreach ( get_locales_with_native_names() as $code => $name ) : ?>
</span><span class="cx" style="display: block; padding: 0 10px">                                                <option value="<?php echo esc_attr( $code ); ?>" <?php selected( $code, $form['language'] ); ?>>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                        <?php echo esc_html( $name ); ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                 <?php
+                                                       printf(
+                                                               '%s [%s]',
+                                                               esc_html( $name ),
+                                                               esc_html( $code ),
+                                                       );
+                                                       ?>
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 </option>
</span><span class="cx" style="display: block; padding: 0 10px">                                        <?php endforeach; ?>
</span><span class="cx" style="display: block; padding: 0 10px">                                </select>
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporglearn2020functionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/functions.php        2021-04-26 21:16:13 UTC (rev 10925)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/functions.php  2021-04-26 23:09:28 UTC (rev 10926)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -291,6 +291,76 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'pre_get_posts', 'wporg_archive_modify_query' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Modify the workshop post type archive query to prioritize workshops in the user's locale.
+ *
+ * In order to show all workshops, but with the ones that are presented/captioned in the user's locale shown first, we
+ * need to modify the posts query in ways that can't be done through the WP_Query or WP_Meta_Query APIs. Instead, here,
+ * we're filtering the individual clauses of the query to add the pieces we need.
+ *
+ * Examples, slightly truncated for simplicity:
+ *
+ * Before:
+ * SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
+ * FROM wp_posts
+ * WHERE 1=1
+ * AND wp_posts.post_type = 'wporg_workshop'
+ * ORDER BY wp_posts.post_date DESC
+ *
+ * After:
+ * SELECT SQL_CALC_FOUND_ROWS wp_posts.*,
+ *   MAX( IF( pmeta.meta_key = 'video_language' AND pmeta.meta_value LIKE 'art_%', 1, 0 ) ) AS has_language,
+ *   MAX( IF( pmeta.meta_key = 'video_caption_language' AND pmeta.meta_value LIKE 'art_%', 1, 0 ) ) AS has_caption
+ * FROM wp_posts
+ * INNER JOIN wp_postmeta pmeta ON ( wp_posts.ID = pmeta.post_id )
+ * WHERE 1=1
+ * AND wp_posts.post_type = 'wporg_workshop'
+ * GROUP BY wp_posts.ID
+ * ORDER BY has_language DESC, has_caption DESC, wp_posts.post_date DESC
+ *
+ * @param array    $clauses
+ * @param WP_Query $query
+ *
+ * @return array
+ */
+function wporg_archive_query_prioritize_locale( $clauses, $query ) {
+       if ( ! $query->is_post_type_archive( 'wporg_workshop' ) || is_admin() ) {
+               return $clauses;
+       }
+
+       global $wpdb;
+
+       $locale      = get_locale();
+       $locale_root = preg_replace( '#^([a-z]{2,3}_?)[a-zA-Z_-]*#', '$1', $locale, -1, $count );
+
+       if ( $count ) {
+               /**
+                * $clauses['fields'] contains the SELECT part of the query.
+                *
+                * The extra fields clauses are calculated fields that will contain a `1` if the workshop post row has a postmeta
+                * value that matches the locale root. The MAX() and the groupby clause below ensure that all the rows for a
+                * given workshop are consolidated into one with the highest value in the calculated column. Without the
+                * grouping, there would be a separate row for each postmeta value for each workshop post.
+                */
+               $clauses['fields']  .= ",
+                       MAX( IF( pmeta.meta_key = 'video_language' AND pmeta.meta_value LIKE '{$locale_root}%', 1, 0 ) ) AS has_language
+               ";
+               $clauses['fields']  .= ",
+                       MAX( IF( pmeta.meta_key = 'video_caption_language' AND pmeta.meta_value LIKE '{$locale_root}%', 1, 0 ) ) AS has_caption
+               ";
+               $clauses['join']    .= " INNER JOIN {$wpdb->postmeta} pmeta ON ( {$wpdb->posts}.ID = pmeta.post_id )";
+               // This orderby clause ensures that the workshops are sorted by the values in the calculated columns first.
+               $clauses['orderby'] = 'has_language DESC, has_caption DESC, ' . $clauses['orderby'];
+
+               if ( false === strpos( $clauses['groupby'], "{$wpdb->posts}.ID" ) ) {
+                       $clauses['groupby'] = "{$wpdb->posts}.ID";
+               }
+       }
+
+       return $clauses;
+}
+add_filter( 'posts_clauses', 'wporg_archive_query_prioritize_locale', 10, 2 );
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px">  * Update a query object if filter parameters are present.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @param WP_Query $query Query object, passed by reference.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -344,6 +414,23 @@
</span><span class="cx" style="display: block; padding: 0 10px">        if ( is_array( $filters ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                $filters = array_filter( $filters );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // If both language and captions filters are set, we assume an "OR" relationship.
+               if ( isset( $filters['captions'], $filters['language'] ) ) {
+                       $meta_query[] = array(
+                               'relation' => 'OR',
+                               array(
+                                       'key'   => $entity_map['captions'],
+                                       'value' => $filters['captions'],
+                               ),
+                               array(
+                                       'key'   => $entity_map['language'],
+                                       'value' => $filters['language'],
+                               ),
+                       );
+
+                       unset( $filters['captions'], $filters['language'] );
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 foreach ( $filters as $filter_name => $filter_value ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        switch ( $filter_name ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                case 'search':
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporglearn2020templatepartscomponentworkshopfiltersphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/template-parts/component-workshop-filters.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/template-parts/component-workshop-filters.php        2021-04-26 21:16:13 UTC (rev 10925)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/template-parts/component-workshop-filters.php  2021-04-26 23:09:28 UTC (rev 10926)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -56,7 +56,15 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                                                value="<?php echo esc_attr( $item_value ); ?>"
</span><span class="cx" style="display: block; padding: 0 10px">                                                                <?php selected( $item_value, filter_input( INPUT_GET, $bucket['name'] ) ); ?>
</span><span class="cx" style="display: block; padding: 0 10px">                                                        >
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                                <?php echo esc_html( $item_label ); ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                         <?php if ( in_array( $bucket['name'], array( 'language', 'captions' ) ) ) :
+                                                                       printf(
+                                                                               '%s [%s]',
+                                                                               esc_html( $item_label ),
+                                                                               esc_html( $item_value ),
+                                                                       );
+                                                               else :
+                                                                       echo esc_html( $item_label );
+                                                               endif; ?>
</ins><span class="cx" style="display: block; padding: 0 10px">                                                         </option>
</span><span class="cx" style="display: block; padding: 0 10px">                                                <?php endforeach; ?>
</span><span class="cx" style="display: block; padding: 0 10px">                                        </select>
</span></span></pre>
</div>
</div>

</body>
</html>