PluginProbe ʕ •ᴥ•ʔ
Slider Ultimate / 2.2.0
Slider Ultimate v2.2.0
trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9
ultimate-slider / includes / CustomPostTypes.class.php
ultimate-slider / includes Last commit date
AboutUs.class.php 3 years ago BackwardsCompatibility.class.php 4 years ago Blocks.class.php 4 years ago CustomPostTypes.class.php 3 years ago Dashboard.class.php 3 years ago DeactivationSurvey.class.php 4 years ago Helper.class.php 4 years ago InstallationWalkthrough.class.php 4 years ago Permissions.class.php 4 years ago ReviewAsk.class.php 4 years ago Settings.class.php 3 years ago Widgets.class.php 4 years ago WooCommerceIntegration.class.php 4 years ago template-functions.php 4 years ago
CustomPostTypes.class.php
710 lines
1 <?php
2 /**
3 * Class to handle all custom post type definitions for Ultimate Slider
4 */
5
6 if ( !defined( 'ABSPATH' ) )
7 exit;
8
9 if ( !class_exists( 'ewdusCustomPostTypes' ) ) {
10 class ewdusCustomPostTypes {
11
12 public function __construct() {
13
14 // Call when plugin is initialized on every page load
15 add_action( 'admin_init', array( $this, 'create_nonce' ) );
16 add_action( 'init', array( $this, 'load_cpts' ) );
17
18 // Handle metaboxes
19 add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
20 add_action( 'save_post', array( $this, 'save_meta' ) );
21
22 // Add columns and filters to the admin list of slides
23 add_action( 'restrict_manage_posts', array( $this, 'filter_by_category' ) );
24 add_filter( 'parse_query', array( $this, 'convert_slide_category_to_taxonomy_term_in_query' ) );
25 add_filter( 'manage_ultimate_slider_posts_columns' , array( $this, 'slide_table_columns_display_order' ) );
26 add_action( 'manage_ultimate_slider_posts_custom_column', array( $this, 'display_slide_columns_content' ), 10, 2 );
27 add_filter( 'manage_edit-ultimate_slider_sortable_columns', array( $this, 'register_post_column_sortables' ) );
28 add_filter( 'posts_clauses', array( $this, 'orderby_categories_column' ), 10, 2 );
29 add_filter( 'manage_edit-ultimate_slider_categories_columns', array( $this, 'register_slide_category_table_columns' ) );
30 add_filter( 'manage_edit-ultimate_slider_categories_columns', array( $this, 'slide_categories_table_columns_display_order' ) );
31 add_filter( 'manage_ultimate_slider_categories_custom_column', array( $this, 'display_category_columns_content' ), 10, 3 );
32 add_action( 'pre_get_posts', array( $this, 'orderby_order_column' ) );
33
34 add_action( 'wp_ajax_ewd_us_get_post_ids', array( $this, 'get_all_post_ids' ) );
35 add_action( 'wp_ajax_ewd_us_slides_update_order', array( $this, 'update_slides_order' ) );
36 }
37
38 /**
39 * Initialize custom post types
40 * @since 2.0.0
41 */
42 public function load_cpts() {
43 global $ewd_us_controller;
44
45 // Define the slide custom post type
46 $args = array(
47 'labels' => array(
48 'name' => __( 'Ultimate Slider', 'ultimate-slider' ),
49 'singular_name' => __( 'Slide', 'ultimate-slider' ),
50 'menu_name' => __( 'Ultimate Slider', 'ultimate-slider' ),
51 'name_admin_bar' => __( 'Slides', 'ultimate-slider' ),
52 'add_new' => __( 'Add New', 'ultimate-slider' ),
53 'add_new_item' => __( 'Add New Slide', 'ultimate-slider' ),
54 'edit_item' => __( 'Edit Slide', 'ultimate-slider' ),
55 'new_item' => __( 'New Slide', 'ultimate-slider' ),
56 'view_item' => __( 'View Slide', 'ultimate-slider' ),
57 'search_items' => __( 'Search Slides', 'ultimate-slider' ),
58 'not_found' => __( 'No slides found', 'ultimate-slider' ),
59 'not_found_in_trash' => __( 'No slides found in trash', 'ultimate-slider' ),
60 'all_items' => __( 'All Slides', 'ultimate-slider' ),
61 ),
62 'public' => true,
63 'has_archive' => true,
64 'menu_icon' => 'dashicons-slides',
65 'rewrite' => array(
66 'slug' => 'ultimate-slider'
67 ),
68 'supports' => array(
69 'title',
70 'editor',
71 'thumbnail',
72 'revisions',
73 'page-attributes'
74 ),
75 'show_in_rest' => true,
76 );
77
78 // Create filter so addons can modify the arguments
79 $args = apply_filters( 'ewd_us_slider_args', $args );
80
81 // Add an action so addons can hook in before the post type is registered
82 do_action( 'ewd_us_slider_pre_register' );
83
84 // Register the post type
85 register_post_type( EWD_US_SLIDER_POST_TYPE, $args );
86
87 // Add an action so addons can hook in after the post type is registered
88 do_action( 'ewd_us_slider_post_register' );
89
90
91 // Define the slide category taxonomy
92 $args = array(
93 'labels' => array(
94 'name' => __( 'Slider Categories', 'ultimate-slider' ),
95 'singular_name' => __( 'Slider Category', 'ultimate-slider' ),
96 'search_items' => __( 'Search Slider Categories', 'ultimate-slider' ),
97 'all_items' => __( 'All Slider Categories', 'ultimate-slider' ),
98 'parent_item' => __( 'Parent Slider Category', 'ultimate-slider' ),
99 'parent_item_colon' => __( 'Parent Slider Category:', 'ultimate-slider' ),
100 'edit_item' => __( 'Edit Slider Category', 'ultimate-slider' ),
101 'update_item' => __( 'Update Slider Category', 'ultimate-slider' ),
102 'add_new_item' => __( 'Add New Slider Category', 'ultimate-slider' ),
103 'new_item_name' => __( 'New Slider Category Name', 'ultimate-slider' ),
104 'menu_name' => __( 'Slider Categories', 'ultimate-slider' ),
105 ),
106 'public' => true,
107 'hierarchical' => true,
108 'show_in_rest' => true
109 );
110
111 // Create filter so addons can modify the arguments
112 $args = apply_filters( 'ewd_us_slider_category_args', $args );
113
114 register_taxonomy( EWD_US_SLIDER_CATEGORY_TAXONOMY, EWD_US_SLIDER_POST_TYPE, $args );
115
116
117 // Define the slide tag taxonomy
118 $args = array(
119 'labels' => array(
120 'name' => __( 'Slider Tags', 'ultimate-slider' ),
121 'singular_name' => __( 'Slider Tag', 'ultimate-slider' ),
122 ),
123 'public' => true,
124 'hierarchical' => false,
125 'show_in_rest' => true
126 );
127
128 // Create filter so addons can modify the arguments
129 $args = apply_filters( 'ewd_us_slider_tag_args', $args );
130
131 register_taxonomy( EWD_US_SLIDER_TAG_TAXONOMY, EWD_US_SLIDER_POST_TYPE, $args );
132 }
133
134 /**
135 * Generate a nonce for secure saving of metadata
136 * @since 2.0.0
137 */
138 public function create_nonce() {
139
140 $this->nonce = wp_create_nonce( basename( __FILE__ ) );
141 }
142
143 /**
144 * Add in new columns for the ultimate_slider type
145 * @since 2.0.0
146 */
147 public function add_meta_boxes() {
148
149 $meta_boxes = array(
150
151 // Add in the slide meta information
152 'slide_meta' => array (
153 'id' => 'slide_meta',
154 'title' => esc_html__( 'Slide Options', 'ultimate-slider' ),
155 'callback' => array( $this, 'show_slide_meta' ),
156 'post_type' => EWD_US_SLIDER_POST_TYPE,
157 'context' => 'normal',
158 'priority' => 'high'
159 ),
160
161 // Add in a link to the documentation for the plugin
162 'us_meta_need_help' => array (
163 'id' => 'ewd_us_meta_need_help',
164 'title' => esc_html__( 'Need Help?', 'ultimate-slider' ),
165 'callback' => array( $this, 'show_need_help_meta' ),
166 'post_type' => EWD_US_SLIDER_POST_TYPE,
167 'context' => 'side',
168 'priority' => 'high'
169 ),
170 );
171
172 // Create filter so addons can modify the metaboxes
173 $meta_boxes = apply_filters( 'ewd_us_meta_boxes', $meta_boxes );
174
175 // Create the metaboxes
176 foreach ( $meta_boxes as $meta_box ) {
177 add_meta_box(
178 $meta_box['id'],
179 $meta_box['title'],
180 $meta_box['callback'],
181 $meta_box['post_type'],
182 $meta_box['context'],
183 $meta_box['priority']
184 );
185 }
186 }
187
188 /**
189 * Add in a link to the plugin documentation
190 * @since 2.0.0
191 */
192 public function show_slide_meta( $post ) {
193 global $ewd_us_controller;
194
195
196 $content_type = get_post_meta( $post->ID, "EWD_US_Content_Type", true );
197 $upcp_product_id = get_post_meta( $post->ID, "EWD_US_UPCP_Product_ID", true );
198 $wc_product_id = get_post_meta( $post->ID, "EWD_US_WC_Product_ID", true );
199 $max_title_chars = get_post_meta( $post->ID, "EWD_US_Max_Title_Chars", true );
200 $max_body_chars = get_post_meta( $post->ID, "EWD_US_Max_Body_Chars", true );
201 $image_type = get_post_meta( $post->ID, "EWD_US_Image_Type", true );
202 $youtube_url = get_post_meta( $post->ID, "EWD_US_YouTube_URL", true );
203 $buttons = is_array( get_post_meta( $post->ID, "EWD_US_Buttons", true ) ) ? get_post_meta( $post->ID, "EWD_US_Buttons", true ) : array();
204
205 $upcp_products = post_type_exists( 'upcp_product' ) ? get_posts( array( 'post_type' => 'upcp_product', 'posts_per_page' => -1 ) ) : array();
206 $wc_products = post_type_exists( 'product' ) ? get_posts( array( 'post_type' => 'product', 'posts_per_page' => -1 ) ) : array();
207
208 $post_links = $this->get_all_post_ids( 'objects' );
209
210 ?>
211
212 <input type="hidden" name="ewd_us_nonce" value="<?php echo $this->nonce; ?>">
213
214 <div class='ewd-us-meta-menu'>
215
216 <div class='ewd-us-meta-menu-item meta-menu-tab-active' id='Menu_Content'><?php _e( 'Content', 'ultimate-slider' ); ?></div>
217 <div class='ewd-us-meta-menu-item' id='Menu_Buttons'><?php _e( 'Buttons', 'ultimate-slider' ); ?></div>
218 <div class='ewd-us-meta-menu-item' id='Menu_Images'><?php _e( 'Image', 'ultimate-slider' ); ?></div>
219
220 </div>
221
222 <div class='ewd-us-meta-body' id='Body_Content'>
223
224 <h3><?php _e( 'Content Type', 'ultimate-slider' ); ?></h3>
225
226 <div class='ewd-us-meta-option-radio'>
227 <input type='radio' name='content_type' value='current_post' <?php echo ( ( $content_type == 'current_post' or $content_type == '' ) ? 'checked' : '' ); ?> />
228 </div>
229
230 <div class='ewd-us-meta-option-explanation'>
231 <?php _e( 'Use this post\'s content', 'ultimate-slider' ); ?>
232 </div>
233
234 <div class='ewd-us-meta-option-radio'>
235 <input type='radio' name='content_type' value='upcp_product' <?php echo ( $content_type == 'upcp_product' ? 'checked' : '' ); ?> <?php echo ( empty( $upcp_products ) ? 'disabled' : '' ); ?> />
236 </div>
237
238 <div class='ewd-us-meta-option-explanation'>
239 <?php _e( 'Use UPCP product content', 'ultimate-slider' ); ?>
240 <?php if (! empty( $upcp_products ) ) { ?>
241
242 <select name='upcp_products'>
243 <?php foreach ( $upcp_products as $product ) { ?>
244
245 <option value='<?php echo $product->ID; ?>' <?php echo ( ( $content_type == "upcp_product" and $product->ID == $upcp_product_id ) ? 'selected' : '' ); ?> >
246 <?php echo esc_html( $product->post_title ); ?>
247 </option>
248 <?php } ?>
249 </select>
250 <?php } ?>
251 </div>
252
253 <div class='ewd-us-meta-option-radio'>
254 <input type='radio' name='content_type' value='woocommerce_product' <?php echo ( $content_type == 'woocommerce_product' ? 'checked' : '' ); ?> <?php echo ( empty( $wc_products ) ? 'disabled' : '' ); ?> />
255 </div>
256
257 <div class='ewd-us-meta-option-explanation'>
258 <?php echo _e( 'Use WooCommerce product content', 'ultimate-slider' ); ?>
259 <?php if ( ! empty( $wc_products ) ) { ?>
260
261 <select name='wc_products'>
262 <?php foreach ($wc_products as $product) { ?>
263
264 <option value='<?php echo $product->ID; ?>' <?php echo ( ( $content_type == "woocommerce_product" and $product->ID == $wc_product_id ) ? 'selected' : '' ); ?> >
265 <?php echo esc_html( $product->post_title ); ?>
266 </option>
267 <?php } ?>
268 </select>
269 <?php } ?>
270 </div>
271
272 <div class='ewd-us-meta-divider'></div>
273
274 <div class='ewd-us-meta-sinle-line'>
275 <?php _e( 'Max Title Characters', 'ultimate-slider' ); ?>:
276 <input type='text' name='max_title_chars' value='<?php echo esc_attr( $max_title_chars ); ?>' />
277 </div>
278
279 <div class='ewd-us-meta-sinle-line'>
280 <?php _e( 'Max Body Characters', 'ultimate-slider' ); ?>:
281 <input type='text' name='max_body_chars' value='<?php esc_attr( $max_body_chars ); ?>' />
282 </div>
283 </div>
284
285 <div class='ewd-us-meta-body ewd-us-hidden' id='Body_Buttons'>
286
287 <h3><?php _e( 'Buttons', 'ultimate-slider' ); ?></h3>
288
289 <table id='ewd-us-buttons-list-table'>
290 <tr>
291 <th></th>
292 <th><?php _e( 'Text', 'ultimate-slider' ); ?></th>
293 <th><?php _e( 'Link Type', 'ultimate-slider' ); ?></th>
294 <th><?php _e( 'Custom Link', 'ultimate-slider' ); ?></th>
295 </tr>
296
297 <?php foreach ( $buttons as $count => $button ) { ?>
298 <tr id='ewd-us-button-list-item-<?php echo $count; ?>'>
299 <td>
300 <a class='ewd-us-delete-button-list-item' data-buttonid='<?php echo $count; ?>'><?php _e( 'Delete', 'ultimate-slider' ); ?></a>
301 </td>
302 <td>
303 <input type='text' name='Button_List_<?php echo $count; ?>_Text' value='<?php echo esc_attr( $button['Text'] ); ?>'/>
304 </td>
305 <td>
306 <select name='Button_List_<?php echo $count; ?>_Post_ID' class='ewd-us-post-select' id='ewd-us-post-select-<?php echo $count; ?>'>
307 <option value='0'><?php _e( 'Custom Link', 'ultimate-slider' ); ?></option>
308 <?php foreach ($post_links as $post) { ?>
309
310 <option value='<?php echo esc_attr( $post->ID ); ?>' <?php echo ( $post->ID == $button['Post_ID'] ? 'selected' : '' ); ?> >
311 <?php echo esc_html( $post->post_title ); ?>
312 </option>
313 <?php } ?>
314 </select>
315 </td>
316 <td>
317 <input type='text' name='Button_List_<?php echo $count; ?>_Custom_Link' value='<?php echo esc_attr( $button['Custom_Link'] ); ?>' id='ewd-us-post-link-<?php echo $count; ?>' />
318 </td>
319 </tr>
320 <?php } ?>
321
322 <tr>
323 <td colspan='4'>
324 <a class='ewd-us-add-button-list-item' data-nextid='<?php echo sizeof( $buttons ); ?>'><?php _e( 'Add', 'ultimate-slider' ); ?></a>
325 </td>
326 </tr>
327 </table>
328
329 </div>
330
331 <div class='ewd-us-meta-body ewd-us-hidden' id='Body_Images'>
332
333 <h3><?php _e( 'Image Options', 'ultimate-slider' ); ?></h3>
334
335 <div class='ewd-us-meta-option-radio'>
336 <input type='radio' class='ewd-us-image-radio' name='use_image' value='featured' <?php echo ( ( $image_type == 'featured' or $image_type == '' ) ? 'checked' : '' ); ?> />
337 </div>
338
339 <div class='ewd-us-meta-option-explanation'>
340 <?php _e( 'Use post\'s featured image', 'ultimate-slider' ); ?>
341 </div>
342
343 <?php if ( $ewd_us_controller->permissions->check_permission( 'youtube' ) ) { ?>
344 <div class='ewd-us-meta-option-radio'>
345 <input type='radio' class='ewd-us-image-radio' name='use_image' value='youtube_video' <?php echo ( $image_type == 'youtube_video' ? 'checked' : '' ); ?> />
346 </div>
347 <div class='ewd-us-meta-option-explanation'>
348 <?php _e( 'Use YouTube URL', 'ultimate-slider' ); ?>:
349 </div>
350 <div class='ewd-us-meta-option-radio'>
351 <input type='text' id='ewd-us-youtube-url' name='youtube_url' value='<?php echo esc_attr( $youtube_url ); ?>' <?php echo ( $image_type != 'youtube_video' ? 'disabled' : '' ); ?> />
352 </div>
353 <?php } else { ?>
354 <div class='ewd-us-upgrade'>
355 <a href="http://www.etoilewebdesign.com/plugins/ultimate-slider/"><?php _e( 'Upgrade to the full version', 'ultimate-slider' ); ?></a> <?php _e( 'to be create YouTube video slides.', 'ultimate-slider' ); ?>
356 </div>
357 <?php } ?>
358 </div>
359
360 <div class='ewd-us-clear'></div>
361
362 <?php }
363
364 /**
365 * Add in a link to the plugin documentation
366 * @since 2.0.0
367 */
368 public function show_need_help_meta() { ?>
369
370 <div class='ewd-us-need-help-box'>
371 <div class='ewd-us-need-help-text'>Visit our Support Center for documentation and tutorials</div>
372 <a class='ewd-us-need-help-button' href='https://www.etoilewebdesign.com/support-center/?Plugin=US' target='_blank'>GET SUPPORT</a>
373 </div>
374
375 <?php }
376
377 /**
378 * Save the metabox data for each slide
379 * @since 2.0.0
380 */
381 public function save_meta( $post_id ) {
382 global $ewd_us_controller;
383
384 // Verify nonce
385 if ( ! isset( $_POST['ewd_us_nonce'] ) || ! wp_verify_nonce( $_POST['ewd_us_nonce'], basename( __FILE__ ) ) ) {
386
387 return $post_id;
388 }
389
390 // Check autosave
391 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
392
393 return $post_id;
394 }
395
396 // Check permissions
397 if ( ! current_user_can( 'edit_page', $post_id ) ) {
398 return $post_id;
399 } elseif ( ! current_user_can( 'edit_post', $post_id ) ) {
400 return $post_id;
401 }
402
403 // Update the meta field in the database.
404 update_post_meta( $post_id, 'EWD_US_Content_Type', sanitize_text_field( $_POST['content_type'] ) );
405 if ( $_POST['content_type'] == 'upcp_product' ) { update_post_meta( $post_id, 'EWD_US_UPCP_Product_ID', intval( $_POST['upcp_products'] ) ); }
406 if ( $_POST['content_type'] == 'woocommerce_product' ) { update_post_meta( $post_id, 'EWD_US_WC_Product_ID', intval( $_POST['wc_products'] ) ); }
407 update_post_meta( $post_id, 'EWD_US_Max_Title_Chars', sanitize_text_field( $_POST['max_title_chars'] ) );
408 update_post_meta( $post_id, 'EWD_US_Max_Body_Chars', sanitize_text_field( $_POST['max_body_chars'] ) );
409
410 $counter = 0;
411 $buttons = array();
412 while ( $counter < 30 ) {
413
414 if ( isset( $_POST['Button_List_' . $counter . '_Text'] ) ) {
415
416 $prefix = 'Button_List_' . $counter;
417 $button = array();
418
419 $button['Text'] = sanitize_text_field( $_POST[$prefix . '_Text'] );
420 $button['Post_ID'] = sanitize_text_field( $_POST[$prefix . '_Post_ID'] );
421 $button['Custom_Link'] = esc_url_raw( $_POST[$prefix . '_Custom_Link'] );
422
423 $buttons[] = $button;
424 }
425 $counter++;
426 }
427 update_post_meta( $post_id, 'EWD_US_Buttons', $buttons );
428
429 update_post_meta( $post_id, 'EWD_US_Image_Type', sanitize_text_field( $_POST['use_image'] ) );
430 if ( ! empty( $_POST['youtube_url'] ) ) { update_post_meta( $post_id, 'EWD_US_YouTube_URL', sanitize_url( $_POST['youtube_url'] ) ); }
431
432 if ( get_post_meta($post_id, "EWD_US_Slide_Order", true) == "" ) { update_post_meta( $post_id, "EWD_US_Slide_Order", 999 ); }
433 }
434
435 /**
436 * Set display order of slide table columns
437 * @since 2.0.0
438 */
439 public function slide_table_columns_display_order( $columns ) {
440
441 return array(
442 'cb' => __( 'Select', 'ultimate-slider' ),
443 'us_thumbnail' => __( 'Slide', 'ultimate-slider' ),
444 'title' => __( 'Title', 'ultimate-slider' ),
445 'us_categories' => __( 'Categories', 'ultimate-slider' ),
446 'us_menu_order' => __( 'Order', 'ultimate-slider' ),
447 'date' => __( 'Date', 'ultimate-slider' )
448 );
449 }
450
451 /**
452 * Set the content for the thumbnail and category columns
453 * @since 2.0.0
454 */
455 public function display_slide_columns_content ( $column_name, $post_id ) {
456
457 if ( $column_name == 'us_categories' ) {
458
459 echo $this->get_slide_categories( $post_id );
460 }
461
462 if ( $column_name == 'us_thumbnail' ) {
463
464 $slide_image_source = $this->get_slide_image_source( $post_id );
465 echo '<img src="' . $slide_image_source . '" class="ewd-us-admin-table-thumbnail" />';
466 }
467
468 if ( $column_name == 'us_menu_order' ) {
469
470 echo get_post_meta( $post_id, "EWD_US_Slide_Order", true );
471 }
472 }
473
474 /**
475 * Register the categories column as being sortable
476 * @since 2.0.0
477 */
478 public function register_post_column_sortables( $column ) {
479
480 $column['us_categories'] = 'us_categories';
481
482 return $column;
483 }
484
485 /**
486 * Get the image source for a slide
487 * @since 2.0.0
488 */
489 public function get_slide_image_source( $post_id ) {
490
491 $content_type = get_post_meta( $post_id, "EWD_US_Content_Type", true );
492 $upcp_product_id = get_post_meta( $post_id, "EWD_US_UPCP_Product_ID", true );
493
494 $image_url = '';
495
496 if ( $content_type == 'upcp_product' and class_exists( 'UPCP_Product' ) ) {
497
498 $product = new UPCP_Product( array( 'ID' => $upcp_product_id ) );
499 $image_url = $product->Get_Field_Value( 'Item_Photo_URL' );
500 }
501 else {
502
503 $post_thumbnail_id = get_post_thumbnail_id( $post_id );
504 $image_url = wp_get_attachment_url( $post_thumbnail_id );
505 }
506
507 return $image_url;
508 }
509
510 /**
511 * Adjust the wp_query if the orderby clause is us_categories
512 * @since 2.0.0
513 */
514 public function orderby_categories_column( $clauses, $wp_query ) {
515 global $wpdb;
516
517 if ( isset( $wp_query->query['orderby'] ) and $wp_query->query['orderby'] == 'us_categories' ) {
518
519 $clauses['join'] .= <<<SQL
520 LEFT OUTER JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID={$wpdb->term_relationships}.object_id
521 LEFT OUTER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id)
522 LEFT OUTER JOIN {$wpdb->terms} USING (term_id)
523 SQL;
524
525 $clauses['where'] .= " AND (taxonomy = 'ultimate_slider_categories' OR taxonomy IS NULL) ";
526 $clauses['groupby'] = " object_id ";
527 $clauses['orderby'] = " GROUP_CONCAT({$wpdb->terms}.name ORDER BY name ASC) ";
528
529 if ( strtoupper( $wp_query->get( 'order' ) ) == 'ASC' ) {
530 $clauses['orderby'] .= 'ASC';
531 } else {
532 $clauses['orderby'] .= 'DESC';
533 }
534 }
535
536 return $clauses;
537 }
538
539 /**
540 * Retrieve a comma separated list of ultimate_slider_categories for a slide
541 * @since 2.0.0
542 */
543 public function get_slide_categories( $post_id ) {
544
545 return get_the_term_list( $post_id, EWD_US_SLIDER_CATEGORY_TAXONOMY, '', ', ' ) . PHP_EOL;
546 }
547
548 /**
549 * Allow filtering by ultimate_slider_category
550 * @since 2.0.0
551 */
552 public function filter_by_category( ) {
553 global $typenow;
554 global $wp_query;
555
556 if ( $typenow == 'ultimate_slider' ) {
557
558 $taxonomy = EWD_US_SLIDER_CATEGORY_TAXONOMY;
559 $us_category_taxonomy = get_taxonomy( $taxonomy );
560
561 wp_dropdown_categories(
562 array(
563 'show_option_all' => __( 'Show All ' . $us_category_taxonomy->label, 'ultimate-slider' ),
564 'taxonomy' => $taxonomy,
565 'name' => EWD_US_SLIDER_CATEGORY_TAXONOMY,
566 'orderby' => 'name',
567 'selected' => isset( $wp_query->query['term'] )? $wp_query->query['term'] : "",
568 'hierarchical' => true,
569 'depth' => 3,
570 'show_count' => true, // Show # listings in parens
571 'hide_empty' => true,
572 )
573 );
574 }
575 }
576
577 /**
578 *
579 * @since 2.0.0
580 */
581 public function convert_slide_category_to_taxonomy_term_in_query( $query ) {
582 global $pagenow;
583
584 $taxonomy = EWD_US_SLIDER_CATEGORY_TAXONOMY;
585 $q_vars = &$query->query_vars;
586
587 if ( $pagenow == 'edit.php' && isset( $q_vars['post_type'] ) && $q_vars['post_type'] == EWD_US_SLIDER_POST_TYPE && isset( $q_vars[$taxonomy] ) && is_numeric( $q_vars[$taxonomy] ) && $q_vars[$taxonomy] != 0 ) {
588
589 $term = get_term_by( 'id', $q_vars[$taxonomy], $taxonomy );
590 $q_vars[$taxonomy] = $term->slug;
591 }
592 }
593
594 /**
595 * Add in new columns for the ultimate_slider_categories table
596 * @since 2.0.0
597 */
598 public function register_slide_category_table_columns($columns){
599
600 $columns['us_category_shortcode'] = __( 'Shortcode', 'ultimate-slider' );
601
602 return $columns;
603 }
604
605 /**
606 * Set display order of slide categories table columns
607 * @since 2.0.0
608 */
609 public function slide_categories_table_columns_display_order( $columns ) {
610
611 return array(
612 'name' => __( 'Name', 'ultimate-slider' ),
613 'description' => __( 'Description', 'ultimate-slider' ),
614 'us_category_shortcode' => __( 'Shortcode', 'ultimate-slider' ),
615 'posts' => __( 'Count', 'ultimate-slider' ),
616 );
617 }
618
619 /**
620 * Set the content for the shortcode column
621 * @since 2.0.0
622 */
623 public function display_category_columns_content( $content, $column_name, $term_id ) {
624
625 if ( $column_name == 'us_category_shortcode' ) {
626
627 $term = get_term( $term_id, EWD_US_SLIDER_CATEGORY_TAXONOMY );
628 $slug = $term->slug;
629 $content .= "[ultimate-slider category='" . $slug . "']";
630 }
631
632 return $content;
633 }
634
635 /**
636 * Adjust the orderby if none specified to display in user-set slide order
637 * @since 2.0.0
638 */
639 public function orderby_order_column( $query ) {
640
641 if ( is_admin() and isset( $_GET['post_type'] ) and $_GET['post_type'] == EWD_US_SLIDER_POST_TYPE and ! isset( $_GET['orderby'] ) ) {
642
643 $query->set( 'meta_key', 'EWD_US_Slide_Order' );
644 $query->set( 'orderby', 'meta_value_num' );
645 $query->set( 'order', 'ASC' );
646 }
647 }
648
649 /**
650 * Get ID/name pairs for all posts and pages
651 * @since 2.0.0
652 */
653 public function get_all_post_ids( $return = 'ajax' ) {
654
655 if ( $return == 'ajax'
656 and ! check_ajax_referer( 'ewd-us-admin-js', 'nonce' )
657 ) {
658
659 ewdusHelper::admin_nopriv_ajax();
660 }
661
662 $args = array(
663 'post_type' => array( 'page', 'post' ),
664 'orderby' => 'menu_order',
665 'posts_per_page' => 200,
666 );
667
668 $query = new WP_Query ( $args );
669 $posts = $query->posts;
670
671 if ( $return == 'objects' ) { return $posts; }
672
673 $return_pairs = array();
674 foreach ( $posts as $post ) {
675
676 $return_pair[ 'ID' ] = $post->ID;
677 $return_pair[ 'Name' ] = $post->post_title;
678
679 $return_pairs[] = $return_pair;
680 }
681
682 echo json_encode( $return_pairs );
683 }
684
685 /**
686 * Update the display order when slides are dragged and dropped
687 * @since 2.0.0
688 */
689 public function update_slides_order() {
690
691 // Authenticate request
692 if ( ! check_ajax_referer( 'ewd-us-admin-js', 'nonce' ) ) {
693
694 ewdusHelper::admin_nopriv_ajax();
695 }
696
697 $post_ids = json_decode( stripslashes( $_POST['IDs'] ) );
698
699 $post_ids = is_array( $post_ids ) ? array_map( 'intval', $post_ids ) : array();
700
701 if ( ! is_array( $post_ids ) ) { $post_ids = array(); }
702
703 foreach ( $post_ids as $order => $post_id ) {
704
705 update_post_meta( intval( $post_id ), 'EWD_US_Slide_Order', intval( $order ) );
706 }
707 }
708 }
709 } // endif;
710