function wprss_save_meta_box_data($post_id) { // Check if our nonce is set. if (!isset($_POST['wprss_meta_box_nonce'])) { return; } // Verify that the nonce is valid. if (!wp_verify_nonce($_POST['wprss_meta_box_nonce'], 'wprss_save_meta_box_data')) { return; } // If this is an autosave, our form has not been submitted, so we don't want to do anything. if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } // Check the user's permissions. if (isset($_POST['post_type']) && 'page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return; } } else { if (!current_user_can('edit_post', $post_id)) { return; } } // OK, it's safe for us to save the data now. $options = get_option('wprss_options'); if (is_array($options) && count($options) > 0) { if (is_object($post_id)) { $post_id = $post_id->ID; } $post = get_post($post_id); $post_categories = wp_get_post_categories($post_id); $post_tags = wp_get_post_tags($post_id); $listcat = array(); $listtag = array(); if (count($post_categories) > 0) { foreach ($post_categories as $c) { $cat = get_category($c); $listcat[] = $cat->name; } } if (count($post_tags) > 0) { foreach ($post_tags as $t) { $listtag[] = $t->name; } } $path_to_www_folder = get_home_path(); include_once $path_to_www_folder . 'wp-includes/class-IXR.php'; $post_date_gmt = new IXR_Date(strtotime($post->post_date_gmt)); foreach ($options as $key => $val) { if ($options[$key]["wprss_host"] != "") { if ($_POST["wprss_check_" . $key] != "") { $h = $options[$key]["wprss_host"]; $u = $options[$key]["wprss_username"]; $p = $options[$key]["wprss_pwd"]; $update_post = 0; $meta_key = 'post_at_' . $h; $remote_post_id = get_post_meta($post_id, $meta_key, true); $client = new IXR_CLIENT($h . '/xmlrpc.php'); if ($remote_post_id != "") { if ($client->query('wp.getPost', '1', $u, $p, $remote_post_id)) { $response = $client->getResponse(); if (count($response) > 0) { $update_post = 1; } else { delete_post_meta($post_id, $meta_key, $remote_post_id); } } else { delete_post_meta($post_id, $meta_key, $remote_post_id); } } if ($update_post == 0) { $content = array(); $content['post_status'] = $post->post_status; $content['post_title'] = $post->post_title; $content['post_excerpt'] = substr($post->post_content_filtered, 0, 250); $content['post_date_gmt'] = $post_date_gmt; $content['post_content'] = $post->post_content_filtered; $content['terms'] = array('category' => $listcat); $content['terms_names'] = array('post_tag' => $listtag); if (!$client->query('wp.newPost', '', $u, $p, $content)) { error_log("Error creation new post: " . $client->getErrorMessage()); } else { $remote_post_id = $client->getResponse(); add_post_meta($post_id, $meta_key, $remote_post_id, true); } } else { $content = array(); $content['post_status'] = $post->post_status; $content['post_title'] = $post->post_title; $content['post_excerpt'] = substr($post->post_content_filtered, 0, 250); $content['post_date_gmt'] = $post_date_gmt; $content['post_content'] = $post->post_content_filtered; $content['terms'] = array('category' => $listcat); $content['terms_names'] = array('post_tag' => $listtag); if (!$client->query('wp.editPost', "1", $u, $p, $remote_post_id, $content, true)) { error_log("Error edit post: " . $client->getErrorMessage()); } } } } } } return; }