Plugin Directory

Changeset 2274268


Ignore:
Timestamp:
04/02/2020 05:28:16 PM (6 years ago)
Author:
sumediawebdesign
Message:

fixing issue in which disabled rewrite module will lead to errors

Location:
sumedia-urlify/trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • sumedia-urlify/trunk/readme.txt

    r2212565 r2274268  
    44Tags: security, admin url, login url, rewrite
    55Requires at least: 5.3
    6 Tested up to: 5.3.1
    7 Stable tag: 5.3
     6Tested up to: 5.4
     7Stable tag: 5.4
    88Requires PHP: 5.6.0
    99License: GPL-3.0-or-later
     
    1414Makes /wp-admin/ and /wp-login.php pathes configurable using mod_rewrite.
    1515
    16 With this plugin i try to support a way to change the admins URL and the login path.
    17 More things could follow.
     16This plugin support a way to change the admins URL and the login path.
    1817
    1918It will change 3 things:
    2019
    21 - Write to .htaccess some Rules
    22 - Define a constant in the wp-config.php
    23 - Hook into the url fetching methods to substitute the new urls
     20* 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
    2423
    2524So far in version 0.2.0 it seems to work properly.
    2625
    27 == Dependencies ==
     26= Dependencies =
    2827
    2928This plugin depends on:
    3029
    3130wp-cli/wp-config-transformer
    32 sumedia-wordpress/base
    3331
    34 ## Troubleshooting
     32= Troubleshooting =
    3533
    3634If something breaks, you have to revert the changes of this plugin as
    3735described in https://www.sumedia-howto.de/wordpress/wordpress-urls-rewrite-zum-schutz-sensibler-dateien-und-pfade/ (German)
     36
     37= Changelog =
     38See changelog.txt
  • sumedia-urlify/trunk/src/Sumedia/Urlify/Config.php

    r2213986 r2274268  
    55if (!class_exists('WPConfigTransformer')) {
    66    require_once(SUMEDIA_URLIFY_PLUGIN_PATH . str_replace('/', DIRECTORY_SEPARATOR, '/vendor/wp-cli/wp-config-transformer/src/WPConfigTransformer.php'));
     7}
     8
     9if (!function_exists('get_home_path')) {
     10    include_once ABSPATH . '/wp-admin/includes/file.php';
    711}
    812
     
    1418    public function write($admin_url)
    1519    {
    16         $path = $this->get_wp_path() . DIRECTORY_SEPARATOR . $admin_url;
     20        $path = $this->buildAdminCookiePath($admin_url);
    1721        $wp_config = new \WPConfigTransformer(get_home_path() . DIRECTORY_SEPARATOR . 'wp-config.php');
    1822        $wp_config->update('constant', 'ADMIN_COOKIE_PATH', $path);
     
    2529    }
    2630
     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
    2744    /**
    2845     * @return string
  • sumedia-urlify/trunk/src/Sumedia/Urlify/Htaccess.php

    r2213986 r2274268  
    122122
    123123        return '# BEGIN sumedia-urlify
    124 <IfModule mod_rewrite.c>
     124<IfModule mod_rewrite.c>   
     125    RewriteEngine on
    125126    RewriteCond %{REQUEST_URI} ^.*?/?' . preg_quote($admin_url) . '/?.*$
    126127    RewriteRule ^(.*?/?)' . preg_quote($admin_url) . '(/?.*)$ $1wp-admin$2 [L,E=IS_BACKEND:1,END]
  • sumedia-urlify/trunk/src/Sumedia/Urlify/Plugin.php

    r2213986 r2274268  
    1717        add_filter('login_url', [$this, 'urlify']);
    1818        add_filter('admin_url', [$this, 'urlify']);
     19        add_action('plugins_loaded', [$this, 'checkRewriteEngineChanges']);
    1920        add_action('plugins_loaded', [$this, 'controller']);
    2021    }
     
    4243    function deactivate()
    4344    {
    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 
    4845        $htaccess = \Sumedia\Urlify\Base\Registry::get('Sumedia\Urlify\Htaccess');
    4946        $htaccess->register_rewrite_filter();
     
    9693    }
    9794
     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
    98113    public function controller()
    99114    {
     
    102117            $action = isset($_POST['action']) ? $_POST['action'] : null;
    103118            $action = null == $action && isset($_GET['action']) ? $_GET['action'] : $action;
     119            $action = null == $action ? 'Config' : $action;
    104120            if (!preg_match('#^[a-z0-9_\-]+$#i', $action)) {
    105121                return;
  • sumedia-urlify/trunk/sumedia-urlify.php

    r2213986 r2274268  
    1212 * Plugin URI:  https://github.com/sumedia-wordpress/urlify
    1313 * Description: Changes important URL's to improve security
    14  * Version:     0.3.0
     14 * Version:     0.3.1
    1515 * Requires at least: 5.3 (nothing else tested yet)
    1616 * Requires PHP: 5.6.0 (not tested, could work)
     
    5757} else {
    5858
    59     define('SUMEDIA_URLIFY_VERSION', '0.3.0');
     59    define('SUMEDIA_URLIFY_VERSION', '0.3.1');
    6060    define('SUMEDIA_URLIFY_PLUGIN_NAME', dirname(plugin_basename(__FILE__)));
    6161    define('SUMEDIA_URLIFY_PLUGIN_PATH', __DIR__);
  • sumedia-urlify/trunk/templates/admin/config.phtml

    r2213986 r2274268  
    77}
    88
     9global $wp_rewrite;
     10
    911$form = \Sumedia\Urlify\Base\Registry::get('Sumedia\Urlify\Admin\Form\Config');
     12
     13$isRewriteEnabled = !empty($wp_rewrite->mod_rewrite_rules());
    1014
    1115?>
     
    1317    <div class="suma-content">
    1418        <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>
    2333                    </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>
    2448                </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; ?>
    4050        </form>
    4151    </div>
Note: See TracChangeset for help on using the changeset viewer.