2016-05-10 07:11:30 -04:00
< ? php
/**
2016-05-10 07:31:28 -04:00
* Upgrader API : Plugin_Installer_Skin class
2016-05-10 07:11:30 -04:00
*
* @ package WordPress
* @ subpackage Upgrader
2016-05-10 07:31:28 -04:00
* @ since 4.6 . 0
2016-05-10 07:11:30 -04:00
*/
/**
* Plugin Installer Skin for WordPress Plugin Installer .
*
* @ since 2.8 . 0
2016-05-13 16:59:27 -04:00
* @ since 4.6 . 0 Moved to its own file from wp - admin / includes / class - wp - upgrader - skins . php .
2016-07-09 09:45:33 -04:00
*
* @ see WP_Upgrader_Skin
2016-05-10 07:11:30 -04:00
*/
class Plugin_Installer_Skin extends WP_Upgrader_Skin {
public $api ;
public $type ;
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
public $url ;
public $overwrite ;
private $is_downgrading = false ;
2016-05-10 07:11:30 -04:00
/**
* @ param array $args
*/
2017-11-30 18:11:00 -05:00
public function __construct ( $args = array () ) {
$defaults = array (
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
'type' => 'web' ,
'url' => '' ,
'plugin' => '' ,
'nonce' => '' ,
'title' => '' ,
'overwrite' => '' ,
2017-11-30 18:11:00 -05:00
);
$args = wp_parse_args ( $args , $defaults );
2016-05-10 07:11:30 -04:00
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
$this -> type = $args [ 'type' ];
$this -> url = $args [ 'url' ];
$this -> api = isset ( $args [ 'api' ] ) ? $args [ 'api' ] : array ();
$this -> overwrite = $args [ 'overwrite' ];
2016-05-10 07:11:30 -04:00
2017-11-30 18:11:00 -05:00
parent :: __construct ( $args );
2016-05-10 07:11:30 -04:00
}
/**
*/
public function before () {
2017-11-30 18:11:00 -05:00
if ( ! empty ( $this -> api ) ) {
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
$this -> upgrader -> strings [ 'process_success' ] = sprintf (
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
$this -> upgrader -> strings [ 'process_success_specific' ],
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
$this -> api -> name ,
$this -> api -> version
);
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:11:30 -04:00
}
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
/**
* Hides the `process_failed` error when updating a plugin by uploading a zip file .
*
* @ since 5.5 . 0
*
* @ param $wp_error WP_Error .
* @ return bool
*/
public function hide_process_failed ( $wp_error ) {
if (
'upload' === $this -> type &&
'' === $this -> overwrite &&
$wp_error -> get_error_code () === 'folder_exists'
) {
return true ;
}
return false ;
}
2016-05-10 07:11:30 -04:00
/**
*/
public function after () {
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
// Check if the plugin can be overwritten and output the HTML.
if ( $this -> do_overwrite () ) {
return ;
}
2016-05-10 07:11:30 -04:00
$plugin_file = $this -> upgrader -> plugin_info ();
$install_actions = array ();
2017-11-30 18:11:00 -05:00
$from = isset ( $_GET [ 'from' ] ) ? wp_unslash ( $_GET [ 'from' ] ) : 'plugins' ;
2016-05-10 07:11:30 -04:00
2020-05-16 14:42:12 -04:00
if ( 'import' === $from ) {
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
$install_actions [ 'activate_plugin' ] = sprintf (
'<a class="button button-primary" href="%s" target="_parent">%s</a>' ,
wp_nonce_url ( 'plugins.php?action=activate&from=import&plugin=' . urlencode ( $plugin_file ), 'activate-plugin_' . $plugin_file ),
__ ( 'Activate Plugin & Run Importer' )
);
2020-05-16 14:42:12 -04:00
} elseif ( 'press-this' === $from ) {
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
$install_actions [ 'activate_plugin' ] = sprintf (
'<a class="button button-primary" href="%s" target="_parent">%s</a>' ,
wp_nonce_url ( 'plugins.php?action=activate&from=press-this&plugin=' . urlencode ( $plugin_file ), 'activate-plugin_' . $plugin_file ),
__ ( 'Activate Plugin & Return to Press This' )
);
2017-09-24 10:22:54 -04:00
} else {
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
$install_actions [ 'activate_plugin' ] = sprintf (
'<a class="button button-primary" href="%s" target="_parent">%s</a>' ,
wp_nonce_url ( 'plugins.php?action=activate&plugin=' . urlencode ( $plugin_file ), 'activate-plugin_' . $plugin_file ),
__ ( 'Activate Plugin' )
);
2017-09-24 10:22:54 -04:00
}
2016-05-10 07:11:30 -04:00
if ( is_multisite () && current_user_can ( 'manage_network_plugins' ) ) {
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
$install_actions [ 'network_activate' ] = sprintf (
'<a class="button button-primary" href="%s" target="_parent">%s</a>' ,
wp_nonce_url ( 'plugins.php?action=activate&networkwide=1&plugin=' . urlencode ( $plugin_file ), 'activate-plugin_' . $plugin_file ),
__ ( 'Network Activate' )
);
2016-05-10 07:11:30 -04:00
unset ( $install_actions [ 'activate_plugin' ] );
}
2020-02-09 11:55:09 -05:00
if ( 'import' === $from ) {
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
$install_actions [ 'importers_page' ] = sprintf (
'<a href="%s" target="_parent">%s</a>' ,
admin_url ( 'import.php' ),
__ ( 'Return to Importers' )
);
2020-02-09 11:55:09 -05:00
} elseif ( 'web' === $this -> type ) {
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
$install_actions [ 'plugins_page' ] = sprintf (
'<a href="%s" target="_parent">%s</a>' ,
self_admin_url ( 'plugin-install.php' ),
__ ( 'Return to Plugin Installer' )
);
2020-02-09 11:55:09 -05:00
} elseif ( 'upload' === $this -> type && 'plugins' === $from ) {
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
$install_actions [ 'plugins_page' ] = sprintf (
'<a href="%s">%s</a>' ,
self_admin_url ( 'plugin-install.php' ),
__ ( 'Return to Plugin Installer' )
);
2016-05-10 07:11:30 -04:00
} else {
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
$install_actions [ 'plugins_page' ] = sprintf (
'<a href="%s" target="_parent">%s</a>' ,
self_admin_url ( 'plugins.php' ),
__ ( 'Return to Plugins page' )
);
2016-05-10 07:11:30 -04:00
}
2017-11-30 18:11:00 -05:00
if ( ! $this -> result || is_wp_error ( $this -> result ) ) {
2016-05-10 07:11:30 -04:00
unset ( $install_actions [ 'activate_plugin' ], $install_actions [ 'network_activate' ] );
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
} elseif ( ! current_user_can ( 'activate_plugin' , $plugin_file ) || is_plugin_active ( $plugin_file ) ) {
2016-05-10 07:11:30 -04:00
unset ( $install_actions [ 'activate_plugin' ] );
}
/**
2016-05-22 14:01:30 -04:00
* Filters the list of action links available following a single plugin installation .
2016-05-10 07:11:30 -04:00
*
* @ since 2.7 . 0
*
2018-03-22 16:27:32 -04:00
* @ param string [] $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 relative to the plugins directory .
2016-05-10 07:11:30 -04:00
*/
$install_actions = apply_filters ( 'install_plugin_complete_actions' , $install_actions , $this -> api , $plugin_file );
2016-09-17 12:23:27 -04:00
if ( ! empty ( $install_actions ) ) {
$this -> feedback ( implode ( ' ' , ( array ) $install_actions ) );
}
2016-05-10 07:11:30 -04:00
}
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
/**
* Check if the plugin can be overwritten and output the HTML for overwriting a plugin on upload .
*
* @ since 5.5 . 0
*
* @ return bool Whether the plugin can be overwritten and HTML was outputted .
*/
private function do_overwrite () {
if ( 'upload' !== $this -> type || ! is_wp_error ( $this -> result ) || 'folder_exists' !== $this -> result -> get_error_code () ) {
return false ;
}
$folder = $this -> result -> get_error_data ( 'folder_exists' );
$folder = ltrim ( substr ( $folder , strlen ( WP_PLUGIN_DIR ) ), '/' );
$current_plugin_data = false ;
foreach ( get_plugins () as $plugin => $plugin_data ) {
if ( strrpos ( $plugin , $folder ) !== 0 ) {
continue ;
}
$current_plugin_data = $plugin_data ;
}
if ( empty ( $current_plugin_data ) || empty ( $this -> upgrader -> new_plugin_data ) ) {
return false ;
}
echo '<h2 class="update-from-upload-heading">' . esc_html ( __ ( 'This plugin is already installed.' ) ) . '</h2>' ;
$this -> is_downgrading = version_compare ( $current_plugin_data [ 'Version' ], $this -> upgrader -> new_plugin_data [ 'Version' ], '>' );
$rows = array (
'Name' => __ ( 'Plugin name' ),
'Version' => __ ( 'Version' ),
'Author' => __ ( 'Author' ),
'RequiresWP' => __ ( 'Required WordPress version' ),
'RequiresPHP' => __ ( 'Required PHP version' ),
);
$table = '<table class="update-from-upload-comparison"><tbody>' ;
$table .= '<tr><th></th><th>' . esc_html ( __ ( 'Current' ) ) . '</th>' ;
$table .= '<th>' . esc_html ( __ ( 'Uploaded' ) ) . '</th></tr>' ;
2020-07-12 06:55:03 -04:00
$is_same_plugin = true ; // Let's consider only these rows.
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
foreach ( $rows as $field => $label ) {
2020-07-12 16:00:03 -04:00
$old_value = ! empty ( $current_plugin_data [ $field ] ) ? ( string ) $current_plugin_data [ $field ] : '-' ;
$new_value = ! empty ( $this -> upgrader -> new_plugin_data [ $field ] ) ? ( string ) $this -> upgrader -> new_plugin_data [ $field ] : '-' ;
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
$is_same_plugin = $is_same_plugin && ( $old_value === $new_value );
$diff_field = ( 'Version' !== $field && $new_value !== $old_value );
$diff_version = ( 'Version' === $field && $this -> is_downgrading );
2020-07-12 16:00:03 -04:00
$table .= '<tr><td class="name-label">' . $label . '</td><td>' . wp_strip_all_tags ( $old_value ) . '</td>' ;
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
$table .= ( $diff_field || $diff_version ) ? '<td class="warning">' : '<td>' ;
2020-07-12 16:00:03 -04:00
$table .= wp_strip_all_tags ( $new_value ) . '</td></tr>' ;
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
}
$table .= '</tbody></table>' ;
/**
2020-07-11 21:19:03 -04:00
* Filters the compare table output for overwriting a plugin package on upload .
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
*
* @ since 5.5 . 0
*
2020-07-11 21:19:03 -04:00
* @ param string $table The output table with Name , Version , Author , RequiresWP , and RequiresPHP info .
* @ param array $current_plugin_data Array with current plugin data .
* @ param array $new_plugin_data Array with uploaded plugin data .
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
*/
echo apply_filters ( 'install_plugin_ovewrite_comparison' , $table , $current_plugin_data , $this -> upgrader -> new_plugin_data );
$install_actions = array ();
$can_update = true ;
$blocked_message = '<p>' . esc_html ( __ ( 'The plugin cannot be updated due to the following:' ) ) . '</p>' ;
$blocked_message .= '<ul class="ul-disc">' ;
2020-07-12 06:55:03 -04:00
if ( ! empty ( $this -> upgrader -> new_plugin_data [ 'RequiresPHP' ] )
&& ! is_php_version_compatible ( $this -> upgrader -> new_plugin_data [ 'RequiresPHP' ] )
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
) {
$error = sprintf (
/* translators: 1: Current PHP version, 2: Version required by the uploaded plugin. */
__ ( 'The PHP version on your server is %1$s, however the uploaded plugin requires %2$s.' ),
phpversion (),
$this -> upgrader -> new_plugin_data [ 'RequiresPHP' ]
);
$blocked_message .= '<li>' . esc_html ( $error ) . '</li>' ;
$can_update = false ;
}
2020-07-12 06:55:03 -04:00
if ( ! empty ( $this -> upgrader -> new_plugin_data [ 'RequiresWP' ] )
&& ! is_wp_version_compatible ( $this -> upgrader -> new_plugin_data [ 'RequiresWP' ] )
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
) {
$error = sprintf (
/* translators: 1: Current WordPress version, 2: Version required by the uploaded plugin. */
__ ( 'Your WordPress version is %1$s, however the uploaded plugin requires %2$s.' ),
$GLOBALS [ 'wp_version' ],
$this -> upgrader -> new_plugin_data [ 'RequiresWP' ]
);
$blocked_message .= '<li>' . esc_html ( $error ) . '</li>' ;
$can_update = false ;
}
$blocked_message .= '</ul>' ;
if ( $can_update ) {
if ( $this -> is_downgrading ) {
2020-07-12 06:34:05 -04:00
$warning = sprintf (
/* translators: %s: Documentation URL. */
__ ( 'You are uploading an older version of a current plugin. You can continue to install the older version, but be sure to <a href="%s">back up your database and files</a> first.' ),
__ ( 'https://wordpress.org/support/article/wordpress-backups/' )
);
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
} else {
2020-07-12 06:34:05 -04:00
$warning = sprintf (
/* translators: %s: Documentation URL. */
__ ( 'You are updating a plugin. Be sure to <a href="%s">back up your database and files</a> first.' ),
__ ( 'https://wordpress.org/support/article/wordpress-backups/' )
);
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
}
echo '<p class="update-from-upload-notice">' . $warning . '</p>' ;
$overwrite = $this -> is_downgrading ? 'downgrade-plugin' : 'update-plugin' ;
$install_actions [ 'ovewrite_plugin' ] = sprintf (
2020-07-10 02:08:06 -04:00
'<a class="button button-primary update-from-upload-overwrite" href="%s" target="_parent">%s</a>' ,
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
wp_nonce_url ( add_query_arg ( 'overwrite' , $overwrite , $this -> url ), 'plugin-upload' ),
2020-07-10 02:08:06 -04:00
__ ( 'Replace current with uploaded' )
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
);
} else {
echo $blocked_message ;
}
2020-07-10 02:08:06 -04:00
$cancel_url = add_query_arg ( 'action' , 'upload-plugin-cancel-overwrite' , $this -> url );
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
$install_actions [ 'plugins_page' ] = sprintf (
'<a class="button" href="%s">%s</a>' ,
2020-07-10 02:08:06 -04:00
wp_nonce_url ( $cancel_url , 'plugin-upload-cancel-overwrite' ),
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
__ ( 'Cancel and go back' )
);
/**
* Filters the list of action links available following a single plugin installation failed but ovewrite is allowed .
*
* @ since 5.5 . 0
*
* @ param string [] $install_actions Array of plugin action links .
* @ param object $api Object containing WordPress . org API plugin data .
* @ param array $new_plugin_data Array with uploaded plugin data .
*/
$install_actions = apply_filters ( 'install_plugin_ovewrite_actions' , $install_actions , $this -> api , $this -> upgrader -> new_plugin_data );
if ( ! empty ( $install_actions ) ) {
2020-07-10 02:08:06 -04:00
printf (
'<p class="update-from-upload-expired hidden">%s</p>' ,
__ ( 'The uploaded file has expired. Please go back and upload it again.' )
);
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
echo '<p class="update-from-upload-actions">' . implode ( ' ' , ( array ) $install_actions ) . '</p>' ;
}
return true ;
}
2016-05-10 07:11:30 -04:00
}