LLMS_Meta_Box_Engagement::save( int $post_id )

Custom save method ensures that the faux fields are not saved to the postmeta table


Description Description


Parameters Parameters

$post_id

(int) (Required) WP Post ID of the engagement


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/admin/post-types/meta-boxes/class.llms.meta.box.engagement.php

	public function save( $post_id ) {

		// 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 = $_POST[ $field['id'] ];

						} // End if().
						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 );

					}
				}
			}// End if().
		}// End foreach().

		// locate and store the trigger post id
		$type = isset( $_POST[ $this->prefix . 'trigger_type' ] ) ? $_POST[ $this->prefix . 'trigger_type' ] : false;
		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;

		}// End switch().

		if ( $var ) {

			$val = isset( $_POST[ '_faux_engagement_trigger_post_' . $var ] ) ? sanitize_text_field( $_POST[ '_faux_engagement_trigger_post_' . $var ] ) : '';

		} else {

			$val = '';

		}

		update_post_meta( $post_id, $this->prefix . 'engagement_trigger_post', $val );

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.1.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.





Permalink: