captaincore/lib/remote-scripts/deactivate
2023-11-15 14:55:10 -05:00

136 lines
No EOL
3.2 KiB
Bash

#!/usr/bin/env bash
#
# Deactivaate
#
# `deactivate --wp_content=<wp-content-dir> --name=<business-name> --link=<business-link>`
#
# Loop through arguments and separate regular arguments from flags
for arg in "$@"; do
# Add to arguments array. (Does not starts with "--")
if [[ $arg != --* ]]; then
count=1+${#arguments[*]}
arguments[$count]=$arg
continue
fi
# Remove leading "--"
flag_name=$( echo $arg | cut -c 3- )
# Add to flags array
count=1+${#flags[*]}
flags[$count]=$arg
# Process flags without data (Assign to variable)
if [[ $arg != *"="* ]]; then
flag_name=${flag_name//-/_}
declare "$flag_name"=true
fi
# Process flags with data (Assign to variable)
if [[ $arg == *"="* ]]; then
flag_value=$( echo $flag_name | perl -n -e '/.+?=(.+)/&& print $1' ) # extract value
flag_name=$( echo $flag_name | perl -n -e '/(.+?)=.+/&& print $1' ) # extract name
flag_name=${flag_name/-/_}
# Remove first and last quote if found
flag_value="${flag_value%\"}"
flag_value="${flag_value#\"}"
declare "$flag_name"="$flag_value"
continue
fi
done
arguments=$( echo $arguments | base64 --decode )
while read -r line; do
declare "$line"
done <<< "$arguments"
if [[ "$wp_content" == "" ]]; then
wp_content="wp-content"
fi
if [ -f "${wp_content}/mu-plugins/captaincore_deactivated.php" ]; then
echo "Removing ${wp_content}/mu-plugins/captaincore_deactivated.php"
rm "${wp_content}/mu-plugins/captaincore_deactivated.php"
fi
# Must use WordPress deactivate plugin
cat <<EOF > captaincore-deactivated.php
<?php
function captaincore_template_redirect() { ?><html>
<head>
<meta charset="utf-8">
<title>Website Deactivated</title>
<!-- Compiled and minified CSS -->
<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-beta/css/materialize.min.css">
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/js/materialize.min.js"></script>
<style>
@import url('https://fonts.googleapis.com/css?family=Roboto');
body {
text-align: center;
margin: 10% auto;
padding: 0%;
font-family: 'Roboto', sans-serif;
overflow: hidden;
display: block;
max-width: 450px;
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 Deactivated</span>
<p>This website is no longer active.</p>
</div>
<div class="card-content grey lighten-4">
<p>Site owners contact <a href="${link}">${name}</a></p>
</div>
</div>
</div>
</div>
</body>
</html>
<?php
die();
}
add_action( 'template_redirect', 'captaincore_template_redirect' );
EOF
mv captaincore-deactivated.php $wp_content/mu-plugins/
home=$( wp option get home )
echo "Generated $wp_content/mu-plugins/captaincore-deactivated.php"
if [[ "$provider" == "kinsta" ]]; then
wp kinsta cache purge --all --skip-themes
fi