Inventory_Presser_Addon::add_license_key_box( $option_name,  $settings_section,  $sanitize_values_hook_name,  $license_key_key_name = 'license_key' )


Source Source

File: includes/class-addon.php

		public static function add_license_key_box( $option_name, $settings_section, $sanitize_values_hook_name, $license_key_key_name = 'license_key' )
		{
			add_action( 'admin_init', function() use ( $option_name, $settings_section, $license_key_key_name ) {

				//is $settings_section an existing section?
				global $wp_settings_sections;
				if( empty( $wp_settings_sections[INVP::option_page()][$settings_section] ) )
				{
					//no, abort
					return;
				}

				$option = get_option( $option_name );
				$current_value = empty( $option[$license_key_key_name] ) ? '' : $option[$license_key_key_name];

				add_settings_field(
					$license_key_key_name, // id
					__( 'License key', 'inventory-presser' ), // title
					function() use ( $option_name, $current_value, $license_key_key_name ) {
						?><p><input type="text" name="<?php echo $option_name; ?>[<?php echo $license_key_key_name; ?>]" class="regular-text code" id="<?php echo $option_name; ?>[<?php echo $license_key_key_name; ?>]" value="<?php echo $current_value; ?>" /></p>
						<p class="description"><?php printf( '%s <a href="https://inventorypresser.com/">https://inventorypresser.com/</a> %s', __( 'Obtain a key at', 'inventory-presser' ), __( 'to receive plugin updates.', 'inventory-presser' ) ); ?></p><?php
					}, // callback
					INVP::option_page(), // page
					$settings_section // section
				);
			}, 20 );

			$hook_parameters_count = 'license_key' == $license_key_key_name ? 3 : 4;
			add_filter( $sanitize_values_hook_name, array( __CLASS__, 'sanitize_and_activate_license_key' ), 10, $hook_parameters_count );
		}