The WP Remote WordPress Plugin - Version 2.0.7

Version Description

Download this release

Release Info

Developer willmot
Plugin Icon 128x128 The WP Remote WordPress Plugin
Version 2.0.7
Comparing to
See all releases

Code changes from version 2.0.6 to 2.0.7

Files changed (4) hide show
  1. plugin.php +1 -1
  2. readme.txt +1 -1
  3. wprp.api.php +1 -0
  4. wprp.backups.php +92 -16
plugin.php CHANGED
@@ -3,7 +3,7 @@
3
  /*
4
  Plugin Name: WP Remote
5
  Description: Manage your WordPress site with <a href="https://wpremote.com/">WP Remote</a>. Deactivate to clear your API Key.
6
- Version: 2.0.6
7
  Author: Human Made Limited
8
  Author URI: http://hmn.md/
9
  */
3
  /*
4
  Plugin Name: WP Remote
5
  Description: Manage your WordPress site with <a href="https://wpremote.com/">WP Remote</a>. Deactivate to clear your API Key.
6
+ Version: 2.0.7
7
  Author: Human Made Limited
8
  Author URI: http://hmn.md/
9
  */
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: humanmade, joehoyle, mattheu, tcrsavage, willmot
3
  Tags: wpremote, remote administration, multiple wordpress
4
  Requires at least: 2.9
5
  Tested up to: 3.3.1
6
- Stable tag: 2.0.6
7
 
8
  WP Remote is a free web app that enables you to easily manage all of your WordPress powered sites from one place.
9
 
3
  Tags: wpremote, remote administration, multiple wordpress
4
  Requires at least: 2.9
5
  Tested up to: 3.3.1
6
+ Stable tag: 2.0.7
7
 
8
  WP Remote is a free web app that enables you to easily manage all of your WordPress powered sites from one place.
9
 
