Пример #1
0
 static function delete($post_ID)
 {
     // global $grape_synced;
     if (!GrapePostController::check_nonce()) {
         return $post_ID;
     }
     $post = new GrapePost($post_ID);
     if (!$post->was_synced()) {
         grape_debug("controller: delete -> STOP (was never synced before)");
         return $post_ID;
     }
     do_action('grape_post_delete', $post);
     foreach ($post->get_connections() as $connection) {
         $post->use_custom_title_field($connection['custom_title_field']);
         $api = new GRAPE_API($connection['api_token'], $connection['api_url']);
         $api->delete($post);
     }
     return $post_ID;
 }
Пример #2
0
function grape_full_sync()
{
    global $wpdb;
    // TODO: implement syncing of taxonomies
    // we need an array of post types that looks like array("post", "page")
    $options = grape_get_options();
    $post_types = array_unique(array_keys($options['syncables']['post_type']));
    // get all the posts from the DB. query takes multiple post types
    $args = array('post_type' => $post_types, 'posts_per_page' => -1);
    $posts = get_posts($args);
    // TODO: if someone adds two post types twice, we have a problem
    $post_count = count($posts);
    // $post_id is not the real post id! it's just the index in the list
    $post_id = 0;
    if (isset($_POST['postId'])) {
        $post_id = intval($_POST['postId']);
    }
    $next_post_id = $post_id + 1;
    $current_post = $posts[$post_id];
    grape_debug('Full Sync: post id ' . $current_post->ID);
    GrapePostController::post($current_post->ID, true);
    $response = array('postsTotal' => $post_count, 'currentPostId' => $post_id, 'currentPostTitle' => $current_post->title);
    if ($next_post_id < $post_count) {
        $response['nextPostId'] = $next_post_id;
    }
    echo json_encode($response);
    wp_die();
    // this is required to terminate immediately and return a proper response
}