[ 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->url ) ) {
 244          $cur->url = '';
 245      }
 246  
 247      if ( ! isset( $cur->response ) ) {
 248          $cur->response = '';
 249      }
 250  
 251      switch ( $cur->response ) {
 252          case 'development':
 253              return sprintf(
 254                  /* translators: 1: WordPress version number, 2: URL to WordPress Updates screen. */
 255                  __( 'You are using a development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.' ),
 256                  get_bloginfo( 'version', 'display' ),
 257                  network_admin_url( 'update-core.php' )
 258              );
 259  
 260          case 'upgrade':
 261              return sprintf(
 262                  '<strong><a href="%s">%s</a></strong>',
 263                  network_admin_url( 'update-core.php' ),
 264                  /* translators: %s: WordPress version. */
 265                  sprintf( __( 'Get Version %s' ), $cur->current )
 266              );
 267  
 268          case 'latest':
 269          default:
 270              /* translators: %s: WordPress version. */
 271              return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
 272      }
 273  }
 274  
 275  /**
 276   * @since 2.3.0
 277   *
 278   * @global string $pagenow
 279   * @return void|false
 280   */
 281  function update_nag() {
 282      if ( is_multisite() && ! current_user_can( 'update_core' ) ) {
 283          return false;
 284      }
 285  
 286      global $pagenow;
 287  
 288      if ( 'update-core.php' == $pagenow ) {
 289          return;
 290      }
 291  
 292      $cur = get_preferred_from_update_core();
 293  
 294      if ( ! isset( $cur->response ) || 'upgrade' !== $cur->response ) {
 295          return false;
 296      }
 297  
 298      $version_url = sprintf(
 299          /* translators: %s: WordPress version. */
 300          esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
 301          sanitize_title( $cur->current )
 302      );
 303  
 304      if ( current_user_can( 'update_core' ) ) {
 305          $msg = sprintf(
 306              /* translators: 1: URL to WordPress release notes, 2: New WordPress version, 3: URL to network admin, 4: Accessibility text. */
 307              __( '<a href="%1$s">WordPress %2$s</a> is available! <a href="%3$s" aria-label="%4$s">Please update now</a>.' ),
 308              $version_url,
 309              $cur->current,
 310              network_admin_url( 'update-core.php' ),
 311              esc_attr__( 'Please update WordPress now' )
 312          );
 313      } else {
 314          $msg = sprintf(
 315              /* translators: 1: URL to WordPress release notes, 2: New WordPress version. */
 316              __( '<a href="%1$s">WordPress %2$s</a> is available! Please notify the site administrator.' ),
 317              $version_url,
 318              $cur->current
 319          );
 320      }
 321      echo "<div class='update-nag'>$msg</div>";
 322  }
 323  
 324  /**
 325   * Displays WordPress version and active theme in the 'At a Glance' dashboard widget.
 326   *
 327   * @since 2.5.0
 328   */
 329  function update_right_now_message() {
 330      $theme_name = wp_get_theme();
 331      if ( current_user_can( 'switch_themes' ) ) {
 332          $theme_name = sprintf( '<a href="themes.php">%1$s</a>', $theme_name );
 333      }
 334  
 335      $msg = '';
 336  
 337      if ( current_user_can( 'update_core' ) ) {
 338          $cur = get_preferred_from_update_core();
 339  
 340          if ( isset( $cur->response ) && 'upgrade' === $cur->response ) {
 341              $msg .= sprintf(
 342                  '<a href="%s" class="button" aria-describedby="wp-version">%s</a> ',
 343                  network_admin_url( 'update-core.php' ),
 344                  /* translators: %s: WordPress version number, or 'Latest' string. */
 345                  sprintf( __( 'Update to %s' ), $cur->current ? $cur->current : __( 'Latest' ) )
 346              );
 347          }
 348      }
 349  
 350      /* translators: 1: Version number, 2: Theme name. */
 351      $content = __( 'WordPress %1$s running %2$s theme.' );
 352  
 353      /**
 354       * Filters the text displayed in the 'At a Glance' dashboard widget.
 355       *
 356       * Prior to 3.8.0, the widget was named 'Right Now'.
 357       *
 358       * @since 4.4.0
 359       *
 360       * @param string $content Default text.
 361       */
 362      $content = apply_filters( 'update_right_now_text', $content );
 363  
 364      $msg .= sprintf( '<span id="wp-version">' . $content . '</span>', get_bloginfo( 'version', 'display' ), $theme_name );
 365  
 366      echo "<p id='wp-version-message'>$msg</p>";
 367  }
 368  
 369  /**
 370   * @since 2.9.0
 371   *
 372   * @return array
 373   */
 374  function get_plugin_updates() {
 375      $all_plugins     = get_plugins();
 376      $upgrade_plugins = array();
 377      $current         = get_site_transient( 'update_plugins' );
 378      foreach ( (array) $all_plugins as $plugin_file => $plugin_data ) {
 379          if ( isset( $current->response[ $plugin_file ] ) ) {
 380              $upgrade_plugins[ $plugin_file ]         = (object) $plugin_data;
 381              $upgrade_plugins[ $plugin_file ]->update = $current->response[ $plugin_file ];
 382          }
 383      }
 384  
 385      return $upgrade_plugins;
 386  }
 387  
 388  /**
 389   * @since 2.9.0
 390   */
 391  function wp_plugin_update_rows() {
 392      if ( ! current_user_can( 'update_plugins' ) ) {
 393          return;
 394      }
 395  
 396      $plugins = get_site_transient( 'update_plugins' );
 397      if ( isset( $plugins->response ) && is_array( $plugins->response ) ) {
 398          $plugins = array_keys( $plugins->response );
 399          foreach ( $plugins as $plugin_file ) {
 400              add_action( "after_plugin_row_{$plugin_file}", 'wp_plugin_update_row', 10, 2 );
 401          }
 402      }
 403  }
 404  
 405  /**
 406   * Displays update information for a plugin.
 407   *
 408   * @since 2.3.0
 409   *
 410   * @param string $file        Plugin basename.
 411   * @param array  $plugin_data Plugin information.
 412   * @return void|false
 413   */
 414  function wp_plugin_update_row( $file, $plugin_data ) {
 415      $current = get_site_transient( 'update_plugins' );
 416      if ( ! isset( $current->response[ $file ] ) ) {
 417          return false;
 418      }
 419  
 420      $response = $current->response[ $file ];
 421  
 422      $plugins_allowedtags = array(
 423          'a'       => array(
 424              'href'  => array(),
 425              'title' => array(),
 426          ),
 427          'abbr'    => array( 'title' => array() ),
 428          'acronym' => array( 'title' => array() ),
 429          'code'    => array(),
 430          'em'      => array(),
 431          'strong'  => array(),
 432      );
 433  
 434      $plugin_name = wp_kses( $plugin_data['Name'], $plugins_allowedtags );
 435      $details_url = self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $response->slug . '&section=changelog&TB_iframe=true&width=600&height=800' );
 436  
 437      /** @var WP_Plugins_List_Table $wp_list_table */
 438      $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
 439  
 440      if ( is_network_admin() || ! is_multisite() ) {
 441          if ( is_network_admin() ) {
 442              $active_class = is_plugin_active_for_network( $file ) ? ' active' : '';
 443          } else {
 444              $active_class = is_plugin_active( $file ) ? ' active' : '';
 445          }
 446  
 447          $requires_php   = isset( $response->requires_php ) ? $response->requires_php : null;
 448          $compatible_php = is_php_version_compatible( $requires_php );
 449          $notice_type    = $compatible_php ? 'notice-warning' : 'notice-error';
 450  
 451          printf(
 452              '<tr class="plugin-update-tr%s" id="%s" data-slug="%s" data-plugin="%s">' .
 453              '<td colspan="%s" class="plugin-update colspanchange">' .
 454              '<div class="update-message notice inline %s notice-alt"><p>',
 455              $active_class,
 456              esc_attr( $response->slug . '-update' ),
 457              esc_attr( $response->slug ),
 458              esc_attr( $file ),
 459              esc_attr( $wp_list_table->get_column_count() ),
 460              $notice_type
 461          );
 462  
 463          if ( ! current_user_can( 'update_plugins' ) ) {
 464              printf(
 465                  /* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number. */
 466                  __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ),
 467                  $plugin_name,
 468                  esc_url( $details_url ),
 469                  sprintf(
 470                      'class="thickbox open-plugin-details-modal" aria-label="%s"',
 471                      /* translators: 1: Plugin name, 2: Version number. */
 472                      esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
 473                  ),
 474                  esc_attr( $response->new_version )
 475              );
 476          } elseif ( empty( $response->package ) ) {
 477              printf(
 478                  /* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number. */
 479                  __( '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>' ),
 480                  $plugin_name,
 481                  esc_url( $details_url ),
 482                  sprintf(
 483                      'class="thickbox open-plugin-details-modal" aria-label="%s"',
 484                      /* translators: 1: Plugin name, 2: Version number. */
 485                      esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
 486                  ),
 487                  esc_attr( $response->new_version )
 488              );
 489          } else {
 490              if ( $compatible_php ) {
 491                  printf(
 492                      /* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number, 5: Update URL, 6: Additional link attributes. */
 493                      __( '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>.' ),
 494                      $plugin_name,
 495                      esc_url( $details_url ),
 496                      sprintf(
 497                          'class="thickbox open-plugin-details-modal" aria-label="%s"',
 498                          /* translators: 1: Plugin name, 2: Version number. */
 499                          esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
 500                      ),
 501                      esc_attr( $response->new_version ),
 502                      wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $file, 'upgrade-plugin_' . $file ),
 503                      sprintf(
 504                          'class="update-link" aria-label="%s"',
 505                          /* translators: %s: Plugin name. */
 506                          esc_attr( sprintf( __( 'Update %s now' ), $plugin_name ) )
 507                      )
 508                  );
 509              } else {
 510                  printf(
 511                      /* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number 5: URL to Update PHP page. */
 512                      __( '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>.' ),
 513                      $plugin_name,
 514                      esc_url( $details_url ),
 515                      sprintf(
 516                          'class="thickbox open-plugin-details-modal" aria-label="%s"',
 517                          /* translators: 1: Plugin name, 2: Version number. */
 518                          esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
 519                      ),
 520                      esc_attr( $response->new_version ),
 521                      esc_url( wp_get_update_php_url() )
 522                  );
 523                  wp_update_php_annotation( '<br><em>', '</em>' );
 524              }
 525          }
 526  
 527          /**
 528           * Fires at the end of the update message container in each
 529           * row of the plugins list table.
 530           *
 531           * The dynamic portion of the hook name, `$file`, refers to the path
 532           * of the plugin's primary file relative to the plugins directory.
 533           *
 534           * @since 2.8.0
 535           *
 536           * @param array $plugin_data {
 537           *     An array of plugin metadata.
 538           *
 539           *     @type string $name        The human-readable name of the plugin.
 540           *     @type string $plugin_uri  Plugin URI.
 541           *     @type string $version     Plugin version.
 542           *     @type string $description Plugin description.
 543           *     @type string $author      Plugin author.
 544           *     @type string $author_uri  Plugin author URI.
 545           *     @type string $text_domain Plugin text domain.
 546           *     @type string $domain_path Relative path to the plugin's .mo file(s).
 547           *     @type bool   $network     Whether the plugin can only be activated network wide.
 548           *     @type string $title       The human-readable title of the plugin.
 549           *     @type string $author_name Plugin author's name.
 550           *     @type bool   $update      Whether there's an available update. Default null.
 551           * }
 552           * @param array $response {
 553           *     An array of metadata about the available plugin update.
 554           *
 555           *     @type int    $id          Plugin ID.
 556           *     @type string $slug        Plugin slug.
 557           *     @type string $new_version New plugin version.
 558           *     @type string $url         Plugin URL.
 559           *     @type string $package     Plugin update package URL.
 560           * }
 561           */
 562          do_action( "in_plugin_update_message-{$file}", $plugin_data, $response ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 563  
 564          echo '</p></div></td></tr>';
 565      }
 566  }
 567  
 568  /**
 569   * @since 2.9.0
 570   *
 571   * @return array
 572   */
 573  function get_theme_updates() {
 574      $current = get_site_transient( 'update_themes' );
 575  
 576      if ( ! isset( $current->response ) ) {
 577          return array();
 578      }
 579  
 580      $update_themes = array();
 581      foreach ( $current->response as $stylesheet => $data ) {
 582          $update_themes[ $stylesheet ]         = wp_get_theme( $stylesheet );
 583          $update_themes[ $stylesheet ]->update = $data;
 584      }
 585  
 586      return $update_themes;
 587  }
 588  
 589  /**
 590   * @since 3.1.0
 591   */
 592  function wp_theme_update_rows() {
 593      if ( ! current_user_can( 'update_themes' ) ) {
 594          return;
 595      }
 596  
 597      $themes = get_site_transient( 'update_themes' );
 598      if ( isset( $themes->response ) && is_array( $themes->response ) ) {
 599          $themes = array_keys( $themes->response );
 600  
 601          foreach ( $themes as $theme ) {
 602              add_action( "after_theme_row_{$theme}", 'wp_theme_update_row', 10, 2 );
 603          }
 604      }
 605  }
 606  
 607  /**
 608   * Displays update information for a theme.
 609   *
 610   * @since 3.1.0
 611   *
 612   * @param string   $theme_key Theme stylesheet.
 613   * @param WP_Theme $theme     Theme object.
 614   * @return void|false
 615   */
 616  function wp_theme_update_row( $theme_key, $theme ) {
 617      $current = get_site_transient( 'update_themes' );
 618  
 619      if ( ! isset( $current->response[ $theme_key ] ) ) {
 620          return false;
 621      }
 622  
 623      $response = $current->response[ $theme_key ];
 624  
 625      $details_url = add_query_arg(
 626          array(
 627              'TB_iframe' => 'true',
 628              'width'     => 1024,
 629              'height'    => 800,
 630          ),
 631          $current->response[ $theme_key ]['url']
 632      );
 633  
 634      /** @var WP_MS_Themes_List_Table $wp_list_table */
 635      $wp_list_table = _get_list_table( 'WP_MS_Themes_List_Table' );
 636  
 637      $active = $theme->is_allowed( 'network' ) ? ' active' : '';
 638  
 639      printf(
 640          '<tr class="plugin-update-tr%s" id="%s" data-slug="%s">' .
 641          '<td colspan="%s" class="plugin-update colspanchange">' .
 642          '<div class="update-message notice inline notice-warning notice-alt"><p>',
 643          $active,
 644          esc_attr( $theme->get_stylesheet() . '-update' ),
 645          esc_attr( $theme->get_stylesheet() ),
 646          $wp_list_table->get_column_count()
 647      );
 648  
 649      if ( ! current_user_can( 'update_themes' ) ) {
 650          printf(
 651              /* translators: 1: Theme name, 2: Details URL, 3: Additional link attributes, 4: Version number. */
 652              __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ),
 653              $theme['Name'],
 654              esc_url( $details_url ),
 655              sprintf(
 656                  'class="thickbox open-plugin-details-modal" aria-label="%s"',
 657                  /* translators: 1: Theme name, 2: Version number. */
 658                  esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
 659              ),
 660              $response['new_version']
 661          );
 662      } elseif ( empty( $response['package'] ) ) {
 663          printf(
 664              /* translators: 1: Theme name, 2: Details URL, 3: Additional link attributes, 4: Version number. */
 665              __( '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>' ),
 666              $theme['Name'],
 667              esc_url( $details_url ),
 668              sprintf(
 669                  'class="thickbox open-plugin-details-modal" aria-label="%s"',
 670                  /* translators: 1: Theme name, 2: Version number. */
 671                  esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
 672              ),
 673              $response['new_version']
 674          );
 675      } else {
 676          printf(
 677              /* translators: 1: Theme name, 2: Details URL, 3: Additional link attributes, 4: Version number, 5: Update URL, 6: Additional link attributes. */
 678              __( '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>.' ),
 679              $theme['Name'],
 680              esc_url( $details_url ),
 681              sprintf(
 682                  'class="thickbox open-plugin-details-modal" aria-label="%s"',
 683                  /* translators: 1: Theme name, 2: Version number. */
 684                  esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
 685              ),
 686              $response['new_version'],
 687              wp_nonce_url( self_admin_url( 'update.php?action=upgrade-theme&theme=' ) . $theme_key, 'upgrade-theme_' . $theme_key ),
 688              sprintf(
 689                  'class="update-link" aria-label="%s"',
 690                  /* translators: %s: Theme name. */
 691                  esc_attr( sprintf( __( 'Update %s now' ), $theme['Name'] ) )
 692              )
 693          );
 694      }
 695  
 696      /**
 697       * Fires at the end of the update message container in each
 698       * row of the themes list table.
 699       *
 700       * The dynamic portion of the hook name, `$theme_key`, refers to
 701       * the theme slug as found in the WordPress.org themes repository.
 702       *
 703       * @since 3.1.0
 704       *
 705       * @param WP_Theme $theme    The WP_Theme object.
 706       * @param array    $response {
 707       *     An array of metadata about the available theme update.
 708       *
 709       *     @type string $new_version New theme version.
 710       *     @type string $url         Theme URL.
 711       *     @type string $package     Theme update package URL.
 712       * }
 713       */
 714      do_action( "in_theme_update_message-{$theme_key}", $theme, $response ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 715  
 716      echo '</p></div></td></tr>';
 717  }
 718  
 719  /**
 720   * @since 2.7.0
 721   *
 722   * @global int $upgrading
 723   * @return void|false
 724   */
 725  function maintenance_nag() {
 726      // Include an unmodified $wp_version.
 727      require  ABSPATH . WPINC . '/version.php';
 728      global $upgrading;
 729      $nag = isset( $upgrading );
 730      if ( ! $nag ) {
 731          $failed = get_site_option( 'auto_core_update_failed' );
 732          /*
 733           * If an update failed critically, we may have copied over version.php but not other files.
 734           * In that case, if the installation claims we're running the version we attempted, nag.
 735           * This is serious enough to err on the side of nagging.
 736           *
 737           * If we simply failed to update before we tried to copy any files, then assume things are
 738           * OK if they are now running the latest.
 739           *
 740           * This flag is cleared whenever a successful update occurs using Core_Upgrader.
 741           */
 742          $comparison = ! empty( $failed['critical'] ) ? '>=' : '>';
 743          if ( isset( $failed['attempted'] ) && version_compare( $failed['attempted'], $wp_version, $comparison ) ) {
 744              $nag = true;
 745          }
 746      }
 747  
 748      if ( ! $nag ) {
 749          return false;
 750      }
 751  
 752      if ( current_user_can( 'update_core' ) ) {
 753          $msg = sprintf(
 754              /* translators: %s: URL to WordPress Updates screen. */
 755              __( 'An automated WordPress update has failed to complete - <a href="%s">please attempt the update again now</a>.' ),
 756              'update-core.php'
 757          );
 758      } else {
 759          $msg = __( 'An automated WordPress update has failed to complete! Please notify the site administrator.' );
 760      }
 761  
 762      echo "<div class='update-nag'>$msg</div>";
 763  }
 764  
 765  /**
 766   * Prints the JavaScript templates for update admin notices.
 767   *
 768   * Template takes one argument with four values:
 769   *
 770   *     param {object} data {
 771   *         Arguments for admin notice.
 772   *
 773   *         @type string id        ID of the notice.
 774   *         @type string className Class names for the notice.
 775   *         @type string message   The notice's message.
 776   *         @type string type      The type of update the notice is for. Either 'plugin' or 'theme'.
 777   *     }
 778   *
 779   * @since 4.6.0
 780   */
 781  function wp_print_admin_notice_templates() {
 782      ?>
 783      <script id="tmpl-wp-updates-admin-notice" type="text/html">
 784          <div <# if ( data.id ) { #>id="{{ data.id }}"<# } #> class="notice {{ data.className }}"><p>{{{ data.message }}}</p></div>
 785      </script>
 786      <script id="tmpl-wp-bulk-updates-admin-notice" type="text/html">
 787          <div id="{{ data.id }}" class="{{ data.className }} notice <# if ( data.errors ) { #>notice-error<# } else { #>notice-success<# } #>">
 788              <p>
 789                  <# if ( data.successes ) { #>
 790                      <# if ( 1 === data.successes ) { #>
 791                          <# if ( 'plugin' === data.type ) { #>
 792                              <?php
 793                              /* translators: %s: Number of plugins. */
 794                              printf( __( '%s plugin successfully updated.' ), '{{ data.successes }}' );
 795                              ?>
 796                          <# } else { #>
 797                              <?php
 798                              /* translators: %s: Number of themes. */
 799                              printf( __( '%s theme successfully updated.' ), '{{ data.successes }}' );
 800                              ?>
 801                          <# } #>
 802                      <# } else { #>
 803                          <# if ( 'plugin' === data.type ) { #>
 804                              <?php
 805                              /* translators: %s: Number of plugins. */
 806                              printf( __( '%s plugins successfully updated.' ), '{{ data.successes }}' );
 807                              ?>
 808                          <# } else { #>
 809                              <?php
 810                              /* translators: %s: Number of themes. */
 811                              printf( __( '%s themes successfully updated.' ), '{{ data.successes }}' );
 812                              ?>
 813                          <# } #>
 814                      <# } #>
 815                  <# } #>
 816                  <# if ( data.errors ) { #>
 817                      <button class="button-link bulk-action-errors-collapsed" aria-expanded="false">
 818                          <# if ( 1 === data.errors ) { #>
 819                              <?php
 820                              /* translators: %s: Number of failed updates. */
 821                              printf( __( '%s update failed.' ), '{{ data.errors }}' );
 822                              ?>
 823                          <# } else { #>
 824                              <?php
 825                              /* translators: %s: Number of failed updates. */
 826                              printf( __( '%s updates failed.' ), '{{ data.errors }}' );
 827                              ?>
 828                          <# } #>
 829                          <span class="screen-reader-text"><?php _e( 'Show more details' ); ?></span>
 830                          <span class="toggle-indicator" aria-hidden="true"></span>
 831                      </button>
 832                  <# } #>
 833              </p>
 834              <# if ( data.errors ) { #>
 835                  <ul class="bulk-action-errors hidden">
 836                      <# _.each( data.errorMessages, function( errorMessage ) { #>
 837                          <li>{{ errorMessage }}</li>
 838                      <# } ); #>
 839                  </ul>
 840              <# } #>
 841          </div>
 842      </script>
 843      <?php
 844  }
 845  
 846  /**
 847   * Prints the JavaScript templates for update and deletion rows in list tables.
 848   *
 849   * The update template takes one argument with four values:
 850   *
 851   *     param {object} data {
 852   *         Arguments for the update row
 853   *
 854   *         @type string slug    Plugin slug.
 855   *         @type string plugin  Plugin base name.
 856   *         @type string colspan The number of table columns this row spans.
 857   *         @type string content The row content.
 858   *     }
 859   *
 860   * The delete template takes one argument with four values:
 861   *
 862   *     param {object} data {
 863   *         Arguments for the update row
 864   *
 865   *         @type string slug    Plugin slug.
 866   *         @type string plugin  Plugin base name.
 867   *         @type string name    Plugin name.
 868   *         @type string colspan The number of table columns this row spans.
 869   *     }
 870   *
 871   * @since 4.6.0
 872   */
 873  function wp_print_update_row_templates() {
 874      ?>
 875      <script id="tmpl-item-update-row" type="text/template">
 876          <tr class="plugin-update-tr update" id="{{ data.slug }}-update" data-slug="{{ data.slug }}" <# if ( data.plugin ) { #>data-plugin="{{ data.plugin }}"<# } #>>
 877              <td colspan="{{ data.colspan }}" class="plugin-update colspanchange">
 878                  {{{ data.content }}}
 879              </td>
 880          </tr>
 881      </script>
 882      <script id="tmpl-item-deleted-row" type="text/template">
 883          <tr class="plugin-deleted-tr inactive deleted" id="{{ data.slug }}-deleted" data-slug="{{ data.slug }}" <# if ( data.plugin ) { #>data-plugin="{{ data.plugin }}"<# } #>>
 884              <td colspan="{{ data.colspan }}" class="plugin-update colspanchange">
 885                  <# if ( data.plugin ) { #>
 886                      <?php
 887                      printf(
 888                          /* translators: %s: Plugin name. */
 889                          _x( '%s was successfully deleted.', 'plugin' ),
 890                          '<strong>{{{ data.name }}}</strong>'
 891                      );
 892                      ?>
 893                  <# } else { #>
 894                      <?php
 895                      printf(
 896                          /* translators: %s: Theme name. */
 897                          _x( '%s was successfully deleted.', 'theme' ),
 898                          '<strong>{{{ data.name }}}</strong>'
 899                      );
 900                      ?>
 901                  <# } #>
 902              </td>
 903          </tr>
 904      </script>
 905      <?php
 906  }
 907  
 908  /**
 909   * Displays a notice when the user is in recovery mode.
 910   *
 911   * @since 5.2.0
 912   */
 913  function wp_recovery_mode_nag() {
 914      if ( ! wp_is_recovery_mode() ) {
 915          return;
 916      }
 917  
 918      $url = wp_login_url();
 919      $url = add_query_arg( 'action', WP_Recovery_Mode::EXIT_ACTION, $url );
 920      $url = wp_nonce_url( $url, WP_Recovery_Mode::EXIT_ACTION );
 921  
 922      ?>
 923      <div class="notice notice-info">
 924          <p>
 925              <?php
 926              printf(
 927                  /* translators: %s: Recovery Mode exit link. */
 928                  __( '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>' ),
 929                  esc_url( $url )
 930              );
 931              ?>
 932          </p>
 933      </div>
 934      <?php
 935  }


Generated: Sun Apr 5 01:00:03 2020 Cross-referenced by PHPXref 0.7.1