class-plugin-upgrader-skin.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Upgrader API: Plugin_Upgrader_Skin class
  4. *
  5. * @package WordPress
  6. * @subpackage Upgrader
  7. * @since 4.6.0
  8. */
  9. /**
  10. * Plugin Upgrader Skin for WordPress Plugin Upgrades.
  11. *
  12. * @since 2.8.0
  13. * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
  14. *
  15. * @see WP_Upgrader_Skin
  16. */
  17. class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
  18. public $plugin = '';
  19. public $plugin_active = false;
  20. public $plugin_network_active = false;
  21. /**
  22. * @param array $args
  23. */
  24. public function __construct( $args = array() ) {
  25. $defaults = array(
  26. 'url' => '',
  27. 'plugin' => '',
  28. 'nonce' => '',
  29. 'title' => __( 'Update Plugin' ),
  30. );
  31. $args = wp_parse_args( $args, $defaults );
  32. $this->plugin = $args['plugin'];
  33. $this->plugin_active = is_plugin_active( $this->plugin );
  34. $this->plugin_network_active = is_plugin_active_for_network( $this->plugin );
  35. parent::__construct( $args );
  36. }
  37. /**
  38. */
  39. public function after() {
  40. $this->plugin = $this->upgrader->plugin_info();
  41. if ( ! empty( $this->plugin ) && ! is_wp_error( $this->result ) && $this->plugin_active ) {
  42. // Currently used only when JS is off for a single plugin update?
  43. printf(
  44. '<iframe title="%s" style="border:0;overflow:hidden" width="100%%" height="170" src="%s"></iframe>',
  45. esc_attr__( 'Update progress' ),
  46. wp_nonce_url( 'update.php?action=activate-plugin&networkwide=' . $this->plugin_network_active . '&plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin )
  47. );
  48. }
  49. $this->decrement_update_count( 'plugin' );
  50. $update_actions = array(
  51. 'activate_plugin' => sprintf(
  52. '<a href="%s" target="_parent">%s</a>',
  53. wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin ),
  54. __( 'Activate Plugin' )
  55. ),
  56. 'plugins_page' => sprintf(
  57. '<a href="%s" target="_parent">%s</a>',
  58. self_admin_url( 'plugins.php' ),
  59. __( 'Return to Plugins page' )
  60. ),
  61. );
  62. if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugin', $this->plugin ) ) {
  63. unset( $update_actions['activate_plugin'] );
  64. }
  65. /**
  66. * Filters the list of action links available following a single plugin update.
  67. *
  68. * @since 2.7.0
  69. *
  70. * @param string[] $update_actions Array of plugin action links.
  71. * @param string $plugin Path to the plugin file relative to the plugins directory.
  72. */
  73. $update_actions = apply_filters( 'update_plugin_complete_actions', $update_actions, $this->plugin );
  74. if ( ! empty( $update_actions ) ) {
  75. $this->feedback( implode( ' | ', (array) $update_actions ) );
  76. }
  77. }
  78. }