acf_pro_check_defined_license()
Check if a license is defined in wp-config.php and requires activation. Also checks if the license key has been changed and reactivates.
Хуков нет.
Возвращает
null. Ничего (null).
Использование
acf_pro_check_defined_license();
Список изменений
| С версии 5.11.0 | Введена. |
Код acf_pro_check_defined_license() acf pro check defined license ACF 6.4.2
function acf_pro_check_defined_license() {
// Bail early if we're doing an AJAX call.
if ( acf_is_ajax() ) {
return;
}
// Bail early if the license is not defined in wp-config.
if ( ! defined( 'ACF_PRO_LICENSE' ) || empty( ACF_PRO_LICENSE ) || ! is_string( ACF_PRO_LICENSE ) ) {
return;
}
// Bail early if no show_admin.
if ( ! acf_get_setting( 'show_admin' ) ) {
return;
}
// Check if we've been asked to clear the transient to retry activation.
if ( acf_verify_nonce( 'acf_delete_activation_transient' ) || ( isset( $_REQUEST['acf_retry_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['acf_retry_nonce'] ) ), 'acf_retry_activation' ) ) ) {
acf_pro_delete_license_transient( 'acf_activation_error' );
} else {
// If we've failed activation recently, check if the key has been changed, otherwise return.
$activation_data = acf_pro_get_activation_failure_transient();
if ( $activation_data && $activation_data['license'] === ACF_PRO_LICENSE ) {
return;
}
}
// If we're already activated, check if the defined license key has changed.
$license = acf_pro_get_license();
if ( $license ) {
// Check the saved license key against the defined key.
if ( acf_pro_get_license_key() !== ACF_PRO_LICENSE ) {
// Deactivate if the key has changed.
$deactivation_response = acf_pro_deactivate_license( true );
// A connection error occurred while trying to deactivate.
if ( is_wp_error( $deactivation_response ) ) {
return acf_pro_set_activation_failure_transient( __( 'Your defined license key has changed, but an error occurred when connecting to activation server', 'acf' ) . ' <span class="description">(' . esc_html( $deactivation_response->get_error_message() ) . ').</span>', ACF_PRO_LICENSE );
// A deactivation error occurred. Display the message returned by our API.
} elseif ( ! $deactivation_response['success'] ) {
return acf_pro_set_activation_failure_transient( __( 'Your defined license key has changed, but an error occurred when deactivating your old license', 'acf' ) . ' <span class="description">(' . $deactivation_response['message'] . ').</span>', ACF_PRO_LICENSE );
}
} else {
// License key hasn't changed, we are activated and license is still valid, return.
return;
}
}
// Activate the defined key license.
$activation_response = acf_pro_activate_license( ACF_PRO_LICENSE, true, true );
$error_text = false;
// Activation was prevented by filter.
if ( $activation_response === false ) {
return;
// A connection error occurred during activation.
} elseif ( is_wp_error( $activation_response ) ) {
$error_text = __( 'An error occurred when connecting to activation server', 'acf' ) . ' <span class="description">(' . esc_html( $activation_response->get_error_message() ) . ').</span>';
// A deactivation error occurred. Display the message returned by our API.
} elseif ( ! $activation_response['success'] ) {
$error_text = __( 'There was an issue activating your license key.', 'acf' ) . ' ';
$error_text .= acf_pro_get_translated_connect_message( $activation_response['message'] );
} else {
// Delete any previously saved activation error transient.
acf_pro_delete_license_transient( 'acf_activation_error' );
// Use our own success message instead of the one from connect so it can be translated.
acf_add_admin_notice(
__( '<strong>ACF PRO —</strong> Your license key has been activated successfully. Access to updates, support & PRO features is now enabled.', 'acf' ),
'success'
);
return;
}
// Clear out old license status if something went wrong.
acf_pro_remove_license_status();
return acf_pro_set_activation_failure_transient( $error_text, ACF_PRO_LICENSE );
}