Tribe_Meta_Box::save( $post_id )


Source

File: lib/tribe-meta-box.php

	public function save( $post_id ) {
		global $post_type;
		$post_type_object = get_post_type_object( $post_type );

		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )						// check autosave
		|| ( ! isset( $_POST['post_ID'] ) || $post_id != $_POST['post_ID'] )			// check revision
		|| ( ! in_array( $post_type, $this->_meta_box['pages'] ) )					// check if current post type is supported
		|| ( ! check_admin_referer( basename( __FILE__ ), 'tribe_meta_box_nonce' ) )		// verify nonce
		|| ( ! current_user_can( $post_type_object->cap->edit_post, $post_id ) ) ) {	// check permission
			return $post_id;
		}

		foreach ( $this->_fields as $field ) {
			$name = $field['meta'];
			$type = $field['type'];
			$old = get_post_meta( $post_id, $name, ! $field['multiple'] );
			$new = isset( $_POST[ $name ] ) ? $_POST[ $name ] : ( $field['multiple'] ? array() : '' );

			// validate meta value
			if ( class_exists( 'Tribe_Meta_Box_Validate' ) && method_exists( 'Tribe_Meta_Box_Validate', $field['validate_func'] ) ) {
				$new = call_user_func( array( 'Tribe_Meta_Box_Validate', $field['validate_func'] ), $new );
			}

			// call defined method to save meta value, if there's no methods, call common one
			$save_func = 'save_field_' . $type;
			if ( method_exists( $this, $save_func ) ) {
				call_user_func( array( $this, 'save_field_' . $type ), $post_id, $field, $old, $new );
			} else {
				$this->save_field( $post_id, $field, $old, $new );
			}
		}
	}