Restrict Widgets - Version 1.2.0

Version Description

  • New: Multisite support
  • New: Option to hide / show widget depending on the device (mobile or not)
  • New: bbPress specific options for hide / show widget
  • Fix: get_class error on widgets not using Widgets API
  • Fix: Logged-in or out users option not working properly
Download this release

Release Info

Developer dfactory
Plugin Icon 128x128 Restrict Widgets
Version 1.2.0
Comparing to
See all releases

Code changes from version 1.1.4 to 1.2.0

js/restrict-widgets-admin.js CHANGED
@@ -1,65 +1,43 @@
1
- (function ($)
2
- {
3
- $(document).ready(function ()
4
- {
5
-
6
- $('#widgets-left').append($('#widgets-options'));
7
-
8
- for(i in restrict_widgets_args.restrict_widgets)
9
- {
10
- $("div[id*='"+restrict_widgets_args.restrict_widgets[i]+"'] div").remove();
11
- }
12
 
13
- for(i in restrict_widgets_args.restrict_class)
14
- {
15
- $("div[id*='"+restrict_widgets_args.restrict_class[i]+"-__i__']").remove();
16
- }
17
 
18
- for(i in restrict_widgets_args.restrict_nonclass)
19
- {
20
- $("div[id*='_"+restrict_widgets_args.restrict_nonclass[i]+"']").remove();
21
- }
22
 
23
- if(restrict_widgets_args.restrict_orphan_sidebar == 1)
24
- {
25
- $('.orphan-sidebar').remove();
26
- }
27
 
28
- $('#options-available-widgets').chosen({
29
- placeholder_text: restrict_widgets_args.restrict_available_widgets
30
- });
31
- $('#options-widgets-selection').chosen({
32
- placeholder_text: restrict_widgets_args.restrict_widgets_selection
33
- });
34
- $('#options-widgets-sidebars').chosen({
35
- placeholder_text: restrict_widgets_args.restrict_sidebars
36
- });
37
- $('#options-widgets-roles').chosen({
38
- placeholder_text: restrict_widgets_args.restrict_roles
39
- });
40
 
41
- });
 
 
 
 
 
 
 
42
 
43
  $(document).on('mouseover', '#widgets-right, .inactive-sidebar', function() {
44
-
45
  $(this).find('.restrict-widgets-hide').chosen({
46
  allow_single_deselect: true,
47
  disable_search: true
48
  });
49
- $(this).find('.restrict-widgets-select').chosen({
50
- placeholder_text: restrict_widgets_args.placeholder_text
51
- });
52
 
 
53
  });
54
-
55
  $(document).on('ajaxStop', function() {
56
  $('#widgets-right .restrict-widgets-hide, .inactive-sidebar .restrict-widgets-hide').chosen({
57
  allow_single_deselect: true,
58
  disable_search: true
59
  });
60
- $('#widgets-right .restrict-widgets-select, .inactive-sidebar .restrict-widgets-select').chosen({
61
- placeholder_text: restrict_widgets_args.placeholder_text
62
- });
63
  });
64
-
65
- })(jQuery);
1
+ jQuery(document).ready(function ($) {
 
 
 
 
 
 
 
 
 
 
2
 
3
+ $('#widgets-left').append($('#widgets-options'));
 
 
 
4
 
5
+ for(i in rwArgs.restrict_widgets) {
6
+ $("div[id*='"+rwArgs.restrict_widgets[i]+"'] div").remove();
7
+ }
 
8
 
9
+ for(i in rwArgs.restrict_class) {
10
+ $("div[id*='"+rwArgs.restrict_class[i]+"-__i__']").remove();
11
+ }
 
12
 
13
+ for(i in rwArgs.restrict_nonclass) {
14
+ $("div[id*='_"+rwArgs.restrict_nonclass[i]+"']").remove();
15
+ }
 
 
 
 
 
 
 
 
 
16
 
17
+ if(rwArgs.restrict_orphan_sidebar == 1) {
18
+ $('.orphan-sidebar').remove();
19
+ }
20
+
21
+ $('#options-available-widgets').chosen({placeholder_text: rwArgs.restrict_available_widgets});
22
+ $('#options-widgets-selection').chosen({placeholder_text: rwArgs.restrict_widgets_selection});
23
+ $('#options-widgets-sidebars').chosen({placeholder_text: rwArgs.restrict_sidebars});
24
+ $('#options-widgets-roles').chosen({placeholder_text: rwArgs.restrict_roles});
25
 
26
  $(document).on('mouseover', '#widgets-right, .inactive-sidebar', function() {
 
27
  $(this).find('.restrict-widgets-hide').chosen({
28
  allow_single_deselect: true,
29
  disable_search: true
30
  });
 
 
 
31
 
32
+ $(this).find('.restrict-widgets-select').chosen({placeholder_text: rwArgs.placeholder_text});
33
  });
34
+
35
  $(document).on('ajaxStop', function() {
36
  $('#widgets-right .restrict-widgets-hide, .inactive-sidebar .restrict-widgets-hide').chosen({
37
  allow_single_deselect: true,
38
  disable_search: true
39
  });
40
+
41
+ $('#widgets-right .restrict-widgets-select, .inactive-sidebar .restrict-widgets-select').chosen({placeholder_text: rwArgs.placeholder_text});
 
42
  });
43
+ });
 
languages/restrict-widgets-pl_PL.mo CHANGED
Binary file
languages/restrict-widgets-pl_PL.po CHANGED
@@ -1,203 +1,231 @@
1
- msgid ""
2
- msgstr ""
3
- "Project-Id-Version: Restrict Widgets\n"
4
- "POT-Creation-Date: 2013-09-04 09:23+0100\n"
5
- "PO-Revision-Date: 2013-09-04 09:23+0100\n"
6
- "Last-Translator: Bartosz Arendt <info@digitalfactory.pl>\n"
7
- "Language-Team: dFactory <info@dfactory.eu>\n"
8
- "Language: English\n"
9
- "MIME-Version: 1.0\n"
10
- "Content-Type: text/plain; charset=UTF-8\n"
11
- "Content-Transfer-Encoding: 8bit\n"
12
- "X-Generator: Poedit 1.5.7\n"
13
- "X-Poedit-KeywordsList: gettext;gettext_noop;__;_e\n"
14
- "X-Poedit-Basepath: .\n"
15
- "X-Poedit-SourceCharset: UTF-8\n"
16
- "X-Poedit-SearchPath-0: ..\n"
17
-
18
- #: ../restrict-widgets.php:175
19
- msgid "Support"
20
- msgstr "Forum pomocy"
21
-
22
- #: ../restrict-widgets.php:197 ../restrict-widgets.php:1475
23
- #: ../restrict-widgets.php:1520
24
- msgid "Widgets"
25
- msgstr "Widgety"
26
-
27
- #: ../restrict-widgets.php:333
28
- msgid "Pages"
29
- msgstr "Strony"
30
-
31
- #: ../restrict-widgets.php:334
32
- msgid "Custom Post Types"
33
- msgstr "Własne typy wpisów"
34
-
35
- #: ../restrict-widgets.php:335
36
- msgid "Custom Post Type Archives"
37
- msgstr "Archiwa własnych typów wpisów"
38
-
39
- #: ../restrict-widgets.php:336
40
- msgid "Categories"
41
- msgstr "Kategorie"
42
-
43
- #: ../restrict-widgets.php:337
44
- msgid "Taxonomies"
45
- msgstr "Taksonomie"
46
-
47
- #: ../restrict-widgets.php:338
48
- msgid "Others"
49
- msgstr "Inne"
50
-
51
- #: ../restrict-widgets.php:339
52
- msgid "Users"
53
- msgstr "Użytkownicy"
54
-
55
- #: ../restrict-widgets.php:340
56
- msgid "Languages"
57
- msgstr "Języki"
58
-
59
- #: ../restrict-widgets.php:344
60
- msgid "Front Page"
61
- msgstr "Strona główna"
62
-
63
- #: ../restrict-widgets.php:345
64
- msgid "Blog Page"
65
- msgstr "Strona z wpisami"
66
-
67
- #: ../restrict-widgets.php:346
68
- msgid "Single Posts"
69
- msgstr "Pojedyncze wpisy"
70
-
71
- #: ../restrict-widgets.php:347
72
- msgid "Sticky Posts"
73
- msgstr "Wpisy przyklejone"
74
-
75
- #: ../restrict-widgets.php:348
76
- msgid "Author Archive"
77
- msgstr "Archiwum autora"
78
-
79
- #: ../restrict-widgets.php:349
80
- msgid "Date Archive"
81
- msgstr "Archiwum daty"
82
-
83
- #: ../restrict-widgets.php:350
84
- msgid "404 Page"
85
- msgstr "Strona błędów 404"
86
-
87
- #: ../restrict-widgets.php:351
88
- msgid "Search Page"
89
- msgstr "Strona wyszukiwania"
90
-
91
- #: ../restrict-widgets.php:355
92
- msgid "Logged in users"
93
- msgstr "Zalogowani użytkownicy"
94
-
95
- #: ../restrict-widgets.php:356
96
- msgid "Logged out users"
97
- msgstr "Wylogowani użytkownicy"
98
-
99
- #: ../restrict-widgets.php:579
100
- msgid "Restrict widgets"
101
- msgstr "Ograniczenia widgetów"
102
-
103
- #: ../restrict-widgets.php:583
104
- msgid ""
105
- "Use this settings to manage access to widgets page and to restrict "
106
- "availability of certain widgets, sidebars and widgets options to site "
107
- "administrators only."
108
- msgstr ""
109
- "Użyj tych ustawień aby określić kto może mieć dostęp do widgetów, jakie "
110
- "widgety, panele boczne i ustawienia widgetów są dostępne dla użytkowników a "
111
- "jakie tylko dla administratorów."
112
-
113
- #: ../restrict-widgets.php:586
114
- msgid "Restrict Users"
115
- msgstr "Ograniczenia użytkowników"
116
-
117
- #: ../restrict-widgets.php:596
118
- msgid "Select user roles restricted to manage widgets."
119
- msgstr "Wybierz role użytkowników, którzy mogą zarządzać widgetami."
120
-
121
- #: ../restrict-widgets.php:600
122
- msgid "Restrict Sidebars"
123
- msgstr "Ograniczenia paneli bocznych"
124
-
125
- #: ../restrict-widgets.php:615
126
- msgid "Select which sidebars will be restricted to admins only."
127
- msgstr "Wybierz panele boczne, które będą dostępne tylko dla administratorów."
128
-
129
- #: ../restrict-widgets.php:619
130
- msgid "Restrict Widgets"
131
- msgstr "Ograniczenia widgetów"
132
-
133
- #: ../restrict-widgets.php:631
134
- msgid "Select which widgets will be restricted to admins only."
135
- msgstr "Wybierz widgety, któe będą dostępne tylko dla administratorów."
136
-
137
- #: ../restrict-widgets.php:635
138
- msgid "Restrict Widget Options"
139
- msgstr "Ograniczenia opcji widgetów"
140
-
141
- #: ../restrict-widgets.php:645
142
- msgid "Select which widget options will be restricted to admins only."
143
- msgstr "Wybierz które opcje widgetów, będą dostępne tylko dla administratorów."
144
-
145
- #: ../restrict-widgets.php:649
146
- msgid "Restrict Option Groups"
147
- msgstr "Ograniczenia grup opcji"
148
-
149
- #: ../restrict-widgets.php:652
150
- msgid "Display widget options in groups"
151
- msgstr "Wyświetl opcje widgetów w grupach"
152
-
153
- #: ../restrict-widgets.php:656
154
- msgid "Modify is_active_sidebar()"
155
- msgstr "Modyfikuj is_active_sidebar()"
156
-
157
- #: ../restrict-widgets.php:659
158
- msgid ""
159
- "By default is_active_sidebar() function returns TRUE even if no widget is "
160
- "displayed in a sidebar. Check this if you want is_active_sidebar() to "
161
- "recognize Restrict Widgets display settings."
162
- msgstr ""
163
- "Domyślnie funkcja is_active_sidebar() zwraca TRUE navet jeśli w danym "
164
- "sidebarze nie jest wyświetlany żaden widget. Zaznacz to, jeśli chcesz aby "
165
- "is_active_sidebar() rozpoznawało ustawienia wyświetlania dodawane przez tę "
166
- "wtyczkę."
167
-
168
- #: ../restrict-widgets.php:663
169
- msgid "Plugin Deactivation"
170
- msgstr "Deaktywacja wtyczki"
171
-
172
- #: ../restrict-widgets.php:666
173
- msgid "Remove all plugin data on deactivation"
174
- msgstr "Usuń wszystkie dane wtyczki podczas deaktywacji"
175
-
176
- #: ../restrict-widgets.php:670
177
- msgid "Save settings"
178
- msgstr "Zapisz ustawienia"
179
-
180
- #: ../restrict-widgets.php:844 ../restrict-widgets.php:854
181
- #, php-format
182
- msgid "Single %s"
183
- msgstr "Pojedyncze %s"
184
-
185
- #: ../restrict-widgets.php:884 ../restrict-widgets.php:894
186
- #, php-format
187
- msgid "%s Archive"
188
- msgstr "Archiwum %s"
189
-
190
- #: ../restrict-widgets.php:1125
191
- msgid "Display / Hide Widget"
192
- msgstr "Wyświetl / Ukryj widget"
193
-
194
- #: ../restrict-widgets.php:1127
195
- msgid "Display widget on selected"
196
- msgstr "Wyświetl widget na wybranych stronach"
197
-
198
- #: ../restrict-widgets.php:1128
199
- msgid "Hide widget on selected"
200
- msgstr "Ukryj widget na wybranych stronach"
201
-
202
- #~ msgid "Created by"
203
- #~ msgstr "Stworzone przez"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Restrict Widgets\n"
4
+ "POT-Creation-Date: 2013-12-03 12:12+0100\n"
5
+ "PO-Revision-Date: 2013-12-03 12:13+0100\n"
6
+ "Last-Translator: Bartosz Arendt <info@digitalfactory.pl>\n"
7
+ "Language-Team: dFactory <info@dfactory.eu>\n"
8
+ "Language: English\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Generator: Poedit 1.5.7\n"
13
+ "X-Poedit-KeywordsList: gettext;gettext_noop;__;_e\n"
14
+ "X-Poedit-Basepath: .\n"
15
+ "X-Poedit-SourceCharset: UTF-8\n"
16
+ "X-Poedit-SearchPath-0: ..\n"
17
+
18
+ #: ../restrict-widgets.php:310
19
+ msgid "Support"
20
+ msgstr "Forum pomocy"
21
+
22
+ #: ../restrict-widgets.php:332 ../restrict-widgets.php:1705
23
+ #: ../restrict-widgets.php:1751
24
+ msgid "Widgets"
25
+ msgstr "Widgety"
26
+
27
+ #: ../restrict-widgets.php:411
28
+ msgid "Pages"
29
+ msgstr "Strony"
30
+
31
+ #: ../restrict-widgets.php:412
32
+ msgid "Custom Post Types"
33
+ msgstr "Własne typy wpisów"
34
+
35
+ #: ../restrict-widgets.php:413
36
+ msgid "Custom Post Type Archives"
37
+ msgstr "Archiwa własnych typów wpisów"
38
+
39
+ #: ../restrict-widgets.php:414
40
+ msgid "Categories"
41
+ msgstr "Kategorie"
42
+
43
+ #: ../restrict-widgets.php:415
44
+ msgid "Taxonomies"
45
+ msgstr "Taksonomie"
46
+
47
+ #: ../restrict-widgets.php:416
48
+ msgid "Others"
49
+ msgstr "Inne"
50
+
51
+ #: ../restrict-widgets.php:423
52
+ msgid "Search"
53
+ msgstr "Strona wyszukiwania"
54
+
55
+ #: ../restrict-widgets.php:424
56
+ msgid "Single User"
57
+ msgstr "Strona użytkownika"
58
+
59
+ #: ../restrict-widgets.php:425
60
+ msgid "Topic Tag"
61
+ msgstr "Tagi tematów"
62
+
63
+ #: ../restrict-widgets.php:428
64
+ msgid "bbPress"
65
+ msgstr "Forum bbPress"
66
+
67
+ #: ../restrict-widgets.php:431
68
+ msgid "Devices"
69
+ msgstr "Urządzenia"
70
+
71
+ #: ../restrict-widgets.php:432
72
+ msgid "Users"
73
+ msgstr "Użytkownicy"
74
+
75
+ #: ../restrict-widgets.php:433
76
+ msgid "Languages"
77
+ msgstr "Języki"
78
+
79
+ #: ../restrict-widgets.php:436
80
+ msgid "Front Page"
81
+ msgstr "Strona główna"
82
+
83
+ #: ../restrict-widgets.php:437
84
+ msgid "Blog Page"
85
+ msgstr "Strona z wpisami"
86
+
87
+ #: ../restrict-widgets.php:438
88
+ msgid "Single Posts"
89
+ msgstr "Pojedyncze wpisy"
90
+
91
+ #: ../restrict-widgets.php:439
92
+ msgid "Sticky Posts"
93
+ msgstr "Wpisy przyklejone"
94
+
95
+ #: ../restrict-widgets.php:440
96
+ msgid "Author Archive"
97
+ msgstr "Archiwum autora"
98
+
99
+ #: ../restrict-widgets.php:441
100
+ msgid "Date Archive"
101
+ msgstr "Archiwum daty"
102
+
103
+ #: ../restrict-widgets.php:442
104
+ msgid "404 Page"
105
+ msgstr "Strona błędów 404"
106
+
107
+ #: ../restrict-widgets.php:443
108
+ msgid "Search Page"
109
+ msgstr "Strona wyszukiwania"
110
+
111
+ #: ../restrict-widgets.php:447
112
+ msgid "Logged in users"
113
+ msgstr "Zalogowani użytkownicy"
114
+
115
+ #: ../restrict-widgets.php:448
116
+ msgid "Logged out users"
117
+ msgstr "Wylogowani użytkownicy"
118
+
119
+ #: ../restrict-widgets.php:452
120
+ msgid "Mobile"
121
+ msgstr "Mobilne"
122
+
123
+ #: ../restrict-widgets.php:453
124
+ msgid "Desktop, Laptop, etc."
125
+ msgstr "Stacjonarne"
126
+
127
+ #: ../restrict-widgets.php:669
128
+ msgid "Restrict widgets"
129
+ msgstr "Ograniczenia widgetów"
130
+
131
+ #: ../restrict-widgets.php:673
132
+ msgid ""
133
+ "Use this settings to manage access to widgets page and to restrict "
134
+ "availability of certain widgets, sidebars and widgets options to site "
135
+ "administrators only."
136
+ msgstr ""
137
+ "Użyj tych ustawień aby określić kto może mieć dostęp do widgetów, jakie "
138
+ "widgety, panele boczne i ustawienia widgetów są dostępne dla użytkowników a "
139
+ "jakie tylko dla administratorów."
140
+
141
+ #: ../restrict-widgets.php:676
142
+ msgid "Restrict Users"
143
+ msgstr "Ograniczenia użytkowników"
144
+
145
+ #: ../restrict-widgets.php:686
146
+ msgid "Select user roles restricted to manage widgets."
147
+ msgstr "Wybierz role użytkowników, którzy mogą zarządzać widgetami."
148
+
149
+ #: ../restrict-widgets.php:690
150
+ msgid "Restrict Sidebars"
151
+ msgstr "Ograniczenia paneli bocznych"
152
+
153
+ #: ../restrict-widgets.php:706
154
+ msgid "Select which sidebars will be restricted to admins only."
155
+ msgstr "Wybierz panele boczne, które będą dostępne tylko dla administratorów."
156
+
157
+ #: ../restrict-widgets.php:710
158
+ msgid "Restrict Widgets"
159
+ msgstr "Ograniczenia widgetów"
160
+
161
+ #: ../restrict-widgets.php:723
162
+ msgid "Select which widgets will be restricted to admins only."
163
+ msgstr "Wybierz widgety, któe będą dostępne tylko dla administratorów."
164
+
165
+ #: ../restrict-widgets.php:727
166
+ msgid "Restrict Widget Options"
167
+ msgstr "Ograniczenia opcji widgetów"
168
+
169
+ #: ../restrict-widgets.php:737
170
+ msgid "Select which widget options will be restricted to admins only."
171
+ msgstr "Wybierz które opcje widgetów, będą dostępne tylko dla administratorów."
172
+
173
+ #: ../restrict-widgets.php:741
174
+ msgid "Restrict Option Groups"
175
+ msgstr "Ograniczenia grup opcji"
176
+
177
+ #: ../restrict-widgets.php:744
178
+ msgid "Display widget options in groups"
179
+ msgstr "Wyświetl opcje widgetów w grupach"
180
+
181
+ #: ../restrict-widgets.php:748
182
+ msgid "Modify is_active_sidebar()"
183
+ msgstr "Modyfikuj is_active_sidebar()"
184
+
185
+ #: ../restrict-widgets.php:751
186
+ msgid ""
187
+ "By default is_active_sidebar() function returns TRUE even if no widget is "
188
+ "displayed in a sidebar. Check this if you want is_active_sidebar() to "
189
+ "recognize Restrict Widgets display settings."
190
+ msgstr ""
191
+ "Domyślnie funkcja is_active_sidebar() zwraca TRUE navet jeśli w danym "
192
+ "sidebarze nie jest wyświetlany żaden widget. Zaznacz to, jeśli chcesz aby "
193
+ "is_active_sidebar() rozpoznawało ustawienia wyświetlania dodawane przez tę "
194
+ "wtyczkę."
195
+
196
+ #: ../restrict-widgets.php:755
197
+ msgid "Plugin Deactivation"
198
+ msgstr "Deaktywacja wtyczki"
199
+
200
+ #: ../restrict-widgets.php:758
201
+ msgid "Remove all plugin data on deactivation"
202
+ msgstr "Usuń wszystkie dane wtyczki podczas deaktywacji"
203
+
204
+ #: ../restrict-widgets.php:762
205
+ msgid "Save settings"
206
+ msgstr "Zapisz ustawienia"
207
+
208
+ #: ../restrict-widgets.php:930 ../restrict-widgets.php:941
209
+ #, php-format
210
+ msgid "Single %s"
211
+ msgstr "Pojedyncze %s"
212
+
213
+ #: ../restrict-widgets.php:968 ../restrict-widgets.php:979
214
+ #, php-format
215
+ msgid "%s Archive"
216
+ msgstr "Archiwum %s"
217
+
218
+ #: ../restrict-widgets.php:1278
219
+ msgid "Display / Hide Widget"
220
+ msgstr "Wyświetl / Ukryj widget"
221
+
222
+ #: ../restrict-widgets.php:1280
223
+ msgid "Display widget on selected"
224
+ msgstr "Wyświetl widget na wybranych stronach"
225
+
226
+ #: ../restrict-widgets.php:1281
227
+ msgid "Hide widget on selected"
228
+ msgstr "Ukryj widget na wybranych stronach"
229
+
230
+ #~ msgid "Created by"
231
+ #~ msgstr "Stworzone przez"
languages/restrict-widgets.pot CHANGED
@@ -1,8 +1,8 @@
1
  msgid ""
2
  msgstr ""
3
  "Project-Id-Version: Restrict Widgets\n"
4
- "POT-Creation-Date: 2013-09-04 09:23+0100\n"
5
- "PO-Revision-Date: 2013-09-04 09:23+0100\n"
6
  "Last-Translator: Bartosz Arendt <info@digitalfactory.pl>\n"
7
  "Language-Team: dFactory <info@dfactory.eu>\n"
8
  "Language: English\n"
@@ -15,179 +15,207 @@ msgstr ""
15
  "X-Poedit-SourceCharset: UTF-8\n"
16
  "X-Poedit-SearchPath-0: ..\n"
17
 
18
- #: ../restrict-widgets.php:175
19
  msgid "Support"
20
  msgstr ""
21
 
22
- #: ../restrict-widgets.php:197 ../restrict-widgets.php:1475
23
- #: ../restrict-widgets.php:1520
24
  msgid "Widgets"
25
  msgstr ""
26
 
27
- #: ../restrict-widgets.php:333
28
  msgid "Pages"
29
  msgstr ""
30
 
31
- #: ../restrict-widgets.php:334
32
  msgid "Custom Post Types"
33
  msgstr ""
34
 
35
- #: ../restrict-widgets.php:335
36
  msgid "Custom Post Type Archives"
37
  msgstr ""
38
 
39
- #: ../restrict-widgets.php:336
40
  msgid "Categories"
41
  msgstr ""
42
 
43
- #: ../restrict-widgets.php:337
44
  msgid "Taxonomies"
45
  msgstr ""
46
 
47
- #: ../restrict-widgets.php:338
48
  msgid "Others"
49
  msgstr ""
50
 
51
- #: ../restrict-widgets.php:339
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  msgid "Users"
53
  msgstr ""
54
 
55
- #: ../restrict-widgets.php:340
56
  msgid "Languages"
57
  msgstr ""
58
 
59
- #: ../restrict-widgets.php:344
60
  msgid "Front Page"
61
  msgstr ""
62
 
63
- #: ../restrict-widgets.php:345
64
  msgid "Blog Page"
65
  msgstr ""
66
 
67
- #: ../restrict-widgets.php:346
68
  msgid "Single Posts"
69
  msgstr ""
70
 
71
- #: ../restrict-widgets.php:347
72
  msgid "Sticky Posts"
73
  msgstr ""
74
 
75
- #: ../restrict-widgets.php:348
76
  msgid "Author Archive"
77
  msgstr ""
78
 
79
- #: ../restrict-widgets.php:349
80
  msgid "Date Archive"
81
  msgstr ""
82
 
83
- #: ../restrict-widgets.php:350
84
  msgid "404 Page"
85
  msgstr ""
86
 
87
- #: ../restrict-widgets.php:351
88
  msgid "Search Page"
89
  msgstr ""
90
 
91
- #: ../restrict-widgets.php:355
92
  msgid "Logged in users"
93
  msgstr ""
94
 
95
- #: ../restrict-widgets.php:356
96
  msgid "Logged out users"
97
  msgstr ""
98
 
99
- #: ../restrict-widgets.php:579
 
 
 
 
 
 
 
 
100
  msgid "Restrict widgets"
101
  msgstr ""
102
 
103
- #: ../restrict-widgets.php:583
104
  msgid ""
105
  "Use this settings to manage access to widgets page and to restrict "
106
  "availability of certain widgets, sidebars and widgets options to site "
107
  "administrators only."
108
  msgstr ""
109
 
110
- #: ../restrict-widgets.php:586
111
  msgid "Restrict Users"
112
  msgstr ""
113
 
114
- #: ../restrict-widgets.php:596
115
  msgid "Select user roles restricted to manage widgets."
116
  msgstr ""
117
 
118
- #: ../restrict-widgets.php:600
119
  msgid "Restrict Sidebars"
120
  msgstr ""
121
 
122
- #: ../restrict-widgets.php:615
123
  msgid "Select which sidebars will be restricted to admins only."
124
  msgstr ""
125
 
126
- #: ../restrict-widgets.php:619
127
  msgid "Restrict Widgets"
128
  msgstr ""
129
 
130
- #: ../restrict-widgets.php:631
131
  msgid "Select which widgets will be restricted to admins only."
132
  msgstr ""
133
 
134
- #: ../restrict-widgets.php:635
135
  msgid "Restrict Widget Options"
136
  msgstr ""
137
 
138
- #: ../restrict-widgets.php:645
139
  msgid "Select which widget options will be restricted to admins only."
140
  msgstr ""
141
 
142
- #: ../restrict-widgets.php:649
143
  msgid "Restrict Option Groups"
144
  msgstr ""
145
 
146
- #: ../restrict-widgets.php:652
147
  msgid "Display widget options in groups"
148
  msgstr ""
149
 
150
- #: ../restrict-widgets.php:656
151
  msgid "Modify is_active_sidebar()"
152
  msgstr ""
153
 
154
- #: ../restrict-widgets.php:659
155
  msgid ""
156
  "By default is_active_sidebar() function returns TRUE even if no widget is "
157
  "displayed in a sidebar. Check this if you want is_active_sidebar() to "
158
  "recognize Restrict Widgets display settings."
159
  msgstr ""
160
 
161
- #: ../restrict-widgets.php:663
162
  msgid "Plugin Deactivation"
163
  msgstr ""
164
 
165
- #: ../restrict-widgets.php:666
166
  msgid "Remove all plugin data on deactivation"
167
  msgstr ""
168
 
169
- #: ../restrict-widgets.php:670
170
  msgid "Save settings"
171
  msgstr ""
172
 
173
- #: ../restrict-widgets.php:844 ../restrict-widgets.php:854
174
  #, php-format
175
  msgid "Single %s"
176
  msgstr ""
177
 
178
- #: ../restrict-widgets.php:884 ../restrict-widgets.php:894
179
  #, php-format
180
  msgid "%s Archive"
181
  msgstr ""
182
 
183
- #: ../restrict-widgets.php:1125
184
  msgid "Display / Hide Widget"
185
  msgstr ""
186
 
187
- #: ../restrict-widgets.php:1127
188
  msgid "Display widget on selected"
189
  msgstr ""
190
 
191
- #: ../restrict-widgets.php:1128
192
  msgid "Hide widget on selected"
193
  msgstr ""
1
  msgid ""
2
  msgstr ""
3
  "Project-Id-Version: Restrict Widgets\n"
4
+ "POT-Creation-Date: 2013-12-03 12:12+0100\n"
5
+ "PO-Revision-Date: 2013-12-03 12:12+0100\n"
6
  "Last-Translator: Bartosz Arendt <info@digitalfactory.pl>\n"
7
  "Language-Team: dFactory <info@dfactory.eu>\n"
8
  "Language: English\n"
15
  "X-Poedit-SourceCharset: UTF-8\n"
16
  "X-Poedit-SearchPath-0: ..\n"
17
 
18
+ #: ../restrict-widgets.php:310
19
  msgid "Support"
20
  msgstr ""
21
 
22
+ #: ../restrict-widgets.php:332 ../restrict-widgets.php:1705
23
+ #: ../restrict-widgets.php:1751
24
  msgid "Widgets"
25
  msgstr ""
26
 
27
+ #: ../restrict-widgets.php:411
28
  msgid "Pages"
29
  msgstr ""
30
 
31
+ #: ../restrict-widgets.php:412
32
  msgid "Custom Post Types"
33
  msgstr ""
34
 
35
+ #: ../restrict-widgets.php:413
36
  msgid "Custom Post Type Archives"
37
  msgstr ""
38
 
39
+ #: ../restrict-widgets.php:414
40
  msgid "Categories"
41
  msgstr ""
42
 
43
+ #: ../restrict-widgets.php:415
44
  msgid "Taxonomies"
45
  msgstr ""
46
 
47
+ #: ../restrict-widgets.php:416
48
  msgid "Others"
49
  msgstr ""
50
 
51
+ #: ../restrict-widgets.php:423
52
+ msgid "Search"
53
+ msgstr ""
54
+
55
+ #: ../restrict-widgets.php:424
56
+ msgid "Single User"
57
+ msgstr ""
58
+
59
+ #: ../restrict-widgets.php:425
60
+ msgid "Topic Tag"
61
+ msgstr ""
62
+
63
+ #: ../restrict-widgets.php:428
64
+ msgid "bbPress"
65
+ msgstr ""
66
+
67
+ #: ../restrict-widgets.php:431
68
+ msgid "Devices"
69
+ msgstr ""
70
+
71
+ #: ../restrict-widgets.php:432
72
  msgid "Users"
73
  msgstr ""
