[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

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


Generated: Tue Oct 22 08:20:01 2019 Cross-referenced by PHPXref 0.7