我需要从我的其他网站动态插入包含Java脚本的帖子?

时间:2013-12-01 作者:alex

我试图动态添加一些内容帖子(也包含一些js),但javascript部分被过滤掉了。我认为通过使用wp\\u set\\u current\\u用户,js将被包括在内。

这是我生成帖子的主要功能

   function mydomain_which_page2($atts) {
    extract( shortcode_atts( array(
        \'temp_title\' => \'something\'
    ), $atts ) );
        //post exists?
    if( wp_exist_post_by_title( $temp_title ) ) {
        $redirect_title = sanitize_title( $temp_title);
        header(\'Location:\' . $redirect_title);
        exit();
    } else { 
        // post does not exist
        wp_set_current_user(NULL, \'Test user\');
        //GET THE MAPS
        $output = getIncludeContent(\'myotherdomain.com/generate.php\'); 
        //SAVE AS WP POSTS
        mydomain_add_post($temp_title,$output);
        //REDIRECT
        $redirect_title = sanitize_title( $temp_title);
        header(\'Location:\' . $redirect_title);
        exit();
    }   
}
直接转到myotherdomain。com/generate。php将在源代码中输出js,$output将用js显示源代码。和add\\u post函数

function add_post($title, $content){
    // Create post object wp_strip_all_tags
    //$content = strip_tags($content);

    $my_post = array(
      \'post_title\'    => $title,
      \'post_content\'  => $content,
      \'post_name\'   => sanitize_title($title),
      \'post_status\'   => \'publish\',
      \'post_author\'   => 1,
      \'post_category\' => array(1)
    );

    // Insert the post into the database
    wp_insert_post( $my_post ); 
}
有什么建议吗?

当做

1 个回复
SO网友:alex

我想我找到了解决办法

function add_post($title, $content){
    // Create post object wp_strip_all_tags

    if (!is_user_logged_in()){
        $user_id = 1;
        wp_set_current_user($user_id,$user_login);
        wp_set_auth_cookie($user_id);
        do_action(\'wp_login\',$user_login);
    }

    $my_post = array(
      \'post_title\'    => $title,
      \'post_content\'  => $content,
      \'post_name\'   => sanitize_title($title),
      \'post_status\'   => \'publish\',
     // \'post_author\'   => 1,
      \'post_category\' => array(1)
    );

    // Insert the post into the database
    wp_insert_post( $my_post ); 
}

结束

相关推荐