在curl响应上的save_post挂钩错误消息显示在当前发布的类似更新消息上

时间:2014-05-06 12:13:30

标签: wordpress-plugin wordpress

  

在我的插件上返回curl错误消息显示在帖子页面上,如a   发布更新消息。

public function __construct() {
        add_action('init', array(&$this, 'init'));
        add_action('admin_init', array(&$this, 'admin_init'));
        add_action('admin_menu', array(&$this, 'add_page'));
        add_action('admin_notices', array(&$this,'socipilot_admin_notice') );
        add_action('admin_bar_menu', array(&$this, 'socipilot_adminbar_links' ), 1001 );
        add_action('add_meta_boxes', array(&$this, 'add_meta_box' ) );
        add_action('admin_enqueue_scripts', array(&$this,'socipilot_enqueue_scripts')); 

        add_action('save_post', array(&$this, 'save'));


        add_filter('plugin_action_links_'.SOCI_PILOT_PLUGIN_BASENAME, array(&$this,'ts_add_plugin_action_links'));
        // Listen for the activate event
        register_activation_hook(SOCI_PILOT_FILE, array(&$this, 'activate'));
        // Deactivation plugin
        register_deactivation_hook(SOCI_PILOT_FILE, array(&$this, 'deactivate'));
}


public function save_socipost($post_id) {
    $res = actionPosttest($options['public_key'],$options['private_key'],$data);
        if($res->error==1){
        global $my_error;
        echo $post_error = $res->msg;
    exit;
}

enter image description here

1 个答案:

答案 0 :(得分:1)

public function __construct() {

    add_action('save_post', array(&$this, 'save_socipost'));

    //add filter on construct 

        add_filter('post_updated_messages', array(&$this,'socipilot_updated_messages'));
}


public function socipilot_updated_messages($messages){
    session_start();

    //difine your message hear
    $messages['post'][11] = sprintf( __($_SESSION['soci_error']));
    return $messages;
}


public function save_socipost($post_id) {

       global $post;
       global $socipost_save_post_flag;

       //function data

       //my fix code for message hear

        if($error_id==0 && isset($res)):

           if ($socipost_save_post_flag == 0){
                $res = actionPosttest($options['public_key'],$options['private_key'],$data);
            } 
            $socipost_save_post_flag =1;

            if($res->error==1){
                 global $my_error;
                 if($_SESSION['soci_error']){
                     session_destroy();
                 }else{
                    session_start();
                    $_SESSION['soci_error']= $res->msg;
                 }

                 wp_redirect(admin_url('post.php?post='.$post_id.'&action=edit&message=11'));
                 die();
            }


            //continew data
            .
            .
            .
}   

enter image description here