LLMS_Admin_Metabox::save( int $post_id )

Save field data.


Description Description

Loops through fields and saves the data to postmeta.

Called by $this->save_actions().

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

(int) -1 When no user or user is missing required capabilities or when there's no or invalid nonce. 0 during inline saves or ajax requests or when no fields are found for the metabox. 1 if fields were found. This doesn't mean there weren't errors during saving.


Top ↑

Source Source

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

	protected function save( $post_id ) {

		if ( ! llms_verify_nonce( 'lifterlms_meta_nonce', 'lifterlms_save_data' ) || ! current_user_can( $this->capability, $post_id ) ) {
			return -1;
		}

		// Return early during quick saves and ajax requests.
		if ( ( isset( $_POST['action'] ) && 'inline-save' === $_POST['action'] ) || llms_is_ajax() ) {
			return 0;
		}

		// Get all defined fields.
		$fields = $this->get_fields();

		if ( ! is_array( $fields ) ) {
			return 0;
		}

		// 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'] ) ) {
						$this->save_field( $post_id, $field );
					}
				}
			}
		}

		return 1;

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.37.12 Move field sanitization and updates to the save_field() method.
3.36.1 Check metabox capability during saves. Return an int depending on return condition. Automatically add FILTER_REQUIRE_ARRAY flag when sanitizing a multi field.
3.36.0 Allow quotes when sanitizing some special fields that store a shortcode.
3.35.0 Added nonce verification before processing data; only access $_POST data via llms_filter_input().
3.14.1 Unknown.
3.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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