Widget Logic - Version 5.7.0

Version Description

Fixed PHP 7 compatibility issue.

Fixed a conflict with the latest WPML plugin.

A new default load logic point attached to the action 'parse_query'. By default the widget logic is only evaluated once.

Translation added: Ukrainian by Roman Sulym

Download this release

Release Info

Developer wpchefgadget
Plugin Icon 128x128 Widget Logic
Version 5.7.0
Comparing to
See all releases

Code changes from version 0.57 to 5.7.0

languages/widget-logic-de_DE.mo CHANGED
File without changes
languages/widget-logic-de_DE.po CHANGED
File without changes
languages/widget-logic-es_ES.mo CHANGED
File without changes
languages/widget-logic-es_ES.po CHANGED
File without changes
languages/widget-logic-hu_HU.mo ADDED
Binary file
languages/widget-logic-hu_HU.po ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Widget Logic v0.57\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: \n"
6
+ "PO-Revision-Date: 2013-12-18 08:33+0100\n"
7
+ "Last-Translator: HunStArt <szemcse@freemail.hu>\n"
8
+ "Language-Team: HunStArt <szemcse@freemail.hu>\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "Plural-Forms: nplurals=1; plural=0;\n"
13
+ "X-Generator: Poedit 1.6.3\n"
14
+ "X-Poedit-SourceCharset: UTF-8\n"
15
+ "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;"
16
+ "_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"
17
+ "X-Poedit-Basepath: ../\n"
18
+ "X-Textdomain-Support: yes\n"
19
+ "Language: hu_HU\n"
20
+ "X-Poedit-SearchPath-0: .\n"
21
+
22
+ # @ widget-logic
23
+ #. translators: plugin header field 'Name'
24
+ #: widget_logic.php:0
25
+ msgid "Widget Logic"
26
+ msgstr "Widget Logika"
27
+
28
+ # @ widget-logic
29
+ #. translators: plugin header field 'PluginURI'
30
+ #: widget_logic.php:0
31
+ msgid "http://wordpress.org/extend/plugins/widget-logic/"
32
+ msgstr "http://wordpress.org/extend/plugins/widget-logic/"
33
+
34
+ # @ widget-logic
35
+ #. translators: plugin header field 'Description'
36
+ #: widget_logic.php:0
37
+ msgid "Control widgets with WP's conditional tags is_home etc"
38
+ msgstr "Vezérlő widget WP feltételes címkékel pl: is_home stb."
39
+
40
+ # @ widget-logic
41
+ #. translators: plugin header field 'Author'
42
+ #: widget_logic.php:0
43
+ msgid "Alan Trewartha"
44
+ msgstr "Alan Trewartha"
45
+
46
+ # @ widget-logic
47
+ #. translators: plugin header field 'AuthorURI'
48
+ #: widget_logic.php:0
49
+ msgid "http://freakytrigger.co.uk/author/alan/"
50
+ msgstr "http://freakytrigger.co.uk/author/alan/"
51
+
52
+ # @ widget-logic
53
+ #. translators: plugin header field 'Version'
54
+ #: widget_logic.php:0
55
+ msgid "0.57"
56
+ msgstr "0.57"
57
+
58
+ # @ widget-logic
59
+ #: widget_logic.php:18
60
+ msgid "when plugin starts (default)"
61
+ msgstr "amikor a bővítmény indul (alapértelmezett)"
62
+
63
+ # @ widget-logic
64
+ #: widget_logic.php:19
65
+ msgid "after theme loads"
66
+ msgstr "sablon betöltése után"
67
+
68
+ # @ widget-logic
69
+ #: widget_logic.php:20
70
+ msgid "when all PHP loaded"
71
+ msgstr "amikor minden PHP betöltődött"
72
+
73
+ # @ widget-logic
74
+ #: widget_logic.php:21
75
+ msgid "during page header"
76
+ msgstr "fejléc közben"
77
+
78
+ # @ widget-logic
79
+ #: widget_logic.php:96
80
+ msgid "Success! Options file imported"
81
+ msgstr "A beállításokat tartalmazó fájl importálása sikeresen befejeződött"
82
+
83
+ # @ widget-logic
84
+ #: widget_logic.php:99
85
+ msgid "Invalid options file"
86
+ msgstr "Érvénytelen fájl beállítások"
87
+
88
+ # @ widget-logic
89
+ #: widget_logic.php:104
90
+ msgid "No options file provided"
91
+ msgstr "Beállítások fájl nincs kiválasztva"
92
+
93
+ # @ widget-logic
94
+ #: widget_logic.php:173
95
+ msgid "Widget Logic options"
96
+ msgstr "Widget Logika Beállításai"
97
+
98
+ # @ widget-logic
99
+ #: widget_logic.php:176
100
+ msgid ""
101
+ "Adds a new WP filter you can use in your own code. Not needed for main "
102
+ "Widget Logic functionality."
103
+ msgstr ""
104
+ "Hozzáad egy új WP szűrőt saját kód segítségével. Nem szükséges főbb Widget "
105
+ "Logic funkcionalitás."
106
+
107
+ # @ widget-logic
108
+ #: widget_logic.php:178
109
+ msgid "Add 'widget_content' filter"
110
+ msgstr "'Widget_content' szűrő hozzáadása"
111
+
112
+ # @ widget-logic
113
+ #: widget_logic.php:181
114
+ msgid "Resets a theme's custom queries before your Widget Logic is checked"
115
+ msgstr ""
116
+ "Visszaállítja a sablon szokás lekérdezéseit, mielőtt a Widget Logic meg van "
117
+ "jelölve"
118
+
119
+ # @ widget-logic
120
+ #: widget_logic.php:183
121
+ msgid "Use 'wp_reset_query' fix"
122
+ msgstr "Használja a 'Wp_reset_query' megerősítést"
123
+
124
+ # @ widget-logic
125
+ #: widget_logic.php:186
126
+ msgid ""
127
+ "Delays widget logic code being evaluated til various points in the WP "
128
+ "loading process"
129
+ msgstr ""
130
+ "Widget logika kód értékelt késleltetései, ami a WP különböző pontjain "
131
+ "történő betöltési folyamat eléréséhez szükségesek"
132
+
133
+ # @ widget-logic
134
+ #: widget_logic.php:186
135
+ msgid "Load logic"
136
+ msgstr "Logika betöltése"
137
+
138
+ # @ widget-logic
139
+ #: widget_logic.php:199
140
+ msgid "Save WL options"
141
+ msgstr "WL beállításainak mentése"
142
+
143
+ # @ widget-logic
144
+ #: widget_logic.php:203
145
+ msgid "Save all WL options to a plain text config file"
146
+ msgstr "Menti az összes WL beállítást sima szöveges konfigurációs fájlba"
147
+
148
+ # @ widget-logic
149
+ #: widget_logic.php:203
150
+ msgid "Export options"
151
+ msgstr "Beállítások exportállása"
152
+
153
+ # @ widget-logic
154
+ #: widget_logic.php:204
155
+ msgid "Import options"
156
+ msgstr "Beállítások importállása"
157
+
158
+ # @ widget-logic
159
+ #: widget_logic.php:204
160
+ msgid "Load all WL options from a plain text config file"
161
+ msgstr "Betölti az összes WL beállítást sima szöveges konfigurációs fájlból"
162
+
163
+ # @ widget-logic
164
+ #: widget_logic.php:205
165
+ msgid "Select file for importing"
166
+ msgstr "Fájl kiválasztása importállásra"
167
+
168
+ # @ widget-logic
169
+ #: widget_logic.php:241
170
+ msgid "Widget logic:"
171
+ msgstr "Widget logika:"
languages/widget-logic-uk.mo ADDED
Binary file
languages/widget-logic-uk.po ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2012
2
+ # This file is distributed under the same license as the package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: Widget Logic\n"
6
+ "Report-Msgid-Bugs-To: http://wordpress.org/tag/wp\n"
7
+ "POT-Creation-Date: 2012-12-17 22:12:06+00:00\n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=UTF-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "PO-Revision-Date: 2014-05-05 11:55+0200\n"
12
+ "Last-Translator: Roman Sulym <sulym.roman@gmail.com>\n"
13
+ "Language-Team: webrain <info@webrain.com.ua>\n"
14
+ "Language: uk\n"
15
+ "X-Generator: Poedit 1.6.3\n"
16
+ "X-Poedit-SourceCharset: UTF-8\n"
17
+
18
+ #: widget_logic.php:5
19
+ msgid "Control widgets with WP's conditional tags is_home etc"
20
+ msgstr ""
21
+ "Керування відображенням віджетів за допомогою стандартних WP теґів на кшталт "
22
+ "is_home()"
23
+
24
+ #: widget_logic.php:18
25
+ msgid "when plugin starts (default)"
26
+ msgstr "під час ініціалізації плаґіна (за замовчуванням)"
27
+
28
+ #: widget_logic.php:19
29
+ msgid "after theme loads"
30
+ msgstr "після завантаження теми"
31
+
32
+ #: widget_logic.php:20
33
+ msgid "when all PHP loaded"
34
+ msgstr "після завантаження всіх PHP файлів"
35
+
36
+ #: widget_logic.php:21
37
+ msgid "during page header"
38
+ msgstr "у заголовку сторінки"
39
+
40
+ #: widget_logic.php:96
41
+ msgid "Success! Options file imported"
42
+ msgstr "Файл налаштувань імпортовано успішно!"
43
+
44
+ #: widget_logic.php:99
45
+ msgid "Invalid options file"
46
+ msgstr "Невірний формат файлу налаштувань"
47
+
48
+ #: widget_logic.php:104
49
+ msgid "No options file provided"
50
+ msgstr "Не вибрано файл налаштувань"
51
+
52
+ #: widget_logic.php:173
53
+ msgid "Widget Logic options"
54
+ msgstr "Налаштування правил логіки"
55
+
56
+ #: widget_logic.php:176
57
+ msgid ""
58
+ "Adds a new WP filter you can use in your own code. Not needed for main "
59
+ "Widget Logic functionality."
60
+ msgstr ""
61
+ "Додати новий фільтр, який ви зможете використовувати у своєму коді. Не "
62
+ "потрібно для базової функціональності плаґіна."
63
+
64
+ #: widget_logic.php:178
65
+ msgid "Add 'widget_content' filter"
66
+ msgstr "Додати фільтр 'widget_content'"
67
+
68
+ #: widget_logic.php:181
69
+ msgid "Resets a theme's custom queries before your Widget Logic is checked"
70
+ msgstr "Скинути всі користувацькі запити перед перевіркою правил логіки"
71
+
72
+ #: widget_logic.php:183
73
+ msgid "Use 'wp_reset_query' fix"
74
+ msgstr "Використовувати функцію 'wp_reset_query'"
75
+
76
+ #: widget_logic.php:186
77
+ msgid ""
78
+ "Delays widget logic code being evaluated til various points in the WP "
79
+ "loading process"
80
+ msgstr ""
81
+ "Призупинити виконання коду плаґіна до певного моменту процесу завантаження WP"
82
+
83
+ #: widget_logic.php:186
84
+ msgid "Load logic"
85
+ msgstr "Завантажувати правила логіки"
86
+
87
+ #: widget_logic.php:199
88
+ msgid "Save WL options"
89
+ msgstr "Зберегти налаштування"
90
+
91
+ #: widget_logic.php:203
92
+ msgid "Save all WL options to a plain text config file"
93
+ msgstr "Зберегти всі налаштування плаґіна у текстовому файлі"
94
+
95
+ #: widget_logic.php:203
96
+ msgid "Export options"
97
+ msgstr "Експортувати налаштування"
98
+
99
+ #: widget_logic.php:204
100
+ msgid "Import options"
101
+ msgstr "Імпортувати налаштування"
102
+
103
+ #: widget_logic.php:204
104
+ msgid "Load all WL options from a plain text config file"
105
+ msgstr "Завантажити всі налаштування плаґіна з текстового файлу"
106
+
107
+ #: widget_logic.php:205
108
+ msgid "Select file for importing"
109
+ msgstr "Вибрати файл для імпорту"
languages/widget-logic.pot CHANGED
@@ -1,23 +1,19 @@
1
- # Copyright (C) 2012
2
  # This file is distributed under the same license as the package.
3
  msgid ""
4
  msgstr ""
5
  "Project-Id-Version: \n"
6
- "Report-Msgid-Bugs-To: http://wordpress.org/tag/wp\n"
7
- "POT-Creation-Date: 2012-12-17 22:12:06+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
11
- "PO-Revision-Date: 2012-MO-DA HO:MI+ZONE\n"
12
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
  "Language-Team: LANGUAGE <LL@li.org>\n"
14
 
15
- #: widget_logic.php:5
16
- msgid "Control widgets with WP's conditional tags is_home etc"
17
- msgstr ""
18
-
19
  #: widget_logic.php:18
20
- msgid "when plugin starts (default)"
21
  msgstr ""
22
 
23
  #: widget_logic.php:19
@@ -29,73 +25,90 @@ msgid "when all PHP loaded"
29
  msgstr ""
30
 
31
  #: widget_logic.php:21
 
 
 
 
32
  msgid "during page header"
33
  msgstr ""
34
 
35
- #: widget_logic.php:96
36
  msgid "Success! Options file imported"
37
  msgstr ""
38
 
39
- #: widget_logic.php:99
40
  msgid "Invalid options file"
41
  msgstr ""
42
 
43
- #: widget_logic.php:104
44
  msgid "No options file provided"
45
  msgstr ""
46
 
47
- #: widget_logic.php:173
48
  msgid "Widget Logic options"
49
  msgstr ""
50
 
51
- #: widget_logic.php:176
52
  msgid ""
53
  "Adds a new WP filter you can use in your own code. Not needed for main "
54
  "Widget Logic functionality."
55
  msgstr ""
56
 
57
- #: widget_logic.php:178
58
  msgid "Add 'widget_content' filter"
59
  msgstr ""
60
 
61
- #: widget_logic.php:181
62
  msgid "Resets a theme's custom queries before your Widget Logic is checked"
63
  msgstr ""
64
 
65
- #: widget_logic.php:183
66
  msgid "Use 'wp_reset_query' fix"
67
  msgstr ""
68
 
69
- #: widget_logic.php:186
 
 
 
 
 
 
 
 
 
70
  msgid ""
71
  "Delays widget logic code being evaluated til various points in the WP "
72
  "loading process"
73
  msgstr ""
74
 
75
- #: widget_logic.php:186
76
  msgid "Load logic"
77
  msgstr ""
78
 
79
- #: widget_logic.php:199
80
  msgid "Save WL options"
81
  msgstr ""
82
 
83
- #: widget_logic.php:203
84
  msgid "Save all WL options to a plain text config file"
85
  msgstr ""
86
 
87
- #: widget_logic.php:203
88
  msgid "Export options"
89
  msgstr ""
90
 
91
- #: widget_logic.php:204
92
  msgid "Import options"
93
  msgstr ""
94
 
95
- #: widget_logic.php:204
96
  msgid "Load all WL options from a plain text config file"
97
  msgstr ""
98
 
99
- #: widget_logic.php:205
100
  msgid "Select file for importing"
101
  msgstr ""
 
 
 
 
1
+ # Copyright (C) 2014
2
  # This file is distributed under the same license as the package.
3
  msgid ""
4
  msgstr ""
5
  "Project-Id-Version: \n"
6
+ "Report-Msgid-Bugs-To: http://wordpress.org/tag/widget-logic\n"
7
+ "POT-Creation-Date: 2014-07-27 16:43:46+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
11
+ "PO-Revision-Date: 2014-MO-DA HO:MI+ZONE\n"
12
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
  "Language-Team: LANGUAGE <LL@li.org>\n"
14
 
 
 
 
 
15
  #: widget_logic.php:18
16
+ msgid "when plugin starts"
17
  msgstr ""
18
 
19
  #: widget_logic.php:19
25
  msgstr ""
26
 
27
  #: widget_logic.php:21
28
+ msgid "after query variables set (default)"
29
+ msgstr ""
30
+
31
+ #: widget_logic.php:22
32
  msgid "during page header"
33
  msgstr ""
34
 
35
+ #: widget_logic.php:97
36
  msgid "Success! Options file imported"
37
  msgstr ""
38
 
39
+ #: widget_logic.php:100
40
  msgid "Invalid options file"
41
  msgstr ""
42
 
43
+ #: widget_logic.php:105
44
  msgid "No options file provided"
45
  msgstr ""
46
 
47
+ #: widget_logic.php:175
48
  msgid "Widget Logic options"
49
  msgstr ""
50
 
51
+ #: widget_logic.php:178
52
  msgid ""
53
  "Adds a new WP filter you can use in your own code. Not needed for main "
54
  "Widget Logic functionality."
55
  msgstr ""
56
 
57
+ #: widget_logic.php:180
58
  msgid "Add 'widget_content' filter"
59
  msgstr ""
60
 
61
+ #: widget_logic.php:183
62
  msgid "Resets a theme's custom queries before your Widget Logic is checked"
63
  msgstr ""
64
 
65
+ #: widget_logic.php:185
66
  msgid "Use 'wp_reset_query' fix"
67
  msgstr ""
68
 
69
+ #: widget_logic.php:188
70
+ msgid ""
71
+ "Re-evaluates widget logic every time the sidebars_widgets filter is called"
72
+ msgstr ""
73
+
74
+ #: widget_logic.php:190
75
+ msgid "Don't cache widget logic results"
76
+ msgstr ""
77
+
78
+ #: widget_logic.php:193
79
  msgid ""
80
  "Delays widget logic code being evaluated til various points in the WP "
81
  "loading process"
82
  msgstr ""
83
 
84
+ #: widget_logic.php:193
85
  msgid "Load logic"
86
  msgstr ""
87
 
88
+ #: widget_logic.php:206
89
  msgid "Save WL options"
90
  msgstr ""
91
 
92
+ #: widget_logic.php:210
93
  msgid "Save all WL options to a plain text config file"
94
  msgstr ""
95
 
96
+ #: widget_logic.php:210
97
  msgid "Export options"
98
  msgstr ""
99
 
100
+ #: widget_logic.php:211
101
  msgid "Import options"
102
  msgstr ""
103
 
104
+ #: widget_logic.php:211
105
  msgid "Load all WL options from a plain text config file"
106
  msgstr ""
107
 
108
+ #: widget_logic.php:212
109
  msgid "Select file for importing"
110
  msgstr ""
111
+
112
+ #: widget_logic.php:248
113
+ msgid "Widget logic:"
114
+ msgstr ""
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Widget Logic ===
2
- Contributors: alanft
3
  Donate link: http://www.justgiving.com/widgetlogic_cancerresearchuk
4
  Tags: widget, admin, conditional tags, filter, context
5
- Requires at least: 2.8
6
- Tested up to: 4.1
7
- Stable tag: 0.57
8
  License: GPLv2 or later
9
 
10
  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
18
 
19
  = Donations =
20
 
21
- 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.
22
-
23
- = Translate =
24
-
25
- Social Translation: [https://translate.foe-services.de](https://translate.foe-services.de)
26
 
27
  == Installation ==
28
 
@@ -38,27 +34,39 @@ Aside from logic against your widgets, there are three options added to the foot
38
 
39
  * 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
40
 
41
- * 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):
42
  * after the theme loads (after_setup_theme trigger)
43
  * when all PHP loaded (wp_loaded trigger)
 
44
  * during page header (wp_head trigger)
45
 
46
  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.
47
 
 
 
48
  == Frequently Asked Questions ==
49
 
50
- = Why isn't it working? =
 
 
 
 
51
 
52
- 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.
 
 
 
53
 
54
- The most common sources of problems are:
55
 
56
- * The logic text on one of your widgets is invalid PHP
57
- * Your theme performs custom queries before calling the dynamic sidebar -- if so, try ticking the `wp_reset_query` option.
58
 
59
- = Use 'wp_reset_query' fix option isn't working properly any more =
60
 
61
- 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.
 
 
 
 
62
 
63
  = What's this stuff in my sidebar when there are no widgets? =
64
 
@@ -72,6 +80,8 @@ There is some confusion between the [Main Page and the front page](http://codex.
72
 
73
  = Logic using is_page() doesn't work =
74
 
 
 
75
  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).
76
 
77
  = How do I get a widget to appear both on a category page and on single posts within that category? =
@@ -105,7 +115,91 @@ Tighten up your definitions with PHPs 'logical AND' &&, for example:
105
  == Screenshots ==
106
 
107
  1. The 'Widget logic' field at work in standard widgets.
108
- 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.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
  == Writing Logic Code ==
111
 
@@ -178,74 +272,3 @@ function make_alternating_widget_styles($content='')
178
  $wl_make_alt_ws=($wl_make_alt_ws=="style_a")?"style_b":"style_a";