74
 
75
+ #: ../restrict-widgets.php:433
76
  msgid "Languages"
77
  msgstr ""
78
 
79
+ #: ../restrict-widgets.php:436
80
  msgid "Front Page"
81
  msgstr ""
82
 
83
+ #: ../restrict-widgets.php:437
84
  msgid "Blog Page"
85
  msgstr ""
86
 
87
+ #: ../restrict-widgets.php:438
88
  msgid "Single Posts"
89
  msgstr ""
90
 
91
+ #: ../restrict-widgets.php:439
92
  msgid "Sticky Posts"
93
  msgstr ""
94
 
95
+ #: ../restrict-widgets.php:440
96
  msgid "Author Archive"
97
  msgstr ""
98
 
99
+ #: ../restrict-widgets.php:441
100
  msgid "Date Archive"
101
  msgstr ""
102
 
103
+ #: ../restrict-widgets.php:442
104
  msgid "404 Page"
105
  msgstr ""
106
 
107
+ #: ../restrict-widgets.php:443
108
  msgid "Search Page"
109
  msgstr ""
110
 
111
+ #: ../restrict-widgets.php:447
112
  msgid "Logged in users"
113
  msgstr ""
114
 
115
+ #: ../restrict-widgets.php:448
116
  msgid "Logged out users"
117
  msgstr ""
118
 
119
+ #: ../restrict-widgets.php:452
120
+ msgid "Mobile"
121
+ msgstr ""
122
+
123
+ #: ../restrict-widgets.php:453
124
+ msgid "Desktop, Laptop, etc."
125
+ msgstr ""
126
+
127
+ #: ../restrict-widgets.php:669
128
  msgid "Restrict widgets"
129
  msgstr ""
130
 
131
+ #: ../restrict-widgets.php:673
132
  msgid ""
133
  "Use this settings to manage access to widgets page and to restrict "
134
  "availability of certain widgets, sidebars and widgets options to site "
135
  "administrators only."
136
  msgstr ""
137
 
138
+ #: ../restrict-widgets.php:676
139
  msgid "Restrict Users"
140
  msgstr ""
141
 
142
+ #: ../restrict-widgets.php:686
143
  msgid "Select user roles restricted to manage widgets."
144
  msgstr ""
145
 
146
+ #: ../restrict-widgets.php:690
147
  msgid "Restrict Sidebars"
148
  msgstr ""
149
 
150
+ #: ../restrict-widgets.php:706
151
  msgid "Select which sidebars will be restricted to admins only."
152
  msgstr ""
153
 
154
+ #: ../restrict-widgets.php:710
155
  msgid "Restrict Widgets"
156
  msgstr ""
157
 
158
+ #: ../restrict-widgets.php:723
159
  msgid "Select which widgets will be restricted to admins only."
160
  msgstr ""
161
 
162
+ #: ../restrict-widgets.php:727
163
  msgid "Restrict Widget Options"
164
  msgstr ""
165
 
166
+ #: ../restrict-widgets.php:737
167
  msgid "Select which widget options will be restricted to admins only."
168
  msgstr ""
169
 
170
+ #: ../restrict-widgets.php:741
171
  msgid "Restrict Option Groups"
172
  msgstr ""
173
 
174
+ #: ../restrict-widgets.php:744
175
  msgid "Display widget options in groups"
176
  msgstr ""
177
 
178
+ #: ../restrict-widgets.php:748
179
  msgid "Modify is_active_sidebar()"
180
  msgstr ""
181
 
182
+ #: ../restrict-widgets.php:751
183
  msgid ""
184
  "By default is_active_sidebar() function returns TRUE even if no widget is "
185
  "displayed in a sidebar. Check this if you want is_active_sidebar() to "
186
  "recognize Restrict Widgets display settings."
187
  msgstr ""
188
 
189
+ #: ../restrict-widgets.php:755
190
  msgid "Plugin Deactivation"
191
  msgstr ""
192
 
193
+ #: ../restrict-widgets.php:758
194
  msgid "Remove all plugin data on deactivation"
195
  msgstr ""
196
 
197
+ #: ../restrict-widgets.php:762
198
  msgid "Save settings"
199
  msgstr ""
200
 
201
+ #: ../restrict-widgets.php:930 ../restrict-widgets.php:941
202
  #, php-format
203
  msgid "Single %s"
204
  msgstr ""
205
 
206
+ #: ../restrict-widgets.php:968 ../restrict-widgets.php:979
207
  #, php-format
208
  msgid "%s Archive"
209
  msgstr ""
210
 
211
+ #: ../restrict-widgets.php:1278
212
  msgid "Display / Hide Widget"
213
  msgstr ""
214
 
215
+ #: ../restrict-widgets.php:1280
216
  msgid "Display widget on selected"
217
  msgstr ""
218
 
219
+ #: ../restrict-widgets.php:1281
220
  msgid "Hide widget on selected"
221
  msgstr ""
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.dfactory.eu/
4
  Tags: widget, widgets, widget-only, cms, conditional tags, conditional, widget logic, widget context, restrict, manage, management, capability, capabilities, sidebar, sidebars, user, permission, permissions
5
  Requires at least: 3.3
6
  Tested up to: 3.7.1
7
- Stable tag: 1.1.4
8
  License: MIT License
9
  License URI: http://opensource.org/licenses/MIT
10
 
@@ -20,13 +20,14 @@ For more information, check out plugin page at [dFactory](http://www.dfactory.eu
20
 
21
  = Features include: =
22
 
23
- * Hide or display each widget on selected pages, posts, categories, custom taxonomies, custom post types, single posts, archives, special pages, for logged in or logged out users, current language and so on
24
  * Select which user roles are restricted to manage widgets
25
  * Select which sidebars will be restricted to admins only
26
  * Select which widgets will be restricted to admins only
27
  * Select which widget options will be restricted to admins only
28
  * Choose to display or not widget options as groups
29
  * Option to modify the is_active_sidebar() function to use Restrict Widgets display settings
 
30
  * WPML compatible
31
  * Polylang compatible
32
  * .pot file for translations included
@@ -55,6 +56,13 @@ No questions yet.
55
 
56
  == Changelog ==
57
 
 
 
 
 
 
 
 
58
  = 1.1.4 =
59
  * New: Introducing rw_option_display_name filter hook
60
  * Tweak: WPML not displaying page names in default site language
@@ -84,6 +92,5 @@ Initial release
84
 
85
  == Upgrade Notice ==
86
 
87
- = 1.1.4 =
88
- * New: Introducing rw_option_display_name filter hook
89
- * Tweak: WPML not displaying page names in default site language
4
  Tags: widget, widgets, widget-only, cms, conditional tags, conditional, widget logic, widget context, restrict, manage, management, capability, capabilities, sidebar, sidebars, user, permission, permissions
5
  Requires at least: 3.3
6
  Tested up to: 3.7.1
7
+ Stable tag: 1.2.0
8
  License: MIT License
9
  License URI: http://opensource.org/licenses/MIT
10
 
20
 
21
  = Features include: =
22
 
23
+ * Hide or display each widget on selected pages, posts, categories, custom taxonomies, custom post types, single posts, archives, special pages, for logged in or logged out users, current language, mobile device and so on
24
  * Select which user roles are restricted to manage widgets
25
  * Select which sidebars will be restricted to admins only
26
  * Select which widgets will be restricted to admins only
27
  * Select which widget options will be restricted to admins only
28
  * Choose to display or not widget options as groups
29
  * Option to modify the is_active_sidebar() function to use Restrict Widgets display settings
30
+ * Multisite compatible
31
  * WPML compatible
32
  * Polylang compatible
33
  * .pot file for translations included
56
 
57
  == Changelog ==
58
 
59
+ = 1.2.0 =
60
+ * New: Multisite support
61
+ * New: Option to hide / show widget depending on the device (mobile or not)
62
+ * New: bbPress specific options for hide / show widget
63
+ * Fix: get_class error on widgets not using Widgets API
64
+ * Fix: Logged-in or out users option not working properly
65
+
66
  = 1.1.4 =
67
  * New: Introducing rw_option_display_name filter hook
68
  * Tweak: WPML not displaying page names in default site language
92
 
93
  == Upgrade Notice ==
94
 
95
+ = 1.2.0 =
96
+ * New: Multisite support, Options to hide / show widget depending on the device (mobile or not), multiple fixes
 
restrict-widgets.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Restrict Widgets
4
  Description: All in one solution for widget management in WordPress. Allows you to hide or display widgets on specified pages and restrict access for users.
5
- Version: 1.1.4
6
  Author: dFactory
7
  Author URI: http://www.dfactory.eu/
8
  Plugin URI: http://www.dfactory.eu/plugins/restrict-widgets/
@@ -21,6 +21,12 @@ The above copyright notice and this permission notice shall be included in all c
21
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
  */
23
 
 
 
 
 
 
 
24
 
25
  class Restrict_Widgets
26
  {
@@ -29,6 +35,8 @@ class Restrict_Widgets
29
  private $custom_post_types_archives = array();
30
  private $categories = array();
31
  private $taxonomies = array();
 
 
32
  private $others = array();
33
  private $users = array();
34
  private $languages = array();
@@ -36,12 +44,15 @@ class Restrict_Widgets
36
  private $hidden_widget = '';
37
  private $checked_widget = '';
38
  private $widgets = array();
 
 
 
39
 
40
 
41
  public function __construct()
42
  {
43
- register_activation_hook(__FILE__, array(&$this, 'activation'));
44
- register_deactivation_hook(__FILE__, array(&$this, 'deactivation'));
45
 
46
  //actions
47
  add_action('wp_loaded', array(&$this, 'polylang_widgets'), 6);
@@ -66,6 +77,124 @@ class Restrict_Widgets
66
  }
67
 
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  /**
70
  * Fix for is_active_sidebar (all hidden widgets on sidebar = FALSE)
71
  */
@@ -83,11 +212,8 @@ class Restrict_Widgets
83
 
84
  foreach($wp_registered_widgets as $widget)
85
  {
86
- if(isset($widget['callback'][0]->option_name) && $widget['callback'][0]->option_name !== '')
87
- {
88
- if(empty($widgets_classes[$widget['callback'][0]->option_name]))
89
- $widgets_c[$widget['callback'][0]->option_name] = get_option($widget['callback'][0]->option_name);
90
- }
91
  }
92
 
93
  foreach($widgets_c as $widget_base_id => $widgets)
@@ -139,14 +265,12 @@ class Restrict_Widgets
139
  */
140
  public function polylang_widgets()
141
  {
142
- if(function_exists('pll_the_languages'));
143
  {
144
  global $polylang;
145
 
146
  if(has_action('in_widget_form', array($polylang, 'in_widget_form')))
147
- {
148
  remove_action('in_widget_form', array($polylang, 'in_widget_form'));
149
- }
150
  }
151
  }
152
 
@@ -156,45 +280,54 @@ class Restrict_Widgets
156
  */
157
  public function load_textdomain()
158
  {
159
- load_plugin_textdomain('restrict-widgets', FALSE, dirname(plugin_basename(__FILE__)).'/languages/');
 
 
 
 
 
 
 
 
 
160
  }
161
-
162
-
163
  /**
164
  * Add links to Support Forum
165
  */
166
  public function plugin_extend_links($links, $file)
167
  {
168
- if (!current_user_can('install_plugins'))
169
  return $links;
170
-
171
  $plugin = plugin_basename(__FILE__);
172
-
173
- if ($file == $plugin)
174
  {
175
  return array_merge(
176
  $links,
177
  array(sprintf('<a href="http://www.dfactory.eu/support/forum/restrict-widgets/" target="_blank">%s</a>', __('Support', 'restrict-widgets')))
178
  );
179
  }
180
-
181
  return $links;
182
  }
183
-
184
-
185
  /**
186
  * Add links to Settings page
187
  */
188
  function plugin_settings_link($links, $file)
189
  {
190
- if (!is_admin() || !current_user_can('edit_theme_options'))
191
  return $links;
192
 
193
  static $plugin;
194
 
195
  $plugin = plugin_basename(__FILE__);
196
 
197
- if ($file == $plugin)
198
  {
199
  $settings_link = sprintf('<a href="%s">%s</a>', admin_url('widgets.php'), __('Widgets', 'restrict-widgets'));
200
  array_unshift($links, $settings_link);
@@ -215,77 +348,20 @@ class Restrict_Widgets
215
 
216
  $option = get_option('rw_widgets_options');
217
 
218
- if(isset($wp_registered_widgets[$params[0]['widget_id']]['callback'][0]))
219
- {
220
- if(in_array(get_class($wp_registered_widgets[$params[0]['widget_id']]['callback'][0]), array_keys($option['available'])))
221
- {
222
- $params[0]['_hide'] = 1;
223
- }
224
- }
 
225
  }
226
 
227
  return $params;
228
  }
229
 
230
 
231
- /**
232
- * Actives plugin
233
- */
234
- public function activation()
235
- {
236
- $role = get_role('administrator');
237
- $role->add_cap('manage_widgets');
238
-
239
- //default settings
240
- add_option(
241
- 'rw_widgets_options',
242
- array(
243
- 'available' => array(),
244
- 'selection' => array(),
245
- 'sidebars' => array(),
246
- 'groups' => TRUE,
247
- 'deactivation' => FALSE,
248
- ),
249
- '',
250
- 'yes'
251
- );
252
- }
253
-
254
-
255
- /**
256
- * Deactivates plugin
257
- */
258
- public function deactivation()
259
- {
260
- $option = get_option('rw_widgets_options');
261
-
262
- if($option['deactivation'] === TRUE)
263
- {
264
- global $wp_roles, $wp_registered_widgets;
265
-
266
- //removes roles
267
- foreach($wp_roles->roles as $role_name => $empty)
268
- {
269
- $role = get_role($role_name);
270
- $role->remove_cap('manage_widgets');
271
- }
272
-
273
- //clears all widgets
274
- foreach($wp_registered_widgets as $widget)
275
- {
276
- if(isset($widget['params'][0]['number']) && $widget['params'][0]['number'] !== -1)
277
- {
278
- $option = get_option($widget['callback'][0]->option_name);
279
- unset($option[$widget['params'][0]['number']]['rw_opt']);
280
- update_option($widget['callback'][0]->option_name, $option);
281
- }
282
- }
283
-
284
- delete_option('rw_widgets_options');
285
- }
286
- }
287
-
288
-
289
  /**
290
  * Loads dynamic data
291
  */
@@ -337,11 +413,25 @@ class Restrict_Widgets
337
  'custom_post_types_archives' => __('Custom Post Type Archives', 'restrict-widgets'),
338
  'categories' => __('Categories', 'restrict-widgets'),
339
  'taxonomies' => __('Taxonomies', 'restrict-widgets'),
340
- 'others' => __('Others', 'restrict-widgets'),
341
- 'users' => __('Users', 'restrict-widgets'),
342
- 'languages' => __('Languages', 'restrict-widgets'),
343
  );
344
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
345
  $this->others = array(
346
  'front_page' => __('Front Page', 'restrict-widgets'),
347
  'blog_page' => __('Blog Page', 'restrict-widgets'),
@@ -355,7 +445,12 @@ class Restrict_Widgets
355
 
356
  $this->users = array(
357
  'logged_in' => __('Logged in users', 'restrict-widgets'),
358
- 'logged_out' => __('Logged out users', 'restrict-widgets'),
 
 
 
 
 
359
  );
360
 
361
  $this->pages = get_pages(
@@ -369,7 +464,7 @@ class Restrict_Widgets
369
  );
370
 
371
  //Polylang support
372
- if(function_exists('pll_the_languages'))
373
  {
374
  $languages = get_terms('language', array('hide_empty' => FALSE));
375
 
@@ -380,7 +475,7 @@ class Restrict_Widgets
380
  }
381
  }
382
  //WMPL support
383
- elseif(function_exists('icl_get_languages'))
384
  $this->languages = icl_get_languages('skip_missing=0&orderby=native_name&order=asc');
385
  else
386
  $this->languages = FALSE;
@@ -453,56 +548,57 @@ class Restrict_Widgets
453
  $tmp = explode('_', $element, 2);
454
 
455
  if(in_array($tmp[0], array('cpt', 'cpta'), TRUE))
456
- {
457
  $save_widgets['selection'][$tmp[0] === 'cpt' ? 'custom_post_types' : 'custom_post_types_archives'][$tmp[0].'_'.sanitize_key($tmp[1])] = TRUE;
458
- }
459
  }
