我已经看过这个问题的以前的例子,但根据我从其他人那里看到的情况,我找不到导致这个通知的解决方案。当我添加新帖子时,这会出现在屏幕顶部。
1145是:
$post = get_post( $args[0] );
我没有收到任何其他类型的错误,因此我不确定这是在我的代码中导致问题的地方。
Any help on this?
代码如下:
//show metabox in post editing page
add_action(\'add_meta_boxes\', \'kk_add_metabox\' );
//save metabox data
add_action(\'save_post\', \'kk_save_metabox\' );
//register widgets
add_action(\'widgets_init\', \'kk_widget_init\');
function kk_add_metabox() {
add_meta_box(\'kk_youtube\', \'YouTube Video Link\',\'kk_youtube_handler\', \'post\');
}
/**
* metabox handler
*/
function kk_youtube_handler($post)
{
$youtube_link = esc_attr( get_post_meta( $post->ID, \'kk_youtube\', true ) );
echo \'<label for="kk_youtube">YouTube Video Link</label><input type="text" id="kk_youtube" name="kk_youtube" value="\' . $youtube_link . \'" />\';
}
/**
* save metadata
*/
function kk_save_metabox($post_id) {
if( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE ) {
return;
}
//check if user can edit post
if( !current_user_can( \'edit_post\' ) ) {
return;
}
if( isset($_POST[\'kk_youtube\'] )) {
update_post_meta($post_id, \'kk_youtube\', esc_url($_POST[\'kk_youtube\']));
}
}
/**
* register widget
*/
function kk_widget_init() {
register_widget(\'KK_Widget\');
}
/**
* Class KK_Widget widget class
*/
class KK_Widget extends WP_Widget
{
function __construct()
{
$widget_options = array(
\'classname\' => \'kk_class\', // For CSS class name
\'description\' => \'Show a YouTube video from post metadata\'
);
$this->WP_Widget(\'kk_id\', \'YouTube Video\', $widget_options);
}
/**
* Show widget form in Appearance/Widgets
*/
function form($instance)
{
$defaults = array(
\'title\' => \'YouTube Video\'
);
$instance = wp_parse_args((array)$instance, $defaults);
var_dump($instance);
$title = esc_attr($instance[\'title\']);
echo \'<p>Title <input type="text" class="widefat" name="\' . $this->get_field_name(\'title\') . \'" value="\' . $title . \'" /></p>\';
}
function update($new_instance, $old_instance)
{
$instance = $old_instance;
$instance[\'title\'] = strip_tags($new_instance[\'title\']);
return $instance;
}
/**
* Show widget in post/page
*/
function widget($args, $instance)
{
global $before_widget;
global $after_widget;
global $before_title;
global $after_title;
extract( $args );
$title = apply_filters(\'widget_title\', $instance[\'title\']);
//show only if single post
if(is_single()) {
echo $before_widget;
echo $before_title.$title.$after_title;
//get post metadata
$kk_youtube = esc_url(get_post_meta(get_the_ID(), \'kk_youtube\', true));
//print widget content
echo \'<iframe width="200" height="200" frameborder="0" allowfullscreen src="http://www.youtube.com/embed/\' . $this->get_yt_videoid($kk_youtube) . \'"></iframe>\';
echo $after_widget;
}
}
function get_yt_videoid($url)
{
parse_str(parse_url($url, PHP_URL_QUERY), $my_array_of_vars);
return $my_array_of_vars[\'v\'];
}
}