对不起,我会说一点英语。
为什么不可行?
我的插件:~/wp-content/plugins/myplugg/myplugg。php
<?php
/**
* Plugin Name: mypluggg
*/
function videos() {
// file_get_content()
// $http_response_header
$postarr = array();
foreach( $videos as $key=> $video ) {
$postarr [ $key ] = array( // etc.
wp_insert_post( $postarr [ $key ], $wp_error );
}
}
videos();
?>
添加1个post,然后添加错误屏幕:
https://i.imgur.com/MlxcTsW.png
此网站出现严重错误。
Learn more about troubleshooting WordPress.为什么?
UPDATE(1):
foreach( $videos as $key=> $video ) {
$postarr [ $key ] = array(
\'post_title\'=> $videos [ \'title\' ] [ $key ],
\'post_content\'=> \'<iframe src="https://*.com/\' . $videos [ \'id\' ] [ $key ] . \'" frameborder=0 width=510 height=400 scrolling=no allowfullscreen=allowfullscreen></iframe>\',
\'post_status\'=> \'publish\',
\'post_author\'=> 1,
\'meta_input\'=> array(
\'site\'=> \'*.com\',
\'video_id\'=> $videos [ \'id\' ] [ $key ],
\'thumbnail\'=> $thumbnail,
\'video_url\'=> $video_url,
\'iframe_src_start\'=> \'https://*.com/embedframe/\',
\'iframe_src_end\'=> \'\',
\'v_tag\'=> $tag
)
);
}
UPDATE(2):
我的~/error\\u日志文件(我不调用is\\u user\\u logged\\u函数):
[31-Aug-2021 15:16:22 UTC] PHP Fatal error: Uncaught Error: Call to undefined function is_user_logged_in() in /home/x/public_html2/y/public_html/wp-includes/post.php:2793
Stack trace:
#0 /home/x/public_html2/y/public_html/wp-includes/post.php(7359): _count_posts_cache_key(\'post\', \'readable\')
#1 /home/x/public_html2/y/public_html/wp-includes/class-wp-hook.php(303): _transition_post_status(\'publish\', \'new\', Object(WP_Post))
#2 /home/x/public_html2/y/public_html/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters(\'\', Array)
#3 /home/x/public_html2/y/public_html/wp-includes/plugin.php(470): WP_Hook->do_action(Array)
#4 /home/x/public_html2/y/public_html/wp-includes/post.php(5098): do_action(\'transition_post...\', \'publish\', \'new\', Object(WP_Post))
#5 /home/x/public_html2/y/public_html/wp-includes/post.php(4368): wp_transition_post_status(\'publish\', \'new\', Object(WP_Post))
#6 /home/x/public_html2/y/public_html in /home/x/public_html2/y/public_html/wp-includes/post.php on line 2793
UPDATE(3):
不工作,我看到错误屏幕(
https://i.imgur.com/MlxcTsW.png):
$ID = wp_insert_post( $postarr [ $key ], $wp_error );
if( ! is_wp_error( $ID ) ) {} else {
echo $ID-> get_error_message();
} else {}
UPDATE(4):
我尝试创建新的测试自定义插件,但问题是相同的。完整代码:
~/wp内容/插件/mypluk/mypluk。php
<?php
/**
* Plugin Name: mypluk
*/
function videoss() {
$postarr = array();
foreach( array( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27 ) as $key ) {
$postarr [ $key ] = array(
\'post_title\'=> \'title\' . $key
);
$ID = wp_insert_post( $postarr [ $key ], $wp_error );
}
}
videoss();
?>