Skip to content

Commit

Permalink
Show a more meaningful notice when trying to install WP plugin in Git…
Browse files Browse the repository at this point in the history
  • Loading branch information
John Spellman authored and Pantheon Automation committed Jul 12, 2022
1 parent ee3b1d9 commit d1ff5a1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions wp-content/mu-plugins/pantheon.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
if ( ! defined('RETURN_TO_PANTHEON_BUTTON') || RETURN_TO_PANTHEON_BUTTON ) {
require_once 'pantheon/pantheon-login-form-mods.php';
}
if ( 'dev' === $_ENV['PANTHEON_ENVIRONMENT'] && function_exists( 'wp_is_writable' ) ) {
require_once 'pantheon/pantheon-plugin-install-notice.php';
}
if ( ! defined( 'FS_METHOD' ) ) {
/**
* When this constant is not set, WordPress writes and then deletes a
Expand Down
29 changes: 29 additions & 0 deletions wp-content/mu-plugins/pantheon/pantheon-plugin-install-notice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* If a Pantheon site is in Git mode, hide the Plugin installation functionality and show a notice.
*/

if ( ! wp_is_writable( WP_PLUGIN_DIR ) ) {
if ( ! defined( 'DISALLOW_FILE_MODS' ) ) {
define( 'DISALLOW_FILE_MODS', true );
}

add_action( 'admin_notices', '_pantheon_plugin_install_notice' );
add_action( 'network_admin_notices', '_pantheon_plugin_install_notice' );
}

function _pantheon_plugin_install_notice() {
$screen = get_current_screen();
// Only show this notice on the plugins page.
if ( 'plugins' === $screen->id || 'plugins-network' === $screen->id ) { ?>
<div class="update-nag notice notice-warning is-dismissible" style="margin: 5px 6em 15px 0;">
<p style="font-size: 14px; margin: 0;">
<?php
// Translators: %s is a URL to the user's Pantheon Dashboard.
echo wp_kses_post( sprintf( __( 'If you wish to update or add plugins using the WordPress UI, switch your site to SFTP mode from <a href="%s">your Pantheon dashboard</a>.', 'pantheon-systems' ), 'https://dashboard.pantheon.io/sites/' . $_ENV['PANTHEON_SITE'] ) );
?>
</p>
</div>
<?php
}
}

0 comments on commit d1ff5a1

Please sign in to comment.