2013-09-04 08:35:10 +02:00
< ? php
/**
* The User Interface " Skins " for the WordPress File Upgrader
*
* @ package WordPress
* @ subpackage Upgrader
* @ since 2.8 . 0
*/
/**
* Generic Skin for the WordPress Upgrader classes . This skin is designed to be extended for specific purposes .
*
* @ package WordPress
* @ subpackage Upgrader
* @ since 2.8 . 0
*/
class WP_Upgrader_Skin {
2014-05-19 03:23:15 +02:00
public $upgrader ;
public $done_header = false ;
2014-08-02 17:16:16 +02:00
public $done_footer = false ;
2014-05-19 03:23:15 +02:00
public $result = false ;
2014-11-02 00:03:22 +01:00
public $options = array ();
2013-09-04 08:35:10 +02:00
2015-05-29 23:17:27 +02:00
/**
*
* @ param array $args
*/
2014-05-19 03:23:15 +02:00
public function __construct ( $args = array ()) {
2013-09-04 08:35:10 +02:00
$defaults = array ( 'url' => '' , 'nonce' => '' , 'title' => '' , 'context' => false );
$this -> options = wp_parse_args ( $args , $defaults );
}
2014-12-01 02:00:22 +01:00
/**
* @ param WP_Upgrader $upgrader
*/
2014-05-19 03:23:15 +02:00
public function set_upgrader ( & $upgrader ) {
2013-09-04 08:35:10 +02:00
if ( is_object ( $upgrader ) )
$this -> upgrader =& $upgrader ;
$this -> add_strings ();
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function add_strings () {
2013-09-04 08:35:10 +02:00
}
2015-05-29 23:32:24 +02:00
/**
*
* @ param string | false | WP_Error $result
*/
2014-05-19 03:23:15 +02:00
public function set_result ( $result ) {
2013-09-04 08:35:10 +02:00
$this -> result = $result ;
}
2015-05-29 23:17:27 +02:00
/**
*
* @ param bool $error
* @ param string $context
* @ param bool $allow_relaxed_file_ownership
* @ return type
*/
2014-11-19 06:40:23 +01:00
public function request_filesystem_credentials ( $error = false , $context = false , $allow_relaxed_file_ownership = false ) {
2013-09-04 08:35:10 +02:00
$url = $this -> options [ 'url' ];
2014-11-19 06:40:23 +01:00
if ( ! $context ) {
$context = $this -> options [ 'context' ];
}
if ( ! empty ( $this -> options [ 'nonce' ]) ) {
2013-09-04 08:35:10 +02:00
$url = wp_nonce_url ( $url , $this -> options [ 'nonce' ]);
2014-11-19 06:40:23 +01:00
}
$extra_fields = array ();
return request_filesystem_credentials ( $url , '' , $error , $context , $extra_fields , $allow_relaxed_file_ownership );
2013-09-04 08:35:10 +02:00
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function header () {
2014-08-02 17:16:16 +02:00
if ( $this -> done_header ) {
2013-09-04 08:35:10 +02:00
return ;
2014-08-02 17:16:16 +02:00
}
2013-09-04 08:35:10 +02:00
$this -> done_header = true ;
echo '<div class="wrap">' ;
2015-06-27 17:41:25 +02:00
echo '<h1>' . $this -> options [ 'title' ] . '</h1>' ;
2013-09-04 08:35:10 +02:00
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function footer () {
2014-08-02 17:16:16 +02:00
if ( $this -> done_footer ) {
return ;
}
$this -> done_footer = true ;
2013-09-04 08:35:10 +02:00
echo '</div>' ;
}
2015-05-29 23:17:27 +02:00
/**
*
* @ param string | WP_Error $errors
*/
2014-05-19 03:23:15 +02:00
public function error ( $errors ) {
2013-09-04 08:35:10 +02:00
if ( ! $this -> done_header )
$this -> header ();
if ( is_string ( $errors ) ) {
$this -> feedback ( $errors );
} elseif ( is_wp_error ( $errors ) && $errors -> get_error_code () ) {
foreach ( $errors -> get_error_messages () as $message ) {
2013-10-14 22:20:10 +02:00
if ( $errors -> get_error_data () && is_string ( $errors -> get_error_data () ) )
2014-03-26 15:39:16 +01:00
$this -> feedback ( $message . ' ' . esc_html ( strip_tags ( $errors -> get_error_data () ) ) );
2013-09-04 08:35:10 +02:00
else
$this -> feedback ( $message );
}
}
}
2015-05-29 23:17:27 +02:00
/**
*
* @ param string $string
*/
2014-05-19 03:23:15 +02:00
public function feedback ( $string ) {
2013-09-04 08:35:10 +02:00
if ( isset ( $this -> upgrader -> strings [ $string ] ) )
$string = $this -> upgrader -> strings [ $string ];
if ( strpos ( $string , '%' ) !== false ) {
$args = func_get_args ();
$args = array_splice ( $args , 1 );
if ( $args ) {
$args = array_map ( 'strip_tags' , $args );
$args = array_map ( 'esc_html' , $args );
$string = vsprintf ( $string , $args );
}
}
if ( empty ( $string ) )
return ;
show_message ( $string );
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function before () {}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function after () {}
2013-09-04 08:35:10 +02:00
2014-02-26 07:55:14 +01:00
/**
* Output JavaScript that calls function to decrement the update counts .
*
* @ since 3.9 . 0
2014-04-07 22:02:15 +02:00
*
* @ param string $type Type of update count to decrement . Likely values include 'plugin' ,
* 'theme' , 'translation' , etc .
2014-02-26 07:55:14 +01:00
*/
protected function decrement_update_count ( $type ) {
if ( ! $this -> result || is_wp_error ( $this -> result ) || 'up_to_date' === $this -> result ) {
return ;
}
2014-08-02 16:37:16 +02:00
if ( defined ( 'IFRAME_REQUEST' ) ) {
echo ' < script type = " text/javascript " >
if ( window . postMessage && JSON ) {
window . parent . postMessage ( JSON . stringify ( { action : " decrementUpdateCount " , upgradeType : " ' . $type . ' " } ), window . location . protocol + " // " + window . location . hostname );
2014-02-26 07:55:14 +01:00
}
2014-08-02 16:37:16 +02:00
</ script > ' ;
} else {
echo ' < script type = " text/javascript " >
( function ( wp ) {
if ( wp && wp . updates . decrementCount ) {
wp . updates . decrementCount ( " ' . $type . ' " );
}
})( window . wp );
</ script > ' ;
}
2014-02-26 07:55:14 +01:00
}
2015-01-10 06:42:22 +01:00
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2015-01-10 06:42:22 +01:00
public function bulk_header () {}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2015-01-10 06:42:22 +01:00
public function bulk_footer () {}
2013-09-04 08:35:10 +02:00
}
/**
* Plugin Upgrader Skin for WordPress Plugin Upgrades .
*
* @ package WordPress
* @ subpackage Upgrader
* @ since 2.8 . 0
*/
class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
2014-05-19 03:23:15 +02:00
public $plugin = '' ;
public $plugin_active = false ;
public $plugin_network_active = false ;
2013-09-04 08:35:10 +02:00
2015-05-29 23:17:27 +02:00
/**
*
* @ param array $args
*/
public function __construct ( $args = array () ) {
2013-09-04 08:35:10 +02:00
$defaults = array ( 'url' => '' , 'plugin' => '' , 'nonce' => '' , 'title' => __ ( 'Update Plugin' ) );
$args = wp_parse_args ( $args , $defaults );
$this -> plugin = $args [ 'plugin' ];
$this -> plugin_active = is_plugin_active ( $this -> plugin );
$this -> plugin_network_active = is_plugin_active_for_network ( $this -> plugin );
parent :: __construct ( $args );
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function after () {
2013-09-04 08:35:10 +02:00
$this -> plugin = $this -> upgrader -> plugin_info ();
if ( ! empty ( $this -> plugin ) && ! is_wp_error ( $this -> result ) && $this -> plugin_active ){
echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url ( 'update.php?action=activate-plugin&networkwide=' . $this -> plugin_network_active . '&plugin=' . urlencode ( $this -> plugin ), 'activate-plugin_' . $this -> plugin ) . '"></iframe>' ;
}
2014-02-26 07:55:14 +01:00
$this -> decrement_update_count ( 'plugin' );
2013-09-04 08:35:10 +02:00
$update_actions = array (
2015-06-15 07:09:25 +02:00
'activate_plugin' => '<a href="' . wp_nonce_url ( 'plugins.php?action=activate&plugin=' . urlencode ( $this -> plugin ), 'activate-plugin_' . $this -> plugin ) . '" target="_parent">' . __ ( 'Activate Plugin' ) . '</a>' ,
'plugins_page' => '<a href="' . self_admin_url ( 'plugins.php' ) . '" target="_parent">' . __ ( 'Return to Plugins page' ) . '</a>'
2013-09-04 08:35:10 +02:00
);
if ( $this -> plugin_active || ! $this -> result || is_wp_error ( $this -> result ) || ! current_user_can ( 'activate_plugins' ) )
unset ( $update_actions [ 'activate_plugin' ] );
2014-04-08 08:26:16 +02:00
/**
* Filter the list of action links available following a single plugin update .
*
* @ since 2.7 . 0
*
* @ param array $update_actions Array of plugin action links .
* @ param string $plugin Path to the plugin file .
*/
$update_actions = apply_filters ( 'update_plugin_complete_actions' , $update_actions , $this -> plugin );
2013-09-04 08:35:10 +02:00
if ( ! empty ( $update_actions ) )
$this -> feedback ( implode ( ' | ' , ( array ) $update_actions ));
}
}
/**
* Plugin Upgrader Skin for WordPress Plugin Upgrades .
*
* @ package WordPress
* @ subpackage Upgrader
* @ since 3.0 . 0
*/
class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
2014-05-19 03:23:15 +02:00
public $in_loop = false ;
2015-01-16 23:44:25 +01:00
/**
* @ var string | false
*/
2014-05-19 03:23:15 +02:00
public $error = false ;
2013-09-04 08:35:10 +02:00
2015-05-29 23:17:27 +02:00
/**
*
* @ param array $args
*/
2014-05-19 03:23:15 +02:00
public function __construct ( $args = array ()) {
2013-09-04 08:35:10 +02:00
$defaults = array ( 'url' => '' , 'nonce' => '' );
$args = wp_parse_args ( $args , $defaults );
parent :: __construct ( $args );
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function add_strings () {
2013-09-04 08:35:10 +02:00
$this -> upgrader -> strings [ 'skin_upgrade_start' ] = __ ( 'The update process is starting. This process may take a while on some hosts, so please be patient.' );
$this -> upgrader -> strings [ 'skin_update_failed_error' ] = __ ( 'An error occurred while updating %1$s: <strong>%2$s</strong>' );
$this -> upgrader -> strings [ 'skin_update_failed' ] = __ ( 'The update of %1$s failed.' );
2015-02-22 18:07:24 +01:00
$this -> upgrader -> strings [ 'skin_update_successful' ] = __ ( '%1$s updated successfully.' ) . ' <a onclick="%2$s" href="#" class="hide-if-no-js"><span>' . __ ( 'Show Details' ) . '</span><span class="hidden">' . __ ( 'Hide Details' ) . '</span></a>' ;
2013-09-04 08:35:10 +02:00
$this -> upgrader -> strings [ 'skin_upgrade_end' ] = __ ( 'All updates have been completed.' );
}
2014-12-01 02:00:22 +01:00
/**
* @ param string $string
*/
2014-05-19 03:23:15 +02:00
public function feedback ( $string ) {
2013-09-04 08:35:10 +02:00
if ( isset ( $this -> upgrader -> strings [ $string ] ) )
$string = $this -> upgrader -> strings [ $string ];
if ( strpos ( $string , '%' ) !== false ) {
$args = func_get_args ();
$args = array_splice ( $args , 1 );
if ( $args ) {
$args = array_map ( 'strip_tags' , $args );
$args = array_map ( 'esc_html' , $args );
$string = vsprintf ( $string , $args );
}
}
if ( empty ( $string ) )
return ;
if ( $this -> in_loop )
echo " $string <br /> \n " ;
else
echo " <p> $string </p> \n " ;
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function header () {
2013-09-04 08:35:10 +02:00
// Nothing, This will be displayed within a iframe.
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function footer () {
2013-09-04 08:35:10 +02:00
// Nothing, This will be displayed within a iframe.
}
2015-05-29 23:17:27 +02:00
/**
*
* @ param string | WP_Error $error
*/
2014-05-19 03:23:15 +02:00
public function error ( $error ) {
2013-09-04 08:35:10 +02:00
if ( is_string ( $error ) && isset ( $this -> upgrader -> strings [ $error ] ) )
$this -> error = $this -> upgrader -> strings [ $error ];
if ( is_wp_error ( $error ) ) {
2014-05-19 07:04:16 +02:00
$messages = array ();
2013-09-04 08:35:10 +02:00
foreach ( $error -> get_error_messages () as $emessage ) {
2013-10-14 22:20:10 +02:00
if ( $error -> get_error_data () && is_string ( $error -> get_error_data () ) )
2014-03-26 15:39:16 +01:00
$messages [] = $emessage . ' ' . esc_html ( strip_tags ( $error -> get_error_data () ) );
2013-09-04 08:35:10 +02:00
else
$messages [] = $emessage ;
}
$this -> error = implode ( ', ' , $messages );
}
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js ( $this -> upgrader -> update_current ) . '\').hide();</script>' ;
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function bulk_header () {
2013-09-04 08:35:10 +02:00
$this -> feedback ( 'skin_upgrade_start' );
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function bulk_footer () {
2013-09-04 08:35:10 +02:00
$this -> feedback ( 'skin_upgrade_end' );
}
2015-05-29 23:17:27 +02:00
/**
*
* @ param string $title
*/
2014-05-19 03:23:15 +02:00
public function before ( $title = '' ) {
2013-09-04 08:35:10 +02:00
$this -> in_loop = true ;
printf ( '<h4>' . $this -> upgrader -> strings [ 'skin_before_update_header' ] . ' <span class="spinner waiting-' . $this -> upgrader -> update_current . '"></span></h4>' , $title , $this -> upgrader -> update_current , $this -> upgrader -> update_count );
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js ( $this -> upgrader -> update_current ) . '\').css("display", "inline-block");</script>' ;
echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr ( $this -> upgrader -> update_current ) . '"><p>' ;
$this -> flush_output ();
}
2015-05-29 23:17:27 +02:00
/**
*
* @ param string $title
*/
2014-05-19 03:23:15 +02:00
public function after ( $title = '' ) {
2013-09-04 08:35:10 +02:00
echo '</p></div>' ;
if ( $this -> error || ! $this -> result ) {
if ( $this -> error )
echo '<div class="error"><p>' . sprintf ( $this -> upgrader -> strings [ 'skin_update_failed_error' ], $title , $this -> error ) . '</p></div>' ;
else
echo '<div class="error"><p>' . sprintf ( $this -> upgrader -> strings [ 'skin_update_failed' ], $title ) . '</p></div>' ;
echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js ( $this -> upgrader -> update_current ) . '\').show();</script>' ;
}
if ( $this -> result && ! is_wp_error ( $this -> result ) ) {
if ( ! $this -> error )
echo '<div class="updated"><p>' . sprintf ( $this -> upgrader -> strings [ 'skin_update_successful' ], $title , 'jQuery(\'#progress-' . esc_js ( $this -> upgrader -> update_current ) . '\').toggle();jQuery(\'span\', this).toggle(); return false;' ) . '</p></div>' ;
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js ( $this -> upgrader -> update_current ) . '\').hide();</script>' ;
}
$this -> reset ();
$this -> flush_output ();
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function reset () {
2013-09-04 08:35:10 +02:00
$this -> in_loop = false ;
$this -> error = false ;
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function flush_output () {
2013-09-04 08:35:10 +02:00
wp_ob_end_flush_all ();
flush ();
}
}
class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
2014-05-19 03:23:15 +02:00
public $plugin_info = array (); // Plugin_Upgrader::bulk() will fill this in.
2013-09-04 08:35:10 +02:00
2014-05-19 03:23:15 +02:00
public function add_strings () {
2013-09-04 08:35:10 +02:00
parent :: add_strings ();
$this -> upgrader -> strings [ 'skin_before_update_header' ] = __ ( 'Updating Plugin %1$s (%2$d/%3$d)' );
}
2015-05-29 23:17:27 +02:00
/**
*
* @ param string $title
*/
2014-05-19 03:23:15 +02:00
public function before ( $title = '' ) {
2013-09-04 08:35:10 +02:00
parent :: before ( $this -> plugin_info [ 'Title' ]);
}
2015-05-29 23:17:27 +02:00
/**
*
* @ param string $title
*/
2014-05-19 03:23:15 +02:00
public function after ( $title = '' ) {
2013-09-04 08:35:10 +02:00
parent :: after ( $this -> plugin_info [ 'Title' ]);
2014-02-26 07:55:14 +01:00
$this -> decrement_update_count ( 'plugin' );
2013-09-04 08:35:10 +02:00
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function bulk_footer () {
2013-09-04 08:35:10 +02:00
parent :: bulk_footer ();
$update_actions = array (
2015-06-15 07:09:25 +02:00
'plugins_page' => '<a href="' . self_admin_url ( 'plugins.php' ) . '" target="_parent">' . __ ( 'Return to Plugins page' ) . '</a>' ,
'updates_page' => '<a href="' . self_admin_url ( 'update-core.php' ) . '" target="_parent">' . __ ( 'Return to WordPress Updates page' ) . '</a>'
2013-09-04 08:35:10 +02:00
);
if ( ! current_user_can ( 'activate_plugins' ) )
unset ( $update_actions [ 'plugins_page' ] );
2014-04-08 08:26:16 +02:00
/**
* Filter the list of action links available following bulk plugin updates .
*
* @ since 3.0 . 0
*
* @ param array $update_actions Array of plugin action links .
* @ param array $plugin_info Array of information for the last - updated plugin .
*/
$update_actions = apply_filters ( 'update_bulk_plugins_complete_actions' , $update_actions , $this -> plugin_info );
2013-09-04 08:35:10 +02:00
if ( ! empty ( $update_actions ) )
$this -> feedback ( implode ( ' | ' , ( array ) $update_actions ));
}
}
class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
2014-05-19 03:23:15 +02:00
public $theme_info = array (); // Theme_Upgrader::bulk() will fill this in.
2013-09-04 08:35:10 +02:00
2014-05-19 03:23:15 +02:00
public function add_strings () {
2013-09-04 08:35:10 +02:00
parent :: add_strings ();
$this -> upgrader -> strings [ 'skin_before_update_header' ] = __ ( 'Updating Theme %1$s (%2$d/%3$d)' );
}
2015-05-29 23:17:27 +02:00
/**
*
* @ param string $title
*/
2014-05-19 03:23:15 +02:00
public function before ( $title = '' ) {
2013-09-04 08:35:10 +02:00
parent :: before ( $this -> theme_info -> display ( 'Name' ) );
}
2015-05-29 23:17:27 +02:00
/**
*
* @ param string $title
*/
2014-05-19 03:23:15 +02:00
public function after ( $title = '' ) {
2013-09-04 08:35:10 +02:00
parent :: after ( $this -> theme_info -> display ( 'Name' ) );
2014-02-26 07:55:14 +01:00
$this -> decrement_update_count ( 'theme' );
2013-09-04 08:35:10 +02:00
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function bulk_footer () {
2013-09-04 08:35:10 +02:00
parent :: bulk_footer ();
$update_actions = array (
2015-06-15 07:09:25 +02:00
'themes_page' => '<a href="' . self_admin_url ( 'themes.php' ) . '" target="_parent">' . __ ( 'Return to Themes page' ) . '</a>' ,
'updates_page' => '<a href="' . self_admin_url ( 'update-core.php' ) . '" target="_parent">' . __ ( 'Return to WordPress Updates page' ) . '</a>'
2013-09-04 08:35:10 +02:00
);
if ( ! current_user_can ( 'switch_themes' ) && ! current_user_can ( 'edit_theme_options' ) )
unset ( $update_actions [ 'themes_page' ] );
2014-04-08 08:26:16 +02:00
/**
* Filter the list of action links available following bulk theme updates .
*
* @ since 3.0 . 0
*
* @ param array $update_actions Array of theme action links .
* @ param array $theme_info Array of information for the last - updated theme .
*/
$update_actions = apply_filters ( 'update_bulk_theme_complete_actions' , $update_actions , $this -> theme_info );
2013-09-04 08:35:10 +02:00
if ( ! empty ( $update_actions ) )
$this -> feedback ( implode ( ' | ' , ( array ) $update_actions ));
}
}
/**
* Plugin Installer Skin for WordPress Plugin Installer .
*
* @ package WordPress
* @ subpackage Upgrader
* @ since 2.8 . 0
*/
class Plugin_Installer_Skin extends WP_Upgrader_Skin {
2014-05-19 03:23:15 +02:00
public $api ;
public $type ;
2013-09-04 08:35:10 +02:00
2015-05-29 23:17:27 +02:00
/**
*
* @ param array $args
*/
2014-05-19 03:23:15 +02:00
public function __construct ( $args = array ()) {
2013-09-04 08:35:10 +02:00
$defaults = array ( 'type' => 'web' , 'url' => '' , 'plugin' => '' , 'nonce' => '' , 'title' => '' );
$args = wp_parse_args ( $args , $defaults );
$this -> type = $args [ 'type' ];
$this -> api = isset ( $args [ 'api' ]) ? $args [ 'api' ] : array ();
parent :: __construct ( $args );
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function before () {
2013-09-04 08:35:10 +02:00
if ( ! empty ( $this -> api ) )
$this -> upgrader -> strings [ 'process_success' ] = sprintf ( __ ( 'Successfully installed the plugin <strong>%s %s</strong>.' ), $this -> api -> name , $this -> api -> version );
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function after () {
2013-09-04 08:35:10 +02:00
$plugin_file = $this -> upgrader -> plugin_info ();
$install_actions = array ();
$from = isset ( $_GET [ 'from' ]) ? wp_unslash ( $_GET [ 'from' ] ) : 'plugins' ;
if ( 'import' == $from )
2015-06-15 07:09:25 +02:00
$install_actions [ 'activate_plugin' ] = '<a 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>' ;
2013-09-04 08:35:10 +02:00
else
2015-06-15 07:09:25 +02:00
$install_actions [ 'activate_plugin' ] = '<a href="' . wp_nonce_url ( 'plugins.php?action=activate&plugin=' . urlencode ( $plugin_file ), 'activate-plugin_' . $plugin_file ) . '" target="_parent">' . __ ( 'Activate Plugin' ) . '</a>' ;
2013-09-04 08:35:10 +02:00
if ( is_multisite () && current_user_can ( 'manage_network_plugins' ) ) {
2015-06-15 07:09:25 +02:00
$install_actions [ 'network_activate' ] = '<a href="' . wp_nonce_url ( 'plugins.php?action=activate&networkwide=1&plugin=' . urlencode ( $plugin_file ), 'activate-plugin_' . $plugin_file ) . '" target="_parent">' . __ ( 'Network Activate' ) . '</a>' ;
2013-09-04 08:35:10 +02:00
unset ( $install_actions [ 'activate_plugin' ] );
}
2015-01-08 08:05:25 +01:00
if ( 'import' == $from ) {
2015-06-15 07:09:25 +02:00
$install_actions [ 'importers_page' ] = '<a href="' . admin_url ( 'import.php' ) . '" target="_parent">' . __ ( 'Return to Importers' ) . '</a>' ;
2015-01-08 08:05:25 +01:00
} elseif ( $this -> type == 'web' ) {
2015-06-15 07:09:25 +02:00
$install_actions [ 'plugins_page' ] = '<a href="' . self_admin_url ( 'plugin-install.php' ) . '" target="_parent">' . __ ( 'Return to Plugin Installer' ) . '</a>' ;
2015-01-08 08:05:25 +01:00
} else {
2015-06-15 07:09:25 +02:00
$install_actions [ 'plugins_page' ] = '<a href="' . self_admin_url ( 'plugins.php' ) . '" target="_parent">' . __ ( 'Return to Plugins page' ) . '</a>' ;
2015-01-08 08:05:25 +01:00
}
2013-09-04 08:35:10 +02:00
if ( ! $this -> result || is_wp_error ( $this -> result ) ) {
unset ( $install_actions [ 'activate_plugin' ], $install_actions [ 'network_activate' ] );
} elseif ( ! current_user_can ( 'activate_plugins' ) ) {
unset ( $install_actions [ 'activate_plugin' ] );
}
2014-04-08 08:26:16 +02:00
/**
* Filter the list of action links available following a single plugin installation .
*
* @ since 2.7 . 0
*
* @ param array $install_actions Array of plugin action links .
* @ param object $api Object containing WordPress . org API plugin data . Empty
* for non - API installs , such as when a plugin is installed
* via upload .
* @ param string $plugin_file Path to the plugin file .
*/
$install_actions = apply_filters ( 'install_plugin_complete_actions' , $install_actions , $this -> api , $plugin_file );
2013-09-04 08:35:10 +02:00
if ( ! empty ( $install_actions ) )
$this -> feedback ( implode ( ' | ' , ( array ) $install_actions ));
}
}
/**
* Theme Installer Skin for the WordPress Theme Installer .
*
* @ package WordPress
* @ subpackage Upgrader
* @ since 2.8 . 0
*/
class Theme_Installer_Skin extends WP_Upgrader_Skin {
2014-05-19 03:23:15 +02:00
public $api ;
public $type ;
2013-09-04 08:35:10 +02:00
2015-05-29 23:17:27 +02:00
/**
*
* @ param array $args
*/
2014-05-19 03:23:15 +02:00
public function __construct ( $args = array ()) {
2013-09-04 08:35:10 +02:00
$defaults = array ( 'type' => 'web' , 'url' => '' , 'theme' => '' , 'nonce' => '' , 'title' => '' );
$args = wp_parse_args ( $args , $defaults );
$this -> type = $args [ 'type' ];
$this -> api = isset ( $args [ 'api' ]) ? $args [ 'api' ] : array ();
parent :: __construct ( $args );
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function before () {
2013-09-04 08:35:10 +02:00
if ( ! empty ( $this -> api ) )
$this -> upgrader -> strings [ 'process_success' ] = sprintf ( $this -> upgrader -> strings [ 'process_success_specific' ], $this -> api -> name , $this -> api -> version );
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function after () {
2013-09-04 08:35:10 +02:00
if ( empty ( $this -> upgrader -> result [ 'destination_name' ]) )
return ;
$theme_info = $this -> upgrader -> theme_info ();
if ( empty ( $theme_info ) )
return ;
$name = $theme_info -> display ( 'Name' );
$stylesheet = $this -> upgrader -> result [ 'destination_name' ];
$template = $theme_info -> get_template ();
$activate_link = add_query_arg ( array (
'action' => 'activate' ,
'template' => urlencode ( $template ),
'stylesheet' => urlencode ( $stylesheet ),
), admin_url ( 'themes.php' ) );
$activate_link = wp_nonce_url ( $activate_link , 'switch-theme_' . $stylesheet );
$install_actions = array ();
2015-07-29 20:36:26 +02:00
2014-07-14 21:01:16 +02:00
if ( current_user_can ( 'edit_theme_options' ) && current_user_can ( 'customize' ) ) {
2015-07-30 21:59:25 +02:00
$install_actions [ 'preview' ] = '<a href="' . wp_customize_url ( $stylesheet ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __ ( 'Live Preview' ) . '</span><span class="screen-reader-text">' . sprintf ( __ ( 'Live Preview “%s”' ), $name ) . '</span></a>' ;
2014-07-14 21:01:16 +02:00
}
2015-06-15 07:09:25 +02:00
$install_actions [ 'activate' ] = '<a href="' . esc_url ( $activate_link ) . '" class="activatelink"><span aria-hidden="true">' . __ ( 'Activate' ) . '</span><span class="screen-reader-text">' . sprintf ( __ ( 'Activate “%s”' ), $name ) . '</span></a>' ;
2013-09-04 08:35:10 +02:00
if ( is_network_admin () && current_user_can ( 'manage_network_themes' ) )
2015-06-15 07:09:25 +02:00
$install_actions [ 'network_enable' ] = '<a href="' . esc_url ( wp_nonce_url ( 'themes.php?action=enable&theme=' . urlencode ( $stylesheet ), 'enable-theme_' . $stylesheet ) ) . '" target="_parent">' . __ ( 'Network Enable' ) . '</a>' ;
2013-09-04 08:35:10 +02:00
if ( $this -> type == 'web' )
2015-06-15 07:09:25 +02:00
$install_actions [ 'themes_page' ] = '<a href="' . self_admin_url ( 'theme-install.php' ) . '" target="_parent">' . __ ( 'Return to Theme Installer' ) . '</a>' ;
2013-09-04 08:35:10 +02:00
elseif ( current_user_can ( 'switch_themes' ) || current_user_can ( 'edit_theme_options' ) )
2015-06-15 07:09:25 +02:00
$install_actions [ 'themes_page' ] = '<a href="' . self_admin_url ( 'themes.php' ) . '" target="_parent">' . __ ( 'Return to Themes page' ) . '</a>' ;
2013-09-04 08:35:10 +02:00
if ( ! $this -> result || is_wp_error ( $this -> result ) || is_network_admin () || ! current_user_can ( 'switch_themes' ) )
unset ( $install_actions [ 'activate' ], $install_actions [ 'preview' ] );
2014-04-08 08:26:16 +02:00
/**
* Filter the list of action links available following a single theme installation .
*
* @ since 2.8 . 0
*
* @ param array $install_actions Array of theme action links .
* @ param object $api Object containing WordPress . org API theme data .
* @ param string $stylesheet Theme directory name .
* @ param WP_Theme $theme_info Theme object .
*/
$install_actions = apply_filters ( 'install_theme_complete_actions' , $install_actions , $this -> api , $stylesheet , $theme_info );
2013-09-04 08:35:10 +02:00
if ( ! empty ( $install_actions ) )
$this -> feedback ( implode ( ' | ' , ( array ) $install_actions ));
}
}
/**
* Theme Upgrader Skin for WordPress Theme Upgrades .
*
* @ package WordPress
* @ subpackage Upgrader
* @ since 2.8 . 0
*/
class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
2014-05-19 03:23:15 +02:00
public $theme = '' ;
2013-09-04 08:35:10 +02:00
2015-05-29 23:17:27 +02:00
/**
*
* @ param array $args
*/
2014-05-19 03:23:15 +02:00
public function __construct ( $args = array ()) {
2013-09-04 08:35:10 +02:00
$defaults = array ( 'url' => '' , 'theme' => '' , 'nonce' => '' , 'title' => __ ( 'Update Theme' ) );
$args = wp_parse_args ( $args , $defaults );
$this -> theme = $args [ 'theme' ];
parent :: __construct ( $args );
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function after () {
2014-02-26 07:55:14 +01:00
$this -> decrement_update_count ( 'theme' );
2013-09-04 08:35:10 +02:00
$update_actions = array ();
if ( ! empty ( $this -> upgrader -> result [ 'destination_name' ] ) && $theme_info = $this -> upgrader -> theme_info () ) {
$name = $theme_info -> display ( 'Name' );
$stylesheet = $this -> upgrader -> result [ 'destination_name' ];
$template = $theme_info -> get_template ();
$activate_link = add_query_arg ( array (
'action' => 'activate' ,
'template' => urlencode ( $template ),
'stylesheet' => urlencode ( $stylesheet ),
), admin_url ( 'themes.php' ) );
$activate_link = wp_nonce_url ( $activate_link , 'switch-theme_' . $stylesheet );
if ( get_stylesheet () == $stylesheet ) {
2014-07-14 21:01:16 +02:00
if ( current_user_can ( 'edit_theme_options' ) && current_user_can ( 'customize' ) ) {
2015-06-15 07:09:25 +02:00
$update_actions [ 'preview' ] = '<a href="' . wp_customize_url ( $stylesheet ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __ ( 'Customize' ) . '</span><span class="screen-reader-text">' . sprintf ( __ ( 'Customize “%s”' ), $name ) . '</span></a>' ;
2014-07-14 21:01:16 +02:00
}
2013-09-04 08:35:10 +02:00
} elseif ( current_user_can ( 'switch_themes' ) ) {
2014-07-14 21:01:16 +02:00
if ( current_user_can ( 'edit_theme_options' ) && current_user_can ( 'customize' ) ) {
2015-08-19 12:35:25 +02:00
$update_actions [ 'preview' ] = '<a href="' . wp_customize_url ( $stylesheet ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __ ( 'Live Preview' ) . '</span><span class="screen-reader-text">' . sprintf ( __ ( 'Live Preview “%s”' ), $name ) . '</span></a>' ;
2014-07-14 21:01:16 +02:00
}
2015-06-15 07:09:25 +02:00
$update_actions [ 'activate' ] = '<a href="' . esc_url ( $activate_link ) . '" class="activatelink"><span aria-hidden="true">' . __ ( 'Activate' ) . '</span><span class="screen-reader-text">' . sprintf ( __ ( 'Activate “%s”' ), $name ) . '</span></a>' ;
2013-09-04 08:35:10 +02:00
}
if ( ! $this -> result || is_wp_error ( $this -> result ) || is_network_admin () )
unset ( $update_actions [ 'preview' ], $update_actions [ 'activate' ] );
}
2015-06-15 07:09:25 +02:00
$update_actions [ 'themes_page' ] = '<a href="' . self_admin_url ( 'themes.php' ) . '" target="_parent">' . __ ( 'Return to Themes page' ) . '</a>' ;
2013-09-04 08:35:10 +02:00
2014-04-08 08:26:16 +02:00
/**
* Filter the list of action links available following a single theme update .
*
* @ since 2.8 . 0
*
* @ param array $update_actions Array of theme action links .
* @ param string $theme Theme directory name .
*/
$update_actions = apply_filters ( 'update_theme_complete_actions' , $update_actions , $this -> theme );
2013-09-04 08:35:10 +02:00
if ( ! empty ( $update_actions ) )
$this -> feedback ( implode ( ' | ' , ( array ) $update_actions ));
}
2013-09-04 09:17:09 +02:00
}
2013-10-16 06:15:09 +02:00
/**
* Translation Upgrader Skin for WordPress Translation Upgrades .
*
* @ package WordPress
* @ subpackage Upgrader
* @ since 3.7 . 0
*/
class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin {
2014-05-19 03:23:15 +02:00
public $language_update = null ;
public $done_header = false ;
2014-08-02 17:16:16 +02:00
public $done_footer = false ;
2014-05-19 03:23:15 +02:00
public $display_footer_actions = true ;
2013-10-16 06:15:09 +02:00
2015-05-29 23:17:27 +02:00
/**
*
* @ param array $args
*/
2014-05-19 03:23:15 +02:00
public function __construct ( $args = array () ) {
2013-10-16 06:15:09 +02:00
$defaults = array ( 'url' => '' , 'nonce' => '' , 'title' => __ ( 'Update Translations' ), 'skip_header_footer' => false );
$args = wp_parse_args ( $args , $defaults );
if ( $args [ 'skip_header_footer' ] ) {
$this -> done_header = true ;
2014-08-02 17:16:16 +02:00
$this -> done_footer = true ;
2013-10-16 06:15:09 +02:00
$this -> display_footer_actions = false ;
}
parent :: __construct ( $args );
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function before () {
2013-10-16 06:15:09 +02:00
$name = $this -> upgrader -> get_name_for_update ( $this -> language_update );
echo '<div class="update-messages lp-show-latest">' ;
printf ( '<h4>' . __ ( 'Updating translations for %1$s (%2$s)…' ) . '</h4>' , $name , $this -> language_update -> language );
}
2015-05-29 23:17:27 +02:00
/**
*
* @ param string | WP_Error $error
*/
2014-05-19 03:23:15 +02:00
public function error ( $error ) {
2013-10-16 06:15:09 +02:00
echo '<div class="lp-error">' ;
parent :: error ( $error );
echo '</div>' ;
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function after () {
2013-10-16 06:15:09 +02:00
echo '</div>' ;
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function bulk_footer () {
2014-02-26 07:55:14 +01:00
$this -> decrement_update_count ( 'translation' );
2013-10-16 06:15:09 +02:00
$update_actions = array ();
2015-06-15 07:09:25 +02:00
$update_actions [ 'updates_page' ] = '<a href="' . self_admin_url ( 'update-core.php' ) . '" target="_parent">' . __ ( 'Return to WordPress Updates page' ) . '</a>' ;
2014-04-08 08:26:16 +02:00
/**
* Filter the list of action links available following a translations update .
*
* @ since 3.7 . 0
*
* @ param array $update_actions Array of translations update links .
*/
2013-10-16 06:15:09 +02:00
$update_actions = apply_filters ( 'update_translations_complete_actions' , $update_actions );
if ( $update_actions && $this -> display_footer_actions )
$this -> feedback ( implode ( ' | ' , $update_actions ) );
}
}
2013-09-04 09:17:09 +02:00
/**
2013-09-13 08:19:12 +02:00
* Upgrader Skin for Automatic WordPress Upgrades
2013-09-04 09:17:09 +02:00
*
2013-10-25 04:29:52 +02:00
* This skin is designed to be used when no output is intended , all output
2013-09-04 09:17:09 +02:00
* is captured and stored for the caller to process and log / email / discard .
*
* @ package WordPress
* @ subpackage Upgrader
* @ since 3.7 . 0
*/
2013-09-13 08:19:12 +02:00
class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
2013-10-25 00:57:58 +02:00
protected $messages = array ();
2013-09-04 09:17:09 +02:00
2015-05-29 23:17:27 +02:00
/**
*
* @ param bool $error
* @ param string $context
* @ param bool $allow_relaxed_file_ownership
* @ return bool
*/
2014-11-19 06:40:23 +01:00
public function request_filesystem_credentials ( $error = false , $context = '' , $allow_relaxed_file_ownership = false ) {
if ( $context ) {
2013-09-13 08:53:09 +02:00
$this -> options [ 'context' ] = $context ;
2014-11-19 06:40:23 +01:00
}
2013-09-04 09:17:09 +02:00
// TODO: fix up request_filesystem_credentials(), or split it, to allow us to request a no-output version
// This will output a credentials form in event of failure, We don't want that, so just hide with a buffer
ob_start ();
2014-11-19 06:40:23 +01:00
$result = parent :: request_filesystem_credentials ( $error , $context , $allow_relaxed_file_ownership );
2013-09-04 09:17:09 +02:00
ob_end_clean ();
return $result ;
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*
* @ return array
*/
2014-05-19 03:23:15 +02:00
public function get_upgrade_messages () {
2013-09-19 10:46:09 +02:00
return $this -> messages ;
}
2014-12-01 02:00:22 +01:00
/**
* @ param string | array | WP_Error $data
*/
2014-05-19 03:23:15 +02:00
public function feedback ( $data ) {
2015-01-08 08:05:25 +01:00
if ( is_wp_error ( $data ) ) {
2013-09-04 09:17:09 +02:00
$string = $data -> get_error_message ();
2015-01-08 08:05:25 +01:00
} elseif ( is_array ( $data ) ) {
2013-09-04 09:17:09 +02:00
return ;
2015-01-08 08:05:25 +01:00
} else {
2013-09-04 09:17:09 +02:00
$string = $data ;
2015-01-08 08:05:25 +01:00
}
2013-09-04 09:17:09 +02:00
if ( ! empty ( $this -> upgrader -> strings [ $string ] ) )
$string = $this -> upgrader -> strings [ $string ];
if ( strpos ( $string , '%' ) !== false ) {
$args = func_get_args ();
$args = array_splice ( $args , 1 );
if ( ! empty ( $args ) )
$string = vsprintf ( $string , $args );
}
$string = trim ( $string );
// Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output.
$string = wp_kses ( $string , array (
'a' => array (
'href' => true
),
'br' => true ,
'em' => true ,
'strong' => true ,
) );
if ( empty ( $string ) )
return ;
$this -> messages [] = $string ;
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function header () {
2013-09-04 09:17:09 +02:00
ob_start ();
}
2015-05-29 23:32:24 +02:00
/**
* @ access public
*/
2014-05-19 03:23:15 +02:00
public function footer () {
2015-06-27 03:12:24 +02:00
$output = ob_get_clean ();
2013-09-04 09:17:09 +02:00
if ( ! empty ( $output ) )
$this -> feedback ( $output );
}
2013-09-23 04:08:10 +02:00
}