class-plugin-upgrader-skin.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. /**
  19. * Holds the plugin slug in the Plugin Directory.
  20. *
  21. * @since 2.8.0
  22. *
  23. * @var string
  24. */
  25. public $plugin = '';
  26. /**
  27. * Whether the plugin is active.
  28. *
  29. * @since 2.8.0
  30. *
  31. * @var bool
  32. */
  33. public $plugin_active = false;
  34. /**
  35. * Whether the plugin is active for the entire network.
  36. *
  37. * @since 2.8.0
  38. *
  39. * @var bool
  40. */
  41. public $plugin_network_active = false;
  42. /**
  43. * Constructor.
  44. *
  45. * Sets up the plugin upgrader skin.
  46. *
  47. * @since 2.8.0
  48. *
  49. * @param array $args Optional. The plugin upgrader skin arguments to
  50. * override default options. Default empty array.
  51. */
  52. public function __construct( $args = array() ) {
  53. $defaults = array(
  54. 'url' => '',
  55. 'plugin' => '',
  56. 'nonce' => '',
  57. 'title' => __( 'Update Plugin' ),
  58. );
  59. $args = wp_parse_args( $args, $defaults );
  60. $this->plugin = $args['plugin'];
  61. $this->plugin_active = is_plugin_active( $this->plugin );
  62. $this->plugin_network_active = is_plugin_active_for_network( $this->plugin );
  63. parent::__construct( $args );
  64. }
  65. /**
  66. * Action to perform following a single plugin update.
  67. *
  68. * @since 2.8.0
  69. */
  70. public function after() {
  71. $this->plugin = $this->upgrader->plugin_info();
  72. if ( ! empty( $this->plugin ) && ! is_wp_error( $this->result ) && $this->plugin_active ) {
  73. // Currently used only when JS is off for a single plugin update?
  74. printf(
  75. '<iframe title="%s" style="border:0;overflow:hidden" width="100%%" height="170" src="%s"></iframe>',
  76. esc_attr__( 'Update progress' ),
  77. wp_nonce_url( 'update.php?action=activate-plugin&networkwide=' . $this->plugin_network_active . '&plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin )
  78. );
  79. }
  80. $this->decrement_update_count( 'plugin' );
  81. $update_actions = array(
  82. 'activate_plugin' => sprintf(
  83. '<a href="%s" target="_parent">%s</a>',
  84. wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin ),
  85. __( 'Activate Plugin' )
  86. ),
  87. 'plugins_page' => sprintf(
  88. '<a href="%s" target="_parent">%s</a>',
  89. self_admin_url( 'plugins.php' ),
  90. __( 'Go to Plugins page' )
  91. ),
  92. );
  93. if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugin', $this->plugin ) ) {
  94. unset( $update_actions['activate_plugin'] );
  95. }
  96. /**
  97. * Filters the list of action links available following a single plugin update.
  98. *
  99. * @since 2.7.0
  100. *
  101. * @param string[] $update_actions Array of plugin action links.
  102. * @param string $plugin Path to the plugin file relative to the plugins directory.
  103. */
  104. $update_actions = apply_filters( 'update_plugin_complete_actions', $update_actions, $this->plugin );
  105. if ( ! empty( $update_actions ) ) {
  106. $this->feedback( implode( ' | ', (array) $update_actions ) );
  107. }
  108. }
  109. }