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 '
'; settings_fields($this->settings_details['option_id']); do_settings_sections($this->options['plugin_id']); diff --git a/inc/WPUBaseSettings/WPUBaseSettings.php b/inc/WPUBaseSettings/WPUBaseSettings.php index ded16b1..126112c 100644 --- a/inc/WPUBaseSettings/WPUBaseSettings.php +++ b/inc/WPUBaseSettings/WPUBaseSettings.php @@ -4,13 +4,16 @@ /* Class Name: WPU Base Settings Description: A class to handle native settings in WordPress admin -Version: 0.13.1 +Version: 0.24.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 */ +defined('ABSPATH') || die; + class WPUBaseSettings { private $hook_page = false; @@ -18,12 +21,17 @@ class WPUBaseSettings { private $admin_url = false; private $is_admin_page = false; private $has_create_page = false; + public $settings = array(); + public $settings_details = array(); public function __construct($settings_details = array(), $settings = array()) { + $this->init($settings_details, $settings); + } + + public function init($settings_details = array(), $settings = array()) { if (empty($settings_details) || empty($settings)) { return; } - $this->set_datas($settings_details, $settings); $this->has_media_setting = false; foreach ($this->settings as $setting) { @@ -49,7 +57,7 @@ public function __construct($settings_details = array(), $settings = array()) { add_action('admin_menu', array(&$this, 'admin_menu' )); - $this->admin_url = admin_url($this->settings_details['parent_page'] . '?page=' . $this->settings_details['plugin_id']); + $this->admin_url = admin_url($this->settings_details['parent_page_url'] . '?page=' . $this->settings_details['plugin_id']); if (isset($settings_details['plugin_basename'])) { add_filter("plugin_action_links_" . $settings_details['plugin_basename'], array(&$this, 'plugin_add_settings_link')); } @@ -69,13 +77,7 @@ public function admin_notices() { } public function get_settings() { - $opt = get_option($this->settings_details['option_id']); - if (!is_array($opt)) { - /* Set default values */ - $opt = $this->get_setting_values(); - update_option($this->settings_details['option_id'], $opt); - } - return $opt; + return $this->get_setting_values(); } public function get_setting($id, $lang = false) { @@ -115,6 +117,9 @@ public function set_datas($settings_details, $settings) { if (!isset($settings_details['parent_page'])) { $settings_details['parent_page'] = 'options-general.php'; } + if (!isset($settings_details['parent_page_url'])) { + $settings_details['parent_page_url'] = $settings_details['parent_page']; + } if (!isset($settings_details['plugin_name'])) { $settings_details['plugin_name'] = $settings_details['plugin_id']; } @@ -146,12 +151,16 @@ public function set_datas($settings_details, $settings) { $default_section = key($this->settings_details['sections']); foreach ($settings as $id => $input) { + $settings[$id]['required'] = isset($input['required']) ? $input['required'] : false; + $settings[$id]['default_value'] = isset($input['default_value']) ? $input['default_value'] : ''; $settings[$id]['label'] = isset($input['label']) ? $input['label'] : ''; $settings[$id]['label_check'] = isset($input['label_check']) ? $input['label_check'] : $settings[$id]['label']; $settings[$id]['help'] = isset($input['help']) ? $input['help'] : ''; $settings[$id]['type'] = isset($input['type']) ? $input['type'] : 'text'; + $settings[$id]['post_type'] = isset($input['post_type']) ? $input['post_type'] : 'post'; $settings[$id]['section'] = isset($input['section']) ? $input['section'] : $default_section; $settings[$id]['datas'] = isset($input['datas']) && is_array($input['datas']) ? $input['datas'] : array(__('No'), __('Yes')); + $settings[$id]['editor_args'] = isset($input['editor_args']) && is_array($input['editor_args']) ? $input['editor_args'] : array(); $settings[$id]['user_cap'] = $this->settings_details['sections'][$settings[$id]['section']]['user_cap']; } @@ -164,7 +173,7 @@ public function set_datas($settings_details, $settings) { $new_settings[$id] = $input; continue; } - foreach ($languages as $lang) { + foreach ($languages as $lang => $lang_name) { $input_lang = $input; unset($input_lang['lang']); $input_lang['translated_from'] = $id; @@ -184,14 +193,34 @@ public function add_settings() { 'show_in_rest' => $this->settings_details, 'default' => array() )); + $has_check_all = false; foreach ($this->settings_details['sections'] as $id => $section) { - if (current_user_can($section['user_cap'])) { - add_settings_section($id, - $section['name'], - isset($section['description']) ? $section['description'] : '', - $this->settings_details['plugin_id'] - ); + if (!current_user_can($section['user_cap'])) { + continue; + } + if (!isset($section['before_section'])) { + $section['before_section'] = ''; + } + if (!isset($section['after_section'])) { + $section['after_section'] = ''; + } + if (isset($section['wpubasesettings_checkall']) && $section['wpubasesettings_checkall']) { + $check_label = __('Check all', __NAMESPACE__); + $section['after_section'] .= ''; + if (!$has_check_all) { + $has_check_all = true; + add_action('admin_footer', array(&$this, 'admin_footer_checkall')); + } } + $section['before_section'] = '
' . $section['before_section']; + $section['after_section'] = $section['after_section'] . '
'; + add_settings_section( + $id, + $section['name'], + isset($section['description']) ? $section['description'] : '', + $this->settings_details['plugin_id'], + $section + ); } foreach ($this->settings as $id => $input) { @@ -199,15 +228,28 @@ public function add_settings() { if (!current_user_can($input['user_cap'])) { continue; } + $lang_id = ''; + if (isset($input['lang_id'])) { + $lang_id = $input['lang_id']; + } add_settings_field($id, $this->settings[$id]['label'], array(&$this, 'render__field' ), $this->settings_details['plugin_id'], $this->settings[$id]['section'], array( 'name' => $this->settings_details['option_id'] . '[' . $id . ']', 'id' => $id, + 'lang_id' => $lang_id, 'label_for' => $id, + 'readonly' => isset($this->settings[$id]['readonly']) ? $this->settings[$id]['readonly'] : false, + 'placeholder' => isset($this->settings[$id]['placeholder']) ? $this->settings[$id]['placeholder'] : false, + 'attributes_html' => isset($this->settings[$id]['attributes_html']) ? $this->settings[$id]['attributes_html'] : false, + 'translated_from' => isset($this->settings[$id]['translated_from']) ? $this->settings[$id]['translated_from'] : false, + 'required' => $this->settings[$id]['required'], + 'post_type' => $this->settings[$id]['post_type'], 'datas' => $this->settings[$id]['datas'], 'type' => $this->settings[$id]['type'], 'help' => $this->settings[$id]['help'], + 'default_value' => $this->settings[$id]['default_value'], + 'editor_args' => $this->settings[$id]['editor_args'], 'label_check' => $this->settings[$id]['label_check'] )); } @@ -257,6 +299,8 @@ public function options_validate($input) { $option_id = ''; } break; + case 'post': + case 'page': case 'media': case 'number': if (!is_numeric($input[$id])) { @@ -289,7 +333,29 @@ public function render__field($args = array()) { $name_val = $option_id . '[' . $args['id'] . ']'; $name = ' name="' . $name_val . '" '; $id = ' id="' . $args['id'] . '" '; - $value = isset($options[$args['id']]) ? $options[$args['id']] : ''; + $attr = ''; + if (isset($args['readonly']) && $args['readonly']) { + $attr .= ' readonly '; + $name = ''; + } + if (isset($args['lang_id']) && $args['lang_id']) { + $attr .= ' data-wpulang="' . esc_attr($args['lang_id']) . '" '; + } + if (isset($args['required']) && $args['required']) { + $attr .= ' required="required" '; + } + + if (isset($args['placeholder']) && $args['placeholder']) { + $attr .= ' placeholder="' . esc_attr($args['placeholder']) . '" '; + } + if (isset($args['attributes_html']) && $args['attributes_html']) { + $attr .= ' ' . $args['attributes_html']; + } + $id .= $attr; + $value = isset($options[$args['id']]) ? $options[$args['id']] : $args['default_value']; + if (!isset($options[$args['id']]) && isset($args['translated_from']) && $args['translated_from'] && isset($options[$args['translated_from']]) && $options[$args['translated_from']]) { + $value = $options[$args['translated_from']]; + } switch ($args['type']) { case 'checkbox': @@ -325,6 +391,22 @@ public function render__field($args = array()) { 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(''+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 f620f75..786a37d 100644 Binary files a/lang/wpumaintenance-fr_FR.mo and b/lang/wpumaintenance-fr_FR.mo differ diff --git a/lang/wpumaintenance-fr_FR.po b/lang/wpumaintenance-fr_FR.po index 5ed2b2b..44ceab9 100644 --- a/lang/wpumaintenance-fr_FR.po +++ b/lang/wpumaintenance-fr_FR.po @@ -1,7 +1,7 @@ msgid "" msgstr "" "Project-Id-Version: WPU Maintenance page\n" -"POT-Creation-Date: 2020-04-25 18:19+0200\n" +"POT-Creation-Date: 2024-12-18 21:14+0100\n" "PO-Revision-Date: \n" "Last-Translator: Darklg \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();