[ Index ]

PHP Cross Reference of WordPress

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|array|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      if ( ! is_array( $updates ) ) {
  19          return false;
  20      }
  21      if ( empty( $updates ) ) {
  22          return (object) array( 'response' => 'latest' );
  23      }
  24      return $updates[0];
  25  }
  26  
  27  /**
  28   * Gets available core updates.
  29   *
  30   * @since 2.7.0
  31   *
  32   * @param array $options Set $options['dismissed'] to true to show dismissed upgrades too,
  33   *                       set $options['available'] to false to skip not-dismissed updates.
  34   * @return array|false Array of the update objects on success, false on failure.
  35   */
  36  function get_core_updates( $options = array() ) {
  37      $options   = array_merge(
  38          array(
  39              'available' => true,
  40              'dismissed' => false,
  41          ),
  42          $options
  43      );
  44      $dismissed = get_site_option( 'dismissed_update_core' );
  45  
  46      if ( ! is_array( $dismissed ) ) {
  47          $dismissed = array();
  48      }
  49  
  50      $from_api = get_site_transient( 'update_core' );
  51  
  52      if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) {
  53          return false;
  54      }
  55  
  56      $updates = $from_api->updates;
  57      $result  = array();
  58      foreach ( $updates as $update ) {
  59          if ( 'autoupdate' === $update->response ) {
  60              continue;
  61          }
  62  
  63          if ( array_key_exists( $update->current . '|' . $update->locale, $dismissed ) ) {
  64              if ( $options['dismissed'] ) {
  65                  $update->dismissed = true;
  66                  $result[]          = $update;
  67              }
  68          } else {
  69              if ( $options['available'] ) {
  70                  $update->dismissed = false;
  71                  $result[]          = $update;
  72              }
  73          }
  74      }
  75      return $result;
  76  }
  77  
  78  /**
  79   * Gets the best available (and enabled) Auto-Update for WordPress core.
  80   *
  81   * 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.
  82   *
  83   * @since 3.7.0
  84   *
  85   * @return object|false The core update offering on success, false on failure.
  86   */
  87  function find_core_auto_update() {
  88      $updates = get_site_transient( 'update_core' );
  89      if ( ! $updates || empty( $updates->updates ) ) {
  90          return false;
  91      }
  92  
  93      require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
  94  
  95      $auto_update = false;
  96      $upgrader    = new WP_Automatic_Updater;
  97      foreach ( $updates->updates as $update ) {
  98          if ( 'autoupdate' !== $update->response ) {
  99              continue;
 100          }
 101  
 102          if ( ! $upgrader->should_update( 'core', $update, ABSPATH ) ) {
 103              continue;
 104          }
 105  
 106          if ( ! $auto_update || version_compare( $update->current, $auto_update->current, '>' ) ) {
 107              $auto_update = $update;
 108          }
 109      }
 110      return $auto_update;
 111  }
 112  
 113  /**
 114   * Gets and caches the checksums for the given version of WordPress.
 115   *
 116   * @since 3.7.0
 117   *
 118   * @param string $version Version string to query.
 119   * @param string $locale  Locale to query.
 120   * @return array|false An array of checksums on success, false on failure.
 121   */
 122  function get_core_checksums( $version, $locale ) {
 123      $http_url = 'http://api.wordpress.org/core/checksums/1.0/?' . http_build_query( compact( 'version', 'locale' ), null, '&' );
 124      $url      = $http_url;
 125  
 126      $ssl = wp_http_supports( array( 'ssl' ) );
 127      if ( $ssl ) {
 128          $url = set_url_scheme( $url, 'https' );
 129      }
 130  
 131      $options = array(
 132          'timeout' => wp_doing_cron() ? 30 : 3,
 133      );
 134  
 135      $response = wp_remote_get( $url, $options );
 136      if ( $ssl && is_wp_error( $response ) ) {
 137          trigger_error(
 138              sprintf(
 139                  /* translators: %s: Support forums URL. */
 140                  __( '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>.' ),
 141                  __( 'https://wordpress.org/support/forums/' )
 142              ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
 143              headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
 144          );
 145          $response = wp_remote_get( $http_url, $options );
 146      }
 147  
 148      if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
 149          return false;
 150      }
 151  
 152      $body = trim( wp_remote_retrieve_body( $response ) );
 153      $body = json_decode( $body, true );
 154  
 155      if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) ) {
 156          return false;
 157      }
 158  
 159      return $body['checksums'];
 160  }
 161  
 162  /**
 163   * Dismisses core update.
 164   *
 165   * @since 2.7.0
 166   *
 167   * @param object $update
 168   * @return bool
 169   */
 170  function dismiss_core_update( $update ) {
 171      $dismissed = get_site_option( 'dismissed_update_core' );
 172      $dismissed[ $update->current . '|' . $update->locale ] = true;
 173      return update_site_option( 'dismissed_update_core', $dismissed );
 174  }
 175  
 176  /**
 177   * Undismisses core update.
 178   *
 179   * @since 2.7.0
 180   *
 181   * @param string $version
 182   * @param string $locale
 183   * @return bool
 184   */
 185  function undismiss_core_update( $version, $locale ) {
 186      $dismissed = get_site_option( 'dismissed_update_core' );
 187      $key       = $version . '|' . $locale;
 188  
 189      if ( ! isset( $dismissed[ $key ] ) ) {
 190          return false;
 191      }
 192  
 193      unset( $dismissed[ $key ] );
 194      return update_site_option( 'dismissed_update_core', $dismissed );
 195  }
 196  
 197  /**
 198   * Finds the available update for WordPress core.
 199   *
 200   * @since 2.7.0
 201   *
 202   * @param string $version Version string to find the update for.
 203   * @param string $locale  Locale to find the update for.
 204   * @return object|false The core update offering on success, false on failure.
 205   */
 206  function find_core_update( $version, $locale ) {
 207      $from_api = get_site_transient( 'update_core' );
 208  
 209      if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) {
 210          return false;
 211      }
 212  
 213      $updates = $from_api->updates;
 214      foreach ( $updates as $update ) {
 215          if ( $update->current == $version && $update->locale == $locale ) {
 216              return $update;
 217          }
 218      }
 219      return false;
 220  }
 221  
 222  /**
 223   * @since 2.3.0
 224   *
 225   * @param string $msg
 226   * @return string
 227   */
 228  function core_update_footer( $msg = '' ) {
 229      if ( ! current_user_can( 'update_core' ) ) {
 230          /* translators: %s: WordPress version. */
 231          return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
 232      }
 233  
 234      $cur = get_preferred_from_update_core();
 235      if ( ! is_object( $cur ) ) {
 236          $cur = new stdClass;
 237      }
 238  
 239      if ( ! isset( $cur->current ) ) {
 240          $cur->current = '';
 241      }
 242  
 243      if ( ! isset( $cur->response ) ) {
 244          $cur->response = '';
 245      }
 246  
 247      // Include an unmodified $wp_version.
 248      require  ABSPATH . WPINC . '/version.php';
 249  
 250      $is_development_version = preg_match( '/alpha|beta|RC/', $wp_version );
 251  
 252      if ( $is_development_version && 'latest' === $cur->response ) {
 253          $cur->response = 'development';
 254      }
 255  
 256      switch ( $cur->response ) {
 257          case 'development':
 258              return sprintf(
 259                  /* translators: 1: WordPress version number, 2: URL to WordPress Updates screen. */
 260                  __( 'You are using a development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.' ),
 261                  get_bloginfo( 'version', 'display' ),
 262                  network_admin_url( 'update-core.php' )
 263              );
 264  
 265          case 'upgrade':
 266              return sprintf(
 267                  '<strong><a href="%s">%s</a></strong>',
 268                  network_admin_url( 'update-core.php' ),
 269                  /* translators: %s: WordPress version. */
 270                  sprintf( __( 'Get Version %s' ), $cur->current )
 271              );
 272  
 273          case 'latest':
 274          default:
 275              /* translators: %s: WordPress version. */
 276              return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
 277      }
 278  }
 279  
 280  /**
 281   * @since 2.3.0
 282   *
 283   * @global string $pagenow
 284   * @return void|false
 285   */
 286  function update_nag() {
 287      if ( is_multisite() && ! current_user_can( 'update_core' ) ) {
 288          return false;
 289      }
 290  
 291      global $pagenow;
 292  
 293      if ( 'update-core.php' === $pagenow ) {
 294          return;
 295      }
 296  
 297      $cur = get_preferred_from_update_core();
 298  
 299      if ( ! isset( $cur->response ) || 'upgrade' !== $cur->response ) {
 300          return false;
 301      }
 302  
 303      $version_url = sprintf(
 304          /* translators: %s: WordPress version. */
 305          esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
 306          sanitize_title( $cur->current )
 307      );
 308  
 309      if ( current_user_can( 'update_core' ) ) {
 310          $msg = sprintf(
 311              /* translators: 1: URL to WordPress release notes, 2: New WordPress version, 3: URL to network admin, 4: Accessibility text. */
 312              __( '<a href="%1$s">WordPress %2$s</a> is available! <a href="%3$s" aria-label="%4$s">Please update now</a>.' ),
 313              $version_url,
 314              $cur->current,
 315              network_admin_url( 'update-core.php' ),
 316              esc_attr__( 'Please update WordPress now' )
 317          );
 318      } else {
 319          $msg = sprintf(
 320              /* translators: 1: URL to WordPress release notes, 2: New WordPress version. */
 321              __( '<a href="%1$s">WordPress %2$s</a> is available! Please notify the site administrator.' ),
 322              $version_url,
 323              $cur->current
 324          );
 325      }
 326  
 327      echo "<div class='update-nag notice notice-warning inline'>$msg</div>";
 328  }
 329  
 330  /**
 331   * Displays WordPress version and active theme in the 'At a Glance' dashboard widget.
 332   *
 333   * @since 2.5.0
 334   */
 335  function update_right_now_message() {
 336      $theme_name = wp_get_theme();
 337      if ( current_user_can( 'switch_themes' ) ) {
 338          $theme_name = sprintf( '<a href="themes.php">%1$s</a>', $theme_name );
 339      }
 340  
 341      $msg = '';
 342  
 343      if ( current_user_can( 'update_core' ) ) {
 344          $cur = get_preferred_from_update_core();
 345  
 346          if ( isset( $cur->response ) && 'upgrade' === $cur->response ) {
 347              $msg .= sprintf(
 348                  '<a href="%s" class="button" aria-describedby="wp-version">%s</a> ',
 349                  network_admin_url( 'update-core.php' ),
 350                  /* translators: %s: WordPress version number, or 'Latest' string. */
 351                  sprintf( __( 'Update to %s' ), $cur->current ? $cur->current : __( 'Latest' ) )
 352              );
 353          }
 354      }
 355  
 356      /* translators: 1: Version number, 2: Theme name. */
 357      $content = __( 'WordPress %1$s running %2$s theme.' );
 358  
 359      /**
 360       * Filters the text displayed in the 'At a Glance' dashboard widget.
 361       *
 362       * Prior to 3.8.0, the widget was named 'Right Now'.
 363       *
 364       * @since 4.4.0
 365       *
 366       * @param string $content Default text.
 367       */
 368      $content = apply_filters( 'update_right_now_text', $content );
 369  
 370      $msg .= sprintf( '<span id="wp-version">' . $content . '</span>', get_bloginfo( 'version', 'display' ), $theme_name );
 371  
 372      echo "<p id='wp-version-message'>$msg</p>";
 373  }
 374  
 375  /**
 376   * @since 2.9.0
 377   *
 378   * @return array
 379   */
 380  function get_plugin_updates() {
 381      $all_plugins     = get_plugins();
 382      $upgrade_plugins = array();
 383      $current         = get_site_transient( 'update_plugins' );
 384      foreach ( (array) $all_plugins as $plugin_file => $plugin_data ) {
 385          if ( isset( $current->response[ $plugin_file ] ) ) {
 386              $upgrade_plugins[ $plugin_file ]         = (object) $plugin_data;
 387              $upgrade_plugins[ $plugin_file ]->update = $current->response[ $plugin_file ];
 388          }
 389      }
 390  
 391      return $upgrade_plugins;
 392  }
 393  
 394  /**
 395   * @since 2.9.0
 396   */
 397  function wp_plugin_update_rows() {
 398      if ( ! current_user_can( 'update_plugins' ) ) {
 399          return;
 400      }
 401  
 402      $plugins = get_site_transient( 'update_plugins' );
 403      if ( isset( $plugins->response ) && is_array( $plugins->response ) ) {
 404          $plugins = array_keys( $plugins->response );
 405          foreach ( $plugins as $plugin_file ) {
 406              add_action( "after_plugin_row_{$plugin_file}", 'wp_plugin_update_row', 10, 2 );
 407          }
 408      }
 409  }
 410  
 411  /**
 412   * Displays update information for a plugin.
 413   *
 414   * @since 2.3.0
 415   *
 416   * @param string $file        Plugin basename.
 417   * @param array  $plugin_data Plugin information.
 418   * @return void|false
 419   */
 420  function wp_plugin_update_row( $file, $plugin_data ) {
 421      $current = get_site_transient( 'update_plugins' );
 422      if ( ! isset( $current->response[ $file ] ) ) {
 423          return false;
 424      }
 425  
 426      $response = $current->response[ $file ];
 427  
 428      $plugins_allowedtags = array(
 429          'a'       => array(
 430              'href'  => array(),
 431              'title' => array(),
 432          ),
 433          'abbr'    => array( 'title' => array() ),
 434          'acronym' => array( 'title' => array() ),
 435          'code'    => array(),
 436          'em'      => array(),
 437          'strong'  => array(),
 438      );
 439  
 440      $plugin_name = wp_kses( $plugin_data['Name'], $plugins_allowedtags );
 441      $details_url = self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $response->slug . '&section=changelog&TB_iframe=true&width=600&height=800' );
 442  
 443      /** @var WP_Plugins_List_Table $wp_list_table */
 444      $wp_list_table = _get_list_table(
 445          'WP_Plugins_List_Table',
 446          array(
 447              'screen' => get_current_screen(),
 448          )
 449      );
 450  
 451      if ( is_network_admin() || ! is_multisite() ) {
 452          if ( is_network_admin() ) {
 453              $active_class = is_plugin_active_for_network( $file ) ? ' active' : '';
 454          } else {
 455              $active_class = is_plugin_active( $file ) ? ' active' : '';
 456          }
 457  
 458          $requires_php   = isset( $response->requires_php ) ? $response->requires_php : null;
 459          $compatible_php = is_php_version_compatible( $requires_php );
 460          $notice_type    = $compatible_php ? 'notice-warning' : 'notice-error';
 461  
 462          printf(
 463              '<tr class="plugin-update-tr%s" id="%s" data-slug="%s" data-plugin="%s">' .
 464              '<td colspan="%s" class="plugin-update colspanchange">' .
 465              '<div class="update-message notice inline %s notice-alt"><p>',
 466              $active_class,
 467              esc_attr( $response->slug . '-update' ),
 468              esc_attr( $response->slug ),
 469              esc_attr( $file ),
 470              esc_attr( $wp_list_table->get_column_count() ),
 471              $notice_type
 472          );
 473  
 474          if ( ! current_user_can( 'update_plugins' ) ) {
 475              printf(
 476                  /* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number. */
 477                  __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ),
 478                  $plugin_name,
 479                  esc_url( $details_url ),
 480                  sprintf(
 481                      'class="thickbox open-plugin-details-modal" aria-label="%s"',
 482                      /* translators: 1: Plugin name, 2: Version number. */
 483                      esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
 484                  ),
 485                  esc_attr( $response->new_version )
 486              );
 487          } elseif ( empty( $response->package ) ) {
 488              printf(
 489                  /* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number. */
 490                  __( '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>' ),
 491                  $plugin_name,
 492                  esc_url( $details_url ),
 493                  sprintf(
 494                      'class="thickbox open-plugin-details-modal" aria-label="%s"',
 495                      /* translators: 1: Plugin name, 2: Version number. */
 496                      esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
 497                  ),
 498                  esc_attr( $response->new_version )
 499              );
 500          } else {
 501              if ( $compatible_php ) {
 502                  printf(
 503                      /* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number, 5: Update URL, 6: Additional link attributes. */
 504                      __( '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>.' ),
 505                      $plugin_name,
 506                      esc_url( $details_url ),
 507                      sprintf(
 508                          'class="thickbox open-plugin-details-modal" aria-label="%s"',
 509                          /* translators: 1: Plugin name, 2: Version number. */
 510                          esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
 511                      ),
 512                      esc_attr( $response->new_version ),
 513                      wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $file, 'upgrade-plugin_' . $file ),
 514                      sprintf(
 515                          'class="update-link" aria-label="%s"',
 516                          /* translators: %s: Plugin name. */
 517                          esc_attr( sprintf( _x( 'Update %s now', 'plugin' ), $plugin_name ) )
 518                      )
 519                  );
 520              } else {
 521                  printf(
 522                      /* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number 5: URL to Update PHP page. */
 523                      __( 'There is a new version of %1$s available, but it doesn&#8217;t 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>.' ),
 524                      $plugin_name,
 525                      esc_url( $details_url ),
 526                      sprintf(
 527                          'class="thickbox open-plugin-details-modal" aria-label="%s"',
 528                          /* translators: 1: Plugin name, 2: Version number. */
 529                          esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
 530                      ),
 531                      esc_attr( $response->new_version ),
 532                      esc_url( wp_get_update_php_url() )
 533                  );
 534                  wp_update_php_annotation( '<br><em>', '</em>' );
 535              }
 536          }
 537  
 538          /**
 539           * Fires at the end of the update message container in each
 540           * row of the plugins list table.
 541           *
 542           * The dynamic portion of the hook name, `$file`, refers to the path
 543           * of the plugin's primary file relative to the plugins directory.
 544           *
 545           * @since 2.8.0
 546           *
 547           * @param array $plugin_data {
 548           *     An array of plugin metadata.
 549           *
 550           *     @type string $name        The human-readable name of the plugin.
 551           *     @type string $plugin_uri  Plugin URI.
 552           *     @type string $version     Plugin version.
 553           *     @type string $description Plugin description.
 554           *     @type string $author      Plugin author.
 555           *     @type string $author_uri  Plugin author URI.
 556           *     @type string $text_domain Plugin text domain.
 557           *     @type string $domain_path Relative path to the plugin's .mo file(s).
 558           *     @type bool   $network     Whether the plugin can only be activated network wide.
 559           *     @type string $title       The human-readable title of the plugin.
 560           *     @type string $author_name Plugin author's name.
 561           *     @type bool   $update      Whether there's an available update. Default null.
 562           * }
 563           * @param array $response {
 564           *     An array of metadata about the available plugin update.
 565           *
 566           *     @type int    $id          Plugin ID.
 567           *     @type string $slug        Plugin slug.
 568           *     @type string $new_version New plugin version.
 569           *     @type string $url         Plugin URL.
 570           *     @type string $package     Plugin update package URL.
 571           * }
 572           */
 573          do_action( "in_plugin_update_message-{$file}", $plugin_data, $response ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 574  
 575          echo '</p></div></td></tr>';
 576      }
 577  }
 578  
 579  /**
 580   * @since 2.9.0
 581   *
 582   * @return array
 583   */
 584  function get_theme_updates() {
 585      $current = get_site_transient( 'update_themes' );
 586  
 587      if ( ! isset( $current->response ) ) {
 588          return array();
 589      }
 590  
 591      $update_themes = array();
 592      foreach ( $current->response as $stylesheet => $data ) {
 593          $update_themes[ $stylesheet ]         = wp_get_theme( $stylesheet );
 594          $update_themes[ $stylesheet ]->update = $data;
 595      }
 596  
 597      return $update_themes;
 598  }
 599  
 600  /**
 601   * @since 3.1.0
 602   */
 603  function wp_theme_update_rows() {
 604      if ( ! current_user_can( 'update_themes' ) ) {
 605          return;
 606      }
 607  
 608      $themes = get_site_transient( 'update_themes' );
 609      if ( isset( $themes->response ) && is_array( $themes->response ) ) {
 610          $themes = array_keys( $themes->response );
 611  
 612          foreach ( $themes as $theme ) {
 613              add_action( "after_theme_row_{$theme}", 'wp_theme_update_row', 10, 2 );
 614          }
 615      }
 616  }
 617  
 618  /**
 619   * Displays update information for a theme.
 620   *
 621   * @since 3.1.0
 622   *
 623   * @param string   $theme_key Theme stylesheet.
 624   * @param WP_Theme $theme     Theme object.
 625   * @return void|false
 626   */
 627  function wp_theme_update_row( $theme_key, $theme ) {
 628      $current = get_site_transient( 'update_themes' );
 629  
 630      if ( ! isset( $current->response[ $theme_key ] ) ) {
 631          return false;
 632      }
 633  
 634      $response = $current->response[ $theme_key ];
 635  
 636      $details_url = add_query_arg(
 637          array(
 638              'TB_iframe' => 'true',
 639              'width'     => 1024,
 640              'height'    => 800,
 641          ),
 642          $current->response[ $theme_key ]['url']
 643      );
 644  
 645      /** @var WP_MS_Themes_List_Table $wp_list_table */
 646      $wp_list_table = _get_list_table( 'WP_MS_Themes_List_Table' );
 647  
 648      $active = $theme->is_allowed( 'network' ) ? ' active' : '';
 649  
 650      $requires_wp  = isset( $response['requires'] ) ? $response['requires'] : null;
 651      $requires_php = isset( $response['requires_php'] ) ? $response['requires_php'] : null;
 652  
 653      $compatible_wp  = is_wp_version_compatible( $requires_wp );
 654      $compatible_php = is_php_version_compatible( $requires_php );
 655  
 656      printf(
 657          '<tr class="plugin-update-tr%s" id="%s" data-slug="%s">' .
 658          '<td colspan="%s" class="plugin-update colspanchange">' .
 659          '<div class="update-message notice inline notice-warning notice-alt"><p>',
 660          $active,
 661          esc_attr( $theme->get_stylesheet() . '-update' ),
 662          esc_attr( $theme->get_stylesheet() ),
 663          $wp_list_table->get_column_count()
 664      );
 665  
 666      if ( $compatible_wp && $compatible_php ) {
 667          if ( ! current_user_can( 'update_themes' ) ) {
 668              printf(
 669                  /* translators: 1: Theme name, 2: Details URL, 3: Additional link attributes, 4: Version number. */
 670                  __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ),
 671                  $theme['Name'],
 672                  esc_url( $details_url ),
 673                  sprintf(
 674                      'class="thickbox open-plugin-details-modal" aria-label="%s"',
 675                      /* translators: 1: Theme name, 2: Version number. */
 676                      esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
 677                  ),
 678                  $response['new_version']
 679              );
 680          } elseif ( empty( $response['package'] ) ) {
 681              printf(
 682                  /* translators: 1: Theme name, 2: Details URL, 3: Additional link attributes, 4: Version number. */
 683                  __( '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>' ),
 684                  $theme['Name'],
 685                  esc_url( $details_url ),
 686                  sprintf(
 687                      'class="thickbox open-plugin-details-modal" aria-label="%s"',
 688                      /* translators: 1: Theme name, 2: Version number. */
 689                      esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
 690                  ),
 691                  $response['new_version']
 692              );
 693          } else {
 694              printf(
 695                  /* translators: 1: Theme name, 2: Details URL, 3: Additional link attributes, 4: Version number, 5: Update URL, 6: Additional link attributes. */
 696                  __( '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>.' ),
 697                  $theme['Name'],
 698                  esc_url( $details_url ),
 699                  sprintf(
 700                      'class="thickbox open-plugin-details-modal" aria-label="%s"',
 701                      /* translators: 1: Theme name, 2: Version number. */
 702                      esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
 703                  ),
 704                  $response['new_version'],
 705                  wp_nonce_url( self_admin_url( 'update.php?action=upgrade-theme&theme=' ) . $theme_key, 'upgrade-theme_' . $theme_key ),
 706                  sprintf(
 707                      'class="update-link" aria-label="%s"',
 708                      /* translators: %s: Theme name. */
 709                      esc_attr( sprintf( _x( 'Update %s now', 'theme' ), $theme['Name'] ) )
 710                  )
 711              );
 712          }
 713      } else {
 714          if ( ! $compatible_wp && ! $compatible_php ) {
 715              printf(
 716                  /* translators: %s: Theme name. */
 717                  __( 'There is a new version of %s available, but it doesn&#8217;t work with your versions of WordPress and PHP.' ),
 718                  $theme['Name']
 719              );
 720              if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
 721                  printf(
 722                      /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
 723                      ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
 724                      self_admin_url( 'update-core.php' ),
 725                      esc_url( wp_get_update_php_url() )
 726                  );
 727                  wp_update_php_annotation( '</p><p><em>', '</em>' );
 728              } elseif ( current_user_can( 'update_core' ) ) {
 729                  printf(
 730                      /* translators: %s: URL to WordPress Updates screen. */
 731                      ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
 732                      self_admin_url( 'update-core.php' )
 733                  );
 734              } elseif ( current_user_can( 'update_php' ) ) {
 735                  printf(
 736                      /* translators: %s: URL to Update PHP page. */
 737                      ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
 738                      esc_url( wp_get_update_php_url() )
 739                  );
 740                  wp_update_php_annotation( '</p><p><em>', '</em>' );
 741              }
 742          } elseif ( ! $compatible_wp ) {
 743              printf(
 744                  /* translators: %s: Theme name. */
 745                  __( 'There is a new version of %s available, but it doesn&#8217;t work with your version of WordPress.' ),
 746                  $theme['Name']
 747              );
 748              if ( current_user_can( 'update_core' ) ) {
 749                  printf(
 750                      /* translators: %s: URL to WordPress Updates screen. */
 751                      ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
 752                      self_admin_url( 'update-core.php' )
 753                  );
 754              }
 755          } elseif ( ! $compatible_php ) {
 756              printf(
 757                  /* translators: %s: Theme name. */
 758                  __( 'There is a new version of %s available, but it doesn&#8217;t work with your version of PHP.' ),
 759                  $theme['Name']
 760              );
 761              if ( current_user_can( 'update_php' ) ) {
 762                  printf(
 763                      /* translators: %s: URL to Update PHP page. */
 764                      ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
 765                      esc_url( wp_get_update_php_url() )
 766                  );
 767                  wp_update_php_annotation( '</p><p><em>', '</em>' );
 768              }
 769          }
 770      }
 771  
 772      /**
 773       * Fires at the end of the update message container in each
 774       * row of the themes list table.
 775       *
 776       * The dynamic portion of the hook name, `$theme_key`, refers to
 777       * the theme slug as found in the WordPress.org themes repository.
 778       *
 779       * @since 3.1.0
 780       *
 781       * @param WP_Theme $theme    The WP_Theme object.
 782       * @param array    $response {
 783       *     An array of metadata about the available theme update.
 784       *
 785       *     @type string $new_version New theme version.
 786       *     @type string $url         Theme URL.
 787       *     @type string $package     Theme update package URL.
 788       * }
 789       */
 790      do_action( "in_theme_update_message-{$theme_key}", $theme, $response ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 791  
 792      echo '</p></div></td></tr>';
 793  }
 794  
 795  /**
 796   * @since 2.7.0
 797   *
 798   * @global int $upgrading
 799   * @return void|false
 800   */
 801  function maintenance_nag() {
 802      // Include an unmodified $wp_version.
 803      require  ABSPATH . WPINC . '/version.php';
 804      global $upgrading;
 805      $nag = isset( $upgrading );
 806      if ( ! $nag ) {
 807          $failed = get_site_option( 'auto_core_update_failed' );
 808          /*
 809           * If an update failed critically, we may have copied over version.php but not other files.
 810           * In that case, if the installation claims we're running the version we attempted, nag.
 811           * This is serious enough to err on the side of nagging.
 812           *
 813           * If we simply failed to update before we tried to copy any files, then assume things are
 814           * OK if they are now running the latest.
 815           *
 816           * This flag is cleared whenever a successful update occurs using Core_Upgrader.
 817           */
 818          $comparison = ! empty( $failed['critical'] ) ? '>=' : '>';
 819          if ( isset( $failed['attempted'] ) && version_compare( $failed['attempted'], $wp_version, $comparison ) ) {
 820              $nag = true;
 821          }
 822      }
 823  
 824      if ( ! $nag ) {
 825          return false;
 826      }
 827  
 828      if ( current_user_can( 'update_core' ) ) {
 829          $msg = sprintf(
 830              /* translators: %s: URL to WordPress Updates screen. */
 831              __( 'An automated WordPress update has failed to complete - <a href="%s">please attempt the update again now</a>.' ),
 832              'update-core.php'
 833          );
 834      } else {
 835          $msg = __( 'An automated WordPress update has failed to complete! Please notify the site administrator.' );
 836      }
 837  
 838      echo "<div class='update-nag notice notice-warning inline'>$msg</div>";
 839  }
 840  
 841  /**
 842   * Prints the JavaScript templates for update admin notices.
 843   *
 844   * Template takes one argument with four values:
 845   *
 846   *     param {object} data {
 847   *         Arguments for admin notice.
 848   *
 849   *         @type string id        ID of the notice.
 850   *         @type string className Class names for the notice.
 851   *         @type string message   The notice's message.
 852   *         @type string type      The type of update the notice is for. Either 'plugin' or 'theme'.
 853   *     }
 854   *
 855   * @since 4.6.0
 856   */
 857  function wp_print_admin_notice_templates() {
 858      ?>
 859      <script id="tmpl-wp-updates-admin-notice" type="text/html">
 860          <div <# if ( data.id ) { #>id="{{ data.id }}"<# } #> class="notice {{ data.className }}"><p>{{{ data.message }}}</p></div>
 861      </script>
 862      <script id="tmpl-wp-bulk-updates-admin-notice" type="text/html">
 863          <div id="{{ data.id }}" class="{{ data.className }} notice <# if ( data.errors ) { #>notice-error<# } else { #>notice-success<# } #>">
 864              <p>
 865                  <# if ( data.successes ) { #>
 866                      <# if ( 1 === data.successes ) { #>
 867                          <# if ( 'plugin' === data.type ) { #>
 868                              <?php
 869                              /* translators: %s: Number of plugins. */
 870                              printf( __( '%s plugin successfully updated.' ), '{{ data.successes }}' );
 871                              ?>
 872                          <# } else { #>
 873                              <?php
 874                              /* translators: %s: Number of themes. */
 875                              printf( __( '%s theme successfully updated.' ), '{{ data.successes }}' );
 876                              ?>
 877                          <# } #>
 878                      <# } else { #>
 879                          <# if ( 'plugin' === data.type ) { #>
 880                              <?php
 881                              /* translators: %s: Number of plugins. */
 882                              printf( __( '%s plugins successfully updated.' ), '{{ data.successes }}' );
 883                              ?>
 884                          <# } else { #>
 885                              <?php
 886                              /* translators: %s: Number of themes. */
 887                              printf( __( '%s themes successfully updated.' ), '{{ data.successes }}' );
 888                              ?>
 889                          <# } #>
 890                      <# } #>
 891                  <# } #>
 892                  <# if ( data.errors ) { #>
 893                      <button class="button-link bulk-action-errors-collapsed" aria-expanded="false">
 894                          <# if ( 1 === data.errors ) { #>
 895                              <?php
 896                              /* translators: %s: Number of failed updates. */
 897                              printf( __( '%s update failed.' ), '{{ data.errors }}' );
 898                              ?>
 899                          <# } else { #>
 900                              <?php
 901                              /* translators: %s: Number of failed updates. */
 902                              printf( __( '%s updates failed.' ), '{{ data.errors }}' );
 903                              ?>
 904                          <# } #>
 905                          <span class="screen-reader-text"><?php _e( 'Show more details' ); ?></span>
 906                          <span class="toggle-indicator" aria-hidden="true"></span>
 907                      </button>
 908                  <# } #>
 909              </p>
 910              <# if ( data.errors ) { #>
 911                  <ul class="bulk-action-errors hidden">
 912                      <# _.each( data.errorMessages, function( errorMessage ) { #>
 913                          <li>{{ errorMessage }}</li>
 914                      <# } ); #>
 915                  </ul>
 916              <# } #>
 917          </div>
 918      </script>
 919      <?php
 920  }
 921  
 922  /**
 923   * Prints the JavaScript templates for update and deletion rows in list tables.
 924   *
 925   * The update template takes one argument with four values:
 926   *
 927   *     param {object} data {
 928   *         Arguments for the update row
 929   *
 930   *         @type string slug    Plugin slug.
 931   *         @type string plugin  Plugin base name.
 932   *         @type string colspan The number of table columns this row spans.
 933   *         @type string content The row content.
 934   *     }
 935   *
 936   * The delete template takes one argument with four values:
 937   *
 938   *     param {object} data {
 939   *         Arguments for the update row
 940   *
 941   *         @type string slug    Plugin slug.
 942   *         @type string plugin  Plugin base name.
 943   *         @type string name    Plugin name.
 944   *         @type string colspan The number of table columns this row spans.
 945   *     }
 946   *
 947   * @since 4.6.0
 948   */
 949  function wp_print_update_row_templates() {
 950      ?>
 951      <script id="tmpl-item-update-row" type="text/template">
 952          <tr class="plugin-update-tr update" id="{{ data.slug }}-update" data-slug="{{ data.slug }}" <# if ( data.plugin ) { #>data-plugin="{{ data.plugin }}"<# } #>>
 953              <td colspan="{{ data.colspan }}" class="plugin-update colspanchange">
 954                  {{{ data.content }}}
 955              </td>
 956          </tr>
 957      </script>
 958      <script id="tmpl-item-deleted-row" type="text/template">
 959          <tr class="plugin-deleted-tr inactive deleted" id="{{ data.slug }}-deleted" data-slug="{{ data.slug }}" <# if ( data.plugin ) { #>data-plugin="{{ data.plugin }}"<# } #>>
 960              <td colspan="{{ data.colspan }}" class="plugin-update colspanchange">
 961                  <# if ( data.plugin ) { #>
 962                      <?php
 963                      printf(
 964                          /* translators: %s: Plugin name. */
 965                          _x( '%s was successfully deleted.', 'plugin' ),
 966                          '<strong>{{{ data.name }}}</strong>'
 967                      );
 968                      ?>
 969                  <# } else { #>
 970                      <?php
 971                      printf(
 972                          /* translators: %s: Theme name. */
 973                          _x( '%s was successfully deleted.', 'theme' ),
 974                          '<strong>{{{ data.name }}}</strong>'
 975                      );
 976                      ?>
 977                  <# } #>
 978              </td>
 979          </tr>
 980      </script>
 981      <?php
 982  }
 983  
 984  /**
 985   * Displays a notice when the user is in recovery mode.
 986   *
 987   * @since 5.2.0
 988   */
 989  function wp_recovery_mode_nag() {
 990      if ( ! wp_is_recovery_mode() ) {
 991          return;
 992      }
 993  
 994      $url = wp_login_url();
 995      $url = add_query_arg( 'action', WP_Recovery_Mode::EXIT_ACTION, $url );
 996      $url = wp_nonce_url( $url, WP_Recovery_Mode::EXIT_ACTION );
 997  
 998      ?>
 999      <div class="notice notice-info">
1000          <p>
1001              <?php
1002              printf(
1003                  /* translators: %s: Recovery Mode exit link. */
1004                  __( '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>' ),
1005                  esc_url( $url )
1006              );
1007              ?>
1008          </p>
1009      </div>
1010      <?php
1011  }
1012  
1013  /**
1014   * Checks whether auto-updates are enabled.
1015   *
1016   * @since 5.5.0
1017   *
1018   * @param string $type The type of update being checked: 'theme' or 'plugin'.
1019   * @return bool True if auto-updates are enabled for `$type`, false otherwise.
1020   */
1021  function wp_is_auto_update_enabled_for_type( $type ) {
1022      if ( ! class_exists( 'WP_Automatic_Updater' ) ) {
1023          require_once ABSPATH . 'wp-admin/includes/class-wp-automatic-updater.php';
1024      }
1025  
1026      $updater = new WP_Automatic_Updater();
1027      $enabled = ! $updater->is_disabled();
1028  
1029      switch ( $type ) {
1030          case 'plugin':
1031              /**
1032               * Filters whether plugins auto-update is enabled.
1033               *
1034               * @since 5.5.0
1035               *
1036               * @param bool $enabled True if plugins auto-update is enabled, false otherwise.
1037               */
1038              return apply_filters( 'plugins_auto_update_enabled', $enabled );
1039          case 'theme':
1040              /**
1041               * Filters whether themes auto-update is enabled.
1042               *
1043               * @since 5.5.0
1044               *
1045               * @param bool $enabled True if themes auto-update is enabled, false otherwise.
1046               */
1047              return apply_filters( 'themes_auto_update_enabled', $enabled );
1048      }
1049  
1050      return false;
1051  }
1052  
1053  /**
1054   * Checks whether auto-updates are forced for an item.
1055   *
1056   * @since 5.6.0
1057   *
1058   * @param string    $type   The type of update being checked: 'theme' or 'plugin'.
1059   * @param bool|null $update Whether to update. The value of null is internally used
1060   *                          to detect whether nothing has hooked into this filter.
1061   * @param object    $item   The update offer.
1062   * @return bool True if auto-updates are forced for `$item`, false otherwise.
1063   */
1064  function wp_is_auto_update_forced_for_item( $type, $update, $item ) {
1065      /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
1066      return apply_filters( "auto_update_{$type}", $update, $item );
1067  }
1068  
1069  /**
1070   * Determines the appropriate auto-update message to be displayed.
1071   *
1072   * @since 5.5.0
1073   *
1074   * @return string The update message to be shown.
1075   */
1076  function wp_get_auto_update_message() {
1077      $next_update_time = wp_next_scheduled( 'wp_version_check' );
1078  
1079      // Check if the event exists.
1080      if ( false === $next_update_time ) {
1081          $message = __( 'Automatic update not scheduled. There may be a problem with WP-Cron.' );
1082      } else {
1083          $time_to_next_update = human_time_diff( (int) $next_update_time );
1084  
1085          // See if cron is overdue.
1086          $overdue = ( time() - $next_update_time ) > 0;
1087  
1088          if ( $overdue ) {
1089              $message = sprintf(
1090                  /* translators: %s: Duration that WP-Cron has been overdue. */
1091                  __( 'Automatic update overdue by %s. There may be a problem with WP-Cron.' ),
1092                  $time_to_next_update
1093              );
1094          } else {
1095              $message = sprintf(
1096                  /* translators: %s: Time until the next update. */
1097                  __( 'Automatic update scheduled in %s.' ),
1098                  $time_to_next_update
1099              );
1100          }
1101      }
1102  
1103      return $message;
1104  }


Generated: Sun Dec 6 01:00:03 2020 Cross-referenced by PHPXref 0.7.1