ari // after install will update the values register_activation_hook(__FILE__, 'ari_install'); function ari_install() { update_option('ari_overall_swich', 'on'); update_option('ari_default_setting', 'on'); update_option('ari_display_box', 'on'); update_option('ari_archive_autosave', ''); } /*Call 'LZ_option_link' function to Add a submenu link under Profile tab.*/ add_action('admin_menu', 'archive_remote_images_option_link'); /** * Function Name: archive_remote_images_option_link * Description: Add a submenu under Settings tab. * */ function archive_remote_images_option_link() { add_options_page('Archive Remote Images', 'Archive Remote Images', 'manage_options', 'archive-remote-images', 'archive_remote_images_option_form'); } function archive_remote_images_option_form() { $ari_path = plugin_dir_url(__FILE__); echo '

General option

'; /** * Check whether the form submitted or not. */ if (isset($_POST['option-save'])) { echo "
Options saved!
"; update_option('ari_overall_swich', trim($_POST['ari_overall_swich'])); update_option('ari_default_setting', trim($_POST['ari_default_setting'])); update_option('ari_display_box', trim($_POST['ari_display_box'])); update_option('ari_archive_autosave', trim($_POST['ari_archive_autosave'])); } ?>

Archive images from remote website base on url, automatic archive images when save post/page, able to customize setting for each post.

Following links can help you:

Enable 'Archive Remote Images' overall switch: (help?) type="checkbox" id="ari_overall_swich" name="ari_overall_swich" />
Auto archive when post saving as default setting: (help?) type="checkbox" id="ari_default_setting" name="ari_default_setting" />
Display Archive Remote Images option box in post page: (help?) type="checkbox" id="ari_display_box" name="ari_display_box" />
Archive Remote Images for auto save: (help?) type="checkbox" id="ari_archive_autosave" name="ari_archive_autosave" />

ID, 'transfer_image', TRUE); $check_one = ''; if ($transfer_image_value != 'yes' && $transfer_image_value != 'no') { if (get_option('ari_default_setting') == "on") { $check_one = 'checked="checked"'; } else { $check_two = 'checked="checked"'; } } else { if ($transfer_image_value == 'yes') { $check_one = 'checked="checked"'; } else { $check_two = 'checked="checked"'; } } ?>

Archive:   id="img-cache-yes-0" class="img-cache-yes" name="transfer_image"> id="img-cache-yes-video" class="img-cache-yes" name="transfer_image">

|i', $content, $matches); foreach ($matches[1] as $url): $url = parse_url($url); $domains[$url['host']]++; endforeach; return $domains; } /** * Archive image from content */ function archive_image_from_remote($url, $postid) { global $wpdb; $orig_url = $url; if (strpos($url, 'blogspot.com') || strpos($url, 'blogger.com') || strpos($url, 'ggpht.com') || strpos($url, 'googleusercontent.com') || strpos($url, 'gstatic.com')) { $response = wp_remote_request($url); if (is_wp_error($response)) return 'error1'; $my_body = wp_remote_retrieve_body($response); if (strpos($my_body, 'src')) { preg_match_all('||i', $my_body, $matches); foreach ($matches[1] as $url): $spisak = $url; endforeach; $url = $spisak; } } set_time_limit(300); require_once(ABSPATH . 'wp-admin/includes/media.php'); require_once(ABSPATH . 'wp-admin/includes/file.php'); $upload = media_sideload_image($url, $postid); if (!is_wp_error($upload)) { preg_match_all('||i', $upload, $locals); foreach ($locals[1] as $newurl): $wpdb->query("UPDATE $wpdb->posts SET post_content = REPLACE(post_content, '$orig_url', '$newurl');"); endforeach; } return $url; } /* * Archive images on while saving */ function archive_save_post($post_ID, $post) { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && get_option('ari_archive_autosave') != "on") return $post_id; if (get_option('ari_overall_swich') != "on" && $_POST['transfer_image'] == "no") { return $post_ID; } global $wpdb; $domains = archive_find_images($post->post_content, $domains); if (!$domains) return $post_ID; $local_domain = parse_url(get_option('siteurl')); foreach ($domains as $domain => $num): if (strstr($domain, $local_domain['host'])) continue; // check if is local images preg_match_all('||i', $post->post_content, $matches); foreach ($matches[1] as $url): if (strstr($url, get_option('siteurl') . '/' . get_option('upload_path')) || !strstr($url, $domain) || (($res) && in_multi_array($url, $res))) continue; // check if is local images archive_image_from_remote($url, $post_ID); endforeach; endforeach; return $post_ID; } add_action('save_post', 'archive_save_post', 10, 2); ?>