Commit 2db3304d authored by lucha's avatar lucha

[auto] plugin: widget-logic 5.9.0

parent 26cdb06b
......@@ -3,8 +3,8 @@ Contributors: wpchefgadget, alanft
Donate link: http://www.justgiving.com/widgetlogic_cancerresearchuk
Tags: widget, admin, conditional tags, filter, context
Requires at least: 3.0
Tested up to: 4.8
Stable tag: 5.8.2
Tested up to: 4.9
Stable tag: 5.9.0
License: GPLv2 or later
Widget Logic lets you control on which pages widgets appear using WP's conditional tags. It also adds a 'widget_content' filter.
......@@ -119,6 +119,10 @@ Tighten up your definitions with PHPs 'logical AND' &&, for example:
== Changelog ==
= 5.9.0 =
wp_reset_query works better under certain conditions.
= 5.8.2 =
The code has been adapted to work on the servers with restricted <?=
......
......@@ -3,7 +3,7 @@
Plugin Name: Widget Logic
Plugin URI: http://wordpress.org/extend/plugins/widget-logic/
Description: Control widgets with WP's conditional tags is_home etc
Version: 5.8.2
Version: 5.9.0
Author: wpchefgadget, alanft
Text Domain: widget-logic
......@@ -36,13 +36,13 @@ add_action( 'init', 'widget_logic_init' );
function widget_logic_init()
{
load_plugin_textdomain( 'widget-logic', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
/*
if ( is_admin() )
{
if ( get_option('widget_logic_version') != WIDGET_LOGIC_VERSION )
widget_logic_activate();
global $wp_version;
if ( version_compare( $wp_version, '4.2', '>=' ) && !file_exists(WP_PLUGIN_DIR.'/limit-login-attempts-reloaded') && current_user_can('install_plugins') )
{
......@@ -67,18 +67,18 @@ if (is_admin())
{
add_filter( 'in_widget_form', 'widget_logic_in_widget_form', 10, 3 );
add_filter( 'widget_update_callback', 'widget_logic_update_callback', 10, 4);
add_action( 'sidebar_admin_setup', 'widget_logic_expand_control');
// before any HTML output save widget changes and add controls to each widget on the widget admin page
add_action( 'sidebar_admin_page', 'widget_logic_options_control');
// add Widget Logic specific options on the widget admin page
add_filter( 'plugin_action_links', 'wl_charity', 10, 2);// add my justgiving page link to the plugin admin page
add_action( 'widgets_init', 'widget_logic_add_controls', 999 );
}
else
{
$loadpoint = (string)@$wl_options['widget_logic-options-load_point'];
$loadpoint = isset($wl_options['widget_logic-options-load_point']) ? (string)@$wl_options['widget_logic-options-load_point'] : '';
if ( 'plugins_loaded' == $loadpoint )
widget_logic_sidebars_widgets_filter_add();
else
......@@ -99,7 +99,7 @@ function widget_logic_in_customizer()
{
global $wl_in_customizer;
$wl_in_customizer = true;
//add_filter( 'widget_display_callback', 'widget_logic_customizer_display_callback', 10, 3 );
add_action( 'dynamic_sidebar', 'widget_logic_customizer_dynamic_sidebar_callback' );
}
......@@ -120,7 +120,7 @@ function widget_logic_update_callback( $instance, $new_instance, $old_instance,
{
if ( isset( $new_instance['widget_logic'] ) )
$instance['widget_logic'] = $new_instance['widget_logic'];
return $instance;
}
......@@ -168,7 +168,7 @@ function widget_logic_expand_control()
wp_redirect( admin_url('widgets.php') );
exit;
}
// UPDATE OTHER WIDGET LOGIC OPTIONS
// must update this to use http://codex.wordpress.org/Settings_API
if ( isset($_POST['widget_logic-options-submit']) )
......@@ -261,24 +261,24 @@ function widget_logic_options_control()
function widget_logic_add_controls()
{
global $wp_registered_widget_controls, $wp_registered_widgets, $wp_registered_widget_updates;
foreach ( $wp_registered_widgets as $id => $widget )
{
if ( preg_match( '/^(.+)-(\d+)$/', $id) )
continue;
if ( !isset( $wp_registered_widget_controls[ $id ] ) )
{
wp_register_widget_control( $id, $id, 'widget_logic_extra_control', array(), $id, null );
continue;
}
if ( @$wp_registered_widget_controls[ $id ]['callback'] != 'widget_logic_extra_control' )
{
$wp_registered_widget_controls[$id]['params'][] = $id;
$wp_registered_widget_controls[$id]['params'][] = @$wp_registered_widget_controls[$id]['callback'];
$wp_registered_widget_controls[$id]['callback'] = 'widget_logic_extra_control';
$wp_registered_widget_updates[$id]['params'][] = $id;
$wp_registered_widget_updates[$id]['params'][] = @$wp_registered_widget_updates[$id]['callback'];
$wp_registered_widget_updates[$id]['callback'] = 'widget_logic_extra_control';
......@@ -306,13 +306,13 @@ function widget_logic_extra_control()
{
global $wp_customize;
$args = func_get_args();
$callback = array_pop( $args );
$widget_id = array_pop( $args );
if ( is_callable($callback) )
call_user_func_array( $callback, $args );
if ( isset( $_POST["widget-$widget_id"]['widget_logic'] ) )
{
$logic = stripslashes( $_POST["widget-$widget_id"]['widget_logic'] );
......@@ -320,7 +320,7 @@ function widget_logic_extra_control()
}
else
$logic = widget_logic_by_id( $widget_id );
$input_id = "widget-$widget_id-widget_logic";
$input_name = "widget-{$widget_id}[widget_logic]";
?>
......@@ -330,7 +330,8 @@ function widget_logic_extra_control()
</label>
<?php if ( !empty($wp_customize) && $wp_customize->is_preview() ): ?>
<textarea class="widefat" id="<?php echo $input_id ?>" readonly><?php echo esc_textarea( $logic ) ?></textarea>
<p class="description"><?php printf( esc_html__('This is a "wp register sidebar widget" and is different from regular widgets. Hence it can only be edited from the %s page.', 'widget-logic'), sprintf( '<a href="%s" target="_blank">%s</a>', esc_attr(admin_url('widgets.php')), __('widgets') ) ) ?></p>
<br>
<span class="description"><?php printf( esc_html__('This is a "wp register sidebar widget" and is different from regular widgets. Hence it can only be edited from the %s page.', 'widget-logic'), sprintf( '<a href="%s" target="_blank">%s</a>', esc_attr(admin_url('widgets.php')), __('widgets') ) ) ?></span>
<?php else: ?>
<textarea class="widefat" name="<?php echo $input_name ?>" id="<?php echo $input_id ?>"><?php echo esc_textarea( $logic ) ?></textarea>
<?php endif ?>
......@@ -353,52 +354,52 @@ function wl_charity($links, $file)
function widget_logic_by_id( $widget_id )
{
global $wl_options;
if ( preg_match( '/^(.+)-(\d+)$/', $widget_id, $m ) )
{
$widget_class = $m[1];
$widget_i = $m[2];
$info = get_option( 'widget_'.$widget_class );
if ( empty( $info[ $widget_i ] ) )
return '';
$info = $info[ $widget_i ];
}
else
$info = (array)get_option( 'widget_'.$widget_id, array() );
if ( isset( $info['widget_logic'] ) )
$logic = $info['widget_logic'];
elseif ( isset( $wl_options[ $widget_id ] ) )
{
$logic = stripslashes( $wl_options[ $widget_id ] );
widget_logic_save( $widget_id, $logic );
unset( $wl_options[ $widget_id ] );
update_option( 'widget_logic', $wl_options );
}
else
$logic = '';
return $logic;
}
function widget_logic_save( $widget_id, $logic )
{
global $wl_options;
if ( preg_match( '/^(.+)-(\d+)$/', $widget_id, $m ) )
{
$widget_class = $m[1];
$widget_i = $m[2];
$info = get_option( 'widget_'.$widget_class );
if ( !is_array( $info[ $widget_i ] ) )
$info[ $widget_i ] = array();
$info[ $widget_i ]['widget_logic'] = $logic;
update_option( 'widget_'.$widget_class, $info );
}
......@@ -413,18 +414,15 @@ function widget_logic_save( $widget_id, $logic )
// CALLED ON 'sidebars_widgets' FILTER
function widget_logic_filter_sidebars_widgets( $sidebars_widgets )
{
global $wp_reset_query_is_done, $wl_options, $wl_in_customizer;
global $wl_options, $wl_in_customizer;
if ( $wl_in_customizer )
return $sidebars_widgets;
// reset any database queries done now that we're about to make decisions based on the context given in the WP query for the page
if ( !empty( $wl_options['widget_logic-options-wp_reset_query'] ) && empty( $wp_reset_query_is_done ) )
{
if ( !empty( $wl_options['widget_logic-options-wp_reset_query'] ) )
wp_reset_query();
$wp_reset_query_is_done=true;
}
// loop through every widget in every sidebar (barring 'wp_inactive_widgets') checking WL for each one
foreach($sidebars_widgets as $widget_area => $widget_list)
{
......@@ -434,7 +432,7 @@ function widget_logic_filter_sidebars_widgets( $sidebars_widgets )
foreach($widget_list as $pos => $widget_id)
{
$logic = widget_logic_by_id( $widget_id );
if ( !widget_logic_check_logic( $logic ) )
unset($sidebars_widgets[$widget_area][$pos]);
}
......@@ -447,29 +445,29 @@ function widget_logic_check_logic( $logic )
{
$logic = @trim( (string)$logic );
$logic = apply_filters( "widget_logic_eval_override", $logic );
if ( is_bool( $logic ) )
return $logic;
if ( $logic === '' )
return true;
if ( stristr( $logic, "return" ) === false )
$logic = "return ( $logic );";
set_error_handler( 'widget_logic_error_handler' );
try {
$show_widget = eval($logic);
}
catch ( Error $e ) {
trigger_error( $e->getMessage(), E_USER_WARNING );
$show_widget = false;
}
restore_error_handler();
return $show_widget;
}
......@@ -477,10 +475,10 @@ function widget_logic_error_handler( $errno , $errstr )
{
global $wl_options;
$show_errors = !empty($wl_options['widget_logic-options-show_errors']) && current_user_can('manage_options');
if ( $show_errors )
echo 'Invalid Widget Logic: '.$errstr;
return true;
}
......@@ -493,16 +491,16 @@ function widget_logic_customizer_display( $widget_id )
{
if ( !preg_match( '/^(.+)-(\d+)$/', $widget_id) )
return;
$logic = widget_logic_by_id( $widget_id );
global $wl_options;
$show_errors = !empty($wl_options['widget_logic-options-show_errors']) && current_user_can('manage_options');
ob_start();
$show_widget = widget_logic_check_logic( $logic );
$error = ob_get_clean();
if ( $show_errors && $error ) :
?><script>jQuery(function($){$('#<?php echo $widget_id?>').append( $('<p class="widget-logic-error">').html(<?php echo json_encode($error)?>) );})</script><?php
endif;
......@@ -524,7 +522,7 @@ function widget_logic_widget_display_callback($params)
// the redirection comes here
function widget_logic_redirected_callback()
{ global $wp_registered_widgets, $wp_reset_query_is_done;
{ global $wp_registered_widgets;
// replace the original callback data
$params=func_get_args();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment