[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

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   * @return object|array|false The response from the API on success, false on failure.
  13   */
  14  function get_preferred_from_update_core() {
  15      $updates = get_core_updates();
  16      if ( ! is_array( $updates ) ) {
  17          return false;
  18      }
  19      if ( empty( $updates ) ) {
  20          return (object) array( 'response' => 'latest' );
  21      }
  22      return $updates[0];
  23  }
  24  
  25  /**
  26   * Get available core updates.
  27   *
  28   * @param array $options Set $options['dismissed'] to true to show dismissed upgrades too,
  29   *                       set $options['available'] to false to skip not-dismissed updates.
  30   * @return array|false Array of the update objects on success, false on failure.
  31   */
  32  function get_core_updates( $options = array() ) {
  33      $options   = array_merge(
  34          array(
  35              'available' => true,
  36              'dismissed' => false,
  37          ),
  38          $options
  39      );
  40      $dismissed = get_site_option( 'dismissed_update_core' );
  41  
  42      if ( ! is_array( $dismissed ) ) {
  43          $dismissed = array();
  44      }
  45  
  46      $from_api = get_site_transient( 'update_core' );
  47  
  48      if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) {
  49          return false;
  50      }
  51  
  52      $updates = $from_api->updates;
  53      $result  = array();
  54      foreach ( $updates as $update ) {
  55          if ( $update->response == 'autoupdate' ) {
  56              continue;
  57          }
  58  
  59          if ( array_key_exists( $update->current . '|' . $update->locale, $dismissed ) ) {
  60              if ( $options['dismissed'] ) {
  61                  $update->dismissed = true;
  62                  $result[]          = $update;
  63              }
  64          } else {
  65              if ( $options['available'] ) {
  66                  $update->dismissed = false;
  67                  $result[]          = $update;
  68              }
  69          }
  70      }
  71      return $result;
  72  }
  73  
  74  /**
  75   * Gets the best available (and enabled) Auto-Update for WordPress Core.
  76   *
  77   * 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
  78   *
  79   * @since 3.7.0
  80   *
  81   * @return array|false False on failure, otherwise the core update offering.
  82   */
  83  function find_core_auto_update() {
  84      $updates = get_site_transient( 'update_core' );
  85      if ( ! $updates || empty( $updates->updates ) ) {
  86          return false;
  87      }
  88  
  89      include_once ( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
  90  
  91      $auto_update = false;
  92      $upgrader    = new WP_Automatic_Updater;
  93      foreach ( $updates->updates as $update ) {
  94          if ( 'autoupdate' != $update->response ) {
  95              continue;
  96          }
  97  
  98          if ( ! $upgrader->should_update( 'core', $update, ABSPATH ) ) {
  99              continue;
 100          }
 101  
 102          if ( ! $auto_update || version_compare( $update->current, $auto_update->current, '>' ) ) {
 103              $auto_update = $update;
 104          }
 105      }
 106      return $auto_update;
 107  }
 108  
 109  /**
 110   * Gets and caches the checksums for the given version of WordPress.
 111   *
 112   * @since 3.7.0
 113   *
 114   * @param string $version Version string to query.
 115   * @param string $locale  Locale to query.
 116   * @return bool|array False on failure. An array of checksums on success.
 117   */
 118  function get_core_checksums( $version, $locale ) {
 119      $url = $http_url = 'http://api.wordpress.org/core/checksums/1.0/?' . http_build_query( compact( 'version', 'locale' ), null, '&' );
 120  
 121      if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
 122          $url = set_url_scheme( $url, 'https' );
 123      }
 124  
 125      $options = array(
 126          'timeout' => wp_doing_cron() ? 30 : 3,
 127      );
 128  
 129      $response = wp_remote_get( $url, $options );
 130      if ( $ssl && is_wp_error( $response ) ) {
 131          trigger_error(
 132              sprintf(
 133                  /* translators: %s: support forums URL */
 134                  __( '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>.' ),
 135                  __( 'https://wordpress.org/support/' )
 136              ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
 137              headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
 138          );
 139          $response = wp_remote_get( $http_url, $options );
 140      }
 141  
 142      if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
 143          return false;
 144      }
 145  
 146      $body = trim( wp_remote_retrieve_body( $response ) );
 147      $body = json_decode( $body, true );
 148  
 149      if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) ) {
 150          return false;
 151      }
 152  
 153      return $body['checksums'];
 154  }
 155  
 156  /**
 157   * @param object $update
 158   * @return bool
 159   */
 160  function dismiss_core_update( $update ) {
 161      $dismissed = get_site_option( 'dismissed_update_core' );
 162      $dismissed[ $update->current . '|' . $update->locale ] = true;
 163      return update_site_option( 'dismissed_update_core', $dismissed );
 164  }
 165  
 166  /**
 167   * @param string $version
 168   * @param string $locale
 169   * @return bool
 170   */
 171  function undismiss_core_update( $version, $locale ) {
 172      $dismissed = get_site_option( 'dismissed_update_core' );
 173      $key       = $version . '|' . $locale;
 174  
 175      if ( ! isset( $dismissed[ $key ] ) ) {
 176          return false;
 177      }
 178  
 179      unset( $dismissed[ $key ] );
 180      return update_site_option( 'dismissed_update_core', $dismissed );
 181  }
 182  
 183  /**
 184   * @param string $version
 185   * @param string $locale
 186   * @return object|false
 187   */
 188  function find_core_update( $version, $locale ) {
 189      $from_api = get_site_transient( 'update_core' );
 190  
 191      if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) {
 192          return false;
 193      }
 194  
 195      $updates = $from_api->updates;
 196      foreach ( $updates as $update ) {
 197          if ( $update->current == $version && $update->locale == $locale ) {
 198              return $update;
 199          }
 200      }
 201      return false;
 202  }
 203  
 204  /**
 205   * @param string $msg
 206   * @return string
 207   */
 208  function core_update_footer( $msg = '' ) {
 209      if ( ! current_user_can( 'update_core' ) ) {
 210          return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
 211      }
 212  
 213      $cur = get_preferred_from_update_core();
 214      if ( ! is_object( $cur ) ) {
 215          $cur = new stdClass;
 216      }
 217  
 218      if ( ! isset( $cur->current ) ) {
 219          $cur->current = '';
 220      }
 221  
 222      if ( ! isset( $cur->url ) ) {
 223          $cur->url = '';
 224      }
 225  
 226      if ( ! isset( $cur->response ) ) {
 227          $cur->response = '';
 228      }
 229  
 230      switch ( $cur->response ) {
 231          case 'development':
 232              /* translators: 1: WordPress version number, 2: WordPress updates admin screen URL */
 233              return sprintf( __( 'You are using a development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.' ), get_bloginfo( 'version', 'display' ), network_admin_url( 'update-core.php' ) );
 234  
 235          case 'upgrade':
 236              return '<strong><a href="' . network_admin_url( 'update-core.php' ) . '">' . sprintf( __( 'Get Version %s' ), $cur->current ) . '</a></strong>';
 237  
 238          case 'latest':
 239          default:
 240              return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
 241      }
 242  }
 243  
 244  /**
 245   * @global string $pagenow
 246   * @return false|void
 247   */
 248  function update_nag() {
 249      if ( is_multisite() && ! current_user_can( 'update_core' ) ) {
 250          return false;
 251      }
 252  
 253      global $pagenow;
 254  
 255      if ( 'update-core.php' == $pagenow ) {
 256          return;
 257      }
 258  
 259      $cur = get_preferred_from_update_core();
 260  
 261      if ( ! isset( $cur->response ) || $cur->response != 'upgrade' ) {
 262          return false;
 263      }
 264  
 265      $version_url = sprintf(
 266          /* translators: %s: WordPress version */
 267          esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
 268          sanitize_title( $cur->current )
 269      );
 270  
 271      if ( current_user_can( 'update_core' ) ) {
 272          $msg = sprintf(
 273              /* translators: 1: URL to WordPress release notes, 2: new WordPress version, 3: URL to network admin, 4: accessibility text */
 274              __( '<a href="%1$s">WordPress %2$s</a> is available! <a href="%3$s" aria-label="%4$s">Please update now</a>.' ),
 275              $version_url,
 276              $cur->current,
 277              network_admin_url( 'update-core.php' ),
 278              esc_attr__( 'Please update WordPress now' )
 279          );
 280      } else {
 281          $msg = sprintf(
 282              /* translators: 1: URL to WordPress release notes, 2: new WordPress version */
 283              __( '<a href="%1$s">WordPress %2$s</a> is available! Please notify the site administrator.' ),
 284              $version_url,
 285              $cur->current
 286          );
 287      }
 288      echo "<div class='update-nag'>$msg</div>";
 289  }
 290  
 291  // Called directly from dashboard
 292  function update_right_now_message() {
 293      $theme_name = wp_get_theme();
 294      if ( current_user_can( 'switch_themes' ) ) {
 295          $theme_name = sprintf( '<a href="themes.php">%1$s</a>', $theme_name );
 296      }
 297  
 298      $msg = '';
 299  
 300      if ( current_user_can( 'update_core' ) ) {
 301          $cur = get_preferred_from_update_core();
 302  
 303          if ( isset( $cur->response ) && $cur->response == 'upgrade' ) {
 304              $msg .= '<a href="' . network_admin_url( 'update-core.php' ) . '" class="button" aria-describedby="wp-version">' . sprintf( __( 'Update to %s' ), $cur->current ? $cur->current : __( 'Latest' ) ) . '</a> ';
 305          }
 306      }
 307  
 308      /* translators: 1: version number, 2: theme name */
 309      $content = __( 'WordPress %1$s running %2$s theme.' );
 310  
 311      /**
 312       * Filters the text displayed in the 'At a Glance' dashboard widget.
 313       *
 314       * Prior to 3.8.0, the widget was named 'Right Now'.
 315       *
 316       * @since 4.4.0
 317       *
 318       * @param string $content Default text.
 319       */
 320      $content = apply_filters( 'update_right_now_text', $content );
 321  
 322      $msg .= sprintf( '<span id="wp-version">' . $content . '</span>', get_bloginfo( 'version', 'display' ), $theme_name );
 323  
 324      echo "<p id='wp-version-message'>$msg</p>";
 325  }
 326  
 327  /**
 328   * @since 2.9.0
 329   *
 330   * @return array
 331   */
 332  function get_plugin_updates() {
 333      $all_plugins     = get_plugins();
 334      $upgrade_plugins = array();
 335      $current         = get_site_transient( 'update_plugins' );
 336      foreach ( (array) $all_plugins as $plugin_file => $plugin_data ) {
 337          if ( isset( $current->response[ $plugin_file ] ) ) {
 338              $upgrade_plugins[ $plugin_file ]         = (object) $plugin_data;
 339              $upgrade_plugins[ $plugin_file ]->update = $current->response[ $plugin_file ];
 340          }
 341      }
 342  
 343      return $upgrade_plugins;
 344  }
 345  
 346  /**
 347   * @since 2.9.0
 348   */
 349  function wp_plugin_update_rows() {
 350      if ( ! current_user_can( 'update_plugins' ) ) {
 351          return;
 352      }
 353  
 354      $plugins = get_site_transient( 'update_plugins' );
 355      if ( isset( $plugins->response ) && is_array( $plugins->response ) ) {
 356          $plugins = array_keys( $plugins->response );
 357          foreach ( $plugins as $plugin_file ) {
 358              add_action( "after_plugin_row_$plugin_file", 'wp_plugin_update_row', 10, 2 );
 359          }
 360      }
 361  }
 362  
 363  /**
 364   * Displays update information for a plugin.
 365   *
 366   * @param string $file        Plugin basename.
 367   * @param array  $plugin_data Plugin information.
 368   * @return false|void
 369   */
 370  function wp_plugin_update_row( $file, $plugin_data ) {
 371      $current = get_site_transient( 'update_plugins' );
 372      if ( ! isset( $current->response[ $file ] ) ) {
 373          return false;
 374      }
 375  
 376      $response = $current->response[ $file ];
 377  
 378      $plugins_allowedtags = array(
 379          'a'       => array(
 380              'href'  => array(),
 381              'title' => array(),
 382          ),
 383          'abbr'    => array( 'title' => array() ),
 384          'acronym' => array( 'title' => array() ),
 385          'code'    => array(),
 386          'em'      => array(),
 387          'strong'  => array(),
 388      );
 389  
 390      $plugin_name = wp_kses( $plugin_data['Name'], $plugins_allowedtags );
 391      $details_url = self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $response->slug . '&section=changelog&TB_iframe=true&width=600&height=800' );
 392  
 393      /** @var WP_Plugins_List_Table $wp_list_table */
 394      $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
 395  
 396      if ( is_network_admin() || ! is_multisite() ) {
 397          if ( is_network_admin() ) {
 398              $active_class = is_plugin_active_for_network( $file ) ? ' active' : '';
 399          } else {
 400              $active_class = is_plugin_active( $file ) ? ' active' : '';
 401          }
 402  
 403          $requires_php   = isset( $response->requires_php ) ? $response->requires_php : null;
 404          $compatible_php = is_php_version_compatible( $requires_php );
 405          $notice_type    = $compatible_php ? 'notice-warning' : 'notice-error';
 406  
 407          echo '<tr class="plugin-update-tr' . $active_class . '" id="' . esc_attr( $response->slug . '-update' ) . '" data-slug="' . esc_attr( $response->slug ) . '" data-plugin="' . esc_attr( $file ) . '"><td colspan="' . esc_attr( $wp_list_table->get_column_count() ) . '" class="plugin-update colspanchange"><div class="update-message notice inline ' . $notice_type . ' notice-alt"><p>';
 408  
 409          if ( ! current_user_can( 'update_plugins' ) ) {
 410              /* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number */
 411              printf(
 412                  __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ),
 413                  $plugin_name,
 414                  esc_url( $details_url ),
 415                  sprintf(
 416                      'class="thickbox open-plugin-details-modal" aria-label="%s"',
 417                      /* translators: 1: plugin name, 2: version number */
 418                      esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
 419                  ),
 420                  esc_attr( $response->new_version )
 421              );
 422          } elseif ( empty( $response->package ) ) {
 423              /* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number */
 424              printf(
 425                  __( '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>' ),
 426                  $plugin_name,
 427                  esc_url( $details_url ),
 428                  sprintf(
 429                      'class="thickbox open-plugin-details-modal" aria-label="%s"',
 430                      /* translators: 1: plugin name, 2: version number */
 431                      esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
 432                  ),
 433                  esc_attr( $response->new_version )
 434              );
 435          } else {
 436              if ( $compatible_php ) {
 437                  /* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number, 5: update URL, 6: additional link attributes */
 438                  printf(
 439                      __( '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>.' ),
 440                      $plugin_name,
 441                      esc_url( $details_url ),
 442                      sprintf(
 443                          'class="thickbox open-plugin-details-modal" aria-label="%s"',
 444                          /* translators: 1: plugin name, 2: version number */
 445                          esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
 446                      ),
 447                      esc_attr( $response->new_version ),
 448                      wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $file, 'upgrade-plugin_' . $file ),
 449                      sprintf(
 450                          'class="update-link" aria-label="%s"',
 451                          /* translators: %s: plugin name */
 452                          esc_attr( sprintf( __( 'Update %s now' ), $plugin_name ) )
 453                      )
 454                  );
 455              } else {
 456                  /* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number 5: Update PHP page URL */
 457                  printf(
 458                      __( '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>.' ),
 459                      $plugin_name,
 460                      esc_url( $details_url ),
 461                      sprintf(
 462                          'class="thickbox open-plugin-details-modal" aria-label="%s"',
 463                          /* translators: 1: plugin name, 2: version number */
 464                          esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
 465                      ),
 466                      esc_attr( $response->new_version ),
 467                      esc_url( wp_get_update_php_url() )
 468                  );
 469                  wp_update_php_annotation( '<br><em>', '</em>' );
 470              }
 471          }
 472  
 473          /**
 474           * Fires at the end of the update message container in each
 475           * row of the plugins list table.
 476           *
 477           * The dynamic portion of the hook name, `$file`, refers to the path
 478           * of the plugin's primary file relative to the plugins directory.
 479           *
 480           * @since 2.8.0
 481           *
 482           * @param array $plugin_data {
 483           *     An array of plugin metadata.
 484           *
 485           *     @type string $name        The human-readable name of the plugin.
 486           *     @type string $plugin_uri  Plugin URI.
 487           *     @type string $version     Plugin version.
 488           *     @type string $description Plugin description.
 489           *     @type string $author      Plugin author.
 490           *     @type string $author_uri  Plugin author URI.
 491           *     @type string $text_domain Plugin text domain.
 492           *     @type string $domain_path Relative path to the plugin's .mo file(s).
 493           *     @type bool   $network     Whether the plugin can only be activated network wide.
 494           *     @type string $title       The human-readable title of the plugin.
 495           *     @type string $author_name Plugin author's name.
 496           *     @type bool   $update      Whether there's an available update. Default null.
 497           * }
 498           * @param array $response {
 499           *     An array of metadata about the available plugin update.
 500           *
 501           *     @type int    $id          Plugin ID.
 502           *     @type string $slug        Plugin slug.
 503           *     @type string $new_version New plugin version.
 504           *     @type string $url         Plugin URL.
 505           *     @type string $package     Plugin update package URL.
 506           * }
 507           */
 508          do_action( "in_plugin_update_message-{$file}", $plugin_data, $response );
 509  
 510          echo '</p></div></td></tr>';
 511      }
 512  }
 513  
 514  /**
 515   * @return array
 516   */
 517  function get_theme_updates() {
 518      $current = get_site_transient( 'update_themes' );
 519  
 520      if ( ! isset( $current->response ) ) {
 521          return array();
 522      }
 523  
 524      $update_themes = array();
 525      foreach ( $current->response as $stylesheet => $data ) {
 526          $update_themes[ $stylesheet ]         = wp_get_theme( $stylesheet );
 527          $update_themes[ $stylesheet ]->update = $data;
 528      }
 529  
 530      return $update_themes;
 531  }
 532  
 533  /**
 534   * @since 3.1.0
 535   */
 536  function wp_theme_update_rows() {
 537      if ( ! current_user_can( 'update_themes' ) ) {
 538          return;
 539      }
 540  
 541      $themes = get_site_transient( 'update_themes' );
 542      if ( isset( $themes->response ) && is_array( $themes->response ) ) {
 543          $themes = array_keys( $themes->response );
 544  
 545          foreach ( $themes as $theme ) {
 546              add_action( "after_theme_row_$theme", 'wp_theme_update_row', 10, 2 );
 547          }
 548      }
 549  }
 550  
 551  /**
 552   * Displays update information for a theme.
 553   *
 554   * @param string   $theme_key Theme stylesheet.
 555   * @param WP_Theme $theme     Theme object.
 556   * @return false|void
 557   */
 558  function wp_theme_update_row( $theme_key, $theme ) {
 559      $current = get_site_transient( 'update_themes' );
 560  
 561      if ( ! isset( $current->response[ $theme_key ] ) ) {
 562          return false;
 563      }
 564  
 565      $response = $current->response[ $theme_key ];
 566  
 567      $details_url = add_query_arg(
 568          array(
 569              'TB_iframe' => 'true',
 570              'width'     => 1024,
 571              'height'    => 800,
 572          ),
 573          $current->response[ $theme_key ]['url']
 574      );
 575  
 576      /** @var WP_MS_Themes_List_Table $wp_list_table */
 577      $wp_list_table = _get_list_table( 'WP_MS_Themes_List_Table' );
 578  
 579      $active = $theme->is_allowed( 'network' ) ? ' active' : '';
 580  
 581      echo '<tr class="plugin-update-tr' . $active . '" id="' . esc_attr( $theme->get_stylesheet() . '-update' ) . '" data-slug="' . esc_attr( $theme->get_stylesheet() ) . '"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message notice inline notice-warning notice-alt"><p>';
 582      if ( ! current_user_can( 'update_themes' ) ) {
 583          /* translators: 1: theme name, 2: details URL, 3: additional link attributes, 4: version number */
 584          printf(
 585              __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ),
 586              $theme['Name'],
 587              esc_url( $details_url ),
 588              sprintf(
 589                  'class="thickbox open-plugin-details-modal" aria-label="%s"',
 590                  /* translators: 1: theme name, 2: version number */
 591                  esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
 592              ),
 593              $response['new_version']
 594          );
 595      } elseif ( empty( $response['package'] ) ) {
 596          /* translators: 1: theme name, 2: details URL, 3: additional link attributes, 4: version number */
 597          printf(
 598              __( '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>' ),
 599              $theme['Name'],
 600              esc_url( $details_url ),
 601              sprintf(
 602                  'class="thickbox open-plugin-details-modal" aria-label="%s"',
 603                  /* translators: 1: theme name, 2: version number */
 604                  esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
 605              ),
 606              $response['new_version']
 607          );
 608      } else {
 609          /* translators: 1: theme name, 2: details URL, 3: additional link attributes, 4: version number, 5: update URL, 6: additional link attributes */
 610          printf(
 611              __( '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>.' ),
 612              $theme['Name'],
 613              esc_url( $details_url ),
 614              sprintf(
 615                  'class="thickbox open-plugin-details-modal" aria-label="%s"',
 616                  /* translators: 1: theme name, 2: version number */
 617                  esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
 618              ),
 619              $response['new_version'],
 620              wp_nonce_url( self_admin_url( 'update.php?action=upgrade-theme&theme=' ) . $theme_key, 'upgrade-theme_' . $theme_key ),
 621              sprintf(
 622                  'class="update-link" aria-label="%s"',
 623                  /* translators: %s: theme name */
 624                  esc_attr( sprintf( __( 'Update %s now' ), $theme['Name'] ) )
 625              )
 626          );
 627      }
 628  
 629      /**
 630       * Fires at the end of the update message container in each
 631       * row of the themes list table.
 632       *
 633       * The dynamic portion of the hook name, `$theme_key`, refers to
 634       * the theme slug as found in the WordPress.org themes repository.
 635       *
 636       * @since 3.1.0
 637       *
 638       * @param WP_Theme $theme    The WP_Theme object.
 639       * @param array    $response {
 640       *     An array of metadata about the available theme update.
 641       *
 642       *     @type string $new_version New theme version.
 643       *     @type string $url         Theme URL.
 644       *     @type string $package     Theme update package URL.
 645       * }
 646       */
 647      do_action( "in_theme_update_message-{$theme_key}", $theme, $response );
 648  
 649      echo '</p></div></td></tr>';
 650  }
 651  
 652  /**
 653   * @global int $upgrading
 654   * @return false|void
 655   */
 656  function maintenance_nag() {
 657      include ( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
 658      global $upgrading;
 659      $nag = isset( $upgrading );
 660      if ( ! $nag ) {
 661          $failed = get_site_option( 'auto_core_update_failed' );
 662          /*
 663           * If an update failed critically, we may have copied over version.php but not other files.
 664           * In that case, if the installation claims we're running the version we attempted, nag.
 665           * This is serious enough to err on the side of nagging.
 666           *
 667           * If we simply failed to update before we tried to copy any files, then assume things are
 668           * OK if they are now running the latest.
 669           *
 670           * This flag is cleared whenever a successful update occurs using Core_Upgrader.
 671           */
 672          $comparison = ! empty( $failed['critical'] ) ? '>=' : '>';
 673          if ( version_compare( $failed['attempted'], $wp_version, $comparison ) ) {
 674              $nag = true;
 675          }
 676      }
 677  
 678      if ( ! $nag ) {
 679          return false;
 680      }
 681  
 682      if ( current_user_can( 'update_core' ) ) {
 683          $msg = sprintf( __( 'An automated WordPress update has failed to complete - <a href="%s">please attempt the update again now</a>.' ), 'update-core.php' );
 684      } else {
 685          $msg = __( 'An automated WordPress update has failed to complete! Please notify the site administrator.' );
 686      }
 687  
 688      echo "<div class='update-nag'>$msg</div>";
 689  }
 690  
 691  /**
 692   * Prints the JavaScript templates for update admin notices.
 693   *
 694   * Template takes one argument with four values:
 695   *
 696   *     param {object} data {
 697   *         Arguments for admin notice.
 698   *
 699   *         @type string id        ID of the notice.
 700   *         @type string className Class names for the notice.
 701   *         @type string message   The notice's message.
 702   *         @type string type      The type of update the notice is for. Either 'plugin' or 'theme'.
 703   *     }
 704   *
 705   * @since 4.6.0
 706   */
 707  function wp_print_admin_notice_templates() {
 708      ?>
 709      <script id="tmpl-wp-updates-admin-notice" type="text/html">
 710          <div <# if ( data.id ) { #>id="{{ data.id }}"<# } #> class="notice {{ data.className }}"><p>{{{ data.message }}}</p></div>
 711      </script>
 712      <script id="tmpl-wp-bulk-updates-admin-notice" type="text/html">
 713          <div id="{{ data.id }}" class="{{ data.className }} notice <# if ( data.errors ) { #>notice-error<# } else { #>notice-success<# } #>">
 714              <p>
 715                  <# if ( data.successes ) { #>
 716                      <# if ( 1 === data.successes ) { #>
 717                          <# if ( 'plugin' === data.type ) { #>
 718                              <?php
 719                              /* translators: %s: Number of plugins */
 720                              printf( __( '%s plugin successfully updated.' ), '{{ data.successes }}' );
 721                              ?>
 722                          <# } else { #>
 723                              <?php
 724                              /* translators: %s: Number of themes */
 725                              printf( __( '%s theme successfully updated.' ), '{{ data.successes }}' );
 726                              ?>
 727                          <# } #>
 728                      <# } else { #>
 729                          <# if ( 'plugin' === data.type ) { #>
 730                              <?php
 731                              /* translators: %s: Number of plugins */
 732                              printf( __( '%s plugins successfully updated.' ), '{{ data.successes }}' );
 733                              ?>
 734                          <# } else { #>
 735                              <?php
 736                              /* translators: %s: Number of themes */
 737                              printf( __( '%s themes successfully updated.' ), '{{ data.successes }}' );
 738                              ?>
 739                          <# } #>
 740                      <# } #>
 741                  <# } #>
 742                  <# if ( data.errors ) { #>
 743                      <button class="button-link bulk-action-errors-collapsed" aria-expanded="false">
 744                          <# if ( 1 === data.errors ) { #>
 745                              <?php
 746                              /* translators: %s: Number of failed updates */
 747                              printf( __( '%s update failed.' ), '{{ data.errors }}' );
 748                              ?>
 749                          <# } else { #>
 750                              <?php
 751                              /* translators: %s: Number of failed updates */
 752                              printf( __( '%s updates failed.' ), '{{ data.errors }}' );
 753                              ?>
 754                          <# } #>
 755                          <span class="screen-reader-text"><?php _e( 'Show more details' ); ?></span>
 756                          <span class="toggle-indicator" aria-hidden="true"></span>
 757                      </button>
 758                  <# } #>
 759              </p>
 760              <# if ( data.errors ) { #>
 761                  <ul class="bulk-action-errors hidden">
 762                      <# _.each( data.errorMessages, function( errorMessage ) { #>
 763                          <li>{{ errorMessage }}</li>
 764                      <# } ); #>
 765                  </ul>
 766              <# } #>
 767          </div>
 768      </script>
 769      <?php
 770  }
 771  
 772  /**
 773   * Prints the JavaScript templates for update and deletion rows in list tables.
 774   *
 775   * The update template takes one argument with four values:
 776   *
 777   *     param {object} data {
 778   *         Arguments for the update row
 779   *
 780   *         @type string slug    Plugin slug.
 781   *         @type string plugin  Plugin base name.
 782   *         @type string colspan The number of table columns this row spans.
 783   *         @type string content The row content.
 784   *     }
 785   *
 786   * The delete template takes one argument with four values:
 787   *
 788   *     param {object} data {
 789   *         Arguments for the update row
 790   *
 791   *         @type string slug    Plugin slug.
 792   *         @type string plugin  Plugin base name.
 793   *         @type string name    Plugin name.
 794   *         @type string colspan The number of table columns this row spans.
 795   *     }
 796   *
 797   * @since 4.6.0
 798   */
 799  function wp_print_update_row_templates() {
 800      ?>
 801      <script id="tmpl-item-update-row" type="text/template">
 802          <tr class="plugin-update-tr update" id="{{ data.slug }}-update" data-slug="{{ data.slug }}" <# if ( data.plugin ) { #>data-plugin="{{ data.plugin }}"<# } #>>
 803              <td colspan="{{ data.colspan }}" class="plugin-update colspanchange">
 804                  {{{ data.content }}}
 805              </td>
 806          </tr>
 807      </script>
 808      <script id="tmpl-item-deleted-row" type="text/template">
 809          <tr class="plugin-deleted-tr inactive deleted" id="{{ data.slug }}-deleted" data-slug="{{ data.slug }}" <# if ( data.plugin ) { #>data-plugin="{{ data.plugin }}"<# } #>>
 810              <td colspan="{{ data.colspan }}" class="plugin-update colspanchange">
 811                  <# if ( data.plugin ) { #>
 812                      <?php
 813                      printf(
 814                          /* translators: %s: Plugin name */
 815                          _x( '%s was successfully deleted.', 'plugin' ),
 816                          '<strong>{{{ data.name }}}</strong>'
 817                      );
 818                      ?>
 819                  <# } else { #>
 820                      <?php
 821                      printf(
 822                          /* translators: %s: Theme name */
 823                          _x( '%s was successfully deleted.', 'theme' ),
 824                          '<strong>{{{ data.name }}}</strong>'
 825                      );
 826                      ?>
 827                  <# } #>
 828              </td>
 829          </tr>
 830      </script>
 831      <?php
 832  }
 833  
 834  /**
 835   * Displays a notice when the user is in recovery mode.
 836   *
 837   * @since 5.2.0
 838   */
 839  function wp_recovery_mode_nag() {
 840      if ( ! wp_is_recovery_mode() ) {
 841          return;
 842      }
 843  
 844      ?>
 845      <div class="notice notice-info">
 846          <p>
 847              <?php esc_html_e( '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.' ); ?>
 848          </p>
 849      </div>
 850      <?php
 851  }


Generated: Tue May 21 08:20:01 2019 Cross-referenced by PHPXref 0.7