Merged in feature/remove-mu-plugins (pull request #18)
remove pantheon mu-plugins * remove pantheon mu-plugins
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
# IMPORTANT NOTE:
|
||||
# Do not edit this file unless you are doing so in your custom upstream repository.
|
||||
# Override the defaults specified here in a site-specific `pantheon.yml` file.
|
||||
# For more information see: https://pantheon.io/docs/pantheon-upstream-yml
|
||||
api_version: 1
|
||||
php_version: 8.1
|
||||
|
||||
# See https://pantheon.io/docs/pantheon-yml#specify-a-version-of-mariadb
|
||||
database:
|
||||
version: 10.4
|
||||
|
||||
# See https://pantheon.io/docs/pantheon-yml/#enforce-https--hsts for valid values.
|
||||
enforce_https: transitional
|
||||
|
||||
# See https://pantheon.io/docs/pantheon-yml#protected-web-paths for usage.
|
||||
protected_web_paths:
|
||||
- /private/
|
||||
- /wp-content/uploads/private/
|
||||
- /xmlrpc.php
|
||||
|
||||
# By default, any 'protected_web_paths' added to the pantheon.yml file
|
||||
# are combined with the paths from the pantheon.upstream.yml file. If
|
||||
# 'protected_web_paths_override' is set to true, then the upstream paths
|
||||
# are disabled.
|
||||
protected_web_paths_override: false
|
||||
@@ -1,22 +0,0 @@
|
||||
api_version: 1
|
||||
enforce_https: full+subdomains
|
||||
php_version: 7.4
|
||||
|
||||
protected_web_paths:
|
||||
- /.user.ini
|
||||
|
||||
workflows:
|
||||
|
||||
# Commits
|
||||
sync_code:
|
||||
after:
|
||||
- type: webphp
|
||||
description: Post to Slack after each code pushed
|
||||
script: private/scripts/slack_notification.php
|
||||
|
||||
# Database Clone
|
||||
clone_database:
|
||||
after:
|
||||
- type: webphp
|
||||
description: Change SFDC environment after database clone
|
||||
script: private/scripts/sfdc_env.php
|
||||
@@ -1,76 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Name: Pantheon MU Plugin Loader
|
||||
* Description: Loads the MU plugins required to run the site
|
||||
* Author: Pantheon Systems
|
||||
* Author URI: https://pantheon.io
|
||||
* Version: 1.0
|
||||
*/
|
||||
|
||||
if ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add mu-plugins here.
|
||||
$pantheon_mu_plugins = [
|
||||
'pantheon-mu-plugin/pantheon.php',
|
||||
];
|
||||
|
||||
foreach ( $pantheon_mu_plugins as $file ) {
|
||||
require_once WPMU_PLUGIN_DIR . '/' . $file;
|
||||
}
|
||||
unset( $file );
|
||||
|
||||
add_action( 'pre_current_active_plugins', function () use ( $pantheon_mu_plugins ) {
|
||||
global $plugins, $wp_list_table;
|
||||
|
||||
// Add our own mu-plugins to the page.
|
||||
foreach ( $pantheon_mu_plugins as $plugin_file ) {
|
||||
// Do not apply markup/translate as it'll be cached.
|
||||
$plugin_data = get_plugin_data( WPMU_PLUGIN_DIR . "/$plugin_file", false, false );
|
||||
|
||||
if ( empty( $plugin_data['Name'] ) ) {
|
||||
$plugin_data['Name'] = $plugin_file;
|
||||
}
|
||||
|
||||
$plugins['mustuse'][ $plugin_file ] = $plugin_data;
|
||||
}
|
||||
|
||||
// Recount totals.
|
||||
$GLOBALS['totals']['mustuse'] = count( $plugins['mustuse'] );
|
||||
|
||||
// Only apply the rest if we're actually looking at the page.
|
||||
if ( $GLOBALS['status'] !== 'mustuse' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset the list table's data.
|
||||
$wp_list_table->items = $plugins['mustuse'];
|
||||
foreach ( $wp_list_table->items as $plugin_file => $plugin_data ) {
|
||||
$wp_list_table->items[ $plugin_file ] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true );
|
||||
}
|
||||
|
||||
$total_this_page = $GLOBALS['totals']['mustuse'];
|
||||
|
||||
if ( $GLOBALS['orderby'] ) {
|
||||
uasort( $wp_list_table->items, [ $wp_list_table, '_order_callback' ] );
|
||||
}
|
||||
|
||||
// Force showing all plugins.
|
||||
// See https://core.trac.wordpress.org/ticket/27110.
|
||||
$plugins_per_page = $total_this_page;
|
||||
|
||||
$wp_list_table->set_pagination_args( [
|
||||
'total_items' => $total_this_page,
|
||||
'per_page' => $plugins_per_page,
|
||||
] );
|
||||
});
|
||||
|
||||
add_filter( 'network_admin_plugin_action_links', function ( $actions, $plugin_file, $plugin_data, $context ) use ( $pantheon_mu_plugins ) {
|
||||
if ( $context !== 'mustuse' || ! in_array( $plugin_file, $pantheon_mu_plugins, true ) ) {
|
||||
return $actions;
|
||||
}
|
||||
|
||||
$actions[] = sprintf( '<span style="color:#333">File: <code>%s</code></span>', $plugin_file );
|
||||
return $actions;
|
||||
}, 10, 4 );
|
||||
@@ -1,3 +0,0 @@
|
||||
# Ignore composer files.
|
||||
/vendor
|
||||
composer.lock
|
||||
@@ -1 +0,0 @@
|
||||
* @pantheon-systems/cms-platform
|
||||
@@ -1,16 +0,0 @@
|
||||
# editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
indent_style = tab
|
||||
|
||||
[{.jshintrc,*.json,*.yml}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[{*.txt,wp-config-sample.php}]
|
||||
end_of_line = crlf
|
||||
@@ -1,63 +0,0 @@
|
||||
#login {
|
||||
width: 500px;
|
||||
}
|
||||
|
||||
#return-to-pantheon {
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
#return-to-pantheon .left {
|
||||
font-size: 16px;
|
||||
font-weight: 400;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
#return-to-pantheon a{
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
color: #000000;
|
||||
padding: 5px 10px;
|
||||
background: #F8DD44;
|
||||
color: #000000 !important;
|
||||
text-decoration: none !important;
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
border-radius: 10px;
|
||||
min-width: 130px
|
||||
}
|
||||
|
||||
#return-to-pantheon a:hover {
|
||||
-webkit-transition: all 0.25s;
|
||||
-moz-transition: all 0.25s;
|
||||
transition: all 0.25s;
|
||||
background: #EFD01B;
|
||||
color: #333333 !important;
|
||||
}
|
||||
|
||||
#return-to-pantheon .fist-icon {
|
||||
display: inline-block;
|
||||
width: 12px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
@media (max-width: 499px) {
|
||||
#login {
|
||||
width: 320px;
|
||||
}
|
||||
#return-to-pantheon {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
#return-to-pantheon .left {
|
||||
order: 2;
|
||||
}
|
||||
|
||||
#return-to-pantheon .right {
|
||||
margin-bottom: 25px;
|
||||
order: 1;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="14px" height="32px" viewBox="0 0 14 32" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<!-- Generator: Sketch 46.2 (44496) - http://www.bohemiancoding.com/sketch -->
|
||||
<title>Group 11</title>
|
||||
<desc>Created with Sketch.</desc>
|
||||
<defs></defs>
|
||||
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="WP---button" transform="translate(-322.000000, -538.000000)" fill="#333333">
|
||||
<g id="Group" transform="translate(311.000000, 534.000000)">
|
||||
<g id="Group-11" transform="translate(11.000000, 4.000000)">
|
||||
<path d="M1.54822908,0 L4.52272957,6.90999702 L0.736842105,6.90999702 L1.98837032,9.82347541 L9.66224514,9.82347541 L1.54822908,0 L1.54822908,0 Z M11.589856,24.7575559 L10.3368651,21.8425037 L8.57849426,21.8425037 L8.54163298,21.7553741 L6.11083637,16.1102593 L4.6957728,16.1102593 L7.16386951,21.8425037 L2.66269769,21.8425037 L10.7780302,31.6679821 L7.80265209,24.7575559 L11.589856,24.7575559 L11.589856,24.7575559 Z" id="Fill-1"></path>
|
||||
<path d="M6.3944081,15.35938 L5.16291955,12.493687 L4.54724842,12.493687 L5.77976089,15.3559463 L3.74741716,15.3559463 L6.2165378,21.0911952 L1.18058487,21.0911952 C0.756241333,21.0911952 0.522640287,21.0911952 0.330873868,20.4898718 C0.102099894,19.7718033 0,18.2748614 0,15.6365067 C0,12.9982951 0.102099894,11.5016393 0.330873868,10.7831416 C0.522640287,10.1818182 0.756241333,10.1818182 1.18058487,10.1818182 L6.73391219,10.1818182 L8.96270314,15.35938 L6.3944081,15.35938 Z M12.6233793,18.7798987 C12.7164101,18.7798987 12.9331895,18.892924 12.9331895,19.9363338 C12.9331895,20.9791714 12.7164101,21.0911952 12.6233793,21.0911952 L8.86294364,21.0911952 L7.86842046,18.7798987 L12.6233793,18.7798987 Z M12.6233793,12.493687 L8.3441065,12.493687 L7.34958333,10.1818182 L12.6233793,10.1818182 C12.7164101,10.1818182 12.9331895,10.2944143 12.9331895,11.3369657 C12.9331895,12.3800894 12.7164101,12.493687 12.6233793,12.493687 Z M13.063228,15.9142057 C13.1571364,15.9142057 13.3739159,16.0268018 13.3739159,17.0699255 C13.3739159,18.1130492 13.1571364,18.225073 13.063228,18.225073 L7.6291147,18.225073 L6.63415269,15.9142057 L13.063228,15.9142057 Z M13.063228,13.0485127 C13.1571364,13.0485127 13.3739159,13.1601073 13.3739159,14.2036602 C13.3739159,15.2463547 13.1571364,15.35938 13.063228,15.35938 L9.57837427,15.35938 L8.58297345,13.0485127 L13.063228,13.0485127 Z" id="Path"></path>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 2.5 KiB |
@@ -1,8 +0,0 @@
|
||||
jQuery(document).ready(function( $ ) {
|
||||
|
||||
$('#return-to-pantheon')
|
||||
.detach()
|
||||
.prependTo('#loginform')
|
||||
.show();
|
||||
|
||||
});
|
||||
@@ -1,97 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* WP-CLI commands for the Pantheon mu-plugin.
|
||||
*
|
||||
* @package pantheon
|
||||
*/
|
||||
|
||||
namespace Pantheon\CLI;
|
||||
|
||||
use Pantheon_Cache;
|
||||
use WP_CLI;
|
||||
|
||||
// Support the old pantheon-cache command but return a deprecation notice.
|
||||
WP_CLI::add_command( 'pantheon-cache set-maintenance-mode', '\\Pantheon\\CLI\\__deprecated_maintenance_mode_output' );
|
||||
WP_CLI::add_command( 'pantheon cache set-maintenance-mode', '\\Pantheon\\CLI\\set_maintenance_mode_command' );
|
||||
WP_CLI::add_command( 'pantheon set-maintenance-mode', '\\Pantheon\\CLI\\set_maintenance_mode_command' );
|
||||
|
||||
/**
|
||||
* Sets maintenance mode status.
|
||||
*
|
||||
* Enable maintenance mode to work on your site while serving cached pages
|
||||
* to visitors and bots, or everyone except administators.
|
||||
*
|
||||
* ## DEPRECATION NOTICE
|
||||
*
|
||||
* This command is deprecated and will be removed in a future release.
|
||||
* Use `pantheon set-maintenance-mode` instead.
|
||||
*
|
||||
* ## USAGE
|
||||
*
|
||||
* wp pantheon-cache set-maintenance-mode <status> (deprecated) or
|
||||
* wp pantheon cache set-maintenance-mode <status>
|
||||
*
|
||||
* ## OPTIONS
|
||||
*
|
||||
* <status>
|
||||
* : Maintenance mode status.
|
||||
* ---
|
||||
* options:
|
||||
* - disabled
|
||||
* - anonymous
|
||||
* - everyone
|
||||
* ---
|
||||
*
|
||||
* @subcommand set-maintenance-mode
|
||||
*
|
||||
* @deprecated 1.0.0
|
||||
*/
|
||||
function __deprecated_maintenance_mode_output( $args ) {
|
||||
$allowed_args = [ 'disabled', 'anonymous', 'everyone' ];
|
||||
$replacement_command = ( ! empty( $args && count( $args ) === 1 ) && in_array( $args[0], $allowed_args, true ) ) ? 'set-maintenance-mode ' . $args[0] : false;
|
||||
|
||||
// translators: %s is the replacement command.
|
||||
WP_CLI::warning( WP_CLI::colorize( '%y' . sprintf( __( 'This command is deprecated and will be removed in a future release. Use `wp pantheon %s` instead.', 'pantheon-systems' ), $replacement_command ) . '%n' ) );
|
||||
WP_CLI::line( __( 'Run `wp pantheon set-maintenance-mode --help` for more information.', 'pantheon-systems' ) );
|
||||
|
||||
// The command should fail before we get here, but in case it doesn't, display an error.
|
||||
if ( false === $replacement_command ) {
|
||||
WP_CLI::error( __( 'Invalid arguments. Run `wp pantheon set-maintenance-mode --help` for more infomation.', 'pantheon-systems' ) );
|
||||
}
|
||||
|
||||
set_maintenance_mode_command( $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets maintenance mode status.
|
||||
*
|
||||
* Enable maintenance mode to work on your site while serving cached pages
|
||||
* to visitors and bots, or everyone except administators.
|
||||
*
|
||||
* ## OPTIONS
|
||||
*
|
||||
* <status>
|
||||
* : Maintenance mode status.
|
||||
* ---
|
||||
* options:
|
||||
* - disabled
|
||||
* - anonymous
|
||||
* - everyone
|
||||
* ---
|
||||
*
|
||||
* @subcommand set-maintenance-mode
|
||||
*/
|
||||
function set_maintenance_mode_command( $args ) {
|
||||
|
||||
list( $status ) = $args;
|
||||
|
||||
$out = Pantheon_Cache()->default_options;
|
||||
if ( ! empty( $status )
|
||||
&& in_array( $status, [ 'anonymous', 'everyone' ], true ) ) {
|
||||
$out['maintenance_mode'] = $status;
|
||||
} else {
|
||||
$out['maintenance_mode'] = 'disabled';
|
||||
}
|
||||
update_option( Pantheon_Cache::SLUG, $out );
|
||||
WP_CLI::success( sprintf( 'Maintenance mode set to: %s', $out['maintenance_mode'] ) );
|
||||
}
|
||||
@@ -1,704 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* File mostly copied from wp-admin/includes/network.php.
|
||||
*
|
||||
* Changes:
|
||||
* - Multisite instructions on step2
|
||||
* - Text area rows increased
|
||||
* - Allow altering config filename
|
||||
* - Allow altering config contents
|
||||
* - Remove if file_exists .htaccess
|
||||
*/
|
||||
|
||||
/**
|
||||
* Check for an existing network.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @global wpdb $wpdb WordPress database abstraction object.
|
||||
*
|
||||
* @return string|false Base domain if network exists, otherwise false.
|
||||
*/
|
||||
function network_domain_check() {
|
||||
global $wpdb;
|
||||
|
||||
$sql = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->site ) );
|
||||
if ( $wpdb->get_var( $sql ) ) { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
||||
return $wpdb->get_var( "SELECT domain FROM $wpdb->site ORDER BY id ASC LIMIT 1" );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow subdomain installation
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @return bool Whether subdomain installation is allowed
|
||||
*/
|
||||
function allow_subdomain_install() {
|
||||
$domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( 'home' ) );
|
||||
if ( parse_url( get_option( 'home' ), PHP_URL_PATH ) || 'localhost' === $domain || preg_match( '|^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$|', $domain ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow subdirectory installation.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @global wpdb $wpdb WordPress database abstraction object.
|
||||
*
|
||||
* @return bool Whether subdirectory installation is allowed
|
||||
*/
|
||||
function allow_subdirectory_install() {
|
||||
global $wpdb;
|
||||
|
||||
/**
|
||||
* Filters whether to enable the subdirectory installation feature in Multisite.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param bool $allow Whether to enable the subdirectory installation feature in Multisite.
|
||||
* Default false.
|
||||
*/
|
||||
if ( apply_filters( 'allow_subdirectory_install', false ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( defined( 'ALLOW_SUBDIRECTORY_INSTALL' ) && ALLOW_SUBDIRECTORY_INSTALL ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$post = $wpdb->get_row( "SELECT ID FROM $wpdb->posts WHERE post_date < DATE_SUB(NOW(), INTERVAL 1 MONTH) AND post_status = 'publish'" );
|
||||
if ( empty( $post ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get base domain of network.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @return string Base domain.
|
||||
*/
|
||||
function get_clean_basedomain() {
|
||||
$existing_domain = network_domain_check();
|
||||
if ( $existing_domain ) {
|
||||
return $existing_domain;
|
||||
}
|
||||
$domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) );
|
||||
$slash = strpos( $domain, '/' );
|
||||
if ( $slash ) {
|
||||
$domain = substr( $domain, 0, $slash );
|
||||
}
|
||||
return $domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints step 1 for Network installation process.
|
||||
*
|
||||
* @todo Realistically, step 1 should be a welcome screen explaining what a Network is and such.
|
||||
* Navigating to Tools > Network should not be a sudden "Welcome to a new install process!
|
||||
* Fill this out and click here." See also contextual help todo.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @global bool $is_apache
|
||||
*
|
||||
* @param false|WP_Error $errors Optional. Error object. Default false.
|
||||
*/
|
||||
function network_step1( $errors = false ) {
|
||||
if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
|
||||
echo '<div class="error"><p><strong>' . esc_html__( 'Error:' ) . '</strong> ' . sprintf(
|
||||
/* translators: %s: DO_NOT_UPGRADE_GLOBAL_TABLES */
|
||||
esc_html__( 'The constant %s cannot be defined when creating a network.' ),
|
||||
'<code>DO_NOT_UPGRADE_GLOBAL_TABLES</code>'
|
||||
) . '</p></div>';
|
||||
echo '</div>';
|
||||
require_once ABSPATH . 'wp-admin/admin-footer.php';
|
||||
die();
|
||||
}
|
||||
|
||||
$active_plugins = get_option( 'active_plugins' );
|
||||
if ( ! empty( $active_plugins ) ) {
|
||||
echo '<div class="notice notice-warning"><p><strong>' . esc_html__( 'Warning:' ) . '</strong> ' . sprintf(
|
||||
/* translators: %s: URL to Plugins screen. */
|
||||
wp_kses_post( __( 'Please <a href="%s">deactivate your plugins</a> before enabling the Network feature.' ) ),
|
||||
esc_url_raw( admin_url( 'plugins.php?plugin_status=active' ) )
|
||||
) . '</p></div>';
|
||||
echo '<p>' . esc_html__( 'Once the network is created, you may reactivate your plugins.' ) . '</p>';
|
||||
echo '</div>';
|
||||
require_once ABSPATH . 'wp-admin/admin-footer.php';
|
||||
die();
|
||||
}
|
||||
|
||||
$hostname = get_clean_basedomain();
|
||||
$has_ports = strstr( $hostname, ':' );
|
||||
if ( ( false !== $has_ports && ! in_array( $has_ports, [ ':80', ':443' ], true ) ) ) {
|
||||
echo '<div class="error"><p><strong>' . esc_html__( 'Error:' ) . '</strong> ' . esc_html__( 'You cannot install a network of sites with your server address.' ) . '</p></div>';
|
||||
echo '<p>' . sprintf(
|
||||
/* translators: %s: Port number. */
|
||||
esc_html__( 'You cannot use port numbers such as %s.' ),
|
||||
'<code>' . $has_ports . '</code>' // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
) . '</p>';
|
||||
echo '<a href="' . esc_url( admin_url() ) . '">' . esc_html__( 'Go to Dashboard' ) . '</a>';
|
||||
echo '</div>';
|
||||
require_once ABSPATH . 'wp-admin/admin-footer.php';
|
||||
die();
|
||||
}
|
||||
|
||||
echo '<form method="post">';
|
||||
|
||||
wp_nonce_field( 'install-network-1' );
|
||||
|
||||
$error_codes = [];
|
||||
if ( is_wp_error( $errors ) ) {
|
||||
echo '<div class="error"><p><strong>' . esc_html__( 'Error: The network could not be created.' ) . '</strong></p>';
|
||||
foreach ( $errors->get_error_messages() as $error ) {
|
||||
echo "<p>$error</p>"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
echo '</div>';
|
||||
$error_codes = $errors->get_error_codes();
|
||||
}
|
||||
|
||||
if ( ! empty( $_POST['sitename'] ) && ! in_array( 'empty_sitename', $error_codes, true ) ) {
|
||||
$site_name = $_POST['sitename'];
|
||||
} else {
|
||||
/* translators: %s: Default network title. */
|
||||
$site_name = sprintf( __( '%s Sites' ), get_option( 'blogname' ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $_POST['email'] ) && ! in_array( 'invalid_email', $error_codes, true ) ) {
|
||||
$admin_email = $_POST['email'];
|
||||
} else {
|
||||
$admin_email = get_option( 'admin_email' );
|
||||
}
|
||||
?>
|
||||
<p><?php esc_html_e( 'Welcome to the Network installation process!' ); ?></p>
|
||||
<p><?php esc_html_e( 'Fill in the information below and you’ll be on your way to creating a network of WordPress sites. Configuration files will be created in the next step.' ); ?></p>
|
||||
<?php
|
||||
|
||||
if ( isset( $_POST['subdomain_install'] ) ) {
|
||||
$subdomain_install = (bool) $_POST['subdomain_install'];
|
||||
} elseif ( apache_mod_loaded( 'mod_rewrite' ) ) { // Assume nothing.
|
||||
$subdomain_install = true;
|
||||
} elseif ( ! allow_subdirectory_install() ) {
|
||||
$subdomain_install = true;
|
||||
} else {
|
||||
$subdomain_install = false;
|
||||
}
|
||||
|
||||
if ( allow_subdomain_install() && allow_subdirectory_install() ) :
|
||||
?>
|
||||
<h3><?php esc_html_e( 'Addresses of Sites in your Network' ); ?></h3>
|
||||
<p><?php esc_html_e( 'Please choose whether you would like sites in your WordPress network to use sub-domains or sub-directories.' ); ?>
|
||||
<strong><?php esc_html_e( 'You cannot change this later.' ); ?></strong></p>
|
||||
<p><?php esc_html_e( 'You will need a wildcard DNS record if you are going to use the virtual host (sub-domain) functionality.' ); ?></p>
|
||||
<?php // @todo Link to an MS readme? ?>
|
||||
<table class="form-table" role="presentation">
|
||||
<tr>
|
||||
<th><label><input type="radio" name="subdomain_install" value="1"<?php checked( $subdomain_install ); ?> /> <?php esc_html_e( 'Sub-domains' ); ?></label></th>
|
||||
<td>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: 1: Host name. */
|
||||
wp_kses_post( _x( 'like <code>site1.%1$s</code> and <code>site2.%1$s</code>', 'subdomain examples' ) ),
|
||||
$hostname // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
);
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label><input type="radio" name="subdomain_install" value="0"<?php checked( ! $subdomain_install ); ?> /> <?php esc_html_e( 'Sub-directories' ); ?></label></th>
|
||||
<td>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: 1: Host name. */
|
||||
wp_kses_post( _x( 'like <code>%1$s/site1</code> and <code>%1$s/site2</code>', 'subdirectory examples' ) ),
|
||||
$hostname // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
);
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
endif;
|
||||
|
||||
if ( WP_CONTENT_DIR !== ABSPATH . 'wp-content' && ( allow_subdirectory_install() || ! allow_subdomain_install() ) ) {
|
||||
echo '<div class="error inline"><p><strong>' . esc_html__( 'Warning:' ) . '</strong> ' . esc_html__( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</p></div>';
|
||||
}
|
||||
|
||||
$is_www = ( 0 === strpos( $hostname, 'www.' ) );
|
||||
if ( $is_www ) :
|
||||
?>
|
||||
<h3><?php esc_html_e( 'Server Address' ); ?></h3>
|
||||
<p>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: 1: Site URL, 2: Host name, 3: www. */
|
||||
esc_html__( 'You should consider changing your site domain to %1$s before enabling the network feature. It will still be possible to visit your site using the %3$s prefix with an address like %2$s but any links will not have the %3$s prefix.' ),
|
||||
'<code>' . substr( $hostname, 4 ) . '</code>', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
'<code>' . $hostname . '</code>', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
'<code>www</code>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<table class="form-table" role="presentation">
|
||||
<tr>
|
||||
<th scope='row'><?php esc_html_e( 'Server Address' ); ?></th>
|
||||
<td>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s: Host name. */
|
||||
esc_html__( 'The internet address of your network will be %s.' ),
|
||||
'<code>' . $hostname . '</code>' // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
);
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php endif; ?>
|
||||
|
||||
<h3><?php esc_html_e( 'Network Details' ); ?></h3>
|
||||
<table class="form-table" role="presentation">
|
||||
<?php if ( 'localhost' === $hostname ) : ?>
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'Sub-directory Installation' ); ?></th>
|
||||
<td>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: 1: localhost, 2: localhost.localdomain */
|
||||
esc_html__( 'Because you are using %1$s, the sites in your WordPress network must use sub-directories. Consider using %2$s if you wish to use sub-domains.' ),
|
||||
'<code>localhost</code>',
|
||||
'<code>localhost.localdomain</code>'
|
||||
);
|
||||
// Uh oh!
|
||||
if ( ! allow_subdirectory_install() ) {
|
||||
echo ' <strong>' . esc_html__( 'Warning:' ) . ' ' . esc_html__( 'The main site in a sub-directory installation will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php elseif ( ! allow_subdomain_install() ) : ?>
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'Sub-directory Installation' ); ?></th>
|
||||
<td>
|
||||
<?php
|
||||
esc_html_e( 'Because your installation is in a directory, the sites in your WordPress network must use sub-directories.' );
|
||||
// Uh oh!
|
||||
if ( ! allow_subdirectory_install() ) {
|
||||
echo ' <strong>' . esc_html__( 'Warning:' ) . ' ' . esc_html__( 'The main site in a sub-directory installation will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php elseif ( ! allow_subdirectory_install() ) : ?>
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'Sub-domain Installation' ); ?></th>
|
||||
<td>
|
||||
<?php
|
||||
esc_html_e( 'Because your installation is not new, the sites in your WordPress network must use sub-domains.' );
|
||||
echo ' <strong>' . esc_html__( 'The main site in a sub-directory installation will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
<?php if ( ! $is_www ) : ?>
|
||||
<tr>
|
||||
<th scope='row'><?php esc_html_e( 'Server Address' ); ?></th>
|
||||
<td>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s: Host name. */
|
||||
esc_html__( 'The internet address of your network will be %s.' ),
|
||||
'<code>' . $hostname . '</code>' // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
);
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
<tr>
|
||||
<th scope='row'><label for="sitename"><?php esc_html_e( 'Network Title' ); ?></label></th>
|
||||
<td>
|
||||
<input name='sitename' id='sitename' type='text' size='45' value='<?php echo esc_attr( $site_name ); ?>' />
|
||||
<p class="description">
|
||||
<?php esc_html_e( 'What would you like to call your network?' ); ?>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope='row'><label for="email"><?php esc_html_e( 'Network Admin Email' ); ?></label></th>
|
||||
<td>
|
||||
<input name='email' id='email' type='text' size='45' value='<?php echo esc_attr( $admin_email ); ?>' />
|
||||
<p class="description">
|
||||
<?php esc_html_e( 'Your email address.' ); ?>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php submit_button( __( 'Install' ), 'primary', 'submit' ); ?>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints step 2 for Network installation process.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @global wpdb $wpdb WordPress database abstraction object.
|
||||
* @global bool $is_nginx Whether the server software is Nginx or something else.
|
||||
*
|
||||
* @param false|WP_Error $errors Optional. Error object. Default false.
|
||||
*/
|
||||
function network_step2( $errors = false ) {
|
||||
global $wpdb, $is_nginx;
|
||||
|
||||
$hostname = get_clean_basedomain();
|
||||
$slashed_home = trailingslashit( get_option( 'home' ) );
|
||||
$base = parse_url( $slashed_home, PHP_URL_PATH );
|
||||
$document_root_fix = str_replace( '\\', '/', realpath( $_SERVER['DOCUMENT_ROOT'] ) );
|
||||
$abspath_fix = str_replace( '\\', '/', ABSPATH );
|
||||
$home_path = 0 === strpos( $abspath_fix, $document_root_fix ) ? $document_root_fix . $base : get_home_path();
|
||||
$wp_siteurl_subdir = preg_replace( '#^' . preg_quote( $home_path, '#' ) . '#', '', $abspath_fix );
|
||||
$rewrite_base = ! empty( $wp_siteurl_subdir ) ? ltrim( trailingslashit( $wp_siteurl_subdir ), '/' ) : '';
|
||||
|
||||
$config_filename = 'wp-config.php';
|
||||
$config_filename = apply_filters( 'pantheon.multisite.config_filename', 'wp-config.php' );
|
||||
|
||||
$location_of_wp_config = $abspath_fix;
|
||||
if ( ! file_exists( ABSPATH . $config_filename ) && file_exists( dirname( ABSPATH ) . '/' . $config_filename ) ) {
|
||||
$location_of_wp_config = dirname( $abspath_fix );
|
||||
}
|
||||
$location_of_wp_config = trailingslashit( $location_of_wp_config );
|
||||
|
||||
// Wildcard DNS message.
|
||||
if ( is_wp_error( $errors ) ) {
|
||||
echo '<div class="error">' . esc_html( $errors->get_error_message() ) . '</div>';
|
||||
}
|
||||
|
||||
if ( $_POST ) {
|
||||
if ( allow_subdomain_install() ) {
|
||||
$subdomain_install = allow_subdirectory_install() ? ! empty( $_POST['subdomain_install'] ) : true;
|
||||
} else {
|
||||
$subdomain_install = false;
|
||||
}
|
||||
} elseif ( is_multisite() ) {
|
||||
$subdomain_install = is_subdomain_install();
|
||||
?>
|
||||
<p><?php esc_html_e( 'The original configuration steps are shown here for reference.' ); ?></p>
|
||||
<?php
|
||||
} else {
|
||||
$subdomain_install = (bool) $wpdb->get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" );
|
||||
?>
|
||||
<div class="error"><p><strong><?php esc_html_e( 'Warning:' ); ?></strong> <?php esc_html_e( 'An existing WordPress network was detected.' ); ?></p></div>
|
||||
<p><?php esc_html_e( 'Please complete the configuration steps. To create a new network, you will need to empty or remove the network database tables.' ); ?></p>
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
$subdir_match = $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?';
|
||||
$subdir_replacement_01 = $subdomain_install ? '' : '$1';
|
||||
$subdir_replacement_12 = $subdomain_install ? '$1' : '$2';
|
||||
|
||||
if ( $_POST || ! is_multisite() ) {
|
||||
?>
|
||||
<h3><?php esc_html_e( 'Enabling the Network' ); ?></h3>
|
||||
<p><?php esc_html_e( 'Complete the following steps to enable the features for creating a network of sites.' ); ?></p>
|
||||
<div class="notice notice-warning inline"><p>
|
||||
<?php
|
||||
if ( file_exists( $home_path . 'web.config' ) ) {
|
||||
echo '<strong>' . esc_html__( 'Caution:' ) . '</strong> ';
|
||||
printf(
|
||||
/* translators: 1: wp-config.php, 2: web.config */
|
||||
esc_html__( 'You should back up your existing %1$s and %2$s files.' ),
|
||||
'<code>' . $config_filename . '</code>', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
'<code>web.config</code>'
|
||||
);
|
||||
} else {
|
||||
echo '<strong>' . esc_html__( 'Caution:' ) . '</strong> ';
|
||||
printf(
|
||||
/* translators: %s: wp-config.php */
|
||||
esc_html__( 'You should back up your existing %s file.' ),
|
||||
'<code>' . $config_filename . '</code>', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
);
|
||||
}
|
||||
?>
|
||||
</p></div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<ol>
|
||||
<li><p id="network-wpconfig-rules-description">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: 1: wp-config.php, 2: Location of wp-config file, 3: Translated version of "That's all, stop editing! Happy publishing." */
|
||||
esc_html__( 'Add the following to your %1$s file in %2$s <strong>above</strong> the line reading %3$s:' ),
|
||||
'<code>' . $config_filename . '</code>', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
'<code>' . $location_of_wp_config . '</code>', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
// translators: This string should only be translated if wp-config-sample.php is localized.
|
||||
// You can check the localized release package or https://i18n.svn.wordpress.org/<locale code>/branches/<wp version>/dist/wp-config-sample.php.
|
||||
'<code>/* ' . esc_html__( 'That’s all, stop editing! Happy publishing.' ) . ' */</code>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<p class="configuration-rules-label"><label for="network-wpconfig-rules">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s: File name (wp-config.php, .htaccess or web.config). */
|
||||
esc_html__( 'Network configuration rules for %s' ),
|
||||
'<code>' . $config_filename . '</code>' // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
);
|
||||
?>
|
||||
</label></p>
|
||||
<textarea id="network-wpconfig-rules" class="code" readonly="readonly" cols="100" rows="31" aria-describedby="network-wpconfig-rules-description">
|
||||
<?php ob_start(); ?>
|
||||
if ( !empty( $_ENV['PANTHEON_ENVIRONMENT'] )) {
|
||||
$site_name = $_ENV['PANTHEON_SITE_NAME'];
|
||||
// Override $hostname value as needed.
|
||||
switch ( $_ENV['PANTHEON_ENVIRONMENT'] ) {
|
||||
case 'live':
|
||||
$hostname = $_SERVER['HTTP_HOST'];
|
||||
break;
|
||||
case 'test':
|
||||
$hostname = 'test-' . $site_name . '.pantheonsite.io';
|
||||
break;
|
||||
case 'dev':
|
||||
$hostname = 'dev-' . $site_name . '.pantheonsite.io';
|
||||
break;
|
||||
case 'lando':
|
||||
$hostname = $site_name . '.lndo.site';
|
||||
break;
|
||||
default:
|
||||
$hostname = $_ENV['PANTHEON_ENVIRONMENT'] . '-' . $site_name . '.pantheonsite.io';
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// Override with a default hostname.
|
||||
$hostname = '<?php echo $hostname; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>';
|
||||
}
|
||||
define( 'MULTISITE', true );
|
||||
define( 'SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?> );
|
||||
define( 'DOMAIN_CURRENT_SITE', $hostname );
|
||||
define( 'PATH_CURRENT_SITE', '<?php echo $base; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>' );
|
||||
define( 'SITE_ID_CURRENT_SITE', 1 );
|
||||
define( 'BLOG_ID_CURRENT_SITE', 1 );
|
||||
<?php
|
||||
$config_file_contents = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$config_file_contents = apply_filters( 'pantheon.multisite.config_contents', $config_file_contents );
|
||||
echo $config_file_contents; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
?>
|
||||
</textarea>
|
||||
<?php
|
||||
$keys_salts = [
|
||||
'AUTH_KEY' => '',
|
||||
'SECURE_AUTH_KEY' => '',
|
||||
'LOGGED_IN_KEY' => '',
|
||||
'NONCE_KEY' => '',
|
||||
'AUTH_SALT' => '',
|
||||
'SECURE_AUTH_SALT' => '',
|
||||
'LOGGED_IN_SALT' => '',
|
||||
'NONCE_SALT' => '',
|
||||
];
|
||||
foreach ( $keys_salts as $c => $v ) {
|
||||
if ( defined( $c ) ) {
|
||||
unset( $keys_salts[ $c ] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $keys_salts ) ) {
|
||||
$keys_salts_str = '';
|
||||
$from_api = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
|
||||
if ( is_wp_error( $from_api ) ) {
|
||||
foreach ( $keys_salts as $c => $v ) {
|
||||
$keys_salts_str .= "\ndefine( '$c', '" . wp_generate_password( 64, true, true ) . "' );";
|
||||
}
|
||||
} else {
|
||||
$from_api = explode( "\n", wp_remote_retrieve_body( $from_api ) );
|
||||
foreach ( $keys_salts as $c => $v ) {
|
||||
$keys_salts_str .= "\ndefine( '$c', '" . substr( array_shift( $from_api ), 28, 64 ) . "' );";
|
||||
}
|
||||
}
|
||||
$num_keys_salts = count( $keys_salts );
|
||||
?>
|
||||
<p id="network-wpconfig-authentication-description">
|
||||
<?php
|
||||
if ( 1 === $num_keys_salts ) {
|
||||
printf(
|
||||
/* translators: %s: wp-config.php */
|
||||
esc_html__( 'This unique authentication key is also missing from your %s file.' ),
|
||||
'<code>' . $config_filename . '</code>', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
);
|
||||
} else {
|
||||
printf(
|
||||
/* translators: %s: wp-config.php */
|
||||
esc_html__( 'These unique authentication keys are also missing from your %s file.' ),
|
||||
'<code>' . $config_filename . '</code>', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
);
|
||||
}
|
||||
?>
|
||||
<?php esc_html_e( 'To make your installation more secure, you should also add:' ); ?>
|
||||
</p>
|
||||
<p class="configuration-rules-label"><label for="network-wpconfig-authentication"><?php esc_html_e( 'Network configuration authentication keys' ); ?></label></p>
|
||||
<textarea id="network-wpconfig-authentication" class="code" readonly="readonly" cols="100" rows="<?php echo $num_keys_salts; ?>" aria-describedby="network-wpconfig-authentication-description"><?php echo esc_textarea( $keys_salts_str ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></textarea>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</li>
|
||||
<?php
|
||||
if ( iis7_supports_permalinks() ) :
|
||||
// IIS doesn't support RewriteBase, all your RewriteBase are belong to us.
|
||||
$iis_subdir_match = ltrim( $base, '/' ) . $subdir_match;
|
||||
$iis_rewrite_base = ltrim( $base, '/' ) . $rewrite_base;
|
||||
$iis_subdir_replacement = $subdomain_install ? '' : '{R:1}';
|
||||
|
||||
$web_config_file = '<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<system.webServer>
|
||||
<rewrite>
|
||||
<rules>
|
||||
<rule name="WordPress Rule 1" stopProcessing="true">
|
||||
<match url="^index\.php$" ignoreCase="false" />
|
||||
<action type="None" />
|
||||
</rule>';
|
||||
if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
|
||||
$web_config_file .= '
|
||||
<rule name="WordPress Rule for Files" stopProcessing="true">
|
||||
<match url="^' . $iis_subdir_match . 'files/(.+)" ignoreCase="false" />
|
||||
<action type="Rewrite" url="' . $iis_rewrite_base . WPINC . '/ms-files.php?file={R:1}" appendQueryString="false" />
|
||||
</rule>';
|
||||
}
|
||||
$web_config_file .= '
|
||||
<rule name="WordPress Rule 2" stopProcessing="true">
|
||||
<match url="^' . $iis_subdir_match . 'wp-admin$" ignoreCase="false" />
|
||||
<action type="Redirect" url="' . $iis_subdir_replacement . 'wp-admin/" redirectType="Permanent" />
|
||||
</rule>
|
||||
<rule name="WordPress Rule 3" stopProcessing="true">
|
||||
<match url="^" ignoreCase="false" />
|
||||
<conditions logicalGrouping="MatchAny">
|
||||
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
|
||||
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
|
||||
</conditions>
|
||||
<action type="None" />
|
||||
</rule>
|
||||
<rule name="WordPress Rule 4" stopProcessing="true">
|
||||
<match url="^' . $iis_subdir_match . '(wp-(content|admin|includes).*)" ignoreCase="false" />
|
||||
<action type="Rewrite" url="' . $iis_rewrite_base . '{R:1}" />
|
||||
</rule>
|
||||
<rule name="WordPress Rule 5" stopProcessing="true">
|
||||
<match url="^' . $iis_subdir_match . '([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
|
||||
<action type="Rewrite" url="' . $iis_rewrite_base . '{R:2}" />
|
||||
</rule>
|
||||
<rule name="WordPress Rule 6" stopProcessing="true">
|
||||
<match url="." ignoreCase="false" />
|
||||
<action type="Rewrite" url="index.php" />
|
||||
</rule>
|
||||
</rules>
|
||||
</rewrite>
|
||||
</system.webServer>
|
||||
</configuration>
|
||||
';
|
||||
|
||||
echo '<li><p id="network-webconfig-rules-description">';
|
||||
printf(
|
||||
/* translators: 1: File name (.htaccess or web.config), 2: File path. */
|
||||
wp_kses_post( __( 'Add the following to your %1$s file in %2$s, <strong>replacing</strong> other WordPress rules:' ) ),
|
||||
'<code>web.config</code>',
|
||||
'<code>' . $home_path . '</code>' // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
);
|
||||
echo '</p>';
|
||||
if ( ! $subdomain_install && WP_CONTENT_DIR !== ABSPATH . 'wp-content' ) {
|
||||
echo '<p><strong>' . esc_html__( 'Warning:' ) . ' ' . esc_html__( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</strong></p>';
|
||||
}
|
||||
?>
|
||||
<p class="configuration-rules-label"><label for="network-webconfig-rules">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s: File name (wp-config.php, .htaccess or web.config). */
|
||||
esc_html__( 'Network configuration rules for %s' ),
|
||||
'<code>web.config</code>'
|
||||
);
|
||||
?>
|
||||
</label></p>
|
||||
<textarea id="network-webconfig-rules" class="code" readonly="readonly" cols="100" rows="20" aria-describedby="network-webconfig-rules-description"><?php echo esc_textarea( $web_config_file ); ?></textarea>
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
<?php
|
||||
elseif ( $is_nginx ) : // End iis7_supports_permalinks(). Link to Nginx documentation instead.
|
||||
|
||||
echo '<li><p>';
|
||||
printf(
|
||||
/* translators: %s: Documentation URL. */
|
||||
wp_kses_post( __( 'It seems your network is running with Nginx web server. <a href="%s">Learn more about further configuration</a>.' ) ),
|
||||
'https://wordpress.org/support/article/nginx/'
|
||||
);
|
||||
echo '</p></li>';
|
||||
|
||||
else : // End $is_nginx. Construct an .htaccess file instead.
|
||||
|
||||
$ms_files_rewriting = '';
|
||||
if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
|
||||
$ms_files_rewriting = "\n# uploaded files\nRewriteRule ^";
|
||||
$ms_files_rewriting .= $subdir_match . "files/(.+) {$rewrite_base}" . WPINC . "/ms-files.php?file={$subdir_replacement_12} [L]" . "\n"; // phpcs:ignore Generic.Strings.UnnecessaryStringConcat.Found
|
||||
}
|
||||
|
||||
$htaccess_file = <<<EOF
|
||||
RewriteEngine On
|
||||
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
|
||||
RewriteBase {$base}
|
||||
RewriteRule ^index\.php$ - [L]
|
||||
{$ms_files_rewriting}
|
||||
# add a trailing slash to /wp-admin
|
||||
RewriteRule ^{$subdir_match}wp-admin$ {$subdir_replacement_01}wp-admin/ [R=301,L]
|
||||
|
||||
RewriteCond %{REQUEST_FILENAME} -f [OR]
|
||||
RewriteCond %{REQUEST_FILENAME} -d
|
||||
RewriteRule ^ - [L]
|
||||
RewriteRule ^{$subdir_match}(wp-(content|admin|includes).*) {$rewrite_base}{$subdir_replacement_12} [L]
|
||||
RewriteRule ^{$subdir_match}(.*\.php)$ {$rewrite_base}$subdir_replacement_12 [L]
|
||||
RewriteRule . index.php [L]
|
||||
|
||||
EOF;
|
||||
|
||||
echo '<li><p id="network-htaccess-rules-description">';
|
||||
printf(
|
||||
/* translators: 1: File name (.htaccess or web.config), 2: File path. */
|
||||
wp_kses_post( __( 'Add the following to your %1$s file in %2$s, <strong>replacing</strong> other WordPress rules:' ) ),
|
||||
'<code>.htaccess</code>',
|
||||
'<code>' . $home_path . '</code>' // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
);
|
||||
echo '</p>';
|
||||
if ( ! $subdomain_install && WP_CONTENT_DIR !== ABSPATH . 'wp-content' ) {
|
||||
echo '<p><strong>' . esc_html__( 'Warning:' ) . ' ' . esc_html__( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</strong></p>';
|
||||
}
|
||||
?>
|
||||
<p class="configuration-rules-label"><label for="network-htaccess-rules">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s: File name (wp-config.php, .htaccess or web.config). */
|
||||
esc_html__( 'Network configuration rules for %s' ),
|
||||
'<code>.htaccess</code>'
|
||||
);
|
||||
?>
|
||||
</label></p>
|
||||
<textarea id="network-htaccess-rules" class="code" readonly="readonly" cols="100" rows="<?php echo substr_count( $htaccess_file, "\n" ) + 1; ?>" aria-describedby="network-htaccess-rules-description"><?php echo esc_textarea( $htaccess_file ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></textarea>
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
<?php
|
||||
endif; // End IIS/Nginx/Apache code branches.
|
||||
|
||||
if ( ! is_multisite() ) {
|
||||
?>
|
||||
<p><?php esc_html_e( 'Once you complete these steps, your network is enabled and configured. You will have to log in again.' ); ?> <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php esc_html_e( 'Log In' ); ?></a></p>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* File mostly copied from wp-admin/network.php.
|
||||
*
|
||||
* Changes:
|
||||
* - s/__DIR__.'\//ABSPATH . 'wp-admin\//g
|
||||
* - s/ABSPATH . 'wp-admin\/includes\/network.php/__DIR__ . '\/includes-network.php/g'
|
||||
*/
|
||||
|
||||
define( 'WP_INSTALLING_NETWORK', true );
|
||||
|
||||
/** WordPress Administration Bootstrap */
|
||||
require_once ABSPATH . 'wp-admin/admin.php';
|
||||
|
||||
if ( ! current_user_can( 'setup_network' ) ) {
|
||||
wp_die( esc_html__( 'Sorry, you are not allowed to manage options for this site.' ) );
|
||||
}
|
||||
|
||||
if ( is_multisite() ) {
|
||||
if ( ! is_network_admin() ) {
|
||||
wp_safe_redirect( network_admin_url( 'setup.php' ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! defined( 'MULTISITE' ) ) {
|
||||
wp_die( esc_html__( 'The Network creation panel is not for WordPress MU networks.' ) );
|
||||
}
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/includes-network.php';
|
||||
|
||||
// We need to create references to ms global tables to enable Network.
|
||||
foreach ( $wpdb->tables( 'ms_global' ) as $table => $prefixed_table ) {
|
||||
$wpdb->$table = $prefixed_table;
|
||||
}
|
||||
|
||||
if ( ! network_domain_check() && ( ! defined( 'WP_ALLOW_MULTISITE' ) || ! WP_ALLOW_MULTISITE ) ) {
|
||||
wp_die(
|
||||
printf( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
/* translators: 1: WP_ALLOW_MULTISITE, 2: wp-config.php */
|
||||
esc_html__( 'You must define the %1$s constant as true in your %2$s file to allow creation of a Network.' ),
|
||||
'<code>WP_ALLOW_MULTISITE</code>',
|
||||
'<code>wp-config.php</code>'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( is_network_admin() ) {
|
||||
// Used in the HTML title tag.
|
||||
$page_title = esc_html__( 'Network Setup' );
|
||||
} else {
|
||||
// Used in the HTML title tag.
|
||||
$page_title = __( 'Create a Network of WordPress Sites' );
|
||||
}
|
||||
|
||||
$network_help = wp_kses_post( '<p>' . __( 'This screen allows you to configure a network as having subdomains (<code>site1.example.com</code>) or subdirectories (<code>example.com/site1</code>). Subdomains require wildcard subdomains to be enabled in Apache and DNS records, if your host allows it.' ) . '</p>' .
|
||||
'<p>' . __( 'Choose subdomains or subdirectories; this can only be switched afterwards by reconfiguring your installation. Fill out the network details, and click Install. If this does not work, you may have to add a wildcard DNS record (for subdomains) or change to another setting in Permalinks (for subdirectories).' ) . '</p>' .
|
||||
'<p>' . __( 'The next screen for Network Setup will give you individually-generated lines of code to add to your wp-config.php and .htaccess files. Make sure the settings of your FTP client make files starting with a dot visible, so that you can find .htaccess; you may have to create this file if it really is not there. Make backup copies of those two files.' ) . '</p>' .
|
||||
'<p>' . __( 'Add the designated lines of code to wp-config.php (just before <code>/*...stop editing...*/</code>) and <code>.htaccess</code> (replacing the existing WordPress rules).' ) . '</p>' .
|
||||
'<p>' . __( 'Once you add this code and refresh your browser, multisite should be enabled. This screen, now in the Network Admin navigation menu, will keep an archive of the added code. You can toggle between Network Admin and Site Admin by clicking on the Network Admin or an individual site name under the My Sites dropdown in the Toolbar.' ) . '</p>' .
|
||||
'<p>' . __( 'The choice of subdirectory sites is disabled if this setup is more than a month old because of permalink problems with “/blog/” from the main site. This disabling will be addressed in a future version.' ) . '</p>' .
|
||||
'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
|
||||
'<p>' . __( '<a href="https://wordpress.org/support/article/create-a-network/">Documentation on Creating a Network</a>' ) . '</p>' .
|
||||
'<p>' . __( '<a href="https://wordpress.org/support/article/tools-network-screen/">Documentation on the Network Screen</a>' ) . '</p>' ); // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent
|
||||
|
||||
get_current_screen()->add_help_tab(
|
||||
[
|
||||
'id' => 'network',
|
||||
'title' => __( 'Network' ),
|
||||
'content' => $network_help,
|
||||
]
|
||||
);
|
||||
|
||||
get_current_screen()->set_help_sidebar(
|
||||
'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
|
||||
'<p>' . __( '<a href="https://wordpress.org/support/article/create-a-network/">Documentation on Creating a Network</a>' ) . '</p>' .
|
||||
'<p>' . __( '<a href="https://wordpress.org/support/article/tools-network-screen/">Documentation on the Network Screen</a>' ) . '</p>' .
|
||||
'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
|
||||
);
|
||||
|
||||
require_once ABSPATH . 'wp-admin/admin-header.php';
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?php echo esc_html( $page_title ); ?></h1>
|
||||
|
||||
<?php
|
||||
if ( $_POST ) {
|
||||
|
||||
check_admin_referer( 'install-network-1' );
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
||||
// Create network tables.
|
||||
install_network();
|
||||
$base = parse_url( trailingslashit( get_option( 'home' ) ), PHP_URL_PATH );
|
||||
$subdomain_install = allow_subdomain_install() ? ! empty( $_POST['subdomain_install'] ) : false;
|
||||
if ( ! network_domain_check() ) {
|
||||
$result = populate_network( 1, get_clean_basedomain(), sanitize_email( $_POST['email'] ), wp_unslash( $_POST['sitename'] ), $base, $subdomain_install );
|
||||
if ( is_wp_error( $result ) ) {
|
||||
if ( 1 === count( $result->get_error_codes() ) && 'no_wildcard_dns' === $result->get_error_code() ) {
|
||||
network_step2( $result );
|
||||
} else {
|
||||
network_step1( $result );
|
||||
}
|
||||
} else {
|
||||
network_step2();
|
||||
}
|
||||
} else {
|
||||
network_step2();
|
||||
}
|
||||
} elseif ( is_multisite() || network_domain_check() ) {
|
||||
network_step2();
|
||||
} else {
|
||||
network_step1();
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
<?php require_once ABSPATH . 'wp-admin/admin-footer.php'; ?>
|
||||
@@ -1,69 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Modify the WordPress login form for Pantheon
|
||||
*/
|
||||
|
||||
/**
|
||||
* Should we proceed with adding the return to Pantheon button?
|
||||
*
|
||||
* Only if we are on a Pantheon subdomain
|
||||
*/
|
||||
$show_return_to_pantheon_button = apply_filters( 'show_return_to_pantheon_button', (
|
||||
(
|
||||
false !== stripos( get_site_url(), 'pantheonsite.io' ) ||
|
||||
( isset( $_SERVER['HTTP_HOST'] ) && false !== stripos( $_SERVER['HTTP_HOST'], 'pantheonsite.io' ) )
|
||||
)
|
||||
) );
|
||||
|
||||
if ( $show_return_to_pantheon_button ) {
|
||||
|
||||
/**
|
||||
* Enqueue Pantheon login styles
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function Pantheon_Enqueue_Login_style() {
|
||||
wp_enqueue_style( 'pantheon-login-mods', plugin_dir_url( __FILE__ ) . 'assets/css/return-to-pantheon-button.css', false, PANTHEON_MU_PLUGIN_VERSION );
|
||||
}
|
||||
|
||||
add_action( 'login_enqueue_scripts', 'Pantheon_Enqueue_Login_style', 10 );
|
||||
|
||||
/**
|
||||
* Enqueue Pantheon login scripts
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function Pantheon_Enqueue_Login_script() {
|
||||
wp_enqueue_script( 'pantheon-login-mods', plugin_dir_url( __FILE__ ) . 'assets/js/return-to-pantheon-button.js', [ 'jquery' ], PANTHEON_MU_PLUGIN_VERSION, true );
|
||||
}
|
||||
|
||||
add_action( 'login_enqueue_scripts', 'Pantheon_Enqueue_Login_script', 1 );
|
||||
|
||||
/**
|
||||
* Print return to Pantheon link HTML
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function Return_To_Pantheon_Button_HTML() {
|
||||
$pantheon_dashboard_url = 'https://dashboard.pantheon.io/sites/' . $_ENV['PANTHEON_SITE'] . '#' . $_ENV['PANTHEON_ENVIRONMENT'];
|
||||
|
||||
$pantheon_fist_icon_url = plugin_dir_url( __FILE__ ) . 'assets/images/pantheon-fist-icon-black.svg';
|
||||
$login_message = apply_filters( 'pantheon_wp_login_text', esc_html__( 'Login to your WordPress Site', 'pantheon' ) );
|
||||
?>
|
||||
<div id="return-to-pantheon" style="display: none;">
|
||||
<div class="left">
|
||||
<?php echo $login_message; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</div>
|
||||
<div class="right">
|
||||
<a href="<?php echo esc_url( $pantheon_dashboard_url ); ?>">
|
||||
<img class="fist-icon" src="<?php echo esc_url( $pantheon_fist_icon_url ); ?>">
|
||||
<?php esc_html_e( 'Return to Pantheon', 'pantheon' ); ?>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
add_action( 'login_header', 'Return_To_Pantheon_Button_HTML', 10 );
|
||||
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* If a site has multisite enabled, but has not had the final installation
|
||||
* steps completed, alert the user and provide links.
|
||||
*
|
||||
* @package pantheon
|
||||
*/
|
||||
|
||||
/**
|
||||
* Detects if a user is using the correct upstream and framework and give them appropriate next steps to finalize WPMS setup.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function pantheon_multisite_install_finalize_message() {
|
||||
?>
|
||||
<div class="notice notice-info is-dismissible">
|
||||
<?php
|
||||
if ( isset( $_ENV['PANTHEON_ENVIRONMENT'] ) ) {
|
||||
if ( getenv( 'FRAMEWORK' ) === 'wordpress_network' ) {
|
||||
?>
|
||||
<p><?php esc_html_e( 'Your WordPress Multisite is almost ready!', 'pantheon' ); ?></p>
|
||||
<p>
|
||||
<?php
|
||||
printf(
|
||||
wp_kses_post(
|
||||
// translators: %s is the link to the Pantheon Multisite Configuration documentation.
|
||||
__( 'Visit <a href="%s">Pantheon Multisite Configuration</a> for documentation on how to finalize configuration of your site network.', 'pantheon' )
|
||||
),
|
||||
'https://pantheon.io/docs/guides/multisite/config/#install-the-wordpress-site-network'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<p><?php esc_html_e( 'You are trying to configure a WordPress Multisite with a wrong upstream!', 'pantheon' ); ?></p>
|
||||
<p>
|
||||
<?php
|
||||
printf(
|
||||
wp_kses_post(
|
||||
// translators: %s is the link to the Pantheon Support page.
|
||||
__( 'Make sure that you have the correct upstream configuration for WPMS. If you do not have that capability or to check if you are eligible, please <a href="%s">Contact Support</a>.', 'pantheon' )
|
||||
), 'https://pantheon.io/support'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
add_action( 'admin_notices', 'pantheon_multisite_install_finalize_message' );
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Network Setup
|
||||
*
|
||||
* @package pantheon-mu-plugin
|
||||
*/
|
||||
|
||||
namespace Pantheon\NetworkSetup;
|
||||
|
||||
/**
|
||||
* Alter network setup pages to include Pantheon-specific instructions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Replace the WordPress core Network Setup page from the Settings menu.
|
||||
*/
|
||||
function pantheon_remove_network_setup() {
|
||||
global $submenu;
|
||||
if ( isset( $submenu['tools.php'][50] ) ) {
|
||||
unset( $submenu['tools.php'][50] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the Pantheon network setup submenu page.
|
||||
*/
|
||||
function pantheon_add_network_setup() {
|
||||
add_management_page(
|
||||
__( 'Create a Network of WordPress Sites', 'network-setup' ),
|
||||
__( 'Network Setup', 'network-setup' ),
|
||||
'setup_network',
|
||||
'setup_network',
|
||||
__NAMESPACE__ . '\\pantheon_render_network_setup_page'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the Pantheon network setup page.
|
||||
*/
|
||||
function pantheon_render_network_setup_page() {
|
||||
global $wpdb;
|
||||
require_once __DIR__ . '/network/network.php';
|
||||
}
|
||||
|
||||
add_action( 'admin_menu', __NAMESPACE__ . '\\pantheon_remove_network_setup' );
|
||||
add_action( 'admin_menu', __NAMESPACE__ . '\\pantheon_add_network_setup' );
|
||||
@@ -1,547 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Pantheon Page Cache
|
||||
*
|
||||
* @package pantheon-mu-plugin
|
||||
*/
|
||||
|
||||
/**
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
class Pantheon_Cache {
|
||||
|
||||
/**
|
||||
* Define the capability required to see and modify the settings page.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $options_capability = 'manage_options';
|
||||
|
||||
/**
|
||||
* Define the default options, which are overridden by what's in wp_options.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $default_options = [];
|
||||
|
||||
/**
|
||||
* Stores the options for this plugin (from wp_options).
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $options = [];
|
||||
|
||||
/**
|
||||
* Store the Paths to be flushed at shutdown.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $paths = [];
|
||||
|
||||
/**
|
||||
* The slug for the plugin, used in various places like the options page.
|
||||
*/
|
||||
const SLUG = 'pantheon-cache';
|
||||
|
||||
/**
|
||||
* Holds the singleton instance.
|
||||
*
|
||||
* @static
|
||||
* @var object
|
||||
*/
|
||||
protected static $instance;
|
||||
|
||||
/**
|
||||
* Get a reference to the singleton.
|
||||
*
|
||||
* @return object The singleton instance.
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new Pantheon_Cache();
|
||||
self::$instance->setup();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
protected function __construct() {
|
||||
/** Don't do anything */
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Setup the actions and filters we need to hook into, and initialize any properties we need.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setup() {
|
||||
$this->options = get_option( self::SLUG, [] );
|
||||
$this->default_options = [
|
||||
'default_ttl' => 600,
|
||||
'maintenance_mode' => 'disabled',
|
||||
];
|
||||
$this->options = wp_parse_args( $this->options, $this->default_options );
|
||||
|
||||
add_action( 'init', [ $this, 'action_init_do_maintenance_mode' ] );
|
||||
|
||||
add_action( 'admin_init', [ $this, 'action_admin_init' ] );
|
||||
add_action( 'admin_menu', [ $this, 'action_admin_menu' ] );
|
||||
add_action( 'load-plugin-install.php', [ $this, 'action_load_plugin_install' ] );
|
||||
|
||||
add_action( 'admin_post_pantheon_cache_flush_site', [ $this, 'flush_site' ] );
|
||||
|
||||
add_action( 'send_headers', [ $this, 'cache_add_headers' ] );
|
||||
add_filter( 'rest_post_dispatch', [ $this, 'filter_rest_post_dispatch_send_cache_control' ], 10, 2 );
|
||||
|
||||
add_action( 'admin_notices', function () {
|
||||
global $wp_object_cache;
|
||||
if ( empty( $wp_object_cache->missing_redis_message ) ) {
|
||||
return;
|
||||
}
|
||||
$wp_object_cache->missing_redis_message = 'Alert! The Pantheon Redis service needs to be enabled before the WP Redis object cache will function properly.';
|
||||
}, 9 ); // Before the message is displayed in the plugin notice.
|
||||
|
||||
add_action( 'shutdown', [ $this, 'cache_clean_urls' ], 999 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays maintenance mode when enabled.
|
||||
*/
|
||||
public function action_init_do_maintenance_mode() {
|
||||
|
||||
$do_maintenance_mode = false;
|
||||
|
||||
if ( in_array( $this->options['maintenance_mode'], [ 'anonymous', 'everyone' ], true )
|
||||
&& ! is_user_logged_in() ) {
|
||||
$do_maintenance_mode = true;
|
||||
}
|
||||
|
||||
if ( 'everyone' === $this->options['maintenance_mode']
|
||||
&& is_user_logged_in()
|
||||
&& ! current_user_can( 'manage_options' ) ) {
|
||||
$do_maintenance_mode = true;
|
||||
}
|
||||
|
||||
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
||||
$do_maintenance_mode = false;
|
||||
}
|
||||
|
||||
if ( 'wp-login.php' === $GLOBALS['pagenow'] ) {
|
||||
$do_maintenance_mode = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify maintenance mode behavior with more advanced conditionals.
|
||||
*
|
||||
* @var boolean $do_maintenance_mode Whether or not to do maintenance mode.
|
||||
*/
|
||||
$do_maintenance_mode = apply_filters( 'pantheon_cache_do_maintenance_mode', $do_maintenance_mode );
|
||||
|
||||
if ( ! $do_maintenance_mode ) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_die(
|
||||
esc_html__( 'Briefly unavailable for scheduled maintenance. Check back in a minute.' ),
|
||||
esc_html__( 'Maintenance' ),
|
||||
503
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prep the Settings API.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function action_admin_init() {
|
||||
register_setting( self::SLUG, self::SLUG, [ self::$instance, 'sanitize_options' ] );
|
||||
add_settings_section( 'general', false, '__return_false', self::SLUG );
|
||||
add_settings_field( 'default_ttl', null, [ self::$instance, 'default_ttl_field' ], self::SLUG, 'general' );
|
||||
add_settings_field( 'maintenance_mode', null, [ self::$instance, 'maintenance_mode_field' ], self::SLUG, 'general' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add the settings page to the menu.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function action_admin_menu() {
|
||||
add_options_page( __( 'Pantheon Page Cache', 'pantheon-cache' ), __( 'Pantheon Page Cache', 'pantheon-cache' ), $this->options_capability, self::SLUG, [ self::$instance, 'view_settings_page' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if JavaScript should trigger the opening of the plugin install box
|
||||
*/
|
||||
public function action_load_plugin_install() {
|
||||
if ( empty( $_GET['action'] ) || 'pantheon-load-infobox' !== $_GET['action'] ) {
|
||||
return;
|
||||
}
|
||||
add_action( 'admin_footer', [ $this, 'action_admin_footer_trigger_plugin_open' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger the opening of the Pantheon Advanced Page Cache infobox
|
||||
*/
|
||||
public function action_admin_footer_trigger_plugin_open() {
|
||||
?>
|
||||
<script>
|
||||
jQuery(document).ready(function(){
|
||||
// Wait until the click event handler is bound by core JavaScript
|
||||
setTimeout(function(){
|
||||
jQuery('.plugin-card-pantheon-advanced-page-cache a.open-plugin-details-modal').trigger('click');
|
||||
}, 1 )
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the HTML for the default TTL field.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function default_ttl_field() {
|
||||
echo '<h3>' . esc_html__( 'Default Time to Live (TTL)', 'pantheon-cache' ) . '</h3>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo '<p>' . esc_html__( 'Maximum time a cached page will be served. A higher TTL typically improves site performance.', 'pantheon-cache' ) . '</p>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo '<input type="text" name="' . self::SLUG . '[default_ttl]" value="' . $this->options['default_ttl'] . '" size="5" /> ' . esc_html__( 'seconds', 'pantheon-cache' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the HTML for the maintenance mode field.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function maintenance_mode_field() {
|
||||
echo '<h3>' . esc_html__( 'Maintenance Mode', 'pantheon-cache' ) . '</h3>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo '<p>' . esc_html__( 'Enable maintenance mode to work on your site while serving cached pages to:', 'pantheon-cache' ) . '</p>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo '<label style="display: block; margin-bottom: 5px;"><input type="radio" name="' . self::SLUG . '[maintenance_mode]" value="" ' . checked( 'disabled', $this->options['maintenance_mode'], false ) . ' /> ' . esc_html__( 'Disabled', 'pantheon-cache' ) . '</label>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo '<label style="display: block; margin-bottom: 5px;"><input type="radio" name="' . self::SLUG . '[maintenance_mode]" value="anonymous" ' . checked( 'anonymous', $this->options['maintenance_mode'], false ) . ' /> ' . esc_html__( 'Logged-Out Visitors', 'pantheon-cache' ) . '</label>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo '<label style="display: block; margin-bottom: 5px;"><input type="radio" name="' . self::SLUG . '[maintenance_mode]" value="everyone" ' . checked( 'everyone', $this->options['maintenance_mode'], false ) . ' /> ' . esc_html__( 'Everyone except Administrators', 'pantheon-cache' ) . '</label>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sanitize our options.
|
||||
*
|
||||
* @param array $in The POST values.
|
||||
* @return array The sanitized POST values.
|
||||
*/
|
||||
public function sanitize_options( $in ) {
|
||||
$out = $this->default_options;
|
||||
|
||||
// Validate default_ttl.
|
||||
$out['default_ttl'] = absint( $in['default_ttl'] );
|
||||
if ( $out['default_ttl'] < 60 && isset( $_ENV['PANTHEON_ENVIRONMENT'] ) && 'live' === $_ENV['PANTHEON_ENVIRONMENT'] ) {
|
||||
$out['default_ttl'] = 60;
|
||||
}
|
||||
|
||||
if ( ! empty( $in['maintenance_mode'] )
|
||||
&& in_array( $in['maintenance_mode'], [ 'anonymous', 'everyone' ], true ) ) {
|
||||
$out['maintenance_mode'] = $in['maintenance_mode'];
|
||||
} else {
|
||||
$out['maintenance_mode'] = 'disabled';
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Output the settings page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function view_settings_page() {
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h2><?php esc_html_e( 'Pantheon Page Cache', 'pantheon-cache' ); ?></h2>
|
||||
|
||||
<?php if ( ! empty( $_GET['cache-cleared'] ) && 'true' === $_GET['cache-cleared'] ) : ?>
|
||||
<div class="updated below-h2">
|
||||
<p><?php esc_html_e( 'Site cache flushed.', 'pantheon-cache' ); ?></p>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if ( class_exists( 'Pantheon_Advanced_Page_Cache\Purger' ) ) : // translators: %s is a link. ?>
|
||||
<div class="notice notice-success"><p><?php echo wp_kses_post( sprintf( __( 'Pantheon Advanced Page Cache activated. <a target="_blank" href="%s">Learn more</a>', 'pantheon-cache' ), 'https://docs.pantheon.io/guides/wordpress-configurations/wordpress-cache-plugin' ) ); ?></p></div>
|
||||
<?php else : // translators: %s is a link. ?>
|
||||
<div class="notice notice-warning"><p><?php echo wp_kses_post( sprintf( __( 'Want to automatically clear related pages when you update content? Learn more about the <a href="%s">Pantheon Advanced Page Cache</a>.', 'pantheon-cache' ), 'https://docs.pantheon.io/guides/wordpress-configurations/wordpress-cache-plugin' ) ); ?></p></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
/**
|
||||
* Permits the Pantheon Advanced Page Cache plugin to add
|
||||
* supplemental text.
|
||||
*/
|
||||
do_action( 'pantheon_cache_settings_page_top' );
|
||||
?>
|
||||
|
||||
<?php if ( apply_filters( 'pantheon_cache_allow_clear_all', true ) ) : ?>
|
||||
|
||||
<form action="admin-post.php" method="POST">
|
||||
<input type="hidden" name="action" value="pantheon_cache_flush_site" />
|
||||
<?php wp_nonce_field( 'pantheon-cache-clear-all', 'pantheon-cache-nonce' ); ?>
|
||||
<h3><?php esc_html_e( 'Clear Site Cache', 'pantheon-cache' ); ?></h3>
|
||||
<p><?php esc_html_e( 'Use with care. Clearing the entire site cache will negatively impact performance for a short period of time.', 'pantheon-cache' ); ?></p>
|
||||
<?php submit_button( __( 'Clear Cache', 'pantheon-cache' ), 'secondary' ); ?>
|
||||
</form>
|
||||
|
||||
<hr />
|
||||
|
||||
<?php endif ?>
|
||||
|
||||
<style>
|
||||
.ttl-form th[scope="row"] {
|
||||
display: none;
|
||||
}
|
||||
.ttl-form td {
|
||||
padding-left: 0;
|
||||
}
|
||||
.ttl-form td p {
|
||||
margin-bottom: 1em;
|
||||
font-size: 13px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<form action="options.php" method="POST" class="ttl-form">
|
||||
<?php settings_fields( self::SLUG ); ?>
|
||||
<?php do_settings_sections( self::SLUG ); ?>
|
||||
<?php submit_button( __( 'Save Changes', 'pantheon-cache' ) ); ?>
|
||||
</form>
|
||||
|
||||
<hr />
|
||||
|
||||
<?php
|
||||
/**
|
||||
* Permits the Pantheon Advanced Page Cache plugin to add
|
||||
* supplemental text.
|
||||
*/
|
||||
do_action( 'pantheon_cache_settings_page_bottom' );
|
||||
?>
|
||||
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache-control header value.
|
||||
*
|
||||
* This removes "max-age=0" which could hypothetically be used by
|
||||
* Varnish on an immediate subsequent request.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_cache_control_header_value() {
|
||||
if ( ! is_admin() && ! is_user_logged_in() ) {
|
||||
$ttl = absint( $this->options['default_ttl'] );
|
||||
if ( $ttl < 60 && isset( $_ENV['PANTHEON_ENVIRONMENT'] ) && 'live' === $_ENV['PANTHEON_ENVIRONMENT'] ) {
|
||||
$ttl = 60;
|
||||
}
|
||||
|
||||
return sprintf( 'public, max-age=%d', $ttl );
|
||||
} else {
|
||||
return 'no-cache, no-store, must-revalidate';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the cache-control header.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function cache_add_headers() {
|
||||
header( sprintf( 'cache-control: %s', $this->get_cache_control_header_value() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the cache control header for REST API requests
|
||||
*
|
||||
* @param WP_REST_Response $response Response.
|
||||
* @return WP_REST_Response Response.
|
||||
*/
|
||||
public function filter_rest_post_dispatch_send_cache_control( $response ) {
|
||||
$response->header( 'Cache-Control', $this->get_cache_control_header_value() );
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cache for the entire site.
|
||||
*
|
||||
* @return void|false
|
||||
*/
|
||||
public function flush_site() {
|
||||
if ( ! function_exists( 'current_user_can' ) || false === current_user_can( 'manage_options' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! empty( $_POST['pantheon-cache-nonce'] ) && wp_verify_nonce( $_POST['pantheon-cache-nonce'], 'pantheon-cache-clear-all' ) ) {
|
||||
if ( function_exists( 'pantheon_clear_edge_all' ) ) {
|
||||
pantheon_clear_edge_all();
|
||||
}
|
||||
wp_cache_flush();
|
||||
wp_safe_redirect( admin_url( 'options-general.php?page=pantheon-cache&cache-cleared=true' ) );
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear the cache for a post.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @param int $post_id A post ID to clean.
|
||||
* @return void
|
||||
*/
|
||||
public function clean_post_cache( $post_id, $include_homepage = true ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable,Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
|
||||
if ( method_exists( 'Pantheon_Advanced_Page_Cache\Purger', 'action_clean_post_cache' ) ) {
|
||||
Pantheon_Advanced_Page_Cache\Purger::action_clean_post_cache( $post_id );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear the cache for a given term or terms and taxonomy.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @param int|array $term_ids Single or list of Term IDs.
|
||||
* @param string $taxonomy Can be empty and will assume tt_ids, else will use for context.
|
||||
* @return void
|
||||
*/
|
||||
public function clean_term_cache( $term_ids, $taxonomy ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed,VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
|
||||
if ( method_exists( 'Pantheon_Advanced_Page_Cache\Purger', 'action_clean_term_cache' ) ) {
|
||||
Pantheon_Advanced_Page_Cache\Purger::action_clean_term_cache( $term_ids );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear the cache for a given term or terms and taxonomy.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @param int|array $object_ids Single or list of term object ID(s).
|
||||
* @param array|string $object_type The taxonomy object type.
|
||||
* @return void
|
||||
*/
|
||||
public function clean_object_term_cache( $object_ids, $object_type ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
|
||||
// Handled by Pantheon Integrated CDN.
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue Fully-qualified urls to be cleared on shutdown.
|
||||
*
|
||||
* @param array|string $urls List of full urls to clear.
|
||||
* @return void
|
||||
*/
|
||||
public function enqueue_urls( $urls ) {
|
||||
$paths = [];
|
||||
$urls = array_filter( (array) $urls, 'is_string' );
|
||||
foreach ( $urls as $full_url ) {
|
||||
// Parse down to the path+query, escape regex.
|
||||
$parsed = parse_url( $full_url );
|
||||
// Sometimes parse_url can return false, on malformed urls.
|
||||
if ( false === $parsed ) {
|
||||
continue;
|
||||
}
|
||||
// Build up the path, checking if the array key exists first.
|
||||
if ( array_key_exists( 'path', $parsed ) ) {
|
||||
$path = $parsed['path'];
|
||||
if ( array_key_exists( 'query', $parsed ) ) {
|
||||
$path = $path . $parsed['query'];
|
||||
}
|
||||
} else {
|
||||
// If the path doesn't exist, set it to the null string.
|
||||
$path = '';
|
||||
}
|
||||
if ( '' === $path ) {
|
||||
continue;
|
||||
}
|
||||
$path = '^' . preg_quote( $path ) . '$'; // phpcs:ignore WordPress.PHP.PregQuoteDelimiter.Missing
|
||||
$paths[] = $path;
|
||||
}
|
||||
|
||||
$this->paths = array_merge( $this->paths, $paths );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue a regex to be cleared.
|
||||
*
|
||||
* You must understand regular expressions to use this, and be careful.
|
||||
*
|
||||
* @param string $regex path regex to clear.
|
||||
* @return void
|
||||
*/
|
||||
public function enqueue_regex( $regex ) {
|
||||
$this->paths[] = $regex;
|
||||
}
|
||||
|
||||
|
||||
public function cache_clean_urls() {
|
||||
if ( empty( $this->paths ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->paths = apply_filters( 'pantheon_clean_urls', array_unique( $this->paths ) );
|
||||
|
||||
// Call the big daddy here.
|
||||
$this->paths = apply_filters( 'pantheon_final_clean_urls', $this->paths );
|
||||
if ( function_exists( 'pantheon_clear_edge_paths' ) ) {
|
||||
pantheon_clear_edge_paths( $this->paths );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get a reference to the singleton.
|
||||
*
|
||||
* This can be used to reference public methods, e.g. `Pantheon_Cache()->clean_post_cache( 123 )`
|
||||
*/
|
||||
function Pantheon_Cache() {
|
||||
return Pantheon_Cache::instance();
|
||||
}
|
||||
add_action( 'plugins_loaded', 'Pantheon_Cache' );
|
||||
|
||||
/**
|
||||
* @see Pantheon_Cache::clean_post_cache
|
||||
*
|
||||
* @deprecated Please call Pantheon Integrated CDN instead.
|
||||
*/
|
||||
function pantheon_clean_post_cache( $post_id, $include_homepage = true ) {
|
||||
Pantheon_Cache()->clean_post_cache( $post_id, $include_homepage );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see Pantheon_Cache::clean_term_cache
|
||||
*
|
||||
* @deprecated Please call Pantheon Integrated CDN instead.
|
||||
*/
|
||||
function pantheon_clean_term_cache( $term_ids, $taxonomy ) {
|
||||
Pantheon_Cache()->clean_term_cache( $term_ids, $taxonomy );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see Pantheon_Cache::enqueue_urls
|
||||
*
|
||||
* @deprecated Please call Pantheon Integrated CDN instead.
|
||||
*/
|
||||
function pantheon_enqueue_urls( $urls ) {
|
||||
Pantheon_Cache()->enqueue_urls( $urls );
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
<?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
|
||||
}
|
||||
}
|
||||
@@ -1,181 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Pantheon MU Plugin Updates
|
||||
*
|
||||
* Handles modifying the default WordPress update behavior on Pantheon.
|
||||
*/
|
||||
|
||||
// If on Pantheon...
|
||||
if ( isset( $_ENV['PANTHEON_ENVIRONMENT'] ) ) {
|
||||
// Disable WordPress auto updates.
|
||||
if ( ! defined( 'WP_AUTO_UPDATE_CORE' ) ) {
|
||||
define( 'WP_AUTO_UPDATE_CORE', false );
|
||||
}
|
||||
|
||||
remove_action( 'wp_maybe_auto_update', 'wp_maybe_auto_update' );
|
||||
// Remove the default WordPress core update nag.
|
||||
add_action( 'admin_menu', '_pantheon_hide_update_nag' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the default WordPress core update nag message.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function _pantheon_hide_update_nag() {
|
||||
remove_action( 'admin_notices', 'update_nag', 3 );
|
||||
remove_action( 'network_admin_notices', 'update_nag', 3 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that returns the current WordPress version.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function _pantheon_get_current_wordpress_version(): string {
|
||||
include ABSPATH . WPINC . '/version.php';
|
||||
return $wp_version; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the latest WordPress version.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
function _pantheon_get_latest_wordpress_version(): ?string {
|
||||
$core_updates = get_core_updates();
|
||||
|
||||
if ( ! is_array( $core_updates ) || empty( $core_updates ) || ! property_exists( $core_updates[0], 'current' ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $core_updates[0]->current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if WordPress core is at the latest version.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function _pantheon_is_wordpress_core_latest(): bool {
|
||||
$latest_wp_version = _pantheon_get_latest_wordpress_version();
|
||||
$wp_version = _pantheon_get_current_wordpress_version();
|
||||
|
||||
if ( null === $latest_wp_version ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Return true if our version is the latest.
|
||||
return version_compare( str_replace( '-src', '', $latest_wp_version ), str_replace( '-src', '', $wp_version ), '<=' ); // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if WordPress core is a pre-release version.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function _pantheon_is_wordpress_core_prerelease(): bool {
|
||||
$wp_version = _pantheon_get_current_wordpress_version();
|
||||
|
||||
// Return true if our version is a prerelease. Pre-releases are identified by a dash in the version number.
|
||||
return false !== strpos( $wp_version, '-' ); // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace WordPress core update nag EVERYWHERE with our own notice.
|
||||
* Use git upstream instead
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function _pantheon_upstream_update_notice() {
|
||||
$wp_version = _pantheon_get_current_wordpress_version();
|
||||
$screen = get_current_screen();
|
||||
// Translators: %s is a URL to the user's Pantheon Dashboard.
|
||||
$notice_message = sprintf( __( 'Check for updates on <a href="%s">your Pantheon dashboard</a>.', 'pantheon-systems' ), 'https://dashboard.pantheon.io/sites/' . $_ENV['PANTHEON_SITE'] );
|
||||
// Translators: %s is a URL to Pantheon's upstream updates documentation.
|
||||
$upstream_help_message = sprintf( __( 'For details on applying updates, see the <a href="%s">Applying Upstream Updates</a> documentation.', 'pantheon-systems' ), 'https://docs.pantheon.io/core-updates' );
|
||||
$update_help = __( 'If you need help, contact an administrator for your Pantheon organization.', 'pantheon-systems' );
|
||||
$div_class = esc_attr( 'update-nag notice notice-warning' );
|
||||
$div_style = esc_attr( 'display: table;' );
|
||||
$paragraph_style = esc_attr( 'font-size: 14px; font-weight: bold; margin: 0 0 0.5em 0;' );
|
||||
|
||||
if ( ! _pantheon_is_wordpress_core_latest() ) {
|
||||
// If WP core is out of date, alter the message and show the nag everywhere.
|
||||
// Translators: %s is a URL to the user's Pantheon Dashboard.
|
||||
$notice_message = sprintf( __( 'A new WordPress update is available! Please update from <a href="%s">your Pantheon dashboard</a>.', 'pantheon-systems' ), 'https://dashboard.pantheon.io/sites/' . $_ENV['PANTHEON_SITE'] );
|
||||
}
|
||||
|
||||
// If WP core is a pre-release, alter the message.
|
||||
if ( _pantheon_is_wordpress_core_prerelease() ) {
|
||||
$version = '<span style="font-weight: normal;">(' . $wp_version . ')</span>';
|
||||
$paragraph_style = esc_attr( 'font-size: 14px;' );
|
||||
// Translators: %s is the current WordPress version.
|
||||
$notice_message = sprintf( __( '<strong>You are using a development version of WordPress.</strong> %s', 'pantheon-systems' ), $version );
|
||||
// If we're on the Updates page, add a note about the Beta Tester plugin.
|
||||
if ( 'update-core' === $screen->id || 'update-core-network' === $screen->id ) {
|
||||
$notice_message .= '<br /><span style="font-weight: normal;">';
|
||||
$notice_message .= __( 'You are responsible for keeping WordPress up-to-date. Pantheon updates to WordPress will not appear in the dashboard as long as you\'re using a pre-release version. If you are using the Beta Tester plugin, you must have your site in SFTP mode to get the latest updates to your Pantheon Dev environment.', 'pantheon-systems' );
|
||||
}
|
||||
}
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<div class="<?php echo esc_attr( $div_class ); ?>" style="<?php echo esc_attr( $div_style ); ?>">
|
||||
<p style="<?php echo esc_attr( $paragraph_style ); ?>">
|
||||
<?php echo wp_kses_post( $notice_message ); ?>
|
||||
</p>
|
||||
<?php if ( ! _pantheon_is_wordpress_core_prerelease() ) : ?>
|
||||
<?php echo wp_kses_post( $upstream_help_message ); ?>
|
||||
<br />
|
||||
<?php echo wp_kses_post( $update_help ); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
$notice_html = ob_get_clean();
|
||||
// If a WP core update is not detected, only show the nag on the updates page.
|
||||
if ( ! _pantheon_is_wordpress_core_latest() || 'update-core' === $screen->id || 'update-core-network' === $screen->id ) {
|
||||
// Escaping is handled above when we're buffering the output, so we can ignore it here.
|
||||
echo $notice_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Pantheon specific WordPress update admin notice.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function _pantheon_register_upstream_update_notice() {
|
||||
// Only register notice if we are on Pantheon and this is not a WordPress Ajax request.
|
||||
if ( isset( $_ENV['PANTHEON_ENVIRONMENT'] ) && ! wp_doing_ajax() ) {
|
||||
add_action( 'admin_notices', '_pantheon_upstream_update_notice' );
|
||||
add_action( 'network_admin_notices', '_pantheon_upstream_update_notice' );
|
||||
}
|
||||
}
|
||||
add_action( 'admin_init', '_pantheon_register_upstream_update_notice' );
|
||||
|
||||
/**
|
||||
* Return zero updates and current time as last checked time.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
function _pantheon_disable_wp_updates(): object {
|
||||
$wp_version = _pantheon_get_current_wordpress_version();
|
||||
return (object) [
|
||||
'updates' => [],
|
||||
'version_checked' => $wp_version, // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
|
||||
'last_checked' => time(),
|
||||
];
|
||||
}
|
||||
|
||||
// In the Test and Live environments, clear plugin/theme update notifications.
|
||||
// Users must check a dev or multidev environment for updates.
|
||||
if ( isset( $_ENV['PANTHEON_ENVIRONMENT'] ) && in_array( $_ENV['PANTHEON_ENVIRONMENT'], [ 'test', 'live' ], true ) && ( php_sapi_name() !== 'cli' ) ) {
|
||||
|
||||
// Disable Plugin Updates.
|
||||
remove_action( 'load-update-core.php', 'wp_update_plugins' );
|
||||
add_filter( 'pre_site_transient_update_plugins', '_pantheon_disable_wp_updates' );
|
||||
|
||||
// Disable Theme Updates.
|
||||
remove_action( 'load-update-core.php', 'wp_update_themes' );
|
||||
add_filter( 'pre_site_transient_update_themes', '_pantheon_disable_wp_updates' );
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Name: Pantheon
|
||||
* Plugin URI: https://pantheon.io/
|
||||
* Description: Building on Pantheon's and WordPress's strengths, together.
|
||||
* Version: 1.2.1
|
||||
* Author: Pantheon
|
||||
* Author URI: https://pantheon.io/
|
||||
*
|
||||
* @package pantheon
|
||||
*/
|
||||
|
||||
define( 'PANTHEON_MU_PLUGIN_VERSION', '1.2.1' );
|
||||
|
||||
if ( isset( $_ENV['PANTHEON_ENVIRONMENT'] ) ) {
|
||||
|
||||
require_once 'inc/pantheon-page-cache.php';
|
||||
if ( ! defined( 'DISABLE_PANTHEON_UPDATE_NOTICES' ) || ! DISABLE_PANTHEON_UPDATE_NOTICES ) {
|
||||
require_once 'inc/pantheon-updates.php';
|
||||
}
|
||||
if ( ! defined( 'RETURN_TO_PANTHEON_BUTTON' ) || RETURN_TO_PANTHEON_BUTTON ) {
|
||||
require_once 'inc/pantheon-login-form-mods.php';
|
||||
}
|
||||
if ( 'dev' === $_ENV['PANTHEON_ENVIRONMENT'] && function_exists( 'wp_is_writable' ) ) {
|
||||
require_once 'inc/pantheon-plugin-install-notice.php';
|
||||
}
|
||||
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
||||
require_once 'inc/cli.php';
|
||||
}
|
||||
if ( ! defined( 'FS_METHOD' ) ) {
|
||||
/**
|
||||
* When this constant is not set, WordPress writes and then deletes a
|
||||
* temporary file to determine if it has direct access to the filesystem,
|
||||
* which we already know to be the case. This multiplies filesystem
|
||||
* operations and can degrade performance of the filesystem as a whole in
|
||||
* the case of large sites that do a lot of filesystem operations.
|
||||
* Setting this constant to 'direct' tells WordPress to assume it has
|
||||
* direct access and skip creating the extra temporary file.
|
||||
*/
|
||||
define( 'FS_METHOD', 'direct' );
|
||||
}
|
||||
// When developing a WordPress Multisite locally, ensure that this constant is set.
|
||||
// This will set the Multisite variable in all Pantheon environments.
|
||||
if ( getenv( 'FRAMEWORK' ) === 'wordpress_network' && ! defined( 'WP_ALLOW_MULTISITE' ) ) {
|
||||
define( 'WP_ALLOW_MULTISITE', true );
|
||||
}
|
||||
if ( defined( 'WP_ALLOW_MULTISITE' ) && WP_ALLOW_MULTISITE ) {
|
||||
if ( defined( 'MULTISITE' ) && MULTISITE ) {
|
||||
require_once 'inc/pantheon-network-setup.php';
|
||||
} else {
|
||||
require_once 'inc/pantheon-multisite-finalize.php';
|
||||
}
|
||||
}
|
||||
} // Ensuring that this is on Pantheon.
|
||||
Reference in New Issue
Block a user