acf_pro_activate_license()
Activates the submitted license key Formally ACF_Admin_Updates::activate_pro_licence since 5.0.0
Хуки из функции
Возвращает
Разное. $response A wp-error instance, or an array with a boolean success key, and string message key.
Использование
acf_pro_activate_license( $license_key, $silent, $automatic );
- $license_key(строка) (обязательный)
- License key to activate.
- $silent(true|false)
- Return errors rather than displaying them.
По умолчанию:false - $automatic(true|false)
- True if this activation is happening automatically.
По умолчанию:false
Список изменений
| С версии 5.11.0 | Введена. |
Код acf_pro_activate_license() acf pro activate license ACF 6.4.2
function acf_pro_activate_license( $license_key, $silent = false, $automatic = false ) {
// Connect to API.
$post = array(
'acf_license' => trim( $license_key ),
'acf_version' => acf_get_setting( 'version' ),
'wp_name' => get_bloginfo( 'name' ),
'wp_url' => acf_get_home_url(),
'wp_version' => get_bloginfo( 'version' ),
'wp_language' => get_bloginfo( 'language' ),
'wp_timezone' => get_option( 'timezone_string' ),
'wp_multisite' => (int) is_multisite(),
'php_version' => PHP_VERSION,
'block_count' => acf_pro_get_registered_block_count(),
);
$activation_url = 'v2/plugins/activate?p=pro';
if ( $automatic ) {
if ( ! apply_filters( 'acf/automatic_license_reactivation', true ) ) {
return false;
}
$activation_url .= '&automatic=true';
}
// Remove the current license status.
acf_pro_delete_license_transient( 'acf_activation_error' );
acf_pro_remove_license_status();
$response = acf_updates()->request( $activation_url, $post );
$expiration = acf_updates()->get_expiration( $response, DAY_IN_SECONDS );
// Check response is expected JSON array (not string).
if ( is_string( $response ) ) {
$response = new WP_Error( 'server_error', esc_html( $response ) );
}
// Display error.
if ( is_wp_error( $response ) ) {
if ( ! $silent ) {
acf_pro_display_wp_activation_error( $response );
}
return $response;
}
$success = false;
// On success.
if ( $response['status'] == 1 ) {
// Update license and clear out existing license status.
acf_pro_update_license( $response['license'] );
if ( ! empty( $response['license_status'] ) && is_array( $response['license_status'] ) ) {
$response['license_status']['next_check'] = time() + $expiration;
acf_pro_update_license_status( $response['license_status'] );
}
// Refresh plugins transient to fetch new update data.
acf_updates()->refresh_plugins_transient();
// Show notice.
if ( ! $silent ) {
acf_add_admin_notice( acf_esc_html( acf_pro_get_translated_connect_message( $response['message'] ) ), 'success' );
}
$success = true;
// On failure.
} else {
// Show notice.
if ( ! $silent ) {
acf_add_admin_notice( acf_esc_html( acf_pro_get_translated_connect_message( $response['message'] ) ), 'warning' );
}
}
// Return status array for automated activation error notices
return array(
'success' => $success,
'message' => $response['message'],
);
}