Skip to content

Commit abaec3b

Browse files
bsetiawan88brianhoggideadude
authored
save post meta only for course post type (#2570)
* save post meta only for course post type * fix coding standards * Adding changelog. * Implementing changes in new template location. * Revert "Implementing changes in new template location." This reverts commit 2af59ba. --------- Co-authored-by: Brian Hogg <brian@lifterlms.com> Co-authored-by: Brian Hogg <brian@bhconsulting.ca> Co-authored-by: Jason Coleman <33220397+ideadude@users.noreply.github.com>
1 parent 9ddd9fd commit abaec3b

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

.changelogs/issue-887.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
significance: patch
2+
type: fixed
3+
links:
4+
- "#887"
5+
attributions:
6+
- "@bsetiawan88"
7+
entry: Avoids saving review meta information for non-courses.

includes/admin/class.llms.admin.reviews.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ public function add_review_meta_boxes( $content ) {
179179
* @return void
180180
*/
181181
public function save_review_meta_boxes() {
182+
$post_id = llms_filter_input( INPUT_POST, 'post_ID', FILTER_SANITIZE_NUMBER_INT );
183+
if ( ! $post_id ) {
184+
return;
185+
}
186+
187+
$post_type = get_post_type( $post_id );
188+
if ( 'course' !== $post_type ) {
189+
return;
190+
}
182191

183192
// phpcs:disable WordPress.Security.NonceVerification.Missing -- Nonce verified by core before triggering hook.
184193

@@ -187,14 +196,10 @@ public function save_review_meta_boxes() {
187196
$num = ( isset( $_POST['_llms_num_reviews'] ) ) ? llms_filter_input_sanitize_string( INPUT_POST, '_llms_num_reviews' ) : 0;
188197
$multiple = ( isset( $_POST['_llms_multiple_reviews_disabled'] ) ) ? llms_filter_input_sanitize_string( INPUT_POST, '_llms_multiple_reviews_disabled' ) : '';
189198

190-
$post_id = llms_filter_input( INPUT_POST, 'post_ID', FILTER_SANITIZE_NUMBER_INT );
191-
192-
if ( $post_id ) {
193-
update_post_meta( $post_id, '_llms_reviews_enabled', $enabled );
194-
update_post_meta( $post_id, '_llms_display_reviews', $display );
195-
update_post_meta( $post_id, '_llms_num_reviews', $num );
196-
update_post_meta( $post_id, '_llms_multiple_reviews_disabled', $multiple );
197-
}
199+
update_post_meta( $post_id, '_llms_reviews_enabled', $enabled );
200+
update_post_meta( $post_id, '_llms_display_reviews', $display );
201+
update_post_meta( $post_id, '_llms_num_reviews', $num );
202+
update_post_meta( $post_id, '_llms_multiple_reviews_disabled', $multiple );
198203
// phpcs:enable WordPress.Security.NonceVerification.Missing
199204
}
200205
}

0 commit comments

Comments
 (0)