Skip to content

Commit

Permalink
Merge branch 'release-2.2.2-b1'
Browse files Browse the repository at this point in the history
  • Loading branch information
archetyped committed Feb 19, 2014
2 parents 3156475 + 708c683 commit c3359cb
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 48 deletions.
96 changes: 50 additions & 46 deletions controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ class SLB_Lightbox extends SLB_Base {

/* Widget properties */

/**
* IDs widgets that have been processed
* @var array
*/
var $widgets_processed = array();

/**
* Widget callback key
* @var string
Expand Down Expand Up @@ -176,7 +182,7 @@ public function _hooks_init() {
add_filter('the_content', $this->m('gallery_unwrap'), $priority + 1);

//Widgets
add_filter('sidebars_widgets', $this->m('sidebars_widgets'));
add_filter('dynamic_sidebar_params', $this->m('widget_process_setup'), 20);
}
}

Expand Down Expand Up @@ -1166,38 +1172,31 @@ function gallery_unwrap($content) {
/*-** Widgets **-*/

/**
* Reroute widget display handlers to internal method
* Reroute widget display callback to internal method
* No widget parameters are modified
*
* @param array $sidebar_widgets List of sidebars & their widgets
* @uses WP Hook `sidebars_widgets` to intercept widget list
* @global $wp_registered_widgets to reroute display callback
* @return array Sidebars and widgets (unmodified)
* @param array $params Widget parameters
* @global $wp_registered_widgets to update display callback
* @return array Updated parameters
*/
function sidebars_widgets($sidebars_widgets) {
function widget_process_setup($params) {
global $wp_registered_widgets;
static $widgets_processed = false;
if ( !$this->is_enabled() || $widgets_processed || empty($wp_registered_widgets) ) {
return $sidebars_widgets;
$p =& $params[0];
$wid = $p['widget_id'];
//Validate request
if ( !$this->is_enabled() || empty($wp_registered_widgets) || array_key_exists($wid, $this->widgets_processed) ) {
return $params;
}
$widgets_processed = true;
//Fetch active widgets from all sidebars
foreach ( $sidebars_widgets as $sb => $ws ) {
//Skip inactive widgets and empty sidebars
if ( 'wp_inactive_widgets' == $sb || empty($ws) || !is_array($ws) )
continue;
foreach ( $ws as $w ) {
if ( isset($wp_registered_widgets[$w]) && isset($wp_registered_widgets[$w][$this->widget_callback]) ) {
$wref =& $wp_registered_widgets[$w];
//Backup original callback
$wref[$this->widget_callback_orig] = $wref[$this->widget_callback];
//Reroute callback
$wref[$this->widget_callback] = $this->m('widget_callback');
unset($wref);
}
}
}

return $sidebars_widgets;
$this->widgets_processed[$wid] = true;
//Update callback
$wref =& $wp_registered_widgets[$wid];
// Backup original callback
$wref[$this->widget_callback_orig] = $wref[$this->widget_callback];
// Reroute callback
$wref[$this->widget_callback] = $this->m('widget_callback');
unset($wref);

return $params;
}

/**
Expand All @@ -1221,28 +1220,33 @@ function widget_callback($args, $widget_args = 1) {
if ( !isset($w[$this->widget_callback_orig]) || !($cb = $w[$this->widget_callback_orig]) || !is_callable($cb) )
return false;
$params = func_get_args();
//Start processing widget output
$this->widget_processing = $wid;
//Set Group ID filter
$filter = (object) array (
'hook' => 'get_group_id',
'cb' => $this->m('widget_group_id'),
);
$this->util->add_filter($filter->hook, $filter->cb);
//Start output buffer
ob_start();
//Call original callback
call_user_func_array($cb, $params);
//Unset Group ID filter
//Flush output buffer
$out = ob_get_clean();
// Buffer output for further processing if enabled
if ( $this->options->get_bool('enabled_widget') ) {
$out = $this->activate_links($out);
//Set Group ID filter
$filter = (object) array (
'hook' => 'get_group_id',
'cb' => $this->m('widget_group_id'),
);
$this->util->add_filter($filter->hook, $filter->cb);
//Start output buffer
ob_start();
//Call original callback
call_user_func_array($cb, $params);
//Flush output buffer
$out = $this->activate_links(ob_get_clean());
//Unset Group ID filter
$this->util->remove_filter($filter->hook, $filter->cb);
//Output widget
echo $out;
}
// Simply execute widget's original callback if processing disabled
else {
call_user_func_array($cb, $params);
}
$this->util->remove_filter($filter->hook, $filter->cb);
//Stop processing widget
$this->widget_processing = false;
//Output widget
echo $out;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion main.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Simple Lightbox
Plugin URI: http://archetyped.com/tools/simple-lightbox/
Description: The highly customizable lightbox for WordPress
Version: 2.2.1
Version: 2.2.2-b1 (BETA)
Author: Archetyped
Author URI: http://archetyped.com
Support URI: https://github.com/archetyped/simple-lightbox/wiki/Reporting-Issues
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-lightbox",
"version": "2.2.1",
"version": "2.2.2-b1",
"title": "Simple Lightbox",
"description": "The highly-customizable lightbox for WordPress",
"author": "Sol Marchessault <[email protected]>",
Expand Down
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ Get more information on [Simple Lightbox's official page](http://archetyped.com/
3. Dark Theme

== Changelog ==
= 2.2.2-b1 =
* Optimize: Widget processing

= 2.2.1 =
* Fix: Enable/Disable lightbox on certain requests (Danny the Enabler)
* Fix: Widget links grouped with post links (Rafa's Widgetarian Adventure)
Expand Down

0 comments on commit c3359cb

Please sign in to comment.