PluginProbe
PlugVersions – Easily roll back to previous versions of your plugins. / 0.0.6.RC-1
PlugVersions – Easily roll back to previous versions of your plugins. v0.0.6.RC-1
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
plugversions / plugversions.php

plugversions.php in PlugVersions – Easily roll back to previous versions of your plugins. 0.0.6.RC-1, at plugversions.php

111 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: PlugVersions
4 Description: it retains up to three versions when you update a plugin. It works also with premium and custom plugins.
5 Author: Jose Mortellaro
6 Author URI: https://josemortellaro.com
7 Domain Path: /languages/
8 Text Domain: plugversions
9 Version: 0.0.6.RC-1
10 */
11 /* This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19 */
20 defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
21
22 //Definitions.
23 define( 'PLUGIN_REVISIONS_PLUGIN_DIR', untrailingslashit( dirname( __FILE__ ) ) );
24 define( 'PLUGIN_REVISIONS_PLUGIN_URL', untrailingslashit( plugins_url( '', __FILE__ ) ) );
25
26 if( is_admin() ){
27 require_once PLUGIN_REVISIONS_PLUGIN_DIR.'/admin/pr-admin.php';
28 }
29
30 add_filter( 'site_transient_update_plugins',function( $obj ){
31 /**
32 * Remove plugin revisions from the update notifications
33 *
34 * @since 0.0.1
35 */
36 if( isset( $obj ) && is_object( $obj ) && isset( $obj->response ) ){
37 $response = $obj->response;
38 $key = eos_plugin_revision_key();
39 foreach( $response as $p => $arr ){
40 if( false !== strpos( $p,'pr-'.$key.'-' ) && isset( $response[$p] ) ){
41 unset( $response[$p] );
42 }
43 }
44 $obj->response = $response;
45 }
46 return $obj;
47 } );
48
49 /**
50 * Return revision key
51 *
52 * @since 0.0.1
53 */
54 function eos_plugin_revision_key(){
55 $opts = get_site_option( 'plugin_revisions' );
56 if( $opts && isset( $opts['time' ] ) ){
57 $key = substr( md5( sanitize_text_field( $opts['time' ] ) ),0,8 );
58 return $key;
59 }
60 else{
61 $time = time();
62 $opts['time'] = $time;
63 update_site_option( 'plugin_revisions',$opts );
64 return substr( md5( $time ),0,8 );
65 }
66 return false;
67 }
68
69 /**
70 * Create zip pclzip.
71 *
72 * @since 0.0.6
73 *
74 */
75 function eos_pv_create_zip_pclzip( $destination, $zip_dirname ) {
76 if( file_exists( ABSPATH . 'wp-admin/includes/class-pclzip.php' ) ) {
77 require_once( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
78 if( class_exists( 'PclZip' ) ) {
79 $files = eos_pv_get_files( $destination );
80 if( $files ) {
81 $zip = new PclZip( str_replace( '/.zip', '.zip', $destination . '.zip' ) );
82 if ( defined( 'PCLZIP_OPT_REMOVE_PATH' ) ) {
83 $zip_created = $zip->create( $files, PCLZIP_OPT_REMOVE_PATH, WP_PLUGIN_DIR );
84 if( 0 == $zip_created ) {
85 return false;
86 }
87 return true;
88 }
89 }
90 }
91 return false;
92 }
93 }
94
95 /**
96 * Get files by path.
97 *
98 * @since 0.0.6
99 */
100 function eos_pv_get_files( $path ) {
101 if( ! class_exists( 'RecursiveIteratorIterator' ) ) return false;
102 $files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $path ), RecursiveIteratorIterator::LEAVES_ONLY );
103 $files_paths = array();
104 foreach ( $files as $name => $file ) {
105 if ( ! $file->isDir() ) {
106 $file_path = str_replace( '\\', '/', $file->getRealPath() );
107 $files_paths[] = $file_path;
108 }
109 }
110 return $files_paths;
111 }