Changeset 2274268
- Timestamp:
- 04/02/2020 05:28:16 PM (6 years ago)
- Location:
- sumedia-urlify/trunk
- Files:
-
- 1 added
- 6 edited
-
changelog.txt (added)
-
readme.txt (modified) (2 diffs)
-
src/Sumedia/Urlify/Config.php (modified) (3 diffs)
-
src/Sumedia/Urlify/Htaccess.php (modified) (1 diff)
-
src/Sumedia/Urlify/Plugin.php (modified) (4 diffs)
-
sumedia-urlify.php (modified) (2 diffs)
-
templates/admin/config.phtml (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sumedia-urlify/trunk/readme.txt
r2212565 r2274268 4 4 Tags: security, admin url, login url, rewrite 5 5 Requires at least: 5.3 6 Tested up to: 5. 3.17 Stable tag: 5. 36 Tested up to: 5.4 7 Stable tag: 5.4 8 8 Requires PHP: 5.6.0 9 9 License: GPL-3.0-or-later … … 14 14 Makes /wp-admin/ and /wp-login.php pathes configurable using mod_rewrite. 15 15 16 With this plugin i try to support a way to change the admins URL and the login path. 17 More things could follow. 16 This plugin support a way to change the admins URL and the login path. 18 17 19 18 It will change 3 things: 20 19 21 -Write to .htaccess some Rules22 -Define a constant in the wp-config.php23 -Hook into the url fetching methods to substitute the new urls20 * Write to .htaccess some Rules 21 * Define a constant in the wp-config.php 22 * Hook into the url fetching methods to substitute the new urls 24 23 25 24 So far in version 0.2.0 it seems to work properly. 26 25 27 = = Dependencies ==26 = Dependencies = 28 27 29 28 This plugin depends on: 30 29 31 30 wp-cli/wp-config-transformer 32 sumedia-wordpress/base33 31 34 ## Troubleshooting 32 = Troubleshooting = 35 33 36 34 If something breaks, you have to revert the changes of this plugin as 37 35 described in https://www.sumedia-howto.de/wordpress/wordpress-urls-rewrite-zum-schutz-sensibler-dateien-und-pfade/ (German) 36 37 = Changelog = 38 See changelog.txt -
sumedia-urlify/trunk/src/Sumedia/Urlify/Config.php
r2213986 r2274268 5 5 if (!class_exists('WPConfigTransformer')) { 6 6 require_once(SUMEDIA_URLIFY_PLUGIN_PATH . str_replace('/', DIRECTORY_SEPARATOR, '/vendor/wp-cli/wp-config-transformer/src/WPConfigTransformer.php')); 7 } 8 9 if (!function_exists('get_home_path')) { 10 include_once ABSPATH . '/wp-admin/includes/file.php'; 7 11 } 8 12 … … 14 18 public function write($admin_url) 15 19 { 16 $path = $this-> get_wp_path() . DIRECTORY_SEPARATOR . $admin_url;20 $path = $this->buildAdminCookiePath($admin_url); 17 21 $wp_config = new \WPConfigTransformer(get_home_path() . DIRECTORY_SEPARATOR . 'wp-config.php'); 18 22 $wp_config->update('constant', 'ADMIN_COOKIE_PATH', $path); … … 25 29 } 26 30 31 public function buildAdminCookiePath($admin_url) 32 { 33 return $this->get_wp_path() . DIRECTORY_SEPARATOR . $admin_url; 34 } 35 36 public function getCurrentAdminCookiePath() 37 { 38 if (defined('ADMIN_COOKIE_PATH')) { 39 return ADMIN_COOKIE_PATH; 40 } 41 return $this->buildAdminCookiePath('wp-admin'); 42 } 43 27 44 /** 28 45 * @return string -
sumedia-urlify/trunk/src/Sumedia/Urlify/Htaccess.php
r2213986 r2274268 122 122 123 123 return '# BEGIN sumedia-urlify 124 <IfModule mod_rewrite.c> 124 <IfModule mod_rewrite.c> 125 RewriteEngine on 125 126 RewriteCond %{REQUEST_URI} ^.*?/?' . preg_quote($admin_url) . '/?.*$ 126 127 RewriteRule ^(.*?/?)' . preg_quote($admin_url) . '(/?.*)$ $1wp-admin$2 [L,E=IS_BACKEND:1,END] -
sumedia-urlify/trunk/src/Sumedia/Urlify/Plugin.php
r2213986 r2274268 17 17 add_filter('login_url', [$this, 'urlify']); 18 18 add_filter('admin_url', [$this, 'urlify']); 19 add_action('plugins_loaded', [$this, 'checkRewriteEngineChanges']); 19 20 add_action('plugins_loaded', [$this, 'controller']); 20 21 } … … 42 43 function deactivate() 43 44 { 44 $urls = \Sumedia\Urlify\Base\Registry::get('Sumedia\Urlify\Repository\Urls');45 $admin_url = $urls->get_admin_url();46 $login_url = $urls->get_login_url();47 48 45 $htaccess = \Sumedia\Urlify\Base\Registry::get('Sumedia\Urlify\Htaccess'); 49 46 $htaccess->register_rewrite_filter(); … … 96 93 } 97 94 95 public function checkRewriteEngineChanges() 96 { 97 global $wp_rewrite; 98 $isRewriteEnabled = !empty($wp_rewrite->mod_rewrite_rules()); 99 $urls = \Sumedia\Urlify\Base\Registry::get('Sumedia\Urlify\Repository\Urls'); 100 101 if (!$isRewriteEnabled && $urls->get_admin_url() != 'wp-admin') { 102 $urls->set_admin_url('wp-admin'); 103 $urls->set_login_url('wp-login.php'); 104 $config = \Sumedia\Urlify\Base\Registry::get('Sumedia\Urlify\Config'); 105 $config->write('wp-admin'); 106 107 add_action('admin_init', function(){ 108 wp_redirect(admin_url()); 109 }); 110 } 111 } 112 98 113 public function controller() 99 114 { … … 102 117 $action = isset($_POST['action']) ? $_POST['action'] : null; 103 118 $action = null == $action && isset($_GET['action']) ? $_GET['action'] : $action; 119 $action = null == $action ? 'Config' : $action; 104 120 if (!preg_match('#^[a-z0-9_\-]+$#i', $action)) { 105 121 return; -
sumedia-urlify/trunk/sumedia-urlify.php
r2213986 r2274268 12 12 * Plugin URI: https://github.com/sumedia-wordpress/urlify 13 13 * Description: Changes important URL's to improve security 14 * Version: 0.3. 014 * Version: 0.3.1 15 15 * Requires at least: 5.3 (nothing else tested yet) 16 16 * Requires PHP: 5.6.0 (not tested, could work) … … 57 57 } else { 58 58 59 define('SUMEDIA_URLIFY_VERSION', '0.3. 0');59 define('SUMEDIA_URLIFY_VERSION', '0.3.1'); 60 60 define('SUMEDIA_URLIFY_PLUGIN_NAME', dirname(plugin_basename(__FILE__))); 61 61 define('SUMEDIA_URLIFY_PLUGIN_PATH', __DIR__); -
sumedia-urlify/trunk/templates/admin/config.phtml
r2213986 r2274268 7 7 } 8 8 9 global $wp_rewrite; 10 9 11 $form = \Sumedia\Urlify\Base\Registry::get('Sumedia\Urlify\Admin\Form\Config'); 12 13 $isRewriteEnabled = !empty($wp_rewrite->mod_rewrite_rules()); 10 14 11 15 ?> … … 13 17 <div class="suma-content"> 14 18 <form class="suma-form" name="suma-urlfix-config-form" action="<?php echo admin_url('admin.php?page=' . SUMEDIA_URLIFY_PLUGIN_NAME . '&action=SetConfig'); ?>" method="post"> 15 <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce(); ?>" /> 16 <fieldset> 17 <legend><?php echo esc_html(__('Setup URL Rewrites', SUMEDIA_URLIFY_PLUGIN_NAME)); ?></legend> 18 <div class="suma-form-option"> 19 <div class="suma-form-label"><label><?php echo esc_html(__('Admin URL', SUMEDIA_URLIFY_PLUGIN_NAME)); ?>:</label></div> 20 <div class="suma-form-input"> 21 <?php echo site_url() . '/wp-admin'; ?> to:<br /> 22 <strong><?php echo site_url(); ?>/</strong> <input name="admin_url" size="10" type="text" value="<?php echo esc_attr($form->get_data('admin_url')); ?>" /> 19 <?php if (!$isRewriteEnabled) : ?> 20 <div class="notice-warning"> 21 <?php echo __('This plugin needs an enabled permalink structure or an enabled mod_rewrite apache modul.'); ?> 22 </div> 23 <?php else: ?> 24 <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce(); ?>" /> 25 <fieldset> 26 <legend><?php echo esc_html(__('Setup URL Rewrites', SUMEDIA_URLIFY_PLUGIN_NAME)); ?></legend> 27 <div class="suma-form-option"> 28 <div class="suma-form-label"><label><?php echo esc_html(__('Admin URL', SUMEDIA_URLIFY_PLUGIN_NAME)); ?>:</label></div> 29 <div class="suma-form-input"> 30 <?php echo site_url() . '/wp-admin'; ?> to:<br /> 31 <strong><?php echo site_url(); ?>/</strong> <input name="admin_url" size="10" type="text" value="<?php echo esc_attr($form->get_data('admin_url')); ?>" /> 32 </div> 23 33 </div> 34 <div class="suma-form-option"> 35 <div class="suma-form-label"><label><?php echo __('Login URL', SUMEDIA_URLIFY_PLUGIN_NAME); ?>:</label></div> 36 <div class="suma-form-input"> 37 <?php echo site_url() . '/wp-login.php'; ?> to:<br /> 38 <strong><?php echo site_url(); ?>/</strong> <input name="login_url" size="10" type="text" value="<?php echo esc_attr($form->get_data('login_url')); ?>" /> 39 </div> 40 </div> 41 </fieldset> 42 <br /> 43 <div class="suma-form-actions"> 44 <input class="button" type="submit" name="submit" value="<?php echo esc_attr(__('Save URL\'s', SUMEDIA_URLIFY_PLUGIN_NAME)); ?>" /> 45 <span class="right"> 46 <a href="javascript:void(0);" name="reset"><?php echo esc_html(__('Reset to Wordpress Defaults', SUMEDIA_URLIFY_PLUGIN_NAME)); ?></a> 47 </span> 24 48 </div> 25 <div class="suma-form-option"> 26 <div class="suma-form-label"><label><?php echo __('Login URL', SUMEDIA_URLIFY_PLUGIN_NAME); ?>:</label></div> 27 <div class="suma-form-input"> 28 <?php echo site_url() . '/wp-login.php'; ?> to:<br /> 29 <strong><?php echo site_url(); ?>/</strong> <input name="login_url" size="10" type="text" value="<?php echo esc_attr($form->get_data('login_url')); ?>" /> 30 </div> 31 </div> 32 </fieldset> 33 <br /> 34 <div class="suma-form-actions"> 35 <input class="button" type="submit" name="submit" value="<?php echo esc_attr(__('Save URL\'s', SUMEDIA_URLIFY_PLUGIN_NAME)); ?>" /> 36 <span class="right"> 37 <a href="javascript:void(0);" name="reset"><?php echo esc_html(__('Reset to Wordpress Defaults', SUMEDIA_URLIFY_PLUGIN_NAME)); ?></a> 38 </span> 39 </div> 49 <?php endif; ?> 40 50 </form> 41 51 </div>
Note: See TracChangeset
for help on using the changeset viewer.