PluginProbe
Property Hive / 2.3.1
Property Hive v2.3.1
2.3.1 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 All 261 releases
propertyhive / includes / admin / settings / class-ph-settings-licenses.php

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

298 lines 10.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // phpcs:set WordPress.Security.ValidatedSanitizedInput customSanitizingFunctions[] ph_clean
3 // ph_clean() recursively sanitizes text; presence, shape and unslashing checks remain separate.
4
5 /**
6 * PropertyHive License Settings
7 *
8 * @author PropertyHive
9 * @category Admin
10 * @package PropertyHive/Admin
11 * @version 1.0.0
12 */
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly
16 }
17
18 if ( ! class_exists( 'PH_Settings_Licenses' ) ) :
19
20 /**
21 * PH_Settings_Licenses.
22 */
23 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- Legacy public global class PH_Settings_Licenses; preserving the existing PH_* class name is required for plugin and extension compatibility.
24 class PH_Settings_Licenses extends PH_Settings_Page {
25
26 /**
27 * Constructor.
28 */
29 public function __construct() {
30 $this->id = 'licensekey';
31 $this->label = __( 'License', 'propertyhive' );
32
33 add_filter( 'propertyhive_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
34 add_action( 'propertyhive_settings_' . $this->id, array( $this, 'output' ) );
35 add_action( 'propertyhive_settings_save_' . $this->id, array( $this, 'save' ) );
36 }
37
38 /**
39 * Get settings array.
40 *
41 * @return array
42 */
43 public function get_settings() {
44
45 $license_type = PH()->license->get_license_type();
46 if ( $license_type == '' )
47 {
48 $license_type = 'pro';
49 }
50
51 // get old license information
52 $license = PH()->license->get_current_license();
53
54 $output = '';
55 $input_border_color = '';
56 $renew_link = '<a href="https://wp-property-hive.com/license-key/" target="_blank">' . __( 'Renew License', 'propertyhive' ) . '</a>';
57 $valid_license = false;
58
59 if ( is_array($license) && empty($license) && get_option( 'propertyhive_license_key', '' ) != '' )
60 {
61 $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>';
62 $input_border_color = '#900';
63
64 if ( get_option( 'propertyhive_license_key_error', '' ) != '' )
65 {
66 $output .= ' <span style="color:#900">' . esc_html(get_option( 'propertyhive_license_key_error', '' )) . '</span>';
67 }
68 }
69 elseif ( isset($license['active']) && $license['active'] != '1' )
70 {
71 $output = '<span style="color:#900">' . __( 'License inactive.', 'propertyhive' ) . '</span>';
72 $input_border_color = '#900';
73 }
74 else
75 {
76 if ( isset($license['expires_at']) && $license['expires_at'] != '' )
77 {
78 if ( (strtotime($license['expires_at']) + 86400) <= time() )
79 {
80 /* translators: %s: License expiry date. */
81 $output = '<span style="color:#900">' . sprintf( __( 'License expired on %s', 'propertyhive' ), gmdate( 'jS F Y', strtotime( $license['expires_at'] ) ) ) . '. ' . $renew_link . '</span>';
82 $input_border_color = '#900';
83 }
84 else
85 {
86 // Valid
87 $output = '<span style="color:#090">' . __( 'License valid', 'propertyhive') . '.</span>';
88 $input_border_color = '#090';
89 $valid_license = true;
90 }
91 }
92 }
93
94 $legacy_error = get_option( 'propertyhive_license_key_error', '' );
95 if ( 'old' === $license_type && '' !== $legacy_error ) {
96 $output = '<span style="color:#900">' . esc_html( $legacy_error ) . '</span>';
97 $input_border_color = '#900';
98 $valid_license = false;
99 }
100
101 // get new license information
102 $valid_pro_license = false;
103 $pro_input_border_color = '';
104 $pro_output = '';
105 $license_key_to_display = '';
106 if (get_option('propertyhive_pro_license_key', '') != '')
107 {
108 $length = strlen(get_option('propertyhive_pro_license_key', ''));
109 $license_key_to_display = get_option('propertyhive_pro_license_key', '');
110 if ( $length >= 6 )
111 {
112 $license_key_to_display = get_option('propertyhive_pro_license_key', '')[0] .
113 get_option('propertyhive_pro_license_key', '')[1] .
114 get_option('propertyhive_pro_license_key', '')[2] .
115 str_repeat('*', $length - 4) .
116 get_option('propertyhive_pro_license_key', '')[$length-3] .
117 get_option('propertyhive_pro_license_key', '')[$length-2] .
118 get_option('propertyhive_pro_license_key', '')[$length-1];
119 }
120
121 if ( PH()->license->is_valid_pro_license_key(true) )
122 {
123 $valid_pro_license = true;
124 // to be used for displaying subscription level in future
125 //$product_id_and_package = PH()->license->get_pro_license_product_id_and_package();
126 $pro_input_border_color = '#090';
127 }
128 else
129 {
130 $pro_license = PH()->license->get_current_pro_license();
131 $pro_input_border_color = '#900';
132 $pro_output = ( isset($pro_license['error']) ? $pro_license['error'] : '' );
133 }
134 }
135
136
137 $settings = array(
138
139 array( 'title' => __( 'License Key', 'propertyhive' ), 'type' => 'title', 'id' => 'license_options' ),
140
141 );
142
143 $settings[] = array(
144 'title' => __( 'License Type', 'propertyhive' ),
145 'id' => 'propertyhive_license_type',
146 'type' => 'radio',
147 'default' => $license_type,
148 'options' => array(
149 'pro' => 'Pro',
150 'old' => 'Old-Style (license keys purchased before October 2023)'
151 )
152 );
153
154 $settings[] = array(
155 'type' => 'html',
156 'id' => 'pro_license_key_info',
157 'html' => '<p>' . wp_kses_post( __( 'With a Pro license subscription you 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 in the <a href="https://wp-property-hive.com/my-account/" target="_blank">My Account</a> section of our website.', 'propertyhive' ) ) . '</p><br><p>' .
158 ( ! $valid_pro_license ?
159 '<a href="https://wp-property-hive.com/pricing/?src=plugin-license-settings" class="button button-primary" target="_blank">' . esc_html__( 'Get PRO', 'propertyhive' ) . '</a>' :
160 '<a href="' . esc_url( admin_url( 'admin.php?page=ph-settings&tab=features' ) ) . '" class="button button-primary">' . esc_html__( 'Activate Features', 'propertyhive' ) . '</a> <a href="https://wp-property-hive.com/my-account/subscriptions/?src=wordpress-license-tab" class="button button" target="_blank">' . esc_html__( 'Manage Subscription', 'propertyhive' ) . '</a>'
161 ) . '</p><input type="hidden" name="pro_license_key_action" value="' . ( $valid_pro_license ? 'deactivate' : 'activate' ) . '">',
162 );
163
164 if ( $valid_pro_license )
165 {
166 $settings[] = array(
167 'type' => 'html',
168 'id' => 'pro_license_key_display',
169 'title' => __( 'License Key', 'propertyhive' ),
170 'html' => '<input type="text" disabled="disabled" value="' . esc_attr( $license_key_to_display ) . '" style="min-width:350px; border:1px solid ' . esc_attr( $pro_input_border_color ) . '"> ' . esc_html( $pro_output )
171 );
172
173 $settings[] = array(
174 'title' => __( 'License Key', 'propertyhive' ),
175 'id' => 'propertyhive_pro_license_key',
176 'type' => 'hidden'
177 );
178 }
179 else
180 {
181 $settings[] = array(
182 'title' => __( 'License Key', 'propertyhive' ),
183 'id' => 'propertyhive_pro_license_key',
184 'type' => 'text',
185 'css' => 'min-width:350px; border:1px solid ' . $pro_input_border_color,
186 'desc' => $pro_output
187 );
188 }
189
190 $legacy_license_message = '';
191
192 if ( 'old' === $license_type )
193 {
194 $legacy_license_message = '<p>' . sprintf(
195 /* translators: %s: URL to the support page */
196 __( 'To switch your existing license key over to the new pricing model, please <a href="%s">get in touch</a>.', 'propertyhive' ),
197 esc_url( 'https://wp-property-hive.com/support' )
198 ) . '</p>';
199 }
200
201 $settings[] = array(
202 'type' => 'html',
203 'id' => 'license_key_info',
204 'html' => sprintf(
205 /* translators: 1: URL to the pricing page, 2: optional message shown to legacy license holders */
206 __(
207 '<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>
208 <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>
209 %2$s
210 <br><p><a href="%1$s" class="button button-primary" target="_blank">Get PRO</a></p>',
211 'propertyhive'
212 ),
213 esc_url( 'https://wp-property-hive.com/pricing/?src=plugin-license-settings' ),
214 $legacy_license_message
215 ),
216 );
217
218 $settings[] = array(
219 'title' => __( 'License Key', 'propertyhive' ),
220 'id' => 'propertyhive_license_key',
221 'type' => 'text',
222 'css' => 'min-width:350px; border:1px solid ' . $input_border_color,
223 'desc' => $output,
224 );
225
226 $settings[] = array( 'type' => 'sectionend', 'id' => 'license_options' );
227
228 return apply_filters( 'propertyhive_get_settings_' . $this->id, $settings );
229 }
230
231 /**
232 * Output the settings.
233 */
234 public function output() {
235 global $current_section, $hide_save_button;
236
237 $settings = $this->get_settings();
238
239 PH_Admin_Settings::output_fields( $settings );
240 }
241
242 /**
243 * Save settings.
244 */
245 public function save() {
246 if ( ! current_user_can( 'manage_options' ) || ! isset( $_REQUEST['_wpnonce'] ) || ! is_string( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'propertyhive-settings' ) ) {
247 return;
248 }
249
250
251 $license_type = isset( $_POST['propertyhive_license_type'] ) && is_string( $_POST['propertyhive_license_type'] ) ? sanitize_text_field( wp_unslash( $_POST['propertyhive_license_type'] ) ) : '';
252 $license_key = isset( $_POST['propertyhive_pro_license_key'] ) && is_string( $_POST['propertyhive_pro_license_key'] ) ? ph_clean( wp_unslash( $_POST['propertyhive_pro_license_key'] ) ) : '';
253 $license_action = isset( $_POST['pro_license_key_action'] ) && is_string( $_POST['pro_license_key_action'] ) ? sanitize_text_field( wp_unslash( $_POST['pro_license_key_action'] ) ) : '';
254
255
256 $settings = $this->get_settings();
257
258 PH_Admin_Settings::save_fields( $settings );
259
260 update_option( 'missing_invalid_expired_license_key_notice_dismissed', '' );
261
262 if ( 'pro' === $license_type && ! empty( $license_key ) && 'activate' === $license_action )
263 {
264 $return = PH()->license->activate_pro_license_key();
265 if ( $return['success'] === false )
266 {
267 PH_Admin_Settings::add_error($return['error']);
268 }
269 else
270 {
271 PH_Admin_Settings::add_message('License key activated successfully');
272 }
273 }
274
275 if ( 'pro' === $license_type && ! empty( $license_key ) && 'deactivate' === $license_action )
276 {
277 $return = PH()->license->deactivate_pro_license_key();
278 if ( $return['success'] === false )
279 {
280 PH_Admin_Settings::add_error($return['error']);
281 }
282 else
283 {
284 PH_Admin_Settings::add_message('License key deactivated successfully');
285 }
286 }
287
288 if ( 'old' === $license_type )
289 {
290 PH()->license->ph_check_licenses(true);
291 }
292 }
293 }
294
295 endif;
296
297 return new PH_Settings_Licenses();
298