Plugin Directory

Changeset 1708022


Ignore:
Timestamp:
08/03/2017 08:01:30 PM (9 years ago)
Author:
Zuige
Message:

Tag version 1.2

Location:
wp-safe-updates
Files:
2 added
18 edited
1 copied

Legend:

Unmodified
Added
Removed
  • wp-safe-updates/tags/1.2/db.php

    r1451001 r1708022  
    11<?php
     2
     3function currheap() {
     4  return isset( $_COOKIE['_alt_heap'] ) && ! empty( $_COOKIE['_alt_heap'] ) ? preg_replace('/[^a-z0-9_]/', '', strtolower( $_COOKIE['_alt_heap'] ) ) : false;
     5}
     6
     7defined( 'WP_CONTENT_DIR' ) || define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/wp-content' );
     8defined( 'WP_CONTENT_URL' ) || define( 'WP_CONTENT_URL', '/wp-content' );
     9if ( false !== currheap() ) {
     10  defined( 'WP_PLUGIN_DIR' ) || define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins_tmp_' . currheap() );
     11  defined( 'WP_PLUGIN_URL' ) || define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins_tmp_' . currheap() );
     12  defined( 'PLUGINDIR' ) || define( 'PLUGINDIR', 'wp-content/plugins_tmp_' . currheap() );
     13}
    214
    315/**
  • wp-safe-updates/tags/1.2/lib/class-alternative-heap.php

    r1507338 r1708022  
    2424      add_action('admin_footer', array( $this, 'render_alternative_heap_indicator' ) );
    2525      add_action('wp_footer', array( $this, 'render_alternative_heap_indicator' ) );
     26      add_action('login_footer', array( $this, 'render_alternative_heap_indicator' ) );
    2627    }
    2728  }
     
    5455    $alt_heap = $query_vars['alt_heap'];
    5556
    56     if( $alt_heap === 'clear' ) {
     57    if ( $alt_heap === 'clean' ) {
     58      // this means we want to clean the alt heap temp files and tables
     59      $this->delete_alt_plugins_dirs( $_COOKIE['_alt_heap'] );
     60      $this->delete_tmp_wp_tables( $_COOKIE['_alt_heap'] );
     61
     62      // and then clear the cookie
     63      $alt_heap = '';
     64    }
     65
     66    if( $alt_heap === 'clear' || $alt_heap === 'exit' ) {
    5767      // this means we want to clear the heap cookie
    5868      // equivalent to empty ?alt_heap=
    5969      $alt_heap = '';
    6070    }
     71
    6172
    6273    // not in a heap yet and GET alt_heap is defined and current user has plugin install privileges
     
    8495    $request_uri .= empty( $query_string ) ? '' : '?' . $query_string;
    8596
     97    // flush caches for this just in case
     98    wp_cache_flush();
     99
    86100    // redirect to requested page, but with alt heap this time
    87101    wp_redirect( $request_uri );
     
    102116
    103117  /**
     118   * Derives the original db prefix from an alt heap prefix
     119   */
     120  public static function derive_orig_prefix( $alt_prefix ) {
     121    $offset = strpos( $alt_prefix, 'tmp_' ) ? strpos( $alt_prefix, 'tmp_' ) : strlen( $alt_prefix );
     122    $orig_prefix = substr( $alt_prefix, 0, $offset );
     123
     124    // fall back to wp_ if all else fails
     125    if( empty( $orig_prefix ) ) {
     126      return 'wp_';
     127    }
     128    return $orig_prefix;
     129  }
     130
     131  /**
    104132   * Returns the plugins dir suffix for an alternative heap
    105133   */
     
    118146  public static function get_wp_tables() {
    119147    global $wpdb;
    120     $tables = $wpdb->get_results( $wpdb->prepare( "SHOW TABLES LIKE %s;", str_replace( '_', '\_', $wpdb->prefix) . '%' ), ARRAY_N );
     148    $orig_prefix = isset( $_COOKIE['_alt_heap'] ) ? self::derive_orig_prefix( $wpdb->prefix ) : $wpdb->prefix;
     149    $tables = $wpdb->get_results( $wpdb->prepare( "SHOW TABLES LIKE %s;", str_replace( '_', '\_', $orig_prefix ) . '%' ), ARRAY_N );
    121150    $tables = array_map( 'reset', $tables );
    122151
     
    133162  public static function get_tmp_wp_tables( $alt_heap = "" ) {
    134163    global $wpdb;
    135     $tables = $wpdb->get_results( $wpdb->prepare( "SHOW TABLES LIKE %s;", str_replace( '_', '\_', self::get_alt_prefix( $alt_heap ) ) . '%' ), ARRAY_N );
     164    // alt prefix will already be $wpdb->prefix if currently in a heap
     165    $alt_prefix = isset( $_COOKIE['_alt_heap'] ) ? $wpdb->prefix : self::get_alt_prefix( $alt_heap );
     166    $tables = $wpdb->get_results( $wpdb->prepare( "SHOW TABLES LIKE %s;", str_replace( '_', '\_', $alt_prefix ) . '%' ), ARRAY_N );
    136167    $tables = array_map( 'reset', $tables );
    137168    return $tables;
     
    257288    $dirs = array();
    258289    if( ! empty( $alt_heap ) ) {
    259       // return $alt_heap dir if defined
    260       $dirs[] = WP_PLUGIN_DIR . self::get_alt_suffix( $alt_heap );
    261 
    262       // return false if no the alt heap dir doesn't exist
     290      $suffix = self::get_alt_suffix( $alt_heap );
     291
     292      // WP_PLUGIN_DIR will be the alt heap dir if in an alt heap
     293      if ( strpos( WP_PLUGIN_DIR, $suffix ) ) {
     294        $dirs[] = WP_PLUGIN_DIR;
     295      } else {
     296        $dirs[] = WP_PLUGIN_DIR . self::get_alt_suffix( $alt_heap );
     297      }
     298
     299      // return false if the alt heap dir doesn't exist
    263300      if( ! file_exists( $dirs[0] ) ) {
    264301        return false;
     
    266303    }
    267304    else {
    268       // otherwise jsut return all alt plugin dirs
     305      // otherwise just return all alt plugin dirs
    269306      $iterator = new DirectoryIterator( dirname( WP_PLUGIN_DIR ) );
    270307      foreach( $iterator as $node ) {
     
    275312      }
    276313    }
     314
    277315    return $dirs;
    278316  }
     
    282320   */
    283321  public function delete_alt_plugins_dirs( $alt_heap = "" ) {
    284     $orig_plugins_dir = WP_PLUGIN_DIR;
     322    $suffix = self::get_alt_suffix( $alt_heap );
     323    $orig_plugins_dir = str_replace( $suffix, '', WP_PLUGIN_DIR );
    285324    $alt_dirs_to_delete = self::get_alt_plugins_dirs( $alt_heap );
    286325
     
    320359<div id="alt-heap-indicator">
    321360<?php echo wp_sprintf( __('You are currently testing updates. Any changes you make will not be saved.', 'wp-safe-updates'), currheap() ); ?>
    322  <a href="<?php echo admin_url('plugins.php?alt_heap=clear'); ?>"><?php _e('Finish tests', 'wp-safe-updates'); ?></a>
     361 <a href="<?php echo admin_url('plugins.php?alt_heap=clean'); ?>"><?php _e('Finish tests', 'wp-safe-updates'); ?></a>
    323362</div>
    324363<?php
  • wp-safe-updates/tags/1.2/readme.md

    r1454344 r1708022  
    1 # WP Safe Updates.
     1# WP Safe Updates
    22[![Latest Stable Version](https://poser.pugx.org/anttiviljami/wp-safe-updates/v/stable)](https://packagist.org/packages/anttiviljami/wp-safe-updates) [![Total Downloads](https://poser.pugx.org/anttiviljami/wp-safe-updates/downloads)](https://packagist.org/packages/anttiviljami/wp-safe-updates) [![Latest Unstable Version](https://poser.pugx.org/anttiviljami/wp-safe-updates/v/unstable)](https://packagist.org/packages/anttiviljami/wp-safe-updates) [![License](https://poser.pugx.org/anttiviljami/wp-safe-updates/license)](https://packagist.org/packages/anttiviljami/wp-safe-updates)
    33
     
    51513. Activate the plugin
    5252
    53 ## Configuration
    54 
    55 First copy the `db.php` file from this plugin to your `wp-content` directory.
    56 
    57 Then just paste these lines to your `wp-config.php`.
    58 ```php
    59 /**
    60  * WordPress Safe Updates required configuration
    61  */
    62 function currheap() {
    63   return isset( $_COOKIE['_alt_heap'] ) && ! empty( $_COOKIE['_alt_heap'] ) ? preg_replace('/[^a-z0-9_]/', '', strtolower( $_COOKIE['_alt_heap'] ) ) : false;
    64 }
    65 defined( 'WP_CONTENT_DIR' ) || define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/wp-content' );
    66 defined( 'WP_CONTENT_URL' ) || define( 'WP_CONTENT_URL', '/wp-content' );
    67 if ( false !== currheap() ) {
    68   defined( 'WP_PLUGIN_DIR' ) || define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins_tmp_' . currheap() );
    69   defined( 'WP_PLUGIN_URL' ) || define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins_tmp_' . currheap() );
    70   defined( 'PLUGINDIR' ) || define( 'PLUGINDIR', 'wp-content/plugins_tmp_' . currheap() );
    71 }
    72 ```
    73 
  • wp-safe-updates/tags/1.2/readme.txt

    r1507338 r1708022  
    55Requires at least: 4.5
    66Tested up to: 4.6.1
    7 Stable tag: 1.1
     7Stable tag: 1.2
    88License: GPLv3
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    2727https://github.com/anttiviljami/wp-safe-updates
    2828
    29 == Installation ==
    30 
    31 Install and activate the plugin via wp-admin.
    32 
    33 Then copy the `db.php` file from this plugin to your `wp-content` directory.
    34 
    35 Finally, paste these lines to your `wp-config.php`.
    36 
    37 `/**
    38  * WordPress Safe Updates required configuration
    39  */
    40 function currheap() {
    41   return isset( $_COOKIE['_alt_heap'] ) && ! empty( $_COOKIE['_alt_heap'] ) ? preg_replace('/[^a-z0-9_]/', '', strtolower( $_COOKIE['_alt_heap'] ) ) : false;
    42 }
    43 defined( 'WP_CONTENT_DIR' ) || define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/wp-content' );
    44 defined( 'WP_CONTENT_URL' ) || define( 'WP_CONTENT_URL', '/wp-content' );
    45 if ( false !== currheap() ) {
    46   defined( 'WP_PLUGIN_DIR' ) || define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins_tmp_' . currheap() );
    47   defined( 'WP_PLUGIN_URL' ) || define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins_tmp_' . currheap() );
    48   defined( 'PLUGINDIR' ) || define( 'PLUGINDIR', 'wp-content/plugins_tmp_' . currheap() );
    49 }`
    50 
    5129== Frequently Asked Questions ==
    5230
  • wp-safe-updates/tags/1.2/vendor/autoload.php

    r1451001 r1708022  
    33// autoload.php @generated by Composer
    44
    5 require_once __DIR__ . '/composer' . '/autoload_real.php';
     5require_once __DIR__ . '/composer/autoload_real.php';
    66
    77return ComposerAutoloaderInit6b6b80b301d3663ac27b1b7644fe5e53::getLoader();
  • wp-safe-updates/tags/1.2/vendor/composer/ClassLoader.php

    r1451001 r1708022  
    5454    private $useIncludePath = false;
    5555    private $classMap = array();
    56 
    5756    private $classMapAuthoritative = false;
     57    private $missingClasses = array();
     58    private $apcuPrefix;
    5859
    5960    public function getPrefixes()
     
    273274
    274275    /**
     276     * APCu prefix to use to cache found/not-found classes, if the extension is enabled.
     277     *
     278     * @param string|null $apcuPrefix
     279     */
     280    public function setApcuPrefix($apcuPrefix)
     281    {
     282        $this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null;
     283    }
     284
     285    /**
     286     * The APCu prefix in use, or null if APCu caching is not enabled.
     287     *
     288     * @return string|null
     289     */
     290    public function getApcuPrefix()
     291    {
     292        return $this->apcuPrefix;
     293    }
     294
     295    /**
    275296     * Registers this instance as an autoloader.
    276297     *
     
    314335    public function findFile($class)
    315336    {
    316         // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
    317         if ('\\' == $class[0]) {
    318             $class = substr($class, 1);
    319         }
    320 
    321337        // class map lookup
    322338        if (isset($this->classMap[$class])) {
    323339            return $this->classMap[$class];
    324340        }
    325         if ($this->classMapAuthoritative) {
     341        if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
    326342            return false;
    327343        }
     344        if (null !== $this->apcuPrefix) {
     345            $file = apcu_fetch($this->apcuPrefix.$class, $hit);
     346            if ($hit) {
     347                return $file;
     348            }
     349        }
    328350
    329351        $file = $this->findFileWithExtension($class, '.php');
    330352
    331353        // Search for Hack files if we are running on HHVM
    332         if ($file === null && defined('HHVM_VERSION')) {
     354        if (false === $file && defined('HHVM_VERSION')) {
    333355            $file = $this->findFileWithExtension($class, '.hh');
    334356        }
    335357
    336         if ($file === null) {
     358        if (null !== $this->apcuPrefix) {
     359            apcu_add($this->apcuPrefix.$class, $file);
     360        }
     361
     362        if (false === $file) {
    337363            // Remember that this class does not exist.
    338             return $this->classMap[$class] = false;
     364            $this->missingClasses[$class] = true;
    339365        }
    340366
     
    349375        $first = $class[0];
    350376        if (isset($this->prefixLengthsPsr4[$first])) {
    351             foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
    352                 if (0 === strpos($class, $prefix)) {
    353                     foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
     377            $subPath = $class;
     378            while (false !== $lastPos = strrpos($subPath, '\\')) {
     379                $subPath = substr($subPath, 0, $lastPos);
     380                $search = $subPath.'\\';
     381                if (isset($this->prefixDirsPsr4[$search])) {
     382                    foreach ($this->prefixDirsPsr4[$search] as $dir) {
     383                        $length = $this->prefixLengthsPsr4[$first][$search];
    354384                        if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
    355385                            return $file;
     
    400430            return $file;
    401431        }
     432
     433        return false;
    402434    }
    403435}
  • wp-safe-updates/tags/1.2/vendor/composer/LICENSE

    r1451001 r1708022  
    11
    2 Copyright (c) 2016 Nils Adermann, Jordi Boggiano
     2Copyright (c) Nils Adermann, Jordi Boggiano
    33
    44Permission is hereby granted, free of charge, to any person obtaining a copy
  • wp-safe-updates/tags/1.2/vendor/composer/autoload_real.php

    r1451001 r1708022  
    2424        spl_autoload_unregister(array('ComposerAutoloaderInit6b6b80b301d3663ac27b1b7644fe5e53', 'loadClassLoader'));
    2525
    26         $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION');
     26        $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
    2727        if ($useStaticLoader) {
    2828            require_once __DIR__ . '/autoload_static.php';
  • wp-safe-updates/tags/1.2/wp-safe-updates.php

    r1507338 r1708022  
    44 * Plugin URI: https://github.com/anttiviljami/wp-safe-updates
    55 * Description: Test WordPress plugin updates safely before applying them on the live site.
    6  * Version: 1.1
     6 * Version: 1.2
    77 * Author: @anttiviljami
    88 * Author URI: https://github.com/anttiviljami
     
    3434  public $alt_heap;
    3535  public $update_logic;
     36
     37  public static $dropin_target = WP_CONTENT_DIR . '/db.php';
     38  public static $dropin_file = __DIR__ . '/db.php';
    3639
    3740  public static function init() {
     
    6669    }
    6770
    68     // clear all heaps on uninstall
     71    // configure custom dropin file
     72    register_activation_hook( __FILE__, array( 'Safe_Updates', 'install_custom_dropin' ) );
     73
     74    // clear all heaps on uninstall and clean up files
    6975    register_uninstall_hook( __FILE__, array( 'Safe_Updates', 'uninstall_cleanup' ) );
    7076  }
     
    9298<div class="notice notice-warning is-dismissible">
    9399  <?php $configure_action = 'https://wordpress.org/plugins/wp-safe-updates/installation/'; ?>
    94   <p><?php echo wp_sprintf( __('WP Safe Updates is not yet active. Please <a href="%s" target="_blank">configure</a> it.', 'wp-safe-updates'), $configure_action ); ?> <button type="button" class="notice-dismiss"></button></p>
     100  <p><?php echo wp_sprintf( __('WP Safe Updates is not yet active. Please copy the <pre>db.php</pre> file inside this plugin to your wp-content directory.', 'wp-safe-updates'), $configure_action ); ?> <button type="button" class="notice-dismiss"></button></p>
    95101</div>
    96102<?php
    97103  }
    98104
     105
     106  /**
     107   * Configure our custom db.php dropin
     108   */
     109  public static function install_custom_dropin() {
     110    if ( ! file_exists( self::$dropin_target ) ) {
     111      error_log('Copying ' . self::$dropin_file . ' -> ' . self::$dropin_target);
     112      @copy( self::$dropin_file, self::$dropin_target );
     113    }
     114  }
    99115
    100116  /**
     
    110126    // Deleting all tmp tables...
    111127    $alt_heap->delete_tmp_wp_tables();
     128
     129    if ( file_exists( self::$dropin_target ) && hash_file( 'md5', self::$dropin_target ) === hash_file( 'md5', self::$dropin_file )) {
     130      @unlink( self::$dropin_target );
     131    }
    112132  }
    113 
    114133
    115134  /**
  • wp-safe-updates/trunk/db.php

    r1451001 r1708022  
    11<?php
     2
     3function currheap() {
     4  return isset( $_COOKIE['_alt_heap'] ) && ! empty( $_COOKIE['_alt_heap'] ) ? preg_replace('/[^a-z0-9_]/', '', strtolower( $_COOKIE['_alt_heap'] ) ) : false;
     5}
     6
     7defined( 'WP_CONTENT_DIR' ) || define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/wp-content' );
     8defined( 'WP_CONTENT_URL' ) || define( 'WP_CONTENT_URL', '/wp-content' );
     9if ( false !== currheap() ) {
     10  defined( 'WP_PLUGIN_DIR' ) || define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins_tmp_' . currheap() );
     11  defined( 'WP_PLUGIN_URL' ) || define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins_tmp_' . currheap() );
     12  defined( 'PLUGINDIR' ) || define( 'PLUGINDIR', 'wp-content/plugins_tmp_' . currheap() );
     13}
    214
    315/**
  • wp-safe-updates/trunk/lib/class-alternative-heap.php

    r1507338 r1708022  
    2424      add_action('admin_footer', array( $this, 'render_alternative_heap_indicator' ) );
    2525      add_action('wp_footer', array( $this, 'render_alternative_heap_indicator' ) );
     26      add_action('login_footer', array( $this, 'render_alternative_heap_indicator' ) );
    2627    }
    2728  }
     
    5455    $alt_heap = $query_vars['alt_heap'];
    5556
    56     if( $alt_heap === 'clear' ) {
     57    if ( $alt_heap === 'clean' ) {
     58      // this means we want to clean the alt heap temp files and tables
     59      $this->delete_alt_plugins_dirs( $_COOKIE['_alt_heap'] );
     60      $this->delete_tmp_wp_tables( $_COOKIE['_alt_heap'] );
     61
     62      // and then clear the cookie
     63      $alt_heap = '';
     64    }
     65
     66    if( $alt_heap === 'clear' || $alt_heap === 'exit' ) {
    5767      // this means we want to clear the heap cookie
    5868      // equivalent to empty ?alt_heap=
    5969      $alt_heap = '';
    6070    }
     71
    6172
    6273    // not in a heap yet and GET alt_heap is defined and current user has plugin install privileges
     
    8495    $request_uri .= empty( $query_string ) ? '' : '?' . $query_string;
    8596
     97    // flush caches for this just in case
     98    wp_cache_flush();
     99
    86100    // redirect to requested page, but with alt heap this time
    87101    wp_redirect( $request_uri );
     
    102116
    103117  /**
     118   * Derives the original db prefix from an alt heap prefix
     119   */
     120  public static function derive_orig_prefix( $alt_prefix ) {
     121    $offset = strpos( $alt_prefix, 'tmp_' ) ? strpos( $alt_prefix, 'tmp_' ) : strlen( $alt_prefix );
     122    $orig_prefix = substr( $alt_prefix, 0, $offset );
     123
     124    // fall back to wp_ if all else fails
     125    if( empty( $orig_prefix ) ) {
     126      return 'wp_';
     127    }
     128    return $orig_prefix;
     129  }
     130
     131  /**
    104132   * Returns the plugins dir suffix for an alternative heap
    105133   */
     
    118146  public static function get_wp_tables() {
    119147    global $wpdb;
    120     $tables = $wpdb->get_results( $wpdb->prepare( "SHOW TABLES LIKE %s;", str_replace( '_', '\_', $wpdb->prefix) . '%' ), ARRAY_N );
     148    $orig_prefix = isset( $_COOKIE['_alt_heap'] ) ? self::derive_orig_prefix( $wpdb->prefix ) : $wpdb->prefix;
     149    $tables = $wpdb->get_results( $wpdb->prepare( "SHOW TABLES LIKE %s;", str_replace( '_', '\_', $orig_prefix ) . '%' ), ARRAY_N );
    121150    $tables = array_map( 'reset', $tables );
    122151
     
    133162  public static function get_tmp_wp_tables( $alt_heap = "" ) {
    134163    global $wpdb;
    135     $tables = $wpdb->get_results( $wpdb->prepare( "SHOW TABLES LIKE %s;", str_replace( '_', '\_', self::get_alt_prefix( $alt_heap ) ) . '%' ), ARRAY_N );
     164    // alt prefix will already be $wpdb->prefix if currently in a heap
     165    $alt_prefix = isset( $_COOKIE['_alt_heap'] ) ? $wpdb->prefix : self::get_alt_prefix( $alt_heap );
     166    $tables = $wpdb->get_results( $wpdb->prepare( "SHOW TABLES LIKE %s;", str_replace( '_', '\_', $alt_prefix ) . '%' ), ARRAY_N );
    136167    $tables = array_map( 'reset', $tables );
    137168    return $tables;
     
    257288    $dirs = array();
    258289    if( ! empty( $alt_heap ) ) {
    259       // return $alt_heap dir if defined
    260       $dirs[] = WP_PLUGIN_DIR . self::get_alt_suffix( $alt_heap );
    261 
    262       // return false if no the alt heap dir doesn't exist
     290      $suffix = self::get_alt_suffix( $alt_heap );
     291
     292      // WP_PLUGIN_DIR will be the alt heap dir if in an alt heap
     293      if ( strpos( WP_PLUGIN_DIR, $suffix ) ) {
     294        $dirs[] = WP_PLUGIN_DIR;
     295      } else {
     296        $dirs[] = WP_PLUGIN_DIR . self::get_alt_suffix( $alt_heap );
     297      }
     298
     299      // return false if the alt heap dir doesn't exist
    263300      if( ! file_exists( $dirs[0] ) ) {
    264301        return false;
     
    266303    }
    267304    else {
    268       // otherwise jsut return all alt plugin dirs
     305      // otherwise just return all alt plugin dirs
    269306      $iterator = new DirectoryIterator( dirname( WP_PLUGIN_DIR ) );
    270307      foreach( $iterator as $node ) {
     
    275312      }
    276313    }
     314
    277315    return $dirs;
    278316  }
     
    282320   */
    283321  public function delete_alt_plugins_dirs( $alt_heap = "" ) {
    284     $orig_plugins_dir = WP_PLUGIN_DIR;
     322    $suffix = self::get_alt_suffix( $alt_heap );
     323    $orig_plugins_dir = str_replace( $suffix, '', WP_PLUGIN_DIR );
    285324    $alt_dirs_to_delete = self::get_alt_plugins_dirs( $alt_heap );
    286325
     
    320359<div id="alt-heap-indicator">
    321360<?php echo wp_sprintf( __('You are currently testing updates. Any changes you make will not be saved.', 'wp-safe-updates'), currheap() ); ?>
    322  <a href="<?php echo admin_url('plugins.php?alt_heap=clear'); ?>"><?php _e('Finish tests', 'wp-safe-updates'); ?></a>
     361 <a href="<?php echo admin_url('plugins.php?alt_heap=clean'); ?>"><?php _e('Finish tests', 'wp-safe-updates'); ?></a>
    323362</div>
    324363<?php
  • wp-safe-updates/trunk/readme.md

    r1454344 r1708022  
    1 # WP Safe Updates.
     1# WP Safe Updates
    22[![Latest Stable Version](https://poser.pugx.org/anttiviljami/wp-safe-updates/v/stable)](https://packagist.org/packages/anttiviljami/wp-safe-updates) [![Total Downloads](https://poser.pugx.org/anttiviljami/wp-safe-updates/downloads)](https://packagist.org/packages/anttiviljami/wp-safe-updates) [![Latest Unstable Version](https://poser.pugx.org/anttiviljami/wp-safe-updates/v/unstable)](https://packagist.org/packages/anttiviljami/wp-safe-updates) [![License](https://poser.pugx.org/anttiviljami/wp-safe-updates/license)](https://packagist.org/packages/anttiviljami/wp-safe-updates)
    33
     
    51513. Activate the plugin
    5252
    53 ## Configuration
    54 
    55 First copy the `db.php` file from this plugin to your `wp-content` directory.
    56 
    57 Then just paste these lines to your `wp-config.php`.
    58 ```php
    59 /**
    60  * WordPress Safe Updates required configuration
    61  */
    62 function currheap() {
    63   return isset( $_COOKIE['_alt_heap'] ) && ! empty( $_COOKIE['_alt_heap'] ) ? preg_replace('/[^a-z0-9_]/', '', strtolower( $_COOKIE['_alt_heap'] ) ) : false;
    64 }
    65 defined( 'WP_CONTENT_DIR' ) || define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/wp-content' );
    66 defined( 'WP_CONTENT_URL' ) || define( 'WP_CONTENT_URL', '/wp-content' );
    67 if ( false !== currheap() ) {
    68   defined( 'WP_PLUGIN_DIR' ) || define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins_tmp_' . currheap() );
    69   defined( 'WP_PLUGIN_URL' ) || define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins_tmp_' . currheap() );
    70   defined( 'PLUGINDIR' ) || define( 'PLUGINDIR', 'wp-content/plugins_tmp_' . currheap() );
    71 }
    72 ```
    73 
  • wp-safe-updates/trunk/readme.txt

    r1507338 r1708022  
    55Requires at least: 4.5
    66Tested up to: 4.6.1
    7 Stable tag: 1.1
     7Stable tag: 1.2
    88License: GPLv3
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    2727https://github.com/anttiviljami/wp-safe-updates
    2828
    29 == Installation ==
    30 
    31 Install and activate the plugin via wp-admin.
    32 
    33 Then copy the `db.php` file from this plugin to your `wp-content` directory.
    34 
    35 Finally, paste these lines to your `wp-config.php`.
    36 
    37 `/**
    38  * WordPress Safe Updates required configuration
    39  */
    40 function currheap() {
    41   return isset( $_COOKIE['_alt_heap'] ) && ! empty( $_COOKIE['_alt_heap'] ) ? preg_replace('/[^a-z0-9_]/', '', strtolower( $_COOKIE['_alt_heap'] ) ) : false;
    42 }
    43 defined( 'WP_CONTENT_DIR' ) || define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/wp-content' );
    44 defined( 'WP_CONTENT_URL' ) || define( 'WP_CONTENT_URL', '/wp-content' );
    45 if ( false !== currheap() ) {
    46   defined( 'WP_PLUGIN_DIR' ) || define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins_tmp_' . currheap() );
    47   defined( 'WP_PLUGIN_URL' ) || define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins_tmp_' . currheap() );
    48   defined( 'PLUGINDIR' ) || define( 'PLUGINDIR', 'wp-content/plugins_tmp_' . currheap() );
    49 }`
    50 
    5129== Frequently Asked Questions ==
    5230
  • wp-safe-updates/trunk/vendor/autoload.php

    r1451001 r1708022  
    33// autoload.php @generated by Composer
    44
    5 require_once __DIR__ . '/composer' . '/autoload_real.php';
     5require_once __DIR__ . '/composer/autoload_real.php';
    66
    77return ComposerAutoloaderInit6b6b80b301d3663ac27b1b7644fe5e53::getLoader();
  • wp-safe-updates/trunk/vendor/composer/ClassLoader.php

    r1451001 r1708022  
    5454    private $useIncludePath = false;
    5555    private $classMap = array();
    56 
    5756    private $classMapAuthoritative = false;
     57    private $missingClasses = array();
     58    private $apcuPrefix;
    5859
    5960    public function getPrefixes()
     
    273274
    274275    /**
     276     * APCu prefix to use to cache found/not-found classes, if the extension is enabled.
     277     *
     278     * @param string|null $apcuPrefix
     279     */
     280    public function setApcuPrefix($apcuPrefix)
     281    {
     282        $this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null;
     283    }
     284
     285    /**
     286     * The APCu prefix in use, or null if APCu caching is not enabled.
     287     *
     288     * @return string|null
     289     */
     290    public function getApcuPrefix()
     291    {
     292        return $this->apcuPrefix;
     293    }
     294
     295    /**
    275296     * Registers this instance as an autoloader.
    276297     *
     
    314335    public function findFile($class)
    315336    {
    316         // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
    317         if ('\\' == $class[0]) {
    318             $class = substr($class, 1);
    319         }
    320 
    321337        // class map lookup
    322338        if (isset($this->classMap[$class])) {
    323339            return $this->classMap[$class];
    324340        }
    325         if ($this->classMapAuthoritative) {
     341        if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
    326342            return false;
    327343        }
     344        if (null !== $this->apcuPrefix) {
     345            $file = apcu_fetch($this->apcuPrefix.$class, $hit);
     346            if ($hit) {
     347                return $file;
     348            }
     349        }
    328350
    329351        $file = $this->findFileWithExtension($class, '.php');
    330352
    331353        // Search for Hack files if we are running on HHVM
    332         if ($file === null && defined('HHVM_VERSION')) {
     354        if (false === $file && defined('HHVM_VERSION')) {
    333355            $file = $this->findFileWithExtension($class, '.hh');
    334356        }
    335357
    336         if ($file === null) {
     358        if (null !== $this->apcuPrefix) {
     359            apcu_add($this->apcuPrefix.$class, $file);
     360        }
     361
     362        if (false === $file) {
    337363            // Remember that this class does not exist.
    338             return $this->classMap[$class] = false;
     364            $this->missingClasses[$class] = true;
    339365        }
    340366
     
    349375        $first = $class[0];
    350376        if (isset($this->prefixLengthsPsr4[$first])) {
    351             foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
    352                 if (0 === strpos($class, $prefix)) {
    353                     foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
     377            $subPath = $class;
     378            while (false !== $lastPos = strrpos($subPath, '\\')) {
     379                $subPath = substr($subPath, 0, $lastPos);
     380                $search = $subPath.'\\';
     381                if (isset($this->prefixDirsPsr4[$search])) {
     382                    foreach ($this->prefixDirsPsr4[$search] as $dir) {
     383                        $length = $this->prefixLengthsPsr4[$first][$search];
    354384                        if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
    355385                            return $file;
     
    400430            return $file;
    401431        }
     432
     433        return false;
    402434    }
    403435}
  • wp-safe-updates/trunk/vendor/composer/LICENSE

    r1451001 r1708022  
    11
    2 Copyright (c) 2016 Nils Adermann, Jordi Boggiano
     2Copyright (c) Nils Adermann, Jordi Boggiano
    33
    44Permission is hereby granted, free of charge, to any person obtaining a copy
  • wp-safe-updates/trunk/vendor/composer/autoload_real.php

    r1451001 r1708022  
    2424        spl_autoload_unregister(array('ComposerAutoloaderInit6b6b80b301d3663ac27b1b7644fe5e53', 'loadClassLoader'));
    2525
    26         $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION');
     26        $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
    2727        if ($useStaticLoader) {
    2828            require_once __DIR__ . '/autoload_static.php';
  • wp-safe-updates/trunk/wp-safe-updates.php

    r1507338 r1708022  
    44 * Plugin URI: https://github.com/anttiviljami/wp-safe-updates
    55 * Description: Test WordPress plugin updates safely before applying them on the live site.
    6  * Version: 1.1
     6 * Version: 1.2
    77 * Author: @anttiviljami
    88 * Author URI: https://github.com/anttiviljami
     
    3434  public $alt_heap;
    3535  public $update_logic;
     36
     37  public static $dropin_target = WP_CONTENT_DIR . '/db.php';
     38  public static $dropin_file = __DIR__ . '/db.php';
    3639
    3740  public static function init() {
     
    6669    }
    6770
    68     // clear all heaps on uninstall
     71    // configure custom dropin file
     72    register_activation_hook( __FILE__, array( 'Safe_Updates', 'install_custom_dropin' ) );
     73
     74    // clear all heaps on uninstall and clean up files
    6975    register_uninstall_hook( __FILE__, array( 'Safe_Updates', 'uninstall_cleanup' ) );
    7076  }
     
    9298<div class="notice notice-warning is-dismissible">
    9399  <?php $configure_action = 'https://wordpress.org/plugins/wp-safe-updates/installation/'; ?>
    94   <p><?php echo wp_sprintf( __('WP Safe Updates is not yet active. Please <a href="%s" target="_blank">configure</a> it.', 'wp-safe-updates'), $configure_action ); ?> <button type="button" class="notice-dismiss"></button></p>
     100  <p><?php echo wp_sprintf( __('WP Safe Updates is not yet active. Please copy the <pre>db.php</pre> file inside this plugin to your wp-content directory.', 'wp-safe-updates'), $configure_action ); ?> <button type="button" class="notice-dismiss"></button></p>
    95101</div>
    96102<?php
    97103  }
    98104
     105
     106  /**
     107   * Configure our custom db.php dropin
     108   */
     109  public static function install_custom_dropin() {
     110    if ( ! file_exists( self::$dropin_target ) ) {
     111      error_log('Copying ' . self::$dropin_file . ' -> ' . self::$dropin_target);
     112      @copy( self::$dropin_file, self::$dropin_target );
     113    }
     114  }
    99115
    100116  /**
     
    110126    // Deleting all tmp tables...
    111127    $alt_heap->delete_tmp_wp_tables();
     128
     129    if ( file_exists( self::$dropin_target ) && hash_file( 'md5', self::$dropin_target ) === hash_file( 'md5', self::$dropin_file )) {
     130      @unlink( self::$dropin_target );
     131    }
    112132  }
    113 
    114133
    115134  /**
Note: See TracChangeset for help on using the changeset viewer.