acf_pro_maybe_reactivate_license()
Attempts to reactivate the license if the URL has changed.
Хуков нет.
Возвращает
null. Ничего (null).
Использование
acf_pro_maybe_reactivate_license();
Список изменений
| С версии 6.2.3 | Введена. |
Код acf_pro_maybe_reactivate_license() acf pro maybe reactivate license ACF 6.4.2
function acf_pro_maybe_reactivate_license() {
// Defined licenses have separate logic.
if ( defined( 'ACF_PRO_LICENSE' ) ) {
return;
}
// Bail if we're in an AJAX request, or tried this recently.
if ( acf_is_ajax() || acf_pro_get_license_transient( 'acf_pro_license_reactivated' ) ) {
return;
}
$license = acf_pro_get_license();
// Nothing to do if URL hasn't changed.
if ( empty( $license['key'] ) || empty( $license['url'] ) || ! acf_pro_has_license_url_changed( $license ) ) {
return;
}
// Set a transient, so we don't keep trying this in a short period.
acf_pro_set_license_transient( 'acf_pro_license_reactivated', true, HOUR_IN_SECONDS );
// Prevent subsequent attempts at reactivation by updating the license URL.
acf_pro_update_license( $license['key'] );
// Attempt to reactivate the license with the current URL.
$reactivation = acf_pro_activate_license( $license['key'], true, true );
// Update license status on failure.
if ( is_wp_error( $reactivation ) || ! is_array( $reactivation ) || empty( $reactivation['success'] ) ) {
$license_status = acf_pro_get_license_status();
$license_status['status'] = 'inactive';
if ( is_array( $reactivation ) && ! empty( $reactivation['message'] ) ) {
$license_status['error_msg'] = sprintf(
/* translators: %s - more details about the error received */
__( "Your site URL has changed since last activating your license, but we weren't able to automatically reactivate it: %s", 'acf' ),
acf_pro_get_translated_connect_message( $reactivation['message'] )
);
}
acf_pro_update_license_status( $license_status );
} else {
acf_add_admin_notice(
__( '<strong>ACF PRO —</strong>', 'acf' ) . ' ' . __( "Your site URL has changed since last activating your license. We've automatically activated it for this site URL.", 'acf' ),
'success'
);
}
}