-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathwordpress-move.php
More file actions
1845 lines (1582 loc) · 67.7 KB
/
wordpress-move.php
File metadata and controls
1845 lines (1582 loc) · 67.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Plugin Name: WordPress Move
Plugin URI: http://www.mertyazicioglu.com/wordpress-move/
Description: WordPress Move is a migration assistant for WordPress that can take care of changing your domain name and/or moving your database and files to another server. After activating the plugin, please navigate to WordPress Move page under the Settings menu to configure it. Then, you can start using the Migration Assistant under the Tools menu.
Version: 1.3.2
Author: Mert Yazicioglu
Author URI: http://www.mertyazicioglu.com
License: GPL2
*/
/* Copyright 2011 Mert Yazicioglu (email : mert@mertyazicioglu.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// Define file path constants
define( 'WPMOVE_DIR', WP_PLUGIN_DIR . '/' . basename( dirname( __FILE__ ) ) );
define( 'WPMOVE_BACKUP_DIR', WPMOVE_DIR . '/backup' );
define( 'WPMOVE_CONVERTED_BACKUP_DIR', WPMOVE_BACKUP_DIR . '/converted' );
define( 'WPMOVE_OLD_BACKUP_DIR', WPMOVE_BACKUP_DIR . '/old' );
define( 'WPMOVE_URL', WP_PLUGIN_URL . '/' . basename( dirname( __FILE__ ) ) );
define( 'WPMOVE_BACKUP_URL', WPMOVE_URL . '/backup' );
define( 'WPMOVE_CONVERTED_BACKUP_URL', WPMOVE_BACKUP_URL . '/converted' );
define( 'WPMOVE_OLD_BACKUP_URL', WPMOVE_BACKUP_URL . '/old' );
// Load functions needed for database and file operations
require_once( 'libs/functions-database-backup.php' );
require_once( 'libs/functions-file-backup.php' );
// Some operations may exceed the limit set by max_execution_time
if( ! ini_get('safe_mode') )
set_time_limit(0);
// Load PemFTP's classes if they're not loaded already
if ( ! class_exists( 'ftp_base' ) )
require_once( ABSPATH . "wp-admin/includes/class-ftp.php" );
// Create the class only if it doesn't exist
if ( ! class_exists( 'WPMove' ) ) {
/**
* WPMove Class
*/
class WPMove {
// Name of the option set
public $admin_options_name = 'wpmove_options';
/**
* Autoloader
*
* @param void
* @return void
*/
function WPMove() {
$this->load_language_file();
}
/**
* Loads the language file.
*
* @param void
* @return void
*/
function load_language_file() {
load_plugin_textdomain( 'WPMove', FALSE, basename( dirname( __FILE__ ) ) . '/lang/' );
}
/**
* Adds the script to the head for Migration Assistant.
*
* @param void
* @return void
*/
function add_migration_assistant_js() {
?>
<script type="text/javascript">
jQuery( document ).ready( function( $ ) {
$( "#wpmove-ma-domain-desc" ).css( 'min-height', $( "#wpmove-ma-migrate-desc" ).css( 'height' ) );
$( "#wpmove-ma-restore-desc" ).css( 'min-height', $( "#wpmove-ma-migrate-desc" ).css( 'height' ) );
if ( $( "#wpmove_file_tree" ).length ) {
$( "#wpmove_file_tree_loading" ).css( 'display', 'block' );
$( "#wpmove_file_tree" ).bind( "loaded.jstree", function( event, data ) {
$( "#wpmove_file_tree_loading" ).css( 'display', 'none' );
$( "#wpmove_file_tree" ).css( 'display', 'block' );
$( "#wpmove_file_tree_buttons" ).css( 'display', 'block' );
$( "#wpmove_file_tree_check_all" ).click( function () { $( "#wpmove_file_tree" ).jstree( "check_all" ); } );
$( "#wpmove_file_tree_uncheck_all" ).click( function () { $( "#wpmove_file_tree" ).jstree( "uncheck_all" ); } );
$( "#wpmove_file_tree" ).jstree( "check_all" );
}).jstree( {
"themes" : { "dots" : false },
"types" : { "valid_children" : [ "file" ], "types" : { "file" : { "icon" : { "image" : "<?php echo WPMOVE_URL; ?>/libs/js/themes/default/file.png" } } } },
"checkbox" : { "real_checkboxes" : true, "real_checkboxes_names" : function(n) { return [ "files[]", $( n[0] ).children( 'a' ).attr( 'title' ) ]; } },
"plugins" : [ "themes", "types", "checkbox", "html_data" ],
} );
}
$( '.if-js-closed' ).removeClass( 'if-js-closed' ).addClass( 'closed' );
postboxes.add_postbox_toggles( 'wpmove-ma-domain' );
postboxes.add_postbox_toggles( 'wpmove-ma-migrate' );
postboxes.add_postbox_toggles( 'wpmove-ma-restore' );
} );
</script>
<?php
}
/**
* Loads the JS file for Migration Assistant.
*
* @param void
* @return void
*/
function load_migration_assistant_scripts() {
wp_enqueue_script( 'file_tree', '/wp-content/plugins/wordpress-move/libs/js/jquery.jstree.js', array( 'jquery' ) );
// Load scripts needed for meta boxes
wp_enqueue_script( 'common' );
wp_enqueue_script( 'wp-lists' );
wp_enqueue_script( 'postbox' );
// Add meta boxes to queue
add_meta_box( 'wpmove-ma-domain', __( 'Change Domain Name', 'WPMove' ), array( $this, 'metabox_ma_domain' ), 'wpmove-domain' );
add_meta_box( 'wpmove-ma-migrate', __( 'Migrate', 'WPMove' ), array( $this, 'metabox_ma_migrate' ), 'wpmove-migrate' );
add_meta_box( 'wpmove-ma-restore', __( 'Restore', 'WPMove' ), array( $this, 'metabox_ma_restore' ), 'wpmove-restore' );
add_meta_box( 'wpmove-ma-migrate-ftp', __( 'FTP Settings', 'WPMove' ), array( $this, 'metabox_ma_migrate_ftp' ), 'wpmove-ma-migrate' );
add_meta_box( 'wpmove-ma-migrate-domain', __( 'Change Domain Name (Optional)', 'WPMove' ), array( $this, 'metabox_ma_migrate_domain' ), 'wpmove-ma-migrate' );
add_meta_box( 'wpmove-ma-migrate-filetree', __( 'Files to Transfer', 'WPMove' ), array( $this, 'metabox_ma_migrate_filetree' ), 'wpmove-ma-migrate' );
}
/**
* Adds the script to the head of the settings page.
*
* @param void
* @return void
*/
function add_settings_page_js() {
?>
<script type="text/javascript">
jQuery( document ).ready( function( $ ) {
$( '.if-js-closed' ).removeClass( 'if-js-closed' ).addClass( 'closed' );
postboxes.add_postbox_toggles( 'wpmove-settings' );
} );
</script>
<?php
}
/**
* Loads JS files for the settings page.
*
* @param void
* @return void
*/
function load_settings_page_scripts() {
// Load scripts needed for meta boxes
wp_enqueue_script( 'common' );
wp_enqueue_script( 'wp-lists' );
wp_enqueue_script( 'postbox' );
// Add meta boxes to queue
add_meta_box( 'wpmove-ftp-connection-details', __( 'FTP Connection Details', 'WPMove' ), array( $this, 'metabox_ftp_connection_details' ), 'wpmove-settings' );
add_meta_box( 'wpmove-db-backup-settings', __( 'Database Backup Settings', 'WPMove' ), array( $this, 'metabox_db_backup_settings' ), 'wpmove-settings' );
add_meta_box( 'wpmove-fs-backup-settings', __( 'File Backup Settings', 'WPMove' ), array( $this, 'metabox_fs_backup_settings' ), 'wpmove-settings' );
}
/**
* Calls functions we need to call after the activation of the plugin.
*
* @param void
* @return void
*/
function init() {
$this->get_admin_options();
}
/**
* Returns settings of the plugin.
*
* @param void
* @return void
*/
function get_admin_options() {
// Define options and their default values
$wpmove_admin_options = array( 'db_chunk_size' => 0,
'fs_chunk_size' => 10,
'ftp_hostname' => '',
'ftp_port' => 21,
'ftp_username' => '',
'ftp_passive_mode' => 1,
'ftp_remote_path' => '',
);
// Try retrieving options from the database
$wpmove_options = get_option( $this->admin_options_name );
// Deletes the FTP Password stored in the database
if ( is_array( $wpmove_options ) && array_key_exists( 'ftp_password', $wpmove_options ) )
unset( $wpmove_options['ftp_password'] );
// If the option set already exists in the database, reset their values
if ( ! empty( $wpmove_options ) )
foreach ( $wpmove_options as $key => $value )
$wpmove_admin_options[$key] = $value;
// Update the database
update_option( $this->admin_options_name, $wpmove_admin_options );
// Return options
return $wpmove_admin_options;
}
/**
* Generates the settings page of the plugin.
*
* @param void
* @return void
*/
function print_settings_page() {
// Get plugin's settings
$wpmove_options = $this->get_admin_options();
// If the form is submitted successfully...
if ( $_POST && check_admin_referer( 'wpmove_update_settings' ) ) {
// If the user was redirected from the migration assistant, redirect him/her back once all necessary fields are filled
if ( isset( $_POST['wpmove_ref'] ) && $_POST['wpmove_ftp_hostname'] !== '' && $_POST['wpmove_ftp_username'] !== '' && $_POST['wpmove_ftp_port'] !== 0 )
echo '<meta http-equiv="refresh" content="' . esc_attr( '0;url=tools.php?page=wpmove&do=migrate' ) . '" />';
// Store the changes made...
$wpmove_options['db_chunk_size'] = intval( $_POST['wpmove_db_chunk_size'] );
$wpmove_options['fs_chunk_size'] = intval( $_POST['wpmove_fs_chunk_size'] );
$wpmove_options['ftp_hostname'] = sanitize_text_field( $_POST['wpmove_ftp_hostname'] );
$wpmove_options['ftp_port'] = intval( $_POST['wpmove_ftp_port'] );
$wpmove_options['ftp_username'] = sanitize_text_field( $_POST['wpmove_ftp_username'] );
$wpmove_options['ftp_passive_mode'] = intval( $_POST['wpmove_ftp_passive_mode'] );
$wpmove_options['ftp_remote_path'] = sanitize_text_field( $_POST['wpmove_ftp_remote_path'] );
// Update plugin settings
update_option( $this->admin_options_name, $wpmove_options );
?>
<div class="updated"><p><strong><?php _e( 'Settings saved.', 'WPMove' ); ?></strong></p></div>
<?php
}
// Tell the user to fill in the FTP details if he/she was redirected from the migration assistant
if ( isset( $_GET['ref'] ) || isset( $_POST['wpmove_ref'] ) )
echo '<div class="updated"><p><strong>' . __( 'Please fill in FTP Connection Details in order to start the migration process.', 'WPMove' ) . '</strong></p></div>';
?>
<div class="wrap">
<div id="icon-options-general" class="icon32">
<br>
</div>
<h2><?php _e( 'WordPress Move Settings', 'WPMove' ); ?></h2>
<p>
<?php _e( 'Please configure the plugin using the settings below before starting to use the Migration Assistant under the Tools menu. If connecting to the remote server fails, please toggle the Passive Mode setting and try again.', 'WPMove' ); ?>
</p>
<form method="post" action="options-general.php?page=wpmove-settings">
<?php
// To make sure the form is submitted via ACP.
wp_nonce_field( 'wpmove_update_settings' );
// Needed to be able to toggle meta boxes
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
?>
<div id="poststuff" class="metabox-holder">
<?php do_meta_boxes( 'wpmove-settings', 'advanced', $wpmove_options ); ?>
</div>
<?php
// Pass the refferer info with a hidden input field
if ( isset( $_GET['ref'] ) || isset( $_POST['wpmove_ref'] ) )
echo '<input id="wpmove_ref" name="wpmove_ref" type="hidden" />';
// Display the submit button
submit_button();
?>
</form>
</div>
<?php
}
/**
* Callback function for the FTP Connection Details meta box.
*
* @param $wpmove_options Plugin settings array
* @return void
*/
function metabox_ftp_connection_details( $wpmove_options ) {
?>
<p>
<?php _e( 'These are the FTP connection details of your new server.', 'WPMove' ); ?>
</p>
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row">
<label for="wpmove_ftp_hostname"><?php _e( 'Hostname', 'WPMove' ); ?></label>
</th>
<td>
<input class="regular-text code" id="wpmove_ftp_hostname" name="wpmove_ftp_hostname" type="text" value="<?php echo esc_attr( $wpmove_options['ftp_hostname'] ); ?>" /> <i><?php _e( 'The hostname you use to establish an FTP connection to the remote server. Might be an IP address or a domain name.', 'WPMove' ); ?></i>
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="wpmove_ftp_port"><?php _e( 'Port', 'WPMove' ); ?></label>
</th>
<td>
<input id="wpmove_ftp_port" name="wpmove_ftp_port" type="text" value="<?php echo esc_attr( $wpmove_options['ftp_port'] ); ?>" size="5" /> <i><?php _e( 'If you do not know what to write, it is most probably 21.', 'WPMove' ); ?></i>
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="wpmove_ftp_username"><?php _e( 'Username', 'WPMove' ); ?></label>
</th>
<td>
<input class="regular-text" id="wpmove_ftp_username" name="wpmove_ftp_username" type="text" value="<?php echo esc_attr( $wpmove_options['ftp_username'] ); ?>" /> <i><?php _e( 'The username you use to establish an FTP connection to the remote server.', 'WPMove' ); ?></i>
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="wpmove_ftp_password"><?php _e( 'Password', 'WPMove' ); ?></label>
</th>
<td>
<i><?php _e( 'You will be asked to enter your FTP Password you use to establish an FTP connection to the remote server, right before starting the migration process.', 'WPMove' ); ?></i>
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="wpmove_ftp_remote_path"><?php _e( 'Remote Backup Path', 'WPMove' ); ?></label>
</th>
<td>
<input class="regular-text code" id="wpmove_ftp_remote_path" name="wpmove_ftp_remote_path" type="text" value="<?php echo esc_attr( $wpmove_options['ftp_remote_path'] ); ?>" /> <i><?php _e( 'Path from the top directory that your FTP account has access to, to the backup directory of the WordPress Move plugin on the remote server. For instance:', 'WPMove' ); ?> <code>/var/www/wp-content/plugins/wordpress-move/backup/</code></i>
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="wpmove_ftp_passive_mode"><?php _e( 'Use Passive Mode', 'WPMove' ); ?></label>
</th>
<td>
<label title="enabled">
<input type="radio" name="wpmove_ftp_passive_mode" value="1" <?php if ( $wpmove_options['ftp_passive_mode'] ) echo 'checked="checked"'; ?> />
<span style="font-size:11px;"><?php _e( 'Yes', 'WPMove' ); ?></span>
</label>
<br>
<label title="disabled">
<input type="radio" name="wpmove_ftp_passive_mode" value="0" <?php if ( ! $wpmove_options['ftp_passive_mode'] ) echo 'checked="checked"'; ?> />
<span style="font-size:11px;"><?php _e( 'No', 'WPMove' ); ?></span>
</label>
</td>
</tr>
</tbody>
</table>
<?php
}
/**
* Callback function for the Database Backup Settings meta box.
*
* @param $wpmove_options Plugin settings array
* @return void
*/
function metabox_db_backup_settings( $wpmove_options ) {
?>
<p>
<?php _e( 'The size of each chunk of your database backup. Actual sizes of chunks may exceed this size limit. 0 means unlimited.', 'WPMove' ); ?>
</p>
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row">
<label for="wpmove_db_chunk_size"><?php _e( 'Chunk Size', 'WPMove' ); ?></label>
</th>
<td>
<input id="wpmove_db_chunk_size" name="wpmove_db_chunk_size" type="text" value="<?php echo esc_attr( $wpmove_options['db_chunk_size'] ); ?>" size="5" /> MB
</td>
</tr>
</tbody>
</table>
<?php
}
/**
* Callback function for the File Backup Settings meta box.
*
* @param $wpmove_options Plugin settings array
* @return void
*/
function metabox_fs_backup_settings( $wpmove_options ) {
?>
<p>
<?php _e( 'The size of files to compress per filesystem backup chunk. Sizes of chunks will be less than or equal to this size limit, depending on the compression ratio. 0 means unlimited.', 'WPMove' ); ?>
</p>
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row">
<label for="wpmove_fs_chunk_size"><?php _e( 'Chunk Size', 'WPMove' ); ?></label>
</th>
<td>
<input id="wpmove_fs_chunk_size" name="wpmove_fs_chunk_size" type="text" value="<?php echo esc_attr( $wpmove_options['fs_chunk_size'] ); ?>" size="5" /> MB
</td>
</tr>
</tbody>
</table>
<?php
}
/**
* Generates the migration assistant page of the plugin.
*
* @param void
* @return void
*/
function print_migration_assistant_page() {
// If the form is submitted...
if ( isset( $_GET['do'] ) ) {
// Call the requested function
switch ( $_GET['do'] ) {
case 'domain': $this->print_change_domain_name_page();
break;
case 'migrate': $this->print_migration_page();
break;
case 'complete': $this->print_complete_migration_page();
break;
}
} else {
?>
<div class="wrap">
<div id="icon-tools" class="icon32">
<br>
</div>
<h2><?php _e( 'Migration Assistant', 'WPMove' ); ?></h2>
<p>
<?php _e( 'Please make sure you read the documentation carefully, before selecting an action to proceed...', 'WPMove' ); ?>
</p>
<?php
// Needed to be able to toggle meta boxes
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
?>
<div id="poststuff" class="metabox-holder">
<div id="post-body" style="clear:left;display:block;float:left;position:relative;width:32%;">
<div id="post-body-content">
<?php do_meta_boxes( 'wpmove-domain', 'advanced', null ); ?>
</div>
</div>
<div id="post-body" style="clear:right;display:block;float:right;position:relative;width:32%;">
<div id="post-body-content">
<?php do_meta_boxes( 'wpmove-restore', 'advanced', null ); ?>
</div>
</div>
<div id="post-body" style="margin-left:34%;width:32%;">
<div id="post-body-content">
<?php do_meta_boxes( 'wpmove-migrate', 'advanced', null ); ?>
</div>
</div>
</div>
</div>
<?php
}
}
/**
* Callback function for the Change Domain Name meta box.
*
* @param void
* @return void
*/
function metabox_ma_domain() {
?>
<div id="domain">
<div id="wpmove-ma-domain-desc">
<p>
<strong><?php _e( 'If you wish to do the following...', 'WPMove' ); ?></strong>
</p>
<p>
<strong>•</strong> <?php _e( 'Just change the domain name this installation uses.', 'WPMove' ); ?><br>
</p>
<p>
<strong><?php _e( 'Do not forget that...', 'WPMove' ); ?></strong>
</p>
<p>
<strong>•</strong> <?php _e( 'Your files and database will not be transferred to another server.', 'WPMove' ); ?><br>
<strong>•</strong> <?php _e( 'Only instances of your old domain name in the database will be replaced.', 'WPMove' ); ?><br>
<strong>•</strong> <?php _e( 'You need to manually configure your server and new domain name to use it on this server.', 'WPMove' ); ?><br>
<strong>•</strong> <?php _e( 'A backup of your database will be made available under the backup directory.', 'WPMove' ); ?><br>
<strong>•</strong> <?php _e( 'Creating a manual backup of your database is still highly encouraged.', 'WPMove' ); ?><br>
</p>
<br>
</div>
<div id="wpmove-ma-domain-button" align="center">
<a class="button-primary" href="<?php echo esc_url( admin_url( 'tools.php?page=wpmove&do=domain' ) ); ?>"><?php _e( 'Begin', 'WPMove' ); ?></a>
</div>
</div>
<?php
}
/**
* Callback function for the Migrate meta box.
*
* @param void
* @return void
*/
function metabox_ma_migrate() {
?>
<div id="migrate">
<div id="wpmove-ma-migrate-desc">
<p>
<strong><?php _e( 'If you wish to do one or more of the following...', 'WPMove' ); ?></strong>
</p>
<p>
<strong>•</strong> <?php _e( 'Transfer your database to another server. ', 'WPMove' ); ?><br>
<strong>•</strong> <?php _e( 'Transfer some/all of your files to another server.', 'WPMove' ); ?><br>
<strong>•</strong> <?php _e( 'Use a different domain name on the target server.', 'WPMove' ); ?><br>
</p>
<p>
<strong><?php _e( 'Make sure that...', 'WPMove' ); ?></strong>
</p>
<p>
<strong>•</strong> <?php _e( 'WordPress and WordPress Move are installed on the target server.', 'WPMove' ); ?><br>
</p>
<p>
<strong><?php _e( 'Do not forget that...', 'WPMove' ); ?></strong>
</p>
<p>
<strong>•</strong> <?php _e( 'This installation will stay as-is after the operation.', 'WPMove' ); ?><br>
<strong>•</strong> <?php _e( 'You need to configure the plugin using the WordPress Move page under the Settings menu.', 'WPMove' ); ?><br>
<strong>•</strong> <?php _e( 'You need to manually configure your existing domain to use it on the target server.', 'WPMove' ); ?><br>
</p>
<br>
</div>
<div id="wpmove-ma-migrate-button" align="center">
<a class="button-primary" href="<?php echo esc_url( admin_url( 'tools.php?page=wpmove&do=migrate' ) ); ?>"><?php _e( 'Begin', 'WPMove' ); ?></a>
</div>
</div>
<?php
}
/**
* Callback function for the Restore meta box.
*
* @param void
* @return void
*/
function metabox_ma_restore() {
?>
<div id="restore">
<div id="wpmove-ma-restore-desc">
<p>
<strong><?php _e( 'If you wish to do one or more of the following...', 'WPMove' ); ?></strong>
</p>
<p>
<strong>•</strong> <?php _e( 'Complete migrating to this server.', 'WPMove' ); ?><br>
<strong>•</strong> <?php _e( 'Restore backup files listed under the Current Backups section of the Backup Manager.', 'WPMove' ); ?><br>
</p>
<p>
<strong><?php _e( 'Make sure that...', 'WPMove' ); ?></strong>
</p>
<p>
<strong>•</strong> <?php _e( 'You have backup files to use for this process under the backup directory.', 'WPMove' ); ?><br>
</p>
<p>
<strong><?php _e( 'Do not forget that...', 'WPMove' ); ?></strong>
</p>
<p>
<strong>•</strong> <?php _e( 'Backups will be processed starting from old to new.', 'WPMove' ); ?><br>
</p>
<br>
</div>
<div id="wpmove-ma-restore-button" align="center">
<a class="button-primary" href="<?php echo esc_url( admin_url( 'tools.php?page=wpmove&do=complete' ) ); ?>"><?php _e( 'Begin', 'WPMove' ); ?></a>
</div>
</div>
<?php
}
/**
* Handles the domain name changing process.
*
* @param void
* @return void
*/
function print_change_domain_name_page() {
// If the form is filled in completely and submitted successfully...
if ( $_POST && ! empty( $_POST['old_domain_name'] ) && ! empty( $_POST['new_domain_name'] ) && check_admin_referer( 'wpmove_change_domain_name_start' ) ) {
// Load plugin settings
$wpmove_options = $this->get_admin_options();
// Apply filters to the given domain names
$old_domain_name = esc_url_raw( $_POST['old_domain_name'] );
$new_domain_name = esc_url_raw( $_POST['new_domain_name'] );
// Create a backup of the database in case the operation fails
$db_backups = wpmove_create_db_backup( $wpmove_options['db_chunk_size'] );
// Create a backup of the database by changing instances of the old domain name with the newer one
$new_db_backups = wpmove_create_db_backup( $wpmove_options['db_chunk_size'], count( $db_backups ) + 1, $old_domain_name, $new_domain_name );
// Set error counter to zero
$errors_occured = 0;
// Import databsae backups we've just created
foreach ( $new_db_backups as $backup )
if ( TRUE !== wpmove_import_db_backup( $backup ) )
$errors_occured++;
// If everything went well...
if ( ! $errors_occured ) {
// Move the backup files we created "just in case" to the old backup directory
foreach ( $db_backups as $backup )
rename( trailingslashit( WPMOVE_BACKUP_DIR ) . $backup, trailingslashit( WPMOVE_OLD_BACKUP_DIR ) . $backup );
// Remove the backup files we've just imported as we won't need them anymore
foreach ( $new_db_backups as $backup )
wpmove_remove_db_backup( $backup );
// Prepare the new homepage URL
$new_home_url = str_replace( $old_domain_name, $new_domain_name, home_url( '/' ) );
// Display a success message
?>
<div class="wrap">
<div id="icon-tools" class="icon32">
<br>
</div>
<h2><?php _e( 'Success!', 'WPMove' ); ?></h2>
<p>
<?php _e( 'Your domain name has been changed successfully.', 'WPMove' ); ?>
<?php printf( __( '<a href="%s">Click here</a> to go to your site using your new domain.', 'WPMove' ), $new_home_url ); ?>
</p>
</div>
<?php
} else {
// Display a failure message on failure
?>
<div class="wrap">
<div id="icon-tools" class="icon32">
<br>
</div>
<h2><?php _e( 'Failure!', 'WPMove' ); ?></h2>
<p>
<?php
_e( 'An error occured while changing instances of your domain name.', 'WPMove' );
// To seperate the next message from the previous one
echo ' ';
// Remove the database backup with replaced domain names
foreach ( $new_db_backups as $backup )
wpmove_remove_db_backup( $backup );
// Set error counter to zero
$errors_occured = 0;
// Try to rollback to the previous state
foreach ( $db_backups as $backup )
if ( ! wpmove_import_db_backup( $backup ) )
$errors_occured++;
// If rolling back succeeds...
if ( ! $errors_occured ) {
_e( 'Changes on your domain has been rolled back automatically.', 'WPMove' );
// Move the backup files we created "just in case" to the old backup directory, again, just in case
foreach ( $db_backups as $backup )
rename( trailingslashit( WPMOVE_BACKUP_DIR ) . $backup, trailingslashit( WPMOVE_OLD_BACKUP_DIR ) . $backup );
} else {
_e( 'Rolling back to the previous state also failed. Please try importing the database backup stored under the backup folder manually.', 'WPMove' );
}
?>
</p>
</div>
<?php
}
} else {
?>
<div class="wrap">
<div id="icon-tools" class="icon32">
<br>
</div>
<form method="post" action="<?php echo esc_url( admin_url( 'tools.php?page=wpmove&do=domain' ) ); ?>">
<?php wp_nonce_field( 'wpmove_change_domain_name_start' ); ?>
<h2><?php _e( 'Changing Domain Name', 'WPMove' ); ?></h2>
<p>
<?php _e( 'Please enter exact paths to your WordPress installations on both domains without the trailing slash. After replacing instances of your old domain name in the database with the new one completes, please do not forget to update your nameservers.', 'WPMove' ); ?>
</p>
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row">
<label for="old_domain_name"><?php _e( 'Old Domain Name', 'WPMove' ); ?></label>
</th>
<td>
<input class="regular-text code" id="old_domain_name" name="old_domain_name" type="text" value="<?php echo home_url(); ?>" />
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="new_domain_name"><?php _e( 'New Domain Name', 'WPMove' ); ?></label>
</th>
<td>
<input class="regular-text code" id="new_domain_name" name="new_domain_name" type="text" />
</td>
</tr>
</tbody>
</table>
<p class="submit">
<input class="button-primary" type="submit" name="wpmove_change_domain_name" value="<?php _e( 'Change', 'WPMove' ); ?>" />
</p>
</form>
</div>
<?php
}
}
/**
* Handles the advanced migration process.
*
* @param void
* @return void
*/
function print_migration_page() {
// Load plugin settings
$wpmove_options = $this->get_admin_options();
// If the FTP details are not on file, redirect the user to the settings page
if ( $wpmove_options['ftp_hostname'] == '' || $wpmove_options['ftp_username'] == '' || $wpmove_options['ftp_port'] == 0 ) {
echo '<meta http-equiv="refresh" content="0;url=options-general.php?page=wpmove-settings&ref=ma" />';
}
if ( $_POST && check_admin_referer( 'wpmove_advanced_migration_start' ) ) {
?>
<div class="wrap">
<div id="icon-tools" class="icon32">
<br>
</div>
<h2><?php _e( 'Migration Assistant', 'WPMove' ); ?></h2>
<p>
<?php
// Load plugin settings
$wpmove_options = $this->get_admin_options();
// Create an array to hold backup files that will be uploaded
$backups = array();
// If changing the current domain name is also requested...
if ( ! empty( $_POST['old_domain_name'] ) && ! empty( $_POST['new_domain_name'] ) ) {
// Apply filters to the given domain names
$old_domain_name = esc_url_raw( $_POST['old_domain_name'] );
$new_domain_name = esc_url_raw( $_POST['new_domain_name'] );
// Create a backup of the database by changing instances of the old domain name with the newer one
$db_backups = wpmove_create_db_backup( $wpmove_options['db_chunk_size'], 1, $old_domain_name, $new_domain_name );
} else {
// Create a backup of the database
$db_backups = wpmove_create_db_backup( $wpmove_options['db_chunk_size'] );
}
// Add names of database backup files to the array of backup files
$backups = array_merge( $backups, $db_backups );
// Check whether an array is actually posted or not
if ( isset( $_POST['files'] ) && is_array( $_POST['files'] ) ) {
// Use the POST data directly, if the fallback method is being used
$files = array_map( 'sanitize_text_field', $_POST['files'] );
// Remove non-empty directories from the array
$files = array_filter( $files );
// Create chunks from the selected files
$chunks = wpmove_divide_into_chunks( $files, $wpmove_options['fs_chunk_size'] );
// To prevent overwriting archives created in the same second
$chunk_id = 1;
// Create an archive of the each chunk
foreach ( $chunks as $chunk )
array_push( $backups, wpmove_create_archive( $chunk, ABSPATH, $chunk_id++ ) );
}
// Check whether creating backups files succeeded or not
if ( ! file_exists( trailingslashit( WPMOVE_BACKUP_DIR ) . $backups['0'] ) ) {
_e( 'Could not create backup files. Please make sure the backup directory is writable. For further info, please refer to the documentation.', 'WPMove' );
} else {
// Upload files and display a success message on success
if ( $this->upload_files( $backups, sanitize_text_field( $_POST['ftp_password'] ) ) ) {
?>
<br>
<?php _e( 'Creating and uploading backups have been completed. You can now go to your new installation and run the migration assistant in Complete Migration mode.', 'WPMove' ); ?>
</p>
</div>
<?php
} else {
?>
<br>
<?php _e( 'Please check your FTP connection details on the settings page.', 'WPMove' ); ?>
</p>
</div>
<?php
}
}
} else {
?>
<div class="wrap">
<div id="icon-tools" class="icon32">
<br>
</div>
<h2><?php _e( 'Migration Assistant', 'WPMove' ); ?></h2>
<p>
<?php _e( 'Please select the files you want to include in the backup from the list below.', 'WPMove' ); ?>
</p>
<div id="poststuff" class="metabox-holder">
<form method="post" action="<?php echo esc_url( admin_url( 'tools.php?page=wpmove&do=migrate&type=advanced' ) ); ?>">
<?php
wp_nonce_field( 'wpmove_advanced_migration_start' );
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
do_meta_boxes( 'wpmove-ma-migrate', 'advanced', null );
submit_button( __( 'Start Migration', 'WPMove' ), 'primary', 'submit', FALSE );
?>
</form>
</div>
<br>
</div>
<?php
}
}
/**
* Callback function for the Migration FTP Settings meta box.
*
* @param $wpmove_options Plugin settings array
* @return void
*/
function metabox_ma_migrate_ftp() {
?>
<p>
<?php _e( 'If your FTP account uses a password, please enter it below.', 'WPMove' ); ?><br>
<blockquote>
<b><?php _e( 'FTP Password:', 'WPMove' ); ?></b> <input id="ftp_password" name="ftp_password" type="password" /><br>
</blockquote>
</p>
<?php
}
/**
* Callback function for the Migration Change Domain Name meta box.
*
* @param $wpmove_options Plugin settings array
* @return void
*/
function metabox_ma_migrate_domain() {
?>
<p>
<?php _e( 'Please enter the exact path to your WordPress installation on your new domain name without the trailing slash and then click Start Migration button to start the migration process.', 'WPMove' ); ?><br>
</p>
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row">
<label for="old_domain_name"><?php _e( 'Old Domain Name', 'WPMove' ); ?></label>
</th>
<td>
<input class="regular-text code" id="old_domain_name" name="old_domain_name" type="text" value="<?php echo home_url(); ?>" />
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="new_domain_name"><?php _e( 'New Domain Name', 'WPMove' ); ?></label>
</th>
<td>
<input class="regular-text code" id="new_domain_name" name="new_domain_name" type="text" />
</td>
</tr>
</tbody>
</table>
<?php
}
/**
* Callback function for the Migration Files to Transfer meta box.
*
* @param $wpmove_options Plugin settings array
* @return void
*/
function metabox_ma_migrate_filetree() {
?>
<p id="wpmove_file_tree_buttons" style="display: none;">
<input type="button" name="wpmove_file_tree_check_all" id="wpmove_file_tree_check_all" class="button-secondary" value="<?php _e( 'Select All', 'WPMove' ); ?>" />
<input type="button" name="wpmove_file_tree_uncheck_all" id="wpmove_file_tree_uncheck_all" class="button-secondary" value="<?php _e( 'Unselect All', 'WPMove' ); ?>" />
<input type="button" name="wpmove_toggle_change_domain_name" id="wpmove_toggle_change_domain_name" class="button-secondary" value="<?php _e( 'Change Domain Name', 'WPMove' ); ?>" style="display:none;" />
</p>
<blockquote>
<?php
// To use as a file ID
$i = 0;
// List all of the files inside the main directory
$abspath = substr( ABSPATH, 0, strlen( ABSPATH ) - 1 );
$files = wpmove_generate_file_tree( $abspath, FALSE, array( WPMOVE_DIR, WPMOVE_BACKUP_DIR, WPMOVE_OLD_BACKUP_DIR ) );
?>
<div id="wpmove_file_tree" style="display:none;">
<ul>
<?php wpmove_display_file_tree( $files ); ?>
</ul>
</div>
<div id="wpmove_file_tree_loading" style="display:none;">
<?php echo '<img src="' . WPMOVE_URL . '/libs/js/themes/default/throbber.gif" alt="' . __( 'Loading...', 'WPMove' ) . '" style="vertical-align:middle;" /> <strong>' . __( 'Loading...', 'WPMove' ) . '</strong>'; ?>
</div>
<noscript>
<?php
// Prepare the file list
$files = wpmove_list_all_files( $abspath, FALSE, array( WPMOVE_DIR, WPMOVE_BACKUP_DIR, WPMOVE_OLD_BACKUP_DIR ) );
// Display each file with a checked checkbox
foreach ( $files as $file ) {
if ( is_file( $file ) ) {
$short_path = str_replace( ABSPATH, '', $file );
echo '<input id="file-' . $i . '" name="files[]" type="checkbox" value="' . $file . '" checked> <label for="file-' . $i++ . '"><span class="code">' . $short_path . '</span></label><br>';
}
}
?>
</noscript>
</blockquote>
<?php
}