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