PluginProbe
PlugVersions – Easily roll back to previous versions of your plugins. / 0.3.0
PlugVersions – Easily roll back to previous versions of your plugins. v0.3.0
0.3.0 0.0.6.RC-1 0.0.7 0.0.8 0.1.0 0.2.0 0.2.1 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6
← All changes | admin/pr-ajax-admin.php +9 -5 0.0.6 → 0.3.0 View file →
@@ -9,13 +9,17 @@
9 9
10 10 add_action( 'wp_ajax_eos_plugin_reviews_restore_version','eos_plugin_reviews_restore_version' );
11 11 /**
12 12 * Restore plugin version
13 + * This function is triggered by an Ajax request to restore a plugin version.
14 + * It verifies the nonce for security, checks user permissions, and restores the plugin version
15 + * from a specified directory. It unzips the plugin version if it is in zip format, renames the
16 + * plugin directory, and activates the plugin.
13 17 *
14 18 * @since 0.0.1
15 19 */
16 20 function eos_plugin_reviews_restore_version(){
17 - if( isset( $_POST['nonce'] ) && isset( $_POST['dir'] ) && isset( $_POST['parent_plugin'] ) && wp_verify_nonce( sanitize_text_field( $_POST['nonce'] ),'plugin_reviews_restore_version' ) ){
21 + if( isset( $_POST['nonce'] ) && isset( $_POST['dir'] ) && isset( $_POST['parent_plugin'] ) && wp_verify_nonce( sanitize_text_field( $_POST['nonce'] ),'plugin_reviews_restore_version' ) && current_user_can( 'manage_options' ) ) {
18 22 $key = eos_plugin_revision_key();
19 23 if( $key ){
20 24 global $wp_filesystem;
21 25 if( empty( $wp_filesystem ) || ! function_exists( 'unzip_file' ) ) {
@@ -40,15 +44,15 @@
40 44 dirname( PLUGIN_REVISIONS_PLUGIN_DIR ) . '/' . $dir,
41 45 dirname( PLUGIN_REVISIONS_PLUGIN_DIR )
42 46 ); // Unzip the chosen version.
43 47 if( $r_unzip ) {
44 - unlink( dirname( PLUGIN_REVISIONS_PLUGIN_DIR ) . '/' . $dir ); // Delete the zip after unzipping it.
48 + wp_delete_file( dirname( PLUGIN_REVISIONS_PLUGIN_DIR ) . '/' . $dir ); // Delete the zip after unzipping it.
45 49 }
46 50 }
47 - $r1 = rename( dirname( PLUGIN_REVISIONS_PLUGIN_DIR ) . '/' . dirname( $plugin ), $plugin_version ); // Rename the actual plugin that will be replaced giving a unique title.
48 - $r2 = rename( dirname( PLUGIN_REVISIONS_PLUGIN_DIR ) . '/' . str_replace( '.zip', '', $dir ) , dirname( PLUGIN_REVISIONS_PLUGIN_DIR ) . '/' . dirname( $plugin ) ); // Rename the chosen plugin version with the official plugin name.
51 + $r1 = $wp_filesystem->move( dirname( PLUGIN_REVISIONS_PLUGIN_DIR ) . '/' . dirname( $plugin ), $plugin_version ); // Rename the actual plugin that will be replaced giving a unique title.
52 + $r2 = $wp_filesystem->move( dirname( PLUGIN_REVISIONS_PLUGIN_DIR ) . '/' . str_replace( '.zip', '', $dir ) , dirname( PLUGIN_REVISIONS_PLUGIN_DIR ) . '/' . dirname( $plugin ) ); // Rename the chosen plugin version with the official plugin name.
49 53 $replaced_version_path = str_replace( $time,'',$plugin_version ); // Remove the time() from the title in the replaced plugin.
50 - $r3 = rename( $plugin_version, $replaced_version_path );
54 + $r3 = $wp_filesystem->move( $plugin_version, $replaced_version_path );
51 55 $r_zip = eos_pv_create_zip_pclzip( $replaced_version_path, '/pr-' . $key . '-' . sanitize_option( 'upload_path', $version ) . '-ver-' . dirname( $plugin ) );
52 56 if( $r_zip ) {
53 57 $wp_filesystem->delete( $replaced_version_path, true );
54 58 }