Astra_Ext_Advanced_Headers_Meta::save_meta_box( number $post_id )

Metabox Save


Description


Parameters

$post_id

(number) (Required) Post ID.


Return

(void)


Source

File: addons/advanced-headers/classes/class-astra-ext-advanced-headers-meta.php

		public function save_meta_box( $post_id ) {

			// Checks save status.
			$is_autosave = wp_is_post_autosave( $post_id );
			$is_revision = wp_is_post_revision( $post_id );

			$is_valid_nonce = ( isset( $_POST['astra-advanced-headers'] ) && wp_verify_nonce( $_POST['astra-advanced-headers'], basename( __FILE__ ) ) ) ? true : false;

			// Exits script depending on save status.
			if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
				return;
			}

			/**
			 * Get meta options
			 */
			$post_meta             = self::get_meta_option();
			$advanced_headers_meta = array(
				'ast-advanced-headers-layout',
				'ast-advanced-headers-design',
			);

			foreach ( $post_meta as $key => $data ) {
				if ( in_array( $key, $advanced_headers_meta ) ) {
					$meta_value = array_map( 'esc_attr', $_POST[ $key ] );
					$meta_value = array_map( 'stripslashes', $_POST[ $key ] );
				} elseif ( in_array( $key, array( 'ast-advanced-headers-users' ) ) ) {
					$index = array_search( '', $_POST[ $key ] );
					if ( false !== $index ) {
						unset( $_POST[ $key ][ $index ] );
					}
					$meta_value = array_map( 'esc_attr', $_POST[ $key ] );
					$meta_value = array_map( 'stripslashes', $_POST[ $key ] );
				} elseif ( in_array(
					$key,
					array(
						'ast-advanced-headers-location',
						'ast-advanced-headers-exclusion',
					)
				) ) {
						$meta_value = Astra_Target_Rules_Fields::get_format_rule_value( $_POST, $key );
				} else {
					// Sanitize values.
					$sanitize_filter = ( isset( $data['sanitize'] ) ) ? $data['sanitize'] : 'FILTER_DEFAULT';

					switch ( $sanitize_filter ) {

						case 'FILTER_SANITIZE_STRING':
							$meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_STRING );
							break;

						case 'FILTER_SANITIZE_URL':
							$meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_URL );
							break;

						case 'FILTER_SANITIZE_NUMBER_INT':
							$meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_NUMBER_INT );
							break;

						default:
							$meta_value = filter_input( INPUT_POST, $key, FILTER_DEFAULT );
							break;
					}
				}

				// Store values.
				if ( $meta_value ) {
					update_post_meta( $post_id, $key, $meta_value );
				} else {
					delete_post_meta( $post_id, $key );
				}
			}

			$logo_id = sanitize_key( $_POST['ast-advanced-headers-design']['logo-id'] );
			if ( '' != $logo_id ) {
				self::generate_logo_by_width( $logo_id );
			}
		}


User Contributed Notes

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