Parsed: 111970

<?php

/**
 * Update Core administration panel.
 *
 * @package WordPress
 * @subpackage Administration
 */


/** WordPress Administration Bootstrap */
require_once __DIR__ . '/admin.php';

wp_enqueue_style( 'plugin-install' );
wp_enqueue_script( 'plugin-install' );
wp_enqueue_script( 'updates' );
add_thickbox();

if ( is_multisite() && ! is_network_admin() ) {
  wp_redirect( network_admin_url( 'update-core.php' ) );
  exit;
}

if ( ! current_user_can( 'update_core' ) && ! current_user_can( 'update_themes' ) && ! current_user_can( 'update_plugins' ) && ! current_user_can( 'update_languages' ) ) {
  wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
}

/* function list_core_update() – Lists available core updates. */

/* function dismissed_updates() – Display dismissed updates. */

/* function core_upgrade_preamble() – Display upgrade WordPress for downloading latest or upgrading automatically form. */

/* function core_auto_updates_settings() – Display WordPress auto-updates settings. */

/* function list_plugin_updates() – Display the upgrade plugins form. */

/* function list_theme_updates() – Display the upgrade themes form. */

/* function list_translation_updates() – Display the update translations form. */

/* function do_core_upgrade() – Upgrade WordPress core display. */

/* function do_dismiss_core_update() – Dismiss a core update. */

/* function do_undismiss_core_update() – Undismiss a core update. */

$action = isset( $_GET['action'] ) ? $_GET['action'] : 'upgrade-core';

$upgrade_error = false;
if ( ( 'do-theme-upgrade' === $action || ( 'do-plugin-upgrade' === $action && ! isset( $_GET['plugins'] ) ) )
  && ! isset( $_POST['checked'] ) ) {
  $upgrade_error = ( 'do-theme-upgrade' === $action ) ? 'themes' : 'plugins';
  $action        = 'upgrade-core';
}

$title       = __( 'WordPress Updates' );
$parent_file = 'index.php';

$updates_overview  = '<p>' . __( 'On this screen, you can update to the latest version of WordPress, as well as update your themes, plugins, and translations from the WordPress.org repositories.' ) . '</p>';
$updates_overview .= '<p>' . __( 'If an update is available, you᾿ll see a notification appear in the Toolbar and navigation menu.' ) . ' ' . __( 'Keeping your site updated is important for security. It also makes the internet a safer place for you and your readers.' ) . '</p>';

get_current_screen()->add_help_tab(
  array(
    'id'      => 'overview',
    'title'   => __( 'Overview' ),
    'content' => $updates_overview,
  )
);

$updates_howto  = '<p>' . __( '<strong>WordPress</strong> &mdash; Updating your WordPress installation is a simple one-click procedure: just <strong>click on the “Update now” button</strong> when you are notified that a new version is available.' ) . ' ' . __( 'In most cases, WordPress will automatically apply maintenance and security updates in the background for you.' ) . '</p>';
$updates_howto .= '<p>' . __( '<strong>Themes and Plugins</strong> &mdash; To update individual themes or plugins from this screen, use the checkboxes to make your selection, then <strong>click on the appropriate “Update” button</strong>. To update all of your themes or plugins at once, you can check the box at the top of the section to select all before clicking the update button.' ) . '</p>';

if ( 'en_US' !== get_locale() ) {
  $updates_howto .= '<p>' . __( '<strong>Translations</strong> &mdash; The files translating WordPress into your language are updated for you whenever any other updates occur. But if these files are out of date, you can <strong>click the “Update Translations”</strong> button.' ) . '</p>';
}

get_current_screen()->add_help_tab(
  array(
    'id'      => 'how-to-update',
    'title'   => __( 'How to Update' ),
    'content' => $updates_howto,
  )
);

$help_sidebar_autoupdates = '';

if ( ( current_user_can( 'update_themes' ) && wp_is_auto_update_enabled_for_type( 'theme' ) ) || ( current_user_can( 'update_plugins' ) && wp_is_auto_update_enabled_for_type( 'plugin' ) ) ) {
  $help_tab_autoupdates  = '<p>' . __( 'Auto-updates can be enabled or disabled for WordPress major versions and for each individual theme or plugin. Themes or plugins with auto-updates enabled will display the estimated date of the next auto-update. Auto-updates depends on the WP-Cron task scheduling system.' ) . '</p>';
  $help_tab_autoupdates .= '<p>' . __( 'Please note: Third-party themes and plugins, or custom code, may override WordPress scheduling.' ) . '</p>';

  get_current_screen()->add_help_tab(
    array(
      'id'      => 'plugins-themes-auto-updates',
      'title'   => __( 'Auto-updates' ),
      'content' => $help_tab_autoupdates,
    )
  );

  $help_sidebar_autoupdates = '<p>' . __( '<a href="https://wordpress.org/documentation/article/plugins-themes-auto-updates/">Documentation on Auto-updates</a>' ) . '</p>';
}

