acf_pro_get_license_status()ACF 6.2.2

Returns the status of the current ACF PRO license.

Хуков нет.

Возвращает

Массив.

Использование

acf_pro_get_license_status( $force_check );
$force_check(true|false)
If we should force a call to the API.
По умолчанию: false

Список изменений

С версии 6.2.2 Введена.

Код acf_pro_get_license_status() ACF 6.4.2

function acf_pro_get_license_status( $force_check = false ) {
	$store  = acf_get_store( 'acf_pro_license_status' );
	$cached = $store->get_data();

	if ( ! empty( $cached ) && ! $force_check ) {
		return $cached;
	}

	$license = acf_pro_get_license_key( true );

	// Defined licenses may not have a license stored in the database.
	if ( ! $license && defined( 'ACF_PRO_LICENSE' ) && acf_pro_get_license() ) {
		$license = ACF_PRO_LICENSE;
	}

	$status     = acf_pro_get_license_option( 'acf_pro_license_status', array() );
	$next_check = isset( $status['next_check'] ) ? (int) $status['next_check'] : 0;

	if ( ! is_array( $status ) ) {
		$status = array();
	}

	// If we don't have a license, remove any existing status.
	if ( empty( $license ) && ! empty( $status ) ) {
		acf_pro_remove_license_status();
		$status = array();
	}

	// Call the API if necessary, if we have a license.
	if ( ( empty( $status ) || $force_check || time() > $next_check ) && $license ) {
		if ( ! get_transient( 'acf_pro_validating_license' ) || $force_check ) {
			set_transient( 'acf_pro_validating_license', true, 15 * MINUTE_IN_SECONDS );

			$post = array(
				'acf_license' => $license,
				'wp_url'      => acf_get_home_url(),
			);

			$response   = acf_updates()->request( 'v2/plugins/validate?p=pro', $post );
			$expiration = acf_updates()->get_expiration( $response );

			if ( is_array( $response ) ) {
				if ( ! empty( $response['license_status'] ) ) {
					$status = $response['license_status'];
				}

				// Handle errors from connect.
				if ( ! empty( $response['code'] ) && 'activation_not_found' === $response['code'] ) {

					// If our activation is no longer found and the user has a defined license, deactivate the license and let the automatic reactivation attempt happen.
					if ( defined( 'ACF_PRO_LICENSE' ) ) {
						acf_pro_update_license( '' );
						acf_pro_check_defined_license();
					} else {
						$status['error_msg'] = sprintf(
						/* translators: %s - URL to ACF updates page */
							__( 'Your license key is valid but not activated on this site. Please <a href="%s">deactivate</a> and then reactivate the license.', 'acf' ),
							esc_url( admin_url( 'edit.php?post_type=acf-field-group&page=acf-settings-updates#deactivate-license' ) )
						);
					}
				} elseif ( ! empty( $response['message'] ) ) {
					$status['error_msg'] = acf_esc_html( acf_pro_get_translated_connect_message( $response['message'] ) );
				}
			}

			$status['next_check'] = time() + $expiration;
			acf_pro_update_license_status( $status );
		}
	}

	$status = acf_pro_parse_license_status( $status );
	$store->set( $status );

	return $status;
}