checkImagePermission($attachment)) { wp_die(esc_html__('You do not have permission to upload files for this author.', 'enable-media-replace')); } $uiHelper = emr()->uiHelper(); $replacer = new Replacer($post_id); $replacer->setMode(\EnableMediaReplace\Replacer::MODE_REPLACE); $datetime = current_time('mysql'); $replacer->setTimeMode( \EnableMediaReplace\Replacer::TIME_UPDATEMODIFIED, $datetime); $api = new Api(); $result = $api->handleDownload($key); if (! $result->success) { die($result->message); } // When are 1-1 replacing. $source = $replacer->getSourceFile(); $redirect_error = $uiHelper->getFailedRedirect($post_id); $redirect_success = $uiHelper->getSuccesRedirect($post_id); if (! file_exists($result->image)) { Log::addError('Download File not here', $result->image); exit(__('Temp file does not exist', 'enable-media-replace')); } try { $result = $replacer->replaceWith($result->image, $source->getFileName() , true); } catch (\RunTimeException $e) { print_r($e->getMessage()); Log::addError($e->getMessage()); die; } if (is_null($result)) { wp_safe_redirect($redirect_error); exit(); } $noticeController = Notices::getInstance(); $notice = Notices::addSuccess('
' . __('File successfully replaced', 'enable-media-replace') . '
'); $notice->is_removable = false; $noticeController->update(); wp_redirect($redirect_success); exit();