-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin.php
122 lines (96 loc) · 3.35 KB
/
admin.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
/**
* @author Jason Lemahieu and Kevin Graeme (Cooperative Extension Technology Services)
* @copyright Copyright (c) 2011 - 2015 Jason Lemahieu and Kevin Graeme (Cooperative Extension Technology Services)
* @license http://www.gnu.org/licenses/gpl-2.0.html GPLv2
* @package CETS\Conditional_Widgets
*/
/** Actions ***********************************************************/
add_action( 'plugins_loaded', 'conditional_widgets_load_plugin_textdomain' );
add_action( 'admin_enqueue_scripts', 'conditional_widgets_enqueue_assets' );
function conditional_widgets_enqueue_assets( $hook ) {
$pages = apply_filters( 'conditional_widgets_admin_pages', array( 'widgets.php', 'customize.php' ) );
if ( ! in_array( $hook, $pages ) ) {
return;
}
add_action( 'admin_print_footer_scripts', 'conditional_widgets_add_js' );
wp_enqueue_style( 'conditional_widgets_admin_styles', plugins_url( "css/conditional-widgets-admin.css", __FILE__ ), array(), '2.1.0-dev' );
} // /function conditional_widgets_enqueue_assets()
/**
* Inject javascript into footerp
*
* @since 2.1.0
*
* @return string
*/
function conditional_widgets_add_js() { ?>
<script type='text/javascript'>function conditional_widgets_form_toggle(divID) { jQuery("#" + divID).slideToggle("slow"); }</script>
<?php
} // /function add_js()
/**
* Load the plugin's textdomain hooked to 'plugins_loaded'.
*
* @since 1.0.0
* @access public
*
* @see load_plugin_textdomain()
* @see plugin_basename()
* @action plugins_loaded
*
* @return void
*/
function conditional_widgets_load_plugin_textdomain() {
load_plugin_textdomain(
'conditional-widgets',
false,
dirname( plugin_basename( __FILE__ ) ) . '/languages/'
);
} // /function load_plugin_textdomain()
/**
* Helper function for outputting the select boxes in the widget's form
*/
function conditional_widgets_form_show_hide_select( $name, $value = '', $only = false, $echo = false ) {
$o = ''; //output
$o .= "<select name=$name>";
$o .= "<option value='1' ";
$o .= selected( $value, 1, false );
$o .= ">" . __( 'Show', 'conditional-widgets' ) . "</option>";
if ( $only ) {
$o .= "<option value='2' ";
$o .= selected( $value, 2, false );
$o .= ">" . __( 'Show only', 'conditional-widgets' ) . "</option>";
}
$o .= "<option value='0' ";
$o .= selected( $value, 0, false );
$o .= ">" . __( 'Hide', 'conditional-widgets' ) . "</option>";
$o .= "</select>";
if ( $echo ) {
echo $o;
return '';
} else {
return $o;
}
} // /function conditional_widgets_form_show_hide_select()
/**
* Helper function for displaying the list of checkboxes for Pages
*/
function conditional_widgets_page_checkboxes( $selected = array() ) {
$args = array(
'title_li' => null,
'walker' => new Conditional_Widgets_Walker_Page_Checklist( $selected ),
);
echo "<ul class='conditional-widget-selection-list'>";
wp_list_pages( $args );
echo "</ul>";
} // /function conditional_widgets_page_checkboxes()
function conditional_widgets_term_checkboxes( $tax, $type, $selected = array() ) {
$args = array(
'selected_cats' => $selected,
'checked_ontop' => false,
'taxonomy' => $tax,
'walker' => new Conditional_Widget_Walker_Category_Checklist( $type, $tax ),
);
echo "<ul class='conditional-widget-selection-list'>";
wp_terms_checklist( 0, $args );
echo "</ul>";
} // /function conditional_widgets_term_checkboxes()