daily pastebin goal
32%
SHARE
TWEET

Untitled

a guest Jun 23rd, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /*
  4.  * Removes un-necessary stuff from WP_Post object returned by Cite Wordpress Post Class
  5.  * Formats data ready to be output in view
  6.  */
  7.  
  8. use Cite\Boilerplate\App;
  9.  
  10.  
  11. function clean_up_object($dirty_object){
  12.  
  13.     // If the data to be cleaned up isn't a WP_Post object return the same data
  14.     if(is_array($dirty_object) || get_class($dirty_object) !== 'WP_Post'){
  15.         return $dirty_object;
  16.     }
  17.     $clean_object = new stdClass();
  18.  
  19.     // format date
  20.     if($dirty_object->post_type == 'post'){
  21.         // news - posted date
  22.         $date = $dirty_object->post_date;
  23.  
  24.     }else{
  25.         // PDF date (resources)
  26.         $date = get_field('pdf_date', $dirty_object->ID);
  27.     }
  28.  
  29.     $date_obj = new DateTime($date);
  30.     $clean_object->date = $date_obj->format(App::$config['theme_date_format']);
  31.  
  32.  
  33.     //title - if it's a news post, make this a link as well
  34.     if($dirty_object->post_type == 'post' || $dirty_object->post_type == 'page'){
  35.         $link_title = '<a href="' . get_permalink($dirty_object->ID) . '">';
  36.         $link_title .= $dirty_object->post_title;
  37.         $link_title .= '</a>';
  38.         $clean_object->title = $link_title;
  39.  
  40.     }else{
  41.         $clean_object->title = $dirty_object->post_title;
  42.     }
  43.  
  44.     // return post type to distinguish between posts
  45.     $clean_object->post_type = $dirty_object->post_type;
  46.  
  47.     // content
  48.     $clean_object->more_text = apply_filters( 'the_content', $dirty_object->post_content );
  49.  
  50.     // excerpt
  51.     $clean_object->excerpt = get_the_excerpt($dirty_object->ID);
  52.  
  53.     // post url
  54.     $clean_object->link = get_permalink($dirty_object->ID);
  55.  
  56.     // page image
  57.     $img_id = get_field('page_image', $dirty_object->ID); // image returns ID
  58.     $formatted_image = make_responsive_page_img($img_id);
  59.    
  60.     if($formatted_image) {
  61.         $clean_object->page_image = $formatted_image;
  62.     }
  63.  
  64.  
  65.     // Listed Item Image - member logo (resources)
  66.     $member_logo_ID   = get_field('member_logo', $dirty_object->ID); // image returns ID
  67.  
  68.     if($member_logo_ID){
  69.         $formatted_image = make_img($member_logo_ID, 'listed-item');
  70.        
  71.         if($formatted_image) {
  72.             $clean_object->listed_item_image = $formatted_image;
  73.         }
  74.  
  75.     // If there isn't a specific img for a listed item, but there is a page img - use this
  76.     }elseif($img_id){
  77.  
  78.         // different post types display a different sized listing image
  79.         switch ($dirty_object->post_type) {
  80.             case 'post':
  81.                 $image_size = 'page-mobile';
  82.                 break;
  83.             default:
  84.                 $image_size = 'listed-item';
  85.                 break;
  86.         }
  87.  
  88.         $clean_object->listed_item_image = make_img($img_id, $image_size);
  89.     }
  90.  
  91.     // PDF download (resources)
  92.     $clean_object->link = get_field('pdf_download', $dirty_object->ID);
  93.  
  94.  
  95.     // PDF author (resources)
  96.     $clean_object->pdf_author = get_field('pdf_author', $dirty_object->ID);
  97.  
  98.  
  99.     // get categories from post model
  100.     $clean_object->categories = PostsModel::get_category_list($dirty_object->ID);
  101.  
  102.     // get tags from post model
  103.     $clean_object->tags = PostsModel::get_tag_list($dirty_object->ID, $dirty_object->post_type);
  104.  
  105.  
  106.  
  107.     return $clean_object;
  108. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top