-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcets_conditional_widgets.php
122 lines (105 loc) · 3.86 KB
/
cets_conditional_widgets.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/**
Plugin Name: Conditional Widgets
Plugin URI: http://wordpress.org/extend/plugins/conditional-widgets/
Description: Grants users advanced control over which pages and categories each widget is displayed on
Version: 2.2
Author: Jason Lemahieu and Kevin Graeme (Cooperative Extension Technology Services)
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: conditional-widgets
Domain Path: /languages
*/
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/* CHANGELOG
= 2.2 =
* New Features: Hide on Desktop / Hide on Mobile. (Note that using either of these options will immediately hide the widget when the condition is true, and any other options to 'show' will be ignored.
* Fixes lots of small bugs related to the display of the widget control form
= 2.1 =
* Major update of code formatting to better align with WordPress style and guidelines - props @cFoellmann
* Support Conditional Widgets toggle JavaScript on the Customize screen
2.0.5
- Further (properly?) addressed strict warnings with walker arguments
2.0.4
- Addressed strict warnings with walker arguments
2.0.3
- more tweaking to fix warnings
2.0.2
- Fixed warning with weird option selection, changed labels from object->taxonomy
2.0.1
- Fixed bug introduced in 2.0 surrounding empty term logic
2.0
- Added update framework
- Added support for custom type/tax pairs via filter
- refactored and split into a few separate files
*/
if ( is_admin() ) {
require_once( dirname(__FILE__) . '/admin.php');
require_once( dirname(__FILE__) . '/update.php');
require_once( dirname(__FILE__) . '/form.php');
require_once( dirname(__FILE__) . '/includes/class-walker-category-checklist.php');
require_once( dirname(__FILE__) . '/includes/class-walker-page-checklist.php');
} else {
require_once( dirname(__FILE__) . '/logic.php');
}
add_filter( 'conditional_widgets_type_tax_pairs', 'conditional_widgets_add_post_categories', 1 );
function conditional_widgets_add_post_categories( $pairs ) {
$pairs[] = array( 'type' => 'post', 'tax' => 'category', );
return $pairs;
} // /function conditional_widgets_add_post_categories()
/**
* Initializes a fresh widget instance
*/
function conditional_widgets_init_instance( $instance ) {
//single values
$keys = array(
'cw_home_enable_checkbox',
'cw_select_home_page',
'cw_pages_enable_checkbox',
'cw_select_pages',
'cw_pages_sub_checkbox',
'cw_404_hide',
'cw_search_hide',
'cw_author_archive_hide',
'cw_date_archive_hide',
'cw_tag_archive_hide',
'cw_posts_page_hide',
'cw_mobile_hide',
'cw_desktop_hide'
);
foreach ( $keys as $key ) {
if ( ! isset( $instance[ $key ] ) ) {
$instance[ $key ] = '';
}
}
//arrays
$arraykeys = array( 'cw_selected_pages', 'cw_custom', );
foreach ( $arraykeys as $arraykey ) {
if ( ! isset( $instance[ $arraykey ] ) ) {
$instance[ $arraykey ] = array();
}
}
return $instance;
} // /function conditional_widgets_init_instance()
function conditional_widgets_get_default_custom_subdata() {
$custom_subdata = array(
'enable' => 0,
'select' => 0,
'selected_ids' => array(),
'all' => 0,
'sub' => 0,
);
return $custom_subdata;
} // /function conditional_widgets_get_default_custom_subdata()