我在管理区域内实现了一种“页面”,可以在没有默认方法的情况下手动插入帖子。这只是开始。。。无论如何,在启动表单的插入按钮后,插入了文章,但我得到了一个很长的错误:致命错误:未捕获错误:调用未定义函数。。。。
代码如下:
<?php
/*
Plugin Name: TEST Importer
Plugin URI:
Description: No description.
Text Domain:
Author: The author
Version: 1.0
Author URI: http://www.example.net/
*/
if ( ! defined( \'ABSPATH\' ) ) {
exit;
}
add_action( \'admin_menu\', \'my_plugin_menu\' );
function my_plugin_menu() {
add_menu_page(
\'Importer\',
\'IMPORTER\',
\'manage_options\',
\'importer\',
\'display_content\', //function
\'dashicons-video-alt3\',
50
);
}
add_action( \'admin_enqueue_scripts\', \'register_importer_styles\' );
function register_importer_styles() {
wp_enqueue_style( \'importer\', plugins_url(\'importer.css\', __FILE__) );
wp_enqueue_script( \'importer\', plugins_url(\'importer.js\', __FILE__) );
}
if (isset($_POST[\'insert\'])) {
$title = $_POST[\'data\'];
/*require_once( ABSPATH . \'wp-load.php\' );*/
$my_post = array(
\'post_title\' => $title,
\'post_content\' => \'content here\',
\'post_status\' => \'draft\',
\'post_author\' => 1,
);
wp_insert_post( $my_post );
/*if ($post_id) {
// insert post meta
add_post_meta($post_id, \'duration\', $seconds);
add_post_meta($post_id, \'quality\', $is_hd);
}*/
}
add_action( \'admin_head\', \'my_custom_admin_head\' );
function my_custom_admin_head() { ?>
<script type="text/javascript">
//Some javascript code...
</script>;
<?php }
function display_content() { ?>
<div id="main_importer_area">
<form action="<?php echo admin_url(\'admin.php?page=importer\'); ?>" method="post">
<input id="jx_text" type="text" name="data" >
<input id="ins_btn" type="submit" value="Insert" name="insert">
</form>
</div>
<?php } ?>
我希望有人能帮助我。。。非常感谢!
Fatal error: Uncaught Error: Call to undefined function is_user_logged_in() in /home/***/public_html/wp-includes/post.php:2191
Stack trace:
#0 /home/***/public_html/wp-includes/post.php(6008): _count_posts_cache_key(\'post\', \'readable\')
#1 /home/***/public_html/wp-includes/class-wp-hook.php(286): _transition_post_status(\'draft\', \'new\', Object(WP_Post))
#2 /home/***/public_html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(\'\', Array)
#3 /home/***/public_html/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
#4 /home/***/public_html/wp-includes/post.php(4036): do_action(\'transition_post...\', \'draft\', \'new\', Object(WP_Post))
#5 /home/***/public_html/wp-includes/post.php(3496): wp_transition_post_status(\'draft\', \'new\', Object(WP_Post))
#6 /home/***/public_html/wp-content/plugins/importer/importer.php(45): wp_insert_post(Array)
#7 /home/***/public_html/wp-settings.php(305): include_once(\'/home/yo.../...\')
#8 /home/***/public_html/wp-config.php(89): require_o in /home/***/public_html/wp-includes/post.php on line 2191