179
  return preg_replace('/(class="widget )/', "$1 widget_${wl_make_alt_ws} ", $content);
180
  }`
181
-
182
-
183
- == Changelog ==
184
-
185
- = 0.57 =
186
- Small fixes to satisfy some define('WP_DEBUG', true) errors
187
-
188
- = 0.56 =
189
- Small fix to the original WP3.5 fix in 0.54 that had the side effect of failing to save logic text on newly added widgets.
190
-
191
- = 0.55 =
192
- Restored a striplashes that vanished in 0.54 causing much grief.
193
-
194
- Translation: Spanish by Eduardo Larequi http://wordpress.org/support/profile/elarequi
195
-
196
- = 0.54 =
197
- Removed a WP 3.1+ function call, hopefully making it 2.8 compatible again.
198
-
199
- 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.
200
-
201
- Translation support! Thanks to Foe Services Labs http://wordpress.org/support/profile/cfoellmann for the work on this and the German translation files.
202
-
203
- Added a 'widget_logic_eval_override' filter. This allows advanced users to bypass EVAL with a function of their own.
204
-
205
- = 0.53 =
206
- Accidentally released code with a terrible bug in it :-(
207
-
208
- = 0.52 =
209
- Two new features: optional delayed loading of logic (see Configuration under [Installation](../installation/)), and the ability to save out and reload all your site's widget logic into a config file
210
-
211
- = 0.51 =
212
- One important bug fix (fairly major and fairly stupid of me too)
213
-
214
- = 0.50 =
215
- For the first time since this started on WP 2.3, I've rewritten how the core widget logic function works, so there may be 'bumps ahead'.
216
-
217
- It now uses the 'sidebars_widgets' filter (as it should have done when that was
218
- introduced in WP2.8 by the look of it). The upshot is that is_active_sidebar should behave properly.
219
-
220
- Widget callbacks only get intercepted if the 'widget_content' filter is activated, and much more briefly. (A widget's 'callback' is rewired within the 'dynamic_sidebar' function just before the widget is called, by the 'dynamic_sidebar_param' filter, and is restored when the callback function is invoked.)
221
-
222
- = 0.48 =
223
- Kill some poor coding practices that throws debug notices - thanks to John James Jacoby.
224
-
225
- = 0.47 =
226
- FINALLY tracked down the elusive 'wp_reset_query' option resetting bug.
227
-
228
- = 0.46 =
229
- Fix to work with new WP2.8 admin ajax. With bonus fixes.
230
-
231
- = 0.44 =
232
- Officially works with 2.7 now. Documentation changes and minor bug fixes.
233
-
234
- = 0.43 =
235
- simple bug fix (form data was being lost when 'Cancel'ing widgets)
236
-
237
- = 0.42 =
238
- WP 2.5+ only now. WP's widget admin has changed so much and I was getting tied up in knots trying to make it work with them both.
239
-
240
- = 0.4 =
241
- Brings WP 2.5 compatibility. I am trying to make it back compatible. If you have trouble using WL with WP 2.1--2.3 let me know the issue. Thanks to Kjetil Flekkoy for reporting and helping to diagnose errors in this version
242
-
243
- = 0.31 =
244
- Last WP 2.3 only version
245
-
246
- == Upgrade Notice ==
247
- = 0.46 =
248
- Required with WP2.8 cos of changes in Widget admin AJAX
249
-
250
- = 0.44 =
251
- Updated for WP2.7 with extra bug fixes
1
  === Widget Logic ===
2
+ Contributors: alanft, wpchefgadget
3
  Donate link: http://www.justgiving.com/widgetlogic_cancerresearchuk
4
  Tags: widget, admin, conditional tags, filter, context
5
+ Requires at least: 3.0
6
+ Tested up to: 4.7.2
7
+ Stable tag: 5.7.0
8
  License: GPLv2 or later
9
 
10
  Widget Logic lets you control on which pages widgets appear using WP's conditional tags. It also adds a 'widget_content' filter.
18
 
19
  = Donations =
20
 
21
+ 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.
 
 
 
 
22
 
23
  == Installation ==
24
 
34
 
35
  * 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
36
 
37
+ * 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):
38
  * after the theme loads (after_setup_theme trigger)
39
  * when all PHP loaded (wp_loaded trigger)
40
+ * after query variables set (parse_query) – this is the default
41
  * during page header (wp_head trigger)
42
 
43
  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.
44
 
45
+ * 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.
46
+
47
  == Frequently Asked Questions ==
48
 
49
+ = I upgraded to Version 5.7.0 and my site's widgets now behave differently =
50
+
51
+ 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'.
52
+
53
+ = What can I try if it's not working? =
54
 
55
+ * Switch to the default theme. If the problem goes away, your theme may be interfering with the WP conditional tags or how widgets work
56
+ * Try the `wp_reset_query` option. If your theme performs custom queries before calling the dynamic sidebar this might help.
57
+ * 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.
58
+ * The 'Evaluate widget logic more than once' option may be needed if you have to use an early 'Load logic' point.
59
 
 
60
 
61
+ = I'm getting errors that read like "PHP Parse error… eval()'d code on line 1" =
 
62
 
63
+ 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.)
64
 
65
+ 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'.
66
+
67
+ = It's causing problems with Woo Commerce / other popular plugin =
68
+
69
+ 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.
70
 
71
  = What's this stuff in my sidebar when there are no widgets? =
72
 
80
 
81
  = Logic using is_page() doesn't work =
82
 
83
+ I believe this is fixed in 5.7.0. Let me know if that is not the case.
84
+
85
  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).
86
 
87
  = How do I get a widget to appear both on a category page and on single posts within that category? =
115
  == Screenshots ==
116
 
117
  1. The 'Widget logic' field at work in standard widgets.
118
+ 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.
119
+
120
+ == Changelog ==
121
+
122
+ = 5.7.0 =
123
+ Fixed PHP 7 compatibility issue.
124
+
125
+ Fixed a conflict with the latest WPML plugin.
126
+
127
+ A new default load logic point attached to the action 'parse_query'. By default the widget logic is only evaluated once.
128
+
129
+ Translation added: Ukrainian by Roman Sulym
130
+
131
+ = 0.57 =
132
+ Small fixes to satisfy some define('WP_DEBUG', true) errors
133
+
134
+ = 0.56 =
135
+ Small fix to the original WP3.5 fix in 0.54 that had the side effect of failing to save logic text on newly added widgets.
136
+
137
+ = 0.55 =
138
+ Restored a striplashes that vanished in 0.54 causing much grief.
139
+
140
+ Translation: Spanish by Eduardo Larequi http://wordpress.org/support/profile/elarequi
141
+
142
+ = 0.54 =
143
+ Removed a WP 3.1+ function call, hopefully making it 2.8 compatible again.
144
+
145
+ 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.
146
+
147
+ Translation support! Thanks to Foe Services Labs http://wordpress.org/support/profile/cfoellmann for the work on this and the German Social Translation
148
+
149
+ Added a 'widget_logic_eval_override' filter. This allows advanced users to bypass EVAL with a function of their own.
150
+
151
+ = 0.53 =
152
+ Accidentally released code with a terrible bug in it :-(
153
+
154
+ = 0.52 =
155
+ Two new features: optional delayed loading of logic (see Configuration under [Installation](../installation/)), and the ability to save out and reload all your site's widget logic into a config file
156
+
157
+ = 0.51 =
158
+ One important bug fix (fairly major and fairly stupid of me too)
159
+
160
+ = 0.50 =
161
+ For the first time since this started on WP 2.3, I've rewritten how the core widget logic function works, so there may be 'bumps ahead'.
162
+
163
+ It now uses the 'sidebars_widgets' filter (as it should have done when that was
164
+ introduced in WP2.8 by the look of it). The upshot is that is_active_sidebar should behave properly.
165
+
166
+ Widget callbacks only get intercepted if the 'widget_content' filter is activated, and much more briefly. (A widget's 'callback' is rewired within the 'dynamic_sidebar' function just before the widget is called, by the 'dynamic_sidebar_param' filter, and is restored when the callback function is invoked.)
167
+
168
+ = 0.48 =
169
+ Kill some poor coding practices that throws debug notices - thanks to John James Jacoby.
170
+
171
+ = 0.47 =
172
+ FINALLY tracked down the elusive 'wp_reset_query' option resetting bug.
173
+
174
+ = 0.46 =
175
+ Fix to work with new WP2.8 admin ajax. With bonus fixes.
176
+
177
+ = 0.44 =
178
+ Officially works with 2.7 now. Documentation changes and minor bug fixes.
179
+
180
+ = 0.43 =
181
+ simple bug fix (form data was being lost when 'Cancel'ing widgets)
182
+
183
+ = 0.42 =
184
+ WP 2.5+ only now. WP's widget admin has changed so much and I was getting tied up in knots trying to make it work with them both.
185
+
186
+ = 0.4 =
187
+ Brings WP 2.5 compatibility. I am trying to make it back compatible. If you have trouble using WL with WP 2.1--2.3 let me know the issue. Thanks to Kjetil Flekkoy for reporting and helping to diagnose errors in this version
188
+
189
+ = 0.31 =
190
+ Last WP 2.3 only version
191
+
192
+ == Upgrade Notice ==
193
+
194
+ = 0.58 =
195
+ 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.
196
+
197
+ = 0.46 =
198
+ Required with WP2.8 cos of changes in Widget admin AJAX
199
+
200
+ = 0.44 =
201
+ Updated for WP2.7 with extra bug fixes
202
+
203
 
204
  == Writing Logic Code ==
205
 
272
  $wl_make_alt_ws=($wl_make_alt_ws=="style_a")?"style_b":"style_a";
273
  return preg_replace('/(class="widget )/', "$1 widget_${wl_make_alt_ws} ", $content);
274
  }`
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
screenshot-1.png CHANGED
Binary file
screenshot-2.png CHANGED
Binary file
widget_logic.php CHANGED
@@ -3,47 +3,98 @@
3
  Plugin Name: Widget Logic
