How can I stop wp_update_post messing up HTML example code?

It was https://wordpress.org/plugins/syntaxhighlighter/ plugin’s fault. There are some functions in it that have something to do with this, namely encode_shortcode_contents_slashed_noquickedit, encode_shortcode_contents_callback. Now I replaced it to https://wordpress.org/plugins/crayon-syntax-highlighter/ but by the time I confirmed it was the other plugin’s fault I had already written a solution. function wpse190396_insert_post_data($data, $postarr){ if($postarr[‘filter’] == ‘db’ && ($data[‘post_type’] == ‘fix’ … Read more

How to allow data:image attribute in src tag during post insert?

Thanks to naththedeveloper from StackOverflow. His answer worked for me. Well, this was a nightmare to find, but I think I’ve resolved it after digging through the WordPress code which hooks in through wp_insert_post. Please add this to your functions.php file and check it works: add_filter(‘kses_allowed_protocols’, function ($protocols) { $protocols[] = ‘data’; return $protocols; }); … Read more

Insert new term during new post creation

first you should set the taxnomy in custom post type you have just set only for post title post content post comments you did not set for custom taxnomy $post = array(‘tax_input’ => [ array( <taxonomy> => <array | string> ) ] // For custom taxonomies. Default empty. ‘page_template’ => [ <string> ] // Requires … Read more

wp_insert_post incorrectly escapes HTML comments when they include tags

The following program: <?php $_SERVER[‘HTTP_HOST’] = ‘localhost’; require_once(‘wp-load.php’); $post = array( ‘post_title’ => ‘HTML Escape’, ‘post_content’ => ‘This is <!– a comment –><br/>This is <!– <p>a comment</p> –>’, ‘post_status’ => ‘publish’ ); $id = wp_insert_post($post); $post = get_post($id); var_export( esc_html( $post->post_content ) ); ?> Outputs the following in the browser: ‘This is <!– a comment … Read more

can’t edit post_modified in wp_insert_post (bug?)

It is not bug, actually WordPress does not allow (using arguments) to set post modification date. Internally WordPress set it to current time if you are updating an existing post else just set it to post date. in /wp-includes/post.php#L3192 you can see wp_insert_post does not use this argument if ( $update || ‘0000-00-00 00:00:00’ == … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)