title: How to insert custom value in the script
body: <p>all,
  I have this script: (I'm sorry I'm putting it all here, but I'm not sure what's important)
  [php]</p>
  
  <pre><code>&lt;?php
  add_action('the_content','rpf_content_filter');
  add_filter('wp_head', 'rpf_init');
  $rpf_options = get_option('rpf_options');
  
  function rpf_content_filter($content){
      if(is_admin())
          return $content;
  
      $id = get_post_meta(get_the_ID(), 'rpf_feed_id', true);
  
      if(!$id)
          return $content;//might be normal content
  
      global $rpf_options;
      if($rpf_options['word_limit'] &gt;0 )
          $content = rpf_truncate($content, $rpf_options['word_limit']);
  
  
      $sourcelink=get_post_meta(get_the_ID(), 'rpf_sourcepermalink', true);
  
      if($sourcelink)
          $link='&lt;p&gt;'.rpf_custom_template($sourcelink,$id).'&lt;/p&gt;';
  
      $content=$content.$link;
  
      return $content;
  
  
  }
  
  function rpf_custom_template($sourcelink,$feed_id){
  
  
  
      global $rpf_options;
      $custom_template = $rpf_options['custom_template'];
  
      if( false ===  strpos($custom_template, '%SOURCE_URL%' ) )
          $custom_template .= ' &lt;a href="%SOURCE_URL%"&gt;%SOURCE_URL%&lt;/a&gt; ';
  
  
  
      $feed = rpf_get_feed($feed_id);
  
      $user = get_userdata($feed['author']);
      $author = $user-&gt;nickname;
  
      $category = get_cat_name($feed['category']);
  
      $feed_url = $feed['url'];
  
      $feed_name = $feed['name'];
  
      $custom_template = str_replace(
          array('%SOURCE_URL%','%AUTHOR%','%CATEGORY%','%FEED_URL%','%FEED_NAME%'),
          array($sourcelink,$author,$category,$feed_url,$feed_name),
          $custom_template
  
      );
  
      return $custom_template;
  
  
  }
  function rpf_truncate($text,$count) { 
      $count=intval($count);
      if(  $count&lt;1 || substr_count($text,' ') &lt; $count )
          return $text;
  
      $temp = explode(' ', $text);
  
      $text = implode(' ', array_slice($temp, 0, $count));
  
      return $text;
  
  }
  function rpf_init(){
  
      global $rpf_options;
  
      $now_time=time();
  
      $interval=60*60*3;
      $lastactive=$rpf_options['lastactive'];
      if(!$lastactive){
          $lastactive=$now_time;
          $rpf_options['lastactive']=$lastactive;
          update_option('rpf_options', $rpf_options);
  
      }
  
      if ( ($now_time - $lastactive ) &gt;= $interval ) {
  
          $rpf_options['lastactive'] = $now_time+$interval;
          update_option('rpf_options', $rpf_options);
          rpf_process_feeds();
      }
  
  }
  
  
  
  function rpf_process_feeds(){
  
      @set_time_limit(0);
  
  
      $feeds=rpf_get_feeds();
      if($feeds){
  
          rpf_log("&lt;b&gt;----------Processing all feeds-------------&lt;/b&gt;");
          foreach($feeds as $feed){
  
              rpf_process_feed($feed);
  
          }
      }else{
  
          rpf_log("No feeds data found!");
      }
  
  
  }
  
  
  function rpf_process_feed($feed){
      @set_time_limit(0);
      if(empty($feed['url'])){
  
          return false;
      }
  
  
      rpf_log("Processing feed &lt;b&gt;{$feed['url']}&lt;/b&gt;");
  
      $lastactive = $feed['lastactive'];
  
      $now=time();
  
      $frequency = $feed['frequency']*60*60;
  
      if( ($now - $lastactive) &gt;= $frequency ){
  
          rpf_update_feed_lastactive($feed['id'],$now);
  
      }else{
  
          rpf_log("It's not the time to update &lt;b&gt;{$feed['url']}&lt;/b&gt;. &lt;a href='http://www.wprssposter.com/faq.html#cronjob'&gt;Explanation&lt;/a&gt;");
          return false;
      }
  
      global $rpf_options;
  
      $max_items=$feed['max_items'];
  
      if(empty($max_items)||!is_numeric($max_items))
  
          $max_items=3;
  
      $simplepie = rpf_fetch_feed($feed['url'],$max_items);
      $error=$simplepie-&gt;error();
  
      if($error){
  
          rpf_log("Feed Error: &lt;b&gt;$error&lt;/b&gt;");
          return false;
      }
  
          $count = 0;
  
      foreach($simplepie-&gt;get_items() as $item){
          if( rpf_is_duplicate(  $item-&gt;get_title() ) ){
                  rpf_log('Filtering duplicate post');
                  continue;
          }
          if(false == rpf_process_item($item,$feed))
              continue;
          $count++;
          if($count == $max_items)
              break;
          }
  
          if($count==0)
          rpf_log("No new or qualified post for &lt;b&gt;{$feed['url']}&lt;/b&gt; &lt;a href='http://www.wprssposter.com/faq.html#newandqualified'&gt;Explanation&lt;/a&gt;");
      else
          rpf_log( "Fetch $count posts from &lt;b&gt;{$feed['url']}&lt;/b&gt;" );
  
  
          return true;
  
  
  }
  function rpf_process_item($item,$feed){
  
  
      global $wpdb;
  
      $title = $item-&gt;get_title();
  
      $link = $item-&gt;get_permalink();
  
      if(false !== strpos($link,'news.google.com')){
          $link=urldecode(substr($link,strpos($link,'url=')+4));
      }elseif(false !== strpos($link,'/**')){
          $link=urldecode(substr($link,strpos($link,'/**')+3));
  
      }   
  
      $content = rpf_full_feed($link);
  
      if(!$content ){
          //rpf_log("Cannot grab full content from &lt;b&gt;$link&lt;/b&gt;");
          return false;
      }
      $title=rpf_title_fix($title);
  
      $content=rpf_content_fix($content);
  
      if(empty($title)||empty($content)){
  
          return false;
      }
  
      $content=rpf_parse_images($content,$item-&gt;get_base());
      $meta = array(
           'rpf_feed_id' =&gt; $feed['id'],
           'rpf_sourcepermalink' =&gt; $link,
  
          );
  
      $rpf_date = date("Y-m-d H:i:s", time());
      if($feed['publish_date'] === 'Publish Immediately'){
  
      }elseif($feed['publish_date'] === 'RSS Publication Date'){
  
          $rpf_date = $item-&gt;get_date("Y-m-d H:i:s");
      }
  
  
  
      rpf_insert_post( $title,$content,$feed['category'],$feed['tags'],$meta,$feed['post_status'],$rpf_date,$feed['author']);
      rpf_log("&lt;b&gt;{$title}&lt;/b&gt; added");
      global $wpdb;
      global $rpf_options;
      $hash=rpf_item_hash($item-&gt;get_title());
      $sql="insert into {$rpf_options['db']['post']} (hash) values ('{$hash}')";
      $wpdb-&gt;query($sql);
  
      return true;
  
  
  }
  function rpf_title_fix($title){
      if($title &amp;&amp; strpos($title,' - ')){
  
          $backup=$title;
          $backup=preg_replace('/([-])/','$1[D]',$backup);
  
          $backup=explode('[D]',$backup);
  
          if( strlen($backup[0])&gt;10 || count($backup)&gt;=2 )
              unset($backup[count($backup)-1]);
          else
              return $title;
  
          $title=trim(implode('',$backup),' - ');
      }
      return $title;
  
  }
  
  function rpf_content_fix($text){
      preg_match_all('@(&lt;a.+?href=\".+?\"&gt;)(.*?&lt;/a&gt;)@',$text,$m);
      $urls = $m[1];
      if(count($urls)){
          foreach($urls as $pos =&gt; $link){
              if(false === stripos($link,'http://') &amp;&amp; false === stripos($link,'https://')){
  
                  $text=str_replace($link,'',$text);
  
                  $text=str_replace($m[2][$pos],str_replace('&lt;/a&gt;','',$m[2][$pos]),$text);
              }
          }
      }
      $text=preg_replace("/[&amp;|#|&amp;#]+[a-z0-9]+;/i","",$text);
      $text=preg_replace('@&lt;[dtrx][^&gt;]*&gt;@','',$text);
      $text=preg_replace('@&lt;/[dtrx][^&gt;]*&gt;@','',$text);
      return $text;
  
  }
  function rpf_parse_images($content,$link){
  
      preg_match_all('/&lt;img(.+?)src=\"(.+?)\"(.*?)&gt;/', $content, $images);
      $urls = $images[2];
  
          if(count($urls)){
  
          foreach($urls as $pos =&gt; $url){
              $oldurl=$url;
              $meta=parse_url($url);
  
              if(!isset($meta['host'])){
  
                  $meta=parse_url($link);
                  $url=$meta['scheme'].'://'.$meta['host'].'/'.$url;
  
              }
  
                  $newurl = rpf_cache_image($url);
                  if($newurl)
                          $content = str_replace($oldurl, $newurl, $content);
              else
                  $content = str_replace($images[0][$pos],'',$content);
              } 
          }
      return $content;
  
  
  
  }
  function rpf_cache_image($url){
      if( strpos($url, "icon_") !== FALSE)
            return false;
      global $rpf_options;
      $contents = rpf_get_file($url);
  
      if( !$contents )
          return false;
      $basename = basename($url);
      $paresed_url = parse_url($basename);
  
      $filename = substr(md5(time()), 0, 5) . '_' . $paresed_url['path'];
  
      $cachepath = RPF_CACHE;
      $pluginpath = RPF_URL_ROOT;
          $real_cachepath=dirname(__FILE__).'/'.$cachepath;
      if(is_writable( $real_cachepath ) ){
  
          if($contents){
  
              file_put_contents($real_cachepath . $filename, $contents);
              $i=@exif_imagetype($real_cachepath . $filename);
              if($i)
                  return $pluginpath . $cachepath . rawurlencode($filename);
          }
      }else{
  
          rpf_log($real_cachepath . " directory is not writable" );
  
      }
  
      return false;
  
  }
  function rpf_insert_post($title,$content,$category=array(1),$tags_input='',$meta='',$post_status='publish',$rpf_date,$post_author=1){
  
  
      $category=(array)$category;
  
      if(!$rpf_date)
          $rpf_date = time();
  
  
      $postid = wp_insert_post(array(
              'post_title'              =&gt; $title,
          'post_content'        =&gt; $content,
          'post_category'           =&gt; $category,
          'tags_input'          =&gt; $tags_input,
          'post_status'         =&gt; $post_status,
          'post_author'             =&gt; $post_author,
          "post_date"           =&gt; get_date_from_gmt($rpf_date),
          ));
      if($meta)
          foreach($meta as $key =&gt; $value) 
              rpf_insert_post_meta($postid, $key, $value);
  
  
      return $postid;
  
  }
  
  function rpf_full_feed($permalink){
  
      require_once(RPFINC.'readability.php');
  
      if ($permalink &amp;&amp; $html = rpf_get_file($permalink)) {
  
          $html = rpf_convert_to_utf8($html);
  
          $content = grabArticleHtml($html);
  
  
      }else
          return false;
  
      if( false !== stripos($content,'readability was unable to parse this page for content') )
          return false;
      if( false !== stripos($content, 'return go_back();') )
          return false;
  
      return $content;
  
  }
  function rpf_insert_post_meta($postid, $key, $value) {
      global $wpdb;
  
      $result = $wpdb-&gt;query( "INSERT INTO $wpdb-&gt;postmeta (post_id,meta_key,meta_value ) " 
                                      . " VALUES ('$postid','$key','$value') ");
  
      return $wpdb-&gt;insert_id;        
  }
  
  function rpf_is_duplicate($title){
  
      global $wpdb;
      global $rpf_options;
  
      $hash = rpf_item_hash($title);
  
      $row = $wpdb-&gt;get_row("SELECT * FROM {$rpf_options['db']['post']} "
                            . "WHERE hash = '{$hash}'");  
      if($row)
          return true;
      return false;
  
  
  }
  
  function rpf_item_hash($data){
  
      return sha1($data);
  }
  function rpf_get_file($url){
  
      if(ini_get('allow_url_fopen') != 1) {
          @ini_set('allow_url_fopen', '1');
      }
  
      if(ini_get('allow_url_fopen') != 1) {
  
          $ch = curl_init();
  
          curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //Set curl to return the data instead of printing it to the browser.
          curl_setopt($ch, CURLOPT_URL, $url);
  
          $data = curl_exec($ch);
          curl_close($ch);
  
          return $data;
  
  
      } else {
          return @file_get_contents($url);
      }
  
      return false;
  
  
  }
  function rpf_fetch_feed($url,$max_items){
  
      $url=str_replace(' ','+',$url);
  
       # SimplePie
      if(! class_exists('SimplePie'))
        require_once( RPFINC . 'simplepie.class.php' );
  
      $feed = new SimplePie();
      $feed-&gt;enable_order_by_date(false); 
      $feed-&gt;set_feed_url($url);
      $feed-&gt;set_item_limit($max_items);
      $feed-&gt;set_stupidly_fast(true);
      $feed-&gt;enable_cache(false);    
      $feed-&gt;init();
      $feed-&gt;handle_content_type(); 
  
      return $feed;
  
  }
  
  function rpf_get_feeds(){
  
      $rtn_feeds=array();
      global $rpf_options;
  
      $feeds=$rpf_options['feed'];
  
      foreach($feeds as $feed){
  
  
          $rtn_feeds[]=$feed;
  
      }
      return $rtn_feeds;
  
  
  }
  
  function rpf_get_feed($id){
  
      $feeds=rpf_get_feeds();
  
      foreach($feeds as $feed){
  
          if($feed['id'] == $id)      
              return $feed;
  
      }
      return false;
  
  
  }
  
  function rpf_update_feed($_feed){
  
      global $rpf_options;
  
      $feeds=$rpf_options['feed'];
  
  
      foreach($_feed as $k =&gt; $v)
          $_feed[$k]=str_replace('\\','',$v);
  
      foreach($feeds as $key =&gt; $feed){
  
          if($feed['id'] == $_feed['id']){
  
              if(empty($_feed['name'])||empty($_feed['url'])){
  
                  unset($feeds[$key]);
                  $feeds[]=array(
                  'id' =&gt; $_feed['id'],
                  'name' =&gt; '',
                  'url' =&gt; '',
                  'category' =&gt; 1,
                  'tags' =&gt;'',
                  'frequency' =&gt; 8,
                  'max_items' =&gt; 3,
                  'lastactive' =&gt;'0',
                  'post_status' =&gt; 'publish',
                  'publish_date' =&gt; 'Publish Immediately',
                  'author' =&gt; 1
                  );
                  break;      
  
              }else{
                  if($_feed['url'] == $feed['url'] &amp;&amp; $_feed['name'] == $feed['name'])
                      $_feed['lastactive']=$feed['lastactive'];
                  else
                      $_feed['lastactive']='0';
  
                  unset($feeds[$key]);
                  $feeds[$key]=$_feed;
                  break;
              }
  
          }   
  
  
      }
      $rpf_options['feed']=$feeds;
      update_option('rpf_options',$rpf_options);
  
  }
  function rpf_update_feed_lastactive($id,$lastactive){
  
      global $rpf_options;
  
      $feeds=$rpf_options['feed'];
  
      foreach($feeds as $key =&gt; $feed){
  
          if($feed['id'] == $id){
              $backup=$feed;
              unset($feeds[$key]);
              $backup['lastactive']=$lastactive;
              $feeds[$key]=$backup;
              break;
  
          }   
  
  
      }
      $rpf_options['feed']=$feeds;
      update_option('rpf_options',$rpf_options);
  
  }
  
  
  function rpf_log($message){
      global $wpdb;
          global $rpf_options;
          $message = $wpdb-&gt;escape($message);
          $time = current_time('mysql', true);
          $wpdb-&gt;query("INSERT INTO {$rpf_options['db']['log']} (message, created_on) VALUES ('{$message}', '{$time}') "); 
  
  }
  function rpf_get_logs($page,$logs_per_page){
      global $wpdb;
      global $rpf_options;
  
  
      if($page == 0) $page = 1;
      $page--;
      $orderby = "created_on";
      $ordertype = 'ASC';
      $start = $page * $logs_per_page;
      $end = $start + $logs_per_page;
      $limit = "LIMIT {$start}, {$end}";
  
  
      return $wpdb-&gt;get_results("SELECT * FROM {$rpf_options['db']['log']} ORDER BY $orderby $ordertype $limit");
  }
  function rpf_timezone_mysql($format, $time){
      return mysql2date($format, $time);    
  }
  //////////////////////////////////////////////
  // Convert $html to UTF8
  // (uses HTTP headers and HTML to find encoding)
  // adapted from http://stackoverflow.com/questions/910793/php-detect-encoding-and-make-everything-utf-8
  //////////////////////////////////////////////
  function rpf_convert_to_utf8($html, $header=null)
  {
      $accept = array(
          'type' =&gt; array('application/rss+xml', 'application/xml', 'application/rdf+xml', 'text/xml', 'text/html'),
          'charset' =&gt; array_diff(mb_list_encodings(), array('pass', 'auto', 'wchar', 'byte2be', 'byte2le', 'byte4be', 'byte4le', 'BASE64', 'UUENCODE', 'HTML-ENTITIES', 'Quoted-Printable', '7bit', '8bit'))
      );
      $encoding = null;
      if ($html || $header) {
          if (is_array($header)) $header = implode("\n", $header);
          if (!$header || !preg_match_all('/^Content-Type:\s+([^;]+)(?:;\s*charset=([^;"\'\n]*))?/im', $header, $match, PREG_SET_ORDER)) {
              // error parsing the response
          } else {
              $match = end($match); // get last matched element (in case of redirects)
              if (!in_array(strtolower($match[1]), $accept['type'])) {
                  // type not accepted
                  // TODO: avoid conversion
              }
              if (isset($match[2])) $encoding = trim($match[2], '"\'');
          }
          if (!$encoding) {
              if (preg_match('/^&lt;\?xml\s+version=(?:"[^"]*"|\'[^\']*\')\s+encoding=("[^"]*"|\'[^\']*\')/s', $html, $match)) {
                  $encoding = trim($match[1], '"\'');
              } elseif(preg_match('/&lt;meta\s+http-equiv=["\']Content-Type["\'] content=["\'][^;]+;\s*charset=([^;"\'&gt;]+)/i', $html, $match)) {
                  if (isset($match[1])) $encoding = trim($match[1]);
              }
          }
          if (!$encoding) {
              $encoding = 'utf-8';
          } else {
              if (!in_array($encoding, array_map('strtolower', $accept['charset']))) {
                  // encoding not accepted
                  // TODO: avoid conversion
              }
              if (strtolower($encoding) != 'utf-8') {
                  if (strtolower($encoding) == 'iso-8859-1') {
                      // replace MS Word smart qutoes
                      $trans = array();
                      $trans[chr(130)] = '&amp;sbquo;';    // Single Low-9 Quotation Mark
                      $trans[chr(131)] = '&amp;fnof;';    // Latin Small Letter F With Hook
                      $trans[chr(132)] = '&amp;bdquo;';    // Double Low-9 Quotation Mark
                      $trans[chr(133)] = '&amp;hellip;';    // Horizontal Ellipsis
                      $trans[chr(134)] = '&amp;dagger;';    // Dagger
                      $trans[chr(135)] = '&amp;Dagger;';    // Double Dagger
                      $trans[chr(136)] = '&amp;circ;';    // Modifier Letter Circumflex Accent
                      $trans[chr(137)] = '&amp;permil;';    // Per Mille Sign
                      $trans[chr(138)] = '&amp;Scaron;';    // Latin Capital Letter S With Caron
                      $trans[chr(139)] = '&amp;lsaquo;';    // Single Left-Pointing Angle Quotation Mark
                      $trans[chr(140)] = '&amp;OElig;';    // Latin Capital Ligature OE
                      $trans[chr(145)] = '&amp;lsquo;';    // Left Single Quotation Mark
                      $trans[chr(146)] = '&amp;rsquo;';    // Right Single Quotation Mark
                      $trans[chr(147)] = '&amp;ldquo;';    // Left Double Quotation Mark
                      $trans[chr(148)] = '&amp;rdquo;';    // Right Double Quotation Mark
                      $trans[chr(149)] = '&amp;bull;';    // Bullet
                      $trans[chr(150)] = '&amp;ndash;';    // En Dash
                      $trans[chr(151)] = '&amp;mdash;';    // Em Dash
                      $trans[chr(152)] = '&amp;tilde;';    // Small Tilde
                      $trans[chr(153)] = '&amp;trade;';    // Trade Mark Sign
                      $trans[chr(154)] = '&amp;scaron;';    // Latin Small Letter S With Caron
                      $trans[chr(155)] = '&amp;rsaquo;';    // Single Right-Pointing Angle Quotation Mark
                      $trans[chr(156)] = '&amp;oelig;';    // Latin Small Ligature OE
                      $trans[chr(159)] = '&amp;Yuml;';    // Latin Capital Letter Y With Diaeresis
                      $html = strtr($html, $trans);
                  }
                  if(!class_exists('SimplePie_Misc'))
                      require_once(RPFINC.'simplepie.class.php');
  
                  $html = SimplePie_Misc::change_encoding($html, $encoding, 'utf-8');
  
                  /*
                  if (function_exists('iconv')) {
                      // iconv appears to handle certain character encodings better than mb_convert_encoding
                      $html = iconv($encoding, 'utf-8', $html);
                  } else {
                      $html = mb_convert_encoding($html, 'utf-8', $encoding);
                  }
                  */
              }
          }
      }
      return $html;
  }
  if ( ! function_exists( 'exif_imagetype' ) ) {
      function exif_imagetype ( $filename ) {
          return @getimagesize( $filename );
      }
  }
  ?&gt;
  </code></pre>
  
  <p>[/php]
  So in line 229 I want to define one more value like this: 
  [php]</p>
  
  <pre><code>$content=rpf_parse_images($content,$item-&gt;get_base());
      $meta = array(
           'rpf_feed_id' =&gt; $feed['id'],
           'rpf_sourcepermalink' =&gt; $link,
           [u][b]'preview'[/b][/u] =&gt;
  </code></pre>
  
  <p>[/php]
  I did it and it works, but the problem is that I want to insert here an already existing value - from line 337 - variable <code>$real_cachepath</code> from function <code>rpf_cache_image</code>. I have tried to define it directly, but it doesn't work. 
  Can you help me, please</p>