karim
karim

Reputation: 45

Why Wordpress wp_update_post function removes html form tags?

I'm trying to add a form with hidden inputs into the post content using external PHP fle.

When i try it from the browser the form added successfully but when i try it from command line, the form inputs are deleted.

Here is my code:

require('../wp-load.php');

$content = '<div class="buy-preowned">
    <form accept-charset="UTF-8" action="https://www.tesla.com//order?redirect=no" id="tesla-cpo-marketing-buy-form" method="post">
        <div>
            <input name="CPOvehicle" type="text" value="1"/>
            <input name="VIN" type="hidden" value="5YJSA1E1XHF210809"/>
            <input name="vehicleMapId" type="hidden" value="1280359"/>
            <input name="titleStatus" type="hidden" value="NEW"/>
            <input name="form_id" type="hidden" value="tesla_cpo_marketing_buy_form"/>
        </div>
    </form>
    <p class="small-text">
        Requires a $2,500 deposit
    </p>

</div>
';

$post_id = 1;
$data = array(
  'ID'           => $post_id,
  'post_content' => $content,
);

When i checked the database, the form is stored as:

<form accept-charset="UTF-8" action="https://www.tesla.com//order?redirect=no" id="tesla-cpo-marketing-buy-form" method="post">
    <div>
    </div>
</form>

this is only happen when i rub the script from command line, any idea how to resolve it.

Thank you

Upvotes: 2

Views: 1596

Answers (1)

Elvin Haci
Elvin Haci

Reputation: 3572

It s because of built-in security filters. As it is not normal to store some form data inside content(there are shortcodes for that), WP disabled inserting some non-text tags.

But anyway, you can enable it manually.

kses_remove_filters();    
$post_id = 1;
$data = array(
  'ID'           => $post_id,
  'post_content' => $content,
);      
wp_update_post($data);
kses_init_filters();

Upvotes: 4

Related Questions