-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add filtering of lesson plans by language #1500
Changes from 7 commits
99f0cdd
8417db5
7b942e6
085e011
13ab2e4
463ea9d
4c1afee
6f881b8
6807634
4cb6519
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,35 +257,40 @@ function get_workshop_duration( WP_Post $workshop, $format = 'raw' ) { | |
} | ||
|
||
/** | ||
* Get a list of locales that are associated with at least one workshop. | ||
* | ||
* Optionally only published workshops. | ||
* Get a list of locales that are associated with at least one post of the specified type. | ||
* | ||
* @param string $meta_key | ||
* @param string $post_type | ||
* @param string $label_language | ||
* @param bool $published_only | ||
* @param string $post_status | ||
* | ||
* @return array | ||
*/ | ||
function get_available_workshop_locales( $meta_key, $label_language = 'english', $published_only = true ) { | ||
function get_available_post_type_locales( $meta_key, $post_type, $label_language = 'english', $post_status ) { | ||
global $wpdb; | ||
|
||
$and_post_status = ''; | ||
if ( $published_only ) { | ||
$and_post_status = "AND posts.post_status = 'publish'"; | ||
} | ||
|
||
$results = $wpdb->get_col( $wpdb->prepare( | ||
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $and_post_status contains no user input. | ||
" | ||
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 | ||
", | ||
$meta_key | ||
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared | ||
) ); | ||
$results = isset( $post_status ) | ||
? $wpdb->get_col( $wpdb->prepare( | ||
" | ||
SELECT DISTINCT postmeta.meta_value | ||
FROM {$wpdb->postmeta} postmeta | ||
JOIN {$wpdb->posts} posts ON posts.ID = postmeta.post_id AND posts.post_type = %s AND posts.post_status = %s | ||
WHERE postmeta.meta_key = %s | ||
", | ||
$post_type, | ||
$post_status, | ||
$meta_key | ||
) ) | ||
: $wpdb->get_col( $wpdb->prepare( | ||
" | ||
SELECT DISTINCT postmeta.meta_value | ||
FROM {$wpdb->postmeta} postmeta | ||
JOIN {$wpdb->posts} posts ON posts.ID = postmeta.post_id AND posts.post_type = %s | ||
WHERE postmeta.meta_key = %s | ||
", | ||
$post_type, | ||
$meta_key | ||
) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I worry that duplicating the query here could lead to them accidentally getting out of sync, and it seems less readable to me. What do you think about integrating There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it's a fair point. I was trying to remove the need for |
||
|
||
if ( empty( $results ) ) { | ||
return array(); | ||
|
@@ -345,6 +350,15 @@ function save_lesson_plan_metabox_fields( $post_id ) { | |
|
||
$download_url = filter_input( INPUT_POST, 'slides-download-url', FILTER_VALIDATE_URL ) ?: ''; | ||
update_post_meta( $post_id, 'slides_download_url', $download_url ); | ||
|
||
// This language meta field is rendered in the editor sidebar using a PluginDocumentSettingPanel block, | ||
// which won't save the field on publish if it has the default value. | ||
// Our filtering by locale depends on it being set, so we force it to be updated after saving: | ||
$language = get_post_meta( $post_id, 'language', true ); | ||
$language_default = 'en_US'; | ||
if ( ! isset( $language ) || $language_default === $language ) { | ||
update_post_meta( $post_id, 'language', $language_default ); | ||
} | ||
Comment on lines
+349
to
+356
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This follows the same approach that we had to take with Tutorials: https://github.com/WordPress/Learn/blob/trunk/wp-content/plugins/wporg-learn/inc/post-meta.php#L525
|
||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get this notice on PHP
8.0.28
. We don't run that on prod yet, but will in the near future, so it'd be good to be prepared now IMO.PHP Deprecated: Required parameter $post_status follows optional parameter $label_language in wp-content/plugins/wporg-learn/inc/post-meta.php on line 269
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 4cb6519