[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/includes/ -> update.php (source)

   1  <?php
   2  /**
   3   * WordPress Administration Update API
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  /**
  10   * Selects the first update version from the update_core option.
  11   *
  12   * @since 2.7.0
  13   *
  14   * @return object|false The response from the API on success, false on failure.
  15   */
  16  function get_preferred_from_update_core() {
  17      $updates = get_core_updates();
  18  
  19      if ( ! is_array( $updates ) ) {
  20          return false;
  21      }
  22  
  23      if ( empty( $updates ) ) {
  24          return (object) array( 'response' => 'latest' );
  25      }
  26  
  27      return $updates[0];
  28  }
  29  
  30  /**
  31   * Gets available core updates.
  32   *
  33   * @since 2.7.0
  34   *
  35   * @param array $options Set $options['dismissed'] to true to show dismissed upgrades too,
  36   *                       set $options['available'] to false to skip not-dismissed updates.
  37   * @return array<object>|false Array of the update objects on success, false on failure.
  38   */
  39  function get_core_updates( $options = array() ) {
  40      $options = array_merge(
  41          array(
  42              'available' => true,
  43              'dismissed' => false,
  44          ),
  45          $options
  46      );
  47  
  48      $dismissed = get_site_option( 'dismissed_update_core' );
  49  
  50      if ( ! is_array( $dismissed ) ) {
  51          $dismissed = array();
  52      }
  53  
  54      $from_api = get_site_transient( 'update_core' );
  55  
  56      if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) {
  57          return false;
  58      }
  59  
  60      $updates = $from_api->updates;
  61      $result  = array();
  62  
  63      foreach ( $updates as $update ) {
  64          if ( 'autoupdate' === $update->response ) {
  65              continue;
  66          }
  67  
  68          if ( array_key_exists( $update->current . '|' . $update->locale, $dismissed ) ) {
  69              if ( $options['dismissed'] ) {
  70                  $update->dismissed = true;
  71                  $result[]          = $update;
  72              }
  73          } else {
  74              if ( $options['available'] ) {
  75                  $update->dismissed = false;
  76                  $result[]          = $update;
  77              }
  78          }
  79      }
  80  
  81      return $result;
  82  }
  83  
  84  /**
  85   * Gets the best available (and enabled) Auto-Update for WordPress core.
  86   *
  87   * If there's 1.2.3 and 1.3 on offer, it'll choose 1.3 if the installation allows it, else, 1.2.3.
  88   *
  89   * @since 3.7.0
  90   *
  91   * @return object|false The core update offering on success, false on failure.
  92   */
  93  function find_core_auto_update() {
  94      $updates = get_site_transient( 'update_core' );
  95  
  96      if ( ! $updates || empty( $updates->updates ) ) {
  97          return false;
  98      }
  99  
 100      require_once  ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
 101  
 102      $auto_update = false;
 103      $upgrader    = new WP_Automatic_Updater();
 104  
 105      foreach ( $updates->updates as $update ) {
 106          if ( 'autoupdate' !== $update->response ) {
 107              continue;
 108          }
 109  
 110          if ( ! $upgrader->should_update( 'core', $update, ABSPATH ) ) {
 111              continue;
 112          }
 113  
 114          if ( ! $auto_update || version_compare( $update->current, $auto_update->current, '>' ) ) {
 115              $auto_update = $update;
 116          }
 117      }
 118  
 119      return $auto_update;
 120  }
 121  
 122  /**
 123   * Gets and caches the checksums for the given version of WordPress.
 124   *
 125   * @since 3.7.0
 126   *
 127   * @param string $version Version string to query.
 128   * @param string $locale  Locale to query.
 129   * @return array<string, string>|false An array of checksums on success, false on failure.
 130   */
 131  function get_core_checksums( $version, $locale ) {
 132      $http_url = 'http://api.wordpress.org/core/checksums/1.0/?' . http_build_query( compact( 'version', 'locale' ), '', '&' );
 133      $url      = $http_url;
 134  
 135      $ssl = wp_http_supports( array( 'ssl' ) );
 136  
 137      if ( $ssl ) {
 138          $url = set_url_scheme( $url, 'https' );
 139      }
 140  
 141      $options = array(
 142          'timeout' => wp_doing_cron() ? 30 : 3,
 143      );
 144  
 145      $response = wp_remote_get( $url, $options );
 146  
 147      if ( $ssl && is_wp_error( $response ) ) {
 148          wp_trigger_error(
 149              __FUNCTION__,
 150              sprintf(
 151                  /* translators: %s: Support forums URL. */
 152                  __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
 153                  __( 'https://wordpress.org/support/forums/' )
 154              ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
 155              headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
 156          );
 157  
 158          $response = wp_remote_get( $http_url, $options );
 159      }
 160  
 161      if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
 162          return false;
 163      }
 164  
 165      $body = trim( wp_remote_retrieve_body( $response ) );
 166      $body = json_decode( $body, true );
 167  
 168      if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) ) {
 169          return false;
 170      }
 171  
 172      return $body['checksums'];
 173  }
 174  
 175  /**
 176   * Dismisses core update.
 177   *
 178   * @since 2.7.0
 179   *
 180   * @param object $update
 181   * @return bool True if the option was updated, false otherwise.
 182   */
 183  function dismiss_core_update( $update ) {
 184      $dismissed = get_site_option( 'dismissed_update_core' );
 185      $dismissed[ $update->current . '|' . $update->locale ] = true;
 186  
 187      return update_site_option( 'dismissed_update_core', $dismissed );
 188  }
 189  
 190  /**
 191   * Undismisses core update.
 192   *
 193   * @since 2.7.0
 194   *
 195   * @param string $version
 196   * @param string $locale
 197   * @return bool True if the option was updated, false otherwise.
 198   */
 199  function undismiss_core_update( $version, $locale ) {
 200      $dismissed = get_site_option( 'dismissed_update_core' );
 201      $key       = $version . '|' . $locale;
 202  
 203      if ( ! isset( $dismissed[ $key ] ) ) {
 204          return false;
 205      }
 206  
 207      unset( $dismissed[ $key ] );
 208  
 209      return update_site_option( 'dismissed_update_core', $dismissed );
 210  }
 211  
 212  /**
 213   * Finds the available update for WordPress core.
 214   *
 215   * @since 2.7.0
 216   *
 217   * @param string $version Version string to find the update for.
 218   * @param string $locale  Locale to find the update for.
 219   * @return object|false The core update offering on success, false on failure.
 220   */
 221  function find_core_update( $version, $locale ) {
 222      $from_api = get_site_transient( 'update_core' );
 223  
 224      if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) {
 225          return false;
 226      }
 227  
 228      $updates = $from_api->updates;
 229  
 230      foreach ( $updates as $update ) {
 231          if ( $update->current === $version && $update->locale === $locale ) {
 232              return $update;
 233          }
 234      }
 235  
 236      return false;
 237  }
 238  
 239  /**
 240   * Returns core update footer message.
 241   *
 242   * @since 2.3.0
 243   *
 244   * @param string $msg
 245   * @return string The core update footer message.
 246   */
 247  function core_update_footer( $msg = '' ) {
 248      if ( ! current_user_can( 'update_core' ) ) {
 249          /* translators: %s: WordPress version. */
 250          return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
 251      }
 252  
 253      $cur = get_preferred_from_update_core();
 254  
 255      if ( ! is_object( $cur ) ) {
 256          $cur = new stdClass();
 257      }
 258  
 259      if ( ! isset( $cur->current ) ) {
 260          $cur->current = '';
 261      }
 262  
 263      if ( ! isset( $cur->response ) ) {
 264          $cur->response = '';
 265      }
 266  
 267      $is_development_version = preg_match( '/alpha|beta|RC/', wp_get_wp_version() );
 268  
 269      if ( $is_development_version ) {
 270          return sprintf(
 271              /* translators: 1: WordPress version number, 2: URL to WordPress Updates screen. */
 272              __( 'You are using a development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.' ),
 273              get_bloginfo( 'version', 'display' ),
 274              network_admin_url( 'update-core.php' )
 275          );
 276      }
 277  
 278      switch ( $cur->response ) {
 279          case 'upgrade':
 280              return sprintf(
 281                  '<strong><a href="%s">%s</a></strong>',
 282                  network_admin_url( 'update-core.php' ),
 283                  /* translators: %s: WordPress version. */
 284                  sprintf( __( 'Get Version %s' ), $cur->current )
 285              );
 286  
 287          case 'latest':
 288          default:
 289              /* translators: %s: WordPress version. */
 290              return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
 291      }
 292  }
 293  
 294  /**
 295   * Returns core update notification message.
 296   *
 297   * @since 2.3.0
 298   *
 299   * @global string $pagenow The filename of the current screen.
 300   * @return void|false Void on success, false if the update nag should not be displayed.
 301   */
 302  function update_nag() {
 303      global $pagenow;
 304  
 305      if ( is_multisite() && ! current_user_can( 'update_core' ) ) {
 306          return false;
 307      }
 308  
 309      if ( 'update-core.php' === $pagenow ) {
 310          return;
 311      }
 312  
 313      $cur = get_preferred_from_update_core();
 314  
 315      if ( ! isset( $cur->response ) || 'upgrade' !== $cur->response ) {
 316          return false;
 317      }
 318  
 319      $version_url = sprintf(
 320          /* translators: %s: WordPress version. */
 321          esc_url( __( 'https://wordpress.org/documentation/wordpress-version/version-%s/' ) ),
 322          sanitize_title( $cur->current )
 323      );
 324  
 325      if ( current_user_can( 'update_core' ) ) {
 326          $msg = sprintf(
 327              /* translators: 1: URL to WordPress release notes, 2: New WordPress version, 3: URL to network admin, 4: Accessibility text. */
 328              __( '<a href="%1$s">WordPress %2$s</a> is available! <a href="%3$s" aria-label="%4$s">Please update now</a>.' ),
 329              $version_url,
 330              $cur->current,
 331              network_admin_url( 'update-core.php' ),
 332              esc_attr__( 'Please update WordPress now' )
 333          );
 334      } else {
 335          $msg = sprintf(
 336              /* translators: 1: URL to WordPress release notes, 2: New WordPress version. */
 337              __( '<a href="%1$s">WordPress %2$s</a> is available! Please notify the site administrator.' ),
 338              $version_url,
 339              $cur->current
 340          );
 341      }
 342  
 343      wp_admin_notice(
 344          $msg,
 345          array(
 346              'type'               => 'warning',
 347              'additional_classes' => array( 'update-nag', 'inline' ),
 348              'paragraph_wrap'     => false,
 349          )
 350      );
 351  }
 352  
 353  /**
 354   * Displays WordPress version and active theme in the 'At a Glance' dashboard widget.
 355   *
 356   * @since 2.5.0
 357   */
 358  function update_right_now_message() {
 359      $theme_name = wp_get_theme();
 360  
 361      if ( current_user_can( 'switch_themes' ) ) {
 362          $theme_name = sprintf( '<a href="themes.php">%1$s</a>', $theme_name );
 363      }
 364  
 365      /* translators: 1: Version number, 2: Theme name. */
 366      $content = __( 'WordPress %1$s running %2$s theme.' );
 367  
 368      /**
 369       * Filters the text displayed in the 'At a Glance' dashboard widget.
 370       *
 371       * Prior to 3.8.0, the widget was named 'Right Now'.
 372       *
 373       * @since 4.4.0
 374       *
 375       * @param string $content Default text.
 376       */
 377      $content = apply_filters( 'update_right_now_text', $content );
 378  
 379      $msg = sprintf( '<span id="wp-version">' . $content . '</span>', get_bloginfo( 'version', 'display' ), $theme_name );
 380  
 381      if ( current_user_can( 'update_core' ) ) {
 382          $cur = get_preferred_from_update_core();
 383  
 384          if ( isset( $cur->response ) && 'upgrade' === $cur->response ) {
 385              $msg .= sprintf(
 386                  '<a href="%s" class="button" aria-describedby="wp-version">%s</a>',
 387                  network_admin_url( 'update-core.php' ),
 388                  sprintf(
 389                      /* translators: %s: WordPress version number, or 'Latest' string. */
 390                      __( 'Update to %s' ),
 391                      $cur->current ? $cur->current : __( 'Latest' )
 392                  )
 393              );
 394          }
 395      }
 396  
 397      echo "<p id='wp-version-message'>$msg</p>";
 398  }
 399  
 400  /**
 401   * Retrieves plugins with updates available.
 402   *
 403   * @since 2.9.0
 404   *
 405   * @return array<string, object> Array of plugin objects with available updates.
 406   */
 407  function get_plugin_updates() {
 408      $all_plugins     = get_plugins();
 409      $upgrade_plugins = array();
 410      $current         = get_site_transient( 'update_plugins' );
 411  
 412      foreach ( (array) $all_plugins as $plugin_file => $plugin_data ) {
 413          if ( isset( $current->response[ $plugin_file ] ) ) {
 414              $upgrade_plugins[ $plugin_file ]         = (object) $plugin_data;
 415              $upgrade_plugins[ $plugin_file ]->update = $current->response[ $plugin_file ];
 416          }
 417      }
 418  
 419      return $upgrade_plugins;
 420  }
 421  
 422  /**
 423   * Adds a callback to display update information for plugins with updates available.
 424   *
 425   * @since 2.9.0
 426   */
 427  function wp_plugin_update_rows() {
 428      if ( ! current_user_can( 'update_plugins' ) ) {
 429          return;
 430      }
 431  
 432      $plugins = get_site_transient( 'update_plugins' );
 433  
 434      if ( isset( $plugins->response ) && is_array( $plugins->response ) ) {
 435          $plugins = array_keys( $plugins->response );
 436  
 437          foreach ( $plugins as $plugin_file ) {
 438              add_action( "after_plugin_row_{$plugin_file}", 'wp_plugin_update_row', 10, 2 );
 439          }
 440      }
 441  }
 442  
 443  /**
 444   * Displays update information for a plugin.
 445   *
 446   * @since 2.3.0
 447   *
 448   * @param string $file        Plugin basename.
 449   * @param array  $plugin_data Plugin information.
 450   * @return void|false Void on success, false if the plugin update is not available.
 451   */
 452  function wp_plugin_update_row( $file, $plugin_data ) {
 453      $current = get_site_transient( 'update_plugins' );
 454  
 455      if ( ! isset( $current->response[ $file ] ) ) {
 456          return false;
 457      }
 458  
 459      $response = $current->response[ $file ];
 460  
 461      $plugins_allowedtags = array(
 462          'a'       => array(
 463              'href'  => array(),
 464              'title' => array(),
 465          ),
 466          'abbr'    => array( 'title' => array() ),
 467          'acronym' => array( 'title' => array() ),
 468          'code'    => array(),
 469          'em'      => array(),
 470          'strong'  => array(),
 471      );
 472  
 473      $plugin_name = wp_kses( $plugin_data['Name'], $plugins_allowedtags );
 474      $plugin_slug = $response->slug ?? $response->id;
 475  
 476      if ( isset( $response->slug ) ) {
 477          $details_url = self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_slug . '&section=changelog' );
 478      } elseif ( isset( $response->url ) ) {
 479          $details_url = $response->url;
 480      } else {
 481          $details_url = $plugin_data['PluginURI'];
 482      }
 483  
 484      $details_url = add_query_arg(
 485          array(
 486              'TB_iframe' => 'true',
 487              'width'     => 600,
 488              'height'    => 800,
 489          ),
 490          $details_url
 491      );
 492  
 493      /** @var WP_Plugins_List_Table $wp_list_table */
 494      $wp_list_table = _get_list_table(
 495          'WP_Plugins_List_Table',
 496          array(
 497              'screen' => get_current_screen(),
 498          )
 499      );
 500  
 501      if ( is_network_admin() || ! is_multisite() ) {
 502          if ( is_network_admin() ) {
 503              $active_class = is_plugin_active_for_network( $file ) ? ' active' : '';
 504          } else {
 505              $active_class = is_plugin_active( $file ) ? ' active' : '';
 506          }
 507  
 508          $requires_php   = $response->requires_php ?? null;
 509          $compatible_php = is_php_version_compatible( $requires_php );
 510          $notice_type    = $compatible_php ? 'notice-warning' : 'notice-error';
 511  
 512          printf(
 513              '<tr class="plugin-update-tr%s" id="%s" data-slug="%s" data-plugin="%s">' .
 514              '<td colspan="%s" class="plugin-update colspanchange">' .
 515              '<div class="update-message notice inline %s notice-alt"><p>',
 516              $active_class,
 517              esc_attr( $plugin_slug . '-update' ),
 518              esc_attr( $plugin_slug ),
 519              esc_attr( $file ),
 520              esc_attr( $wp_list_table->get_column_count() ),
 521              $notice_type
 522          );
 523  
 524          if ( ! current_user_can( 'update_plugins' ) ) {
 525              printf(
 526                  /* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number. */
 527                  __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ),
 528                  $plugin_name,
 529                  esc_url( $details_url ),
 530                  sprintf(
 531                      'class="thickbox open-plugin-details-modal" aria-label="%s"',
 532                      /* translators: 1: Plugin name, 2: Version number. */
 533                      esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
 534                  ),
 535                  esc_attr( $response->new_version )
 536              );
 537          } elseif ( empty( $response->package ) ) {
 538              printf(
 539                  /* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number. */
 540                  __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this plugin.</em>' ),
 541                  $plugin_name,
 542                  esc_url( $details_url ),
 543                  sprintf(
 544                      'class="thickbox open-plugin-details-modal" aria-label="%s"',
 545                      /* translators: 1: Plugin name, 2: Version number. */
 546                      esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
 547                  ),
 548                  esc_attr( $response->new_version )
 549              );
 550          } else {
 551              if ( $compatible_php ) {
 552                  printf(
 553                      /* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number, 5: Update URL, 6: Additional link attributes. */
 554                      __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ),
 555                      $plugin_name,
 556                      esc_url( $details_url ),
 557                      sprintf(
 558                          'class="thickbox open-plugin-details-modal" aria-label="%s"',
 559                          /* translators: 1: Plugin name, 2: Version number. */
 560                          esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
 561                      ),
 562                      esc_attr( $response->new_version ),
 563                      wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $file, 'upgrade-plugin_' . $file ),
 564                      sprintf(
 565                          'class="update-link" aria-label="%s"',
 566                          /* translators: %s: Plugin name. */
 567                          esc_attr( sprintf( _x( 'Update %s now', 'plugin' ), $plugin_name ) )
 568                      )
 569                  );
 570              } else {
 571                  printf(
 572                      /* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number 5: URL to Update PHP page. */
 573                      __( 'There is a new version of %1$s available, but it does not work with your version of PHP. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s">learn more about updating PHP</a>.' ),
 574                      $plugin_name,
 575                      esc_url( $details_url ),
 576                      sprintf(
 577                          'class="thickbox open-plugin-details-modal" aria-label="%s"',
 578                          /* translators: 1: Plugin name, 2: Version number. */
 579                          esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
 580                      ),
 581                      esc_attr( $response->new_version ),
 582                      esc_url( wp_get_update_php_url() )
 583                  );
 584                  wp_update_php_annotation( '<br><em>', '</em>' );
 585              }
 586          }
 587  
 588          /**
 589           * Fires at the end of the update message container in each
 590           * row of the plugins list table.
 591           *
 592           * The dynamic portion of the hook name, `$file`, refers to the path
 593           * of the plugin's primary file relative to the plugins directory.
 594           *
 595           * @since 2.8.0
 596           *
 597           * @param array  $plugin_data An array of plugin metadata. See get_plugin_data()
 598           *                            and the {@see 'plugin_row_meta'} filter for the list
 599           *                            of possible values.
 600           * @param object $response {
 601           *     An object of metadata about the available plugin update.
 602           *
 603           *     @type string   $id           Plugin ID, e.g. `w.org/plugins/[plugin-name]`.
 604           *     @type string   $slug         Plugin slug.
 605           *     @type string   $plugin       Plugin basename.
 606           *     @type string   $new_version  New plugin version.
 607           *     @type string   $url          Plugin URL.
 608           *     @type string   $package      Plugin update package URL.
 609           *     @type string[] $icons        An array of plugin icon URLs.
 610           *     @type string[] $banners      An array of plugin banner URLs.
 611           *     @type string[] $banners_rtl  An array of plugin RTL banner URLs.
 612           *     @type string   $requires     The version of WordPress which the plugin requires.
 613           *     @type string   $tested       The version of WordPress the plugin is tested against.
 614           *     @type string   $requires_php The version of PHP which the plugin requires.
 615           * }
 616           */
 617          do_action( "in_plugin_update_message-{$file}", $plugin_data, $response ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 618  
 619          echo '</p></div></td></tr>';
 620      }
 621  }
 622  
 623  /**
 624   * Retrieves themes with updates available.
 625   *
 626   * @since 2.9.0
 627   *
 628   * @return array<string, WP_Theme> Array of theme objects with available updates.
 629   */
 630  function get_theme_updates() {
 631      $current = get_site_transient( 'update_themes' );
 632  
 633      if ( ! isset( $current->response ) ) {
 634          return array();
 635      }
 636  
 637      $update_themes = array();
 638  
 639      foreach ( $current->response as $stylesheet => $data ) {
 640          $update_themes[ $stylesheet ]         = wp_get_theme( $stylesheet );
 641          $update_themes[ $stylesheet ]->update = $data;
 642      }
 643  
 644      return $update_themes;
 645  }
 646  
 647  /**
 648   * Gets plugin names for translation updates.
 649   *
 650   * @since 7.2.0
 651   *
 652   * @return string[] Plugin names keyed by plugin file, directory, basename, and slug.
 653   */
 654  function wp_get_translation_update_plugin_names() {
 655      require_once  ABSPATH . 'wp-admin/includes/plugin.php';
 656  
 657      $plugin_names  = array();
 658      $all_plugins   = get_plugins();
 659      $plugin_update = get_site_transient( 'update_plugins' );
 660  
 661      if ( is_object( $plugin_update ) ) {
 662          $plugin_updates = array();
 663  
 664          if ( ! empty( $plugin_update->response ) && is_array( $plugin_update->response ) ) {
 665              $plugin_updates = array_merge( $plugin_updates, $plugin_update->response );
 666          }
 667  
 668          if ( ! empty( $plugin_update->no_update ) && is_array( $plugin_update->no_update ) ) {
 669              $plugin_updates = array_merge( $plugin_updates, $plugin_update->no_update );
 670          }
 671  
 672          foreach ( $plugin_updates as $plugin_file => $plugin_data ) {
 673              $plugin_data = (object) $plugin_data;
 674  
 675              if ( ! empty( $plugin_data->slug ) && ! empty( $all_plugins[ $plugin_file ]['Name'] ) ) {
 676                  $plugin_names[ $plugin_data->slug ] = $all_plugins[ $plugin_file ]['Name'];
 677              }
 678          }
 679      }
 680  
 681      foreach ( $all_plugins as $plugin_file => $plugin_data ) {
 682          $plugin_basename = dirname( $plugin_file );
 683  
 684          if ( isset( $plugin_data['Name'] ) ) {
 685              $plugin_names[ $plugin_file ]                     = $plugin_data['Name'];
 686              $plugin_names[ basename( $plugin_file, '.php' ) ] = $plugin_data['Name'];
 687  
 688              if ( '.' !== $plugin_basename ) {
 689                  $plugin_names[ $plugin_basename ] = $plugin_data['Name'];
 690              }
 691          }
 692      }
 693  
 694      return $plugin_names;
 695  }
 696  
 697  /**
 698   * Gets the display name for a translation update.
 699   *
 700   * @since 7.2.0
 701   *
 702   * @param object        $update       Translation update object.
 703   * @param string[]|null $plugin_names Optional. Plugin names keyed by plugin file, directory,
 704   *                                    basename, and slug. Default null.
 705   * @return string The translation update name.
 706   */
 707  function wp_get_translation_update_name( $update, $plugin_names = null ) {
 708      $type = isset( $update->type ) ? $update->type : '';
 709      $slug = isset( $update->slug ) ? $update->slug : '';
 710  
 711      switch ( $type ) {
 712          case 'core':
 713              return 'WordPress'; // Not translated.
 714  
 715          case 'theme':
 716              $theme = wp_get_theme( $slug );
 717              if ( $theme->exists() ) {
 718                  return $theme->get( 'Name' );
 719              }
 720              break;
 721  
 722          case 'plugin':
 723              if ( null === $plugin_names ) {
 724                  $plugin_names = wp_get_translation_update_plugin_names();
 725              }
 726  
 727              if ( ! empty( $plugin_names[ $slug ] ) ) {
 728                  return $plugin_names[ $slug ];
 729              }
 730              break;
 731      }
 732  
 733      return $slug;
 734  }
 735  
 736  /**
 737   * Gets the display language for a translation update.
 738   *
 739   * @since 7.2.0
 740   *
 741   * @param string $locale Translation update locale.
 742   * @return string The translation update language.
 743   */
 744  function wp_get_translation_update_language( $locale ) {
 745      $translations = get_site_transient( 'available_translations' );
 746  
 747      if ( is_array( $translations ) && ! empty( $translations[ $locale ]['native_name'] ) ) {
 748          return sprintf(
 749              /* translators: 1: Native language name, 2: Locale. */
 750              __( '%1$s (%2$s)' ),
 751              $translations[ $locale ]['native_name'],
 752              $locale
 753          );
 754      }
 755  
 756      return $locale;
 757  }
 758  
 759  /**
 760   * Gets display data for available translation updates.
 761   *
 762   * @since 7.2.0
 763   *
 764   * @return array[] {
 765   *     An array of translation update display data.
 766   *
 767   *     @type bool   $checked       Whether the translation update is selected for installation.
 768   *     @type bool   $deferred      Whether the translation update has been deferred.
 769   *     @type string $id            Translation update identifier.
 770   *     @type string $language      Translation update language.
 771   *     @type string $language_code Translation update locale.
 772   *     @type string $name          Translation update name.
 773   *     @type string $slug          Translation update slug.
 774   *     @type string $type          Translation update type.
 775   *     @type string $version       Translation update version.
 776   * }
 777   */
 778  function wp_get_translation_update_data() {
 779      $available_updates            = wp_get_translation_updates();
 780      $deferred_translation_updates = wp_get_deferred_translation_updates( $available_updates );
 781      $plugin_names                 = null;
 782      $translation_updates          = array();
 783  
 784      foreach ( $available_updates as $update ) {
 785          $translation_update_id = wp_get_translation_update_id( $update );
 786          $language              = isset( $update->language ) ? $update->language : '';
 787          $type                  = isset( $update->type ) ? $update->type : '';
 788          $deferred              = isset( $deferred_translation_updates[ $translation_update_id ] );
 789  
 790          if ( 'plugin' === $type && null === $plugin_names ) {
 791              $plugin_names = wp_get_translation_update_plugin_names();
 792          }
 793  
 794          $translation_updates[] = array(
 795              'checked'       => ! $deferred,
 796              'deferred'      => $deferred,
 797              'id'            => $translation_update_id,
 798              'language'      => wp_get_translation_update_language( $language ),
 799              'language_code' => $language,
 800              'name'          => wp_get_translation_update_name( $update, $plugin_names ),
 801              'slug'          => isset( $update->slug ) ? $update->slug : '',
 802              'type'          => $type,
 803              'version'       => isset( $update->version ) ? $update->version : '',
 804          );
 805      }
 806  
 807      return $translation_updates;
 808  }
 809  
 810  /**
 811   * Processes a translation update selection and stores the deferred updates.
 812   *
 813   * Only currently available updates included in the submitted form can be selected
 814   * or deferred. Previously deferred updates outside the form remain deferred, while
 815   * newly available updates outside the form are left unchanged.
 816   *
 817   * The caller must check capabilities and the nonce before calling this function.
 818   *
 819   * @since 7.2.0
 820   *
 821   * @param string[] $translation_update_ids          Sanitized identifiers of updates included in the form.
 822   * @param string[] $selected_translation_update_ids Sanitized identifiers of selected updates.
 823   * @return object[]|false Selected current translation updates keyed by identifier, an empty array
 824   *                        if all updates in the form were deferred, or false if the form contains
 825   *                        no currently available updates. On false, stored deferrals are unchanged.
 826   */
 827  function wp_process_translation_update_selection( $translation_update_ids, $selected_translation_update_ids ) {
 828      if ( empty( $translation_update_ids ) ) {
 829          return false;
 830      }
 831  
 832      $current_translation_updates = wp_get_translation_updates_by_id();
 833      $translation_updates         = array_intersect_key( $current_translation_updates, array_flip( $translation_update_ids ) );
 834  
 835      if ( empty( $translation_updates ) ) {
 836          return false;
 837      }
 838  
 839      $selected_translation_updates  = array_intersect_key( $translation_updates, array_flip( $selected_translation_update_ids ) );
 840      $deferred_translation_updates  = array_intersect_key(
 841          $current_translation_updates,
 842          wp_get_deferred_translation_updates()
 843      );
 844      $deferred_translation_updates  = array_diff_key( $deferred_translation_updates, $translation_updates );
 845      $deferred_translation_updates += array_diff_key( $translation_updates, $selected_translation_updates );
 846  
 847      wp_set_deferred_translation_updates( $deferred_translation_updates );
 848  
 849      return $selected_translation_updates;
 850  }
 851  
 852  /**
 853   * Adds a callback to display update information for themes with updates available.
 854   *
 855   * @since 3.1.0
 856   */
 857  function wp_theme_update_rows() {
 858      if ( ! current_user_can( 'update_themes' ) ) {
 859          return;
 860      }
 861  
 862      $themes = get_site_transient( 'update_themes' );
 863  
 864      if ( isset( $themes->response ) && is_array( $themes->response ) ) {
 865          $themes = array_keys( $themes->response );
 866  
 867          foreach ( $themes as $theme ) {
 868              add_action( "after_theme_row_{$theme}", 'wp_theme_update_row', 10, 2 );
 869          }
 870      }
 871  }
 872  
 873  /**
 874   * Displays update information for a theme.
 875   *
 876   * @since 3.1.0
 877   *
 878   * @param string   $theme_key Theme stylesheet.
 879   * @param WP_Theme $theme     Theme object.
 880   * @return void|false Void on success, false if the theme update is not available.
 881   */
 882  function wp_theme_update_row( $theme_key, $theme ) {
 883      $current = get_site_transient( 'update_themes' );
 884  
 885      if ( ! isset( $current->response[ $theme_key ] ) ) {
 886          return false;
 887      }
 888  
 889      $response = $current->response[ $theme_key ];
 890  
 891      $details_url = add_query_arg(
 892          array(
 893              'TB_iframe' => 'true',
 894              'width'     => 1024,
 895              'height'    => 800,
 896          ),
 897          $current->response[ $theme_key ]['url']
 898      );
 899  
 900      /** @var WP_MS_Themes_List_Table $wp_list_table */
 901      $wp_list_table = _get_list_table( 'WP_MS_Themes_List_Table' );
 902  
 903      $active = $theme->is_allowed( 'network' ) ? ' active' : '';
 904  
 905      $requires_wp  = $response['requires'] ?? null;
 906      $requires_php = $response['requires_php'] ?? null;
 907  
 908      $compatible_wp  = is_wp_version_compatible( $requires_wp );
 909      $compatible_php = is_php_version_compatible( $requires_php );
 910  
 911      printf(
 912          '<tr class="plugin-update-tr%s" id="%s" data-slug="%s">' .
 913          '<td colspan="%s" class="plugin-update colspanchange">' .
 914          '<div class="update-message notice inline notice-warning notice-alt"><p>',
 915          $active,
 916          esc_attr( $theme->get_stylesheet() . '-update' ),
 917          esc_attr( $theme->get_stylesheet() ),
 918          $wp_list_table->get_column_count()
 919      );
 920  
 921      if ( $compatible_wp && $compatible_php ) {
 922          if ( ! current_user_can( 'update_themes' ) ) {
 923              printf(
 924                  /* translators: 1: Theme name, 2: Details URL, 3: Additional link attributes, 4: Version number. */
 925                  __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ),
 926                  $theme['Name'],
 927                  esc_url( $details_url ),
 928                  sprintf(
 929                      'class="thickbox open-plugin-details-modal" aria-label="%s"',
 930                      /* translators: 1: Theme name, 2: Version number. */
 931                      esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
 932                  ),
 933                  $response['new_version']
 934              );
 935          } elseif ( empty( $response['package'] ) ) {
 936              printf(
 937                  /* translators: 1: Theme name, 2: Details URL, 3: Additional link attributes, 4: Version number. */
 938                  __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ),
 939                  $theme['Name'],
 940                  esc_url( $details_url ),
 941                  sprintf(
 942                      'class="thickbox open-plugin-details-modal" aria-label="%s"',
 943                      /* translators: 1: Theme name, 2: Version number. */
 944                      esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
 945                  ),
 946                  $response['new_version']
 947              );
 948          } else {
 949              printf(
 950                  /* translators: 1: Theme name, 2: Details URL, 3: Additional link attributes, 4: Version number, 5: Update URL, 6: Additional link attributes. */
 951                  __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ),
 952                  $theme['Name'],
 953                  esc_url( $details_url ),
 954                  sprintf(
 955                      'class="thickbox open-plugin-details-modal" aria-label="%s"',
 956                      /* translators: 1: Theme name, 2: Version number. */
 957                      esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
 958                  ),
 959                  $response['new_version'],
 960                  wp_nonce_url( self_admin_url( 'update.php?action=upgrade-theme&theme=' ) . $theme_key, 'upgrade-theme_' . $theme_key ),
 961                  sprintf(
 962                      'class="update-link" aria-label="%s"',
 963                      /* translators: %s: Theme name. */
 964                      esc_attr( sprintf( _x( 'Update %s now', 'theme' ), $theme['Name'] ) )
 965                  )
 966              );
 967          }
 968      } else {
 969          if ( ! $compatible_wp && ! $compatible_php ) {
 970              printf(
 971                  /* translators: %s: Theme name. */
 972                  __( 'There is a new version of %s available, but it does not work with your versions of WordPress and PHP.' ),
 973                  $theme['Name']
 974              );
 975              if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
 976                  printf(
 977                      /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
 978                      ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
 979                      self_admin_url( 'update-core.php' ),
 980                      esc_url( wp_get_update_php_url() )
 981                  );
 982                  wp_update_php_annotation( '</p><p><em>', '</em>' );
 983              } elseif ( current_user_can( 'update_core' ) ) {
 984                  printf(
 985                      /* translators: %s: URL to WordPress Updates screen. */
 986                      ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
 987                      self_admin_url( 'update-core.php' )
 988                  );
 989              } elseif ( current_user_can( 'update_php' ) ) {
 990                  printf(
 991                      /* translators: %s: URL to Update PHP page. */
 992                      ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
 993                      esc_url( wp_get_update_php_url() )
 994                  );
 995                  wp_update_php_annotation( '</p><p><em>', '</em>' );
 996              }
 997          } elseif ( ! $compatible_wp ) {
 998              printf(
 999                  /* translators: %s: Theme name. */
1000                  __( 'There is a new version of %s available, but it does not work with your version of WordPress.' ),
1001                  $theme['Name']
1002              );
1003              if ( current_user_can( 'update_core' ) ) {
1004                  printf(
1005                      /* translators: %s: URL to WordPress Updates screen. */
1006                      ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
1007                      self_admin_url( 'update-core.php' )
1008                  );
1009              }
1010          } elseif ( ! $compatible_php ) {
1011              printf(
1012                  /* translators: %s: Theme name. */
1013                  __( 'There is a new version of %s available, but it does not work with your version of PHP.' ),
1014                  $theme['Name']
1015              );
1016              if ( current_user_can( 'update_php' ) ) {
1017                  printf(
1018                      /* translators: %s: URL to Update PHP page. */
1019                      ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
1020                      esc_url( wp_get_update_php_url() )
1021                  );
1022                  wp_update_php_annotation( '</p><p><em>', '</em>' );
1023              }
1024          }
1025      }
1026  
1027      /**
1028       * Fires at the end of the update message container in each
1029       * row of the themes list table.
1030       *
1031       * The dynamic portion of the hook name, `$theme_key`, refers to
1032       * the theme slug as found in the WordPress.org themes repository.
1033       *
1034       * @since 3.1.0
1035       *
1036       * @param WP_Theme $theme    The WP_Theme object.
1037       * @param array    $response {
1038       *     An array of metadata about the available theme update.
1039       *
1040       *     @type string $new_version New theme version.
1041       *     @type string $url         Theme URL.
1042       *     @type string $package     Theme update package URL.
1043       * }
1044       */
1045      do_action( "in_theme_update_message-{$theme_key}", $theme, $response ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1046  
1047      echo '</p></div></td></tr>';
1048  }
1049  
1050  /**
1051   * Displays maintenance nag HTML message.
1052   *
1053   * @since 2.7.0
1054   *
1055   * @global int $upgrading
1056   *
1057   * @return void|false Void on success, false if the maintenance nag should not be displayed.
1058   */
1059  function maintenance_nag() {
1060      global $upgrading;
1061  
1062      $nag = isset( $upgrading );
1063  
1064      if ( ! $nag ) {
1065          $failed = get_site_option( 'auto_core_update_failed' );
1066          /*
1067           * If an update failed critically, we may have copied over version.php but not other files.
1068           * In that case, if the installation claims we're running the version we attempted, nag.
1069           * This is serious enough to err on the side of nagging.
1070           *
1071           * If we simply failed to update before we tried to copy any files, then assume things are
1072           * OK if they are now running the latest.
1073           *
1074           * This flag is cleared whenever a successful update occurs using Core_Upgrader.
1075           */
1076          $comparison = ! empty( $failed['critical'] ) ? '>=' : '>';
1077          if ( isset( $failed['attempted'] ) && version_compare( $failed['attempted'], wp_get_wp_version(), $comparison ) ) {
1078              $nag = true;
1079          }
1080      }
1081  
1082      if ( ! $nag ) {
1083          return false;
1084      }
1085  
1086      if ( current_user_can( 'update_core' ) ) {
1087          $msg = sprintf(
1088              /* translators: %s: URL to WordPress Updates screen. */
1089              __( 'An automated WordPress update has failed to complete - <a href="%s">please attempt the update again now</a>.' ),
1090              'update-core.php'
1091          );
1092      } else {
1093          $msg = __( 'An automated WordPress update has failed to complete! Please notify the site administrator.' );
1094      }
1095  
1096      wp_admin_notice(
1097          $msg,
1098          array(
1099              'type'               => 'warning',
1100              'additional_classes' => array( 'update-nag', 'inline' ),
1101              'paragraph_wrap'     => false,
1102          )
1103      );
1104  }
1105  
1106  /**
1107   * Prints the JavaScript templates for update admin notices.
1108   *
1109   * @since 4.6.0
1110   *
1111   * Template takes one argument with four values:
1112   *
1113   *     param {object} data {
1114   *         Arguments for admin notice.
1115   *
1116   *         @type string id        ID of the notice.
1117   *         @type string className Class names for the notice.
1118   *         @type string message   The notice's message.
1119   *         @type string type      The type of update the notice is for. Either 'plugin' or 'theme'.
1120   *     }
1121   */
1122  function wp_print_admin_notice_templates() {
1123      ?>
1124      <script id="tmpl-wp-updates-admin-notice" type="text/html">
1125          <div <# if ( data.id ) { #>id="{{ data.id }}"<# } #> class="notice {{ data.className }}"><p>{{{ data.message }}}</p></div>
1126      </script>
1127      <script id="tmpl-wp-bulk-updates-admin-notice" type="text/html">
1128          <div id="{{ data.id }}" class="{{ data.className }} notice <# if ( data.errorMessage ) { #>notice-error<# } else { #>notice-success<# } #>">
1129              <p>
1130                  <# if ( data.successMessage ) { #>
1131                      {{{ data.successMessage }}}
1132                  <# } #>
1133                  <# if ( data.errorMessage ) { #>
1134                      <button class="button-link bulk-action-errors-collapsed" aria-expanded="false">
1135                          {{{ data.errorMessage }}}
1136                          <span class="screen-reader-text">
1137                              <?php
1138                              /* translators: Hidden accessibility text. */
1139                              _e( 'Show more details' );
1140                              ?>
1141                          </span>
1142                          <span class="toggle-indicator" aria-hidden="true"></span>
1143                      </button>
1144                  <# } #>
1145              </p>
1146              <# if ( data.errorMessages ) { #>
1147                  <ul class="bulk-action-errors hidden">
1148                      <# _.each( data.errorMessages, function( errorMessage ) { #>
1149                          <li>{{ errorMessage }}</li>
1150                      <# } ); #>
1151                  </ul>
1152              <# } #>
1153          </div>
1154      </script>
1155      <?php
1156  }
1157  
1158  /**
1159   * Prints the JavaScript templates for update and deletion rows in list tables.
1160   *
1161   * @since 4.6.0
1162   *
1163   * The update template takes one argument with four values:
1164   *
1165   *     param {object} data {
1166   *         Arguments for the update row
1167   *
1168   *         @type string slug    Plugin slug.
1169   *         @type string plugin  Plugin base name.
1170   *         @type string colspan The number of table columns this row spans.
1171   *         @type string content The row content.
1172   *     }
1173   *
1174   * The delete template takes one argument with four values:
1175   *
1176   *     param {object} data {
1177   *         Arguments for the update row
1178   *
1179   *         @type string slug    Plugin slug.
1180   *         @type string plugin  Plugin base name.
1181   *         @type string name    Plugin name.
1182   *         @type string colspan The number of table columns this row spans.
1183   *     }
1184   */
1185  function wp_print_update_row_templates() {
1186      ?>
1187      <script id="tmpl-item-update-row" type="text/template">
1188          <tr class="plugin-update-tr update" id="{{ data.slug }}-update" data-slug="{{ data.slug }}" <# if ( data.plugin ) { #>data-plugin="{{ data.plugin }}"<# } #>>
1189              <td colspan="{{ data.colspan }}" class="plugin-update colspanchange">
1190                  {{{ data.content }}}
1191              </td>
1192          </tr>
1193      </script>
1194      <script id="tmpl-item-deleted-row" type="text/template">
1195          <tr class="plugin-deleted-tr inactive deleted" id="{{ data.slug }}-deleted" data-slug="{{ data.slug }}" <# if ( data.plugin ) { #>data-plugin="{{ data.plugin }}"<# } #>>
1196              <td colspan="{{ data.colspan }}" class="plugin-update colspanchange">
1197                  <# if ( data.plugin ) { #>
1198                      <?php
1199                      printf(
1200                          /* translators: %s: Plugin name. */
1201                          _x( '%s was successfully deleted.', 'plugin' ),
1202                          '<strong>{{{ data.name }}}</strong>'
1203                      );
1204                      ?>
1205                  <# } else { #>
1206                      <?php
1207                      printf(
1208                          /* translators: %s: Theme name. */
1209                          _x( '%s was successfully deleted.', 'theme' ),
1210                          '<strong>{{{ data.name }}}</strong>'
1211                      );
1212                      ?>
1213                  <# } #>
1214              </td>
1215          </tr>
1216      </script>
1217      <?php
1218  }
1219  
1220  /**
1221   * Displays a notice when the user is in recovery mode.
1222   *
1223   * @since 5.2.0
1224   */
1225  function wp_recovery_mode_nag() {
1226      if ( ! wp_is_recovery_mode() ) {
1227          return;
1228      }
1229  
1230      $url = wp_login_url();
1231      $url = add_query_arg( 'action', WP_Recovery_Mode::EXIT_ACTION, $url );
1232      $url = wp_nonce_url( $url, WP_Recovery_Mode::EXIT_ACTION );
1233  
1234      $message = sprintf(
1235          /* translators: %s: Recovery Mode exit link. */
1236          __( 'You are in recovery mode. This means there may be an error with a theme or plugin. To exit recovery mode, log out or use the Exit button. <a href="%s">Exit Recovery Mode</a>' ),
1237          esc_url( $url )
1238      );
1239      wp_admin_notice( $message, array( 'type' => 'info' ) );
1240  }
1241  
1242  /**
1243   * Checks whether auto-updates are enabled.
1244   *
1245   * @since 5.5.0
1246   *
1247   * @param string $type The type of update being checked: Either 'theme' or 'plugin'.
1248   * @return bool True if auto-updates are enabled for `$type`, false otherwise.
1249   */
1250  function wp_is_auto_update_enabled_for_type( $type ) {
1251      if ( ! class_exists( 'WP_Automatic_Updater' ) ) {
1252          require_once  ABSPATH . 'wp-admin/includes/class-wp-automatic-updater.php';
1253      }
1254  
1255      $updater = new WP_Automatic_Updater();
1256      $enabled = ! $updater->is_disabled();
1257  
1258      switch ( $type ) {
1259          case 'plugin':
1260              /**
1261               * Filters whether plugins auto-update is enabled.
1262               *
1263               * @since 5.5.0
1264               *
1265               * @param bool $enabled True if plugins auto-update is enabled, false otherwise.
1266               */
1267              return apply_filters( 'plugins_auto_update_enabled', $enabled );
1268          case 'theme':
1269              /**
1270               * Filters whether themes auto-update is enabled.
1271               *
1272               * @since 5.5.0
1273               *
1274               * @param bool $enabled True if themes auto-update is enabled, false otherwise.
1275               */
1276              return apply_filters( 'themes_auto_update_enabled', $enabled );
1277      }
1278  
1279      return false;
1280  }
1281  
1282  /**
1283   * Checks whether auto-updates are forced for an item.
1284   *
1285   * @since 5.6.0
1286   *
1287   * @param string    $type   The type of update being checked: Either 'theme' or 'plugin'.
1288   * @param bool|null $update Whether to update. The value of null is internally used
1289   *                          to detect whether nothing has hooked into this filter.
1290   * @param object    $item   The update offer.
1291   * @return bool True if auto-updates are forced for `$item`, false otherwise.
1292   */
1293  function wp_is_auto_update_forced_for_item( $type, $update, $item ) {
1294      /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
1295      return apply_filters( "auto_update_{$type}", $update, $item );
1296  }
1297  
1298  /**
1299   * Determines the appropriate auto-update message to be displayed.
1300   *
1301   * @since 5.5.0
1302   * @since 7.2.0 Added the `$type` parameter. A message is now returned when
1303   *              automatic updates cannot run because the filesystem requires
1304   *              credentials or the site appears to be under version control.
1305   *
1306   * @param string $type Optional. The type of update the message is for: 'plugin' or 'theme'.
1307   *                     Determines which directory is checked. Default empty, which checks ABSPATH.
1308   * @return string The update message to be shown.
1309   */
1310  function wp_get_auto_update_message( $type = '' ) {
1311      // Loads Automatic_Upgrader_Skin and WP_Automatic_Updater.
1312      require_once  ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
1313  
1314      if ( ! function_exists( 'request_filesystem_credentials' ) ) {
1315          require_once  ABSPATH . 'wp-admin/includes/file.php';
1316      }
1317  
1318      switch ( $type ) {
1319          case 'plugin':
1320              $context = WP_PLUGIN_DIR;
1321              break;
1322          case 'theme':
1323              $context = get_theme_root();
1324              break;
1325          default:
1326              $context = ABSPATH;
1327      }
1328  
1329      /*
1330       * These mirror the checks in WP_Automatic_Updater::should_update(), which skips
1331       * the update regardless of the schedule if either one fails.
1332       */
1333      $skin    = new Automatic_Upgrader_Skin();
1334      $updater = new WP_Automatic_Updater();
1335  
1336      $message = '';
1337      if ( ! $skin->request_filesystem_credentials( false, $context ) ) {
1338          $message = __( 'Automatic update will not run because WordPress needs FTP credentials to update files.' );
1339      } elseif ( $updater->is_vcs_checkout( $context ) ) {
1340          $message = __( 'Automatic update will not run because this site appears to be under version control.' );
1341      }
1342  
1343      if ( $message ) {
1344          if ( current_user_can( 'view_site_health_checks' ) ) {
1345              $message .= ' ' . sprintf(
1346                  /* translators: %s: URL to the Site Health screen. */
1347                  __( '<a href="%s">Learn more in Site Health</a>.' ),
1348                  esc_url( admin_url( 'site-health.php' ) )
1349              );
1350          }
1351  
1352          return $message;
1353      }
1354  
1355      $next_update_time = wp_next_scheduled( 'wp_version_check' );
1356  
1357      // Check if the event exists.
1358      if ( false === $next_update_time ) {
1359          $message = __( 'Automatic update not scheduled. There may be a problem with WP-Cron.' );
1360      } else {
1361          $time_to_next_update = human_time_diff( (int) $next_update_time );
1362  
1363          // See if cron is overdue.
1364          $overdue = ( time() - $next_update_time ) > 0;
1365  
1366          if ( $overdue ) {
1367              $message = sprintf(
1368                  /* translators: %s: Duration that WP-Cron has been overdue. */
1369                  __( 'Automatic update overdue by %s. There may be a problem with WP-Cron.' ),
1370                  $time_to_next_update
1371              );
1372          } else {
1373              $message = sprintf(
1374                  /* translators: %s: Time until the next update. */
1375                  __( 'Automatic update scheduled in %s.' ),
1376                  $time_to_next_update
1377              );
1378          }
1379      }
1380  
1381      return $message;
1382  }


Generated : Sun Nov 29 08:20:01 2026 Cross-referenced by PHPXref