From 236a6e55ef3f3ac55172dd3bb222ce3fb842bb5e Mon Sep 17 00:00:00 2001
From: Kevin
Date: Wed, 18 Dec 2024 21:18:03 +0100
Subject: [PATCH] v 1.2.0
- Update dependencies.
- Add github actions.
- Protect some directories.
- Update lang method.
- Option to disable header 503.
- Option to disable page content edition if a template is in use.
---
.github/.htaccess | 1 +
.github/workflows/php.yml | 19 ++
.gitignore | 1 +
LICENSE | 21 ++
README.md | 4 +-
inc/.htaccess | 1 +
inc/WPUBaseSettings/.htaccess | 1 +
inc/WPUBaseSettings/README.md | 6 +-
inc/WPUBaseSettings/WPUBaseSettings.php | 284 +++++++++++++++++++++---
inc/WPUBaseSettings/index.php | 1 +
inc/WPUBaseUpdate/.htaccess | 1 +
inc/WPUBaseUpdate/README.md | 2 +-
inc/WPUBaseUpdate/WPUBaseUpdate.php | 42 +++-
inc/WPUBaseUpdate/index.php | 1 +
inc/index.php | 1 +
includes/maintenance.php | 2 +-
index.php | 1 +
lang/.htaccess | 1 +
lang/index.php | 1 +
lang/wpumaintenance-fr_FR.l10n.php | 2 +
lang/wpumaintenance-fr_FR.mo | Bin 1404 -> 1797 bytes
lang/wpumaintenance-fr_FR.po | 66 ++++--
uninstall.php | 14 ++
wpumaintenance.php | 86 ++++---
24 files changed, 474 insertions(+), 85 deletions(-)
create mode 100644 .github/.htaccess
create mode 100644 .github/workflows/php.yml
create mode 100644 .gitignore
create mode 100644 LICENSE
create mode 100644 inc/.htaccess
create mode 100644 inc/WPUBaseSettings/.htaccess
create mode 100644 inc/WPUBaseSettings/index.php
create mode 100644 inc/WPUBaseUpdate/.htaccess
create mode 100644 inc/WPUBaseUpdate/index.php
create mode 100644 inc/index.php
create mode 100644 index.php
create mode 100644 lang/.htaccess
create mode 100644 lang/index.php
create mode 100644 lang/wpumaintenance-fr_FR.l10n.php
create mode 100644 uninstall.php
diff --git a/.github/.htaccess b/.github/.htaccess
new file mode 100644
index 0000000..8d2f256
--- /dev/null
+++ b/.github/.htaccess
@@ -0,0 +1 @@
+deny from all
diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml
new file mode 100644
index 0000000..aa092ae
--- /dev/null
+++ b/.github/workflows/php.yml
@@ -0,0 +1,19 @@
+name: PHP Lint
+
+on:
+ push:
+ branches: [ main ]
+ pull_request:
+ branches: [ main ]
+
+jobs:
+ phplint:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+
+ - name: PHP Lint
+ uses: michaelw90/PHP-Lint@2.1.0
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..78568eb
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.mo.php
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..f144cd3
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2024 WPUtilities
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
index e3984ec..fde4624 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,8 @@
WPU Maintenance
==============
+Add [![PHP workflow](https://github.com/WordPressUtilities/wpumaintenance/actions/workflows/php.yml/badge.svg 'PHP workflow')](https://github.com/WordPressUtilities/wpumaintenance/actions) to your README.md
+
Adds a maintenance page for non logged-in users
## How to install :
@@ -28,4 +30,4 @@ You can use the hooks and filters of the default page ( called before the "init"
### File
-If you place a file named "maintenance.php", "maintenance.html" or "index.html" at the root of your active theme, it will be included instead of the default maintenance page.
\ No newline at end of file
+If you place a file named "maintenance.php", "maintenance.html" or "index.html" in the folder wpumaintenance/ of your active theme, it will be included instead of the default maintenance page.
diff --git a/inc/.htaccess b/inc/.htaccess
new file mode 100644
index 0000000..8d2f256
--- /dev/null
+++ b/inc/.htaccess
@@ -0,0 +1 @@
+deny from all
diff --git a/inc/WPUBaseSettings/.htaccess b/inc/WPUBaseSettings/.htaccess
new file mode 100644
index 0000000..8d2f256
--- /dev/null
+++ b/inc/WPUBaseSettings/.htaccess
@@ -0,0 +1 @@
+deny from all
diff --git a/inc/WPUBaseSettings/README.md b/inc/WPUBaseSettings/README.md
index ef364d6..95d3539 100644
--- a/inc/WPUBaseSettings/README.md
+++ b/inc/WPUBaseSettings/README.md
@@ -11,6 +11,7 @@ $this->settings_details = array(
'create_page' => true,
'plugin_basename' => plugin_basename(__FILE__),
# Default
+ 'plugin_name' => 'Import Twitter',
'plugin_id' => 'wpuimporttwitter',
'option_id' => 'wpuimporttwitter_options',
'sections' => array(
@@ -27,14 +28,15 @@ $this->settings = array(
)
);
if (is_admin()) {
- include dirname( __FILE__ ) . '/inc/WPUBaseSettings.php';
+ require_once __DIR__ . '/inc/WPUBaseSettings/WPUBaseSettings.php';
new \wpuimporttwitter\WPUBaseSettings($this->settings_details,$this->settings);
}
```
-## Insert in your admin page content
+## Insert in your admin page content ( if needed )
```php
+settings_errors();
echo '
';
}
break;
+ case 'post':
+ case 'page':
+ $page_dropdown_args = array(
+ 'echo' => false,
+ 'name' => $name_val,
+ 'id' => $args['id'],
+ 'selected' => $value,
+ 'post_type' => isset($args['post_type']) ? $args['post_type'] : $args['type']
+ );
+
+ if (isset($args['lang_id']) && $args['lang_id'] && function_exists('pll_get_post')) {
+ $page_dropdown_args['lang'] = $args['lang_id'];
+ }
+ $code_dropdown = wp_dropdown_pages($page_dropdown_args);
+ echo str_replace('';
foreach ($args['datas'] as $_id => $_data) {
@@ -334,13 +416,14 @@ public function render__field($args = array()) {
break;
case 'editor':
$editor_args = array(
- 'textarea_rows' => isset($args['textarea_rows']) && is_numeric($args['textarea_rows']) ? $args['textarea_rows'] : 3,
- 'textarea_name' => $name_val
+ 'textarea_rows' => isset($args['textarea_rows']) && is_numeric($args['textarea_rows']) ? $args['textarea_rows'] : 3
);
if (isset($args['editor_args']) && is_array($args['editor_args'])) {
$editor_args = $args['editor_args'];
}
+ $editor_args['textarea_name'] = $name_val;
wp_editor($value, $option_id . '_' . $args['id'], $editor_args);
+ echo ' ';
break;
case 'url':
case 'number':
@@ -354,21 +437,23 @@ public function render__field($args = array()) {
}
public static function isRegex($str0) {
- /* Thx http://stackoverflow.com/a/16098097 */
+ /* Thx https://stackoverflow.com/a/16098097 */
$regex = "/^\/[\s\S]+\/$/";
return preg_match($regex, $str0);
}
/* Media */
public function load_assets() {
+ add_action('admin_footer', array(&$this, 'admin_footer'));
+ add_action('admin_head', array(&$this, 'admin_head'));
+
if (!$this->has_media_setting) {
return;
}
add_action('admin_print_scripts', array(&$this, 'admin_scripts'));
add_action('admin_print_styles', array(&$this, 'admin_styles'));
- add_action('admin_head', array(&$this, 'admin_head'));
- add_action('admin_footer', array(&$this, 'admin_footer'));
+ add_action('admin_footer', array(&$this, 'admin_footer_medias'));
}
public function admin_scripts() {
@@ -404,13 +489,44 @@ public function admin_head() {
color: #000;
background-color: #fff;
}
+
+.wpubasesettings-form-table-section h2 {
+ cursor: pointer;
+ -webkit-user-select: none;
+ -moz-user-select: none;
+ user-select: none;
+}
+
+.wpubasesettings-form-table-section h2:after {
+ content: '▼';
+ display: inline-block;
+ padding-left: 0.3em;
+ text-align: center;
+ cursor: pointer;
+}
+
+.wpubasesettings-form-table-section:not(.is-open) h2:after {
+ content: '▶';
+}
+
+.wpubasesettings-form-table-section:not(.is-open) >*:not(h2) {
+ visibility: hidden;
+ z-index: 1;
+ position: absolute;
+ top: -99vh;
+ left: -99vw;
+ pointer-events: none;
+}
EOT;
}
- public function admin_footer() {
+ public function admin_footer_medias() {
echo <<
+(function(){
+{$this->admin_footer_js_check_correct_page()}
+
/* Delete image */
jQuery('.wpubasesettings-mediabox .x').click(function(e) {
var \$this = jQuery(this),
@@ -445,7 +561,109 @@ public function admin_footer() {
e.preventDefault();
});
+}());
+
+EOT;
+ }
+
+ public function admin_footer_js_check_correct_page() {
+ return <<settings_details['option_id']}"]').length){return;}
+EOT;
+ }
+
+ public function admin_footer() {
+ $option_id = $this->settings_details['option_id'];
+ $languages = json_encode($this->get_languages());
+ $label_txt = __('Language');
+ echo <<
+(function(){
+{$this->admin_footer_js_check_correct_page()}
+/* Check langs */
+var _langs = {$languages};
+if(!_langs){
+ return;
+}
+
+/* Get items */
+var jQinput = jQuery('input[type="hidden"][name="option_page"][value="{$option_id}"]');
+if(!jQinput.length){
+ return;
+}
+var jQform = jQinput.closest('form');
+
+/* Add toggles on titles */
+jQform.find('h2').each(function(i,el){
+ var jQel = jQuery(el),
+ jQWrap = jQel.closest('.wpubasesettings-form-table-section');
+ jQWrap.addClass('is-open');
+ jQel.on('click',function(){
+ jQWrap.toggleClass('is-open');
+ });
+});
+
+/* Add lang on TR */
+jQform.find('[data-wpulang]').each(function(i,el){
+ var jQel = jQuery(el);
+ jQel.closest('tr').attr('data-wpulangtr', jQel.attr('data-wpulang'));
+});
+var jQTr = jQform.find('[data-wpulangtr]'),
+ _firstLang = Object.keys(_langs)[0];
+if(!jQTr.length){
+ return;
+}
+
+/* Build switch */
+var select_html='';
+for(var _l in _langs){
+ select_html+=''+_langs[_l]+' ';
+}
+var jQSelect = jQuery('{$label_txt} : '+select_html+' ');
+jQSelect.prependTo(jQform);
+
+/* Switch */
+function show_lang(_lang_id){
+ jQTr.hide();
+ jQTr.filter('[data-wpulangtr="'+_lang_id+'"]').show();
+}
+show_lang(_firstLang);
+jQSelect.on('change', 'select',function(){
+ show_lang(jQuery(this).val());
+});
+
+}());
+
+EOT;
+ }
+
+ function admin_footer_checkall() {
+ echo <<
+jQuery(document).ready(function() {
+ {$this->admin_footer_js_check_correct_page()}
+ jQuery(".wpubasesettings-check-all").each(function() {
+ var _btn = jQuery(this),
+ _table = _btn.prev(".form-table"),
+ _checkboxes = _table.find(":checkbox"),
+ _check_all = true;
+
+ _btn.on("click", function(e) {
+ e.preventDefault();
+ _checkboxes.prop("checked", _check_all);
+ _checkboxes.trigger("change");
+ });
+
+ function check_checkboxes_mode() {
+ var _checked = _checkboxes.filter(":checked").length;
+ _check_all = _checked < _checkboxes.length;
+ _btn.text(_check_all ? _btn.data("check-label") : _btn.data("uncheck-label"));
+ }
+ _checkboxes.on("change", check_checkboxes_mode);
+ check_checkboxes_mode();
+ });
+});
EOT;
}
@@ -534,11 +752,20 @@ public function get_languages() {
return $languages;
}
+ // Obtaining from WPML
+ if (function_exists('icl_get_languages')) {
+ $wpml_lang = icl_get_languages();
+ foreach ($wpml_lang as $lang) {
+ $languages[$lang['code']] = $lang['native_name'];
+ }
+ return $languages;
+ }
return array();
}
public function get_current_language() {
+
// Obtaining from Qtranslate
if (function_exists('qtrans_getLanguage')) {
return qtrans_getLanguage();
@@ -554,6 +781,11 @@ public function get_current_language() {
return pll_current_language();
}
+ // Obtaining from WPML
+ if (defined('ICL_LANGUAGE_CODE')) {
+ return ICL_LANGUAGE_CODE;
+ }
+
return '';
}
diff --git a/inc/WPUBaseSettings/index.php b/inc/WPUBaseSettings/index.php
new file mode 100644
index 0000000..194cdb1
--- /dev/null
+++ b/inc/WPUBaseSettings/index.php
@@ -0,0 +1 @@
+settings_update = new \PLUGINID\WPUBaseUpdate(
'WordPressUtilities',
'PLUGINID',
diff --git a/inc/WPUBaseUpdate/WPUBaseUpdate.php b/inc/WPUBaseUpdate/WPUBaseUpdate.php
index 7369b46..928ea7e 100644
--- a/inc/WPUBaseUpdate/WPUBaseUpdate.php
+++ b/inc/WPUBaseUpdate/WPUBaseUpdate.php
@@ -4,24 +4,29 @@
/*
Class Name: WPU Base Update
Description: A class to handle plugin update from github
-Version: 0.4.2
+Version: 0.6.0
+Class URI: https://github.com/WordPressUtilities/wpubaseplugin
Author: Darklg
-Author URI: http://darklg.me/
+Author URI: https://darklg.me/
License: MIT License
-License URI: http://opensource.org/licenses/MIT
+License URI: https://opensource.org/licenses/MIT
Thanks: https://gist.github.com/danielbachhuber/7684646
*/
+defined('ABSPATH') || die;
+
class WPUBaseUpdate {
public $current_version;
private $github_username;
private $github_project;
+ private $github_path;
private $transient_name;
private $transient_expiration;
private $plugin_id;
private $plugin_dir;
private $details;
+ private $is_tracked = false;
public function __construct($github_username = false, $github_project = false, $current_version = false, $details = array()) {
$this->init($github_username, $github_project, $current_version, $details);
@@ -43,9 +48,7 @@ public function init($github_username = false, $github_project = false, $current
$this->plugin_dir = (defined('WP_PLUGIN_DIR') ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/plugins') . '/' . $this->plugin_id;
$gitpath = dirname($this->plugin_dir) . '/.git';
- if (is_dir($gitpath) || file_exists($gitpath)) {
- return;
- }
+ $this->is_tracked = (is_dir($gitpath) || file_exists($gitpath));
if (!is_array($details)) {
$details = array();
@@ -121,9 +124,19 @@ public function get_new_plugin_info() {
'sections' => array()
);
+ /* Disable download link if plugin is tracked */
+ if ($this->is_tracked) {
+ $plugin_info['trunk'] = '';
+ $plugin_info['download_link'] = '';
+ $plugin_info['package'] = '';
+ }
+
/* Fetch plugin data */
$plugin_data = array();
if (file_exists($this->plugin_dir)) {
+ if (!function_exists('get_plugin_data')) {
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
+ }
$plugin_data = get_plugin_data($this->plugin_dir);
}
@@ -163,7 +176,7 @@ public function plugins_api($res, $action, $args) {
return false;
}
- if ('github-' . $this->github_project !== $args->slug) {
+ if ('github-' . $this->github_project !== $args->slug && $this->github_project !== $args->slug) {
return $res;
}
@@ -172,7 +185,20 @@ public function plugins_api($res, $action, $args) {
return (object) $plugin_info;
}
- return false;
+ $plugin_details = array(
+ 'name' => $this->github_project,
+ 'slug' => $this->github_project
+ );
+
+ $parent_plugin = __DIR__ . '/../../' . $this->github_project . '.php';
+ if (file_exists($parent_plugin)) {
+ $plugin_name = get_plugin_data($parent_plugin);
+ if (isset($plugin_name['Name'])) {
+ $plugin_details['name'] = $plugin_name['Name'];
+ }
+ }
+
+ return (object) $plugin_details;
}
diff --git a/inc/WPUBaseUpdate/index.php b/inc/WPUBaseUpdate/index.php
new file mode 100644
index 0000000..194cdb1
--- /dev/null
+++ b/inc/WPUBaseUpdate/index.php
@@ -0,0 +1 @@
+
+
>
diff --git a/index.php b/index.php
new file mode 100644
index 0000000..194cdb1
--- /dev/null
+++ b/index.php
@@ -0,0 +1 @@
+NULL,'plural-forms'=>NULL,'messages'=>['Settings'=>'Réglages','No'=>'Non','Yes'=>'Oui','Check all'=>'Tout cocher','Uncheck all'=>'Tout décocher','Settings saved.'=>'Paramètres sauvegardés.','Upload New Media'=>'Ajouter un nouveau média','Language'=>'Langue','Save'=>'Enregistrer','Add a maintenance page for non logged-in users'=>'Ajoute une page de maintenance pour les utilisateurs non connectés','Maintenance mode'=>'Mode maintenance','This template is in use : %s'=>'Ce modèle est utilisé : %s','Enable'=>'Activer','Enable maintenance mode'=>'Activer le mode maintenance','Disable 503'=>'Désactiver 503','Do not send a 503 header'=>'Ne pas envoyer d’en-tête 503','Disable for users'=>'Désactiver pour les utilisateurs','Disable maintenance mode for logged-in users'=>'Désactiver le mode maintenance pour les utilisateurs connectés','Authorize these IPs'=>'Autoriser ces IP','Page content'=>'Contenu de la page','Off'=>'Désactivé','On'=>'Activé','%s is in maintenance mode.'=>'%s est en mode maintenance.'],'language'=>'fr_FR','x-generator'=>'Poedit 3.5'];
\ No newline at end of file
diff --git a/lang/wpumaintenance-fr_FR.mo b/lang/wpumaintenance-fr_FR.mo
index f620f755157993b0a14dff90e31facd42625e394..786a37d0a2effee5b66c0454064fcf923a14511a 100644
GIT binary patch
delta 872
zcmYk3O=}ZT6oyaIiPcooTB}wK<_gWODV0(|RH!ryg;qrb7a};$+$L$`osyXpKNi(R
zLFhtc6e+l{i!S0y=)#4|`~){HL_q}qgo4kBDR`K3pZhiMdGEcy^BaZrZ=>F8A;!rf
z`IRh_Z!dOWl6?_TLz->4OyRZa3><_{Ts6vxaPjrPwg|0&_cn_+P5bFL_I0_&3=Qp9=
z*c*5PZo?w=}^G`6nn=AbV4%m)7
delta 513
zcmX}ozb^w}9LMpeckPv;)f&W)YMZn~A_i8ZMvIC;VzKB+F_7Lh5la^aF+S-|A|`{9
zNc<00tC&cP1{31_k*43=bFcf}J@T6M*oHpAH9ieuu7+_G-B$N=^g*sO=S}\n"
"Language-Team: \n"
@@ -9,80 +9,104 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
-"X-Generator: Poedit 2.3\n"
+"X-Generator: Poedit 3.5\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-Basepath: .\n"
"X-Poedit-KeywordsList: __;_e\n"
"X-Poedit-SearchPath-0: ../.\n"
-#: .././inc/WPUBaseSettings/WPUBaseSettings.php:127
-#: .././inc/WPUBaseSettings/WPUBaseSettings.php:456
-#: .././inc/WPUBaseSettings/WPUBaseSettings.php:463 .././wpumaintenance.php:64
+#: .././inc/WPUBaseSettings/WPUBaseSettings.php:132
+#: .././inc/WPUBaseSettings/WPUBaseSettings.php:674
+#: .././inc/WPUBaseSettings/WPUBaseSettings.php:681 .././wpumaintenance.php:90
msgid "Settings"
msgstr "Réglages"
-#: .././inc/WPUBaseSettings/WPUBaseSettings.php:154
+#: .././inc/WPUBaseSettings/WPUBaseSettings.php:162
msgid "No"
msgstr "Non"
-#: .././inc/WPUBaseSettings/WPUBaseSettings.php:154
+#: .././inc/WPUBaseSettings/WPUBaseSettings.php:162
msgid "Yes"
msgstr "Oui"
-#: .././inc/WPUBaseSettings/WPUBaseSettings.php:279
+#: .././inc/WPUBaseSettings/WPUBaseSettings.php:208
+msgid "Check all"
+msgstr "Tout cocher"
+
+#: .././inc/WPUBaseSettings/WPUBaseSettings.php:209
+msgid "Uncheck all"
+msgstr "Tout décocher"
+
+#: .././inc/WPUBaseSettings/WPUBaseSettings.php:323
msgid "Settings saved."
msgstr "Paramètres sauvegardés."
-#: .././inc/WPUBaseSettings/WPUBaseSettings.php:317
+#: .././inc/WPUBaseSettings/WPUBaseSettings.php:383
msgid "Upload New Media"
msgstr "Ajouter un nouveau média"
-#: .././inc/WPUBaseSettings/WPUBaseSettings.php:478
+#: .././inc/WPUBaseSettings/WPUBaseSettings.php:578
+msgid "Language"
+msgstr "Langue"
+
+#: .././inc/WPUBaseSettings/WPUBaseSettings.php:696
msgid "Save"
msgstr "Enregistrer"
-#: .././wpumaintenance.php:43
+#: .././wpumaintenance.php:54
+msgid "Add a maintenance page for non logged-in users"
+msgstr "Ajoute une page de maintenance pour les utilisateurs non connectés"
+
+#: .././wpumaintenance.php:69
msgid "Maintenance mode"
msgstr "Mode maintenance"
-#: .././wpumaintenance.php:51
+#: .././wpumaintenance.php:77
#, php-format
msgid "This template is in use : %s"
msgstr "Ce modèle est utilisé : %s"
-#: .././wpumaintenance.php:72
+#: .././wpumaintenance.php:98
msgid "Enable"
msgstr "Activer"
-#: .././wpumaintenance.php:73
+#: .././wpumaintenance.php:99
msgid "Enable maintenance mode"
msgstr "Activer le mode maintenance"
-#: .././wpumaintenance.php:78
+#: .././wpumaintenance.php:104
+msgid "Disable 503"
+msgstr "Désactiver 503"
+
+#: .././wpumaintenance.php:105
+msgid "Do not send a 503 header"
+msgstr "Ne pas envoyer d’en-tête 503"
+
+#: .././wpumaintenance.php:110
msgid "Disable for users"
msgstr "Désactiver pour les utilisateurs"
-#: .././wpumaintenance.php:79
+#: .././wpumaintenance.php:111
msgid "Disable maintenance mode for logged-in users"
msgstr "Désactiver le mode maintenance pour les utilisateurs connectés"
-#: .././wpumaintenance.php:82
+#: .././wpumaintenance.php:114
msgid "Authorize these IPs"
msgstr "Autoriser ces IP"
-#: .././wpumaintenance.php:87
+#: .././wpumaintenance.php:119
msgid "Page content"
msgstr "Contenu de la page"
-#: .././wpumaintenance.php:230
+#: .././wpumaintenance.php:266
msgid "Off"
msgstr "Désactivé"
-#: .././wpumaintenance.php:230
+#: .././wpumaintenance.php:266
msgid "On"
msgstr "Activé"
-#: .././wpumaintenance.php:250
+#: .././wpumaintenance.php:286
#, php-format
msgid "%s is in maintenance mode."
msgstr "%s est en mode maintenance."
diff --git a/uninstall.php b/uninstall.php
new file mode 100644
index 0000000..2c181f8
--- /dev/null
+++ b/uninstall.php
@@ -0,0 +1,14 @@
+plugin_description = __('Add a maintenance page for non logged-in users', 'wpumaintenance');
+ }
+
+ public function init() {
$this->options = array(
'id' => 'wpumaintenance',
@@ -73,6 +99,12 @@ public function plugins_loaded() {
'label' => __('Enable', 'wpumaintenance'),
'label_check' => __('Enable maintenance mode', 'wpumaintenance')
),
+ 'disable_header_503' => array(
+ 'default' => '0',
+ 'type' => 'checkbox',
+ 'label' => __('Disable 503', 'wpumaintenance'),
+ 'label_check' => __('Do not send a 503 header', 'wpumaintenance')
+ ),
'disabled_users' => array(
'default' => '1',
'type' => 'checkbox',
@@ -88,10 +120,11 @@ public function plugins_loaded() {
'label' => __('Page content', 'wpumaintenance'),
'default' => '',
'type' => 'textarea',
+ 'readonly' => $help_page_content ? '1' : '0',
'help' => $help_page_content
)
);
- include dirname(__FILE__) . '/inc/WPUBaseSettings/WPUBaseSettings.php';
+ require_once __DIR__ . '/inc/WPUBaseSettings/WPUBaseSettings.php';
$this->settings_obj = new \wpumaintenance\WPUBaseSettings($this->settings_details, $this->settings);
$this->settings_values = $this->settings_obj->get_settings();
foreach ($this->settings as $setting_id => $setting) {
@@ -102,14 +135,14 @@ public function plugins_loaded() {
$this->settings_values = apply_filters('wpumaintenance__settings_values', $this->settings_values);
/* Auto-update */
- include dirname(__FILE__) . '/inc/WPUBaseUpdate/WPUBaseUpdate.php';
+ require_once __DIR__ . '/inc/WPUBaseUpdate/WPUBaseUpdate.php';
$this->settings_update = new \wpumaintenance\WPUBaseUpdate(
'WordPressUtilities',
'wpumaintenance',
$this->plugin_version);
}
- public function init() {
+ public function init_maintenance() {
/* Admin bar */
if (current_user_can($this->options['plugin_minlevel'])) {
@@ -194,7 +227,7 @@ public function has_maintenance() {
* Get IP Address
*
* @return string $ip_address
- * Src: http://stackoverflow.com/a/6718472
+ * Src: https://stackoverflow.com/a/6718472
*/
public function get_ip() {
@@ -261,7 +294,7 @@ public function launch_maintenance() {
// Try to include a template file
$maintenance_template = $this->get_maintenance_template();
if ($maintenance_template) {
- $this->header_503();
+ $this->maybe_header_503();
include $maintenance_template;
die;
}
@@ -280,12 +313,15 @@ public function launch_maintenance() {
_default_wp_die_handler($default_content, $page_title, array('response' => 503));
}
- $this->header_503();
- include dirname(__FILE__) . '/includes/maintenance.php';
+ $this->maybe_header_503();
+ require_once __DIR__ . '/includes/maintenance.php';
die;
}
- public function header_503() {
+ public function maybe_header_503() {
+ if ($this->settings_values['disable_header_503'] == '1') {
+ return;
+ }
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 300'); //300 seconds
@@ -341,22 +377,22 @@ public function disable_maintenance() {
WP_CLI::success('Enabled');
}
if ($args[0] == 'disable') {
- $WPUMaintenance->disable_maintenance();;
+ $WPUMaintenance->disable_maintenance();
WP_CLI::success('Disabled');
}
}, array(
'shortdesc' => 'Enable or disable maintenance mode.',
- 'longdesc' => '## EXAMPLES' . "\n\n" . 'wp wpumaintenance enable'. "\n" . 'wp wpumaintenance disable',
+ 'longdesc' => '## EXAMPLES' . "\n\n" . 'wp wpumaintenance enable' . "\n" . 'wp wpumaintenance disable',
'synopsis' => array(
array(
- 'type' => 'positional',
- 'name' => 'enable_or_disable',
+ 'type' => 'positional',
+ 'name' => 'enable_or_disable',
'description' => 'Enable or disable maintenance mode.',
- 'optional' => false,
- 'repeating' => false,
- 'options' => array( 'enable', 'disable' ),
+ 'optional' => false,
+ 'repeating' => false,
+ 'options' => array('enable', 'disable')
)
- ),
+ )
));
} else {
$WPUMaintenance = new WPUMaintenance();