mirror of
https://gh.wpcy.net/https://github.com/CaptainCore/do.git
synced 2026-04-17 21:52:19 +08:00
144 lines
No EOL
4.6 KiB
Bash
144 lines
No EOL
4.6 KiB
Bash
# ----------------------------------------------------
|
|
# Deactivates a suspend message by removing the mu-plugin.
|
|
# ----------------------------------------------------
|
|
function suspend_deactivate() {
|
|
local wp_content="$1"
|
|
|
|
# Set default wp-content if not provided
|
|
if [[ -z "$wp_content" ]]; then
|
|
wp_content="wp-content"
|
|
fi
|
|
|
|
local suspend_file="${wp_content}/mu-plugins/do-suspend.php"
|
|
|
|
if [ -f "$suspend_file" ]; then
|
|
echo "Deactivating suspend message by removing ${suspend_file}..."
|
|
rm "$suspend_file"
|
|
echo "✅ Suspend message deactivated. Site is now live."
|
|
else
|
|
echo "Site appears to be already live (suspend file not found)."
|
|
fi
|
|
|
|
# Clear Kinsta cache if environment is detected
|
|
if [ -f "/etc/update-motd.d/00-kinsta-welcome" ]; then
|
|
if setup_wp_cli && "$WP_CLI_CMD" kinsta cache purge --all --skip-themes &> /dev/null; then
|
|
echo "Kinsta cache purged."
|
|
else
|
|
echo "Warning: Could not purge Kinsta cache. Is the 'wp kinsta' command available?" >&2
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# ----------------------------------------------------
|
|
# Activates a suspend message by adding an mu-plugin.
|
|
# ----------------------------------------------------
|
|
function suspend_activate() {
|
|
local name="$1"
|
|
local link="$2"
|
|
local wp_content="$3"
|
|
|
|
# Set default wp-content if not provided
|
|
if [[ -z "$wp_content" ]]; then
|
|
wp_content="wp-content"
|
|
fi
|
|
|
|
# Check for required arguments
|
|
if [[ -z "$name" || -z "$link" ]]; then
|
|
echo "Error: Missing required flags for 'suspend activate'." >&2
|
|
show_command_help "suspend"
|
|
return 1
|
|
fi
|
|
|
|
if [ ! -d "${wp_content}/mu-plugins" ]; then
|
|
echo "Creating directory: ${wp_content}/mu-plugins"
|
|
mkdir -p "${wp_content}/mu-plugins"
|
|
fi
|
|
|
|
# Remove existing deactivation file if present
|
|
if [ -f "${wp_content}/mu-plugins/do-suspend.php" ]; then
|
|
echo "Removing existing suspend file..."
|
|
rm "${wp_content}/mu-plugins/do-suspend.php"
|
|
fi
|
|
|
|
# Create the deactivation mu-plugin
|
|
local output_file="${wp_content}/mu-plugins/do-suspend.php"
|
|
echo "Generating suspend file at ${output_file}..."
|
|
cat <<EOF > "$output_file"
|
|
<?php
|
|
/**
|
|
* Plugin Name: Website Suspended
|
|
* Description: Deactivates the front-end of the website.
|
|
*/
|
|
function captaincore_template_redirect() {
|
|
// Return if in WP Admin or CLI
|
|
if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
|
|
return;
|
|
}
|
|
?>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Website Suspended</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
|
|
<style>
|
|
@import url('https://fonts.googleapis.com/css?family=Roboto');
|
|
body {
|
|
text-align: center;
|
|
margin: 10% auto;
|
|
padding: 0 15px;
|
|
font-family: 'Roboto', sans-serif;
|
|
overflow: hidden;
|
|
display: block;
|
|
max-width: 550px;
|
|
background: #eeeeee;
|
|
}
|
|
p {
|
|
margin-top: 3%;
|
|
line-height: 1.4em;
|
|
display: block;
|
|
}
|
|
img {
|
|
margin-top: 1%;
|
|
}
|
|
a {
|
|
color:#27c3f3;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="row">
|
|
<div class="col s12">
|
|
<div class="card">
|
|
<div class="card-content">
|
|
<span class="card-title">Website Suspended</span>
|
|
<p>This website is currently unavailable.</p>
|
|
</div>
|
|
<div class="card-content grey lighten-4">
|
|
<p>Site owners may contact <a href="${link}" target="_blank" rel="noopener noreferrer">${name}</a>.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
<?php
|
|
// Stop WordPress from loading further
|
|
die();
|
|
}
|
|
add_action( 'template_redirect', 'captaincore_template_redirect', 1 );
|
|
EOF
|
|
|
|
echo "✅ Generated ${output_file}"
|
|
|
|
# Clear Kinsta cache if environment is detected
|
|
if [ -f "/etc/update-motd.d/00-kinsta-welcome" ]; then
|
|
if setup_wp_cli && "$WP_CLI_CMD" kinsta cache purge --all --skip-themes &> /dev/null; then
|
|
echo "Kinsta cache purged."
|
|
else
|
|
echo "Warning: Could not purge Kinsta cache. Is the 'wp kinsta' command available?" >&2
|
|
fi
|
|
fi
|
|
} |