1. Echo โ WordPress
Auto-publish your echoes to WordPress as posts.
Auto-sync to WordPress
Every new echo becomes a WordPress post
2. WordPress โ Echo
Import WordPress posts as echoes.
Import from WordPress
Pull WordPress posts into your feed
3. WordPress Plugin (One-Click Setup)
Install this plugin on WordPress for automatic sync.
<?php
/**
* Plugin Name: Echo Sync
* Description: Two-way sync with Echo microblog
* Version: 1.0
*/
add_action('rest_api_init', function() {
register_rest_route('echo/v1', '/sync', array(
'methods' => 'POST',
'callback' => 'echo_receive_sync',
'permission_callback' => '__return_true'
));
});
function echo_receive_sync($request) {
$data = $request->get_json_params();
$post_id = wp_insert_post(array(
'post_title' => wp_trim_words($data['text'], 10, '...'),
'post_content' => $data['text'],
'post_status' => 'publish',
'post_author' => 1,
'post_date' => $data['created_at'],
'post_type' => 'post'
));
if ($post_id && !is_wp_error($post_id)) {
update_post_meta($post_id, '_echo_id', $data['id']);
update_post_meta($post_id, '_echo_author', $data['author']);
return array('success' => true, 'post_id' => $post_id);
}
return array('success' => false);
}
// Also push WP posts to Echo
add_action('publish_post', 'echo_push_to_microblog', 10, 2);
function echo_push_to_microblog($post_id, $post) {
$echo_url = get_option('echo_url');
if (!$echo_url) return;
wp_remote_post($echo_url . '/api.php?action=wp_sync', array(
'headers' => array('Content-Type' => 'application/json'),
'body' => json_encode(array(
'id' => 'wp_' . $post_id,
'text' => $post->post_title . "\n\n" . $post->post_content,
'author' => get_the_author_meta('display_name', $post->post_author),
'handle' => '@' . get_the_author_meta('user_nicename', $post->post_author),
'created_at' => $post->post_date,
'source' => 'wordpress'
))
));
}
?>