Skip to content
Snippets Groups Projects
Commit 9bf2bbf2 authored by lucha's avatar lucha
Browse files

[auto] plugin: widget-logic 5.7.2

parent c9a97831
Branches
No related tags found
No related merge requests found
File added
msgid ""
msgstr ""
"Project-Id-Version: Widget Logic v0.57\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: 2013-12-18 08:33+0100\n"
"Last-Translator: HunStArt <szemcse@freemail.hu>\n"
"Language-Team: HunStArt <szemcse@freemail.hu>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Poedit 1.6.3\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;"
"_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2\n"
"X-Poedit-Basepath: ../\n"
"X-Textdomain-Support: yes\n"
"Language: hu_HU\n"
"X-Poedit-SearchPath-0: .\n"
# @ widget-logic
#. translators: plugin header field 'Name'
#: widget_logic.php:0
msgid "Widget Logic"
msgstr "Widget Logika"
# @ widget-logic
#. translators: plugin header field 'PluginURI'
#: widget_logic.php:0
msgid "http://wordpress.org/extend/plugins/widget-logic/"
msgstr "http://wordpress.org/extend/plugins/widget-logic/"
# @ widget-logic
#. translators: plugin header field 'Description'
#: widget_logic.php:0
msgid "Control widgets with WP's conditional tags is_home etc"
msgstr "Vezérlő widget WP feltételes címkékel pl: is_home stb."
# @ widget-logic
#. translators: plugin header field 'Author'
#: widget_logic.php:0
msgid "Alan Trewartha"
msgstr "Alan Trewartha"
# @ widget-logic
#. translators: plugin header field 'AuthorURI'
#: widget_logic.php:0
msgid "http://freakytrigger.co.uk/author/alan/"
msgstr "http://freakytrigger.co.uk/author/alan/"
# @ widget-logic
#. translators: plugin header field 'Version'
#: widget_logic.php:0
msgid "0.57"
msgstr "0.57"
# @ widget-logic
#: widget_logic.php:18
msgid "when plugin starts (default)"
msgstr "amikor a bővítmény indul (alapértelmezett)"
# @ widget-logic
#: widget_logic.php:19
msgid "after theme loads"
msgstr "sablon betöltése után"
# @ widget-logic
#: widget_logic.php:20
msgid "when all PHP loaded"
msgstr "amikor minden PHP betöltődött"
# @ widget-logic
#: widget_logic.php:21
msgid "during page header"
msgstr "fejléc közben"
# @ widget-logic
#: widget_logic.php:96
msgid "Success! Options file imported"
msgstr "A beállításokat tartalmazó fájl importálása sikeresen befejeződött"
# @ widget-logic
#: widget_logic.php:99
msgid "Invalid options file"
msgstr "Érvénytelen fájl beállítások"
# @ widget-logic
#: widget_logic.php:104
msgid "No options file provided"
msgstr "Beállítások fájl nincs kiválasztva"
# @ widget-logic
#: widget_logic.php:173
msgid "Widget Logic options"
msgstr "Widget Logika Beállításai"
# @ widget-logic
#: widget_logic.php:176
msgid ""
"Adds a new WP filter you can use in your own code. Not needed for main "
"Widget Logic functionality."
msgstr ""
"Hozzáad egy új WP szűrőt saját kód segítségével. Nem szükséges főbb Widget "
"Logic funkcionalitás."
# @ widget-logic
#: widget_logic.php:178
msgid "Add 'widget_content' filter"
msgstr "'Widget_content' szűrő hozzáadása"
# @ widget-logic
#: widget_logic.php:181
msgid "Resets a theme's custom queries before your Widget Logic is checked"
msgstr ""
"Visszaállítja a sablon szokás lekérdezéseit, mielőtt a Widget Logic meg van "
"jelölve"
# @ widget-logic
#: widget_logic.php:183
msgid "Use 'wp_reset_query' fix"
msgstr "Használja a 'Wp_reset_query' megerősítést"
# @ widget-logic
#: widget_logic.php:186
msgid ""
"Delays widget logic code being evaluated til various points in the WP "
"loading process"
msgstr ""
"Widget logika kód értékelt késleltetései, ami a WP különböző pontjain "
"történő betöltési folyamat eléréséhez szükségesek"
# @ widget-logic
#: widget_logic.php:186
msgid "Load logic"
msgstr "Logika betöltése"
# @ widget-logic
#: widget_logic.php:199
msgid "Save WL options"
msgstr "WL beállításainak mentése"
# @ widget-logic
#: widget_logic.php:203
msgid "Save all WL options to a plain text config file"
msgstr "Menti az összes WL beállítást sima szöveges konfigurációs fájlba"
# @ widget-logic
#: widget_logic.php:203
msgid "Export options"
msgstr "Beállítások exportállása"
# @ widget-logic
#: widget_logic.php:204
msgid "Import options"
msgstr "Beállítások importállása"
# @ widget-logic
#: widget_logic.php:204
msgid "Load all WL options from a plain text config file"
msgstr "Betölti az összes WL beállítást sima szöveges konfigurációs fájlból"
# @ widget-logic
#: widget_logic.php:205
msgid "Select file for importing"
msgstr "Fájl kiválasztása importállásra"
# @ widget-logic
#: widget_logic.php:241
msgid "Widget logic:"
msgstr "Widget logika:"
File added
# Copyright (C) 2012
# This file is distributed under the same license as the package.
msgid ""
msgstr ""
"Project-Id-Version: Widget Logic\n"
"Report-Msgid-Bugs-To: http://wordpress.org/tag/wp\n"
"POT-Creation-Date: 2012-12-17 22:12:06+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"PO-Revision-Date: 2014-05-05 11:55+0200\n"
"Last-Translator: Roman Sulym <sulym.roman@gmail.com>\n"
"Language-Team: webrain <info@webrain.com.ua>\n"
"Language: uk\n"
"X-Generator: Poedit 1.6.3\n"
"X-Poedit-SourceCharset: UTF-8\n"
#: widget_logic.php:5
msgid "Control widgets with WP's conditional tags is_home etc"
msgstr ""
"Керування відображенням віджетів за допомогою стандартних WP теґів на кшталт "
"is_home()"
#: widget_logic.php:18
msgid "when plugin starts (default)"
msgstr "під час ініціалізації плаґіна (за замовчуванням)"
#: widget_logic.php:19
msgid "after theme loads"
msgstr "після завантаження теми"
#: widget_logic.php:20
msgid "when all PHP loaded"
msgstr "після завантаження всіх PHP файлів"
#: widget_logic.php:21
msgid "during page header"
msgstr "у заголовку сторінки"
#: widget_logic.php:96
msgid "Success! Options file imported"
msgstr "Файл налаштувань імпортовано успішно!"
#: widget_logic.php:99
msgid "Invalid options file"
msgstr "Невірний формат файлу налаштувань"
#: widget_logic.php:104
msgid "No options file provided"
msgstr "Не вибрано файл налаштувань"
#: widget_logic.php:173
msgid "Widget Logic options"
msgstr "Налаштування правил логіки"
#: widget_logic.php:176
msgid ""
"Adds a new WP filter you can use in your own code. Not needed for main "
"Widget Logic functionality."
msgstr ""
"Додати новий фільтр, який ви зможете використовувати у своєму коді. Не "
"потрібно для базової функціональності плаґіна."
#: widget_logic.php:178
msgid "Add 'widget_content' filter"
msgstr "Додати фільтр 'widget_content'"
#: widget_logic.php:181
msgid "Resets a theme's custom queries before your Widget Logic is checked"
msgstr "Скинути всі користувацькі запити перед перевіркою правил логіки"
#: widget_logic.php:183
msgid "Use 'wp_reset_query' fix"
msgstr "Використовувати функцію 'wp_reset_query'"
#: widget_logic.php:186
msgid ""
"Delays widget logic code being evaluated til various points in the WP "
"loading process"
msgstr ""
"Призупинити виконання коду плаґіна до певного моменту процесу завантаження WP"
#: widget_logic.php:186
msgid "Load logic"
msgstr "Завантажувати правила логіки"
#: widget_logic.php:199
msgid "Save WL options"
msgstr "Зберегти налаштування"
#: widget_logic.php:203
msgid "Save all WL options to a plain text config file"
msgstr "Зберегти всі налаштування плаґіна у текстовому файлі"
#: widget_logic.php:203
msgid "Export options"
msgstr "Експортувати налаштування"
#: widget_logic.php:204
msgid "Import options"
msgstr "Імпортувати налаштування"
#: widget_logic.php:204
msgid "Load all WL options from a plain text config file"
msgstr "Завантажити всі налаштування плаґіна з текстового файлу"
#: widget_logic.php:205
msgid "Select file for importing"
msgstr "Вибрати файл для імпорту"
# Copyright (C) 2012
# Copyright (C) 2014
# This file is distributed under the same license as the package.
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: http://wordpress.org/tag/wp\n"
"POT-Creation-Date: 2012-12-17 22:12:06+00:00\n"
"Report-Msgid-Bugs-To: http://wordpress.org/tag/widget-logic\n"
"POT-Creation-Date: 2014-07-27 16:43:46+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"PO-Revision-Date: 2012-MO-DA HO:MI+ZONE\n"
"PO-Revision-Date: 2014-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
#: widget_logic.php:5
msgid "Control widgets with WP's conditional tags is_home etc"
msgstr ""
#: widget_logic.php:18
msgid "when plugin starts (default)"
msgid "when plugin starts"
msgstr ""
#: widget_logic.php:19
......@@ -29,73 +25,90 @@ msgid "when all PHP loaded"
msgstr ""
#: widget_logic.php:21
msgid "after query variables set (default)"
msgstr ""
#: widget_logic.php:22
msgid "during page header"
msgstr ""
#: widget_logic.php:96
#: widget_logic.php:97
msgid "Success! Options file imported"
msgstr ""
#: widget_logic.php:99
#: widget_logic.php:100
msgid "Invalid options file"
msgstr ""
#: widget_logic.php:104
#: widget_logic.php:105
msgid "No options file provided"
msgstr ""
#: widget_logic.php:173
#: widget_logic.php:175
msgid "Widget Logic options"
msgstr ""
#: widget_logic.php:176
#: widget_logic.php:178
msgid ""
"Adds a new WP filter you can use in your own code. Not needed for main "
"Widget Logic functionality."
msgstr ""
#: widget_logic.php:178
#: widget_logic.php:180
msgid "Add 'widget_content' filter"
msgstr ""
#: widget_logic.php:181
#: widget_logic.php:183
msgid "Resets a theme's custom queries before your Widget Logic is checked"
msgstr ""
#: widget_logic.php:183
#: widget_logic.php:185
msgid "Use 'wp_reset_query' fix"
msgstr ""
#: widget_logic.php:186
#: widget_logic.php:188
msgid ""
"Re-evaluates widget logic every time the sidebars_widgets filter is called"
msgstr ""
#: widget_logic.php:190
msgid "Don't cache widget logic results"
msgstr ""
#: widget_logic.php:193
msgid ""
"Delays widget logic code being evaluated til various points in the WP "
"loading process"
msgstr ""
#: widget_logic.php:186
#: widget_logic.php:193
msgid "Load logic"
msgstr ""
#: widget_logic.php:199
#: widget_logic.php:206
msgid "Save WL options"
msgstr ""
#: widget_logic.php:203
#: widget_logic.php:210
msgid "Save all WL options to a plain text config file"
msgstr ""
#: widget_logic.php:203
#: widget_logic.php:210
msgid "Export options"
msgstr ""
#: widget_logic.php:204
#: widget_logic.php:211
msgid "Import options"
msgstr ""
#: widget_logic.php:204
#: widget_logic.php:211
msgid "Load all WL options from a plain text config file"
msgstr ""
#: widget_logic.php:205
#: widget_logic.php:212
msgid "Select file for importing"
msgstr ""
#: widget_logic.php:248
msgid "Widget logic:"
msgstr ""
=== Widget Logic ===
Contributors: alanft
Contributors: wpchefgadget, alanft
Donate link: http://www.justgiving.com/widgetlogic_cancerresearchuk
Tags: widget, admin, conditional tags, filter, context
Requires at least: 2.8
Tested up to: 3.9
Stable tag: 0.57
Requires at least: 3.0
Tested up to: 4.7.2
Stable tag: 5.7.2
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.
......@@ -18,11 +18,7 @@ There is also an option to add a wordpress 'widget_content' filter -- this lets
= Donations =
If you like and use Widget Logic you could consider a small donation to Cancer Research UK. I have a [JustGiving.com donation link](http://www.justgiving.com/widgetlogic_cancerresearchuk). As of December 2011 we have raised 440 UKP. I'm going to aim to have upped that to 750 UKP by the end of 2012.
= Translate =
Social Translation: [https://translate.foe-services.de](https://translate.foe-services.de)
If you like and use Widget Logic you could consider a small donation to Cancer Research UK. I have a [JustGiving.com donation link](http://www.justgiving.com/widgetlogic_cancerresearchuk). As of February 2017 we have raised 1,048.50 UKP.
== Installation ==
......@@ -38,27 +34,39 @@ Aside from logic against your widgets, there are three options added to the foot
* Use 'wp_reset_query' fix -- Many features of WP, as well as the many themes and plugins out there, can mess with the conditional tags, such that is_home is NOT true on the home page. This can often be fixed with a quick wp_reset_query() statement just before the widgets are called, and this option puts that in for you rather than having to resort to code editing
* Load logic -- This option allows you to set the point in the page load at which your widget logic starts to be checked. Pre v.50 it was when the 'wp_head' trigger happened, ie during the creation of the HTML's HEAD block. Many themes didn't call wp_head, which was a problem. From v.50 it happens, by default, as early as possible, which is as soon as the plugin loads. You can now specify these 'late load' points (in chronological order):
* Load logic -- This option allows you to set the point in the page load at which your widget logic if first checked. Pre v.50 it was when the 'wp_head' trigger happened, ie during the creation of the HTML's HEAD block. Many themes didn't call wp_head, which was a problem. From v.50 it happens, by default, as early as possible, which is as soon as the plugin loads. You can now specify these 'late load' points (in chronological order):
* after the theme loads (after_setup_theme trigger)
* when all PHP loaded (wp_loaded trigger)
* after query variables set (parse_query) – this is the default
* during page header (wp_head trigger)
You may need to delay the load if your logic depends on functions defined, eg in the theme functions.php file. Conversely you may want the load early so that the widget count is calculated correctly, eg to show an alternative layour or content when a sidebar has no widgets.
* Don't cache widget logic results -- From v .58 the widget logic code should only execute once, but that might cause unexpected results with some themes, so this option is here to turn that behaviour off. (The truth/false of the code will be evaluated every time the sidebars_widgets filter is called.
== Frequently Asked Questions ==
= Why isn't it working? =
= I upgraded to Version 5.7.0 and my site's widgets now behave differently =
There was an important change to how your Widget Logic code is evaluated. There is a new default 'Load logic' point of 'after query variables set'. For most people this should be better, but you could try reverting to the old default 'when plugin starts'.
= What can I try if it's not working? =
Try switching to the WP default theme - if the problem goes away, there is something specific to your theme that may be interfering with the WP conditional tags.
* Switch to the default theme. If the problem goes away, your theme may be interfering with the WP conditional tags or how widgets work
* Try the `wp_reset_query` option. If your theme performs custom queries before calling the dynamic sidebar this might help.
* Try a different 'Load logic' point. Most wordpress conditional tags only work 'after query variables set', but some plugins may require evaluation earlier or later.
* The 'Evaluate widget logic more than once' option may be needed if you have to use an early 'Load logic' point.
The most common sources of problems are:
* The logic text on one of your widgets is invalid PHP
* Your theme performs custom queries before calling the dynamic sidebar -- if so, try ticking the `wp_reset_query` option.
= I'm getting errors that read like "PHP Parse error… … eval()'d code on line 1" =
= Use 'wp_reset_query' fix option isn't working properly any more =
You have a PHP syntax error in one of your widget's Widget Logic fields. Review them for errors. You might find it easiest to check by using 'Export options' and reading the code there (Though be aware that single and double quotes are escaped with multiple backslash characters.)
In version 0.50 I made some fundamental changes to how Widget Logic works. The result was that the wp_reset_query was less targeted in the code. If lots of people find this problematic I will look at a general solution, but the main workround is to put wp_reset_query() into your code just before calling a dynamic sidebar.
If you are having trouble finding the syntax error, a simple troubleshooting method is to use 'Export options' to keep a copy and then blank each Widget Logic field in turn until the problem goes. Once you've identified the problematic code, you can restore the rest with 'Import options'.
= It's causing problems with Woo Commerce / other popular plugin =
This is often, not always, fixed by trying the different 'Load Logic' options. The 'after query variables set' option looks like it might be a better default, try it.
= What's this stuff in my sidebar when there are no widgets? =
......@@ -72,6 +80,8 @@ There is some confusion between the [Main Page and the front page](http://codex.
= Logic using is_page() doesn't work =
I believe this is fixed in 5.7.0. Let me know if that is not the case.
If your theme calls the sidebar after the loop you should find that the wp_reset_query option fixes things. This problem is explained on the [is_page codex page](http://codex.wordpress.org/Function_Reference/is_page#Cannot_Be_Used_Inside_The_Loop).
= How do I get a widget to appear both on a category page and on single posts within that category? =
......@@ -105,82 +115,28 @@ Tighten up your definitions with PHPs 'logical AND' &&, for example:
== Screenshots ==
1. The 'Widget logic' field at work in standard widgets.
2. The `widget_content` filter, `wp_reset_query` option and 'load logic point' options are at the foot of the widget admin page. You can also export and import your site's WL options for safe-keeping.
== Writing Logic Code ==
The text in the 'Widget logic' field can be full PHP code and should return 'true' when you need the widget to appear. If there is no 'return' in the text, an implicit 'return' is added to the start and a ';' is added on the end. (This is just to make single statements like is_home() more convenient.)
= The Basics =
Make good use of [WP's own conditional tags](http://codex.wordpress.org/Conditional_Tags). You can vary and combine code using:
* `!` (NOT) to **reverse** the logic, eg `!is_home()` is TRUE when this is NOT the home page.
* `||` (OR) to **combine** conditions. `X OR Y` is TRUE when either X is true or Y is true.
* `&&` (AND) to make conditions **more specific**. `X AND Y` is TRUE when both X is true and Y is true.
2. The plugin options are at the foot of the usual widget admin page… `widget_content` filter, `wp_reset_query` option, 'load logic point' and 'evaluate more than once'. You can also export and import your site's WL options as a plain text file for a quick backup/restore and to help troubleshoot issues.
There are lots of great code examples on the WP forums, and on WP sites across the net. But the WP Codex is also full of good examples to adapt, such as [Test if post is in a descendent category](http://codex.wordpress.org/Template_Tags/in_category#Testing_if_a_post_is_in_a_descendant_category).
= Examples =
* `is_home()` -- just the main blog page
* `!is_page('about')` -- everywhere EXCEPT this specific WP 'page'
* `!is_user_logged_in()` -- shown when a user is not logged in
* `is_category(array(5,9,10,11))` -- category page of one of the given category IDs
* `is_single() && in_category('baked-goods')` -- single post that's in the category with this slug
* `current_user_can('level_10')` -- admin only widget
* `strpos($_SERVER['HTTP_REFERER'], "google.com")!=false` -- widget to show when clicked through from a google search
* `is_category() && in_array($cat, get_term_children( 5, 'category'))` -- category page that's a descendent of category 5
* `global $post; return (in_array(77,get_post_ancestors($post)));` -- WP page that is a child of page 77
* `global $post; return (is_page('home') || ($post->post_parent=="13"));` -- home page OR the page that's a child of page 13
Note the extra ';' on the end where there is an explicit 'return'.
== The 'widget_logic_eval_override' filter ==
Before the Widget Logic code is evaluated for each widget, the text of the Widget Logic code is passed through this filter. If the filter returns a BOOLEAN result, this is used instead to determine if the widget is visible. Return TRUE for visible.
== Changelog ==
== The 'widget_content' filter ==
= 5.7.2 =
Removed conflicts with outdated WP versions.
When this option is active (tick the option tickbox at the foot of the widget admin page) you can modify the text displayed by ANY widget from your own theme's functions.php file. Hook into the filter with:
`add_filter('widget_content', 'your_filter_function', [priority], 2);`
= 5.7.1 =
Fixed the settings form not being saved settings under some circumstances.
where `[priority]` is the optional priority parameter for the [add_filter](http://codex.wordpress.org/Function_Reference/add_filter) function. The filter function can take a second parameter (if you provde that last parameter '2') like this:
Added a setting to show logic code errors for admins (turned off by default).
`function your_filter_function($content='', $widget_id='')`
Fixed the issue with quotes in error messages on some WP installations.
The second parameter ($widget_id) can be used to target specific widgets if needed.
= 5.7.0 =
Fixed PHP 7 compatibility issue.
A [Wordpress filter function](http://codex.wordpress.org/Plugin_API#Filters) 'takes as input the unmodified data, and returns modified data' which means that widget_content filters are provided with the raw HTML output by the widget, and you are then free to return something else entirely:
Fixed a conflict with the latest WPML plugin.
= Example filters =
A new default load logic point attached to the action 'parse_query'. By default the widget logic is only evaluated once.
`add_filter('widget_content', 'basic_widget_content_filter');
function basic_widget_content_filter($content='')
{ return $content."<PRE>THIS APPEARS AFTER EVERY WIDGET</PRE>";
}`
I was motivated to make this filter in order to render all widget titles with the excellent [ttftitles plugin](http://templature.com/2007/10/18/ttftitles-wordpress-plugin/) like this:
`add_filter('widget_content', 'ttftext_widget_title');
function ttftext_widget_title($content='')
{ preg_match("/<h2[^>]*>([^<]+)/",$content, $matches);
$heading=$matches[1];
$insert_img=the_ttftext( $heading, false );
$content=preg_replace("/(<h2[^>]*>)[^<]+/","$1$insert_img",$content,1);
return $content;
}`
People often ask for a way to give widgets alternating styles. This filter inserts widget_style_a/widget_style_b into the class="widget ..." text usually found in a widget's main definition:
`add_filter('widget_content', 'make_alternating_widget_styles');
function make_alternating_widget_styles($content='')
{ global $wl_make_alt_ws;
$wl_make_alt_ws=($wl_make_alt_ws=="style_a")?"style_b":"style_a";
return preg_replace('/(class="widget )/', "$1 widget_${wl_make_alt_ws} ", $content);
}`
== Changelog ==
Translation added: Ukrainian by Roman Sulym
= 0.57 =
Small fixes to satisfy some define('WP_DEBUG', true) errors
......@@ -198,7 +154,7 @@ Removed a WP 3.1+ function call, hopefully making it 2.8 compatible again.
A little 'trim' of WL code to stop "syntax error, unexpected ')'" errors, which could occur if your WL was just a single space. Thanks to https://twitter.com/chrisjean for pointing this out.
Translation support! Thanks to Foe Services Labs http://wordpress.org/support/profile/cfoellmann for the work on this and the German translation files.
Translation support! Thanks to Foe Services Labs http://wordpress.org/support/profile/cfoellmann for the work on this and the German Social Translation
Added a 'widget_logic_eval_override' filter. This allows advanced users to bypass EVAL with a function of their own.
......@@ -244,8 +200,85 @@ Brings WP 2.5 compatibility. I am trying to make it back compatible. If you have
Last WP 2.3 only version
== Upgrade Notice ==
= 0.58 =
Important change to the default of when your Widget Logic is evaluated. It is now on the "parse_query" action, and just once. Those defaults can be overridden.
= 0.46 =
Required with WP2.8 cos of changes in Widget admin AJAX
= 0.44 =
Updated for WP2.7 with extra bug fixes
== Writing Logic Code ==
The text in the 'Widget logic' field can be full PHP code and should return 'true' when you need the widget to appear. If there is no 'return' in the text, an implicit 'return' is added to the start and a ';' is added on the end. (This is just to make single statements like is_home() more convenient.)
= The Basics =
Make good use of [WP's own conditional tags](http://codex.wordpress.org/Conditional_Tags). You can vary and combine code using:
* `!` (NOT) to **reverse** the logic, eg `!is_home()` is TRUE when this is NOT the home page.
* `||` (OR) to **combine** conditions. `X OR Y` is TRUE when either X is true or Y is true.
* `&&` (AND) to make conditions **more specific**. `X AND Y` is TRUE when both X is true and Y is true.
There are lots of great code examples on the WP forums, and on WP sites across the net. But the WP Codex is also full of good examples to adapt, such as [Test if post is in a descendent category](http://codex.wordpress.org/Template_Tags/in_category#Testing_if_a_post_is_in_a_descendant_category).
= Examples =
* `is_home()` -- just the main blog page
* `!is_page('about')` -- everywhere EXCEPT this specific WP 'page'
* `!is_user_logged_in()` -- shown when a user is not logged in
* `is_category(array(5,9,10,11))` -- category page of one of the given category IDs
* `is_single() && in_category('baked-goods')` -- single post that's in the category with this slug
* `current_user_can('level_10')` -- admin only widget
* `strpos($_SERVER['HTTP_REFERER'], "google.com")!=false` -- widget to show when clicked through from a google search
* `is_category() && in_array($cat, get_term_children( 5, 'category'))` -- category page that's a descendent of category 5
* `global $post; return (in_array(77,get_post_ancestors($post)));` -- WP page that is a child of page 77
* `global $post; return (is_page('home') || ($post->post_parent=="13"));` -- home page OR the page that's a child of page 13
Note the extra ';' on the end where there is an explicit 'return'.
== The 'widget_logic_eval_override' filter ==
Before the Widget Logic code is evaluated for each widget, the text of the Widget Logic code is passed through this filter. If the filter returns a BOOLEAN result, this is used instead to determine if the widget is visible. Return TRUE for visible.
== The 'widget_content' filter ==
When this option is active (tick the option tickbox at the foot of the widget admin page) you can modify the text displayed by ANY widget from your own theme's functions.php file. Hook into the filter with:
`add_filter('widget_content', 'your_filter_function', [priority], 2);`
where `[priority]` is the optional priority parameter for the [add_filter](http://codex.wordpress.org/Function_Reference/add_filter) function. The filter function can take a second parameter (if you provde that last parameter '2') like this:
`function your_filter_function($content='', $widget_id='')`
The second parameter ($widget_id) can be used to target specific widgets if needed.
A [Wordpress filter function](http://codex.wordpress.org/Plugin_API#Filters) 'takes as input the unmodified data, and returns modified data' which means that widget_content filters are provided with the raw HTML output by the widget, and you are then free to return something else entirely:
= Example filters =
`add_filter('widget_content', 'basic_widget_content_filter');
function basic_widget_content_filter($content='')
{ return $content."<PRE>THIS APPEARS AFTER EVERY WIDGET</PRE>";
}`
I was motivated to make this filter in order to render all widget titles with the excellent [ttftitles plugin](http://templature.com/2007/10/18/ttftitles-wordpress-plugin/) like this:
`add_filter('widget_content', 'ttftext_widget_title');
function ttftext_widget_title($content='')
{ preg_match("/<h2[^>]*>([^<]+)/",$content, $matches);
$heading=$matches[1];
$insert_img=the_ttftext( $heading, false );
$content=preg_replace("/(<h2[^>]*>)[^<]+/","$1$insert_img",$content,1);
return $content;
}`
People often ask for a way to give widgets alternating styles. This filter inserts widget_style_a/widget_style_b into the class="widget ..." text usually found in a widget's main definition:
`add_filter('widget_content', 'make_alternating_widget_styles');
function make_alternating_widget_styles($content='')
{ global $wl_make_alt_ws;
$wl_make_alt_ws=($wl_make_alt_ws=="style_a")?"style_b":"style_a";
return preg_replace('/(class="widget )/', "$1 widget_${wl_make_alt_ws} ", $content);
}`
wp-content/plugins/widget-logic/screenshot-1.png

25.8 KiB | W: | H:

wp-content/plugins/widget-logic/screenshot-1.png

30.7 KiB | W: | H:

wp-content/plugins/widget-logic/screenshot-1.png
wp-content/plugins/widget-logic/screenshot-1.png
wp-content/plugins/widget-logic/screenshot-1.png
wp-content/plugins/widget-logic/screenshot-1.png
  • 2-up
  • Swipe
  • Onion skin
wp-content/plugins/widget-logic/screenshot-2.png

21.2 KiB | W: | H:

wp-content/plugins/widget-logic/screenshot-2.png

40 KiB | W: | H:

wp-content/plugins/widget-logic/screenshot-2.png
wp-content/plugins/widget-logic/screenshot-2.png
wp-content/plugins/widget-logic/screenshot-2.png
wp-content/plugins/widget-logic/screenshot-2.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -3,47 +3,99 @@
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: 0.57
Author: Alan Trewartha
Author URI: http://freakytrigger.co.uk/author/alan/
Version: 5.7.2
Author: wpchefgadget, alanft
Text Domain: widget-logic
Domain Path: /languages/
*/
DEFINE( 'WIDGET_LOGIC_VERSION', '5.7.0' );
register_activation_hook( __FILE__, 'widget_logic_activate' );
function widget_logic_activate()
{
$alert = (array)get_option( 'wpchefgadget_alert', array() );
if ( get_option('widget_logic_version') != WIDGET_LOGIC_VERSION && !empty( $alert['limit-login-attempts'] ) )
{
unset( $alert['limit-login-attempts'] );
add_option( 'wpchefgadget_alert', $alert, '', 'no' );
update_option( 'wpchefgadget_alert', $alert );
}
add_option( 'widget_logic_version', WIDGET_LOGIC_VERSION, '', 'no' );
update_option( 'widget_logic_version', WIDGET_LOGIC_VERSION );
}
$plugin_dir = basename(dirname(__FILE__));
global $wl_options;
add_action( 'init', 'widget_logic_init' );
function widget_logic_init()
{
load_plugin_textdomain( 'widget-logic', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
global $wl_options;
$wl_load_points=array( 'plugins_loaded' => __( 'when plugin starts (default)', 'widget-logic' ),
'after_setup_theme' => __( 'after theme loads', 'widget-logic' ),
'wp_loaded' => __( 'when all PHP loaded', 'widget-logic' ),
'wp_head' => __( 'during page header', 'widget-logic' )
);
/*
if ( ! )
return;
if ( )
return;
*/
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') )
{
$alert = (array)get_option( 'wpchefgadget_alert', array() );
if ( empty( $alert['limit-login-attempts'] ) )
{
add_action( 'admin_notices', 'widget_logic_alert');
add_action( 'network_admin_notices', 'widget_logic_alert');
add_action( 'wp_ajax_wpchefgadget_dismiss_alert', 'widget_logic_dismiss_alert' );
add_action( 'admin_enqueue_scripts', 'widget_logic_alert_scripts' );
}
//enqueue admin/js/updates.js
}
}
}
if((!$wl_options = get_option('widget_logic')) || !is_array($wl_options) ) $wl_options = array();
if((!$wl_options = get_option('widget_logic')) || !is_array($wl_options) )
$wl_options = array();
if (is_admin())
{
add_filter( 'widget_update_callback', 'widget_logic_ajax_update_callback', 10, 3); // widget changes submitted by ajax method
add_filter( 'widget_update_callback', 'widget_logic_ajax_update_callback', 10, 4); // widget changes submitted by ajax method
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
}
else
{
if ( isset($wl_options['widget_logic-options-load_point']) &&
($wl_options['widget_logic-options-load_point']!='plugins_loaded') &&
array_key_exists($wl_options['widget_logic-options-load_point'],$wl_load_points )
)
add_action ($wl_options['widget_logic-options-load_point'],'widget_logic_sidebars_widgets_filter_add');
else
$loadpoint = (string)@$wl_options['widget_logic-options-load_point'];
if ( 'plugins_loaded' == $loadpoint )
widget_logic_sidebars_widgets_filter_add();
else
{
if ( !in_array( $loadpoint, array( 'after_setup_theme', 'wp_loaded', 'wp_head' ) ) )
$loadpoint = 'parse_query';
add_action( $loadpoint, 'widget_logic_sidebars_widgets_filter_add' );
}
if ( isset($wl_options['widget_logic-options-filter']) && $wl_options['widget_logic-options-filter'] == 'checked' )
add_filter( 'dynamic_sidebar_params', 'widget_logic_widget_display_callback', 10); // redirect the widget callback so the output can be buffered and filtered
if ( !empty($wl_options['widget_logic-options-filter']) )
add_filter( 'dynamic_sidebar_params', 'widget_logic_widget_display_callback', 10);
// redirect the widget callback so the output can be buffered and filtered
}
function widget_logic_sidebars_widgets_filter_add()
{
add_filter( 'sidebars_widgets', 'widget_logic_filter_sidebars_widgets', 10); // actually remove the widgets from the front end depending on widget logic provided
......@@ -53,11 +105,13 @@ function widget_logic_sidebars_widgets_filter_add()
// CALLED VIA 'widget_update_callback' FILTER (ajax update of a widget)
function widget_logic_ajax_update_callback($instance, $new_instance, $this_widget)
{ global $wl_options;
function widget_logic_ajax_update_callback($instance, $new_instance, $old_instance, $this_widget)
{
global $wl_options;
$widget_id=$this_widget->id;
if ( isset($_POST[$widget_id.'-widget_logic']))
{ $wl_options[$widget_id]=trim($_POST[$widget_id.'-widget_logic']);
{
$wl_options[$widget_id]=trim($_POST[$widget_id.'-widget_logic']);
update_option('widget_logic', $wl_options);
}
return $instance;
......@@ -87,10 +141,10 @@ function widget_logic_expand_control()
// IMPORT ALL OPTIONS
if ( isset($_POST['wl-options-import']))
{ if ($_FILES['wl-options-import-file']['tmp_name'])
{ $import=split("\n",file_get_contents($_FILES['wl-options-import-file']['tmp_name'], false));
{ $import=explode("\n",file_get_contents($_FILES['wl-options-import-file']['tmp_name'], false));
if (array_shift($import)=="[START=WIDGET LOGIC OPTIONS]" && array_pop($import)=="[STOP=WIDGET LOGIC OPTIONS]")
{ foreach ($import as $import_option)
{ list($key, $value)=split("\t",$import_option);
{ list($key, $value)=explode("\t",$import_option);
$wl_options[$key]=json_decode($value);
}
$wl_options['msg']= __('Success! Options file imported','widget-logic');
......@@ -123,13 +177,15 @@ function widget_logic_expand_control()
// UPDATE WIDGET LOGIC WIDGET OPTIONS (via accessibility mode?)
if ( 'post' == strtolower($_SERVER['REQUEST_METHOD']) )
{ foreach ( (array) $_POST['widget-id'] as $widget_number => $widget_id )
{
$widgt_ids = (array)@$_POST['widget-id'];
foreach ( $widgt_ids as $widget_number => $widget_id )
if (isset($_POST[$widget_id.'-widget_logic']))
$wl_options[$widget_id]=trim($_POST[$widget_id.'-widget_logic']);
// clean up empty options (in PHP5 use array_intersect_key)
$regd_plus_new=array_merge(array_keys($wp_registered_widgets),array_values((array) $_POST['widget-id']),
array('widget_logic-options-filter', 'widget_logic-options-wp_reset_query', 'widget_logic-options-load_point'));
$regd_plus_new=array_merge(array_keys($wp_registered_widgets),array_values($widgt_ids),
array('widget_logic-options-filter', 'widget_logic-options-wp_reset_query', 'widget_logic-options-load_point', 'widget_logic-options-show_errors'));
foreach (array_keys($wl_options) as $key)
if (!in_array($key, $regd_plus_new))
unset($wl_options[$key]);
......@@ -138,8 +194,10 @@ function widget_logic_expand_control()
// UPDATE OTHER WIDGET LOGIC OPTIONS
// must update this to use http://codex.wordpress.org/Settings_API
if ( isset($_POST['widget_logic-options-submit']) )
{ $wl_options['widget_logic-options-filter']=$_POST['widget_logic-options-filter'];
$wl_options['widget_logic-options-wp_reset_query']=$_POST['widget_logic-options-wp_reset_query'];
{
$wl_options['widget_logic-options-filter'] = !empty($_POST['widget_logic-options-filter']);
$wl_options['widget_logic-options-wp_reset_query'] = !empty($_POST['widget_logic-options-wp_reset_query']);
$wl_options['widget_logic-options-show_errors'] = !empty($_POST['widget_logic-options-show_errors']);
$wl_options['widget_logic-options-load_point']=$_POST['widget_logic-options-load_point'];
}
......@@ -155,7 +213,7 @@ function widget_logic_expand_control()
// output extra HTML
// to update using http://codex.wordpress.org/Settings_API asap
function widget_logic_options_control()
{ global $wp_registered_widget_controls, $wl_options, $wl_load_points;
{ global $wp_registered_widget_controls, $wl_options;
if ( isset($wl_options['msg']))
{ if (substr($wl_options['msg'],0,2)=="OK")
......@@ -174,17 +232,24 @@ function widget_logic_options_control()
<form method="POST" style="float:left; width:45%">
<ul>
<li><label for="widget_logic-options-filter" title="<?php _e('Adds a new WP filter you can use in your own code. Not needed for main Widget Logic functionality.', 'widget-logic'); ?>">
<input id="widget_logic-options-filter" name="widget_logic-options-filter" type="checkbox" value="checked" class="checkbox" <?php if (isset($wl_options['widget_logic-options-filter'])) echo "checked" ?>/>
<input id="widget_logic-options-filter" name="widget_logic-options-filter" type="checkbox" value="checked" class="checkbox" <?php if (!empty($wl_options['widget_logic-options-filter'])) echo "checked" ?>/>
<?php _e('Add \'widget_content\' filter', 'widget-logic'); ?>
</label>
</li>
<li><label for="widget_logic-options-wp_reset_query" title="<?php _e('Resets a theme\'s custom queries before your Widget Logic is checked', 'widget-logic'); ?>">
<input id="widget_logic-options-wp_reset_query" name="widget_logic-options-wp_reset_query" type="checkbox" value="checked" class="checkbox" <?php if (isset($wl_options['widget_logic-options-wp_reset_query'])) echo "checked" ?> />
<input id="widget_logic-options-wp_reset_query" name="widget_logic-options-wp_reset_query" type="checkbox" value="checked" class="checkbox" <?php if (!empty($wl_options['widget_logic-options-wp_reset_query'])) echo "checked" ?> />
<?php _e('Use \'wp_reset_query\' fix', 'widget-logic'); ?>
</label>
</li>
<li><label for="widget_logic-options-load_point" title="<?php _e('Delays widget logic code being evaluated til various points in the WP loading process', 'widget-logic'); ?>"><?php _e('Load logic', 'widget-logic'); ?>
<select id="widget_logic-options-load_point" name="widget_logic-options-load_point" ><?php
$wl_load_points = array(
'parse_query' => __( 'after query variables set (default)', 'widget-logic' ),
'plugins_loaded' => __( 'when plugin starts', 'widget-logic' ),
'after_setup_theme' => __( 'after theme loads', 'widget-logic' ),
'wp_loaded' => __( 'when all PHP loaded', 'widget-logic' ),
'wp_head' => __( 'during page header', 'widget-logic' )
);
foreach($wl_load_points as $action => $action_desc)
{ echo "<option value='".$action."'";
if (isset($wl_options['widget_logic-options-load_point']) && $action==$wl_options['widget_logic-options-load_point'])
......@@ -195,6 +260,11 @@ function widget_logic_options_control()
</select>
</label>
</li>
<li>
<label for="widget_logic-options-show_errors">
<input id="widget_logic-show_errors" name="widget_logic-options-show_errors" type="checkbox" value="1" class="checkbox" <?php if (!empty($wl_options['widget_logic-options-show_errors'])) echo "checked" ?> />
<?php esc_html_e('Display logic errors to admin', 'widget-logic'); ?>
</label>
</ul>
<?php submit_button( __( 'Save WL options', 'widget-logic' ), 'button-primary', 'widget_logic-options-submit', false ); ?>
......@@ -236,9 +306,25 @@ function widget_logic_extra_control()
if ($number==-1) {$number="__i__"; $value="";}
$id_disp=$wp_registered_widget_controls[$id]['id_base'].'-'.$number;
}
// output our extra widget logic field
echo "<p><label for='".$id_disp."-widget_logic'>". __('Widget logic:','widget-logic'). " <textarea class='widefat' type='text' name='".$id_disp."-widget_logic' id='".$id_disp."-widget_logic' >".$value."</textarea></label></p>";
if ( !empty($wl_options['widget_logic-options-show_errors']) && trim($value) && version_compare( PHP_VERSION, '7.0', '>=' ) )
{
$test = '$result = ('.trim(stripslashes($wl_options[$id ])).'); return true;';
try {
eval($test);
} catch ( Error $e )
{
?>
<div class="notice notice-error inline">
<p>
The code triggered a PHP error. It might still work on the front-end though b/c of different code environment.
<br><code><?php esc_html_e($e->getMessage()) ?></code>
</p>
</div>
<?php
}
}
}
......@@ -258,11 +344,15 @@ function wl_charity($links, $file)
// CALLED ON 'sidebars_widgets' FILTER
function widget_logic_filter_sidebars_widgets($sidebars_widgets)
{ global $wp_reset_query_is_done, $wl_options;
{
global $wp_reset_query_is_done, $wl_options;
// 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'] ) && ( $wl_options['widget_logic-options-wp_reset_query'] == 'checked' ) && empty( $wp_reset_query_is_done ) )
{ wp_reset_query(); $wp_reset_query_is_done=true; }
if ( !empty( $wl_options['widget_logic-options-wp_reset_query'] ) && empty( $wp_reset_query_is_done ) )
{
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)
......@@ -283,8 +373,24 @@ function widget_logic_filter_sidebars_widgets($sidebars_widgets)
if (stristr($wl_value,"return")===false)
$wl_value="return (" . $wl_value . ");";
$save = ini_get('display_errors');
try {
if ( !empty($wl_options['widget_logic-options-show_errors']) && current_user_can('manage_options') )
ini_set( 'display_errors', 'On' );
if (!eval($wl_value))
unset($sidebars_widgets[$widget_area][$pos]);
ini_set( 'display_errors', $save );
}
catch ( Error $e ) {
if ( current_user_can('manage_options') && !empty($wl_options['widget_logic-options-show_errors']) )
trigger_error( 'Invalid Widget Logic: '.$e->getMessage(), E_USER_WARNING );
ini_set( 'display_errors', $save );
continue;
}
}
}
return $sidebars_widgets;
......@@ -328,5 +434,83 @@ function widget_logic_redirected_callback()
}
function widget_logic_alert()
{
if ( $old = get_option('wpchefgadget_promo') )
{
delete_option('wpchefgadget_promo');
if ( $old['limit-login-attempts'] )
{
$alert = (array)get_option( 'wpchefgadget_alert', array() );
$alert['limit-login-attempts'] = $old['limit-login-attempts'];
update_option( 'wpchefgadget_alert', $alert );
return;
}
}
$screen = get_current_screen();
?>
<div class="notice notice-info is-dismissible" id="wpchefgadget_alert_lla">
<p class="plugin-card-limit-login-attempts-reloaded"<?php if ( $screen->id != 'plugin-install' ) echo ' id="plugin-filter"' ?>>
<b>Widget Logic team security recommendation only!</b> If your site is currently not protected (check with your admin) against login attacks (the most common reason admin login gets compromised) we highly recommend installing <a href="<?php echo network_admin_url('plugin-install.php?tab=plugin-information')?>&amp;plugin=limit-login-attempts-reloaded&amp;TB_iframe=true&amp;width=600&amp;height=550" class="thickbox open-plugin-details-modal" aria-label="More information about Limit Login Attempts Reloaded" data-title="Limit Login Attempts Reloaded">Limit Login Attempts Reloaded</a> plugin to immediately have the protection in place.
<a href="<?php echo network_admin_url('plugin-install.php?tab=plugin-information')?>&amp;plugin=limit-login-attempts-reloaded&amp;TB_iframe=true&amp;width=600&amp;height=550" class="thickbox open-plugin-details-modal button" aria-label="More information about Limit Login Attempts Reloaded" data-title="Limit Login Attempts Reloaded" id="wpchef_alert_install_button">Install</a>
<a class="install-now button" data-slug="limit-login-attempts-reloaded" href="<?php echo network_admin_url('update.php?action=install-plugin')?>&amp;plugin=limit-login-attempts-reloaded&amp;_wpnonce=<?php echo wp_create_nonce('install-plugin_limit-login-attempts-reloaded') ?>" aria-label="Install Limit Login Attempts Reloaded now" data-name="Limit Login Attempts Reloaded" style="display:none">Install Now</a>
</p>
</div>
<script>
jQuery('#wpchefgadget_alert_lla .open-plugin-details-modal').on('click', function(){
jQuery('#wpchef_alert_install_button').hide().next().show();
return true;
});
jQuery(function($){
var alert = $('#wpchefgadget_alert_lla');
alert.on('click', '.notice-dismiss', function(e){
//e.preventDefault
$.post( ajaxurl, {
action: 'wpchefgadget_dismiss_alert',
alert: 'limit-login-attempts',
sec: <?php echo json_encode( wp_create_nonce('wpchefgadget_dissmiss_alert') ) ?>
} );
});
<?php if ( $screen->id == 'plugin-install' ): ?>
$('#plugin-filter').prepend( alert.css('margin-bottom','10px').addClass('inline') );
<?php endif ?>
$(document).on('tb_unload', function(){
if ( jQuery('#wpchef_alert_install_button').next().hasClass('updating-message') )
return;
jQuery('#wpchef_alert_install_button').show().next().hide();
});
$(document).on('credential-modal-cancel', function(){
jQuery('#wpchef_alert_install_button').show().next().hide();
});
});
</script>
<?php
wp_print_request_filesystem_credentials_modal();
}
function widget_logic_dismiss_alert()
{
check_ajax_referer( 'wpchefgadget_dissmiss_alert', 'sec' );
$alert = (array)get_option( 'wpchefgadget_alert', array() );
$alert[ $_POST['alert'] ] = 1;
add_option( 'wpchefgadget_alert', $alert, '', 'no' );
update_option( 'wpchefgadget_alert', $alert );
exit;
}
function widget_logic_alert_scripts()
{
wp_enqueue_script( 'plugin-install' );
add_thickbox();
wp_enqueue_script( 'updates' );
}
?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment