PluginProbe
PlugVersions – Easily roll back to previous versions of your plugins. / 0.0.8
PlugVersions – Easily roll back to previous versions of your plugins. v0.0.8
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
plugversions / admin / pr-ajax-admin.php

pr-ajax-admin.php in PlugVersions – Easily roll back to previous versions of your plugins. 0.0.8, at admin/pr-ajax-admin.php

64 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * It includes the code for the Ajax activities.
4
5 * @package Plugversions
6 */
7
8 defined( 'PLUGIN_REVISIONS_PLUGIN_DIR' ) || exit; // Exit if not accessed from Plugversions.
9
10 add_action( 'wp_ajax_eos_plugin_reviews_restore_version','eos_plugin_reviews_restore_version' );
11 /**
12 * Restore plugin version
13 *
14 * @since 0.0.1
15 */
16 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' ) && current_user_can( 'manage_options' ) ) {
18 $key = eos_plugin_revision_key();
19 if( $key ){
20 global $wp_filesystem;
21 if( empty( $wp_filesystem ) || ! function_exists( 'unzip_file' ) ) {
22 require_once ABSPATH .'/wp-admin/includes/file.php';
23 WP_Filesystem();
24 }
25 $time = time();
26 $dir = sanitize_text_field( $_POST['dir'] ); // $dir is the path of the plugin versoin that will be restored.
27 $plugin = sanitize_text_field( $_POST['parent_plugin'] );
28 $plugin_data = get_plugin_data( dirname( PLUGIN_REVISIONS_PLUGIN_DIR ) . '/' . $plugin );
29 $version = $plugin_data['Version'];
30 $plugin_version = dirname( PLUGIN_REVISIONS_PLUGIN_DIR ) . '/pr-' . $key . '-' . sanitize_option( 'upload_path',$version ) . '-ver-' . $time . dirname( $plugin );
31 // $plugin_version is the path assigned to the plugin that will be replaced.
32
33 $r_unzip = true;
34 if( 'zip' === pathinfo( $dir, PATHINFO_EXTENSION ) ) {
35 if( ! function_exists( 'unzip_file' ) ) {
36 die();
37 exit;
38 }
39 $r_unzip = unzip_file(
40 dirname( PLUGIN_REVISIONS_PLUGIN_DIR ) . '/' . $dir,
41 dirname( PLUGIN_REVISIONS_PLUGIN_DIR )
42 ); // Unzip the chosen version.
43 if( $r_unzip ) {
44 wp_delete_file( dirname( PLUGIN_REVISIONS_PLUGIN_DIR ) . '/' . $dir ); // Delete the zip after unzipping it.
45 }
46 }
47 $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.
48 $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 $replaced_version_path = str_replace( $time,'',$plugin_version ); // Remove the time() from the title in the replaced plugin.
50 $r3 = $wp_filesystem->move( $plugin_version, $replaced_version_path );
51 $r_zip = eos_pv_create_zip_pclzip( $replaced_version_path, '/pr-' . $key . '-' . sanitize_option( 'upload_path', $version ) . '-ver-' . dirname( $plugin ) );
52 if( $r_zip ) {
53 $wp_filesystem->delete( $replaced_version_path, true );
54 }
55 do_action( 'activate_plugin',$plugin );
56 do_action( "activate_{$plugin}" );
57 do_action( 'activated_plugin', $plugin );
58 echo (bool) ( $r_unzip && $r1 && $r2 && $r3 && $r_zip ); // Echo true if everything was successfull.
59 }
60 }
61 die();
62 exit;
63 }
64