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


Generated: Mon Nov 18 01:00:04 2019 Cross-referenced by PHPXref 0.7.1