460
 
461
  foreach($this->pages as $page)
462
  {
463
  if(in_array('pageid_'.$page->ID, $selected, TRUE))
464
- {
465
  $save_widgets['selection']['pages']['pageid_'.$page->ID] = TRUE;
466
- }
467
  }
468
 
469
  foreach($this->custom_post_types as $cpt)
470
  {
471
  if(in_array('cpt_'.$cpt->name, $selected, TRUE))
472
- {
473
  $save_widgets['selection']['custom_post_types']['cpt_'.$cpt->name] = TRUE;
474
- }
475
  }
476
 
477
  foreach($this->categories as $category)
478
  {
479
  if(in_array('category_'.$category->cat_ID, $selected, TRUE))
480
- {
481
  $save_widgets['selection']['categories']['category_'.$category->cat_ID] = TRUE;
482
- }
483
  }
484
 
485
  foreach($this->taxonomies as $taxonomy)
486
  {
487
  if(in_array('taxonomy_'.$taxonomy->name, $selected, TRUE))
488
- {
489
  $save_widgets['selection']['taxonomies']['taxonomy_'.$taxonomy->name] = TRUE;
490
- }
491
  }
492
 
493
  foreach($this->others as $key => $value)
494
  {
495
  if(in_array('others_'.$key, $selected, TRUE))
496
- {
497
  $save_widgets['selection']['others']['others_'.$key] = TRUE;
498
- }
499
  }
500
 
501
  foreach($this->users as $key => $value)
502
  {
503
  if(in_array('users_'.$key, $selected, TRUE))
504
- {
505
  $save_widgets['selection']['users']['users_'.$key] = TRUE;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
506
  }
507
  }
508
  }
@@ -526,13 +622,9 @@ class Restrict_Widgets
526
  $role = get_role($role_name);
527
 
528
  if(in_array($role_name, $roles_a))
529
- {
530
  $role->add_cap('manage_widgets');
531
- }
532
  else
533
- {
534
  $role->remove_cap('manage_widgets');
535
- }
536
  }
537
  }
538
 
@@ -565,13 +657,9 @@ class Restrict_Widgets
565
  foreach($widgets as $widget)
566
  {
567
  if(isset($widget['callback'][0]) && is_object($widget['callback'][0]))
568
- {
569
  $widgets_unique[get_class($widget['callback'][0])] = $widget['name'];
570
- }
571
  else
572
- {
573
  $widgets_unique[$widget['id']] = $widget['name'];
574
- }
575
  }
576
 
577
  echo '
@@ -607,7 +695,8 @@ class Restrict_Widgets
607
  {
608
  if($sidebar['id'] !== 'wp_inactive_widgets')
609
  {
610
- if(isset($option['sidebars'][$sidebar['id']]) === FALSE) $option['sidebars'][$sidebar['id']] = FALSE;
 
611
 
612
  echo '<option value="'.$sidebar['id'].'" '.selected($option['sidebars'][$sidebar['id']], TRUE, FALSE).'>'.$sidebar['name'].'</option>';
613
  }
@@ -624,7 +713,8 @@ class Restrict_Widgets
624
 
625
  foreach(array_unique($widgets_unique) as $widget_class => $widget_name)
626
  {
627
- if(isset($option['available'][$widget_class]) === FALSE) $option['available'][$widget_class] = FALSE;
 
628
 
629
  echo '<option value="'.$widget_class.'" '.selected($option['available'][$widget_class], TRUE, FALSE).'>'.$widget_name.'</option>';
630
  }
@@ -670,7 +760,7 @@ class Restrict_Widgets
670
  </tr>
671
  </table>
672
  <input type="submit" value="'.__('Save settings', 'restrict-widgets').'" name="save-widgets-options" class="button button-primary" id="save-widgets-options" />
673
- <p id="df-credits">Created by<a href="http://www.dfactory.eu/?utm_source=restrict-widgets-settings&utm_medium=link&utm_campaign=created-by" target="_blank" title="dFactory - Quality plugins for WordPress"><img src="'.plugins_url('images/logo-dfactory.png' ,__FILE__).'" title="dFactory - Quality plugins for WordPress" alt="dFactory - Quality plugins for WordPress" /></a></p>
674
  <br class="clear" />
675
  </form>
676
  </div>
@@ -697,13 +787,13 @@ class Restrict_Widgets
697
 
698
  wp_enqueue_script(
699
  'chosen',
700
- plugins_url('js/chosen.jquery.min.js', __FILE__),
701
  array('jquery')
702
  );
703
 
704
  wp_enqueue_script(
705
  'restrict-widgets',
706
- plugins_url('js/restrict-widgets-admin.js', __FILE__),
707
  array('jquery', 'chosen')
708
  );
709
 
@@ -731,13 +821,14 @@ class Restrict_Widgets
731
  //which sidebars to hide
732
  foreach($widgets as $widget)
733
  {
734
- if(isset($wp_registered_widgets[$widget]['callback'][0]))
735
- {
736
- if(in_array(get_class($wp_registered_widgets[$widget]['callback'][0]), $restrict))
737
- {
738
- $js_widgets[] = $widget;
739
- }
740
- }
 
741
  }
742
 
743
  //which widgets to hide
@@ -745,20 +836,16 @@ class Restrict_Widgets
745
  {
746
  //standard based widget class
747
  if(isset($widget['callback'][0]) && is_object($widget['callback'][0]) && in_array(get_class($widget['callback'][0]), $restrict))
748
- {
749
  $js_class[] = $widget['callback'][0]->id_base;
750
- }
751
  //non-standard based widget
752
  elseif(in_array($widget['id'], $restrict))
753
- {
754
  $js_nonclass[] = $widget['id'];
755
- }
756
  }
757
  }
758
 
759
  wp_localize_script(
760
  'restrict-widgets',
761
- 'restrict_widgets_args',
762
  array(
763
  'placeholder_text' => esc_attr__('Select options', 'restrict-widgets'),
764
  'restrict_available_widgets' => esc_attr__('Select widgets', 'restrict-widgets'),
@@ -773,8 +860,8 @@ class Restrict_Widgets
773
  )
774
  );
775
 
776
- wp_enqueue_style('chosen', plugins_url('css/chosen.css', __FILE__));
777
- wp_enqueue_style('style', plugins_url('css/restrict-widgets-admin.css', __FILE__));
778
  }
779
 
780
 
@@ -791,9 +878,7 @@ class Restrict_Widgets
791
  case 'pages':
