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