Inventory_Presser_Addon::add_license_key_box( mixed $option_name, mixed $settings_section, mixed $sanitize_values_hook_name, mixed $license_key_key_name = 'license_key' )
add_license_key_box
On This Page
Parameters Parameters
- $option_name
-
(mixed) (Required)
- $settings_section
-
(mixed) (Required)
- $sanitize_values_hook_name
-
(mixed) (Required)
- $license_key_key_name
-
(mixed) (Optional)
Default value: 'license_key'
Return Return
(void)
Source Source
File: includes/addon/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 esc_attr( $option_name ); ?>[<?php echo esc_attr( $license_key_key_name ); ?>]" class="regular-text code" id="<?php echo esc_attr( $option_name ); ?>[<?php echo esc_attr( $license_key_key_name ); ?>]" value="<?php echo esc_attr( $current_value ); ?>" /></p> <p class="description"><?php printf( '%s <a href="https://inventorypresser.com/">https://inventorypresser.com/</a> %s', esc_html__( 'Obtain a key at', 'inventory-presser' ), esc_html__( '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 ); }
Expand full source codeCollapse full source codeView on Github