-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate-codes.php
More file actions
200 lines (176 loc) · 4.04 KB
/
template-codes.php
File metadata and controls
200 lines (176 loc) · 4.04 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
/**
* @Author Jonathon byrd
* @link http://www.5twentystudios.com
* @Package Wordpress
* @SubPackage Total Widget Control
* @copyright Proprietary Software, Copyright Byrd Incorporated. All Rights Reserved
* @Since 1.5.5
*
*
*
*/
defined('ABSPATH') or die("Cannot access pages directly.");
/**
* Function is responsible for returning the number of widgets that
* are set to display on the current page.
*
* @param string $sidebar_id
* @return integer
*/
function twc_count_widgets( $index = 1 )
{
//initializing variables
global $wp_registered_sidebars, $sidebars_widgets;
$sidebars_widgets = twc_wp_get_sidebars_widgets();
$count = 0;
if ( is_int($index) ) {
$index = "sidebar-$index";
} else {
$index = sanitize_title($index);
foreach ( (array) $wp_registered_sidebars as $key => $value ) {
if ( sanitize_title($value['name']) == $index ) {
$index = $key;
break;
}
}
}
if (isset($sidebars_widgets[$index]))
{
foreach ((array)$sidebars_widgets[$index] as $position => $widget_slug)
{
//initializing variables
$widget = twc_get_widget_by_id($widget_slug);
$display = twc_is_widget_displaying($widget);
//reasons to continue
$display = apply_filters('twc_display_widget', $display, $widget);
if (!$display) continue;
$count++;
}
}
return $count;
}
/**
* Function is responsible for returning the sidebar widgets as a string
*
* @param string $sidebar_id
* @return integer
*/
function twc_get_sidebar( $sidebar_id = 1 )
{
ob_start();
twc_dynamic_sidebar( $sidebar_id );
$sidebar = ob_get_clean();
return $sidebar;
}
/**
* Function is responsible for echoing the widgets of a given sidebar
*
* @param string $sidebar_id
* @return integer
*/
function twc_sidebar( $sidebar_id = 1 )
{
twc_dynamic_sidebar( $sidebar_id );
}
/**
* Function is responsible to get the currently dislaying widget, or
* a specific widget from a given id
*
* @param string $widget_id
* @param boolean $force //forces the widget to display, regardless of admin settings
* @return string $twc_widget_to_wrap
*/
function twc_get_widget( $widget_id = null, $force = false )
{
if (is_null($widget_id))
{
//initializing variables
global $twc_widget_to_wrap;
return $twc_widget_to_wrap;
}
ob_start();
twc_display_the_widget(null, $widget_id, null, $force);
$display = ob_get_clean();
return $display;
}
/**
* Function is responsible for echoing the given widget id, or the currently
* displaying widget.
*
* @param string $widget_id
* @param boolean $force
* @return string $twc_widget_to_wrap
*/
function twc_widget( $widget_id = null, $force = false )
{
echo twc_get_widget( $widget_id, $force = false );
return true;
}
/**
* Function returns the object id as a string
*
* The object id is loaded when a specific record is loaded from the database.
* This id is used to compare against the menu item id.
*
* @return unknown
*/
function twc_get_object_id()
{
return twc_set_object_id();
}
/**
* Function is responsible for making sure that set is run
* and then the string is returned
*
* @return string
*/
function twc_get_object_url()
{
return twc_set_object_url();
}
/**
* Function is responsible for accepting the shortcode data and
* returning the queried widget
*
* @example
<pre>
[twc_show_widget id="" force=""]
</pre>
*
* @param array $atts
* @return string
*/
function twc_show_widget( $atts = array() )
{
//initializing variables
$atts = shortcode_atts( array(
'id' => FALSE,
'force' => FALSE,
), $atts );
//reasons to fail
if (!$atts['id']) return false;
return twc_get_widget( $atts['id'], $atts['force'] );
}
/**
* Function is responsible for accepting the shortcode data and
* returning the queried sidebar
*
* @example
<pre>
[twc_show_sidebar id=""]
</pre>
*
* @param array $atts
* @return string
*/
function twc_show_sidebar( $atts = array() )
{
//initializing variables
$atts = shortcode_atts( array(
'id' => FALSE,
), $atts );
//reasons to fail
if (!$atts['id']) return false;
return twc_get_sidebar( $atts['id'] );
}