0

I have a custom functionality which create a custom post with info entered on a form

Part of the post content is a line like <div id="featuredcocktail">

When I tested it as an admin all worked perfect and the content was created as I wanted, but once I used the form as non-logged user the custom post was created with only <div>.

When I changed the id to class like <div class="featuredcocktail"> it worked well for both admin and non-logged user.

$my_post = array(
                'post_title' => $company_field,
                'post_type' => 'bgmp',              
                'post_status' => 'draft',
                'comment_status'  => 'closed',
                'ping_status' => 'closed',
                'post_content' => $content
            );

    $id = wp_insert_post( $my_post );
    $cont   = '<div id="featuredcocktail">'. "\r\n";
    $cont  .= '<img src="'. $attach_data['file'] .'" alt="'. $filename .'" title="'. $filename .'" width="'. $attach_data['width'] .'" height="'. $attach_data['height'] .'" class="alignright size-medium" />'. "\r\n";
    wp_update_post( array('ID' => $id, 'post_content' => $cont ) ); 

Any idea how I can use id?

  • Without seeing the code that creates that markup, I don't see how this can be answered. – s_ha_dum Dec 21 '13 at 17:49
1

simplest solution - set the post_author to an admin or editor user.

The reason "id" and other attributes and tags are stripped from the content is to prevent unauthorized users to inject content which might be used to "still" the credentials of other users. Right now you don't explicitly set the user to which the post is associated which probably cause wordpress to filter the content.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.