edd_add_download_post_classes

Adds post classes for downloads.

Description

(array) edd_add_download_post_classes( (array) $classes, (string) $class = '', (bool) $post_id = false ); 

Returns (array)

Modified array of classes

Parameters (3)

0. $classes (array)
Current classes
1. $class — Optional. (string) => ''
The class.
2. $post_id — Optional. (bool) => false
The ID of the current post

Usage

  1. if ( !function_exists( 'edd_add_download_post_classes' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'easy-digital-downloads/includes/template-functions.php'; 
  3.  
  4. // Current classes 
  5. $classes = array(); 
  6.  
  7. // The class. 
  8. $class = ''; 
  9.  
  10. // The ID of the current post 
  11. $post_id = false; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = edd_add_download_post_classes($classes, $class, $post_id); 
  15.  

Defined (1)

The function is defined in the following location(s).

/includes/template-functions.php  
  1. function edd_add_download_post_classes( $classes, $class = '', $post_id = false ) { 
  2. if( ! $post_id || get_post_type( $post_id ) !== 'download' || is_admin() ) { 
  3. return $classes; 
  4.  
  5. $download = edd_get_download( $post_id ); 
  6.  
  7. if( $download ) { 
  8. $classes[] = 'edd-download'; 
  9.  
  10. // Add category slugs 
  11. $categories = get_the_terms( $post_id, 'download_category' ); 
  12. if( ! empty( $categories ) ) { 
  13. foreach( $categories as $key => $value ) { 
  14. $classes[] = 'edd-download-cat-' . $value->slug; 
  15.  
  16. // Add tag slugs 
  17. $tags = get_the_terms( $post_id, 'download_tag' ); 
  18. if( ! empty( $tags ) ) { 
  19. foreach( $tags as $key => $value ) { 
  20. $classes[] = 'edd-download-tag-' . $value->slug; 
  21.  
  22. // Add edd-download 
  23. if( is_singular( 'download' ) ) { 
  24. $classes[] = 'edd-download'; 
  25.  
  26. return $classes;