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 / plugversions.php

plugversions.php in PlugVersions – Easily roll back to previous versions of your plugins. 0.0.8, at plugversions.php

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