PluginProbe
Property Hive / 2.2.3
Property Hive v2.2.3
2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 1.4.62 All 260 releases
propertyhive / includes / admin / settings / class-ph-settings-licenses.php

class-ph-settings-licenses.php in Property Hive 2.2.3, at includes/admin/settings/class-ph-settings-licenses.php

281 lines 9.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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', '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 settings array.
36 *
37 * @return array
38 */
39 public function get_settings() {
40
41 $license_type = PH()->license->get_license_type();
42 if ( $license_type == '' )
43 {
44 $license_type = 'pro';
45 }
46
47 // get old license information
48 $license = PH()->license->get_current_license();
49
50 $output = '';
51 $input_border_color = '';
52 $renew_link = '<a href="https://wp-property-hive.com/license-key/" target="_blank">' . __( 'Renew License', 'propertyhive' ) . '</a>';
53 $valid_license = false;
54
55 if ( is_array($license) && empty($license) && get_option( 'propertyhive_license_key', '' ) != '' )
56 {
57 $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>';
58 $input_border_color = '#900';
59
60 if ( get_option( 'propertyhive_license_key_error', '' ) != '' )
61 {
62 $output .= ' <span style="color:#900">' . esc_html(get_option( 'propertyhive_license_key_error', '' )) . '</span>';
63 }
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']) + 86400) <= 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 else
81 {
82 // Valid
83 $output = '<span style="color:#090">' . __( 'License valid', 'propertyhive') . '.</span>';
84 $input_border_color = '#090';
85 $valid_license = true;
86 }
87 }
88 }
89
90 // get new license information
91 $valid_pro_license = false;
92 $pro_input_border_color = '';
93 $pro_output = '';
94 $license_key_to_display = '';
95 if (get_option('propertyhive_pro_license_key', '') != '')
96 {
97 $length = strlen(get_option('propertyhive_pro_license_key', ''));
98 $license_key_to_display = get_option('propertyhive_pro_license_key', '');
99 if ( $length >= 6 )
100 {
101 $license_key_to_display = get_option('propertyhive_pro_license_key', '')[0] .
102 get_option('propertyhive_pro_license_key', '')[1] .
103 get_option('propertyhive_pro_license_key', '')[2] .
104 str_repeat('*', $length - 4) .
105 get_option('propertyhive_pro_license_key', '')[$length-3] .
106 get_option('propertyhive_pro_license_key', '')[$length-2] .
107 get_option('propertyhive_pro_license_key', '')[$length-1];
108 }
109
110 if ( PH()->license->is_valid_pro_license_key(true) )
111 {
112 $valid_pro_license = true;
113 // to be used for displaying subscription level in future
114 //$product_id_and_package = PH()->license->get_pro_license_product_id_and_package();
115 $pro_input_border_color = '#090';
116 }
117 else
118 {
119 $pro_license = PH()->license->get_current_pro_license();
120 $pro_input_border_color = '#900';
121 $pro_output = ( isset($pro_license['error']) ? $pro_license['error'] : '' );
122 }
123 }
124
125
126 $settings = array(
127
128 array( 'title' => __( 'License Key', 'propertyhive' ), 'type' => 'title', 'id' => 'license_options' ),
129
130 );
131
132 $settings[] = array(
133 'title' => __( 'License Type', 'propertyhive' ),
134 'id' => 'propertyhive_license_type',
135 'type' => 'radio',
136 'default' => $license_type,
137 'options' => array(
138 'pro' => 'Pro',
139 'old' => 'Old-Style (license keys purchased before October 2023)'
140 )
141 );
142
143 $settings[] = array(
144 'type' => 'html',
145 'id' => 'pro_license_key_info',
146 'html' => __( '<p>With a Pro license subscription you\'ll unlock a wide array of Property Hive functionality. We offer multiple packages to suit your needs. Your Pro subscription details and license key can be found within the \'<a href="https://wp-property-hive.com/my-account/" target="_blank">My Account</a>\' section of our website.</p>
147 ' . ( (!$valid_pro_license) ?
148 '<br><p><a href="https://wp-property-hive.com/pricing/?src=plugin-license-settings" class="button button-primary" target="_blank">Get PRO</a></p>' :
149 '<br><p>
150 <a href="' . admin_url('admin.php?page=ph-settings&tab=features') . '" class="button button-primary">Activate Features</a>
151 <a href="https://wp-property-hive.com/my-account/subscriptions/?src=wordpress-license-tab" class="button button" target="_blank">Manage Subscription</a>
152 </p>'
153 ), 'propertyhive' ) . '
154 <input type="hidden" name="pro_license_key_action" value="' . ( $valid_pro_license ? 'deactivate' : 'activate' ) . '">',
155 );
156
157 if ( $valid_pro_license )
158 {
159 $settings[] = array(
160 'type' => 'html',
161 'id' => 'pro_license_key_display',
162 'title' => __( 'License Key', 'propertyhive' ),
163 'html' => '<input type="text" disabled="disabled" value="' . $license_key_to_display . '" style="min-width:350px; border:1px solid ' . $pro_input_border_color . '"> ' . $pro_output
164 );
165
166 $settings[] = array(
167 'title' => __( 'License Key', 'propertyhive' ),
168 'id' => 'propertyhive_pro_license_key',
169 'type' => 'hidden'
170 );
171 }
172 else
173 {
174 $settings[] = array(
175 'title' => __( 'License Key', 'propertyhive' ),
176 'id' => 'propertyhive_pro_license_key',
177 'type' => 'text',
178 'css' => 'min-width:350px; border:1px solid ' . $pro_input_border_color,
179 'desc' => $pro_output
180 );
181 }
182
183 $legacy_license_message = '';
184
185 if ( 'old' === $license_type )
186 {
187 $legacy_license_message = '<p>' . sprintf(
188 /* translators: %s: URL to the support page */
189 __( 'To switch your existing license key over to the new pricing model, please <a href="%s">get in touch</a>.', 'propertyhive' ),
190 esc_url( 'https://wp-property-hive.com/support' )
191 ) . '</p>';
192 }
193
194 $settings[] = array(
195 'type' => 'html',
196 'id' => 'license_key_info',
197 'html' => sprintf(
198 /* translators: 1: URL to the pricing page, 2: optional message shown to legacy license holders */
199 __(
200 '<p>If you purchased a license key prior to 16th October 2023, you can enter it here to benefit from updates to any existing add-ons you\'ve purchased.</p>
201 <p>We\'ve since moved to a new and improved <a href="%1$s" target="_blank">pro pricing model</a> that is more cost effective for you and gives access to more features.</p>
202 %2$s
203 <br><p><a href="%1$s" class="button button-primary" target="_blank">Get PRO</a></p>',
204 'propertyhive'
205 ),
206 esc_url( 'https://wp-property-hive.com/pricing/?src=plugin-license-settings' ),
207 $legacy_license_message
208 ),
209 );
210
211 $settings[] = array(
212 'title' => __( 'License Key', 'propertyhive' ),
213 'id' => 'propertyhive_license_key',
214 'type' => 'text',
215 'css' => 'min-width:350px; border:1px solid ' . $input_border_color,
216 'desc' => $output,
217 );
218
219 $settings[] = array( 'type' => 'sectionend', 'id' => 'license_options' );
220
221 return apply_filters( 'propertyhive_get_settings_' . $this->id, $settings );
222 }
223
224 /**
225 * Output the settings.
226 */
227 public function output() {
228 global $current_section, $hide_save_button;
229
230 $settings = $this->get_settings();
231
232 PH_Admin_Settings::output_fields( $settings );
233 }
234
235 /**
236 * Save settings.
237 */
238 public function save() {
239
240 $settings = $this->get_settings();
241
242 PH_Admin_Settings::save_fields( $settings );
243
244 update_option( 'missing_invalid_expired_license_key_notice_dismissed', '' );
245
246 if ( $_POST['propertyhive_license_type'] == 'pro' && isset($_POST['propertyhive_pro_license_key']) && !empty(ph_clean($_POST['propertyhive_pro_license_key'])) && $_POST['pro_license_key_action'] == 'activate' )
247 {
248 $return = PH()->license->activate_pro_license_key();
249 if ( $return['success'] === false )
250 {
251 PH_Admin_Settings::add_error($return['error']);
252 }
253 else
254 {
255 PH_Admin_Settings::add_message('License key activated successfully');
256 }
257 }
258
259 if ( $_POST['propertyhive_license_type'] == 'pro' && isset($_POST['propertyhive_pro_license_key']) && !empty(ph_clean($_POST['propertyhive_pro_license_key'])) && $_POST['pro_license_key_action'] == 'deactivate' )
260 {
261 $return = PH()->license->deactivate_pro_license_key();
262 if ( $return['success'] === false )
263 {
264 PH_Admin_Settings::add_error($return['error']);
265 }
266 else
267 {
268 PH_Admin_Settings::add_message('License key deactivated successfully');
269 }
270 }
271
272 if ( $_POST['propertyhive_license_type'] == 'old' )
273 {
274 PH()->license->ph_check_licenses(true);
275 }
276 }
277 }
278
279 endif;
280
281 return new PH_Settings_Licenses();