get_current_screen()->set_help_sidebar(
  '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  '<p>' . __( '<a href="https://wordpress.org/documentation/article/dashboard-updates-screen/">Documentation on Updating WordPress</a>' ) . '</p>' .
  $help_sidebar_autoupdates .
  '<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>'
);

if ( 'upgrade-core' === $action ) {
  // Force a update check when requested.
  $force_check = ! empty( $_GET['force-check'] );
  wp_version_check( array(), $force_check );

  require_once ABSPATH . 'wp-admin/admin-header.php';
  ?>
	<div class="wrap">
	<h1><?php _e( 'WordPress Updates' ); ?></h1>
	<p><?php _e( 'Here you can find information about updates, set auto-updates and see what plugins or themes need updating.' ); ?></p>

	<?php
  if ( $upgrade_error ) {
    echo '<div class="error"><p>';
    if ( 'themes' === $upgrade_error ) {
      _e( 'Please select one or more themes to update.' );
    } else {
      _e( 'Please select one or more plugins to update.' );
    }
    echo '</p></div>';
  }

  $last_update_check = false;
  $current           = get_site_transient( 'update_core' );

  if ( $current && isset( $current->last_checked ) ) {
    $last_update_check = $current->last_checked + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
  }

  echo '<h2 class="wp-current-version">';
  /* translators: Current version of WordPress. */
  printf( __( 'Current version: %s' ), get_bloginfo( 'version' ) );
  echo '</h2>';

  echo '<p class="update-last-checked">';
  /* translators: 1: Date, 2: Time. */
  printf( __( 'Last checked on %1$s at %2$s.' ), date_i18n( __( 'F j, Y' ), $last_update_check ), date_i18n( __( 'g:i a T' ), $last_update_check ) );
  echo ' <a href="' . esc_url( Telf_admin_url( 'update-core.php?force-check=1' ) ) . '">' . __( 'Check again.' ) . '</a>';
  echo '</p>';

  if ( current_user_can( 'update_core' ) ) {
    core_auto_updates_settings();
    core_upgrade_preamble();
  }
  if ( current_user_can( 'update_plugins' ) ) {
    list_plugin_updates();
  }
  if ( current_user_can( 'update_themes' ) ) {
    list_theme_updates();
  }
  if ( current_user_can( 'update_languages' ) ) {
    list_translation_updates();
  }

  
/**
 * Fires after the core, plugin, and theme update tables.
 *
 * @since 2.9.0
 */
  do_action( 'core_upgrade_preamble' );
  echo '</div>';

  wp_localize_script(
    'updates',
    '_wpUpdatesItemCounts',
    array(
      'totals' => wp_get_update_data(),
    )
  );

  require_once ABSPATH . 'wp-admin/admin-footer.php';

} elseif ( 'do-core-upgrade' === $action || 'do-core-reinstall' === $action ) {

  if ( ! current_user_can( 'update_core' ) ) {
    wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
  }

  check_admin_referer( 'upgrade-core' );

  // Do the (un)dismiss actions before headers, so that they can redirect.
  if ( isset( $_POST['dismiss'] ) ) {
    do_dismiss_core_update();
  } elseif ( isset( $_POST['undismiss'] ) ) {
    do_undismiss_core_update();
  }

  require_once ABSPATH . 'wp-admin/admin-header.php';
  if ( 'do-core-reinstall' === $action ) {
    $reinstall = true;
  } else {
    $reinstall = false;
  }

  if ( isset( $_POST['upgrade'] ) ) {
    do_core_upgrade( $reinstall );
  }

  wp_localize_script(
    'updates',
    '_wpUpdatesItemCounts',
    array(
      'totals' => wp_get_update_data(),
    )
  );

  require_once ABSPATH . 'wp-admin/admin-footer.php';

} elseif ( 'do-plugin-upgrade' === $action ) {

  if ( ! current_user_can( 'update_plugins' ) ) {
    wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
  }

  check_admin_referer( 'upgrade-core' );

  if ( isset( $_GET['plugins'] ) ) {
    $plugins = explode( ',', $_GET['plugins'] );
  } elseif ( isset( $_POST['checked'] ) ) {
    $plugins = (array) $_POST['checked'];
  } else {
    wp_redirect( admin_url( 'update-core.php' ) );
    exit;
  }

  $url = 'update.php?action=update-selected&plugins=' . urlencode( implode( ',', $plugins ) );
  $url = wp_nonce_url( $url, 'bulk-update-plugins' );

  // Used in the HTML title tag.
  $title = __( 'Update Plugins' );

  require_once ABSPATH . 'wp-admin/admin-header.php';
  ?>
	<div class="wrap">
		<h1><?php _e( 'Update Plugins' ); ?></h1>
		<iframe src="<?php echo $url; ?>" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="<?php esc_attr_e( 'Update progress' ); ?>"></iframe>
	</div>
	<?php

  wp_localize_script(
    'updates',
    '_wpUpdatesItemCounts',
    array(
      'totals' => wp_get_update_data(),
    )
  );

  require_once ABSPATH . 'wp-admin/admin-footer.php';

} elseif ( 'do-theme-upgrade' === $action ) {

  if ( ! current_user_can( 'update_themes' ) ) {
    wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
  }

  check_admin_referer( 'upgrade-core' );

  if ( isset( $_GET['themes'] ) ) {
    $themes = explode( ',', $_GET['themes'] );
  } elseif ( isset( $_POST['checked'] ) ) {
    $themes = (array) $_POST['checked'];
  } else {
    wp_redirect( admin_url( 'update-core.php' ) );
    exit;
  }

  $url = 'update.php?action=update-selected-themes&themes=' . urlencode( implode( ',', $themes ) );
  $url = wp_nonce_url( $url, 'bulk-update-themes' );

  // Used in the HTML title tag.
  $title = __( 'Update Themes' );

  require_once ABSPATH . 'wp-admin/admin-header.php';
  ?>
	<div class="wrap">
		<h1><?php _e( 'Update Themes' ); ?></h1>
		<iframe src="<?php echo $url; ?>" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="<?php esc_attr_e( 'Update progress' ); ?>"></iframe>
	</div>
	<?php

  wp_localize_script(
    'updates',
    '_wpUpdatesItemCounts',
    array(
      'totals' => wp_get_update_data(),
    )
  );

  require_once ABSPATH . 'wp-admin/admin-footer.php';

} elseif ( 'do-translation-upgrade' === $action ) {

  if ( ! current_user_can( 'update_languages' ) ) {
    wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
  }

  check_admin_referer( 'upgrade-translations' );

  require_once ABSPATH . 'wp-admin/admin-header.php';
  require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';

  $url     = 'update-core.php?action=do-translation-upgrade';
  $nonce   = 'upgrade-translations';
  $title   = __( 'Update Translations' );
  $context = WP_LANG_DIR;

  $upgrader = new Language_Pack_Upgrader( new Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) );
  $result   = $upgrader->bulk_upgrade();

  wp_localize_script(
    'updates',
    '_wpUpdatesItemCounts',
    array(
      'totals' => wp_get_update_data(),
    )
  );

  require_once ABSPATH . 'wp-admin/admin-footer.php';

} elseif ( 'core-major-auto-updates-settings' === $action ) {

  if ( ! current_user_can( 'update_core' ) ) {
    wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
  }

  $redirect_url = Telf_admin_url( 'update-core.php' );

  if ( isset( $_GET['value'] ) ) {
    check_admin_referer( 'core-major-auto-updates-nonce' );

    if ( 'enable' === $_GET['value'] ) {
      update_site_option( 'auto_update_core_major', 'enabled' );
      $redirect_url = add_query_arg( 'core-major-auto-updates-saved', 'enabled', $redirect_url );
    } elseif ( 'disable' === $_GET['value'] ) {
      update_site_option( 'auto_update_core_major', 'disabled' );
      $redirect_url = add_query_arg( 'core-major-auto-updates-saved', 'disabled', $redirect_url );
    }
  }

  wp_redirect( $redirect_url );
  exit;
} else {
  
/**
 * Fires for each custom update action on the WordPress Updates screen.
 *
 * The dynamic portion of the hook name, `$action`, refers to the
 * passed update action. The hook fires in lieu of all available
 * default update actions.
 *
 * @since 3.2.0
 */
  do_action( "update-core-custom_{$action}" );  // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
}