# propertyhive/2.3.1/includes/admin/settings/class-ph-settings-licenses.php

Property Hive, version 2.3.1. 298 lines.

- Page: https://pluginprobe.com/plugins/propertyhive/2.3.1/code/includes/admin/settings/class-ph-settings-licenses.php
- Raw: https://pluginprobe.com/plugins/propertyhive/2.3.1/raw/includes/admin/settings/class-ph-settings-licenses.php
- Modified: 2026-09-16T09:29:48+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/propertyhive/2.3.1/code/includes/admin/settings/class-ph-settings-licenses.php#L10-L20`.

```php
<?php
// phpcs:set WordPress.Security.ValidatedSanitizedInput customSanitizingFunctions[] ph_clean
// ph_clean() recursively sanitizes text; presence, shape and unslashing checks remain separate.

/**
 * PropertyHive License Settings
 *
 * @author      PropertyHive
 * @category    Admin
 * @package     PropertyHive/Admin
 * @version     1.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

if ( ! class_exists( 'PH_Settings_Licenses' ) ) :

/**
 * PH_Settings_Licenses.
 */
// 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.
class PH_Settings_Licenses extends PH_Settings_Page {

	/**
	 * Constructor.
	 */
	public function __construct() {
		$this->id    = 'licensekey';
		$this->label = __( 'License', 'propertyhive' );

		add_filter( 'propertyhive_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
		add_action( 'propertyhive_settings_' . $this->id, array( $this, 'output' ) );
		add_action( 'propertyhive_settings_save_' . $this->id, array( $this, 'save' ) );
	}

	/**
	 * Get settings array.
	 *
	 * @return array
	 */
	public function get_settings() {

		$license_type = PH()->license->get_license_type();
		if ( $license_type == '' )
		{
			$license_type = 'pro';
		}

		// get old license information
		$license = PH()->license->get_current_license();

		$output = '';
		$input_border_color = '';
		$renew_link = '<a href="https://wp-property-hive.com/license-key/" target="_blank">' . __( 'Renew License', 'propertyhive' ) . '</a>';
		$valid_license = false;

		if ( is_array($license) && empty($license) && get_option( 'propertyhive_license_key', '' ) != '' )
		{
			$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>';
			$input_border_color = '#900';

			if ( get_option( 'propertyhive_license_key_error', '' ) != '' )
			{
				$output .= ' <span style="color:#900">' . esc_html(get_option( 'propertyhive_license_key_error', '' )) . '</span>';
			}
		}
		elseif ( isset($license['active']) && $license['active'] != '1' )
		{
			$output = '<span style="color:#900">' . __( 'License inactive.', 'propertyhive' ) . '</span>';
			$input_border_color = '#900';
		}
		else
		{
			if ( isset($license['expires_at']) && $license['expires_at'] != '' )
			{
				if ( (strtotime($license['expires_at']) + 86400) <= time() )
				{
					/* translators: %s: License expiry date. */
					$output = '<span style="color:#900">' . sprintf( __( 'License expired on %s', 'propertyhive' ), gmdate( 'jS F Y', strtotime( $license['expires_at'] ) ) ) . '. ' . $renew_link . '</span>';
					$input_border_color = '#900';
				}
				else
				{
					// Valid
					$output = '<span style="color:#090">' . __( 'License valid', 'propertyhive') . '.</span>';
					$input_border_color = '#090';
					$valid_license = true;
				}
			}
		}

		$legacy_error = get_option( 'propertyhive_license_key_error', '' );
		if ( 'old' === $license_type && '' !== $legacy_error ) {
			$output = '<span style="color:#900">' . esc_html( $legacy_error ) . '</span>';
			$input_border_color = '#900';
			$valid_license = false;
		}

		// get new license information
		$valid_pro_license = false;
		$pro_input_border_color = '';
		$pro_output = '';
		$license_key_to_display = '';
		if (get_option('propertyhive_pro_license_key', '') != '') 
		{ 
			$length = strlen(get_option('propertyhive_pro_license_key', '')); 
			$license_key_to_display = get_option('propertyhive_pro_license_key', '');
			if ( $length >= 6 )
			{
				$license_key_to_display = get_option('propertyhive_pro_license_key', '')[0] . 
				get_option('propertyhive_pro_license_key', '')[1] . 
				get_option('propertyhive_pro_license_key', '')[2] . 
				str_repeat('*', $length - 4) . 
				get_option('propertyhive_pro_license_key', '')[$length-3] . 
				get_option('propertyhive_pro_license_key', '')[$length-2] . 
				get_option('propertyhive_pro_license_key', '')[$length-1]; 
			}

			if ( PH()->license->is_valid_pro_license_key(true) )
			{
				$valid_pro_license = true;				
				// to be used for displaying subscription level in future
				//$product_id_and_package = PH()->license->get_pro_license_product_id_and_package();
				$pro_input_border_color = '#090';
			}
			else
			{
				$pro_license = PH()->license->get_current_pro_license();
				$pro_input_border_color = '#900'; 
				$pro_output = ( isset($pro_license['error']) ? $pro_license['error'] : '' );
			}
		}
		

		$settings = array(

			array( 'title' => __( 'License Key', 'propertyhive' ), 'type' => 'title', 'id' => 'license_options' ),

		);

		$settings[] = array(
			'title'       => __( 'License Type', 'propertyhive' ),
			'id'          => 'propertyhive_license_type',
			'type'        => 'radio',
			'default' 	  => $license_type,
			'options'     => array(
				'pro' => 'Pro',
				'old' => 'Old-Style (license keys purchased before October 2023)'
			)
		);

		$settings[] = array(
			'type'        => 'html',
			'id' 		  => 'pro_license_key_info',
			'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>' .
                ( ! $valid_pro_license ?
                    '<a href="https://wp-property-hive.com/pricing/?src=plugin-license-settings" class="button button-primary" target="_blank">' . esc_html__( 'Get PRO', 'propertyhive' ) . '</a>' :
                    '<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>'
                ) . '</p><input type="hidden" name="pro_license_key_action" value="' . ( $valid_pro_license ? 'deactivate' : 'activate' ) . '">',
		);

		if ( $valid_pro_license )
		{
			$settings[] = array(
				'type'        => 'html',
				'id' 		  => 'pro_license_key_display',
				'title'		  => __( 'License Key', 'propertyhive' ),
				'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 )
			);

			$settings[] = array(
				'title'       => __( 'License Key', 'propertyhive' ),
				'id'          => 'propertyhive_pro_license_key',
				'type'        => 'hidden'
			);
		}
		else
		{
			$settings[] = array(
				'title'       => __( 'License Key', 'propertyhive' ),
				'id'          => 'propertyhive_pro_license_key',
				'type'        => 'text',
				'css' 	  => 'min-width:350px; border:1px solid ' . $pro_input_border_color,
				'desc' 		  => $pro_output
			);
		}

		$legacy_license_message = '';

		if ( 'old' === $license_type ) 
		{
			$legacy_license_message = '<p>' . sprintf(
				/* translators: %s: URL to the support page */
				__( 'To switch your existing license key over to the new pricing model, please <a href="%s">get in touch</a>.', 'propertyhive' ),
				esc_url( 'https://wp-property-hive.com/support' )
			) . '</p>';
		}

		$settings[] = array(
			'type' => 'html',
			'id'   => 'license_key_info',
			'html' => sprintf(
				/* translators: 1: URL to the pricing page, 2: optional message shown to legacy license holders */
				__(
					'<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>
					<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>
					%2$s
					<br><p><a href="%1$s" class="button button-primary" target="_blank">Get PRO</a></p>',
					'propertyhive'
				),
				esc_url( 'https://wp-property-hive.com/pricing/?src=plugin-license-settings' ),
				$legacy_license_message
			),
		);

		$settings[] = array(
			'title'       => __( 'License Key', 'propertyhive' ),
			'id'          => 'propertyhive_license_key',
			'type'        => 'text',
			'css'         => 'min-width:350px; border:1px solid ' . $input_border_color,
			'desc' 		  => $output,
		);

		$settings[] = array( 'type' => 'sectionend', 'id' => 'license_options' );

		return apply_filters( 'propertyhive_get_settings_' . $this->id, $settings );
	}

	/**
	 * Output the settings.
	 */
	public function output() {
		global $current_section, $hide_save_button;

        $settings = $this->get_settings();

		PH_Admin_Settings::output_fields( $settings );
	}

	/**
	 * Save settings.
	 */
	public function save() {
        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' ) ) {
            return;
        }


        $license_type = isset( $_POST['propertyhive_license_type'] ) && is_string( $_POST['propertyhive_license_type'] ) ? sanitize_text_field( wp_unslash( $_POST['propertyhive_license_type'] ) ) : '';
        $license_key = isset( $_POST['propertyhive_pro_license_key'] ) && is_string( $_POST['propertyhive_pro_license_key'] ) ? ph_clean( wp_unslash( $_POST['propertyhive_pro_license_key'] ) ) : '';
        $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'] ) ) : '';


		$settings = $this->get_settings();

		PH_Admin_Settings::save_fields( $settings );

		update_option( 'missing_invalid_expired_license_key_notice_dismissed', '' );

		if ( 'pro' === $license_type && ! empty( $license_key ) && 'activate' === $license_action )
		{
			$return = PH()->license->activate_pro_license_key();
			if ( $return['success'] === false )
			{
				PH_Admin_Settings::add_error($return['error']);
			}
			else
			{
				PH_Admin_Settings::add_message('License key activated successfully');
			}
		}

		if ( 'pro' === $license_type && ! empty( $license_key ) && 'deactivate' === $license_action )
		{
			$return = PH()->license->deactivate_pro_license_key();
			if ( $return['success'] === false )
			{
				PH_Admin_Settings::add_error($return['error']);
			}
			else
			{
				PH_Admin_Settings::add_message('License key deactivated successfully');
			}
		}

		if ( 'old' === $license_type )
		{
			PH()->license->ph_check_licenses(true);
		}
	}
}

endif;

return new PH_Settings_Licenses();

```
