/**
 *
 */
function external_image_import_all_ajax()
{
    //external_images_verify_permission();
    global $wpdb;
    $post_id = intval($_POST['import_images_post']);
    $response = array();
    if (!$post_id) {
        $results = array('success' => false, 'message' => 'Missing ID Parameter');
        echo json_encode($results);
        die;
    }
    $post = get_post($post_id);
    // do what we need with image...
    $response = external_image_import_images($post_id, true);
    $results = $response ? '<strong>' . $post->post_title . '</strong> had (' . $response . ') attachments successfully imported<br />' : '<strong>' . $post->post_title . ': </strong> No attachments imported - you might want to check whether they still exist!';
    echo json_encode($results);
    die;
    // required by wordpress
}
Exemplo n.º 2
0
function external_image_backcatalog()
{
    $posts = get_posts(array('numberposts' => -1));
    echo '<h4>Processing Posts...</h4>';
    set_time_limit(300);
    $count = 0;
    $before = '<form style="padding: 0 10px; margin: 20px 20px 0 0; float: left;" action="" method="post" name="external_image-backcatalog">';
    $resubmit = '<input type="hidden" value="backcatalog" name="action">
			<input class="button-primary" type="submit" value="Process More Posts">';
    $after = '</form>';
    foreach ($posts as $post) {
        try {
            $imgs = external_image_get_img_tags($post->ID);
            if (is_array($imgs) && count($imgs) > 0) {
                $count += count($imgs);
                echo '<p>Post titled: "<strong>' . $post->post_title . '</strong>" - ';
                external_image_import_images($post->ID, true);
                echo count($imgs) . ' Images processed</p>';
            }
        } catch (Exception $e) {
            echo '<em>an error occurred</em>.</p>';
        }
    }
    if ($done_message) {
        echo $before;
        echo $done_message;
        echo $resubmit;
        echo $after;
    } else {
        echo '<p>Finished processing past posts!</p>';
    }
}