| 1 |
<?php |
| 2 |
|
| 3 |
// don't load directly |
| 4 |
defined( 'ABSPATH' ) || exit; |
| 5 |
|
| 6 |
|
| 7 |
/*-----------------------------------------------------------------------------------*/ |
| 8 |
/* *. Borderless License |
| 9 |
/*-----------------------------------------------------------------------------------*/ |
| 10 |
|
| 11 |
class BorderlessLicense { |
| 12 |
private $borderless_license_options; |
| 13 |
|
| 14 |
public function __construct() { |
| 15 |
add_action( 'admin_menu', array( $this, 'borderless_license_add_plugin_page' ) ); |
| 16 |
add_action( 'admin_init', array( $this, 'borderless_license_page_init' ) ); |
| 17 |
} |
| 18 |
|
| 19 |
public function borderless_license_add_plugin_page() { |
| 20 |
add_submenu_page( |
| 21 |
'borderless.php', // parent slug |
| 22 |
esc_html__( 'License', 'borderless' ), // page title |
| 23 |
esc_html__( 'License', 'borderless' ), // menu title |
| 24 |
'manage_options', // capability |
| 25 |
'borderless-license.php', // slug |
| 26 |
array( $this, 'borderless_license_create_admin_page' ) // function |
| 27 |
); |
| 28 |
} |
| 29 |
|
| 30 |
public function borderless_license_create_admin_page() { |
| 31 |
$this->borderless_license_options = get_option( 'borderless_license_option_name' ); ?> |
| 32 |
|
| 33 |
<div class="wrap"> |
| 34 |
<h2><?php echo esc_html( 'License', 'borderless' ) ?></h2> |
| 35 |
<?php settings_errors(); ?> |
| 36 |
|
| 37 |
<form method="post" action="options.php"> |
| 38 |
<?php |
| 39 |
settings_fields( 'borderless_license_option_group' ); |
| 40 |
do_settings_sections( 'borderless-license-admin' ); |
| 41 |
submit_button(); |
| 42 |
?> |
| 43 |
</form> |
| 44 |
</div> |
| 45 |
<?php } |
| 46 |
|
| 47 |
public function borderless_license_page_init() { |
| 48 |
register_setting( |
| 49 |
'borderless_license_option_group', // option_group |
| 50 |
'borderless_license_option_name', // option_name |
| 51 |
array( $this, 'borderless_license_sanitize' ) // sanitize_callback |
| 52 |
); |
| 53 |
|
| 54 |
add_settings_section( |
| 55 |
'borderless_license_setting_section', // id |
| 56 |
'', // title |
| 57 |
array( $this, 'borderless_license_section_info' ), // callback |
| 58 |
'borderless-license-admin' // page |
| 59 |
); |
| 60 |
|
| 61 |
add_settings_field( |
| 62 |
'borderless_license_key', // id |
| 63 |
'Borderless License Key', // title |
| 64 |
array( $this, 'borderless_license_key_callback' ), // callback |
| 65 |
'borderless-license-admin', // page |
| 66 |
'borderless_license_setting_section' // section |
| 67 |
); |
| 68 |
} |
| 69 |
|
| 70 |
public function borderless_license_sanitize($input) { |
| 71 |
$sanitary_values = array(); |
| 72 |
if ( isset( $input['borderless_license_key'] ) ) { |
| 73 |
$sanitary_values['borderless_license_key'] = sanitize_text_field( htmlspecialchars( $input['borderless_license_key'] ) ); |
| 74 |
} |
| 75 |
|
| 76 |
return $sanitary_values; |
| 77 |
} |
| 78 |
|
| 79 |
public function borderless_license_section_info() { |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
public function borderless_license_key_callback() { |
| 84 |
|
| 85 |
$borderless_license = isset( $this->borderless_license_options['borderless_license_key'] ) ? $this->borderless_license_options['borderless_license_key'] : ''; |
| 86 |
|
| 87 |
printf( |
| 88 |
'<input class="regular-text" type="text" name="borderless_license_option_name[borderless_license_key]" id="borderless_license_key" value="%s">', |
| 89 |
isset( $borderless_license ) ? esc_attr( $borderless_license ) : '' |
| 90 |
); |
| 91 |
|
| 92 |
if (strlen($borderless_license) == 40 && preg_match('/\d/', $borderless_license) && preg_match('/[a-zA-Z]/', $borderless_license)) { |
| 93 |
echo "<p>".esc_html( 'Activated', 'borderless' )."</p>"; |
| 94 |
} else { |
| 95 |
echo "<p>".esc_html( 'Deactivated', 'borderless' )."</p>"; |
| 96 |
} |
| 97 |
|
| 98 |
} |
| 99 |
|
| 100 |
} |
| 101 |
if ( is_admin() ) |
| 102 |
$license = new BorderlessLicense(); |
| 103 |
|