Completed
Pull Request — develop (#689)
by
unknown
01:46
created

TGMPA_Bulk_Installer_Skin::bulk_footer()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 37
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 15
nc 4
nop 0
dl 0
loc 37
rs 8.8571
c 0
b 0
f 0
1
<?php
2
		
3
	namespace TGM;
4
		
5
	/**
6
	 * Installer skin to set strings for the bulk plugin installations..
7
	 *
8
	 * Extends Bulk_Upgrader_Skin and customizes to suit the installation of multiple
9
	 * plugins.
10
	 *
11
	 * @since 2.2.0
12
	 *
13
	 * {@internal Since 2.5.2 the class has been renamed from TGM_Bulk_Installer_Skin to
14
	 *            TGMPA_Bulk_Installer_Skin.
15
	 *            This was done to prevent backward compatibility issues with v2.3.6.}}
16
	 *
17
	 * @see https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes/class-wp-upgrader-skins.php
18
	 *
19
	 * @package TGM-Plugin-Activation
20
	 * @author  Thomas Griffin
21
	 * @author  Gary Jones
22
	 */
23
	class TGMPA_Bulk_Installer_Skin extends Bulk_Upgrader_Skin {
24
	  /**
25
	   * Holds plugin info for each individual plugin installation.
26
	   *
27
	   * @since 2.2.0
28
	   *
29
	   * @var array
30
	   */
31
	  public $plugin_info = array();
32
	
33
	  /**
34
	   * Holds names of plugins that are undergoing bulk installations.
35
	   *
36
	   * @since 2.2.0
37
	   *
38
	   * @var array
39
	   */
40
	  public $plugin_names = array();
41
	
42
	  /**
43
	   * Integer to use for iteration through each plugin installation.
44
	   *
45
	   * @since 2.2.0
46
	   *
47
	   * @var integer
48
	   */
49
	  public $i = 0;
50
	
51
	  /**
52
	   * TGMPA instance
53
	   *
54
	   * @since 2.5.0
55
	   *
56
	   * @var object
57
	   */
58
	  protected $tgmpa;
59
	
60
	  /**
61
	   * Constructor. Parses default args with new ones and extracts them for use.
62
	   *
63
	   * @since 2.2.0
64
	   *
65
	   * @param array $args Arguments to pass for use within the class.
66
	   */
67
	  public function __construct( $args = array() ) {
68
	    // Get TGMPA class instance.
69
	    $this->tgmpa = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) );
70
	
71
	    // Parse default and new args.
72
	    $defaults = array(
73
	      'url'          => '',
74
	      'nonce'        => '',
75
	      'names'        => array(),
76
	      'install_type' => 'install',
77
	    );
78
	    $args     = wp_parse_args( $args, $defaults );
79
	
80
	    // Set plugin names to $this->plugin_names property.
81
	    $this->plugin_names = $args['names'];
82
	
83
	    // Extract the new args.
84
	    parent::__construct( $args );
85
	  }
86
	
87
	  /**
88
	   * Sets install skin strings for each individual plugin.
89
	   *
90
	   * Checks to see if the automatic activation flag is set and uses the
91
	   * the proper strings accordingly.
92
	   *
93
	   * @since 2.2.0
94
	   */
95
	  public function add_strings() {
96
	    if ( 'update' === $this->options['install_type'] ) {
97
	      parent::add_strings();
98
	      /* translators: 1: plugin name, 2: action number 3: total number of actions. */
99
	      $this->upgrader->strings['skin_before_update_header'] = __( 'Updating Plugin %1$s (%2$d/%3$d)', 'tgmpa' );
100
	    } else {
101
	      /* translators: 1: plugin name, 2: error message. */
102
	      $this->upgrader->strings['skin_update_failed_error'] = __( 'An error occurred while installing %1$s: <strong>%2$s</strong>.', 'tgmpa' );
103
	      /* translators: 1: plugin name. */
104
	      $this->upgrader->strings['skin_update_failed'] = __( 'The installation of %1$s failed.', 'tgmpa' );
105
	
106
	      if ( $this->tgmpa->is_automatic ) {
107
	        // Automatic activation strings.
108
	        $this->upgrader->strings['skin_upgrade_start'] = __( 'The installation and activation process is starting. This process may take a while on some hosts, so please be patient.', 'tgmpa' );
109
	        /* translators: 1: plugin name. */
110
	        $this->upgrader->strings['skin_update_successful'] = __( '%1$s installed and activated successfully.', 'tgmpa' );
111
	        $this->upgrader->strings['skin_upgrade_end']       = __( 'All installations and activations have been completed.', 'tgmpa' );
112
	        /* translators: 1: plugin name, 2: action number 3: total number of actions. */
113
	        $this->upgrader->strings['skin_before_update_header'] = __( 'Installing and Activating Plugin %1$s (%2$d/%3$d)', 'tgmpa' );
114
	      } else {
115
	        // Default installation strings.
116
	        $this->upgrader->strings['skin_upgrade_start'] = __( 'The installation process is starting. This process may take a while on some hosts, so please be patient.', 'tgmpa' );
117
	        /* translators: 1: plugin name. */
118
	        $this->upgrader->strings['skin_update_successful'] = __( '%1$s installed successfully.', 'tgmpa' );
119
	        $this->upgrader->strings['skin_upgrade_end']       = __( 'All installations have been completed.', 'tgmpa' );
120
	        /* translators: 1: plugin name, 2: action number 3: total number of actions. */
121
	        $this->upgrader->strings['skin_before_update_header'] = __( 'Installing Plugin %1$s (%2$d/%3$d)', 'tgmpa' );
122
	      }
123
	
124
	      // Add "read more" link only for WP < 4.8.
125
	      if ( version_compare( $this->tgmpa->wp_version, '4.8', '<' ) ) {
126
	        $this->upgrader->strings['skin_update_successful'] .= ' <a href="#" class="hide-if-no-js" onclick="%2$s"><span>' . esc_html__( 'Show Details', 'tgmpa' ) . '</span><span class="hidden">' . esc_html__( 'Hide Details', 'tgmpa' ) . '</span>.</a>';
127
	      }
128
	    }
129
	  }
