ACF_Admin_Updates::load │ public │ ACF 5.0.0
load
Runs when loading the submenu page.
Метод класса: ACF_Admin_Updates{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$ACF_Admin_Updates = new ACF_Admin_Updates(); $ACF_Admin_Updates->load();
Список изменений
| С версии 5.0.0 | Введена. |
Код ACF_Admin_Updates::load() ACF Admin Updates::load ACF 6.4.2
function load() {
add_action( 'admin_body_class', array( $this, 'admin_body_class' ) );
// Check activate.
if ( acf_verify_nonce( 'activate_pro_license' ) && ! empty( $_POST['acf_pro_license'] ) ) {
acf_pro_activate_license( sanitize_text_field( $_POST['acf_pro_license'] ) ); //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- unslash not needed.
// Check deactivate.
} elseif ( acf_verify_nonce( 'deactivate_pro_license' ) ) {
acf_pro_deactivate_license();
}
// Check if we should force check the license status.
$force_get_license_status = false;
$retry_license_nonce = acf_request_arg( 'acf_retry_nonce' );
if ( wp_verify_nonce( $retry_license_nonce, 'acf_recheck_status' ) || ! empty( $_GET['force-license-check'] ) ) {
$force_get_license_status = true;
}
// vars
$license = acf_pro_get_license_key();
$this->view = array(
'license' => $license,
'license_status' => acf_pro_get_license_status( $force_get_license_status ),
'active' => $license ? 1 : 0,
'current_version' => acf_get_setting( 'version' ),
'remote_version' => '',
'update_available' => false,
'changelog' => '',
'upgrade_notice' => '',
'is_defined_license' => defined( 'ACF_PRO_LICENSE' ) && ! empty( ACF_PRO_LICENSE ) && is_string( ACF_PRO_LICENSE ),
'license_error' => false,
'wp_not_compatible' => false,
);
// get plugin updates
$force_check = ! empty( $_GET['force-check'] );
$info = acf_updates()->get_plugin_info( 'pro', $force_check );
// Display error.
if ( is_wp_error( $info ) ) {
return $this->display_wp_error( $info );
}
// add info to view
$this->view['remote_version'] = $info['version'];
// add changelog if the remote version is '>' than the current version
$version = acf_get_setting( 'version' );
// check if remote version is higher than current version
if ( version_compare( $info['version'], $version, '>' ) ) {
// update view.
$this->view['update_available'] = true;
$this->view['changelog'] = $this->get_changelog_changes( $info['changelog'], $info['version'] );
$this->view['upgrade_notice'] = $this->get_changelog_changes( $info['upgrade_notice'], $info['version'] );
// perform update checks if license is active.
$basename = acf_get_setting( 'basename' );
$update = acf_updates()->get_plugin_update( $basename );
$no_update = acf_updates()->get_no_update( $basename );
if ( $no_update && ! empty( $no_update['reason'] ) && $no_update['reason'] === 'wp_not_compatible' ) {
$this->view['wp_not_compatible'] = true;
acf_new_admin_notice(
array(
/* translators: %s the version of WordPress required for this ACF update */
'text' => sprintf( __( 'An update to ACF is available, but it is not compatible with your version of WordPress. Please upgrade to WordPress %s or newer to update ACF.', 'acf' ), $no_update['requires'] ),
'type' => 'error',
)
);
}
if ( $license ) {
if ( isset( $update['license_valid'] ) && ! $update['license_valid'] ) {
$this->view['license_error'] = true;
acf_new_admin_notice(
array(
'text' => __( '<strong>Error</strong>. Your license for this site has expired or been deactivated. Please reactivate your ACF PRO license.', 'acf' ),
'type' => 'error',
)
);
} else {
// display error if no package url - possible if license key or site URL has been modified.
if ( $update && ! $update['package'] ) {
$this->view['license_error'] = true;
acf_new_admin_notice(
array(
'text' => __( '<strong>Error</strong>. Could not authenticate update package. Please check again or deactivate and reactivate your ACF PRO license.', 'acf' ),
'type' => 'error',
)
);
}
}
// refresh transient - if no update exists in the transient or if the transient 'new_version' is stale.
if ( ! $update || $update['new_version'] !== $info['version'] ) {
acf_updates()->refresh_plugins_transient();
}
}
}
}