LLMS_Meta_Box_Engagement::save( int $post_id )
Custom save method.
Description Description
Ensures that the faux fields are not saved to the postmeta table.
Parameters Parameters
- $post_id
-
(int) (Required) WP Post ID of the engagement.
Return Return
(void)
Source Source
File: includes/admin/post-types/meta-boxes/class.llms.meta.box.engagement.php
public function save( $post_id ) {
if ( ! llms_verify_nonce( 'lifterlms_meta_nonce', 'lifterlms_save_data' ) ) {
return;
}
// Get all defined fields.
$fields = $this->get_fields();
if ( ! is_array( $fields ) ) {
return;
}
// Loop through the fields.
foreach ( $fields as $group => $data ) {
// Find the fields in each tab.
if ( isset( $data['fields'] ) && is_array( $data['fields'] ) ) {
// Loop through the fields.
foreach ( $data['fields'] as $field ) {
// Don't save things that don't have an ID.
if ( isset( $field['id'] ) ) {
// Skip our faux fields.
if ( 0 === strpos( $field['id'], '_faux_engagement_trigger_post_' ) ) {
continue;
}
// Get the posted value.
if ( isset( $_POST[ $field['id'] ] ) ) {
$val = llms_filter_input_sanitize_string( INPUT_POST, $field['id'] );
} elseif ( ! isset( $_POST[ $field['id'] ] ) ) {
$val = '';
}
// Update the value if we have one.
if ( isset( $val ) ) {
update_post_meta( $post_id, $field['id'], $val );
}
unset( $val );
}
}
}
}
// Locate and store the trigger post id.
$type = llms_filter_input( INPUT_POST, $this->prefix . 'trigger_type' );
switch ( $type ) {
case 'access_plan_purchased':
$var = 'access_plan';
break;
case 'course_completed':
case 'course_purchased':
case 'course_enrollment':
$var = 'course';
break;
case 'lesson_completed':
$var = 'lesson';
break;
case 'membership_purchased':
case 'membership_enrollment':
$var = 'membership';
break;
case 'quiz_completed':
case 'quiz_passed':
case 'quiz_failed':
$var = 'quiz';
break;
case 'section_completed':
$var = 'section';
break;
case 'course_track_completed':
$var = 'track';
break;
default:
$var = false;
}
if ( $var ) {
$val = llms_filter_input_sanitize_string( INPUT_POST, '_faux_engagement_trigger_post_' . $var );
} else {
$val = '';
}
update_post_meta( $post_id, $this->prefix . 'engagement_trigger_post', $val );
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 5.9.0 | Stop using deprecated FILTER_SANITIZE_STRING. |
| 3.35.0 | Verify nonce and access $_POST data via llms_filter_input(). |
| 3.11.0 | Unknown. |
| 3.1.0 | Introduced. |