Plugin Directory

Changeset 1929933


Ignore:
Timestamp:
08/24/2018 08:48:24 PM (8 years ago)
Author:
nuagelab
Message:

2.0.2

  • Tested up to WordPress 4.9.8
  • Added a way to change the protocol to HTTP or HTTPS
Location:
automatic-domain-changer/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • automatic-domain-changer/trunk/auto-domain-change.php

    r1505955 r1929933  
    55Description: Automatically changes the domain of a WordPress blog
    66Author: NuageLab <wordpress-plugins@nuagelab.com>
    7 Version: 2.0.1
     7Version: 2.0.2
    88License: GPLv2 or later
    99Author URI: http://www.nuagelab.com/wordpress-plugins
     
    169169                            $error_terms = true;
    170170                        } else {
    171                             return $this->do_change($_POST['old-domain'], $_POST['new-domain']);
     171                            return $this->do_change($_POST['old-domain'], $_POST['new-domain'], $_POST['force-protocol'] ? $_POST['force-protocol'] : null);
    172172                        }
    173173                        break;
     
    191191        echo '<input type="hidden" name="action" value="'.$action.'" />';
    192192
     193        if (array_key_exists('force-protocol', $_POST)) {
     194            $force_protocol = $_POST['force-protocol'];
     195        } else if (array_key_exists('HTTPS', $_SERVER)) {
     196            $force_protocol = 'https';
     197        } else if (array_key_exists('HTTP_X_FORWARDED_PROTO', $_SERVER) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
     198            $force_protocol = 'https';
     199        } else {
     200            $force_protocol = 'http';
     201        }
     202
     203        echo '<style>';
     204        echo '.adc-widefat { height:28px; padding:2px; position:relative; top:2px; width:250px; max-width:100%;}';
     205        echo '.adc-select { text-align:right;}';
     206        echo '</style>';
     207
    193208        echo '<table class="form-table">';
    194209        echo '<tbody>';
    195210        echo '<tr valign="top">';
    196211        echo '<th scope="row"><label for="old-domain">'.__('Change domain from: ','auto-domain-change').'</label></th>';
    197         echo '<td>http://<input class="regular-text" type="text" name="old-domain" id="old-domain" value="'.esc_html(get_option('auto_domain_change-domain')).'" /></td>';
     212        echo '<td>http://<input class="adc-widefat" class="regular-text" type="text" name="old-domain" id="old-domain" value="'.esc_html(get_option('auto_domain_change-domain')).'" /></td>';
    198213        echo '</tr>';
    199214
    200215        echo '<tr valign="top">';
    201216        echo '<th scope="row"><label for="new-domain">'.__('Change domain to: ','auto-domain-change').'</label></th>';
    202         echo '<td>http://<input class="regular-text" type="text" name="new-domain" id="new-domain" value="'.esc_html($_SERVER['HTTP_HOST']).'" /></td>';
     217        echo '<td>';
     218        echo '<select name="force-protocol" id="force-protocol" class="adc-select">';
     219        foreach (array(
     220                     'https'=>__('https://', 'auto-domain-change'),
     221                     'http'=>__('http://', 'auto-domain-change'),
     222                     ''=>__('(same)', 'auto-domain-change'),
     223                 ) as $protocol=>$name) {
     224            printf('<option value="%1$s"%3$s>%2$s</option>',
     225                $protocol,
     226                $name,
     227                ($force_protocol == $protocol ? ' selected' : '')
     228            );
     229        }
     230        echo '</select>';
     231        echo '<input class="adc-widefat" class="regular-text" type="text" name="new-domain" id="new-domain" value="'.esc_html($_SERVER['HTTP_HOST']).'" /></td>';
    203232        echo '</tr>';
    204233
     
    260289     * @access  private
    261290     */
    262     private function do_change($old, $new)
     291    private function do_change($old, $new, $forceProtocol=null)
    263292    {
    264293        global $wpdb;
     
    325354
    326355                        // Process value
    327                         $v = $this->processValue( $v, $old, $new );
     356                        $v = $this->processValue( $v, $old, $new, $forceProtocol );
    328357
    329358                        // If value changed, replace it
     
    351380   
    352381   
    353     private function processValue($v, $old, $new)
     382    private function processValue($v, $old, $new, $forceProtocol)
    354383    {
    355384        $sfalse = serialize(false);
     
    374403        if (($serialized) && (is_string($v))) {
    375404            // Reprocess in case of double serialize done by sketchy plugins
    376             $v = $this->processValue($v, $old, $new);
     405            $v = $this->processValue($v, $old, $new, $forceProtocol);
    377406        } else {
    378407            // Replace
    379             $this->replace($v, $old, $new);
     408            $this->replace($v, $old, $new, $forceProtocol);
    380409        }
    381410
     
    539568     * @access  private
    540569     */
    541     private function replace(&$v, $old, $new)
     570    private function replace(&$v, $old, $new, $forceProtocol=null)
    542571    {
    543572        $protocols = array('http');
     
    553582        if ((is_array($v)) || (is_object($v))) {
    554583            foreach ($v as &$vv) {
    555                 $this->replace($vv, $old, $new);
     584                $this->replace($vv, $old, $new, $forceProtocol);
    556585            }
    557586        } else if (is_string($v)) {
    558587            foreach ($protocols as $protocol) {
    559588                foreach ($domains as $o=>$n) {
    560                     $v = preg_replace(','.$protocol.'://'.preg_quote($o,',').',i',$protocol.'://'.$n, $v);
     589                    $toProtocol = $forceProtocol ? $forceProtocol : $protocol;
     590                    $v = preg_replace(','.$protocol.'://'.preg_quote($o,',').',i',$toProtocol.'://'.$n, $v);
    561591                }
    562592            }
  • automatic-domain-changer/trunk/readme.txt

    r1505955 r1929933  
    44Tags: admin, administration, links, resources, domain change, migration
    55Requires at least: 3.0
    6 Tested up to: 4.5.1
     6Tested up to: 4.9.8
    77Stable tag: trunk
    88License: GPLv2 or later
     
    8383
    8484== Changelog ==
     85= 2.0.2 =
     86* Tested up to WordPress 4.9.8
     87* Added a way to change the protocol to HTTP or HTTPS
     88
    8589= 2.0.1 =
    8690* Tested up to WordPress 4.6.1
     
    8993= 2.0.0 =
    9094* Tested up to WordPress 4.4.2
    91 * Added backup functionnality
     95* Added backup functionality
    9296* Removed usage of mysql_* functions in favor of $wpdb
    9397
Note: See TracChangeset for help on using the changeset viewer.