• Hi

    I am using some php in my functions.php with a form on another page which creates posts on my wordpress site, when using this php form on a non-wordpress site without the post creation feature, it functions perfectly however when using on my wordpress site it appears to strip out the site name in the [tab:sitename] and just leaves [tab:].

    Any ideas?

    This is the code for functions.php:

    $formatted = "";
    $groups = array();
    $first = true;
    
    if(isset($_POST["input"]))
    {
      $iframes = split("\n", $_POST["input"]);
      foreach($iframes as $iframe)
      {
        $iframe = trim($iframe);
    
        if($iframe == "")
        {
          continue;
        }
    
        if(stripos($iframe, "iframe") === false)
        {
          if(!$first)
          {
            $formatted .= "[tab:END]\n";
            array_push($groups, $formatted);
            $formatted = "";
          }
    
          $formatted .= $iframe . "\n";
          $first = false;
    
          continue;
        }
    
        preg_match_all('/src="([^"]*)"/i', $iframe, $matches);
        $site_name = $matches[1][0];
        $site_name = parse_url($site_name);
        $site_name = $site_name["host"];
        $site_name = split("\.", $site_name);
        $site_name = $site_name[0] == "www" ? $site_name[1] : $site_name[0];
    
        $formatted .= "[tab:" . $site_name . "]";
        $formatted .= $iframe;
        $formatted .= "\n";
      }
      $formatted .= "[tab:END]\n";
      array_push($groups, $formatted);
    
      foreach($groups as $group)
      {
        $title = split("\n", $group);
        $title = $title[0];
        $title = split("/", $title);
        $title = ucwords(str_replace("-", " ", $title[3]));
    
        $post = array(
          "post_content" => $group,
          "post_title" => $title,
          "post_status" => "publish",
          "filter" => true
        );
    
        wp_insert_post($post, $wp_error);
      }
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • An idea, but not necessarily a solution…

    It looks like variable $site_name starts as array and later becomes a string. I know normally PHP will handle variable typing automatically but as this is where the problem lies, you might try using different variables for the two types.

    Thread Starter baysey

    (@baysey)

    Thanks, I have fixed it now it seems to work great however i use it to input code such as:

    http://xyz.com/hello-world/
    <IFRAME SRC="http://abc.com" FRAMEBORDER=0 MARGINWIDTH=0 MARGINHEIGHT=0 SCROLLING=NO WIDTH=540 HEIGHT=330></IFRAME>
    <IFRAME SRC="def.com" FRAMEBORDER=0 MARGINWIDTH=0 MARGINHEIGHT=0 SCROLLING=NO WIDTH=600 HEIGHT=360></IFRAME>

    How do I get it to stop producing the http:// link at the top of the inputted code? I.e. so it just outputs the iframe code? The http is important in separating the iframes into groups when I have multiple groups of iframes however I don’t want it to reproduce this link in the post.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘WP stripping out code’ is closed to new replies.