Skip to content

Commit

Permalink
Remaming :allthethings 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Welcher committed Nov 23, 2016
1 parent 88a5732 commit 019aadc
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 41 deletions.
1 change: 1 addition & 0 deletions assets/css/bypass-transients.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions assets/css/bypass-transients.src.css
@@ -0,0 +1,5 @@
#wpadminbar #wp-admin-bar-bypass-transients.active {
background: green; }

#wpadminbar #wp-admin-bar-bypass-transients.found {
background: red; }
@@ -1,5 +1,5 @@
#wpadminbar {
#wp-admin-bar-suspend-transients {
#wp-admin-bar-bypass-transients {
&.active {
background: green;
}
Expand Down
1 change: 0 additions & 1 deletion assets/css/suspend-transients.min.css

This file was deleted.

5 changes: 0 additions & 5 deletions assets/css/suspend-transients.src.css

This file was deleted.

18 changes: 9 additions & 9 deletions bypass-transients.php
@@ -1,6 +1,6 @@
<?php
/**
* Plugin Name: Suspend Transients
* Plugin Name: Bypass Transients
* Plugin URI:
* Description: Bypass transients for development.
* Version: 1.0.0
Expand All @@ -23,23 +23,23 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

namespace suspendTransients;
namespace bypassTransients;

require_once 'includes/class-suspend-transients.php';
require_once 'includes/class-suspend-transients-database.php';
require_once 'includes/class-bypass-transients.php';
require_once 'includes/class-bypass-transients-database.php';



// Get the instance we need.

$suspend_transients = ( wp_using_ext_object_cache() ) ? new Suspend_Transients() : new Suspend_Transients_Database();
$suspend_transients->init();
$bypass_transients = ( wp_using_ext_object_cache() ) ? new Bypass_Transients() : new Bypass_Transients_Database();
$bypass_transients->init();

register_activation_hook( __FILE__, array( $suspend_transients, 'on_activate' ) );
register_activation_hook( __FILE__, array( $bypass_transients, 'on_activate' ) );

function add_to_debug_bar( $panels ) {
require_once 'includes/class-suspend-transients-debug-bar.php';
$panels[] = new \Suspend_Transients_Debug_Bar();
require_once 'includes/class-bypass-transients-debug-bar.php';
$panels[] = new \Bypass_Transients_Debug_Bar();
return $panels;
}
add_filter( 'debug_bar_panels', __NAMESPACE__ .'\\add_to_debug_bar' );
Expand Down
@@ -1,8 +1,8 @@
<?php

namespace suspendTransients;
namespace bypassTransients;

class Suspend_Transients_Database extends Suspend_Transients {
class Bypass_Transients_Database extends Bypass_Transients {

public function on_activate() {
parent::on_activate();
Expand Down Expand Up @@ -57,7 +57,7 @@ public function inject_admin_bar_button_scan() {
$wp_admin_bar->add_menu(
array(
'id' => 'scan-transients',
'parent' => 'suspend-transients',
'parent' => 'bypass-transients',
'title' => 'Scan Transients',
'href' => '?scan-transients=true&wp_nonce=' . wp_create_nonce( 'scan_transients' ),
)
Expand Down
@@ -1,5 +1,5 @@
<?php
class Suspend_Transients_Debug_Bar extends \Debug_Bar_Panel {
class Bypass_Transients_Debug_Bar extends \Debug_Bar_Panel {

public function init() {
$this->title( __( 'Bypass Transients' ) );
Expand All @@ -10,7 +10,7 @@ public function init() {
*/
public function render() {
?>
<div id="suspend-transient-information">
<div id="bypass-transient-information">
<?php
$this->output_transients( 'suspended' );
$this->output_transients( 'found' );
Expand All @@ -21,20 +21,20 @@ public function render() {
}

function output_transients( $type = 'known' ) {
global $suspend_transients;
global $bypass_transients;
switch ( $type ) {
case 'suspended':
$transients = $suspend_transients->get_suspended_transients();
$transients = $bypass_transients->get_bypassed_transients();
$number_of_transients = count( $transients );
$message = sprintf( _n( 'There was %s transient bypassed for this page load.', 'There were %s transients bypassed for this page load.', $number_of_transients ), $number_of_transients );
break;
case 'found':
$transients = $suspend_transients->get_found_transients();
$transients = $bypass_transients->get_found_transients();
$number_of_transients = count( $transients );
$message = sprintf( _n( 'There was %s transient found for this page load.', 'There were %s transients found for this page load.', $number_of_transients ), $number_of_transients );
break;
case 'known':
$transients = $suspend_transients->get_known_transients();
$transients = $bypass_transients->get_known_transients();
$number_of_transients = count( $transients );
$message = sprintf( _n( 'There is %s known transient for the active theme/plugins.', 'There are %s known transients for the active theme/plugins.', $number_of_transients ), $number_of_transients );
break;
Expand Down
@@ -1,12 +1,12 @@
<?php
namespace suspendTransients;
namespace bypassTransients;

class Suspend_Transients {
class Bypass_Transients {

protected $_known_transients = array();
protected $_found_transients = array();
protected $_option_key = 'st_known_transients';
protected $_transients_suspended = array();
protected $_transients_bypassed = array();

protected $_is_bypassing = false;

Expand All @@ -33,7 +33,8 @@ public function init() {
}

function add_admin_bar_css() {
wp_enqueue_style( 'suspend-transients', plugins_url( 'assets/css/suspend-transients.src.css', dirname( __FILE__ ) ) );
$min = ( defined( 'SCRIPT_DEBUG' ) & true === SCRIPT_DEBUG ) ? 'src' : 'min';
wp_enqueue_style( 'bypass-transients', plugins_url( 'assets/css/bypass-transients.' . $min . '.css', dirname( __FILE__ ) ) );
}


Expand All @@ -45,13 +46,13 @@ public function filter_all_known_transients() {
$this->_known_transients = $this->get_known_transients();

foreach ( $this->get_known_transients() as $transient ) {
add_filter( 'transient_' . $transient , [ $this, 'count_and_return_false' ], 10, 2 );
add_filter( 'transient_' . $transient , [ $this, 'count_and_return_false' ], 10, 2 );
}
}


public function count_and_return_false( $value, $transient ) {
$this->_transients_suspended[] = $transient;
$this->_transients_bypassed[] = $transient;
return false;
}

Expand Down Expand Up @@ -95,8 +96,8 @@ public function get_known_transients() {
* Helper to retrieve suspended transients.
* @return array
*/
public function get_suspended_transients() {
return $this->_transients_suspended;
public function get_bypassed_transients() {
return $this->_transients_bypassed;
}

/**
Expand Down Expand Up @@ -146,12 +147,12 @@ public function inject_admin_bar_button() {
$classes .= ' found';
}

$title = ( $this->_is_bypassing ) ? 'Activate Transients' : 'Bypass Transients';
$title = ( $this->_is_bypassing ) ? 'Re-activate Transients' : 'Bypass Transients';
$href = ( $this->_is_bypassing ) ? '/' :'?bypass-transients=true&wp_nonce=' . wp_create_nonce( 'bypass_transients' );

$wp_admin_bar->add_menu(
array(
'id' => 'suspend-transients',
'id' => 'bypass-transients',
'parent' => 'top-secondary',
'title' => $title,
'href' => $href,
Expand All @@ -164,12 +165,12 @@ public function inject_admin_bar_button() {
$wp_admin_bar->add_menu(
array(
'id' => 'bypassed-transients',
'parent' => 'suspend-transients',
'title' => 'Bypassed Transients: ' . count( $this->_transients_suspended ),
'parent' => 'bypass-transients',
'title' => 'Bypassed Transients: ' . count( $this->_transients_bypassed ),
)
);

foreach ( $this->_transients_suspended as $key => $transient ) {
foreach ( $this->_transients_bypassed as $key => $transient ) {
$wp_admin_bar->add_menu(
array(
'id' => $key . '_' . $transient,
Expand All @@ -184,7 +185,7 @@ public function inject_admin_bar_button() {
$wp_admin_bar->add_menu(
array(
'id' => 'known-transients',
'parent' => 'suspend-transients',
'parent' => 'bypass-transients',
'title' => 'Known Transients: ' . count( $this->get_known_transients() ),
)
);
Expand All @@ -193,7 +194,7 @@ public function inject_admin_bar_button() {
$wp_admin_bar->add_menu(
array(
'id' => 'found-transients',
'parent' => 'suspend-transients',
'parent' => 'bypass-transients',
'title' => 'Found Transients: ' . count( $this->get_found_transients() ),
)
);
Expand All @@ -219,7 +220,7 @@ public function inject_admin_bar_button_scan() {
$wp_admin_bar->add_menu(
array(
'id' => 'flush-transients',
'parent' => 'suspend-transients',
'parent' => 'bypass-transients',
'title' => 'Flush Transients',
'href' => '?flush-transients=true&wp_nonce=' . wp_create_nonce( 'flush_transients' ),
)
Expand Down
73 changes: 73 additions & 0 deletions readme.txt
@@ -0,0 +1,73 @@
=== Bypass Transients ===
Contributors: welcher
Donate link: http://www.ryanwelcher.com/donate/
Tags: transients, developer, debug bar, admin bar
Requires at least: 3.0
Tested up to: 4.6.1
Stable tag: trunk
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Bypass any get_transient() calls on a per page basis by clicking the link in the Admin Bar.

== Description ==

We all know that caching is FTW. But, caching can be a nuisance when trying to develop or debug. That's where this plugin comes in.
You can bypass any get_transient() calls on a per page basis by clicking the link in the Admin Bar.

Features:

1. Bypass Transients with a single click
2. Supports Transients saved to the database
3. Object Cache support - currently only tested with memecached
4. Will automatically detected any new transients set.
5. Debug Bar integration to provide details such as lists of known, found and bypassed transients.


Usage:

Install and activate the plugin as normal. Suspend transients will loading the appropriate class based on the results `wp_using_ext_object_cache()`. Anytime a transient set, the plugin will detect it and add it to the
known list.

Standard Transients ( saved to the database )

When activated, the plugin will retrieve any existing transients from the database and add them to the known transients list.

The Admin Bar will have two new buttons:

1. Bypass Transients: bypasses known transients
2. Scan Transients: reloads the transients from the database.

Object Cached Transients ( i.e memcached )
These transients are not stored in the database so the best way to get them is to use the Flush Transients button and reload the page to utilize the transient detection feature of the plugin.
It may require two page loads; One to detect and add the transient, and then a second to actually bypass it.

Admin Bar buttons:

1. Bypass Transients: bypasses known transients
2. Flush Transients: Calls wp_object_cache_flush() to invalidate the caches.

**Disclaimer**
This plugin should NOT be run in a production environment. It is meant for local and MAYBE staging development. By it's very nature this will slow
your site down.

== Installation ==

Install this plugin as described in the [Codex](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins)

== Frequently Asked Questions ==

= Should I run this on a production server? =

This will bypass your caching and slow down your site. If that is what you want, then yes run it on a production server :)

= Does this delete transients? =

No standard transients are not deleted. In an object cached environment, the caches are flushed so in that sense they are deleted.


== Changelog ==

= 1.0.0 =
* Inital Release

0 comments on commit 019aadc

Please sign in to comment.