| 1 |
<?php |
| 2 |
|
| 3 |
// Exit if accessed directly |
| 4 |
defined( 'ABSPATH' ) || exit; |
| 5 |
|
| 6 |
|
| 7 |
/** |
| 8 |
* Wpgetapi_License_Handler Class |
| 9 |
*/ |
| 10 |
class Wpgetapi_License_Handler { |
| 11 |
|
| 12 |
/** |
| 13 |
* Main constructor |
| 14 |
* @since 1.0.0 |
| 15 |
*/ |
| 16 |
public function __construct() { |
| 17 |
$this->hooks(); |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Hooks |
| 22 |
* @since 1.0.0 |
| 23 |
*/ |
| 24 |
public function hooks() { |
| 25 |
add_action( 'admin_menu', array( $this, 'license_menu' ) ); |
| 26 |
add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Adds the plugin license page to the admin menu. |
| 31 |
* |
| 32 |
* @return void |
| 33 |
*/ |
| 34 |
function license_menu() { |
| 35 |
if ( |
| 36 |
is_plugin_active('wpgetapi-woocommerce/wpgetapi-woocommerce.php' ) || |
| 37 |
is_plugin_active('wpgetapi-post-import/wpgetapi-post-import.php' ) || |
| 38 |
is_plugin_active('wpgetapi-oauth/wpgetapi-oauth.php' ) || |
| 39 |
is_plugin_active('wpgetapi-extras/wpgetapi-extras.php' ) |
| 40 |
) { |
| 41 |
add_submenu_page( |
| 42 |
'wpgetapi_setup', |
| 43 |
__( 'Plugin Licenses' ), |
| 44 |
__( 'Licenses' ), |
| 45 |
'manage_options', |
| 46 |
WPGETAPILICENSEPAGE, |
| 47 |
array( $this, 'license_page' ) |
| 48 |
); |
| 49 |
} |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
function license_page() { |
| 55 |
|
| 56 |
add_settings_section( |
| 57 |
'wpgetapi_licenses_section', |
| 58 |
__( '' ), |
| 59 |
array( $this, 'license_key_settings_section' ), |
| 60 |
WPGETAPILICENSEPAGE |
| 61 |
); |
| 62 |
|
| 63 |
?> |
| 64 |
<div class="wrap"> |
| 65 |
<h2><?php esc_html_e( 'WPGetAPI Extension Licenses' ); ?></h2> |
| 66 |
<form method="post" action="options.php"> |
| 67 |
|
| 68 |
<?php |
| 69 |
do_settings_sections( WPGETAPILICENSEPAGE ); |
| 70 |
settings_fields( 'wpgetapi_licenses_section' ); |
| 71 |
submit_button(); |
| 72 |
?> |
| 73 |
|
| 74 |
</form> |
| 75 |
<?php |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
/** |
| 80 |
* Adds content to the settings section. |
| 81 |
* |
| 82 |
* @return void |
| 83 |
*/ |
| 84 |
function license_key_settings_section() { |
| 85 |
|
| 86 |
?> |
| 87 |
<div class="intro"> |
| 88 |
<p>License fields will appear here if you have purchased any of our premium plugin extensions.<br>Enter your license keys to receive updates for your premium plugins.</p> |
| 89 |
<p><a class="button" target="_blank" href="https://wpgetapi.com">View premium extensions</a></p> |
| 90 |
</div> |
| 91 |
|
| 92 |
<?php |
| 93 |
|
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
/** |
| 98 |
* This is a means of catching errors from the activation method above and displaying it to the customer |
| 99 |
*/ |
| 100 |
function admin_notices() { |
| 101 |
if ( isset( $_GET['sl_activation'] ) && ! empty( $_GET['message'] ) ) { |
| 102 |
|
| 103 |
switch ( $_GET['sl_activation'] ) { |
| 104 |
|
| 105 |
case 'false': |
| 106 |
$message = urldecode( $_GET['message'] ); |
| 107 |
?> |
| 108 |
<div class="error"> |
| 109 |
<p><?php echo wp_kses_post( $message ); ?></p> |
| 110 |
</div> |
| 111 |
<?php |
| 112 |
break; |
| 113 |
|
| 114 |
case 'true': |
| 115 |
default: |
| 116 |
?> |
| 117 |
<div class="error"> |
| 118 |
<p>Activated successfully.</p> |
| 119 |
</div> |
| 120 |
<?php |
| 121 |
// Developers can put a custom success message here for when activation is successful if they way. |
| 122 |
break; |
| 123 |
|
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
} |
| 131 |
|
| 132 |
return new Wpgetapi_License_Handler(); |
| 133 |
|
| 134 |
|