| 1 |
<?php |
| 2 |
/** |
| 3 |
* PropertyHive License Settings |
| 4 |
* |
| 5 |
* @author PropertyHive |
| 6 |
* @category Admin |
| 7 |
* @package PropertyHive/Admin |
| 8 |
* @version 1.0.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; // Exit if accessed directly |
| 13 |
} |
| 14 |
|
| 15 |
if ( ! class_exists( 'PH_Settings_Licenses' ) ) : |
| 16 |
|
| 17 |
/** |
| 18 |
* PH_Settings_Licenses. |
| 19 |
*/ |
| 20 |
class PH_Settings_Licenses extends PH_Settings_Page { |
| 21 |
|
| 22 |
/** |
| 23 |
* Constructor. |
| 24 |
*/ |
| 25 |
public function __construct() { |
| 26 |
$this->id = 'licensekey'; |
| 27 |
$this->label = __( 'License Key', 'propertyhive' ); |
| 28 |
|
| 29 |
add_filter( 'propertyhive_settings_tabs_array', array( $this, 'add_settings_page' ), 20 ); |
| 30 |
add_action( 'propertyhive_settings_' . $this->id, array( $this, 'output' ) ); |
| 31 |
add_action( 'propertyhive_settings_save_' . $this->id, array( $this, 'save' ) ); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Get sections. |
| 36 |
* |
| 37 |
* @return array |
| 38 |
*/ |
| 39 |
public function get_sections() { |
| 40 |
$sections = array( |
| 41 |
'' => __( 'License Key', 'propertyhive' ), |
| 42 |
); |
| 43 |
return apply_filters( 'propertyhive_get_sections_' . $this->id, $sections ); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Get settings array. |
| 48 |
* |
| 49 |
* @return array |
| 50 |
*/ |
| 51 |
public function get_settings() { |
| 52 |
|
| 53 |
$license = PH()->license->get_current_license(); |
| 54 |
|
| 55 |
$output = ''; |
| 56 |
$input_border_color = ''; |
| 57 |
$renew_link = '<a href="https://wp-property-hive.com/product/12-month-license-key/" target="_blank">' . __( 'Renew License', 'propertyhive' ) . '</a>'; |
| 58 |
$valid_license = false; |
| 59 |
|
| 60 |
if ( is_array($license) && empty($license) && get_option( 'propertyhive_license_key', '' ) != '' ) |
| 61 |
{ |
| 62 |
$output = '<span style="color:#900">' . __( 'Invalid license key entered. If you\'re seeing this message and the license key is correct please contact Property Hive support.', 'propertyhive' ) . '</span>'; |
| 63 |
$input_border_color = '#900'; |
| 64 |
} |
| 65 |
elseif ( isset($license['active']) && $license['active'] != '1' ) |
| 66 |
{ |
| 67 |
$output = '<span style="color:#900">' . __( 'License inactive.', 'propertyhive' ) . '</span>'; |
| 68 |
$input_border_color = '#900'; |
| 69 |
} |
| 70 |
else |
| 71 |
{ |
| 72 |
if ( isset($license['expires_at']) && $license['expires_at'] != '' ) |
| 73 |
{ |
| 74 |
if ( strtotime($license['expires_at']) <= time() ) |
| 75 |
{ |
| 76 |
// Expired |
| 77 |
$output = '<span style="color:#900">' . __( 'License expired on ' . date("jS F Y", strtotime($license['expires_at'])), 'propertyhive' ) . '. ' . $renew_link . '</span>'; |
| 78 |
$input_border_color = '#900'; |
| 79 |
} |
| 80 |
elseif ( |
| 81 |
strtotime($license['expires_at']) > time() && |
| 82 |
strtotime($license['expires_at']) < (time() + 30 * 24 * 60 * 60) |
| 83 |
) |
| 84 |
{ |
| 85 |
// Expires in less than 30 days |
| 86 |
$output = '<span style="color:#F90">' . __( 'License expires on ' . date("jS F Y", strtotime($license['expires_at'])), 'propertyhive' ) . '. ' . $renew_link . '</span>'; |
| 87 |
$input_border_color = '#F90'; |
| 88 |
} |
| 89 |
elseif (strtotime($license['expires_at']) > time()) |
| 90 |
{ |
| 91 |
// Valid |
| 92 |
$output = '<span style="color:#090">' . __( 'License valid. Expires on ' . date("jS F Y", strtotime($license['expires_at'])), 'propertyhive' ) . '.</span>'; |
| 93 |
$input_border_color = '#090'; |
| 94 |
$valid_license = true; |
| 95 |
} |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
$settings = apply_filters( 'propertyhive_licenses_settings', array( |
| 100 |
|
| 101 |
array( 'title' => __( 'License Key', 'propertyhive' ), 'type' => 'title', 'id' => 'license_options' ), |
| 102 |
|
| 103 |
array( |
| 104 |
'type' => 'html', |
| 105 |
'html' => __( '<p>By having a license key you will benefit from priority one-to-one email support, setup assistance, troubleshooting, and updates to purchased add ons containing new functionality and fixes.</p> |
| 106 |
|
| 107 |
<p>Licenses are valid for 12 months from the date of purchase and exist on a per-site-basis. Should a license key not exist, your website will still function as it does now. However support will be limited and potentially slower than usual and you won’t receive updates to any purchased add ons.</p> |
| 108 |
|
| 109 |
' . ( (!$valid_license) ? '<br><p><a href="https://wp-property-hive.com/product/12-month-license-key/" class="button button-primary" target="_blank">Purchase License Key</a></p>' : '' ), 'propertyhive' ), |
| 110 |
), |
| 111 |
|
| 112 |
array( |
| 113 |
'title' => __( 'License Key', 'propertyhive' ), |
| 114 |
'id' => 'propertyhive_license_key', |
| 115 |
'type' => 'text', |
| 116 |
'css' => 'min-width:300px; border:1px solid ' . $input_border_color, |
| 117 |
'desc' => $output, |
| 118 |
), |
| 119 |
|
| 120 |
array( 'type' => 'sectionend', 'id' => 'license_options' ), |
| 121 |
|
| 122 |
) ); |
| 123 |
|
| 124 |
return apply_filters( 'propertyhive_get_settings_' . $this->id, $settings ); |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* Output the settings. |
| 129 |
*/ |
| 130 |
public function output() { |
| 131 |
global $current_section; |
| 132 |
|
| 133 |
$settings = $this->get_settings(); |
| 134 |
PH_Admin_Settings::output_fields( $settings ); |
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* Save settings. |
| 139 |
*/ |
| 140 |
public function save() { |
| 141 |
PH_Admin_Settings::save_fields( $this->get_settings() ); |
| 142 |
|
| 143 |
update_option( 'missing_invalid_expired_license_key_notice_dismissed', '' ); |
| 144 |
|
| 145 |
PH()->license->ph_check_licenses(true); |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
endif; |
| 150 |
|
| 151 |
return new PH_Settings_Licenses(); |