Skip to main content
Found function that triggers the bug, but not the fix
Source Link
Kalizi
  • 111
  • 5

I'm developing a Wordpress plugin (integrated with WooCommerce) that fetches HTML Content from an API, and add it to a WP Post as post_content into an iframe, this way:

kses_remove_filters();
$newData['description'] = str_replace("\n", "", $newData['description']);
$newData['description'] = str_replace("\t", "", $newData['description']);
$post = $this->getPostByAPIId($product->api_id);

$id = $post->ID ?? get_post($product->woo_id)->ID;
if (isset($id) && !empty($id)) {
    $this->wpdb->update(
        "{$this->wpdb->prefix}posts",
        [
            'post_content'  => '<iframe class="custom-post" id="custom_product_post_content" src="' . htmlspecialchars('data:text/html,' . stripslashes(rawurlencode($newData['description']))) . '" style="display: block;width:100vw; height:100vh; border:none; margin:0; padding:0; overflow:hidden; z-index:999999; min-height:300px!important;"></iframe>'
        ],
        [
            'ID' => $id
        ]
    );
}
kses_init_filters();

Even if I put the kses_remove_filters(), when I open wordpress to check the new content, I find out that the post_content is empty.

If I try to debug the plugin with xdebug, I find out that post_content is updated, but when I refresh wordpress, the post_content disappear.

A few project specifications before starting:

  1. I can't just embed the API as src
  2. I don't want to fetch content via javascript
  3. I used an iframe because I know that wordpress post_content can't embed a full HTML page like this: html > head { title } > body { style and various tags }
  4. I don't write the HTML personally, I need to embed it via the API

Feel free to ask any question. Thanks in advance.

Edit: Even if I use wp_update_post(['ID' => $id, 'post_content' => '...']) the post_content doesn't get updated and I get empty content.

Edit 2:

I enabled query log on my development environment and during debug session I found out that the function that "remove" the post_content is

wc_update_product_stock( $postId, $quantity )

Even if I wrap this function with a kses_remove_filters(), the function doesn't change its behaviour. Is there any way to "change" this behaviour without changing stock quantity update?

I'm developing a Wordpress plugin (integrated with WooCommerce) that fetches HTML Content from an API, and add it to a WP Post as post_content into an iframe, this way:

kses_remove_filters();
$newData['description'] = str_replace("\n", "", $newData['description']);
$newData['description'] = str_replace("\t", "", $newData['description']);
$post = $this->getPostByAPIId($product->api_id);

$id = $post->ID ?? get_post($product->woo_id)->ID;
if (isset($id) && !empty($id)) {
    $this->wpdb->update(
        "{$this->wpdb->prefix}posts",
        [
            'post_content'  => '<iframe class="custom-post" id="custom_product_post_content" src="' . htmlspecialchars('data:text/html,' . stripslashes(rawurlencode($newData['description']))) . '" style="display: block;width:100vw; height:100vh; border:none; margin:0; padding:0; overflow:hidden; z-index:999999; min-height:300px!important;"></iframe>'
        ],
        [
            'ID' => $id
        ]
    );
}
kses_init_filters();

Even if I put the kses_remove_filters(), when I open wordpress to check the new content, I find out that the post_content is empty.

If I try to debug the plugin with xdebug, I find out that post_content is updated, but when I refresh wordpress, the post_content disappear.

A few project specifications before starting:

  1. I can't just embed the API as src
  2. I don't want to fetch content via javascript
  3. I used an iframe because I know that wordpress post_content can't embed a full HTML page like this: html > head { title } > body { style and various tags }
  4. I don't write the HTML personally, I need to embed it via the API

Feel free to ask any question. Thanks in advance.

Edit: Even if I use wp_update_post(['ID' => $id, 'post_content' => '...']) the post_content doesn't get updated and I get empty content.

I'm developing a Wordpress plugin (integrated with WooCommerce) that fetches HTML Content from an API, and add it to a WP Post as post_content into an iframe, this way:

kses_remove_filters();
$newData['description'] = str_replace("\n", "", $newData['description']);
$newData['description'] = str_replace("\t", "", $newData['description']);
$post = $this->getPostByAPIId($product->api_id);

