0

wp_insert_post を使用して、ファイルの html を取得し、投稿を自動的に作成しています。ディレクトリを検索し、正しいhtmlを開いて抽出する機能があります。ファイルには日付があります (これが、以下の subsrt() を使用する理由です)。html は、コンテンツに使用する他のものと同様に文字列です。

<?PHP
require_once(dirname(__FILE__)."/createpost.php");
$dir = dirname(__FILE__)."/html";
$files = scandir($dir);
$date = (string) date("Ymd");
foreach($files as  $value){
    if((substr($value,5,8)) == $date){
            $html = file_get_contents($dir."/".$value);
            createpost($value, $html);
            }
}

上記は機能します。以下は createpost() です。

<?php
function createpost($post_title, $post_content){
require_once("/var/www/wp-load.php");
$mypost = array(
  'ID'             => $post_id,//[ <post id> ] //Are you updating an existing post?
  'menu_order'     => $menu_order,//[ <order> ] //If new post is a page, it sets the order in        which it should appear in the tabs.
  'comment_status' => $comment_status,//[ 'closed' | 'open' ] // 'closed' means no comments.
  'ping_status'    => $ping_status,//[ 'closed' | 'open' ] // 'closed' means pingbacks or trackbacks turned off
  'pinged'         => $pinged,//[ ? ] //?
  'post_author'    => $post_author,//[ <user ID> ] //The user ID number of the author.
  'post_category'  => $post_category,//[ array(<category id>, <...>) ] //post_category no longer exists, try wp_set_post_terms() for setting a post's categories
 'post_content'   => "[raw]\n\n".$post_content."\n\n[/raw]",//[ <the text of the post> ] //The full text of the post.
 'post_date'      => $post_date,//[ Y-m-d H:i:s ] //The time post was made.
  'post_date_gmt'  => $post_date_gmt,//[ Y-m-d H:i:s ] //The time post was made, in GMT.
  'post_excerpt'   => $post_excerpt,//[ <an excerpt> ] //For all your post excerpt needs.
  'post_name'      => $post_name,//[ <the name> ] // The name (slug) for your post
  'post_parent'    => $post_parent,//[ <post ID> ] //Sets the parent of the new post.
  'post_password'  => $post_password,//[ ? ] //password for post?
  'post_status'    => 'private',//[ 'draft' | 'publish' | 'pending'| 'future' | 'private' | 'custom_registered_status' ] //Set the status of the new post.
 'post_title'     => $post_title,//[ <the title> ] //The title of your post.
 'post_type'      => $post_type,//[ 'post' | 'page' | 'link' | 'nav_menu_item' | 'custom_post_type' ] //You may want to insert a regular post, page, link, a menu item or some custom post type
  'tags_input'     => $tags_input,//[ '<tag>, <tag>, <...>' ] //For tags.
  'to_ping'        => $to_ping,//[ ? ] //?
  'tax_input'      => $tax_input//[ array( 'taxonomy_name' => array( 'term', 'term2', 'term3' ) ) ] // support for custom taxonomies. 
);  
// Insert the post into the database
wp_insert_post( $mypost );
}
?>

これがすべて実行されると、次の無限エラーが発生し、投稿が作成されません:

PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/wp-includes/kses.php on line 1146

PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/wp-includes/kses.php on line 1146

PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/wp-includes/kses.php on line 1146....

HTMLファイルの内容をコメントアウトまたは変更すると、これは正常に実行されます。html に何かあるように見えますが、ファイルの内容に関係なく、文字列として表示されています。この警告は何を指していますか? それを回避するためのアイデアはありますか?

4

1 に答える 1

0

kses フィルターをオフにします。フィルターは、挿入するコードを実際に変更しています。https://developer.wordpress.org/reference/functions/kses_remove_filters/

インサートの直前でオフにしてからオンに戻します。

于 2014-07-09T06:01:12.117 に答える