| @@ -3,11 +3,16 @@ | ||
| 3 | 3 | Plugin Name: PlugVersions |
| 4 | 4 | Description: it retains up to three versions when you update a plugin. It works also with premium and custom plugins. |
| 5 | 5 | Author: Jose Mortellaro |
| 6 | 6 | Author URI: https://josemortellaro.com |
| 7 | +Plugin URI: https://josemortellaro.com | |
| 7 | 8 | Domain Path: /languages/ |
| 8 | 9 | Text Domain: plugversions |
| 9 | -Version: 0.0.6.RC-1 | |
| 10 | +License: GPLv2 or later | |
| 11 | +License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html | |
| 12 | +Version: 0.3.1 | |
| 13 | +Requires PHP: 7.4 | |
| 14 | +Tags: plugin, versions, revisions, restore, rollback, backup, management | |
| 10 | 15 | */ |
| 11 | 16 | /* This program is free software; you can redistribute it and/or modify |
| 12 | 17 | it under the terms of the GNU General Public License as published by |
| 13 | 18 | the Free Software Foundation; either version 2 of the License, or |
| @@ -23,22 +28,25 @@ | ||
| 23 | 28 | define( 'PLUGIN_REVISIONS_PLUGIN_DIR', untrailingslashit( dirname( __FILE__ ) ) ); |
| 24 | 29 | define( 'PLUGIN_REVISIONS_PLUGIN_URL', untrailingslashit( plugins_url( '', __FILE__ ) ) ); |
| 25 | 30 | |
| 26 | 31 | if( is_admin() ){ |
| 27 | - require_once PLUGIN_REVISIONS_PLUGIN_DIR.'/admin/pr-admin.php'; | |
| 32 | + require_once PLUGIN_REVISIONS_PLUGIN_DIR . '/admin/pr-admin.php'; | |
| 28 | 33 | } |
| 29 | 34 | |
| 30 | -add_filter( 'site_transient_update_plugins',function( $obj ){ | |
| 35 | +add_filter( 'site_transient_update_plugins', function( $obj ) { | |
| 31 | 36 | /** |
| 32 | 37 | * Remove plugin revisions from the update notifications |
| 38 | + * This filter is applied to the site transient update plugins object. | |
| 39 | + * It checks if the object is set and is an object, then it iterates through the response array. | |
| 40 | + * If it finds a key that matches the plugin revision key, it removes that entry from the response. | |
| 33 | 41 | * |
| 34 | 42 | * @since 0.0.1 |
| 35 | - */ | |
| 36 | - if( isset( $obj ) && is_object( $obj ) && isset( $obj->response ) ){ | |
| 43 | + */ | |
| 44 | + if( isset( $obj ) && is_object( $obj ) && isset( $obj->response ) ) { | |
| 37 | 45 | $response = $obj->response; |
| 38 | 46 | $key = eos_plugin_revision_key(); |
| 39 | 47 | foreach( $response as $p => $arr ){ |
| 40 | - if( false !== strpos( $p,'pr-'.$key.'-' ) && isset( $response[$p] ) ){ | |
| 48 | + if( false !== strpos( $p,'pr-'.$key.'-' ) && isset( $response[$p] ) ) { | |
| 41 | 49 | unset( $response[$p] ); |
| 42 | 50 | } |
| 43 | 51 | } |
| 44 | 52 | $obj->response = $response; |
| @@ -47,15 +55,18 @@ | ||
| 47 | 55 | } ); |
| 48 | 56 | |
| 49 | 57 | /** |
| 50 | 58 | * Return revision key |
| 59 | + * This key is used to identify the plugin revisions. | |
| 60 | + * It is based on the current time and is sanitized to ensure it is safe for use. | |
| 61 | + * If the key does not exist, it creates a new one and saves it in the site options. | |
| 51 | 62 | * |
| 52 | 63 | * @since 0.0.1 |
| 53 | 64 | */ |
| 54 | 65 | function eos_plugin_revision_key(){ |
| 55 | - $opts = get_site_option( 'plugin_revisions' ); | |
| 66 | + $opts = get_site_option( 'plugin_revisions', array() ); | |
| 56 | 67 | if( $opts && isset( $opts['time' ] ) ){ |
| 57 | - $key = substr( md5( sanitize_text_field( $opts['time' ] ) ),0,8 ); | |
| 68 | + $key = substr( md5( sanitize_text_field( $opts['time' ] ) ), 0, 8 ); | |
| 58 | 69 | return $key; |
| 59 | 70 | } |
| 60 | 71 | else{ |
| 61 | 72 | $time = time(); |
| @@ -60,16 +71,24 @@ | ||
| 60 | 71 | else{ |
| 61 | 72 | $time = time(); |
| 62 | 73 | $opts['time'] = $time; |
| 63 | 74 | update_site_option( 'plugin_revisions',$opts ); |
| 64 | - return substr( md5( $time ),0,8 ); | |
| 75 | + return substr( md5( $time ), 0, 8 ); | |
| 65 | 76 | } |
| 66 | 77 | return false; |
| 67 | 78 | } |
| 68 | 79 | |
| 69 | 80 | /** |
| 70 | - * Create zip pclzip. | |
| 81 | + * Create a zip file using PclZip. | |
| 82 | + * This function creates a zip file from a specified directory using the PclZip library. | |
| 83 | + * It checks if the PclZip class exists, retrieves all files from the directory, | |
| 84 | + * and creates a zip file at the specified destination. | |
| 85 | + * If the zip creation fails, it returns false; otherwise, it returns true. | |
| 71 | 86 | * |
| 87 | + * @param string $destination The path where the zip file will be created. | |
| 88 | + * @param string $zip_dirname The directory name to be zipped. | |
| 89 | + * @return bool True on success, false on failure. | |
| 90 | + * | |
| 72 | 91 | * @since 0.0.6 |
| 73 | 92 | * |
| 74 | 93 | */ |
| 75 | 94 | function eos_pv_create_zip_pclzip( $destination, $zip_dirname ) { |
| @@ -81,8 +100,9 @@ | ||
| 81 | 100 | $zip = new PclZip( str_replace( '/.zip', '.zip', $destination . '.zip' ) ); |
| 82 | 101 | if ( defined( 'PCLZIP_OPT_REMOVE_PATH' ) ) { |
| 83 | 102 | $zip_created = $zip->create( $files, PCLZIP_OPT_REMOVE_PATH, WP_PLUGIN_DIR ); |
| 84 | 103 | if( 0 == $zip_created ) { |
| 104 | + // If the zip creation fails, return false | |
| 85 | 105 | return false; |
| 86 | 106 | } |
| 87 | 107 | return true; |
| 88 | 108 | } |
| @@ -92,9 +112,11 @@ | ||
| 92 | 112 | } |
| 93 | 113 | } |
| 94 | 114 | |
| 95 | 115 | /** |
| 96 | - * Get files by path. | |
| 116 | + * This function retrieves all files from a given directory path, including subdirectories. | |
| 117 | + * It uses the RecursiveDirectoryIterator and RecursiveIteratorIterator classes to traverse the directory structure. | |
| 118 | + * The function returns an array of file paths, with backslashes replaced by forward slashes for consistency. | |
| 97 | 119 | * |
| 98 | 120 | * @since 0.0.6 |
| 99 | 121 | */ |
| 100 | 122 | function eos_pv_get_files( $path ) { |
| @@ -107,5 +129,5 @@ | ||
| 107 | 129 | $files_paths[] = $file_path; |
| 108 | 130 | } |
| 109 | 131 | } |
| 110 | 132 | return $files_paths; |
| 111 | -} | |
| 133 | +} | |