$id = $post->ID ?? get_post($product->woo_id)->ID;
if (isset($id) && !empty($id)) {
    $this->wpdb->update(
        "{$this->wpdb->prefix}posts",
        [
            'post_content'  => '<iframe class="custom-post" id="custom_product_post_content" src="' . htmlspecialchars('data:text/html,' . stripslashes(rawurlencode($newData['description']))) . '" style="display: block;width:100vw; height:100vh; border:none; margin:0; padding:0; overflow:hidden; z-index:999999; min-height:300px!important;"></iframe>'
        ],
        [
            'ID' => $id
        ]
    );
}
kses_init_filters();

Even if I put the kses_remove_filters(), when I open wordpress to check the new content, I find out that the post_content is empty.

If I try to debug the plugin with xdebug, I find out that post_content is updated, but when I refresh wordpress, the post_content disappear.

A few project specifications before starting:

  1. I can't just embed the API as src
  2. I don't want to fetch content via javascript
  3. I used an iframe because I know that wordpress post_content can't embed a full HTML page like this: html > head { title } > body { style and various tags }
  4. I don't write the HTML personally, I need to embed it via the API

Feel free to ask any question. Thanks in advance.

Edit: Even if I use wp_update_post(['ID' => $id, 'post_content' => '...']) the post_content doesn't get updated and I get empty content.

Edit 2:

I enabled query log on my development environment and during debug session I found out that the function that "remove" the post_content is

wc_update_product_stock( $postId, $quantity )

Even if I wrap this function with a kses_remove_filters(), the function doesn't change its behaviour. Is there any way to "change" this behaviour without changing stock quantity update?

added 153 characters in body
Source Link
Kalizi
  • 111
  • 5

I'm developing a Wordpress plugin (integrated with WooCommerce) that fetches HTML Content from an API, and add it to a WP Post as post_content into an iframe, this way:

kses_remove_filters();
$newData['description'] = str_replace("\n", "", $newData['description']);
$newData['description'] = str_replace("\t", "", $newData['description']);
$post = $this->getPostByAPIId($product->api_id);

$id = $post->ID ?? get_post($product->woo_id)->ID;
if (isset($id) && !empty($id)) {
    $this->wpdb->update(
        "{$this->wpdb->prefix}posts",
        [
            'post_content'  => '<iframe class="custom-post" id="custom_product_post_content" src="' . htmlspecialchars('data:text/html,' . stripslashes(rawurlencode($newData['description']))) . '" style="display: block;width:100vw; height:100vh; border:none; margin:0; padding:0; overflow:hidden; z-index:999999; min-height:300px!important;"></iframe>'
        ],
        [
            'ID' => $id
        ]
    );
}
kses_init_filters();

Even if I put the kses_remove_filters(), when I open wordpress to check the new content, I find out that the post_content is empty.

If I try to debug the plugin with xdebug, I find out that post_content is updated, but when I refresh wordpress, the post_content disappear.

A few project specifications before starting:

  1. I can't just embed the API as src
  2. I don't want to fetch content via javascript
  3. I used an iframe because I know that wordpress post_content can't embed a full HTML page like this: html > head { title } > body { style and various tags }
  4. I don't write the HTML personally, I need to embed it via the API

Feel free to ask any question. Thanks in advance.

Edit: Even if I use wp_update_post(['ID' => $id, 'post_content' => '...']) the post_content doesn't get updated and I get empty content.

I'm developing a Wordpress plugin (integrated with WooCommerce) that fetches HTML Content from an API, and add it to a WP Post as post_content into an iframe, this way:

kses_remove_filters();
$newData['description'] = str_replace("\n", "", $newData['description']);
$newData['description'] = str_replace("\t", "", $newData['description']);
$post = $this->getPostByAPIId($product->api_id);

$id = $post->ID ?? get_post($product->woo_id)->ID;
if (isset($id) && !empty($id)) {
    $this->wpdb->update(
        "{$this->wpdb->prefix}posts",
        [
            'post_content'  => '<iframe class="custom-post" id="custom_product_post_content" src="' . htmlspecialchars('data:text/html,' . stripslashes(rawurlencode($newData['description']))) . '" style="display: block;width:100vw; height:100vh; border:none; margin:0; padding:0; overflow:hidden; z-index:999999; min-height:300px!important;"></iframe>'
        ],
        [
            'ID' => $id
        ]
    );
}
kses_init_filters();