792
  {
793
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
794
- {
795
  $html .= '<optgroup label="'.$this->options['pages'].'">';
796
- }
797
 
798
  foreach($this->pages as $page)
799
  {
@@ -801,7 +886,8 @@ class Restrict_Widgets
801
  {
802
  case 'option':
803
  {
804
- if(isset($option['selection']['pages']['pageid_'.$page->ID]) === FALSE) $option['selection']['pages']['pageid_'.$page->ID] = FALSE;
 
805
 
806
  $html .= '<option value="pageid_'.$page->ID.'" '.selected($option['selection']['pages']['pageid_'.$page->ID], TRUE, FALSE).'>'.$page->post_title.'</option>';
807
 
@@ -811,7 +897,8 @@ class Restrict_Widgets
811
  {
812
  if(!isset($rw_option['selection']['pages']['pageid_'.$page->ID]) || current_user_can('manage_options'))
813
  {
814
- if(isset($instance['rw_opt']['pageid_'.$page->ID]) === FALSE) $instance['rw_opt']['pageid_'.$page->ID] = 0;
 
815
 
816
  $html .= '<option value="pageid_'.$page->ID.'" '.selected($instance['rw_opt']['pageid_'.$page->ID], TRUE, FALSE).'>'.apply_filters('rw_option_display_name', $page->post_title, 'page').'</option>';
817
  }
@@ -822,18 +909,14 @@ class Restrict_Widgets
822
  }
823
 
824
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
825
- {
826
  $html .= '</optgroup>';
827
- }
828
 
829
  return $html;
830
  }
831
  case 'custom_post_types':
832
  {
833
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
834
- {
835
  $html .= '<optgroup label="'.$this->options['custom_post_types'].'">';
836
- }
837
 
838
  foreach($this->custom_post_types as $cpt)
839
  {
@@ -841,7 +924,8 @@ class Restrict_Widgets
841
  {
842
  case 'option':
843
  {
844
- if(isset($option['selection']['custom_post_types']['cpt_'.$cpt->name]) === FALSE) $option['selection']['custom_post_types']['cpt_'.$cpt->name] = FALSE;
 
845
 
846
  $html .= '<option value="cpt_'.$cpt->name.'" '.selected($option['selection']['custom_post_types']['cpt_'.$cpt->name], TRUE, FALSE).'>'.sprintf(__('Single %s','restrict-widgets'), $cpt->label).'</option>';
847
 
@@ -851,7 +935,8 @@ class Restrict_Widgets
851
  {
852
  if(!isset($rw_option['selection']['custom_post_types']['cpt_'.$cpt->name]) || current_user_can('manage_options'))
853
  {
854
- if(isset($instance['rw_opt']['cpt_'.$cpt->name]) === FALSE) $instance['rw_opt']['cpt_'.$cpt->name] = 0;
 
855
 
856
  $html .= '<option value="cpt_'.$cpt->name.'" '.selected($instance['rw_opt']['cpt_'.$cpt->name], TRUE, FALSE).'>'.apply_filters('rw_option_display_name', sprintf(__('Single %s','restrict-widgets'), $cpt->label), 'custom_post_type').'</option>';
857
  }
@@ -862,18 +947,14 @@ class Restrict_Widgets
862
  }
863
 
864
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
865
- {
866
  $html .= '</optgroup>';
867
- }
868
 
869
  return $html;
870
  }
871
  case 'custom_post_types_archives':
872
  {
873
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
874
- {
875
  $html .= '<optgroup label="'.$this->options['custom_post_types_archives'].'">';
876
- }
877
 
878
  foreach($this->custom_post_types_archives as $cpta)
879
  {
@@ -881,7 +962,8 @@ class Restrict_Widgets
881
  {
882
  case 'option':
883
  {
884
- if(isset($option['selection']['custom_post_types_archives']['cpta_'.$cpta->name]) === FALSE) $option['selection']['custom_post_types_archives']['cpta_'.$cpta->name] = FALSE;
 
885
 
886
  $html .= '<option value="cpta_'.$cpta->name.'" '.selected($option['selection']['custom_post_types_archives']['cpta_'.$cpta->name], TRUE, FALSE).'>'.sprintf(__('%s Archive','restrict-widgets'), $cpta->label).'</option>';
887
 
@@ -891,7 +973,8 @@ class Restrict_Widgets
891
  {
892
  if(!isset($rw_option['selection']['custom_post_types_archives']['cpta_'.$cpta->name]) || current_user_can('manage_options'))
893
  {
894
- if(isset($instance['rw_opt']['cpta_'.$cpta->name]) === FALSE) $instance['rw_opt']['cpta_'.$cpta->name] = 0;
 
895
 
896
  $html .= '<option value="cpta_'.$cpta->name.'" '.selected($instance['rw_opt']['cpta_'.$cpta->name], TRUE, FALSE).'>'.apply_filters('rw_option_display_name', sprintf(__('%s Archive','restrict-widgets'), $cpta->label), 'custom_post_type_archive').'</option>';
897
  }
@@ -902,18 +985,14 @@ class Restrict_Widgets
902
  }
903
 
904
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
905
- {
906
  $html .= '</optgroup>';
907
- }
908
 
909
  return $html;
910
  }
911
  case 'categories':
912
  {
913
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
914
- {
915
  $html .= '<optgroup label="'.$this->options['categories'].'">';
916
- }
917
 
918
  foreach($this->categories as $category)
919
  {
@@ -921,7 +1000,8 @@ class Restrict_Widgets
921
  {
922
  case 'option':
923
  {
924
- if(isset($option['selection']['categories']['category_'.$category->cat_ID]) === FALSE) $option['selection']['categories']['category_'.$category->cat_ID] = FALSE;
 
925
 
926
  $html .= '<option value="category_'.$category->cat_ID.'" '.selected($option['selection']['categories']['category_'.$category->cat_ID], TRUE, FALSE).'>'.$category->cat_name.'</option>';
927
 
@@ -931,7 +1011,8 @@ class Restrict_Widgets
931
  {
932
  if(!isset($rw_option['selection']['categories']['category_'.$category->cat_ID]) || current_user_can('manage_options'))
933
  {
934
- if(isset($instance['rw_opt']['category_'.$category->cat_ID]) === FALSE) $instance['rw_opt']['category_'.$category->cat_ID] = 0;
 
935
 
936
  $html .= '<option value="category_'.$category->cat_ID.'" '.selected($instance['rw_opt']['category_'.$category->cat_ID], TRUE, FALSE).'>'.apply_filters('rw_option_display_name', $category->cat_name, 'category').'</option>';
937
  }
@@ -942,18 +1023,14 @@ class Restrict_Widgets
942
  }
943
 
944
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
945
- {
946
  $html .= '</optgroup>';
947
- }
948
 
949
  return $html;
950
  }
951
  case 'taxonomies':
952
  {
953
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
954
- {
955
  $html .= '<optgroup label="'.$this->options['taxonomies'].'">';
956
- }
957
 
958
  foreach($this->taxonomies as $taxonomy)
959
  {
@@ -961,7 +1038,8 @@ class Restrict_Widgets
961
  {
962
  case 'option':
963
  {
964
- if(isset($option['selection']['taxonomies']['taxonomy_'.$taxonomy->name]) === FALSE) $option['selection']['taxonomies']['taxonomy_'.$taxonomy->name] = FALSE;
 
965
 
966
  $html .= '<option value="taxonomy_'.$taxonomy->name.'" '.selected($option['selection']['taxonomies']['taxonomy_'.$taxonomy->name], TRUE, FALSE).'>'.$taxonomy->label.'</option>';
967
 
@@ -971,7 +1049,8 @@ class Restrict_Widgets
971
  {
972
  if(!isset($rw_option['selection']['taxonomies']['taxonomy_'.$taxonomy->name]) || current_user_can('manage_options'))
973
  {
974
- if(isset($instance['rw_opt']['taxonomy_'.$taxonomy->name]) === FALSE) $instance['rw_opt']['taxonomy_'.$taxonomy->name] = 0;
 
975
 
976
  $html .= '<option value="taxonomy_'.$taxonomy->name.'" '.selected($instance['rw_opt']['taxonomy_'.$taxonomy->name], TRUE, FALSE).'>'.apply_filters('rw_option_display_name', $taxonomy->label, 'taxonomy').'</option>';
977
  }
@@ -982,18 +1061,14 @@ class Restrict_Widgets
982
  }
983
 
984
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
985
- {
986
  $html .= '</optgroup>';
987
- }
988
 
989
  return $html;
990
  }
991
  case 'others':
992
  {
993
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
994
- {
995
  $html .= '<optgroup label="'.$this->options['others'].'">';
996
- }
997
 
998
  foreach($this->others as $key => $value)
999
  {
@@ -1001,7 +1076,8 @@ class Restrict_Widgets
1001
  {
1002
  case 'option':
1003
  {
1004
- if(isset($option['selection']['others']['others_'.$key]) === FALSE) $option['selection']['others']['others_'.$key] = FALSE;
 
1005
 
1006
  $html .= '<option value="others_'.$key.'" '.selected($option['selection']['others']['others_'.$key], TRUE, FALSE).'>'.$value.'</option>';
1007
 
@@ -1011,7 +1087,8 @@ class Restrict_Widgets
1011
  {
1012
  if(!isset($rw_option['selection']['others']['others_'.$key]) || current_user_can('manage_options'))
1013
  {
1014
- if(isset($instance['rw_opt']['others_'.$key]) === FALSE) $instance['rw_opt']['others_'.$key] = 0;
 
1015
 
1016
  $html .= '<option value="others_'.$key.'" '.selected($instance['rw_opt']['others_'.$key], TRUE, FALSE).'>'.apply_filters('rw_option_display_name', $value, 'other').'</option>';
1017
  }
@@ -1022,18 +1099,93 @@ class Restrict_Widgets
1022
  }
1023
 
1024
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
 
 
 
 
 
 
 
 
 
 
1025
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1026
  $html .= '</optgroup>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1027
  }
1028
 
 
 
 
1029
  return $html;
1030
  }
1031
  case 'users':
1032
  {
1033
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
1034
- {
1035
  $html .= '<optgroup label="'.$this->options['users'].'">';
1036
- }
1037
 
1038
  foreach($this->users as $key => $value)
1039
  {
@@ -1041,7 +1193,8 @@ class Restrict_Widgets
1041
  {
1042
  case 'option':
1043
  {
1044
- if(isset($option['selection']['users']['users_'.$key]) === FALSE) $option['selection']['users']['users_'.$key] = FALSE;
 
1045
 
1046
  $html .= '<option value="users_'.$key.'" '.selected($option['selection']['users']['users_'.$key], TRUE, FALSE).'>'.$value.'</option>';
1047
 
@@ -1051,7 +1204,8 @@ class Restrict_Widgets
1051
  {
1052
  if(!isset($rw_option['selection']['users']['users_'.$key]) || current_user_can('manage_options'))
1053
  {
1054
- if(isset($instance['rw_opt']['users_'.$key]) === FALSE) $instance['rw_opt']['users_'.$key] = 0;
 
1055
 
1056
  $html .= '<option value="users_'.$key.'" '.selected($instance['rw_opt']['users_'.$key], TRUE, FALSE).'>'.apply_filters('rw_option_display_name', $value, 'user').'</option>';
1057
  }
@@ -1062,54 +1216,50 @@ class Restrict_Widgets
1062
  }
1063
 
1064
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
1065
- {
1066
  $html .= '</optgroup>';
1067
- }
1068
 
1069
  return $html;
1070
  }
1071
  case 'languages':
1072
  {
1073
  if($this->languages !== FALSE)
1074
- {
1075
- if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
1076
- {
1077
- $html .= '<optgroup label="'.$this->options['languages'].'">';
1078
- }
1079
 
1080
- foreach($this->languages as $key => $language)
 
 
 
 
 
1081
  {
1082
- switch($type)
1083
  {
1084
- case 'option':
1085
- {
1086
- if(isset($option['selection']['languages']['language_'.$key]) === FALSE) $option['selection']['languages']['language_'.$key] = FALSE;
1087
 
1088
- $html .= '<option value="language_'.$key.'" '.selected($option['selection']['languages']['language_'.$key], TRUE, FALSE).'>'.$language['native_name'].'</option>';
1089
 
1090
- break;
1091
- }
1092
- case 'widget':
 
 
1093
  {
1094
- if(!isset($rw_option['selection']['languages']['language_'.$key]) || current_user_can('manage_options'))
1095
- {
1096
- if(isset($instance['rw_opt']['language_'.$key]) === FALSE) $instance['rw_opt']['language_'.$key] = 0;
1097
-
1098
- $html .= '<option value="language_'.$key.'" '.selected($instance['rw_opt']['language_'.$key], TRUE, FALSE).'>'.apply_filters('rw_option_display_name', $language['native_name'], 'language').'</option>';
1099
- }
1100
 
1101
- break;
1102
  }
 
 
1103
  }
1104
  }
 
1105
 
1106
- if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
1107
- {
1108
- $html .= '</optgroup>';
1109
- }
1110
 
1111
- return $html;
1112
- }
1113
  }
1114
  }
1115
  }
@@ -1120,7 +1270,8 @@ class Restrict_Widgets
1120
  */
1121
  public function display_admin_widgets_options($widget, $empty, $instance)
1122
  {
1123
- if(isset($instance['rw_opt']['widget_select']) === FALSE) $instance['rw_opt']['widget_select'] = FALSE;
 
1124
 
1125
  echo '
1126
  <div class="restrict-widgets-hide-div restrict-widgets">
@@ -1157,77 +1308,74 @@ class Restrict_Widgets
1157
  foreach($this->pages as $page)
1158
  {
1159
  if(in_array('pageid_'.$page->ID, $selected))
1160
- {
1161
  $instance['rw_opt']['pageid_'.$page->ID] = TRUE;
1162
- }
1163
  else
1164
- {
1165
  unset($instance['rw_opt']['pageid_'.$page->ID]);
1166
- }
1167
  }
1168
 
1169
  //custom post types
1170
  foreach($this->custom_post_types as $cpt)
1171
  {
1172
  if(in_array('cpt_'.$cpt->name, $selected))
1173
- {
1174
  $instance['rw_opt']['cpt_'.$cpt->name] = TRUE;
1175
- }
1176
  else
1177
- {
1178
  unset($instance['rw_opt']['cpt_'.$cpt->name]);
1179
- }
1180
  }
1181
 
1182
  //custom post types archives
1183
  foreach($this->custom_post_types_archives as $cpta)
1184
  {
1185
  if(in_array('cpta_'.$cpta->name, $selected))
1186
- {
1187
  $instance['rw_opt']['cpta_'.$cpta->name] = TRUE;
1188
- }
1189
  else
1190
- {
1191
  unset($instance['rw_opt']['cpta_'.$cpta->name]);
1192
- }
1193
  }
1194
 
1195
  //categories
1196
  foreach($this->categories as $category)
1197
  {
1198
  if(in_array('category_'.$category->cat_ID, $selected))
1199
- {
1200
  $instance['rw_opt']['category_'.$category->cat_ID] = TRUE;
1201
- }
1202
  else
1203
- {
1204
  unset($instance['rw_opt']['category_'.$category->cat_ID]);
1205
- }
1206
  }
1207
 
1208
  //taxonomies
1209
  foreach($this->taxonomies as $taxonomy)
1210
  {
1211
  if(in_array('taxonomy_'.$taxonomy->name, $selected))
1212
- {
1213
  $instance['rw_opt']['taxonomy_'.$taxonomy->name] = TRUE;
1214
- }
1215
  else
1216
- {
1217
  unset($instance['rw_opt']['taxonomy_'.$taxonomy->name]);
1218
- }
1219
  }
1220
 
1221
  //others
1222
  foreach($this->others as $key => $value)
1223
  {
1224
  if(in_array('others_'.$key, $selected))
1225
- {
1226
  $instance['rw_opt']['others_'.$key] = TRUE;
1227
- }
1228
  else
1229
- {
1230
  unset($instance['rw_opt']['others_'.$key]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1231
  }
1232
  }
1233
 
@@ -1235,13 +1383,9 @@ class Restrict_Widgets
1235
  foreach($this->users as $key => $value)
1236
  {
1237
  if(in_array('users_'.$key, $selected))
1238
- {
1239
  $instance['rw_opt']['users_'.$key] = TRUE;
1240
- }
1241
  else
1242
- {
1243
  unset($instance['rw_opt']['users_'.$key]);
1244
- }
1245
  }
1246
 
1247
  //languages
@@ -1250,13 +1394,9 @@ class Restrict_Widgets
1250
  foreach($this->languages as $key => $value)
1251
  {
1252
  if(in_array('language_'.$key, $selected))
1253
- {
1254
  $instance['rw_opt']['language_'.$key] = TRUE;
1255
- }
1256
  else
1257
- {
1258
  unset($instance['rw_opt']['language_'.$key]);
1259
- }
1260
  }
1261
  }
1262
  }
@@ -1279,7 +1419,9 @@ class Restrict_Widgets
1279
  $action = explode('_', $option, 2);
1280
 
1281
  if($type === 'main')
1282
- $array = array('category', 'taxonomy', 'cpt', 'cpta', 'pageid', 'others');
 
 
1283
  elseif($type === 'lang')
1284
  $array = array('language');
1285
  elseif($type === 'user')
@@ -1310,31 +1452,30 @@ class Restrict_Widgets
1310
  {
1311
  global $wp_query;
1312
 
1313
- $display_lang = $display_user = $display_main = '';
1314
- $empty_lang = $empty_user = $empty_main = TRUE;
1315
  $return = FALSE;
1316
 
1317
  $post_id = $wp_query->get_queried_object_id();
1318
 
1319
  $display_type = isset($instance['rw_opt']['widget_select']) ? $instance['rw_opt']['widget_select'] : FALSE;
1320
 
 
1321
  if(isset($instance['rw_opt']) && $this->is_widget_empty($instance['rw_opt'], 'lang') === FALSE)
1322
  {
1323
- if(function_exists('icl_get_languages') || function_exists('pll_the_languages'))
1324
  {
1325
  $empty_lang = FALSE;
1326
-
1327
- // fix for WPML
1328
- if (function_exists('icl_object_id')) {
1329
-
1330
  global $sitepress;
1331
-
1332
- if (isset($sitepress))
1333
- {
1334
  $post_id = icl_object_id($post_id, 'page', TRUE, $sitepress->get_default_language());
1335
- } else {
1336
  $post_id = icl_object_id($post_id, 'page', FALSE);
1337
- }
1338
  }
1339
 
1340
  $found_lang = (defined('ICL_LANGUAGE_CODE') && isset($instance['rw_opt']['language_'.ICL_LANGUAGE_CODE]) ? TRUE : FALSE);
@@ -1358,6 +1499,7 @@ class Restrict_Widgets
1358
  else
1359
  $display_lang = TRUE;
1360
 
 
1361
  if($return === FALSE)
1362
  {
1363
  if(isset($instance['rw_opt']) && $this->is_widget_empty($instance['rw_opt'], 'user') === FALSE)
@@ -1396,6 +1538,46 @@ class Restrict_Widgets
1396
  $display_user = TRUE;
1397
  }
1398
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1399
  if($return === FALSE)
1400
  {
1401
  if(isset($instance['rw_opt']) && $this->is_widget_empty($instance['rw_opt'], 'main') === FALSE)
@@ -1436,6 +1618,12 @@ class Restrict_Widgets
1436
  $found_main = isset($instance['rw_opt']['others_date_archive']) ? TRUE : FALSE;
1437
  elseif(is_post_type_archive())
1438
  $found_main = isset($instance['rw_opt']['cpta_'.get_post_type($post_id)]) ? TRUE : FALSE;
 
 
 
 
 
 
1439
 
1440
  $display_main = ($display_type === TRUE ? ($found_main === TRUE ? TRUE : FALSE) : ($found_main === TRUE ? FALSE : TRUE));
1441
  }
@@ -1447,15 +1635,41 @@ class Restrict_Widgets
1447
  $instance = TRUE;
1448
 
1449
  if($display_type === TRUE)
1450
- $final_return = ($display_lang === TRUE && $display_user === TRUE && $display_main === TRUE ? $instance : FALSE);
1451
  else
1452
- $final_return = ((($empty_lang === FALSE && $empty_user === FALSE && $empty_main === FALSE && $display_lang === FALSE && $display_user === FALSE && $display_main === FALSE) || ($empty_lang === FALSE && $empty_user === FALSE && $display_lang === FALSE && $display_user === FALSE) || ($empty_lang === FALSE && $empty_main === FALSE && $display_lang === FALSE && $display_main === FALSE) || ($empty_user === FALSE && $empty_main === FALSE && $display_user === FALSE && $display_main === FALSE) || ($empty_lang === FALSE && $display_lang === FALSE) || ($empty_user === FALSE && $display_lang === FALSE) || ($empty_main === FALSE && $display_main === FALSE)) ? FALSE : $instance);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1453
 
1454
- // filter true or false
1455
  if($filter === TRUE)
1456
  $final_return = apply_filters_ref_array('rw_display_widget', array($final_return, $instance));
1457
 
1458
- // if true return instance
1459
  $final_return = ($final_return === FALSE) ? FALSE : $instance;
1460
 
1461
  //display: return $instance, hide: return FALSE
@@ -1470,21 +1684,21 @@ class Restrict_Widgets
1470
  {
1471
  global $menu, $submenu;
1472
 
1473
- // if user can manage widgets but can't edit_theme_options, add widgets menu (appearance)
1474
  if(current_user_can('manage_widgets') && !current_user_can('edit_theme_options'))
1475
  {
1476
  foreach($menu as $menu_key => $menu_values)
1477
  {
1478
  if(isset($menu_values[5]) && $menu_values[5] === 'menu-appearance')
1479
  {
1480
- // if appearance menu not exists
1481
  if(empty($submenu[$menu_values[2]]))
1482
  {
1483
  $menu[$menu_key][1] = 'manage_widgets';
1484
  $menu[$menu_key][2] = 'widgets.php';
1485
  }
1486
  else
1487
- // if appearance menu exists
1488
  {
1489
  foreach($submenu[$menu_values[2]] as $submenu_key => $submenu_values)
1490
  {
@@ -1493,7 +1707,8 @@ class Restrict_Widgets
1493
  }
1494
  }
1495
  }
1496
- } // if user can't manage widgets but can edit_theme_options, remove widgets from menu
 
1497
  elseif(!current_user_can('manage_widgets') && current_user_can('edit_theme_options'))
1498
  {
1499
  foreach($menu as $menu_key => $menu_values)
@@ -1524,27 +1739,25 @@ class Restrict_Widgets
1524
  {
1525
  if(isset($menu_values[5]) && $menu_values[5] === 'menu-appearance')
1526
  {
1527
- // if appearance menu not exists
1528
  if(empty($submenu[$menu_values[2]]))
1529
  {
1530
  $menu[$menu_key][1] = 'manage_widgets';
1531
  $menu[$menu_key][2] = 'widgets.php';
1532
  }
1533
  else
1534
- // if appearance menu exists
1535
  {
1536
  $submenu[$menu_values[2]][7] = array(__('Widgets'), 'manage_widgets', 'widgets.php');
1537
 
1538
- // remove menus with edit_theme_options capability
1539
  foreach($submenu[$menu_values[2]] as $submenu_key => $submenu_values)
1540
  {
1541
  if($submenu_values[1] == 'edit_theme_options')
1542
- {
1543
  unset($submenu[$menu_values[2]][$submenu_key]);
1544
- }
1545
  }
1546
 
1547
- // fix if appearance menu item is only 1, remove submenu
1548
  if(count($submenu[$menu_values[2]]) < 2)
1549
  {
1550
  unset($submenu[$menu_values[2]][7]);
@@ -1566,19 +1779,18 @@ class Restrict_Widgets
1566
 
1567
  if($pagenow === 'widgets.php' || (defined('DOING_AJAX') && DOING_AJAX))
1568
  {
1569
- // break if we're not asking to edit widgets
1570
  if(('edit_theme_options' != $args[0]) || empty($allcaps['manage_widgets']))
1571
- {
1572
  return $allcaps;
1573
- }
1574
  else
1575
  {
1576
- // if user can't edit_theme_options but can manage_widgets
1577
  if(empty($allcaps['edit_theme_options']))
1578
  {
1579
- // menu fix
1580
  add_action('admin_menu', array(&$this, 'manage_widgets_menu_fix'), 999);
1581
- // add cap to edit widgets
 
1582
  $allcaps['edit_theme_options'] = TRUE;
1583
  }
1584
  }
@@ -1587,7 +1799,4 @@ class Restrict_Widgets
1587
  return $allcaps;
1588
  }
1589
  }
1590
-
1591
-
1592
- $restrict_widgets = new Restrict_Widgets();
1593
  ?>
2
  /*
3
  Plugin Name: Restrict Widgets
4
  Description: All in one solution for widget management in WordPress. Allows you to hide or display widgets on specified pages and restrict access for users.
5
+ Version: 1.2.0
6
  Author: dFactory
7
  Author URI: http://www.dfactory.eu/
8
  Plugin URI: http://www.dfactory.eu/plugins/restrict-widgets/
21
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
  */
23
 
24
+ if(!defined('ABSPATH')) exit; // Exit if accessed directly
25
+
26
+ define('RESTRICT_WIDGETS_URL', plugins_url('', __FILE__));
27
+ define('RESTRICT_WIDGETS_REL_PATH', dirname(plugin_basename(__FILE__)).'/');
28
+
29
+ $restrict_widgets = new Restrict_Widgets();
30
 
31
  class Restrict_Widgets
32
  {
35
  private $custom_post_types_archives = array();
36
  private $categories = array();
37
  private $taxonomies = array();
38
+ private $devices = array();
39
+ private $bbpress = array();
40
  private $others = array();
41
  private $users = array();
42
  private $languages = array();
44
  private $hidden_widget = '';
45
  private $checked_widget = '';
46
  private $widgets = array();
47
+ private $bbpress_active = FALSE;
48
+ private $polylang_active = FALSE;
49
+ private $wpml_active = FALSE;
50
 
51
 
52
  public function __construct()
53
  {
54
+ register_activation_hook(__FILE__, array(&$this, 'multisite_activation'));
55
+ register_deactivation_hook(__FILE__, array(&$this, 'multisite_deactivation'));
56
 
57
  //actions
58
  add_action('wp_loaded', array(&$this, 'polylang_widgets'), 6);
77
  }
78
 
79
 
80
+ /**
81
+ * Multisite activation
82
+ */
83
+ public function multisite_activation($networkwide)
84
+ {
85
+ if(is_multisite() && $networkwide)
86
+ {
87
+ global $wpdb;
88
+
89
+ $activated_blogs = array();
90
+ $current_blog_id = get_current_blog_id();
91
+ $blogs_ids = $wpdb->get_col($wpdb->prepare('SELECT blog_id FROM '.$wpdb->blogs, ''));
92
+
93
+ foreach($blogs_ids as $blog_id)
94
+ {
95
+ switch_to_blog($blog_id);
96
+ $this->activate_single();
97
+ $activated_blogs[] = (int)$blog_id;
98
+ }
99
+
100
+ switch_to_blog($current_blog_id);
101
+ update_site_option('restrict_widgets_activated_blogs', $activated_blogs, array());
102
+ }
103
+ else
104
+ $this->activate_single();
105
+ }
106
+
107
+
108
+ /**
109
+ * Activation
110
+ */
111
+ public function activate_single()
112
+ {
113
+ $role = get_role('administrator');
114
+ $role->add_cap('manage_widgets');
115
+
116
+ //default settings
117
+ add_option(
118
+ 'rw_widgets_options',
119
+ array(
120
+ 'available' => array(),
121
+ 'selection' => array(),
122
+ 'sidebars' => array(),
123
+ 'groups' => TRUE,
124
+ 'deactivation' => FALSE,
125
+ ),
126
+ '',
127
+ 'no'
128
+ );
129
+ }
130
+
131
+
132
+ /**
133
+ * Multisite deactivation
134
+ */
135
+ public function multisite_deactivation($networkwide)
136
+ {
137
+ if(is_multisite() && $networkwide)
138
+ {
139
+ global $wpdb;
140
+
141
+ $current_blog_id = get_current_blog_id();
142
+ $blogs_ids = $wpdb->get_col($wpdb->prepare('SELECT blog_id FROM '.$wpdb->blogs, ''));
143
+
144
+ if(($activated_blogs = get_site_option('restrict_widgets_activated_blogs', FALSE, FALSE)) === FALSE)
145
+ $activated_blogs = array();
146
+
147
+ foreach($blogs_ids as $blog_id)
148
+ {
149
+ switch_to_blog($blog_id);
150
+ $this->deactivate_single();
151
+
152
+ if(in_array((int)$blog_id, $activated_blogs, TRUE))
153
+ unset($activated_blogs[array_search($blog_id, $activated_blogs)]);
154
+ }
155
+
156
+ switch_to_blog($current_blog_id);
157
+ update_site_option('restrict_widgets_activated_blogs', $activated_blogs);
158
+ }
159
+ else
160
+ $this->deactivate_single();
161
+ }
162
+
163
+
164
+ /**
165
+ * Deactivation
166
+ */
167
+ public function deactivate_single()
168
+ {
169
+ $option = get_option('rw_widgets_options');
170
+
171
+ if($option['deactivation'] === TRUE)
172
+ {
173
+ global $wp_roles, $wp_registered_widgets;
174
+
175
+ //removes roles
176
+ foreach($wp_roles->roles as $role_name => $empty)
177
+ {
178
+ $role = get_role($role_name);
179
+ $role->remove_cap('manage_widgets');
180
+ }
181
+
182
+ //clears all widgets
183
+ foreach($wp_registered_widgets as $widget)
184
+ {
185
+ if(isset($widget['params'][0]['number']) && $widget['params'][0]['number'] !== -1)
186
+ {
187
+ $option = get_option($widget['callback'][0]->option_name);
188
+ unset($option[$widget['params'][0]['number']]['rw_opt']);
189
+ update_option($widget['callback'][0]->option_name, $option);
190
+ }
191
+ }
192
+
193
+ delete_option('rw_widgets_options');
194
+ }
195
+ }
196
+
197
+
198
  /**
199
  * Fix for is_active_sidebar (all hidden widgets on sidebar = FALSE)
200
  */
212
 
213
  foreach($wp_registered_widgets as $widget)
214
  {
215
+ if(isset($widget['callback'][0]->option_name) && $widget['callback'][0]->option_name !== '' && empty($widgets_classes[$widget['callback'][0]->option_name]))
216
+ $widgets_c[$widget['callback'][0]->option_name] = get_option($widget['callback'][0]->option_name);
 
 
 
217
  }
218
 
219
  foreach($widgets_c as $widget_base_id => $widgets)
265
  */
266
  public function polylang_widgets()
267
  {
268
+ if($this->polylang_active === TRUE)
269
  {
270
  global $polylang;
271
 
272
  if(has_action('in_widget_form', array($polylang, 'in_widget_form')))
 
273
  remove_action('in_widget_form', array($polylang, 'in_widget_form'));
 
274
  }
275
  }
276
 
280
  */
281
  public function load_textdomain()
282
  {
283
+ load_plugin_textdomain('restrict-widgets', FALSE, RESTRICT_WIDGETS_REL_PATH.'languages/');
284
+
285
+ if(class_exists('bbPress'))
286
+ $this->bbpress_active = TRUE;
287
+
288
+ if(class_exists('Polylang'))
289
+ $this->polylang_active = TRUE;
290
+
291
+ if(class_exists('SitePress'))
292
+ $this->wpml_active = TRUE;
293
  }
294
+
295
+
296
  /**
297
  * Add links to Support Forum
298
  */
299
  public function plugin_extend_links($links, $file)
300
  {
301
+ if(!current_user_can('install_plugins'))
302
  return $links;
303
+
304
  $plugin = plugin_basename(__FILE__);
305
+
306
+ if($file == $plugin)
307
  {
308
  return array_merge(
309
  $links,
310
  array(sprintf('<a href="http://www.dfactory.eu/support/forum/restrict-widgets/" target="_blank">%s</a>', __('Support', 'restrict-widgets')))
311
  );
312
  }
313
+
314
  return $links;
315
  }
316
+
317
+
318
  /**
319
  * Add links to Settings page
320
  */
321
  function plugin_settings_link($links, $file)
322
  {
323
+ if(!is_admin() || !current_user_can('edit_theme_options'))
324
  return $links;
325
 
326
  static $plugin;
327
 
328
  $plugin = plugin_basename(__FILE__);
329
 
330
+ if($file == $plugin)
331
  {
332
  $settings_link = sprintf('<a href="%s">%s</a>', admin_url('widgets.php'), __('Widgets', 'restrict-widgets'));
333
  array_unshift($links, $settings_link);
348
 
349
  $option = get_option('rw_widgets_options');
350
 
351
+ if(
352
+ //standard based widget class
353
+ (isset($wp_registered_widgets[$params[0]['widget_id']]['callback'][0]) && is_object($wp_registered_widgets[$params[0]['widget_id']]['callback'][0]) && in_array(get_class($wp_registered_widgets[$params[0]['widget_id']]['callback'][0]), array_keys($option['available']))) ||
354
+
355
+ //non-standard based widget
356
+ (isset($wp_registered_widgets[$params[0]['widget_id']]['id']) && in_array($wp_registered_widgets[$params[0]['widget_id']]['id'], array_keys($option['available'])))
357
+ )
358
+ $params[0]['_hide'] = 1;
359
  }
360
 
361
  return $params;
362
  }
363
 
364
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
365
  /**
366
  * Loads dynamic data
367
  */
413
  'custom_post_types_archives' => __('Custom Post Type Archives', 'restrict-widgets'),
414
  'categories' => __('Categories', 'restrict-widgets'),
415
  'taxonomies' => __('Taxonomies', 'restrict-widgets'),
416
+ 'others' => __('Others', 'restrict-widgets')
 
 
417
  );
418
 
419
+ //bbPress support
420
+ if($this->bbpress_active === TRUE)
421
+ {
422
+ $this->bbpress = array(
423
+ 'search' => __('Search', 'restrict-widgets'),
424
+ 'single_user' => __('Single User', 'restrict-widgets'),
425
+ 'topic_tag' => __('Topic Tag', 'restrict-widgets')
426
+ );
427
+
428
+ $this->options['bbpress'] = __('bbPress', 'restrict-widgets');
429
+ }
430
+
431
+ $this->options['devices'] = __('Devices', 'restrict-widgets');
432
+ $this->options['users'] = __('Users', 'restrict-widgets');
433
+ $this->options['languages'] = __('Languages', 'restrict-widgets');
434
+
435
  $this->others = array(
436
  'front_page' => __('Front Page', 'restrict-widgets'),
437
  'blog_page' => __('Blog Page', 'restrict-widgets'),
445
 
446
  $this->users = array(
447
  'logged_in' => __('Logged in users', 'restrict-widgets'),
448
+ 'logged_out' => __('Logged out users', 'restrict-widgets')
449
+ );
450
+
451
+ $this->devices = array(
452
+ 'mobile' => __('Mobile', 'restrict-widgets'),
453
+ 'desktop' => __('Desktop, Laptop, etc.', 'restrict-widgets')
454
  );
455
 
456
  $this->pages = get_pages(
464
  );
465
 
466
  //Polylang support
467
+ if($this->polylang_active === TRUE)
468
  {
469
  $languages = get_terms('language', array('hide_empty' => FALSE));
470
 
475
  }
476
  }
477
  //WMPL support
478
+ elseif($this->wpml_active === TRUE)
479
  $this->languages = icl_get_languages('skip_missing=0&orderby=native_name&order=asc');
480
  else
481
  $this->languages = FALSE;
548
  $tmp = explode('_', $element, 2);
549
 
550
  if(in_array($tmp[0], array('cpt', 'cpta'), TRUE))
 
551
  $save_widgets['selection'][$tmp[0] === 'cpt' ? 'custom_post_types' : 'custom_post_types_archives'][$tmp[0].'_'.sanitize_key($tmp[1])] = TRUE;
 
552
  }
553
 
554
  foreach($this->pages as $page)
555
  {
556
  if(in_array('pageid_'.$page->ID, $selected, TRUE))
 
557
  $save_widgets['selection']['pages']['pageid_'.$page->ID] = TRUE;
 
558
  }
559
 
560
  foreach($this->custom_post_types as $cpt)
561
  {
562
  if(in_array('cpt_'.$cpt->name, $selected, TRUE))
 
563
  $save_widgets['selection']['custom_post_types']['cpt_'.$cpt->name] = TRUE;
 
564
  }
565
 
566
  foreach($this->categories as $category)
567
  {
568
  if(in_array('category_'.$category->cat_ID, $selected, TRUE))
 
569
  $save_widgets['selection']['categories']['category_'.$category->cat_ID] = TRUE;
 
570
  }
571
 
572
  foreach($this->taxonomies as $taxonomy)
573
  {
574
  if(in_array('taxonomy_'.$taxonomy->name, $selected, TRUE))
 
575
  $save_widgets['selection']['taxonomies']['taxonomy_'.$taxonomy->name] = TRUE;
 
576
  }
577
 
578
  foreach($this->others as $key => $value)
579
  {
580
  if(in_array('others_'.$key, $selected, TRUE))
 
581
  $save_widgets['selection']['others']['others_'.$key] = TRUE;
 
582
  }
583
 
584
  foreach($this->users as $key => $value)
585
  {
586
  if(in_array('users_'.$key, $selected, TRUE))
 
587
  $save_widgets['selection']['users']['users_'.$key] = TRUE;
588
+ }
589
+
590
+ foreach($this->devices as $key => $value)
591
+ {
592
+ if(in_array('devices_'.$key, $selected, TRUE))
593
+ $save_widgets['selection']['devices']['devices_'.$key] = TRUE;
594
+ }
595
+
596
+ if($this->bbpress_active === TRUE)
597
+ {
598
+ foreach($this->bbpress as $key => $value)
599
+ {
600
+ if(in_array('bbpress_'.$key, $selected, TRUE))
601
+ $save_widgets['selection']['bbpress']['bbpress_'.$key] = TRUE;
602
  }
603
  }
604
  }
622
  $role = get_role($role_name);
623
 
624
  if(in_array($role_name, $roles_a))
 
625
  $role->add_cap('manage_widgets');
 
626
  else
 
627
  $role->remove_cap('manage_widgets');
 
628
  }
629
  }
630
 
657
  foreach($widgets as $widget)
658
  {
659
  if(isset($widget['callback'][0]) && is_object($widget['callback'][0]))
 
660
  $widgets_unique[get_class($widget['callback'][0])] = $widget['name'];
 
661
  else
 
662
  $widgets_unique[$widget['id']] = $widget['name'];
 
663
  }
664
 
665
  echo '
695
  {
696
  if($sidebar['id'] !== 'wp_inactive_widgets')
697
  {
698
+ if(isset($option['sidebars'][$sidebar['id']]) === FALSE)
699
+ $option['sidebars'][$sidebar['id']] = FALSE;
700
 
701
  echo '<option value="'.$sidebar['id'].'" '.selected($option['sidebars'][$sidebar['id']], TRUE, FALSE).'>'.$sidebar['name'].'</option>';
702
  }
713
 
714
  foreach(array_unique($widgets_unique) as $widget_class => $widget_name)
715
  {
716
+ if(isset($option['available'][$widget_class]) === FALSE)
717
+ $option['available'][$widget_class] = FALSE;
718
 
719
  echo '<option value="'.$widget_class.'" '.selected($option['available'][$widget_class], TRUE, FALSE).'>'.$widget_name.'</option>';
720
  }
760
  </tr>
761
  </table>
762
  <input type="submit" value="'.__('Save settings', 'restrict-widgets').'" name="save-widgets-options" class="button button-primary" id="save-widgets-options" />
763
+ <p id="df-credits">Created by<a href="http://www.dfactory.eu/?utm_source=restrict-widgets-settings&utm_medium=link&utm_campaign=created-by" target="_blank" title="dFactory - Quality plugins for WordPress"><img src="'.RESTRICT_WIDGETS_URL.'/images/logo-dfactory.png'.'" title="dFactory - Quality plugins for WordPress" alt="dFactory - Quality plugins for WordPress" /></a></p>
764
  <br class="clear" />
765
  </form>
766
  </div>
787
 
788
  wp_enqueue_script(
789
  'chosen',
790
+ RESTRICT_WIDGETS_URL.'/js/chosen.jquery.min.js',
791
  array('jquery')
792
  );
793
 
794
  wp_enqueue_script(
795
  'restrict-widgets',
796
+ RESTRICT_WIDGETS_URL.'/js/restrict-widgets-admin.js',
797
  array('jquery', 'chosen')
798
  );
799
 
821
  //which sidebars to hide
822
  foreach($widgets as $widget)
823
  {
824
+ if(
825
+ //standard based widget class
826
+ (isset($wp_registered_widgets[$widget]['callback'][0]) && is_object($wp_registered_widgets[$widget]['callback'][0]) && in_array(get_class($wp_registered_widgets[$widget]['callback'][0]), $restrict)) ||
827
+
828
+ //non-standard based widget
829
+ (isset($wp_registered_widgets[$widget]['id']) && in_array($wp_registered_widgets[$widget]['id'], $restrict))
830
+ )
831
+ $js_widgets[] = $widget;
832
  }
833
 
834
  //which widgets to hide
836
  {
837
  //standard based widget class
838
  if(isset($widget['callback'][0]) && is_object($widget['callback'][0]) && in_array(get_class($widget['callback'][0]), $restrict))
 
839
  $js_class[] = $widget['callback'][0]->id_base;
 
840
  //non-standard based widget
841
  elseif(in_array($widget['id'], $restrict))
 
842
  $js_nonclass[] = $widget['id'];
 
843
  }
844
  }
845
 
846
  wp_localize_script(
847
  'restrict-widgets',
848
+ 'rwArgs',
849
  array(
850
  'placeholder_text' => esc_attr__('Select options', 'restrict-widgets'),
851
  'restrict_available_widgets' => esc_attr__('Select widgets', 'restrict-widgets'),
860
  )
861
  );
862
 
863
+ wp_enqueue_style('chosen', RESTRICT_WIDGETS_URL.'/css/chosen.css');
864
+ wp_enqueue_style('style', RESTRICT_WIDGETS_URL.'/css/restrict-widgets-admin.css');
865
  }
866
 
867
 
878
  case 'pages':
879
  {
880
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
 
881
  $html .= '<optgroup label="'.$this->options['pages'].'">';
 
882
 
883
  foreach($this->pages as $page)
884
  {
886
  {
887
  case 'option':
888
  {
889
+ if(isset($option['selection']['pages']['pageid_'.$page->ID]) === FALSE)
890
+ $option['selection']['pages']['pageid_'.$page->ID] = FALSE;
891
 
892
  $html .= '<option value="pageid_'.$page->ID.'" '.selected($option['selection']['pages']['pageid_'.$page->ID], TRUE, FALSE).'>'.$page->post_title.'</option>';
893
 
897
  {
898
  if(!isset($rw_option['selection']['pages']['pageid_'.$page->ID]) || current_user_can('manage_options'))
899
  {
900
+ if(isset($instance['rw_opt']['pageid_'.$page->ID]) === FALSE)
901
+ $instance['rw_opt']['pageid_'.$page->ID] = 0;
902
 
903
  $html .= '<option value="pageid_'.$page->ID.'" '.selected($instance['rw_opt']['pageid_'.$page->ID], TRUE, FALSE).'>'.apply_filters('rw_option_display_name', $page->post_title, 'page').'</option>';
904
  }
909
  }
910
 
911
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
 
912
  $html .= '</optgroup>';
 
913
 
914
  return $html;
915
  }
916
  case 'custom_post_types':
917
  {
918
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
 
919
  $html .= '<optgroup label="'.$this->options['custom_post_types'].'">';
 
920
 
921
  foreach($this->custom_post_types as $cpt)
922
  {
924
  {
925
  case 'option':
926
  {
927
+ if(isset($option['selection']['custom_post_types']['cpt_'.$cpt->name]) === FALSE)
928
+ $option['selection']['custom_post_types']['cpt_'.$cpt->name] = FALSE;
929
 
930
  $html .= '<option value="cpt_'.$cpt->name.'" '.selected($option['selection']['custom_post_types']['cpt_'.$cpt->name], TRUE, FALSE).'>'.sprintf(__('Single %s','restrict-widgets'), $cpt->label).'</option>';
931
 
935
  {
936
  if(!isset($rw_option['selection']['custom_post_types']['cpt_'.$cpt->name]) || current_user_can('manage_options'))
937
  {
938
+ if(isset($instance['rw_opt']['cpt_'.$cpt->name]) === FALSE)
939
+ $instance['rw_opt']['cpt_'.$cpt->name] = 0;
940
 
941
  $html .= '<option value="cpt_'.$cpt->name.'" '.selected($instance['rw_opt']['cpt_'.$cpt->name], TRUE, FALSE).'>'.apply_filters('rw_option_display_name', sprintf(__('Single %s','restrict-widgets'), $cpt->label), 'custom_post_type').'</option>';
942
  }
947
  }
948
 
949
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
 
950
  $html .= '</optgroup>';
 
951
 
952
  return $html;
953
  }
954
  case 'custom_post_types_archives':
955
  {
956
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
 
957
  $html .= '<optgroup label="'.$this->options['custom_post_types_archives'].'">';
 
958
 
959
  foreach($this->custom_post_types_archives as $cpta)
960
  {
962
  {
963
  case 'option':
964
  {
965
+ if(isset($option['selection']['custom_post_types_archives']['cpta_'.$cpta->name]) === FALSE)
966
+ $option['selection']['custom_post_types_archives']['cpta_'.$cpta->name] = FALSE;
967
 
968
  $html .= '<option value="cpta_'.$cpta->name.'" '.selected($option['selection']['custom_post_types_archives']['cpta_'.$cpta->name], TRUE, FALSE).'>'.sprintf(__('%s Archive','restrict-widgets'), $cpta->label).'</option>';
969
 
973
  {
974
  if(!isset($rw_option['selection']['custom_post_types_archives']['cpta_'.$cpta->name]) || current_user_can('manage_options'))
975
  {
976
+ if(isset($instance['rw_opt']['cpta_'.$cpta->name]) === FALSE)
977
+ $instance['rw_opt']['cpta_'.$cpta->name] = 0;
978
 
979
  $html .= '<option value="cpta_'.$cpta->name.'" '.selected($instance['rw_opt']['cpta_'.$cpta->name], TRUE, FALSE).'>'.apply_filters('rw_option_display_name', sprintf(__('%s Archive','restrict-widgets'), $cpta->label), 'custom_post_type_archive').'</option>';
980
  }
985
  }
986
 
987
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
 
988
  $html .= '</optgroup>';
 
989
 
990
  return $html;
991
  }
992
  case 'categories':
993
  {
994
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
 
995
  $html .= '<optgroup label="'.$this->options['categories'].'">';
 
996
 
997
  foreach($this->categories as $category)
998
  {
1000
  {
1001
  case 'option':
1002
  {
1003
+ if(isset($option['selection']['categories']['category_'.$category->cat_ID]) === FALSE)
1004
+ $option['selection']['categories']['category_'.$category->cat_ID] = FALSE;
1005
 
1006
  $html .= '<option value="category_'.$category->cat_ID.'" '.selected($option['selection']['categories']['category_'.$category->cat_ID], TRUE, FALSE).'>'.$category->cat_name.'</option>';
1007
 
1011
  {
1012
  if(!isset($rw_option['selection']['categories']['category_'.$category->cat_ID]) || current_user_can('manage_options'))
1013
  {
1014
+ if(isset($instance['rw_opt']['category_'.$category->cat_ID]) === FALSE)
1015
+ $instance['rw_opt']['category_'.$category->cat_ID] = 0;
1016
 
1017
  $html .= '<option value="category_'.$category->cat_ID.'" '.selected($instance['rw_opt']['category_'.$category->cat_ID], TRUE, FALSE).'>'.apply_filters('rw_option_display_name', $category->cat_name, 'category').'</option>';
1018
  }
1023
  }
1024
 
1025
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
 
1026
  $html .= '</optgroup>';
 
1027
 
1028
  return $html;
1029
  }
1030
  case 'taxonomies':
1031
  {
1032
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
 
1033
  $html .= '<optgroup label="'.$this->options['taxonomies'].'">';
 
1034
 
1035
  foreach($this->taxonomies as $taxonomy)
1036
  {
1038
  {
1039
  case 'option':
1040
  {
1041
+ if(isset($option['selection']['taxonomies']['taxonomy_'.$taxonomy->name]) === FALSE)
1042
+ $option['selection']['taxonomies']['taxonomy_'.$taxonomy->name] = FALSE;
1043
 
1044
  $html .= '<option value="taxonomy_'.$taxonomy->name.'" '.selected($option['selection']['taxonomies']['taxonomy_'.$taxonomy->name], TRUE, FALSE).'>'.$taxonomy->label.'</option>';
1045
 
1049
  {
1050
  if(!isset($rw_option['selection']['taxonomies']['taxonomy_'.$taxonomy->name]) || current_user_can('manage_options'))
1051
  {
1052
+ if(isset($instance['rw_opt']['taxonomy_'.$taxonomy->name]) === FALSE)
1053
+ $instance['rw_opt']['taxonomy_'.$taxonomy->name] = 0;
1054
 
1055
  $html .= '<option value="taxonomy_'.$taxonomy->name.'" '.selected($instance['rw_opt']['taxonomy_'.$taxonomy->name], TRUE, FALSE).'>'.apply_filters('rw_option_display_name', $taxonomy->label, 'taxonomy').'</option>';
1056
  }
1061
  }
1062
 
1063
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
 
1064
  $html .= '</optgroup>';
 
1065
 
1066
  return $html;
1067
  }
1068
  case 'others':
1069
  {
1070
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
 
1071
  $html .= '<optgroup label="'.$this->options['others'].'">';
 
1072
 
1073
  foreach($this->others as $key => $value)
1074
  {
1076
  {
1077
  case 'option':
1078
  {
1079
+ if(isset($option['selection']['others']['others_'.$key]) === FALSE)
1080
+ $option['selection']['others']['others_'.$key] = FALSE;
1081
 
1082
  $html .= '<option value="others_'.$key.'" '.selected($option['selection']['others']['others_'.$key], TRUE, FALSE).'>'.$value.'</option>';
1083
 
1087
  {
1088
  if(!isset($rw_option['selection']['others']['others_'.$key]) || current_user_can('manage_options'))
1089
  {
1090
+ if(isset($instance['rw_opt']['others_'.$key]) === FALSE)
1091
+ $instance['rw_opt']['others_'.$key] = 0;
1092
 
1093
  $html .= '<option value="others_'.$key.'" '.selected($instance['rw_opt']['others_'.$key], TRUE, FALSE).'>'.apply_filters('rw_option_display_name', $value, 'other').'</option>';
1094
  }
1099
  }
1100
 
1101
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
1102
+ $html .= '</optgroup>';
1103
+
1104
+ return $html;
1105
+ }
1106
+ case 'devices':
1107
+ {
1108
+ if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
1109
+ $html .= '<optgroup label="'.$this->options['devices'].'">';
1110
+
1111
+ foreach($this->devices as $key => $value)
1112
  {
1113
+ switch($type)
1114
+ {
1115
+ case 'option':
1116
+ {
1117
+ if(isset($option['selection']['devices']['devices_'.$key]) === FALSE)
1118
+ $option['selection']['devices']['devices_'.$key] = FALSE;
1119
+
1120
+ $html .= '<option value="devices_'.$key.'" '.selected($option['selection']['devices']['devices_'.$key], TRUE, FALSE).'>'.$value.'</option>';
1121
+
1122
+ break;
1123
+ }
1124
+ case 'widget':
1125
+ {
1126
+ if(!isset($rw_option['selection']['devices']['devices_'.$key]) || current_user_can('manage_options'))
1127
+ {
1128
+ if(isset($instance['rw_opt']['devices_'.$key]) === FALSE)
1129
+ $instance['rw_opt']['devices_'.$key] = 0;
1130
+
1131
+ $html .= '<option value="devices_'.$key.'" '.selected($instance['rw_opt']['devices_'.$key], TRUE, FALSE).'>'.apply_filters('rw_option_display_name', $value, 'device').'</option>';
1132
+ }
1133
+
1134
+ break;
1135
+ }
1136
+ }
1137
+ }
1138
+
1139
+ if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
1140
  $html .= '</optgroup>';
1141
+
1142
+ return $html;
1143
+ }
1144
+ case 'bbpress':
1145
+ {
1146
+ if($this->bbpress_active === FALSE)
1147
+ return $html;
1148
+
1149
+ if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
1150
+ $html .= '<optgroup label="'.$this->options['bbpress'].'">';
1151
+
1152
+ foreach($this->bbpress as $key => $value)
1153
+ {
1154
+ switch($type)
1155
+ {
1156
+ case 'option':
1157
+ {
1158
+ if(isset($option['selection']['bbpress']['bbpress_'.$key]) === FALSE)
1159
+ $option['selection']['bbpress']['bbpress_'.$key] = FALSE;
1160
+
1161
+ $html .= '<option value="bbpress_'.$key.'" '.selected($option['selection']['bbpress']['bbpress_'.$key], TRUE, FALSE).'>'.$value.'</option>';
1162
+
1163
+ break;
1164
+ }
1165
+ case 'widget':
1166
+ {
1167
+ if(!isset($rw_option['selection']['bbpress']['bbpress_'.$key]) || current_user_can('manage_options'))
1168
+ {
1169
+ if(isset($instance['rw_opt']['bbpress_'.$key]) === FALSE)
1170
+ $instance['rw_opt']['bbpress_'.$key] = 0;
1171
+
1172
+ $html .= '<option value="bbpress_'.$key.'" '.selected($instance['rw_opt']['bbpress_'.$key], TRUE, FALSE).'>'.apply_filters('rw_option_display_name', $value, 'bbpress').'</option>';
1173
+ }
1174
+
1175
+ break;
1176
+ }
1177
+ }
1178
  }
1179
 
1180
+ if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
1181
+ $html .= '</optgroup>';
1182
+
1183
  return $html;
1184
  }
1185
  case 'users':
1186
  {
1187
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
 
1188
  $html .= '<optgroup label="'.$this->options['users'].'">';
 
1189
 
1190
  foreach($this->users as $key => $value)
1191
  {
1193
  {
1194
  case 'option':
1195
  {
1196
+ if(isset($option['selection']['users']['users_'.$key]) === FALSE)
1197
+ $option['selection']['users']['users_'.$key] = FALSE;
1198
 
1199
  $html .= '<option value="users_'.$key.'" '.selected($option['selection']['users']['users_'.$key], TRUE, FALSE).'>'.$value.'</option>';
1200
 
1204
  {
1205
  if(!isset($rw_option['selection']['users']['users_'.$key]) || current_user_can('manage_options'))
1206
  {
1207
+ if(isset($instance['rw_opt']['users_'.$key]) === FALSE)
1208
+ $instance['rw_opt']['users_'.$key] = 0;
1209
 
1210
  $html .= '<option value="users_'.$key.'" '.selected($instance['rw_opt']['users_'.$key], TRUE, FALSE).'>'.apply_filters('rw_option_display_name', $value, 'user').'</option>';
1211
  }
1216
  }
1217
 
1218
  if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
 
1219
  $html .= '</optgroup>';
 
1220
 
1221
  return $html;
1222
  }
1223
  case 'languages':
1224
  {
1225
  if($this->languages !== FALSE)
1226
+ return $html;
 
 
 
 
1227
 
1228
+ if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
1229
+ $html .= '<optgroup label="'.$this->options['languages'].'">';
1230
+
1231
+ foreach($this->languages as $key => $language)
1232
+ {
1233
+ switch($type)
1234
  {
1235
+ case 'option':
1236
  {
1237
+ if(isset($option['selection']['languages']['language_'.$key]) === FALSE)
1238
+ $option['selection']['languages']['language_'.$key] = FALSE;
 
1239
 
1240
+ $html .= '<option value="language_'.$key.'" '.selected($option['selection']['languages']['language_'.$key], TRUE, FALSE).'>'.$language['native_name'].'</option>';
1241
 
1242
+ break;
1243
+ }
1244
+ case 'widget':
1245
+ {
1246
+ if(!isset($rw_option['selection']['languages']['language_'.$key]) || current_user_can('manage_options'))
1247
  {
1248
+ if(isset($instance['rw_opt']['language_'.$key]) === FALSE)
1249
+ $instance['rw_opt']['language_'.$key] = 0;
 
 
 
 
1250
 
1251
+ $html .= '<option value="language_'.$key.'" '.selected($instance['rw_opt']['language_'.$key], TRUE, FALSE).'>'.apply_filters('rw_option_display_name', $language['native_name'], 'language').'</option>';
1252
  }
1253
+
1254
+ break;
1255
  }
1256
  }
1257
+ }
1258
 
1259
+ if(($rw_option['groups'] === TRUE && $type === 'widget') || current_user_can('manage_options'))
1260
+ $html .= '</optgroup>';
 
 
1261
 
1262
+ return $html;
 
1263
  }
1264
  }
1265
  }
1270
  */
1271
  public function display_admin_widgets_options($widget, $empty, $instance)
1272
  {
1273
+ if(isset($instance['rw_opt']['widget_select']) === FALSE)
1274
+ $instance['rw_opt']['widget_select'] = FALSE;
1275
 
1276
  echo '
1277
  <div class="restrict-widgets-hide-div restrict-widgets">
1308
  foreach($this->pages as $page)
1309
  {
1310
  if(in_array('pageid_'.$page->ID, $selected))
 
1311
  $instance['rw_opt']['pageid_'.$page->ID] = TRUE;
 
1312
  else
 
1313
  unset($instance['rw_opt']['pageid_'.$page->ID]);
 
1314
  }
1315
 
1316
  //custom post types
1317
  foreach($this->custom_post_types as $cpt)
1318
  {
1319
  if(in_array('cpt_'.$cpt->name, $selected))
 
1320
  $instance['rw_opt']['cpt_'.$cpt->name] = TRUE;
 
1321
  else
 
1322
  unset($instance['rw_opt']['cpt_'.$cpt->name]);
 
1323
  }
1324
 
1325
  //custom post types archives
1326
  foreach($this->custom_post_types_archives as $cpta)
1327
  {
1328
  if(in_array('cpta_'.$cpta->name, $selected))
 
1329
  $instance['rw_opt']['cpta_'.$cpta->name] = TRUE;
 
1330
  else
 
1331
  unset($instance['rw_opt']['cpta_'.$cpta->name]);
 
1332
  }
1333
 
1334
  //categories
1335
  foreach($this->categories as $category)
1336
  {
1337
  if(in_array('category_'.$category->cat_ID, $selected))
 
1338
  $instance['rw_opt']['category_'.$category->cat_ID] = TRUE;
 
1339
  else
 
1340
  unset($instance['rw_opt']['category_'.$category->cat_ID]);
 
1341
  }
1342
 
1343
  //taxonomies
1344
  foreach($this->taxonomies as $taxonomy)
1345
  {
1346
  if(in_array('taxonomy_'.$taxonomy->name, $selected))
 
1347
  $instance['rw_opt']['taxonomy_'.$taxonomy->name] = TRUE;
 
1348
  else
 
1349
  unset($instance['rw_opt']['taxonomy_'.$taxonomy->name]);
 
1350
  }
1351
 
1352
  //others
1353
  foreach($this->others as $key => $value)
1354
  {
1355
  if(in_array('others_'.$key, $selected))
 
1356
  $instance['rw_opt']['others_'.$key] = TRUE;
 
1357
  else
 
1358
  unset($instance['rw_opt']['others_'.$key]);
1359
+ }
1360
+
1361
+ //devices
1362
+ foreach($this->devices as $key => $value)
1363
+ {
1364
+ if(in_array('devices_'.$key, $selected))
1365
+ $instance['rw_opt']['devices_'.$key] = TRUE;
1366
+ else
1367
+ unset($instance['rw_opt']['devices_'.$key]);
1368
+ }
1369
+
1370
+ //bbpress
1371
+ if($this->bbpress_active === TRUE)
1372
+ {
1373
+ foreach($this->bbpress as $key => $value)
1374
+ {
1375
+ if(in_array('bbpress_'.$key, $selected))
1376
+ $instance['rw_opt']['bbpress_'.$key] = TRUE;
1377
+ else
1378
+ unset($instance['rw_opt']['bbpress_'.$key]);
1379
  }
1380
  }
1381
 
1383
  foreach($this->users as $key => $value)
1384
  {
1385
  if(in_array('users_'.$key, $selected))
 
1386
  $instance['rw_opt']['users_'.$key] = TRUE;
 
1387
  else
 
1388
  unset($instance['rw_opt']['users_'.$key]);
 
1389
  }
1390
 
1391
  //languages
1394
  foreach($this->languages as $key => $value)
1395
  {
1396
  if(in_array('language_'.$key, $selected))
 
1397
  $instance['rw_opt']['language_'.$key] = TRUE;
 
1398
  else
 
1399
  unset($instance['rw_opt']['language_'.$key]);
 
1400
  }
1401
  }
1402
  }
1419
  $action = explode('_', $option, 2);
1420
 
1421
  if($type === 'main')
1422
+ $array = array('category', 'taxonomy', 'cpt', 'cpta', 'pageid', 'others', 'bbpress');
1423
+ elseif($type === 'device')
1424
+ $array = array('devices');
1425
  elseif($type === 'lang')
1426
  $array = array('language');
1427
  elseif($type === 'user')
1452
  {
1453
  global $wp_query;
1454
 
1455
+ $display_lang = $display_user = $display_device = $display_main = '';
1456
+ $empty_lang = $empty_user = $empty_device = $empty_main = TRUE;
1457
  $return = FALSE;
1458
 
1459
  $post_id = $wp_query->get_queried_object_id();
1460
 
1461
  $display_type = isset($instance['rw_opt']['widget_select']) ? $instance['rw_opt']['widget_select'] : FALSE;
1462
 
1463
+ //languages
1464
  if(isset($instance['rw_opt']) && $this->is_widget_empty($instance['rw_opt'], 'lang') === FALSE)
1465
  {
1466
+ if($this->polylang_active === TRUE || $this->wpml_active === TRUE)
1467
  {
1468
  $empty_lang = FALSE;
1469
+
1470
+ //fix for WPML
1471
+ if(function_exists('icl_object_id'))
1472
+ {
1473
  global $sitepress;
1474
+
1475
+ if(isset($sitepress))
 
1476
  $post_id = icl_object_id($post_id, 'page', TRUE, $sitepress->get_default_language());
1477
+ else
1478
  $post_id = icl_object_id($post_id, 'page', FALSE);
 
1479
  }
1480
 
1481
  $found_lang = (defined('ICL_LANGUAGE_CODE') && isset($instance['rw_opt']['language_'.ICL_LANGUAGE_CODE]) ? TRUE : FALSE);
1499
  else
1500
  $display_lang = TRUE;
1501
 
1502
+ //users
1503
  if($return === FALSE)
1504
  {
1505
  if(isset($instance['rw_opt']) && $this->is_widget_empty($instance['rw_opt'], 'user') === FALSE)
1538
  $display_user = TRUE;
1539
  }
1540
 
1541
+ //devices
1542
+ if($return === FALSE)
1543
+ {
1544
+ if(isset($instance['rw_opt']) && $this->is_widget_empty($instance['rw_opt'], 'device') === FALSE)
1545
+ {
1546
+ $empty_device = FALSE;
1547
+
1548
+ if(wp_is_mobile())
1549
+ {
1550
+ if(isset($instance['rw_opt']['devices_mobile'], $instance['rw_opt']['devices_desktop']) || isset($instance['rw_opt']['devices_mobile']))
1551
+ $found_device = TRUE;
1552
+ elseif(isset($instance['rw_opt']['devices_desktop']))
1553
+ $found_device = FALSE;
1554
+ }
1555
+ else
1556
+ {
1557
+ if(isset($instance['rw_opt']['devices_desktop'], $instance['rw_opt']['devices_mobile']) || isset($instance['rw_opt']['devices_desktop']))
1558
+ $found_device = TRUE;
1559
+ elseif(isset($instance['rw_opt']['devices_mobile']))
1560
+ $found_device = FALSE;
1561
+ }
1562
+
1563
+ if($display_type === TRUE)
1564
+ {
1565
+ if($found_device === TRUE)
1566
+ $display_device = TRUE;
1567
+ else
1568
+ {
1569
+ $return = TRUE;
1570
+ $display_device = FALSE;
1571
+ }
1572
+ }
1573
+ else
1574
+ $display_device = ($found_device === TRUE ? FALSE : TRUE);
1575
+ }
1576
+ else
1577
+ $display_device = TRUE;
1578
+ }
1579
+
1580
+ //rest
1581
  if($return === FALSE)
1582
  {
1583
  if(isset($instance['rw_opt']) && $this->is_widget_empty($instance['rw_opt'], 'main') === FALSE)
1618
  $found_main = isset($instance['rw_opt']['others_date_archive']) ? TRUE : FALSE;
1619
  elseif(is_post_type_archive())
1620
  $found_main = isset($instance['rw_opt']['cpta_'.get_post_type($post_id)]) ? TRUE : FALSE;
1621
+ elseif(bbp_is_search())
1622
+ $found_main = isset($instance['rw_opt']['bbpress_search']) ? TRUE : FALSE;
1623
+ elseif(bbp_is_single_user())
1624
+ $found_main = isset($instance['rw_opt']['bbpress_single_user']) ? TRUE : FALSE;
1625
+ elseif(bbp_is_topic_tag())
1626
+ $found_main = isset($instance['rw_opt']['bbpress_topic_tag']) ? TRUE : FALSE;
1627
 
1628
  $display_main = ($display_type === TRUE ? ($found_main === TRUE ? TRUE : FALSE) : ($found_main === TRUE ? FALSE : TRUE));
1629
  }
1635
  $instance = TRUE;
1636
 
1637
  if($display_type === TRUE)
1638
+ $final_return = ($display_lang === TRUE && $display_user === TRUE && $display_device === TRUE && $display_main === TRUE ? $instance : FALSE);
1639
  else
1640
+ $final_return = (
1641
+ (
1642
+ //4
1643
+ ($empty_lang === FALSE && $empty_user === FALSE && $empty_device === FALSE && $empty_main === FALSE && $display_lang === FALSE && $display_user === FALSE && $display_device === FALSE && $display_main === FALSE) ||
1644
+
1645
+ //3
1646
+ ($empty_lang === FALSE && $empty_user === FALSE && $empty_device === FALSE && $display_lang === FALSE && $display_user === FALSE && $display_device === FALSE) ||
1647
+ ($empty_lang === FALSE && $empty_user === FALSE && $empty_main === FALSE && $display_lang === FALSE && $display_user === FALSE && $display_main === FALSE) ||
1648
+ ($empty_lang === FALSE && $empty_device === FALSE && $empty_main === FALSE && $display_lang === FALSE && $display_device === FALSE && $display_main === FALSE) ||
1649
+ ($empty_user === FALSE && $empty_device === FALSE && $empty_main === FALSE && $display_user === FALSE && $display_device === FALSE && $display_main === FALSE) ||
1650
+
1651
+ //2
1652
+ ($empty_lang === FALSE && $empty_user === FALSE && $display_lang === FALSE && $display_user === FALSE) ||
1653
+ ($empty_lang === FALSE && $empty_device === FALSE && $display_lang === FALSE && $display_device === FALSE) ||
1654
+ ($empty_lang === FALSE && $empty_main === FALSE && $display_lang === FALSE && $display_main === FALSE) ||
1655
+ ($empty_user === FALSE && $empty_device === FALSE && $display_user === FALSE && $display_device === FALSE) ||
1656
+ ($empty_user === FALSE && $empty_main === FALSE && $display_user === FALSE && $display_main === FALSE) ||
1657
+ ($empty_device === FALSE && $empty_main === FALSE && $display_device === FALSE && $display_main === FALSE) ||
1658
+
1659
+ //1
1660
+ ($empty_lang === FALSE && $display_lang === FALSE) ||
1661
+ ($empty_user === FALSE && $display_user === FALSE) ||
1662
+ ($empty_device === FALSE && $display_device === FALSE) ||
1663
+ ($empty_main === FALSE && $display_main === FALSE)
1664
+ )
1665
+ ? FALSE : $instance
1666
+ );
1667
 
1668
+ //filter true or false
1669
  if($filter === TRUE)
1670
  $final_return = apply_filters_ref_array('rw_display_widget', array($final_return, $instance));
1671
 
1672
+ //if true return instance
1673
  $final_return = ($final_return === FALSE) ? FALSE : $instance;
1674
 
1675
  //display: return $instance, hide: return FALSE
1684
  {
1685
  global $menu, $submenu;
1686
 
1687
+ //if user can manage widgets but can't edit_theme_options, add widgets menu (appearance)
1688
  if(current_user_can('manage_widgets') && !current_user_can('edit_theme_options'))
1689
  {
1690
  foreach($menu as $menu_key => $menu_values)
1691
  {
1692
  if(isset($menu_values[5]) && $menu_values[5] === 'menu-appearance')
1693
  {
1694
+ //if appearance menu not exists
1695
  if(empty($submenu[$menu_values[2]]))
1696
  {
1697
  $menu[$menu_key][1] = 'manage_widgets';
1698
  $menu[$menu_key][2] = 'widgets.php';
1699
  }
1700
  else
1701
+ //if appearance menu exists
1702
  {
1703
  foreach($submenu[$menu_values[2]] as $submenu_key => $submenu_values)
1704
  {
1707
  }
1708
  }
1709
  }
1710
+ }
1711
+ //if user can't manage widgets but can edit_theme_options, remove widgets from menu
1712
  elseif(!current_user_can('manage_widgets') && current_user_can('edit_theme_options'))
1713
  {
1714
  foreach($menu as $menu_key => $menu_values)
1739
  {
1740
  if(isset($menu_values[5]) && $menu_values[5] === 'menu-appearance')
1741
  {
1742
+ //if appearance menu not exists
1743
  if(empty($submenu[$menu_values[2]]))
1744
  {
1745
  $menu[$menu_key][1] = 'manage_widgets';
1746
  $menu[$menu_key][2] = 'widgets.php';
1747
  }
1748
  else
1749
+ //if appearance menu exists
1750
  {
1751
  $submenu[$menu_values[2]][7] = array(__('Widgets'), 'manage_widgets', 'widgets.php');
1752
 
1753
+ //remove menus with edit_theme_options capability
1754
  foreach($submenu[$menu_values[2]] as $submenu_key => $submenu_values)
1755
  {
1756
  if($submenu_values[1] == 'edit_theme_options')
 
1757
  unset($submenu[$menu_values[2]][$submenu_key]);
 
1758
  }
1759
 
1760
+ //fix if appearance menu item is only 1, remove submenu
1761
  if(count($submenu[$menu_values[2]]) < 2)
1762
  {
1763
  unset($submenu[$menu_values[2]][7]);
1779
 
1780
  if($pagenow === 'widgets.php' || (defined('DOING_AJAX') && DOING_AJAX))
1781
  {
1782
+ //break if we're not asking to edit widgets
1783
  if(('edit_theme_options' != $args[0]) || empty($allcaps['manage_widgets']))
 
1784
  return $allcaps;
 
1785
  else
1786
  {
1787
+ //if user can't edit_theme_options but can manage_widgets
1788
  if(empty($allcaps['edit_theme_options']))
1789
  {
1790
+ //menu fix
1791
  add_action('admin_menu', array(&$this, 'manage_widgets_menu_fix'), 999);
1792
+
1793
+ //add cap to edit widgets
1794
  $allcaps['edit_theme_options'] = TRUE;
1795
  }
1796
  }
1799
  return $allcaps;
1800
  }
1801
  }
 
 
 
1802
  ?>