// CAROUSEL LICENSE POP UP
×

Attribution & License

This image is provided for non-commercial, educational use under
CC BY-NC-ND 4.0.

Free for non-commercial use with these restrictions:
provide credit, no edits or derivatives, no resale or relicensing.

(Click in the box to select all text for copying)

Notice: ancient-greece.org is not responsible for errors. The license applies to the photograph; users are responsible for clearing rights to underlying subjects (museums, artifacts, etc.).
Φ
Φῶς
Ἴχνος
Λ
Λέξη
Search
    /* end language toggle */ /* ========================================================================== 000-always the last block in the file. STANDALONE IMAGE SWAP ENGINE (Preserves Metadata) ========================================================================== */ /** * Backend Engine: Overwrites physical file while keeping Post ID & Meta intact. */ function ag_core_image_swap_logic($attachment_id, $file_array) { if (!current_user_can('edit_post', $attachment_id)) return false; require_once(ABSPATH . 'wp-admin/includes/file.php'); require_once(ABSPATH . 'wp-admin/includes/image.php'); $old_file = get_attached_file($attachment_id); $movefile = wp_handle_upload($file_array, array('test_form' => false)); if ($movefile && !isset($movefile['error'])) { // Clean up physical thumbnails to prevent server clutter $meta = wp_get_attachment_metadata($attachment_id); if ($meta) { $base_dir = wp_upload_dir()['basedir']; foreach (($meta['sizes'] ?? []) as $size) { $path = path_join($base_dir, dirname($meta['file']) . '/' . $size['file']); if (file_exists($path)) @unlink($path); } if (file_exists($old_file)) @unlink($old_file); } // Update database with new file path and regenerate metadata update_attached_file($attachment_id, $movefile['file']); wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, $movefile['file'])); clean_post_cache($attachment_id); return true; } return false; } /** * AJAX Responder */ add_action('wp_ajax_ag_swap_image', function() { check_ajax_referer('ag_inline_nonce', 'nonce'); $id = intval($_POST['attachment_id']); if (!empty($_FILES['new_file']) && ag_core_image_swap_logic($id, $_FILES['new_file'])) { wp_send_json_success(); } wp_send_json_error(); }); /** * UI Injection & JS Handler */ add_action('admin_footer', function() { $screen = get_current_screen(); if (!$screen || $screen->id !== 'upload') return; ?>