LLMS_Admin_Metabox::save( int $post_id )

Save field data Loops through fields and saves the data to postmeta Called by $this->save_actions()


Description Description

This function is dumb. If the fields need to output error messages or do validation Override this method and create a custom save method to accommodate the validations or conditions


Parameters Parameters

$post_id

(int) (Required) WP Post ID of the post being saved


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/abstracts/abstract.llms.admin.metabox.php

	protected function save( $post_id ) {

		// dont save metabox during a quick save action
		if ( isset( $_POST['action'] ) && 'inline-save' === $_POST['action'] ) {
			return;
			// don't save during ajax calls
		} elseif ( llms_is_ajax() ) {
			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'] ) ) {

						// 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 foreach().

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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





Permalink: