| 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 = function_exists( 'UPCP_Get_All_Products' ) ? UPCP_Get_All_Products() : array(); |
| 206 |
$wc_products = get_posts( array( 'post_type' => 'product', 'posts_per_page' => -1 ) ); |
| 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->Get_Item_ID(); ?>' <?php echo ( ( $content_type == "upcp_product" and $product->Get_Item_ID() == $upcp_product_id ) ? 'selected' : '' ); ?> > |
| 246 |
<?php echo esc_html( $product->Get_Product_Name() ); ?> |
| 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 |
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 |
'us_thumbnail' => __( 'Slide', 'ultimate-slider' ), |
| 443 |
'title' => __( 'Title', 'ultimate-slider' ), |
| 444 |
'us_categories' => __( 'Categories', 'ultimate-slider' ), |
| 445 |
'us_menu_order' => __( 'Order', 'ultimate-slider' ), |
| 446 |
'date' => __( 'Date', 'ultimate-slider' ) |
| 447 |
); |
| 448 |
} |
| 449 |
|
| 450 |
/** |
| 451 |
* Set the content for the thumbnail and category columns |
| 452 |
* @since 2.0.0 |
| 453 |
*/ |
| 454 |
public function display_slide_columns_content ( $column_name, $post_id ) { |
| 455 |
|
| 456 |
if ( $column_name == 'us_categories' ) { |
| 457 |
|
| 458 |
echo $this->get_slide_categories( $post_id ); |
| 459 |
} |
| 460 |
|
| 461 |
if ( $column_name == 'us_thumbnail' ) { |
| 462 |
|
| 463 |
$slide_image_source = $this->get_slide_image_source( $post_id ); |
| 464 |
echo '<img src="' . $slide_image_source . '" class="ewd-us-admin-table-thumbnail" />'; |
| 465 |
} |
| 466 |
|
| 467 |
if ( $column_name == 'us_menu_order' ) { |
| 468 |
|
| 469 |
echo get_post_meta( $post_id, "EWD_US_Slide_Order", true ); |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
/** |
| 474 |
* Register the categories column as being sortable |
| 475 |
* @since 2.0.0 |
| 476 |
*/ |
| 477 |
public function register_post_column_sortables( $column ) { |
| 478 |
|
| 479 |
$column['us_categories'] = 'us_categories'; |
| 480 |
|
| 481 |
return $column; |
| 482 |
} |
| 483 |
|
| 484 |
/** |
| 485 |
* Get the image source for a slide |
| 486 |
* @since 2.0.0 |
| 487 |
*/ |
| 488 |
public function get_slide_image_source( $post_id ) { |
| 489 |
|
| 490 |
$content_type = get_post_meta( $post_id, "EWD_US_Content_Type", true ); |
| 491 |
$upcp_product_id = get_post_meta( $post_id, "EWD_US_UPCP_Product_ID", true ); |
| 492 |
|
| 493 |
$image_url = ''; |
| 494 |
|
| 495 |
if ( $content_type == 'upcp_product' and class_exists( 'UPCP_Product' ) ) { |
| 496 |
|
| 497 |
$product = new UPCP_Product( array( 'ID' => $upcp_product_id ) ); |
| 498 |
$image_url = $product->Get_Field_Value( 'Item_Photo_URL' ); |
| 499 |
} |
| 500 |
else { |
| 501 |
|
| 502 |
$post_thumbnail_id = get_post_thumbnail_id( $post_id ); |
| 503 |
$image_url = wp_get_attachment_url( $post_thumbnail_id ); |
| 504 |
} |
| 505 |
|
| 506 |
return $image_url; |
| 507 |
} |
| 508 |
|
| 509 |
/** |
| 510 |
* Adjust the wp_query if the orderby clause is us_categories |
| 511 |
* @since 2.0.0 |
| 512 |
*/ |
| 513 |
public function orderby_categories_column( $clauses, $wp_query ) { |
| 514 |
global $wpdb; |
| 515 |
|
| 516 |
if ( isset( $wp_query->query['orderby'] ) and $wp_query->query['orderby'] == 'us_categories' ) { |
| 517 |
|
| 518 |
$clauses['join'] .= <<<SQL |
| 519 |
LEFT OUTER JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID={$wpdb->term_relationships}.object_id |
| 520 |
LEFT OUTER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id) |
| 521 |
LEFT OUTER JOIN {$wpdb->terms} USING (term_id) |
| 522 |
SQL; |
| 523 |
|
| 524 |
$clauses['where'] .= " AND (taxonomy = 'ultimate_slider_categories' OR taxonomy IS NULL) "; |
| 525 |
$clauses['groupby'] = " object_id "; |
| 526 |
$clauses['orderby'] = " GROUP_CONCAT({$wpdb->terms}.name ORDER BY name ASC) "; |
| 527 |
|
| 528 |
if ( strtoupper( $wp_query->get( 'order' ) ) == 'ASC' ) { |
| 529 |
$clauses['orderby'] .= 'ASC'; |
| 530 |
} else { |
| 531 |
$clauses['orderby'] .= 'DESC'; |
| 532 |
} |
| 533 |
} |
| 534 |
|
| 535 |
return $clauses; |
| 536 |
} |
| 537 |
|
| 538 |
/** |
| 539 |
* Retrieve a comma separated list of ultimate_slider_categories for a slide |
| 540 |
* @since 2.0.0 |
| 541 |
*/ |
| 542 |
public function get_slide_categories( $post_id ) { |
| 543 |
|
| 544 |
return get_the_term_list( $post_id, EWD_US_SLIDER_CATEGORY_TAXONOMY, '', ', ' ) . PHP_EOL; |
| 545 |
} |
| 546 |
|
| 547 |
/** |
| 548 |
* Allow filtering by ultimate_slider_category |
| 549 |
* @since 2.0.0 |
| 550 |
*/ |
| 551 |
public function filter_by_category( ) { |
| 552 |
global $typenow; |
| 553 |
global $wp_query; |
| 554 |
|
| 555 |
if ( $typenow == 'ultimate_slider' ) { |
| 556 |
|
| 557 |
$taxonomy = EWD_US_SLIDER_CATEGORY_TAXONOMY; |
| 558 |
$us_category_taxonomy = get_taxonomy( $taxonomy ); |
| 559 |
|
| 560 |
wp_dropdown_categories( |
| 561 |
array( |
| 562 |
'show_option_all' => __( 'Show All ' . $us_category_taxonomy->label, 'ultimate-slider' ), |
| 563 |
'taxonomy' => $taxonomy, |
| 564 |
'name' => EWD_US_SLIDER_CATEGORY_TAXONOMY, |
| 565 |
'orderby' => 'name', |
| 566 |
'selected' => isset( $wp_query->query['term'] )? $wp_query->query['term'] : "", |
| 567 |
'hierarchical' => true, |
| 568 |
'depth' => 3, |
| 569 |
'show_count' => true, // Show # listings in parens |
| 570 |
'hide_empty' => true, |
| 571 |
) |
| 572 |
); |
| 573 |
} |
| 574 |
} |
| 575 |
|
| 576 |
/** |
| 577 |
* |
| 578 |
* @since 2.0.0 |
| 579 |
*/ |
| 580 |
public function convert_slide_category_to_taxonomy_term_in_query( $query ) { |
| 581 |
global $pagenow; |
| 582 |
|
| 583 |
$taxonomy = EWD_US_SLIDER_CATEGORY_TAXONOMY; |
| 584 |
$q_vars = &$query->query_vars; |
| 585 |
|
| 586 |
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 ) { |
| 587 |
|
| 588 |
$term = get_term_by( 'id', $q_vars[$taxonomy], $taxonomy ); |
| 589 |
$q_vars[$taxonomy] = $term->slug; |
| 590 |
} |
| 591 |
} |
| 592 |
|
| 593 |
/** |
| 594 |
* Add in new columns for the ultimate_slider_categories table |
| 595 |
* @since 2.0.0 |
| 596 |
*/ |
| 597 |
public function register_slide_category_table_columns($columns){ |
| 598 |
|
| 599 |
$columns['us_category_shortcode'] = __( 'Shortcode', 'ultimate-slider' ); |
| 600 |
|
| 601 |
return $columns; |
| 602 |
} |
| 603 |
|
| 604 |
/** |
| 605 |
* Set display order of slide categories table columns |
| 606 |
* @since 2.0.0 |
| 607 |
*/ |
| 608 |
public function slide_categories_table_columns_display_order( $columns ) { |
| 609 |
|
| 610 |
return array( |
| 611 |
'name' => __( 'Name', 'ultimate-slider' ), |
| 612 |
'description' => __( 'Description', 'ultimate-slider' ), |
| 613 |
'us_category_shortcode' => __( 'Shortcode', 'ultimate-slider' ), |
| 614 |
'posts' => __( 'Count', 'ultimate-slider' ), |
| 615 |
); |
| 616 |
} |
| 617 |
|
| 618 |
/** |
| 619 |
* Set the content for the shortcode column |
| 620 |
* @since 2.0.0 |
| 621 |
*/ |
| 622 |
public function display_category_columns_content( $content, $column_name, $term_id ) { |
| 623 |
|
| 624 |
if ( $column_name == 'us_category_shortcode' ) { |
| 625 |
|
| 626 |
$term = get_term( $term_id, EWD_US_SLIDER_CATEGORY_TAXONOMY ); |
| 627 |
$slug = $term->slug; |
| 628 |
$content .= "[ultimate-slider category='" . $slug . "']"; |
| 629 |
} |
| 630 |
|
| 631 |
return $content; |
| 632 |
} |
| 633 |
|
| 634 |
/** |
| 635 |
* Adjust the orderby if none specified to display in user-set slide order |
| 636 |
* @since 2.0.0 |
| 637 |
*/ |
| 638 |
public function orderby_order_column( $query ) { |
| 639 |
|
| 640 |
if ( is_admin() and isset( $_GET['post_type'] ) and $_GET['post_type'] == EWD_US_SLIDER_POST_TYPE and ! isset( $_GET['orderby'] ) ) { |
| 641 |
|
| 642 |
$query->set( 'meta_key', 'EWD_US_Slide_Order' ); |
| 643 |
$query->set( 'orderby', 'meta_value_num' ); |
| 644 |
$query->set( 'order', 'ASC' ); |
| 645 |
} |
| 646 |
} |
| 647 |
|
| 648 |
/** |
| 649 |
* Get ID/name pairs for all posts and pages |
| 650 |
* @since 2.0.0 |
| 651 |
*/ |
| 652 |
public function get_all_post_ids( $return = 'json' ) { |
| 653 |
|
| 654 |
$args = array( |
| 655 |
'post_type' => array( 'page', 'post' ), |
| 656 |
'orderby' => 'menu_order', |
| 657 |
'posts_per_page' => 200, |
| 658 |
); |
| 659 |
|
| 660 |
$query = new WP_Query ( $args ); |
| 661 |
$posts = $query->posts; |
| 662 |
|
| 663 |
if ( $return == 'objects' ) { return $posts; } |
| 664 |
|
| 665 |
$return_pairs = array(); |
| 666 |
foreach ( $posts as $post ) { |
| 667 |
|
| 668 |
$return_pair[ 'ID' ] = $post->ID; |
| 669 |
$return_pair[ 'Name' ] = $post->post_title; |
| 670 |
|
| 671 |
$return_pairs[] = $return_pair; |
| 672 |
} |
| 673 |
|
| 674 |
echo json_encode( $return_pairs ); |
| 675 |
} |
| 676 |
|
| 677 |
/** |
| 678 |
* Update the display order when slides are dragged and dropped |
| 679 |
* @since 2.0.0 |
| 680 |
*/ |
| 681 |
public function update_slides_order() { |
| 682 |
|
| 683 |
$post_ids = json_decode( stripslashes( $_POST['IDs'] ) ); |
| 684 |
if ( ! is_array( $post_ids ) ) { $post_ids = array(); } |
| 685 |
|
| 686 |
foreach ( $post_ids as $order => $post_id ) { |
| 687 |
|
| 688 |
update_post_meta( intval( $post_id ), 'EWD_US_Slide_Order', intval( $order ) ); |
| 689 |
} |
| 690 |
} |
| 691 |
} |
| 692 |
} // endif; |
| 693 |
|