A8C_Files::delete_file PHP Метод

delete_file() публичный Метод

public delete_file ( $file_name )
    function delete_file($file_name)
    {
        $url_parts = parse_url($file_name);
        if (false !== stripos($url_parts['path'], constant('LOCAL_UPLOADS'))) {
            $file_uri = substr($url_parts['path'], stripos($url_parts['path'], constant('LOCAL_UPLOADS')) + strlen(constant('LOCAL_UPLOADS')));
        } else {
            $file_uri = '/' . $url_parts['path'];
        }
        $headers = array('X-Client-Site-ID: ' . constant('FILES_CLIENT_SITE_ID'), 'X-Access-Token: ' . constant('FILES_ACCESS_TOKEN'));
        $service_url = $this->get_files_service_hostname() . '/' . $this->get_upload_path();
        if (is_multisite() && !(is_main_network() && is_main_site())) {
            $service_url .= '/sites/' . get_current_blog_id();
        }
        $ch = curl_init($service_url . $file_uri);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_exec($ch);
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        if (200 != $http_code) {
            error_log(sprintf(__('Error deleting the file from the remote servers: Code %d'), $http_code));
            return;
        }
        // We successfully deleted the file, purge the file from the caches
        $invalidation_url = get_site_url() . '/' . $this->get_upload_path();
        if (is_multisite() && !(is_main_network() && is_main_site())) {
            $invalidation_url .= '/sites/' . get_current_blog_id();
        }
        $invalidation_url .= $file_uri;
        $this->purge_file_cache($invalidation_url, 'PURGE');
    }