This repository was archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathclass.functions.php
More file actions
279 lines (213 loc) · 15.5 KB
/
class.functions.php
File metadata and controls
279 lines (213 loc) · 15.5 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<?php
class CptoFunctions
{
/**
* Return the user level
*
* This is deprecated, will be removed in the next versions
*
* @param mixed $return_as_numeric
*/
function userdata_get_user_level($return_as_numeric = FALSE)
{
global $userdata;
$user_level = '';
for ($i=10; $i >= 0;$i--)
{
if (current_user_can('level_' . $i) === TRUE)
{
$user_level = $i;
if ($return_as_numeric === FALSE)
$user_level = 'level_'.$i;
break;
}
}
return ($user_level);
}
/**
* Retrieve the plugin options
*
*/
function get_options()
{
//make sure the vars are set as default
$options = get_option('cpto_options');
$defaults = array (
'show_reorder_interfaces' => array(),
'autosort' => 1,
'adminsort' => 1,
'archive_drag_drop' => 1,
'capability' => 'install_plugins',
'navigation_sort_apply' => 1,
);
$options = wp_parse_args( $options, $defaults );
$options = apply_filters('pto/get_options', $options);
return $options;
}
/**
* General messages box
*
*/
function cpt_info_box()
{
?>
<div id="cpt_info_box">
<div id="p_right">
<div id="p_socialize">
<div class="p_s_item s_f">
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like" data-href="https://www.facebook.com/Nsp-Code-190329887674484/" data-layout="button_count" data-action="like" data-show-faces="true" data-share="false"></div>
</div>
<div class="p_s_item s_t">
<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.nsp-code.com" data-text="Define custom order for your post types through an easy to use javascript AJAX drag and drop interface. No theme code updates are necessarily, this plugin will take care of query update." data-count="none">Tweet</a><script type="text/javascript" src="//platform.twitter.com/widgets.js"></script>
</div>
<div class="p_s_item s_gp">
<!-- Place this tag in your head or just before your close body tag -->
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<!-- Place this tag where you want the +1 button to render -->
<div class="g-plusone" data-size="small" data-annotation="none" data-href="http://nsp-code.com/"></div>
</div>
<div class="clear"></div>
</div>
</div>
<p><?php _e('Did you find this plugin useful? Please support our work by purchasing the advanced version or write an article about this plugin in your blog with a link to our site', 'post-types-order') ?> <a href="http://www.nsp-code.com/" target="_blank"><strong>http://www.nsp-code.com/</strong></a>.</p>
<h4><?php _e('Did you know there is available an Advanced version of this plug-in?', 'post-types-order') ?> <a target="_blank" href="http://www.nsp-code.com/premium-plugins/wordpress-plugins/advanced-post-types-order/"><?php _e('Read more', 'post-types-order') ?></a></h4>
<p><?php _e('Check our', 'post-types-order') ?> <a target="_blank" href="http://wordpress.org/plugins/taxonomy-terms-order/">Category Order - Taxonomy Terms Order</a> <?php _e('plugin which allow to custom sort categories and custom taxonomies terms', 'post-types-order') ?> </p>
<p><span style="color:#CC0000" class="dashicons dashicons-megaphone" alt="f488"> </span> <?php _e('Check out', 'post-types-order') ?> <a href="https://wordpress.org/plugins/wp-hide-security-enhancer/" target="_blank"><b>WP Hide & Security Enhancer</b></a> <?php _e('the easy way to completely hide your WordPress core files, theme and plugins', 'post-types-order') ?>.</p>
<div class="clear"></div>
</div>
<?php
}
function cpto_get_previous_post_where($where, $in_same_term, $excluded_terms)
{
global $post, $wpdb;
if ( empty( $post ) )
return $where;
//?? WordPress does not pass through this varialbe, so we presume it's category..
$taxonomy = 'category';
if(preg_match('/ tt.taxonomy = \'([^\']+)\'/i',$where, $match))
$taxonomy = $match[1];
$_join = '';
$_where = '';
if ( $in_same_term || ! empty( $excluded_terms ) )
{
$_join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";
$_where = $wpdb->prepare( "AND tt.taxonomy = %s", $taxonomy );
if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) )
{
// back-compat, $excluded_terms used to be $excluded_terms with IDs separated by " and "
if ( false !== strpos( $excluded_terms, ' and ' ) )
{
_deprecated_argument( __FUNCTION__, '3.3', sprintf( __( 'Use commas instead of %s to separate excluded terms.' ), "'and'" ) );
$excluded_terms = explode( ' and ', $excluded_terms );
}
else
{
$excluded_terms = explode( ',', $excluded_terms );
}
$excluded_terms = array_map( 'intval', $excluded_terms );
}
if ( $in_same_term )
{
$term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
// Remove any exclusions from the term array to include.
$term_array = array_diff( $term_array, (array) $excluded_terms );
$term_array = array_map( 'intval', $term_array );
$_where .= " AND tt.term_id IN (" . implode( ',', $term_array ) . ")";
}
if ( ! empty( $excluded_terms ) ) {
$_where .= " AND p.ID NOT IN ( SELECT tr.object_id FROM $wpdb->term_relationships tr LEFT JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE tt.term_id IN (" . implode( $excluded_terms, ',' ) . ') )';
}
}
$current_menu_order = $post->menu_order;
$query = $wpdb->prepare( "SELECT p.* FROM $wpdb->posts AS p
$_join
WHERE p.post_date < %s AND p.menu_order = %d AND p.post_type = %s AND p.post_status = 'publish' $_where" , $post->post_date, $current_menu_order, $post->post_type);
$results = $wpdb->get_results($query);
if (count($results) > 0)
{
$where .= $wpdb->prepare( " AND p.menu_order = %d", $current_menu_order );
}
else
{
$where = str_replace("p.post_date < '". $post->post_date ."'", "p.menu_order > '$current_menu_order'", $where);
}
return $where;
}
function cpto_get_previous_post_sort($sort)
{
global $post, $wpdb;
$sort = 'ORDER BY p.menu_order ASC, p.post_date DESC LIMIT 1';
return $sort;
}
function cpto_get_next_post_where($where, $in_same_term, $excluded_terms)
{
global $post, $wpdb;
if ( empty( $post ) )
return $where;
$taxonomy = 'category';
if(preg_match('/ tt.taxonomy = \'([^\']+)\'/i',$where, $match))
$taxonomy = $match[1];
$_join = '';
$_where = '';
if ( $in_same_term || ! empty( $excluded_terms ) )
{
$_join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";
$_where = $wpdb->prepare( "AND tt.taxonomy = %s", $taxonomy );
if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) )
{
// back-compat, $excluded_terms used to be $excluded_terms with IDs separated by " and "
if ( false !== strpos( $excluded_terms, ' and ' ) )
{
_deprecated_argument( __FUNCTION__, '3.3', sprintf( __( 'Use commas instead of %s to separate excluded terms.' ), "'and'" ) );
$excluded_terms = explode( ' and ', $excluded_terms );
}
else
{
$excluded_terms = explode( ',', $excluded_terms );
}
$excluded_terms = array_map( 'intval', $excluded_terms );
}
if ( $in_same_term )
{
$term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
// Remove any exclusions from the term array to include.
$term_array = array_diff( $term_array, (array) $excluded_terms );
$term_array = array_map( 'intval', $term_array );
$_where .= " AND tt.term_id IN (" . implode( ',', $term_array ) . ")";
}
if ( ! empty( $excluded_terms ) ) {
$_where .= " AND p.ID NOT IN ( SELECT tr.object_id FROM $wpdb->term_relationships tr LEFT JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE tt.term_id IN (" . implode( $excluded_terms, ',' ) . ') )';
}
}
$current_menu_order = $post->menu_order;
//check if there are more posts with lower menu_order
$query = $wpdb->prepare( "SELECT p.* FROM $wpdb->posts AS p
$_join
WHERE p.post_date > %s AND p.menu_order = %d AND p.post_type = %s AND p.post_status = 'publish' $_where", $post->post_date, $current_menu_order, $post->post_type );
$results = $wpdb->get_results($query);
if (count($results) > 0)
{
$where .= $wpdb->prepare(" AND p.menu_order = %d", $current_menu_order );
}
else
{
$where = str_replace("p.post_date > '". $post->post_date ."'", "p.menu_order < '$current_menu_order'", $where);
}
return $where;
}
function cpto_get_next_post_sort($sort)
{
global $post, $wpdb;
$sort = 'ORDER BY p.menu_order DESC, p.post_date ASC LIMIT 1';
return $sort;
}
}
?>