Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 13th, 2012  |  syntax: None  |  size: 1.19 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. /**
  3.  * Sets up the theme by loading the Mysitemyway class & initializing the framework
  4.  * which activates all classes and functions needed for theme's operation.
  5.  *
  6.  * @package Mysitemyway
  7.  * @subpackage Functions
  8.  */
  9.  
  10. <?php
  11.  
  12. // update the "4" to the ID of your form
  13. add_filter("gform_post_submission_4", "gform_set_post_thumbnail");
  14. function gform_set_post_thumbnail($entry){
  15.    
  16.     // get post ID of the created post
  17.     $post_id = $entry["post_id"];
  18.    
  19.     // get the last image added to the post
  20.     $attachments = get_posts(array('numberposts' => '1', 'post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC'));
  21.    
  22.     if(sizeof($attachments) == 0)
  23.         return; //no images attached to the post
  24.  
  25.     // set image as the post thumbnail
  26.     set_post_thumbnail($post_id, $attachments[0]->ID);
  27.  
  28. }
  29.  
  30. # Load the Mysitemyway class.
  31. require_once( TEMPLATEPATH . '/framework.php' );
  32.  
  33. # Get theme data.
  34. $theme_data = get_theme_data( TEMPLATEPATH . '/style.css' );
  35.  
  36. # Initialize the Mysitemyway framework.
  37. Mysitemyway::init(array(
  38.         'theme_name' => $theme_data['Name'],
  39.         'theme_version' => $theme_data['Version']
  40. ));
  41.  
  42. ?>