130
	
131
	  /**
132
	   * Outputs the header strings and necessary JS before each plugin installation.
133
	   *
134
	   * @since 2.2.0
135
	   *
136
	   * @param string $title Unused in this implementation.
137
	   */
138
	  public function before( $title = '' ) {
139
	    if ( empty( $title ) ) {
140
	      $title = esc_html( $this->plugin_names[ $this->i ] );
141
	    }
142
	    parent::before( $title );
143
	  }
144
	
145
	  /**
146
	   * Outputs the footer strings and necessary JS after each plugin installation.
147
	   *
148
	   * Checks for any errors and outputs them if they exist, else output
149
	   * success strings.
150
	   *
151
	   * @since 2.2.0
152
	   *
153
	   * @param string $title Unused in this implementation.
154
	   */
155
	  public function after( $title = '' ) {
156
	    if ( empty( $title ) ) {
157
	      $title = esc_html( $this->plugin_names[ $this->i ] );
158
	    }
159
	    parent::after( $title );
160
	
161
	    $this->i++;
162
	  }
163
	
164
	  /**
165
	   * Outputs links after bulk plugin installation is complete.
166
	   *
167
	   * @since 2.2.0
168
	   */
169
	  public function bulk_footer() {
170
	    // Serve up the string to say installations (and possibly activations) are complete.
171
	    parent::bulk_footer();
172
	
173
	    // Flush plugins cache so we can make sure that the installed plugins list is always up to date.
174
	    wp_clean_plugins_cache();
175
	
176
	    $this->tgmpa->show_tgmpa_version();
177
	
178
	    // Display message based on if all plugins are now active or not.
179
	    $update_actions = array();
180
	
181
	    if ( $this->tgmpa->is_tgmpa_complete() ) {
182
	      // All plugins are active, so we display the complete string and hide the menu to protect users.
183
	      echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>';
184
	      $update_actions['dashboard'] = sprintf(
185
	        esc_html( $this->tgmpa->strings['complete'] ),
186
	        '<a href="' . esc_url( self_admin_url() ) . '">' . esc_html( $this->tgmpa->strings['dashboard'] ) . '</a>'
187
	      );
188
	    } else {
189
	      $update_actions['tgmpa_page'] = '<a href="' . esc_url( $this->tgmpa->get_tgmpa_url() ) . '" target="_parent">' . esc_html( $this->tgmpa->strings['return'] ) . '</a>';
190
	    }
191
	
192
	    /**
193
	     * Filter the list of action links available following bulk plugin installs/updates.
194
	     *
195
	     * @since 2.5.0
196
	     *
197
	     * @param array $update_actions Array of plugin action links.
198
	     * @param array $plugin_info    Array of information for the last-handled plugin.
199
	     */
200
	    $update_actions = apply_filters( 'tgmpa_update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info );
201
	
202
	    if ( ! empty( $update_actions ) ) {
203
	      $this->feedback( implode( ' | ', (array) $update_actions ) );
204
	    }
205
	  }
206
	
207
	  /* *********** DEPRECATED METHODS *********** */
208
	
209
	  /**
210
	   * Flush header output buffer.
211
	   *
212
	   * @since      2.2.0
213
	   * @deprecated 2.5.0 use {@see Bulk_Upgrader_Skin::flush_output()} instead
214
	   * @see        Bulk_Upgrader_Skin::flush_output()
215
	   */
216
	  public function before_flush_output() {
217
	    _deprecated_function( __FUNCTION__, 'TGMPA 2.5.0', 'Bulk_Upgrader_Skin::flush_output()' );
218
	    $this->flush_output();
219
	  }
220
	
221
	  /**
222
	   * Flush footer output buffer and iterate $this->i to make sure the
223
	   * installation strings reference the correct plugin.
224
	   *
225
	   * @since      2.2.0
226
	   * @deprecated 2.5.0 use {@see Bulk_Upgrader_Skin::flush_output()} instead
227
	   * @see        Bulk_Upgrader_Skin::flush_output()
228
	   */
229
	  public function after_flush_output() {
230
	    _deprecated_function( __FUNCTION__, 'TGMPA 2.5.0', 'Bulk_Upgrader_Skin::flush_output()' );
231
	    $this->flush_output();
232
	    $this->i++;
233
	  }
234
	}
235