AnsPress_Admin::process_option_form()

Description #

Process AnsPress option form.

Source #

File: admin/anspress-admin.php

	public static function process_option_form() {
		$redirect = admin_url( 'admin.php?page=anspress_options' );

		if ( ap_isset_post_value( '__nonce' ) && ap_verify_nonce( 'nonce_option_form' ) && current_user_can( 'manage_options' ) ) {

			$settings = get_option( 'anspress_opt', array() );
			$groups   = ap_get_option_groups();
			$active   = ap_sanitize_unslash( 'fields_group', 'request' );
			$ap_active_section = ap_isset_post_value( 'ap_active_section', '' );

			// If active is set.
			if ( '' !== $active && '' !== $ap_active_section ) {

				$default_opt = ap_default_options();

				$i = 0;
				// Check $_POST value against fields.
				foreach ( (array) $groups[ $active ]['sections'] as $section_slug => $section ) {
					if ( $section_slug === $ap_active_section ) {
						foreach ( (array) $section['fields'] as $k => $f ) {

							if ( ! isset( $f['name'] ) ) {
								continue;
							}

							if ( isset( $f['type'] ) && 'textarea' === $f['type'] ) {
								$value = esc_textarea( wp_unslash( ap_isset_post_value( $f['name'], '' ) ) );
							} else {
								$value = ap_sanitize_unslash( $f['name'], 'request' );
							}

							// If reset then get value from default option.
							if ( ap_sanitize_unslash( 'reset', 'p' ) ) {
								$value = $default_opt[ $f['name'] ];
							}

							// Set checkbox field value as 0 when empty.
							if ( isset( $f['type'] ) && 'checkbox' === $f['type'] && empty( $value ) ) {
								$value = '0';
							}

							if ( isset( $value ) ) {
								$settings[ $f['name'] ] = $value;
							} else {
								unset( $settings[ $f['name'] ] );
							}
						}
					}
					$i++;
				}

				update_option( 'anspress_opt', $settings );
				wp_cache_delete( 'anspress_opt', 'ap' );
			}

			flush_rewrite_rules();
			$redirect = admin_url( 'admin.php?page=anspress_options&updated=true&option_page='. $active );
		}

		wp_safe_redirect( $redirect );
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment