[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/includes/ -> plugin-install.php (source)

   1  <?php
   2  /**
   3   * WordPress Plugin Install Administration API
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  /**
  10   * Retrieves plugin installer pages from the WordPress.org Plugins API.
  11   *
  12   * It is possible for a plugin to override the Plugin API result with three
  13   * filters. Assume this is for plugins, which can extend on the Plugin Info to
  14   * offer more choices. This is very powerful and must be used with care when
  15   * overriding the filters.
  16   *
  17   * The first filter, {@see 'plugins_api_args'}, is for the args and gives the action
  18   * as the second parameter. The hook for {@see 'plugins_api_args'} must ensure that
  19   * an object is returned.
  20   *
  21   * The second filter, {@see 'plugins_api'}, allows a plugin to override the WordPress.org
  22   * Plugin Installation API entirely. If `$action` is 'query_plugins' or 'plugin_information',
  23   * an object MUST be passed. If `$action` is 'hot_tags' or 'hot_categories', an array MUST
  24   * be passed.
  25   *
  26   * Finally, the third filter, {@see 'plugins_api_result'}, makes it possible to filter the
  27   * response object or array, depending on the `$action` type.
  28   *
  29   * Supported arguments per action:
  30   *
  31   * | Argument Name        | query_plugins | plugin_information | hot_tags | hot_categories |
  32   * | -------------------- | :-----------: | :----------------: | :------: | :------------: |
  33   * | `$slug`              | No            |  Yes               | No       | No             |
  34   * | `$per_page`          | Yes           |  No                | No       | No             |
  35   * | `$page`              | Yes           |  No                | No       | No             |
  36   * | `$number`            | No            |  No                | Yes      | Yes            |
  37   * | `$search`            | Yes           |  No                | No       | No             |
  38   * | `$tag`               | Yes           |  No                | No       | No             |
  39   * | `$author`            | Yes           |  No                | No       | No             |
  40   * | `$user`              | Yes           |  No                | No       | No             |
  41   * | `$browse`            | Yes           |  No                | No       | No             |
  42   * | `$locale`            | Yes           |  Yes               | No       | No             |
  43   * | `$installed_plugins` | Yes           |  No                | No       | No             |
  44   * | `$is_ssl`            | Yes           |  Yes               | No       | No             |
  45   * | `$fields`            | Yes           |  Yes               | No       | No             |
  46   *
  47   * @since 2.7.0
  48   *
  49   * @param string       $action API action to perform: 'query_plugins', 'plugin_information',
  50   *                             'hot_tags' or 'hot_categories'.
  51   * @param array|object $args   {
  52   *     Optional. Array or object of arguments to serialize for the Plugin Info API.
  53   *
  54   *     @type string  $slug              The plugin slug. Default empty.
  55   *     @type int     $per_page          Number of plugins per page. Default 24.
  56   *     @type int     $page              Number of current page. Default 1.
  57   *     @type int     $number            Number of tags or categories to be queried.
  58   *     @type string  $search            A search term. Default empty.
  59   *     @type string  $tag               Tag to filter plugins. Default empty.
  60   *     @type string  $author            Username of an plugin author to filter plugins. Default empty.
  61   *     @type string  $user              Username to query for their favorites. Default empty.
  62   *     @type string  $browse            Browse view: 'popular', 'new', 'beta', 'recommended'.
  63   *     @type string  $locale            Locale to provide context-sensitive results. Default is the value
  64   *                                      of get_locale().
  65   *     @type string  $installed_plugins Installed plugins to provide context-sensitive results.
  66   *     @type bool    $is_ssl            Whether links should be returned with https or not. Default false.
  67   *     @type array   $fields            {
  68   *         Array of fields which should or should not be returned.
  69   *
  70   *         @type bool $short_description Whether to return the plugin short description. Default true.
  71   *         @type bool $description       Whether to return the plugin full description. Default false.
  72   *         @type bool $sections          Whether to return the plugin readme sections: description, installation,
  73   *                                       FAQ, screenshots, other notes, and changelog. Default false.
  74   *         @type bool $tested            Whether to return the 'Compatible up to' value. Default true.
  75   *         @type bool $requires          Whether to return the required WordPress version. Default true.
  76   *         @type bool $rating            Whether to return the rating in percent and total number of ratings.
  77   *                                       Default true.
  78   *         @type bool $ratings           Whether to return the number of rating for each star (1-5). Default true.
  79   *         @type bool $downloaded        Whether to return the download count. Default true.
  80   *         @type bool $downloadlink      Whether to return the download link for the package. Default true.
  81   *         @type bool $last_updated      Whether to return the date of the last update. Default true.
  82   *         @type bool $added             Whether to return the date when the plugin was added to the wordpress.org
  83   *                                       repository. Default true.
  84   *         @type bool $tags              Whether to return the assigned tags. Default true.
  85   *         @type bool $compatibility     Whether to return the WordPress compatibility list. Default true.
  86   *         @type bool $homepage          Whether to return the plugin homepage link. Default true.
  87   *         @type bool $versions          Whether to return the list of all available versions. Default false.
  88   *         @type bool $donate_link       Whether to return the donation link. Default true.
  89   *         @type bool $reviews           Whether to return the plugin reviews. Default false.
  90   *         @type bool $banners           Whether to return the banner images links. Default false.
  91   *         @type bool $icons             Whether to return the icon links. Default false.
  92   *         @type bool $active_installs   Whether to return the number of active installations. Default false.
  93   *         @type bool $group             Whether to return the assigned group. Default false.
  94   *         @type bool $contributors      Whether to return the list of contributors. Default false.
  95   *     }
  96   * }
  97   * @return object|array|WP_Error Response object or array on success, WP_Error on failure. See the
  98   *         {@link https://developer.wordpress.org/reference/functions/plugins_api/ function reference article}
  99   *         for more information on the make-up of possible return values depending on the value of `$action`.
 100   */
 101  function plugins_api( $action, $args = array() ) {
 102      // include an unmodified $wp_version
 103      include ( ABSPATH . WPINC . '/version.php' );
 104  
 105      if ( is_array( $args ) ) {
 106          $args = (object) $args;
 107      }
 108  
 109      if ( 'query_plugins' == $action ) {
 110          if ( ! isset( $args->per_page ) ) {
 111              $args->per_page = 24;
 112          }
 113      }
 114  
 115      if ( ! isset( $args->locale ) ) {
 116          $args->locale = get_user_locale();
 117      }
 118  
 119      if ( ! isset( $args->wp_version ) ) {
 120          $args->wp_version = substr( $wp_version, 0, 3 ); // X.y
 121      }
 122  
 123      /**
 124       * Filters the WordPress.org Plugin Installation API arguments.
 125       *
 126       * Important: An object MUST be returned to this filter.
 127       *
 128       * @since 2.7.0
 129       *
 130       * @param object $args   Plugin API arguments.
 131       * @param string $action The type of information being requested from the Plugin Installation API.
 132       */
 133      $args = apply_filters( 'plugins_api_args', $args, $action );
 134  
 135      /**
 136       * Filters the response for the current WordPress.org Plugin Installation API request.
 137       *
 138       * Passing a non-false value will effectively short-circuit the WordPress.org API request.
 139       *
 140       * If `$action` is 'query_plugins' or 'plugin_information', an object MUST be passed.
 141       * If `$action` is 'hot_tags' or 'hot_categories', an array should be passed.
 142       *
 143       * @since 2.7.0
 144       *
 145       * @param false|object|array $result The result object or array. Default false.
 146       * @param string             $action The type of information being requested from the Plugin Installation API.
 147       * @param object             $args   Plugin API arguments.
 148       */
 149      $res = apply_filters( 'plugins_api', false, $action, $args );
 150  
 151      if ( false === $res ) {
 152  
 153          $url = 'http://api.wordpress.org/plugins/info/1.2/';
 154          $url = add_query_arg(
 155              array(
 156                  'action'  => $action,
 157                  'request' => $args,
 158              ),
 159              $url
 160          );
 161  
 162          $http_url = $url;
 163          $ssl      = wp_http_supports( array( 'ssl' ) );
 164          if ( $ssl ) {
 165              $url = set_url_scheme( $url, 'https' );
 166          }
 167  
 168          $http_args = array(
 169              'timeout'    => 15,
 170              'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
 171          );
 172          $request   = wp_remote_get( $url, $http_args );
 173  
 174          if ( $ssl && is_wp_error( $request ) ) {
 175              trigger_error(
 176                  sprintf(
 177                      /* translators: %s: Support forums URL. */
 178                      __( '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>.' ),
 179                      __( 'https://wordpress.org/support/forums/' )
 180                  ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
 181                  headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
 182              );
 183              $request = wp_remote_get( $http_url, $http_args );
 184          }
 185  
 186          if ( is_wp_error( $request ) ) {
 187              $res = new WP_Error(
 188                  'plugins_api_failed',
 189                  sprintf(
 190                      /* translators: %s: Support forums URL. */
 191                      __( '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>.' ),
 192                      __( 'https://wordpress.org/support/forums/' )
 193                  ),
 194                  $request->get_error_message()
 195              );
 196          } else {
 197              $res = json_decode( wp_remote_retrieve_body( $request ), true );
 198              if ( is_array( $res ) ) {
 199                  // Object casting is required in order to match the info/1.0 format.
 200                  $res = (object) $res;
 201              } elseif ( null === $res ) {
 202                  $res = new WP_Error(
 203                      'plugins_api_failed',
 204                      sprintf(
 205                          /* translators: %s: Support forums URL. */
 206                          __( '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>.' ),
 207                          __( 'https://wordpress.org/support/forums/' )
 208                      ),
 209                      wp_remote_retrieve_body( $request )
 210                  );
 211              }
 212  
 213              if ( isset( $res->error ) ) {
 214                  $res = new WP_Error( 'plugins_api_failed', $res->error );
 215              }
 216          }
 217      } elseif ( ! is_wp_error( $res ) ) {
 218          $res->external = true;
 219      }
 220  
 221      /**
 222       * Filters the Plugin Installation API response results.
 223       *
 224       * @since 2.7.0
 225       *
 226       * @param object|WP_Error $res    Response object or WP_Error.
 227       * @param string          $action The type of information being requested from the Plugin Installation API.
 228       * @param object          $args   Plugin API arguments.
 229       */
 230      return apply_filters( 'plugins_api_result', $res, $action, $args );
 231  }
 232  
 233  /**
 234   * Retrieve popular WordPress plugin tags.
 235   *
 236   * @since 2.7.0
 237   *
 238   * @param array $args
 239   * @return array
 240   */
 241  function install_popular_tags( $args = array() ) {
 242      $key  = md5( serialize( $args ) );
 243      $tags = get_site_transient( 'poptags_' . $key );
 244      if ( false !== $tags ) {
 245          return $tags;
 246      }
 247  
 248      $tags = plugins_api( 'hot_tags', $args );
 249  
 250      if ( is_wp_error( $tags ) ) {
 251          return $tags;
 252      }
 253  
 254      set_site_transient( 'poptags_' . $key, $tags, 3 * HOUR_IN_SECONDS );
 255  
 256      return $tags;
 257  }
 258  
 259  /**
 260   * @since 2.7.0
 261   */
 262  function install_dashboard() {
 263      ?>
 264      <p>
 265          <?php
 266          printf(
 267              /* translators: %s: https://wordpress.org/plugins/ */
 268              __( 'Plugins extend and expand the functionality of WordPress. You may automatically install plugins from the <a href="%s">WordPress Plugin Directory</a> or upload a plugin in .zip format by clicking the button at the top of this page.' ),
 269              __( 'https://wordpress.org/plugins/' )
 270          );
 271          ?>
 272      </p>
 273  
 274      <?php display_plugins_table(); ?>
 275  
 276      <div class="plugins-popular-tags-wrapper">
 277      <h2><?php _e( 'Popular tags' ); ?></h2>
 278      <p><?php _e( 'You may also browse based on the most popular tags in the Plugin Directory:' ); ?></p>
 279      <?php
 280  
 281      $api_tags = install_popular_tags();
 282  
 283      echo '<p class="popular-tags">';
 284      if ( is_wp_error( $api_tags ) ) {
 285          echo $api_tags->get_error_message();
 286      } else {
 287          //Set up the tags in a way which can be interpreted by wp_generate_tag_cloud()
 288          $tags = array();
 289          foreach ( (array) $api_tags as $tag ) {
 290              $url                  = self_admin_url( 'plugin-install.php?tab=search&type=tag&s=' . urlencode( $tag['name'] ) );
 291              $data                 = array(
 292                  'link'  => esc_url( $url ),
 293                  'name'  => $tag['name'],
 294                  'slug'  => $tag['slug'],
 295                  'id'    => sanitize_title_with_dashes( $tag['name'] ),
 296                  'count' => $tag['count'],
 297              );
 298              $tags[ $tag['name'] ] = (object) $data;
 299          }
 300          echo wp_generate_tag_cloud(
 301              $tags,
 302              array(
 303                  /* translators: %s: Number of plugins. */
 304                  'single_text'   => __( '%s plugin' ),
 305                  /* translators: %s: Number of plugins. */
 306                  'multiple_text' => __( '%s plugins' ),
 307              )
 308          );
 309      }
 310      echo '</p><br class="clear" /></div>';
 311  }
 312  
 313  /**
 314   * Displays a search form for searching plugins.
 315   *
 316   * @since 2.7.0
 317   * @since 4.6.0 The `$type_selector` parameter was deprecated.
 318   *
 319   * @param bool $deprecated Not used.
 320   */
 321  function install_search_form( $deprecated = true ) {
 322      $type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
 323      $term = isset( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : '';
 324      ?>
 325      <form class="search-form search-plugins" method="get">
 326          <input type="hidden" name="tab" value="search" />
 327          <label class="screen-reader-text" for="typeselector"><?php _e( 'Search plugins by:' ); ?></label>
 328          <select name="type" id="typeselector">
 329              <option value="term"<?php selected( 'term', $type ); ?>><?php _e( 'Keyword' ); ?></option>
 330              <option value="author"<?php selected( 'author', $type ); ?>><?php _e( 'Author' ); ?></option>
 331              <option value="tag"<?php selected( 'tag', $type ); ?>><?php _ex( 'Tag', 'Plugin Installer' ); ?></option>
 332          </select>
 333          <label><span class="screen-reader-text"><?php _e( 'Search Plugins' ); ?></span>
 334              <input type="search" name="s" value="<?php echo esc_attr( $term ); ?>" class="wp-filter-search" placeholder="<?php esc_attr_e( 'Search plugins...' ); ?>" />
 335          </label>
 336          <?php submit_button( __( 'Search Plugins' ), 'hide-if-js', false, false, array( 'id' => 'search-submit' ) ); ?>
 337      </form>
 338      <?php
 339  }
 340  
 341  /**
 342   * Upload from zip
 343   *
 344   * @since 2.8.0
 345   */
 346  function install_plugins_upload() {
 347      ?>
 348  <div class="upload-plugin">
 349      <p class="install-help"><?php _e( 'If you have a plugin in a .zip format, you may install it by uploading it here.' ); ?></p>
 350      <form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo self_admin_url( 'update.php?action=upload-plugin' ); ?>">
 351          <?php wp_nonce_field( 'plugin-upload' ); ?>
 352          <label class="screen-reader-text" for="pluginzip"><?php _e( 'Plugin zip file' ); ?></label>
 353          <input type="file" id="pluginzip" name="pluginzip" />
 354          <?php submit_button( __( 'Install Now' ), '', 'install-plugin-submit', false ); ?>
 355      </form>
 356  </div>
 357      <?php
 358  }
 359  
 360  /**
 361   * Show a username form for the favorites page
 362   *
 363   * @since 3.5.0
 364   */
 365  function install_plugins_favorites_form() {
 366      $user   = get_user_option( 'wporg_favorites' );
 367      $action = 'save_wporg_username_' . get_current_user_id();
 368      ?>
 369      <p class="install-help"><?php _e( 'If you have marked plugins as favorites on WordPress.org, you can browse them here.' ); ?></p>
 370      <form method="get">
 371          <input type="hidden" name="tab" value="favorites" />
 372          <p>
 373              <label for="user"><?php _e( 'Your WordPress.org username:' ); ?></label>
 374              <input type="search" id="user" name="user" value="<?php echo esc_attr( $user ); ?>" />
 375              <input type="submit" class="button" value="<?php esc_attr_e( 'Get Favorites' ); ?>" />
 376              <input type="hidden" id="wporg-username-nonce" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( $action ) ); ?>" />
 377          </p>
 378      </form>
 379      <?php
 380  }
 381  
 382  /**
 383   * Display plugin content based on plugin list.
 384   *
 385   * @since 2.7.0
 386   *
 387   * @global WP_List_Table $wp_list_table
 388   */
 389  function display_plugins_table() {
 390      global $wp_list_table;
 391  
 392      switch ( current_filter() ) {
 393          case 'install_plugins_favorites':
 394              if ( empty( $_GET['user'] ) && ! get_user_option( 'wporg_favorites' ) ) {
 395                  return;
 396              }
 397              break;
 398          case 'install_plugins_recommended':
 399              echo '<p>' . __( 'These suggestions are based on the plugins you and other users have installed.' ) . '</p>';
 400              break;
 401          case 'install_plugins_beta':
 402              printf(
 403                  /* translators: %s: URL to "Features as Plugins" page. */
 404                  '<p>' . __( 'You are using a development version of WordPress. These feature plugins are also under development. <a href="%s">Learn more</a>.' ) . '</p>',
 405                  'https://make.wordpress.org/core/handbook/about/release-cycle/features-as-plugins/'
 406              );
 407              break;
 408      }
 409  
 410      ?>
 411      <form id="plugin-filter" method="post">
 412          <?php $wp_list_table->display(); ?>
 413      </form>
 414      <?php
 415  }
 416  
 417  /**
 418   * Determine the status we can perform on a plugin.
 419   *
 420   * @since 3.0.0
 421   *
 422   * @param  array|object $api  Data about the plugin retrieved from the API.
 423   * @param  bool         $loop Optional. Disable further loops. Default false.
 424   * @return array {
 425   *     Plugin installation status data.
 426   *
 427   *     @type string $status  Status of a plugin. Could be one of 'install', 'update_available', 'latest_installed' or 'newer_installed'.
 428   *     @type string $url     Plugin installation URL.
 429   *     @type string $version The most recent version of the plugin.
 430   *     @type string $file    Plugin filename relative to the plugins directory.
 431   * }
 432   */
 433  function install_plugin_install_status( $api, $loop = false ) {
 434      // This function is called recursively, $loop prevents further loops.
 435      if ( is_array( $api ) ) {
 436          $api = (object) $api;
 437      }
 438  
 439      // Default to a "new" plugin
 440      $status      = 'install';
 441      $url         = false;
 442      $update_file = false;
 443      $version     = '';
 444  
 445      /*
 446       * Check to see if this plugin is known to be installed,
 447       * and has an update awaiting it.
 448       */
 449      $update_plugins = get_site_transient( 'update_plugins' );
 450      if ( isset( $update_plugins->response ) ) {
 451          foreach ( (array) $update_plugins->response as $file => $plugin ) {
 452              if ( $plugin->slug === $api->slug ) {
 453                  $status      = 'update_available';
 454                  $update_file = $file;
 455                  $version     = $plugin->new_version;
 456                  if ( current_user_can( 'update_plugins' ) ) {
 457                      $url = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' . $update_file ), 'upgrade-plugin_' . $update_file );
 458                  }
 459                  break;
 460              }
 461          }
 462      }
 463  
 464      if ( 'install' == $status ) {
 465          if ( is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) {
 466              $installed_plugin = get_plugins( '/' . $api->slug );
 467              if ( empty( $installed_plugin ) ) {
 468                  if ( current_user_can( 'install_plugins' ) ) {
 469                      $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug );
 470                  }
 471              } else {
 472                  $key         = array_keys( $installed_plugin );
 473                  $key         = reset( $key ); //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers
 474                  $update_file = $api->slug . '/' . $key;
 475                  if ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '=' ) ) {
 476                      $status = 'latest_installed';
 477                  } elseif ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '<' ) ) {
 478                      $status  = 'newer_installed';
 479                      $version = $installed_plugin[ $key ]['Version'];
 480                  } else {
 481                      //If the above update check failed, Then that probably means that the update checker has out-of-date information, force a refresh
 482                      if ( ! $loop ) {
 483                          delete_site_transient( 'update_plugins' );
 484                          wp_update_plugins();
 485                          return install_plugin_install_status( $api, true );
 486                      }
 487                  }
 488              }
 489          } else {
 490              // "install" & no directory with that slug
 491              if ( current_user_can( 'install_plugins' ) ) {
 492                  $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug );
 493              }
 494          }
 495      }
 496      if ( isset( $_GET['from'] ) ) {
 497          $url .= '&amp;from=' . urlencode( wp_unslash( $_GET['from'] ) );
 498      }
 499  
 500      $file = $update_file;
 501      return compact( 'status', 'url', 'version', 'file' );
 502  }
 503  
 504  /**
 505   * Display plugin information in dialog box form.
 506   *
 507   * @since 2.7.0
 508   *
 509   * @global string $tab
 510   */
 511  function install_plugin_information() {
 512      global $tab;
 513  
 514      if ( empty( $_REQUEST['plugin'] ) ) {
 515          return;
 516      }
 517  
 518      $api = plugins_api(
 519          'plugin_information',
 520          array(
 521              'slug' => wp_unslash( $_REQUEST['plugin'] ),
 522          )
 523      );
 524  
 525      if ( is_wp_error( $api ) ) {
 526          wp_die( $api );
 527      }
 528  
 529      $plugins_allowedtags = array(
 530          'a'          => array(
 531              'href'   => array(),
 532              'title'  => array(),
 533              'target' => array(),
 534          ),
 535          'abbr'       => array( 'title' => array() ),
 536          'acronym'    => array( 'title' => array() ),
 537          'code'       => array(),
 538          'pre'        => array(),
 539          'em'         => array(),
 540          'strong'     => array(),
 541          'div'        => array( 'class' => array() ),
 542          'span'       => array( 'class' => array() ),
 543          'p'          => array(),
 544          'br'         => array(),
 545          'ul'         => array(),
 546          'ol'         => array(),
 547          'li'         => array(),
 548          'h1'         => array(),
 549          'h2'         => array(),
 550          'h3'         => array(),
 551          'h4'         => array(),
 552          'h5'         => array(),
 553          'h6'         => array(),
 554          'img'        => array(
 555              'src'   => array(),
 556              'class' => array(),
 557              'alt'   => array(),
 558          ),
 559          'blockquote' => array( 'cite' => true ),
 560      );
 561  
 562      $plugins_section_titles = array(
 563          'description'  => _x( 'Description', 'Plugin installer section title' ),
 564          'installation' => _x( 'Installation', 'Plugin installer section title' ),
 565          'faq'          => _x( 'FAQ', 'Plugin installer section title' ),
 566          'screenshots'  => _x( 'Screenshots', 'Plugin installer section title' ),
 567          'changelog'    => _x( 'Changelog', 'Plugin installer section title' ),
 568          'reviews'      => _x( 'Reviews', 'Plugin installer section title' ),
 569          'other_notes'  => _x( 'Other Notes', 'Plugin installer section title' ),
 570      );
 571  
 572      // Sanitize HTML
 573      foreach ( (array) $api->sections as $section_name => $content ) {
 574          $api->sections[ $section_name ] = wp_kses( $content, $plugins_allowedtags );
 575      }
 576  
 577      foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) {
 578          if ( isset( $api->$key ) ) {
 579              $api->$key = wp_kses( $api->$key, $plugins_allowedtags );
 580          }
 581      }
 582  
 583      $_tab = esc_attr( $tab );
 584  
 585      $section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; // Default to the Description tab, Do not translate, API returns English.
 586      if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) {
 587          $section_titles = array_keys( (array) $api->sections );
 588          $section        = reset( $section_titles );
 589      }
 590  
 591      iframe_header( __( 'Plugin Installation' ) );
 592  
 593      $_with_banner = '';
 594  
 595      if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) {
 596          $_with_banner = 'with-banner';
 597          $low          = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low'];
 598          $high         = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high'];
 599          ?>
 600          <style type="text/css">
 601              #plugin-information-title.with-banner {
 602                  background-image: url( <?php echo esc_url( $low ); ?> );
 603              }
 604              @media only screen and ( -webkit-min-device-pixel-ratio: 1.5 ) {
 605                  #plugin-information-title.with-banner {
 606                      background-image: url( <?php echo esc_url( $high ); ?> );
 607                  }
 608              }
 609          </style>
 610          <?php
 611      }
 612  
 613      echo '<div id="plugin-information-scrollable">';
 614      echo "<div id='{$_tab}-title' class='{$_with_banner}'><div class='vignette'></div><h2>{$api->name}</h2></div>";
 615      echo "<div id='{$_tab}-tabs' class='{$_with_banner}'>\n";
 616  
 617      foreach ( (array) $api->sections as $section_name => $content ) {
 618          if ( 'reviews' === $section_name && ( empty( $api->ratings ) || 0 === array_sum( (array) $api->ratings ) ) ) {
 619              continue;
 620          }
 621  
 622          if ( isset( $plugins_section_titles[ $section_name ] ) ) {
 623              $title = $plugins_section_titles[ $section_name ];
 624          } else {
 625              $title = ucwords( str_replace( '_', ' ', $section_name ) );
 626          }
 627  
 628          $class       = ( $section_name === $section ) ? ' class="current"' : '';
 629          $href        = add_query_arg(
 630              array(
 631                  'tab'     => $tab,
 632                  'section' => $section_name,
 633              )
 634          );
 635          $href        = esc_url( $href );
 636          $san_section = esc_attr( $section_name );
 637          echo "\t<a name='$san_section' href='$href' $class>$title</a>\n";
 638      }
 639  
 640      echo "</div>\n";
 641  
 642      ?>
 643  <div id="<?php echo $_tab; ?>-content" class='<?php echo $_with_banner; ?>'>
 644      <div class="fyi">
 645          <ul>
 646              <?php if ( ! empty( $api->version ) ) { ?>
 647                  <li><strong><?php _e( 'Version:' ); ?></strong> <?php echo $api->version; ?></li>
 648              <?php } if ( ! empty( $api->author ) ) { ?>
 649                  <li><strong><?php _e( 'Author:' ); ?></strong> <?php echo links_add_target( $api->author, '_blank' ); ?></li>
 650              <?php } if ( ! empty( $api->last_updated ) ) { ?>
 651                  <li><strong><?php _e( 'Last Updated:' ); ?></strong>
 652                      <?php
 653                      /* translators: %s: Human-readable time difference. */
 654                      printf( __( '%s ago' ), human_time_diff( strtotime( $api->last_updated ) ) );
 655                      ?>
 656                  </li>
 657              <?php } if ( ! empty( $api->requires ) ) { ?>
 658                  <li>
 659                      <strong><?php _e( 'Requires WordPress Version:' ); ?></strong>
 660                      <?php
 661                      /* translators: %s: Version number. */
 662                      printf( __( '%s or higher' ), $api->requires );
 663                      ?>
 664                  </li>
 665              <?php } if ( ! empty( $api->tested ) ) { ?>
 666                  <li><strong><?php _e( 'Compatible up to:' ); ?></strong> <?php echo $api->tested; ?></li>
 667              <?php } if ( ! empty( $api->requires_php ) ) { ?>
 668                  <li>
 669                      <strong><?php _e( 'Requires PHP Version:' ); ?></strong>
 670                      <?php
 671                      /* translators: %s: Version number. */
 672                      printf( __( '%s or higher' ), $api->requires_php );
 673                      ?>
 674                  </li>
 675              <?php } if ( isset( $api->active_installs ) ) { ?>
 676                  <li><strong><?php _e( 'Active Installations:' ); ?></strong>
 677                  <?php
 678                  if ( $api->active_installs >= 1000000 ) {
 679                      $active_installs_millions = floor( $api->active_installs / 1000000 );
 680                      printf(
 681                          /* translators: %s: Number of millions. */
 682                          _nx( '%s+ Million', '%s+ Million', $active_installs_millions, 'Active plugin installations' ),
 683                          number_format_i18n( $active_installs_millions )
 684                      );
 685                  } elseif ( 0 == $api->active_installs ) {
 686                      _ex( 'Less Than 10', 'Active plugin installations' );
 687                  } else {
 688                      echo number_format_i18n( $api->active_installs ) . '+';
 689                  }
 690                  ?>
 691                  </li>
 692              <?php } if ( ! empty( $api->slug ) && empty( $api->external ) ) { ?>
 693                  <li><a target="_blank" href="<?php echo __( 'https://wordpress.org/plugins/' ) . $api->slug; ?>/"><?php _e( 'WordPress.org Plugin Page &#187;' ); ?></a></li>
 694              <?php } if ( ! empty( $api->homepage ) ) { ?>
 695                  <li><a target="_blank" href="<?php echo esc_url( $api->homepage ); ?>"><?php _e( 'Plugin Homepage &#187;' ); ?></a></li>
 696              <?php } if ( ! empty( $api->donate_link ) && empty( $api->contributors ) ) { ?>
 697                  <li><a target="_blank" href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a></li>
 698              <?php } ?>
 699          </ul>
 700          <?php if ( ! empty( $api->rating ) ) { ?>
 701              <h3><?php _e( 'Average Rating' ); ?></h3>
 702              <?php
 703              wp_star_rating(
 704                  array(
 705                      'rating' => $api->rating,
 706                      'type'   => 'percent',
 707                      'number' => $api->num_ratings,
 708                  )
 709              );
 710              ?>
 711              <p aria-hidden="true" class="fyi-description">
 712                  <?php
 713                  printf(
 714                      /* translators: %s: Number of ratings. */
 715                      _n( '(based on %s rating)', '(based on %s ratings)', $api->num_ratings ),
 716                      number_format_i18n( $api->num_ratings )
 717                  );
 718                  ?>
 719              </p>
 720              <?php
 721          }
 722  
 723          if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) {
 724              ?>
 725              <h3><?php _e( 'Reviews' ); ?></h3>
 726              <p class="fyi-description"><?php _e( 'Read all reviews on WordPress.org or write your own!' ); ?></p>
 727              <?php
 728              foreach ( $api->ratings as $key => $ratecount ) {
 729                  // Avoid div-by-zero.
 730                  $_rating    = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0;
 731                  $aria_label = esc_attr(
 732                      sprintf(
 733                          /* translators: 1: Number of stars (used to determine singular/plural), 2: Number of reviews. */
 734                          _n(
 735                              'Reviews with %1$d star: %2$s. Opens in a new tab.',
 736                              'Reviews with %1$d stars: %2$s. Opens in a new tab.',
 737                              $key
 738                          ),
 739                          $key,
 740                          number_format_i18n( $ratecount )
 741                      )
 742                  );
 743                  ?>
 744                  <div class="counter-container">
 745                          <span class="counter-label">
 746                              <?php
 747                              printf(
 748                                  '<a href="%s" target="_blank" aria-label="%s">%s</a>',
 749                                  "https://wordpress.org/support/plugin/{$api->slug}/reviews/?filter={$key}",
 750                                  $aria_label,
 751                                  /* translators: %s: Number of stars. */
 752                                  sprintf( _n( '%d star', '%d stars', $key ), $key )
 753                              );
 754                              ?>
 755                          </span>
 756                          <span class="counter-back">
 757                              <span class="counter-bar" style="width: <?php echo 92 * $_rating; ?>px;"></span>
 758                          </span>
 759                      <span class="counter-count" aria-hidden="true"><?php echo number_format_i18n( $ratecount ); ?></span>
 760                  </div>
 761                  <?php
 762              }
 763          }
 764          if ( ! empty( $api->contributors ) ) {
 765              ?>
 766              <h3><?php _e( 'Contributors' ); ?></h3>
 767              <ul class="contributors">
 768                  <?php
 769                  foreach ( (array) $api->contributors as $contrib_username => $contrib_details ) {
 770                      $contrib_name = $contrib_details['display_name'];
 771                      if ( ! $contrib_name ) {
 772                          $contrib_name = $contrib_username;
 773                      }
 774                      $contrib_name = esc_html( $contrib_name );
 775  
 776                      $contrib_profile = esc_url( $contrib_details['profile'] );
 777                      $contrib_avatar  = esc_url( add_query_arg( 's', '36', $contrib_details['avatar'] ) );
 778  
 779                      echo "<li><a href='{$contrib_profile}' target='_blank'><img src='{$contrib_avatar}' width='18' height='18' alt='' />{$contrib_name}</a></li>";
 780                  }
 781                  ?>
 782              </ul>
 783                      <?php if ( ! empty( $api->donate_link ) ) { ?>
 784                  <a target="_blank" href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a>
 785              <?php } ?>
 786                  <?php } ?>
 787      </div>
 788      <div id="section-holder">
 789      <?php
 790      $requires_php = isset( $api->requires_php ) ? $api->requires_php : null;
 791      $requires_wp  = isset( $api->requires ) ? $api->requires : null;
 792  
 793      $compatible_php = is_php_version_compatible( $requires_php );
 794      $compatible_wp  = is_wp_version_compatible( $requires_wp );
 795      $tested_wp      = ( empty( $api->tested ) || version_compare( get_bloginfo( 'version' ), $api->tested, '<=' ) );
 796  
 797      if ( ! $compatible_php ) {
 798          echo '<div class="notice notice-error notice-alt"><p>';
 799          _e( '<strong>Error:</strong> This plugin <strong>requires a newer version of PHP</strong>.' );
 800          if ( current_user_can( 'update_php' ) ) {
 801              printf(
 802                  /* translators: %s: URL to Update PHP page. */
 803                  ' ' . __( '<a href="%s" target="_blank">Click here to learn more about updating PHP</a>.' ),
 804                  esc_url( wp_get_update_php_url() )
 805              );
 806  
 807              wp_update_php_annotation( '</p><p><em>', '</em>' );
 808          } else {
 809              echo '</p>';
 810          }
 811          echo '</div>';
 812      }
 813  
 814      if ( ! $tested_wp ) {
 815          echo '<div class="notice notice-warning notice-alt"><p>';
 816          _e( '<strong>Warning:</strong> This plugin <strong>has not been tested</strong> with your current version of WordPress.' );
 817          echo '</p></div>';
 818      } elseif ( ! $compatible_wp ) {
 819          echo '<div class="notice notice-error notice-alt"><p>';
 820          _e( '<strong>Error:</strong> This plugin <strong>requires a newer version of WordPress</strong>.' );
 821          if ( current_user_can( 'update_core' ) ) {
 822              printf(
 823                  /* translators: %s: URL to WordPress Updates screen. */
 824                  ' ' . __( '<a href="%s" target="_parent">Click here to update WordPress</a>.' ),
 825                  self_admin_url( 'update-core.php' )
 826              );
 827          }
 828          echo '</p></div>';
 829      }
 830  
 831      foreach ( (array) $api->sections as $section_name => $content ) {
 832          $content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' );
 833          $content = links_add_target( $content, '_blank' );
 834  
 835          $san_section = esc_attr( $section_name );
 836  
 837          $display = ( $section_name === $section ) ? 'block' : 'none';
 838  
 839          echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n";
 840          echo $content;
 841          echo "\t</div>\n";
 842      }
 843      echo "</div>\n";
 844      echo "</div>\n";
 845      echo "</div>\n"; // #plugin-information-scrollable
 846      echo "<div id='$tab-footer'>\n";
 847      if ( ! empty( $api->download_link ) && ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) {
 848          $status = install_plugin_install_status( $api );
 849          switch ( $status['status'] ) {
 850              case 'install':
 851                  if ( $status['url'] ) {
 852                      if ( $compatible_php && $compatible_wp ) {
 853                          echo '<a data-slug="' . esc_attr( $api->slug ) . '" id="plugin_install_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Now' ) . '</a>';
 854                      } else {
 855                          printf(
 856                              '<button type="button" class="button button-primary button-disabled right" disabled="disabled">%s</button>',
 857                              _x( 'Cannot Install', 'plugin' )
 858                          );
 859                      }
 860                  }
 861                  break;
 862              case 'update_available':
 863                  if ( $status['url'] ) {
 864                      if ( $compatible_php ) {
 865                          echo '<a data-slug="' . esc_attr( $api->slug ) . '" data-plugin="' . esc_attr( $status['file'] ) . '" id="plugin_update_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) . '</a>';
 866                      } else {
 867                          printf(
 868                              '<button type="button" class="button button-primary button-disabled right" disabled="disabled">%s</button>',
 869                              _x( 'Cannot Update', 'plugin' )
 870                          );
 871                      }
 872                  }
 873                  break;
 874              case 'newer_installed':
 875                  /* translators: %s: Plugin version. */
 876                  echo '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed' ), $status['version'] ) . '</a>';
 877                  break;
 878              case 'latest_installed':
 879                  echo '<a class="button button-primary right disabled">' . __( 'Latest Version Installed' ) . '</a>';
 880                  break;
 881          }
 882      }
 883      echo "</div>\n";
 884  
 885      iframe_footer();
 886      exit;
 887  }


Generated: Wed Sep 18 01:00:03 2019 Cross-referenced by PHPXref 0.7.1