Even if I put the kses_remove_filters(), when I open wordpress to check the new content, I find out that the post_content is empty.

If I try to debug the plugin with xdebug, I find out that post_content is updated, but when I refresh wordpress, the post_content disappear.

A few project specifications before starting:

  1. I can't just embed the API as src
  2. I don't want to fetch content via javascript
  3. I used an iframe because I know that wordpress post_content can't embed a full HTML page like this: html > head { title } > body { style and various tags }
  4. I don't write the HTML personally, I need to embed it via the API

Feel free to ask any question. Thanks in advance.

I'm developing a Wordpress plugin (integrated with WooCommerce) that fetches HTML Content from an API, and add it to a WP Post as post_content into an iframe, this way:

kses_remove_filters();
$newData['description'] = str_replace("\n", "", $newData['description']);
$newData['description'] = str_replace("\t", "", $newData['description']);
$post = $this->getPostByAPIId($product->api_id);

$id = $post->ID ?? get_post($product->woo_id)->ID;
if (isset($id) && !empty($id)) {
    $this->wpdb->update(
        "{$this->wpdb->prefix}posts",
        [
            'post_content'  => '<iframe class="custom-post" id="custom_product_post_content" src="' . htmlspecialchars('data:text/html,' . stripslashes(rawurlencode($newData['description']))) . '" style="display: block;width:100vw; height:100vh; border:none; margin:0; padding:0; overflow:hidden; z-index:999999; min-height:300px!important;"></iframe>'
        ],
        [
            'ID' => $id
        ]
    );
}
kses_init_filters();

Even if I put the kses_remove_filters(), when I open wordpress to check the new content, I find out that the post_content is empty.

If I try to debug the plugin with xdebug, I find out that post_content is updated, but when I refresh wordpress, the post_content disappear.

A few project specifications before starting:

  1. I can't just embed the API as src
  2. I don't want to fetch content via javascript
  3. I used an iframe because I know that wordpress post_content can't embed a full HTML page like this: html > head { title } > body { style and various tags }
  4. I don't write the HTML personally, I need to embed it via the API

Feel free to ask any question. Thanks in advance.

Edit: Even if I use wp_update_post(['ID' => $id, 'post_content' => '...']) the post_content doesn't get updated and I get empty content.

Source Link
Kalizi
  • 111
  • 5

Wordpress post_content gets deleted in cron after wp_update_post

I'm developing a Wordpress plugin (integrated with WooCommerce) that fetches HTML Content from an API, and add it to a WP Post as post_content into an iframe, this way:

kses_remove_filters();
$newData['description'] = str_replace("\n", "", $newData['description']);
$newData['description'] = str_replace("\t", "", $newData['description']);
$post = $this->getPostByAPIId($product->api_id);

$id = $post->ID ?? get_post($product->woo_id)->ID;
if (isset($id) && !empty($id)) {
    $this->wpdb->update(
        "{$this->wpdb->prefix}posts",
        [
            'post_content'  => '<iframe class="custom-post" id="custom_product_post_content" src="' . htmlspecialchars('data:text/html,' . stripslashes(rawurlencode($newData['description']))) . '" style="display: block;width:100vw; height:100vh; border:none; margin:0; padding:0; overflow:hidden; z-index:999999; min-height:300px!important;"></iframe>'
        ],
        [
            'ID' => $id
        ]
    );
}
kses_init_filters();

Even if I put the kses_remove_filters(), when I open wordpress to check the new content, I find out that the post_content is empty.

If I try to debug the plugin with xdebug, I find out that post_content is updated, but when I refresh wordpress, the post_content disappear.

A few project specifications before starting:

  1. I can't just embed the API as src
  2. I don't want to fetch content via javascript
  3. I used an iframe because I know that wordpress post_content can't embed a full HTML page like this: html > head { title } > body { style and various tags }
  4. I don't write the HTML personally, I need to embed it via the API

Feel free to ask any question. Thanks in advance.