123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- <?php
- if ( ! defined( 'ABSPATH' ) ) {
- exit;
- }
- if ( ! class_exists( 'ACF_Admin_Updates' ) ) :
- class ACF_Admin_Updates {
-
- var $view = array();
-
- function __construct() {
-
- add_action( 'admin_menu', array( $this, 'admin_menu' ), 20 );
- }
-
- function display_wp_error( $wp_error ) {
-
- if ( acf_has_done( 'display_wp_error' ) ) {
- return;
- }
-
- acf_new_admin_notice(
- array(
- 'text' => __( '<b>Error</b>. Could not connect to update server', 'acf' ) . ' <span class="description">(' . esc_html( $wp_error->get_error_message() ) . ').</span>',
- 'type' => 'error',
- )
- );
- }
-
- function get_changelog_changes( $changelog = '', $version = '' ) {
-
- $bits = array_filter( explode( '<h4>', $changelog ) );
-
- foreach ( $bits as $bit ) {
-
- $bit = explode( '</h4>', $bit );
- $bit_version = trim( $bit[0] );
- $bit_text = trim( $bit[1] );
-
- if ( acf_version_compare( $bit_version, '==', $version ) ) {
- return '<h4>' . esc_html( $bit_version ) . '</h4>' . acf_esc_html( $bit_text );
- }
- }
-
- return '';
- }
-
- function admin_menu() {
-
- if ( ! acf_get_setting( 'show_admin' ) ) {
- return;
- }
-
- if ( ! acf_get_setting( 'show_updates' ) ) {
- return;
- }
-
- if ( ! acf_is_plugin_active() ) {
- return;
- }
-
- $page = add_submenu_page( 'edit.php?post_type=acf-field-group', __( 'Updates', 'acf' ), __( 'Updates', 'acf' ), acf_get_setting( 'capability' ), 'acf-settings-updates', array( $this, 'html' ) );
-
- add_action( "load-$page", array( $this, 'load' ) );
- }
-
- function load() {
-
- if ( acf_verify_nonce( 'activate_pro_license' ) ) {
- acf_pro_activate_license( sanitize_text_field( $_POST['acf_pro_license'] ) );
-
- } elseif ( acf_verify_nonce( 'deactivate_pro_license' ) ) {
- acf_pro_deactivate_license();
- }
-
- $license = acf_pro_get_license_key();
- $this->view = array(
- 'license' => $license,
- '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,
- );
-
- $force_check = ! empty( $_GET['force-check'] );
- $info = acf_updates()->get_plugin_info( 'pro', $force_check );
-
- if ( is_wp_error( $info ) ) {
- return $this->display_wp_error( $info );
- }
-
- $this->view['remote_version'] = $info['version'];
-
- $version = acf_get_setting( 'version' );
-
- if ( version_compare( $info['version'], $version, '>' ) ) {
-
- $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'] );
-
- $basename = acf_get_setting( 'basename' );
- $update = acf_updates()->get_plugin_update( $basename );
- if ( $license ) {
- if ( isset( $update['license_valid'] ) && ! $update['license_valid'] ) {
- $this->view['license_error'] = true;
- acf_new_admin_notice(
- array(
- 'text' => __( '<b>Error</b>. Your license for this site has expired or been deactivated. Please reactivate your ACF PRO license.', 'acf' ),
- 'type' => 'error',
- )
- );
- } else {
-
-
- if ( $update && ! $update['package'] ) {
- $this->view['license_error'] = true;
- acf_new_admin_notice(
- array(
- 'text' => __( '<b>Error</b>. Could not authenticate update package. Please check again or deactivate and reactivate your ACF PRO license.', 'acf' ),
- 'type' => 'error',
- )
- );
- }
- }
-
-
-
- if ( ! $update || $update['new_version'] !== $info['version'] ) {
- acf_updates()->refresh_plugins_transient();
- }
- }
- }
- }
-
- function html() {
- acf_get_view( dirname( __FILE__ ) . '/views/html-settings-updates.php', $this->view );
- }
- }
-
- acf_new_instance( 'ACF_Admin_Updates' );
- endif;
|