wprp.api.php CHANGED
@@ -69,6 +69,7 @@ foreach( $actions as $action => $value ) {
69
  case 'do_backup' :
70
  case 'delete_backup' :
71
  case 'supports_backups' :
 
72
 
73
  $actions[$action] = _wprp_backups_api_call( $action );
74
 
69
  case 'do_backup' :
70
  case 'delete_backup' :
71
  case 'supports_backups' :
72
+ case 'get_backup' :
73
 
74
  $actions[$action] = _wprp_backups_api_call( $action );
75
 
wprp.backups.php CHANGED
@@ -18,16 +18,33 @@ function _wprp_backups_api_call( $action ) {
18
  return true;
19
 
20
  case 'do_backup' :
21
-
 
 
22
  $backup = new HM_Backup();
23
-
24
  $upload_dir = wp_upload_dir();
25
-
26
  // Store the backup file in the uploads dir
27
  $backup->path = $upload_dir['basedir'] . '/_wpremote_backups';
28
 
29
- if ( !is_dir( $backup->path ) )
30
- mkdir( $backup->path );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  // Set a random backup filename
33
  $backup->archive_filename = md5( time() ) . '.zip';
@@ -41,27 +58,86 @@ function _wprp_backups_api_call( $action ) {
41
 
42
  $backup->backup();
43
 
44
- if ( $errors = $backup->errors() ) {
45
- $wp_error = new WP_Error;
 
 
 
 
 
 
 
 
46
 
47
- foreach ( $errors as $error )
48
- $wp_error->add( reset( $error ), reset( $error ) );
49
-
50
- return $wp_error;
 
 
51
  }
52
 
 
 
 
 
 
 
 
53
 
54
- return str_replace( ABSPATH, site_url( '/' ), $backup->archive_filepath() );
 
 
 
 
 
 
 
 
55
 
 
 
 
 
 
 
 
 
 
 
 
56
  case 'delete_backup' :
57
 
58
  $upload_dir = wp_upload_dir();
59
-
60
- if ( ! empty( $_REQUEST['backup'] ) && file_exists( $upload_dir['basedir'] . '/_wpremote_backups/' . $_REQUEST['backup'] ) && substr( $_REQUEST['backup'], -4 ) == '.zip' )
61
- unlink( $upload_dir['basedir'] . '/_wpremote_backups/' . $_REQUEST['backup'] );
62
-
63
  break;
64
 
65
  endswitch;
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  }
18
  return true;
19
 
20
  case 'do_backup' :
21
+
22
+ @ignore_user_abort(true);
23
+
24
  $backup = new HM_Backup();
 
25
  $upload_dir = wp_upload_dir();
26
+
27
  // Store the backup file in the uploads dir
28
  $backup->path = $upload_dir['basedir'] . '/_wpremote_backups';
29
 
30
+ $running_file = $backup->path . '/.backup_running';
31
+
32
+ // delete the backups folder to cleanup old backups
33
+ _wprp_backups_rmdirtree( $backup->path );
34
+
35
+ if ( ! @mkdir( $backup->path ) )
36
+ return new WP_Error( 'unable-to-create-backups-directory', 'Unable to write the .backup_running file - check your permissions on wp-content/uploads' );
37
+
38
+ // write the backup runing file for tracking...
39
+ if ( ! $handle = @fopen( $running_file, 'w' ) )
40
+ return new WP_Error( 'unable-to-write-backup-running-file' );
41
+
42
+ fwrite( $handle, $backup->archive_filename() );
43
+
44
+ fclose( $handle );
45
+
46
+ if ( ! file_exists( $running_file ) )
47
+ return new WP_Error( 'backup-running-file-was-not-created' );
48
 
49
  // Set a random backup filename
50
  $backup->archive_filename = md5( time() ) . '.zip';
58
 
59
  $backup->backup();
60
 
61
+ unlink( $backup->path . '/.backup_completed' );
62
+ unlink( $backup->path . '/.backup_running' );
63
+
64
+ // write the backup runing file for tracking...
65
+ $completed_file = $backup->path . '/.backup_completed';
66
+
67
+ if ( ! $handle = @fopen( $completed_file, 'w' ) )
68
+ return new WP_Error( 'unable-to-write-backup-completed-file' );
69
+
70
+ if ( $backup->errors() || ( $backup->warnings() && ! file_exists( $backup->archive_filepath() ) ) ) {
71
 
72
+ $errors = array_merge( $backup->errors(), $backup->warnings() );
73
+ fwrite( $handle, json_encode( $errors ) );
74
+
75
+ } else {
76
+
77
+ fwrite( $handle, 'file:' . $backup->archive_filename() );
78
  }
79
 
80
+ fclose( $handle );
81
+
82
+ return true;
83
+
84
+ case 'get_backup' :
85
+
86
+ $upload_dir = wp_upload_dir();
87
 
88
+ // Store the backup file in the uploads dir
89
+ $path = $upload_dir['basedir'] . '/_wpremote_backups';
90
+ $url = $upload_dir['baseurl'] . '/_wpremote_backups';
91
+
92
+ if ( ! is_dir( $path ) )
93
+ return new WP_Error( 'backups-dir-does-not-exist' );
94
+
95
+ if ( file_exists( $path . '/.backup_running' ) )
96
+ return new WP_Error( 'backup-running' );
97
 
98
+ if ( ! file_exists( $path . '/.backup_completed' ) )
99
+ return new WP_Error( 'backup-not-started' );
100
+
101
+ $file = file_get_contents( $path . '/.backup_completed' );
102
+
103
+ if ( strpos( $file, 'file:' ) === 0 )
104
+ return $url . '/' . substr( $file, 5 );
105
+
106
+ // must have errored, return errors in a WP_Error
107
+ return new WP_Error( 'backup-failed', json_decode( $file ) );
108
+
109
  case 'delete_backup' :
110
 
111
  $upload_dir = wp_upload_dir();
112
+
113
+ _wprp_backups_rmdirtree( $upload_dir['basedir'] . '/_wpremote_backups' );
114
+
 
115
  break;
116
 
117
  endswitch;
118
 
119
+ }
120
+
121
+ function _wprp_backups_rmdirtree( $dir ) {
122
+
123
+ if ( is_file( $dir ) )
124
+ unlink( $dir );
125
+
126
+ if ( ! is_dir( $dir ) )
127
+ return false;
128
+
129
+ $files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $dir ), RecursiveIteratorIterator::CHILD_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD );
130
+
131
+ foreach ( $files as $file ) {
132
+
133
+ if ( $file->isDir() )
134
+ @rmdir( $file->getPathname() );
135
+
136
+ else
137
+ @unlink( $file->getPathname() );
138
+
139
+ }
140
+
141
+ return @rmdir( $dir );
142
+
143
  }