4
  Plugin URI: http://wordpress.org/extend/plugins/widget-logic/
5
  Description: Control widgets with WP's conditional tags is_home etc
6
- Version: 0.57
7
- Author: Alan Trewartha
8
- Author URI: http://freakytrigger.co.uk/author/alan/
9
-
10
  Text Domain: widget-logic
11
  Domain Path: /languages/
12
- */
13
 
14
- $plugin_dir = basename(dirname(__FILE__));
15
- load_plugin_textdomain( 'widget-logic', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
 
17
  global $wl_options;
18
- $wl_load_points=array( 'plugins_loaded' => __( 'when plugin starts (default)', 'widget-logic' ),
19
- 'after_setup_theme' => __( 'after theme loads', 'widget-logic' ),
20
- 'wp_loaded' => __( 'when all PHP loaded', 'widget-logic' ),
21
- 'wp_head' => __( 'during page header', 'widget-logic' )
22
- );
23
 
24
- if((!$wl_options = get_option('widget_logic')) || !is_array($wl_options) ) $wl_options = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  if (is_admin())
27
  {
28
- add_filter( 'widget_update_callback', 'widget_logic_ajax_update_callback', 10, 3); // widget changes submitted by ajax method
29
  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
30
  add_action( 'sidebar_admin_page', 'widget_logic_options_control'); // add Widget Logic specific options on the widget admin page
31
  add_filter( 'plugin_action_links', 'wl_charity', 10, 2); // add my justgiving page link to the plugin admin page
32
  }
33
  else
34
  {
35
- if ( isset($wl_options['widget_logic-options-load_point']) &&
36
- ($wl_options['widget_logic-options-load_point']!='plugins_loaded') &&
37
- array_key_exists($wl_options['widget_logic-options-load_point'],$wl_load_points )
38
- )
39
- add_action ($wl_options['widget_logic-options-load_point'],'widget_logic_sidebars_widgets_filter_add');
40
- else
41
  widget_logic_sidebars_widgets_filter_add();
42
-
 
 
 
 
 
 
 
43
  if ( isset($wl_options['widget_logic-options-filter']) && $wl_options['widget_logic-options-filter'] == 'checked' )
44
- add_filter( 'dynamic_sidebar_params', 'widget_logic_widget_display_callback', 10); // redirect the widget callback so the output can be buffered and filtered
 
45
  }
46
 
 
 
 
 
47
  function widget_logic_sidebars_widgets_filter_add()
48
  {
49
  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 +104,13 @@ function widget_logic_sidebars_widgets_filter_add()
53
 
54
 
55
  // CALLED VIA 'widget_update_callback' FILTER (ajax update of a widget)
56
- function widget_logic_ajax_update_callback($instance, $new_instance, $this_widget)
57
- { global $wl_options;
 
58
  $widget_id=$this_widget->id;
59
  if ( isset($_POST[$widget_id.'-widget_logic']))
60
- { $wl_options[$widget_id]=trim($_POST[$widget_id.'-widget_logic']);
 
61
  update_option('widget_logic', $wl_options);
62
  }
63
  return $instance;
@@ -75,7 +128,7 @@ function widget_logic_expand_control()
75
  {
76
  header("Content-Disposition: attachment; filename=widget_logic_options.txt");
77
  header('Content-Type: text/plain; charset=utf-8');
78
-
79
  echo "[START=WIDGET LOGIC OPTIONS]\n";
80
  foreach ($wl_options as $id => $text)
81
  echo "$id\t".json_encode($text)."\n";
@@ -87,10 +140,10 @@ function widget_logic_expand_control()
87
  // IMPORT ALL OPTIONS
88
  if ( isset($_POST['wl-options-import']))
89
  { if ($_FILES['wl-options-import-file']['tmp_name'])
90
- { $import=split("\n",file_get_contents($_FILES['wl-options-import-file']['tmp_name'], false));
91
  if (array_shift($import)=="[START=WIDGET LOGIC OPTIONS]" && array_pop($import)=="[STOP=WIDGET LOGIC OPTIONS]")
92
  { foreach ($import as $import_option)
93
- { list($key, $value)=split("\t",$import_option);
94
  $wl_options[$key]=json_decode($value);
95
  }
96
  $wl_options['msg']= __('Success! Options file imported','widget-logic');
@@ -98,11 +151,11 @@ function widget_logic_expand_control()
98
  else
99
  { $wl_options['msg']= __('Invalid options file','widget-logic');
100
  }
101
-
102
  }
103
  else
104
  $wl_options['msg']= __('No options file provided','widget-logic');
105
-
106
  update_option('widget_logic', $wl_options);
107
  wp_redirect( admin_url('widgets.php') );
108
  exit;
@@ -117,18 +170,20 @@ function widget_logic_expand_control()
117
  wp_register_widget_control($id,$widget['name'], 'widget_logic_empty_control');
118
  $wp_registered_widget_controls[$id]['callback_wl_redirect']=$wp_registered_widget_controls[$id]['callback'];
119
  $wp_registered_widget_controls[$id]['callback']='widget_logic_extra_control';
120
- array_push($wp_registered_widget_controls[$id]['params'],$id);
121
  }
122
 
123
 
124
  // UPDATE WIDGET LOGIC WIDGET OPTIONS (via accessibility mode?)
125
  if ( 'post' == strtolower($_SERVER['REQUEST_METHOD']) )
126
- { foreach ( (array) $_POST['widget-id'] as $widget_number => $widget_id )
 
 
127
  if (isset($_POST[$widget_id.'-widget_logic']))
128
  $wl_options[$widget_id]=trim($_POST[$widget_id.'-widget_logic']);
129
-
130
  // clean up empty options (in PHP5 use array_intersect_key)
131
- $regd_plus_new=array_merge(array_keys($wp_registered_widgets),array_values((array) $_POST['widget-id']),
132
  array('widget_logic-options-filter', 'widget_logic-options-wp_reset_query', 'widget_logic-options-load_point'));
133
  foreach (array_keys($wl_options) as $key)
134
  if (!in_array($key, $regd_plus_new))
@@ -138,8 +193,8 @@ function widget_logic_expand_control()
138
  // UPDATE OTHER WIDGET LOGIC OPTIONS
139
  // must update this to use http://codex.wordpress.org/Settings_API
140
  if ( isset($_POST['widget_logic-options-submit']) )
141
- { $wl_options['widget_logic-options-filter']=$_POST['widget_logic-options-filter'];
142
- $wl_options['widget_logic-options-wp_reset_query']=$_POST['widget_logic-options-wp_reset_query'];
143
  $wl_options['widget_logic-options-load_point']=$_POST['widget_logic-options-load_point'];
144
  }
145
 
@@ -155,7 +210,7 @@ function widget_logic_expand_control()
155
  // output extra HTML
156
  // to update using http://codex.wordpress.org/Settings_API asap
157
  function widget_logic_options_control()
158
- { global $wp_registered_widget_controls, $wl_options, $wl_load_points;
159
 
160
  if ( isset($wl_options['msg']))
161
  { if (substr($wl_options['msg'],0,2)=="OK")
@@ -169,7 +224,7 @@ function widget_logic_options_control()
169
 
170
 
171
  ?><div class="wrap">
172
-
173
  <h2><?php _e('Widget Logic options', 'widget-logic'); ?></h2>
174
  <form method="POST" style="float:left; width:45%">
175
  <ul>
@@ -185,11 +240,18 @@ function widget_logic_options_control()
185
  </li>
186
  <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'); ?>
187
  <select id="widget_logic-options-load_point" name="widget_logic-options-load_point" ><?php
 
 
 
 
 
 
 
188
  foreach($wl_load_points as $action => $action_desc)
189
  { echo "<option value='".$action."'";
190
  if (isset($wl_options['widget_logic-options-load_point']) && $action==$wl_options['widget_logic-options-load_point'])
191
  echo " selected ";
192
- echo ">".$action_desc."</option>"; //
193
  }
194
  ?>
195
  </select>
@@ -225,8 +287,8 @@ function widget_logic_extra_control()
225
  // go to the original control function
226
  $callback=$wp_registered_widget_controls[$id]['callback_wl_redirect'];
227
  if (is_callable($callback))
228
- call_user_func_array($callback, $params);
229
-
230
  $value = !empty( $wl_options[$id ] ) ? htmlspecialchars( stripslashes( $wl_options[$id ] ),ENT_QUOTES ) : '';
231
 
232
  // dealing with multiple widgets - get the number. if -1 this is the 'template' for the admin interface
@@ -236,9 +298,25 @@ function widget_logic_extra_control()
236
  if ($number==-1) {$number="__i__"; $value="";}
237
  $id_disp=$wp_registered_widget_controls[$id]['id_base'].'-'.$number;
238
  }
239
-
240
  // output our extra widget logic field
241
  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>";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  }
243
 
244
 
@@ -283,8 +361,24 @@ function widget_logic_filter_sidebars_widgets($sidebars_widgets)
283
  if (stristr($wl_value,"return")===false)
284
  $wl_value="return (" . $wl_value . ");";
285
 
286
- if (!eval($wl_value))
287
- unset($sidebars_widgets[$widget_area][$pos]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
288
  }
289
  }
290
  return $sidebars_widgets;
@@ -318,7 +412,7 @@ function widget_logic_redirected_callback()
318
  $wp_registered_widgets[$id]['callback']=$callback;
319
 
320
  // run the callback but capture and filter the output using PHP output buffering
321
- if ( is_callable($callback) )
322
  { ob_start();
323
  call_user_func_array($callback, $params);
324
  $widget_content = ob_get_contents();
@@ -328,5 +422,71 @@ function widget_logic_redirected_callback()
328
  }
329
 
330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
331
 
332
  ?>
3
  Plugin Name: Widget Logic
4
  Plugin URI: http://wordpress.org/extend/plugins/widget-logic/
5
  Description: Control widgets with WP's conditional tags is_home etc
6
+ Version: 5.7.0
7
+ Author: alanft, wpchefgadget
8
+
 
9
  Text Domain: widget-logic
10
  Domain Path: /languages/
11
+ */
12
 
13
+ DEFINE( 'WIDGET_LOGIC_VERSION', '5.7.0' );
14
+
15
+ register_activation_hook( __FILE__, 'widget_logic_activate' );
16
+
17
+ function widget_logic_activate()
18
+ {
19
+ $promo = (array)get_option( 'wpchefgadget_promo', array() );
20
+ if ( !empty( $promo['limit-login-attempts'] ) )
21
+ {
22
+ unset( $promo['limit-login-attempts'] );
23
+ add_option( 'wpchefgadget_promo', $promo, '', 'no' );
24
+ update_option( 'wpchefgadget_promo', $promo );
25
+ }
26
+ add_option( 'widget_logic_version', WIDGET_LOGIC_VERSION, '', 'no' );
27
+ update_option( 'widget_logic_version', WIDGET_LOGIC_VERSION );
28
+ }
29
 
30
+ $plugin_dir = basename(dirname(__FILE__));
31
  global $wl_options;
 
 
 
 
 
32
 
33
+ add_action( 'init', 'widget_logic_init' );
34
+ function widget_logic_init()
35
+ {
36
+ load_plugin_textdomain( 'widget-logic', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
37
+
38
+ /*
39
+ if ( ! )
40
+ return;
41
+
42
+ if ( )
43
+ return;
44
+ */
45
+ if ( is_admin() )
46
+ {
47
+ if ( get_option('widget_logic_version') != WIDGET_LOGIC_VERSION )
48
+ widget_logic_activate();
49
+
50
+ if ( !file_exists(WP_PLUGIN_DIR.'/limit-login-attempts-reloaded') && current_user_can('install_plugins') )
51
+ {
52
+ $promo = (array)get_option( 'wpchefgadget_promo', array() );
53
+ if ( empty( $promo['limit-login-attempts'] ) )
54
+ {
55
+ add_action( 'admin_notices', 'widget_logic_promo');
56
+ add_action( 'network_admin_notices', 'widget_logic_promo');
57
+ add_action( 'wp_ajax_wpchefgadget_dissmiss_promo', 'widgel_logic_dissmiss_promo' );
58
+ add_action( 'admin_enqueue_scripts', 'widget_logic_promo_scripts' );
59
+ }
60
+ //enqueue admin/js/updates.js
61
+ }
62
+ }
63
+
64
+ }
65
+
66
+ if((!$wl_options = get_option('widget_logic')) || !is_array($wl_options) )
67
+ $wl_options = array();
68
 
69
  if (is_admin())
70
  {
71
+ add_filter( 'widget_update_callback', 'widget_logic_ajax_update_callback', 10, 4); // widget changes submitted by ajax method
72
  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
73
  add_action( 'sidebar_admin_page', 'widget_logic_options_control'); // add Widget Logic specific options on the widget admin page
74
  add_filter( 'plugin_action_links', 'wl_charity', 10, 2); // add my justgiving page link to the plugin admin page
75
  }
76
  else
77
  {
78
+ $loadpoint = (string)@$wl_options['widget_logic-options-load_point'];
79
+ if ( 'plugins_loaded' == $loadpoint )
 
 
 
 
80
  widget_logic_sidebars_widgets_filter_add();
81
+ else
82
+ {
83
+ if ( !in_array( $loadpoint, array( 'after_setup_theme', 'wp_loaded', 'wp_head' ) ) )
84
+ $loadpoint = 'parse_query';
85
+
86
+ add_action( $loadpoint, 'widget_logic_sidebars_widgets_filter_add' );
87
+ }
88
+
89
  if ( isset($wl_options['widget_logic-options-filter']) && $wl_options['widget_logic-options-filter'] == 'checked' )
90
+ add_filter( 'dynamic_sidebar_params', 'widget_logic_widget_display_callback', 10);
91
+ // redirect the widget callback so the output can be buffered and filtered
92
  }
93
 
94
+
95
+
96
+
97
+
98
  function widget_logic_sidebars_widgets_filter_add()
99
  {
100
  add_filter( 'sidebars_widgets', 'widget_logic_filter_sidebars_widgets', 10); // actually remove the widgets from the front end depending on widget logic provided
104
 
105
 
106
  // CALLED VIA 'widget_update_callback' FILTER (ajax update of a widget)
107
+ function widget_logic_ajax_update_callback($instance, $new_instance, $old_instance, $this_widget)
108
+ {
109
+ global $wl_options;
110
  $widget_id=$this_widget->id;
111
  if ( isset($_POST[$widget_id.'-widget_logic']))
112
+ {
113
+ $wl_options[$widget_id]=trim($_POST[$widget_id.'-widget_logic']);
114
  update_option('widget_logic', $wl_options);
115
  }
116
  return $instance;
128
  {
129
  header("Content-Disposition: attachment; filename=widget_logic_options.txt");
130
  header('Content-Type: text/plain; charset=utf-8');
131
+
132
  echo "[START=WIDGET LOGIC OPTIONS]\n";
133
  foreach ($wl_options as $id => $text)
134
  echo "$id\t".json_encode($text)."\n";
140
  // IMPORT ALL OPTIONS
141
  if ( isset($_POST['wl-options-import']))
142
  { if ($_FILES['wl-options-import-file']['tmp_name'])
143
+ { $import=explode("\n",file_get_contents($_FILES['wl-options-import-file']['tmp_name'], false));
144
  if (array_shift($import)=="[START=WIDGET LOGIC OPTIONS]" && array_pop($import)=="[STOP=WIDGET LOGIC OPTIONS]")
145
  { foreach ($import as $import_option)
146
+ { list($key, $value)=explode("\t",$import_option);
147
  $wl_options[$key]=json_decode($value);
148
  }
149
  $wl_options['msg']= __('Success! Options file imported','widget-logic');
151
  else
152
  { $wl_options['msg']= __('Invalid options file','widget-logic');
153
  }
154
+
155
  }
156
  else
157
  $wl_options['msg']= __('No options file provided','widget-logic');
158
+
159
  update_option('widget_logic', $wl_options);
160
  wp_redirect( admin_url('widgets.php') );
161
  exit;
170
  wp_register_widget_control($id,$widget['name'], 'widget_logic_empty_control');
171
  $wp_registered_widget_controls[$id]['callback_wl_redirect']=$wp_registered_widget_controls[$id]['callback'];
172
  $wp_registered_widget_controls[$id]['callback']='widget_logic_extra_control';
173
+ array_push($wp_registered_widget_controls[$id]['params'],$id);
174
  }
175
 
176
 
177
  // UPDATE WIDGET LOGIC WIDGET OPTIONS (via accessibility mode?)
178
  if ( 'post' == strtolower($_SERVER['REQUEST_METHOD']) )
179
+ {
180
+ $widgt_ids = (array)@$_POST['widget-id'];
181
+ foreach ( $widgt_ids as $widget_number => $widget_id )
182
  if (isset($_POST[$widget_id.'-widget_logic']))
183
  $wl_options[$widget_id]=trim($_POST[$widget_id.'-widget_logic']);
184
+
185
  // clean up empty options (in PHP5 use array_intersect_key)
186
+ $regd_plus_new=array_merge(array_keys($wp_registered_widgets),array_values($widgt_ids),
187
  array('widget_logic-options-filter', 'widget_logic-options-wp_reset_query', 'widget_logic-options-load_point'));
188
  foreach (array_keys($wl_options) as $key)
189
  if (!in_array($key, $regd_plus_new))
193
  // UPDATE OTHER WIDGET LOGIC OPTIONS
194
  // must update this to use http://codex.wordpress.org/Settings_API
195
  if ( isset($_POST['widget_logic-options-submit']) )
196
+ { $wl_options['widget_logic-options-filter'] = !empty($_POST['widget_logic-options-filter']);
197
+ $wl_options['widget_logic-options-wp_reset_query'] = !empty($_POST['widget_logic-options-wp_reset_query']);
198
  $wl_options['widget_logic-options-load_point']=$_POST['widget_logic-options-load_point'];
199
  }
200
 
210
  // output extra HTML
211
  // to update using http://codex.wordpress.org/Settings_API asap
212
  function widget_logic_options_control()
213
+ { global $wp_registered_widget_controls, $wl_options;
214
 
215
  if ( isset($wl_options['msg']))
216
  { if (substr($wl_options['msg'],0,2)=="OK")
224
 
225
 
226
  ?><div class="wrap">
227
+
228
  <h2><?php _e('Widget Logic options', 'widget-logic'); ?></h2>
229
  <form method="POST" style="float:left; width:45%">
230
  <ul>
240
  </li>
241
  <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'); ?>
242
  <select id="widget_logic-options-load_point" name="widget_logic-options-load_point" ><?php
243
+ $wl_load_points = array(
244
+ 'parse_query' => __( 'after query variables set (default)', 'widget-logic' ),
245
+ 'plugins_loaded' => __( 'when plugin starts', 'widget-logic' ),
246
+ 'after_setup_theme' => __( 'after theme loads', 'widget-logic' ),
247
+ 'wp_loaded' => __( 'when all PHP loaded', 'widget-logic' ),
248
+ 'wp_head' => __( 'during page header', 'widget-logic' )
249
+ );
250
  foreach($wl_load_points as $action => $action_desc)
251
  { echo "<option value='".$action."'";
252
  if (isset($wl_options['widget_logic-options-load_point']) && $action==$wl_options['widget_logic-options-load_point'])
253
  echo " selected ";
254
+ echo ">".$action_desc."</option>"; //
255
  }
256
  ?>
257
  </select>
287
  // go to the original control function
288
  $callback=$wp_registered_widget_controls[$id]['callback_wl_redirect'];
289
  if (is_callable($callback))
290
+ call_user_func_array($callback, $params);
291
+
292
  $value = !empty( $wl_options[$id ] ) ? htmlspecialchars( stripslashes( $wl_options[$id ] ),ENT_QUOTES ) : '';
293
 
294
  // dealing with multiple widgets - get the number. if -1 this is the 'template' for the admin interface
298
  if ($number==-1) {$number="__i__"; $value="";}
299
  $id_disp=$wp_registered_widget_controls[$id]['id_base'].'-'.$number;
300
  }
 
301
  // output our extra widget logic field
302
  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>";
303
+ if ( trim($value) && version_compare( PHP_VERSION, '7.0', '>=' ) )
304
+ {
305
+ $test = '$result = ('.$wl_options[$id ].'); return true;';
306
+ try {
307
+ eval($test);
308
+ } catch ( Error $e )
309
+ {
310
+ ?>
311
+ <div class="notice notice-error inline">
312
+ <p>
313
+ The code triggered a PHP error. It might still work on the front-end though b/c of different code environment.
314
+ <br><code><?php esc_html_e($e->getMessage()) ?></code>
315
+ </p>
316
+ </div>
317
+ <?php
318
+ }
319
+ }
320
  }
321
 
322
 
361
  if (stristr($wl_value,"return")===false)
362
  $wl_value="return (" . $wl_value . ");";
363
 
364
+ $save = ini_get('display_errors');
365
+ try {
366
+ if ( current_user_can('manage_options') )
367
+ ini_set( 'display_errors', 'On' );
368
+
369
+ if (!eval($wl_value))
370
+ unset($sidebars_widgets[$widget_area][$pos]);
371
+
372
+ ini_set( 'display_errors', $save );
373
+ }
374
+ catch ( Error $e ) {
375
+ if ( current_user_can('manage_options') )
376
+ trigger_error( 'Invalid Widget Logic: '.$e->getMessage(), E_USER_WARNING );
377
+
378
+ ini_set( 'display_errors', $save );
379
+ continue;
380
+ }
381
+
382
  }
383
  }
384
  return $sidebars_widgets;
412
  $wp_registered_widgets[$id]['callback']=$callback;
413
 
414
  // run the callback but capture and filter the output using PHP output buffering
415
+ if ( is_callable($callback) )
416
  { ob_start();
417
  call_user_func_array($callback, $params);
418
  $widget_content = ob_get_contents();
422
  }
423
 
424
 
425
+ function widget_logic_promo()
426
+ {
427
+ $screen = get_current_screen();
428
+
429
+ ?>
430
+ <div class="notice notice-error is-dismissible" id="wpchefgadget_promo_lla">
431
+ <p class="plugin-card-limit-login-attempts-reloaded"<?php if ( $screen->id != 'plugin-install' ) echo ' id="plugin-filter"' ?>>
432
+ <b>Widget Logic team security recommendation:</b> It appears your site might NOT be currently protected against login attacks. This is 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 prevent this.
433
+ <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_promo_install_button">Install</a>
434
+ <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>
435
+ </p>
436
+ </div>
437
+ <script>
438
+ jQuery('#wpchefgadget_promo_lla .open-plugin-details-modal').on('click', function(){
439
+ jQuery('#wpchef_promo_install_button').hide().next().show();
440
+ return true;
441
+ });
442
+ jQuery(function($){
443
+ var promo = $('#wpchefgadget_promo_lla');
444
+ promo.on('click', '.notice-dismiss', function(e){
445
+ //e.preventDefault
446
+ $.post( ajaxurl, {
447
+ action: 'wpchefgadget_dissmiss_promo',
448
+ promo: 'limit-login-attempts',
449
+ sec: <?php echo json_encode( wp_create_nonce('wpchefgadget_dissmiss_promo') ) ?>
450
+ } );
451
+ });
452
+
453
+ <?php if ( $screen->id == 'plugin-install' ): ?>
454
+ $('#plugin-filter').prepend( promo.css('margin-bottom','10px').addClass('inline') );
455
+ <?php endif ?>
456
+
457
+ $(document).on('tb_unload', function(){
458
+ if ( jQuery('#wpchef_promo_install_button').next().hasClass('updating-message') )
459
+ return;
460
+
461
+ jQuery('#wpchef_promo_install_button').show().next().hide();
462
+ });
463
+ $(document).on('credential-modal-cancel', function(){
464
+ jQuery('#wpchef_promo_install_button').show().next().hide();
465
+ });
466
+ });
467
+ </script>
468
+ <?php
469
+ wp_print_request_filesystem_credentials_modal();
470
+ }
471
+
472
+ function widgel_logic_dissmiss_promo()
473
+ {
474
+ check_ajax_referer( 'wpchefgadget_dissmiss_promo', 'sec' );
475
+
476
+ $promo = (array)get_option( 'wpchefgadget_promo', array() );
477
+ $promo[ $_POST['promo'] ] = 1;
478
+
479
+ add_option( 'wpchefgadget_promo', $promo, '', 'no' );
480
+ update_option( 'wpchefgadget_promo', $promo );
481
+
482
+ exit;
483
+ }
484
+
485
+ function widget_logic_promo_scripts()
486
+ {
487
+ wp_enqueue_script( 'plugin-install' );
488
+ add_thickbox();
489
+ wp_enqueue_script( 'updates' );
490
+ }
491
 
492
  ?>