|
1 <?php |
|
2 /** |
|
3 * Upgrader API: Plugin_Installer_Skin class |
|
4 * |
|
5 * @package WordPress |
|
6 * @subpackage Upgrader |
|
7 * @since 4.6.0 |
|
8 */ |
|
9 |
|
10 /** |
|
11 * Plugin Installer Skin for WordPress Plugin Installer. |
|
12 * |
|
13 * @since 2.8.0 |
|
14 * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php. |
|
15 * |
|
16 * @see WP_Upgrader_Skin |
|
17 */ |
|
18 class Plugin_Installer_Skin extends WP_Upgrader_Skin { |
|
19 public $api; |
|
20 public $type; |
|
21 |
|
22 /** |
|
23 * |
|
24 * @param array $args |
|
25 */ |
|
26 public function __construct($args = array()) { |
|
27 $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' ); |
|
28 $args = wp_parse_args($args, $defaults); |
|
29 |
|
30 $this->type = $args['type']; |
|
31 $this->api = isset($args['api']) ? $args['api'] : array(); |
|
32 |
|
33 parent::__construct($args); |
|
34 } |
|
35 |
|
36 /** |
|
37 */ |
|
38 public function before() { |
|
39 if ( !empty($this->api) ) |
|
40 $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version); |
|
41 } |
|
42 |
|
43 /** |
|
44 */ |
|
45 public function after() { |
|
46 $plugin_file = $this->upgrader->plugin_info(); |
|
47 |
|
48 $install_actions = array(); |
|
49 |
|
50 $from = isset($_GET['from']) ? wp_unslash( $_GET['from'] ) : 'plugins'; |
|
51 |
|
52 if ( 'import' == $from ) { |
|
53 $install_actions['activate_plugin'] = '<a class="button button-primary" href="' . wp_nonce_url( 'plugins.php?action=activate&from=import&plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ) . '" target="_parent">' . __( 'Activate Plugin & Run Importer' ) . '</a>'; |
|
54 } else if ( 'press-this' == $from ) { |
|
55 $install_actions['activate_plugin'] = '<a class="button button-primary" href="' . wp_nonce_url( 'plugins.php?action=activate&from=press-this&plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ) . '" target="_parent">' . __( 'Activate Plugin & Return to Press This' ) . '</a>'; |
|
56 } else { |
|
57 $install_actions['activate_plugin'] = '<a class="button button-primary" href="' . wp_nonce_url( 'plugins.php?action=activate&plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ) . '" target="_parent">' . __( 'Activate Plugin' ) . '</a>'; |
|
58 } |
|
59 |
|
60 if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) { |
|
61 $install_actions['network_activate'] = '<a class="button button-primary" href="' . wp_nonce_url( 'plugins.php?action=activate&networkwide=1&plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ) . '" target="_parent">' . __( 'Network Activate' ) . '</a>'; |
|
62 unset( $install_actions['activate_plugin'] ); |
|
63 } |
|
64 |
|
65 if ( 'import' == $from ) { |
|
66 $install_actions['importers_page'] = '<a href="' . admin_url( 'import.php' ) . '" target="_parent">' . __( 'Return to Importers' ) . '</a>'; |
|
67 } elseif ( $this->type == 'web' ) { |
|
68 $install_actions['plugins_page'] = '<a href="' . self_admin_url( 'plugin-install.php' ) . '" target="_parent">' . __( 'Return to Plugin Installer' ) . '</a>'; |
|
69 } elseif ( 'upload' == $this->type && 'plugins' == $from ) { |
|
70 $install_actions['plugins_page'] = '<a href="' . self_admin_url( 'plugin-install.php' ) . '">' . __( 'Return to Plugin Installer' ) . '</a>'; |
|
71 } else { |
|
72 $install_actions['plugins_page'] = '<a href="' . self_admin_url( 'plugins.php' ) . '" target="_parent">' . __( 'Return to Plugins page' ) . '</a>'; |
|
73 } |
|
74 |
|
75 if ( ! $this->result || is_wp_error($this->result) ) { |
|
76 unset( $install_actions['activate_plugin'], $install_actions['network_activate'] ); |
|
77 } elseif ( ! current_user_can( 'activate_plugin', $plugin_file ) ) { |
|
78 unset( $install_actions['activate_plugin'] ); |
|
79 } |
|
80 |
|
81 /** |
|
82 * Filters the list of action links available following a single plugin installation. |
|
83 * |
|
84 * @since 2.7.0 |
|
85 * |
|
86 * @param array $install_actions Array of plugin action links. |
|
87 * @param object $api Object containing WordPress.org API plugin data. Empty |
|
88 * for non-API installs, such as when a plugin is installed |
|
89 * via upload. |
|
90 * @param string $plugin_file Path to the plugin file. |
|
91 */ |
|
92 $install_actions = apply_filters( 'install_plugin_complete_actions', $install_actions, $this->api, $plugin_file ); |
|
93 |
|
94 if ( ! empty( $install_actions ) ) { |
|
95 $this->feedback( implode( ' ', (array) $install_actions ) ); |
|
96 } |
|
97 } |
|
98 } |