time() ) ); } } ); add_filter( 'upgrader_package_options',function( $options ) { /** * Update revisions after plugin update * * @since 0.0.1 */ if( isset( $options['destination'] ) && isset( $options['hook_extra'] ) ){ $hook_extra = $options['hook_extra']; if( isset( $hook_extra['plugin'] ) ){ $plugin = $hook_extra['plugin']; $plugin_name = dirname( $plugin ); $path = sanitize_option( 'upload_path',$options['destination'].'/'.$plugin ); if( file_exists( $path ) ){ $plugin_data = get_plugin_data( $path ); $version = $plugin_data['Version']; if( !class_exists( 'WP_Upgrader' ) ){ if( file_exists( ABSPATH.'wp-admin/includes/class-wp-upgrader.php' ) ){ require_once ABSPATH.'/wp-admin/includes/class-wp-upgrader.php'; } } if( class_exists( 'WP_Upgrader' ) ){ $upgrader = new WP_Upgrader(); $key = eos_plugin_revision_key(); if( $key ){ $zip_dirname = 'pr-'.$key.'-'.sanitize_option( 'upload_path',$version ).'-ver-'.dirname( $plugin ); $destination = str_replace( dirname( $plugin ), $zip_dirname, sanitize_option( 'upload_path',plugin_dir_path( $path )) ); if( !is_dir( $destination ) ){ global $wp_filesystem; if( empty( $wp_filesystem ) ){ require_once ( ABSPATH .'/wp-admin/includes/file.php' ); WP_Filesystem(); } $wp_filesystem->mkdir( $destination ); } if( !empty( $wp_filesystem ) && $wp_filesystem->is_dir( $destination ) ){ $result = copy_dir( plugin_dir_path( $path ),$destination ); $zip_dirname .= '.zip'; if( eos_pv_create_zip_pclzip( $destination, $zip_dirname ) ) { // If zipped archive created delete the unzipped directory. $wp_filesystem->delete( $destination, true ); } eos_plugin_revisions_remove_versions( apply_filters( 'max_plugin_revisions',4 ),$plugin_name ); } } } } } } return $options; },10,4 ); add_action( 'admin_head',function(){ /** * Add style to properly show the revisions on the page of plugins * * @since 0.0.1 */ global $pagenow; if( $pagenow && 'plugins.php' === sanitize_text_field( $pagenow ) ){ ?> delete( dirname( PLUGIN_REVISIONS_PLUGIN_DIR ).'/'.$dir,true ); } } ++$n; } } } /** * Remove all revisions of all the plugins * * @since 0.0.1 */ function eos_plugin_revisions_remove_all_versions(){ $key = eos_plugin_revision_key(); $all_dirs = eos_plugin_revisions_scandir( dirname( PLUGIN_REVISIONS_PLUGIN_DIR ) ); global $wp_filesystem; if( empty( $wp_filesystem ) ){ require_once ABSPATH . 'wp-admin/includes/file.php'; WP_Filesystem(); } if( $all_dirs && !empty( $all_dirs ) ){ foreach( $all_dirs as $dir ){ if( false !== strpos( $dir,'pr-'.$key.'-' ) ){ $result = $wp_filesystem->delete( dirname( PLUGIN_REVISIONS_PLUGIN_DIR ).'/'.$dir,true ); } } } } /** * Revisions scandir * * @since 0.0.1 */ function eos_plugin_revisions_scandir( $dir ) { $ignored = array('.', '..', '.svn', '.htaccess'); $files = array(); foreach( scandir( $dir ) as $file ){ if( in_array( $file,$ignored ) ) continue; $files[$file] = filemtime( $dir.'/'.$file ); } asort( $files ); $files = array_keys( $files ); return ( $files ) ? $files : false; } add_action( 'admin_init', 'eos_pv_restore_revision_links' ); /** * Add links to restore previous revisions from zipped plugins. * * @since 0.0.6 */ function eos_pv_restore_revision_links() { require_once PLUGIN_REVISIONS_PLUGIN_DIR . '/admin/classes/class-plugversions-restoring-link.php'; $link = new PlugVersions_Restoring_Link(); }